3 * Script will find all rows in the categorylinks table whose collation is
4 * out-of-date (cl_collation != $wgCategoryCollation) and repopulate cl_sortkey
5 * using the page title and cl_sortkey_prefix.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
23 * @ingroup Maintenance
24 * @author Aryeh Gregor (Simetrical)
27 #$optionsWithArgs = array( 'begin', 'max-slave-lag' );
29 require_once( dirname( __FILE__
) . '/Maintenance.php' );
31 class UpdateCollation
extends Maintenance
{
32 const BATCH_SIZE
= 1000;
34 public function __construct() {
35 parent
::__construct();
37 global $wgCategoryCollation;
38 $this->mDescription
= <<<TEXT
39 This script will find all rows in the categorylinks table whose collation is
40 out-of-date (cl_collation != '$wgCategoryCollation') and repopulate cl_sortkey
41 using the page title and cl_sortkey_prefix. If everything's collation is
42 up-to-date, it will do nothing.
45 #$this->addOption( 'force', 'Run on all rows, even if the collation is supposed to be up-to-date.' );
48 public function execute() {
49 global $wgCategoryCollation, $wgContLang;
51 $dbw = wfGetDB( DB_MASTER
);
52 $count = $dbw->selectField(
55 'cl_collation != ' . $dbw->addQuotes( $wgCategoryCollation ),
60 $this->output( "Collations up-to-date.\n" );
63 $this->output( "Fixing collation for $count rows.\n" );
68 array( 'categorylinks', 'page' ),
69 array( 'cl_from', 'cl_to', 'cl_sortkey_prefix', 'cl_collation',
70 'cl_sortkey', 'page_namespace', 'page_title'
73 'cl_collation != ' . $dbw->addQuotes( $wgCategoryCollation ),
77 array( 'LIMIT' => self
::BATCH_SIZE
)
81 foreach ( $res as $row ) {
82 $title = Title
::newFromRow( $row );
83 if ( $row->cl_collation
== 0 ) {
84 # This is an old-style row, so the sortkey needs to be
86 if ( $row->cl_sortkey
== $title->getText()
87 ||
$row->cl_sortkey
== $title->getPrefixedText() ) {
90 # Custom sortkey, use it as a prefix
91 $prefix = $row->cl_sortkey
;
94 $prefix = $row->cl_sortkey_prefix
;
96 # cl_type will be wrong for lots of pages if cl_collation is 0,
97 # so let's update it while we're here.
98 if ( $title->getNamespace() == NS_CATEGORY
) {
100 } elseif ( $title->getNamespace() == NS_FILE
) {
108 'cl_sortkey' => $wgContLang->convertToSortkey(
109 $title->getCategorySortkey( $prefix ) ),
110 'cl_sortkey_prefix' => $prefix,
111 'cl_collation' => $wgCategoryCollation,
113 'cl_timestamp = cl_timestamp',
115 array( 'cl_from' => $row->cl_from
, 'cl_to' => $row->cl_to
),
121 $count +
= $res->numRows();
122 $this->output( "$count done.\n" );
123 } while ( $res->numRows() == self
::BATCH_SIZE
);
127 $maintClass = "UpdateCollation";
128 require_once( DO_MAINTENANCE
);