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 $wgCollationVersion;
19 $this->mDescription
= <<<TEXT
20 This script will find all rows in the categorylinks table whose collation is
21 out-of-date (cl_collation != $wgCollationVersion) 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 $wgCollationVersion, $wgContLang;
32 $dbw = wfGetDB( DB_MASTER
);
33 $count = $dbw->estimateRowCount(
35 array( 'cl_from', 'cl_to', 'cl_sortkey_prefix' ),
36 'cl_collation != ' . $dbw->addQuotes( $wgCollationVersion ),
40 $this->output( "Fixing collation for around $count rows (estimate might be wrong).\n" );
45 array( 'categorylinks', 'page' ),
46 array( 'cl_from', 'cl_to', 'cl_sortkey_prefix', 'cl_collation',
47 'cl_sortkey', 'page_namespace', 'page_title'
50 'cl_collation != ' . $dbw->addQuotes( $wgCollationVersion ),
54 array( 'LIMIT' => self
::BATCH_SIZE
)
58 foreach ( $res as $row ) {
59 $title = Title
::newFromRow( $row );
60 if ( $row->cl_collation
== 0 ) {
61 # This is an old-style row, so the sortkey needs to be
63 if ( $row->cl_sortkey
== $title->getText()
64 ||
$row->cl_sortkey
== $title->getPrefixedText() ) {
67 # Custom sortkey, use it as a prefix
68 $prefix = $row->cl_sortkey
;
71 $prefix = $row->cl_sortkey_prefix
;
73 # cl_type will be wrong for lots of pages if cl_collation is 0,
74 # so let's update it while we're here.
75 if ( $title->getNamespace() == NS_CATEGORY
) {
77 } elseif ( $title->getNamespace() == NS_FILE
) {
85 'cl_sortkey' => $wgContLang->convertToSortkey(
86 $title->getCategorySortkey( $prefix ) ),
87 'cl_sortkey_prefix' => $prefix,
88 'cl_collation' => $wgCollationVersion,
91 array( 'cl_from' => $row->cl_from
, 'cl_to' => $row->cl_to
),
97 $count +
= $res->numRows();
98 $this->output( "$count done.\n" );
99 } while ( $res->numRows() == self
::BATCH_SIZE
);
103 $maintClass = "UpdateCollation";
104 require_once( DO_MAINTENANCE
);