5 * @author Aryeh Gregor (Simetrical)
8 #$optionsWithArgs = array( 'begin', 'max-slave-lag' );
10 require_once( dirname( __FILE__
) . '/Maintenance.php' );
12 class UpdateCollation
extends Maintenance
{
13 const BATCH_SIZE
= 1000;
15 public function __construct() {
16 parent
::__construct();
18 global $wgCategoryCollation;
19 $this->mDescription
= <<<TEXT
20 This script will find all rows in the categorylinks table whose collation is
21 out-of-date (cl_collation != '$wgCategoryCollation') and repopulate cl_sortkey
22 using the page title and cl_sortkey_prefix. If everything's collation is
23 up-to-date, it will do nothing.
26 #$this->addOption( 'force', 'Run on all rows, even if the collation is supposed to be up-to-date.' );
29 public function execute() {
30 global $wgCategoryCollation, $wgContLang;
32 $dbw = wfGetDB( DB_MASTER
);
33 $count = $dbw->selectField(
36 'cl_collation != ' . $dbw->addQuotes( $wgCategoryCollation ),
41 $this->output( "Collations up-to-date.\n" );
44 $this->output( "Fixing collation for $count rows.\n" );
49 array( 'categorylinks', 'page' ),
50 array( 'cl_from', 'cl_to', 'cl_sortkey_prefix', 'cl_collation',
51 'cl_sortkey', 'page_namespace', 'page_title'
54 'cl_collation != ' . $dbw->addQuotes( $wgCategoryCollation ),
58 array( 'LIMIT' => self
::BATCH_SIZE
)
62 foreach ( $res as $row ) {
63 $title = Title
::newFromRow( $row );
64 if ( $row->cl_collation
== 0 ) {
65 # This is an old-style row, so the sortkey needs to be
67 if ( $row->cl_sortkey
== $title->getText()
68 ||
$row->cl_sortkey
== $title->getPrefixedText() ) {
71 # Custom sortkey, use it as a prefix
72 $prefix = $row->cl_sortkey
;
75 $prefix = $row->cl_sortkey_prefix
;
77 # cl_type will be wrong for lots of pages if cl_collation is 0,
78 # so let's update it while we're here.
79 if ( $title->getNamespace() == NS_CATEGORY
) {
81 } elseif ( $title->getNamespace() == NS_FILE
) {
89 'cl_sortkey' => $wgContLang->convertToSortkey(
90 $title->getCategorySortkey( $prefix ) ),
91 'cl_sortkey_prefix' => $prefix,
92 'cl_collation' => $wgCategoryCollation,
94 'cl_timestamp = cl_timestamp',
96 array( 'cl_from' => $row->cl_from
, 'cl_to' => $row->cl_to
),
102 $count +
= $res->numRows();
103 $this->output( "$count done.\n" );
104 } while ( $res->numRows() == self
::BATCH_SIZE
);
108 $maintClass = "UpdateCollation";
109 require_once( DO_MAINTENANCE
);