Index: trunk/phase3/maintenance/updateCollation.php |
— | — | @@ -0,0 +1,74 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * @file |
| 5 | + * @ingroup Maintenance |
| 6 | + * @author Aryeh Gregor (Simetrical) |
| 7 | + */ |
| 8 | + |
| 9 | +#$optionsWithArgs = array( 'begin', 'max-slave-lag' ); |
| 10 | + |
| 11 | +require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
| 12 | + |
| 13 | +class UpdateCollation extends Maintenance { |
| 14 | + const BATCH_SIZE = 1000; |
| 15 | + |
| 16 | + public function __construct() { |
| 17 | + parent::__construct(); |
| 18 | + |
| 19 | + global $wgCollationVersion; |
| 20 | + $this->mDescription = <<<TEXT |
| 21 | +This script will find all rows in the categorylinks table whose collation is |
| 22 | +out-of-date (cl_collation < $wgCollationVersion) and repopulate cl_sortkey |
| 23 | +using cl_raw_sortkey. If everything's collation is up-to-date, it will do |
| 24 | +nothing. |
| 25 | +TEXT; |
| 26 | + |
| 27 | + #$this->addOption( 'force', 'Run on all rows, even if the collation is supposed to be up-to-date.' ); |
| 28 | + } |
| 29 | + |
| 30 | + public function execute() { |
| 31 | + global $wgCollationVersion, $wgContLang; |
| 32 | + |
| 33 | + $dbw = wfGetDB( DB_MASTER ); |
| 34 | + $count = $dbw->estimateRowCount( |
| 35 | + 'categorylinks', |
| 36 | + array( 'cl_from', 'cl_to', 'cl_raw_sortkey' ), |
| 37 | + 'cl_collation < ' . $dbw->addQuotes( $wgCollationVersion ), |
| 38 | + __METHOD__ |
| 39 | + ); |
| 40 | + |
| 41 | + $this->output( "Fixing around $count rows (estimate might be wrong).\n" ); |
| 42 | + |
| 43 | + $count = 0; |
| 44 | + do { |
| 45 | + $res = $dbw->select( |
| 46 | + 'categorylinks', |
| 47 | + array( 'cl_from', 'cl_to', 'cl_raw_sortkey' ), |
| 48 | + 'cl_collation < ' . $dbw->addQuotes( $wgCollationVersion ), |
| 49 | + __METHOD__, |
| 50 | + array( 'LIMIT' => self::BATCH_SIZE ) |
| 51 | + ); |
| 52 | + |
| 53 | + $dbw->begin(); |
| 54 | + foreach ( $res as $row ) { |
| 55 | + # TODO: Handle the case where cl_raw_sortkey is null. |
| 56 | + $dbw->update( |
| 57 | + 'categorylinks', |
| 58 | + array( |
| 59 | + 'cl_sortkey' => $wgContLang->convertToSortkey( $row->cl_raw_sortkey ), |
| 60 | + 'cl_collation' => $wgCollationVersion |
| 61 | + ), |
| 62 | + array( 'cl_from' => $row->cl_from, 'cl_to' => $row->cl_to ), |
| 63 | + __METHOD__ |
| 64 | + ); |
| 65 | + } |
| 66 | + $dbw->commit(); |
| 67 | + |
| 68 | + $count += self::BATCH_SIZE; |
| 69 | + $this->output( "$count done.\n" ); |
| 70 | + } while ( $res->numRows() >= self::BATCH_SIZE ); |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +$maintClass = "UpdateCollation"; |
| 75 | +require_once( DO_MAINTENANCE ); |
Property changes on: trunk/phase3/maintenance/updateCollation.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 76 | + native |
Index: trunk/phase3/includes/CategoryPage.php |
— | — | @@ -172,14 +172,20 @@ |
173 | 173 | * else use sortkey... |
174 | 174 | */ |
175 | 175 | function getSubcategorySortChar( $title, $sortkey ) { |
176 | | - global $wgContLang; |
| 176 | + global $wgContLang, $wgExperimentalCategorySort; |
177 | 177 | |
178 | 178 | if ( $title->getPrefixedText() == $sortkey ) { |
179 | | - $firstChar = $wgContLang->firstChar( $title->getDBkey() ); |
| 179 | + $word = $title->getDBkey(); |
180 | 180 | } else { |
181 | | - $firstChar = $wgContLang->firstChar( $sortkey ); |
| 181 | + $word = $sortkey; |
182 | 182 | } |
183 | 183 | |
| 184 | + if ( $wgExperimentalCategorySort ) { |
| 185 | + $firstChar = $wgContLang->firstLetterForLists( $word ); |
| 186 | + } else { |
| 187 | + $firstChar = $wgContLang->firstChar( $word ); |
| 188 | + } |
| 189 | + |
184 | 190 | return $wgContLang->convert( $firstChar ); |
185 | 191 | } |
186 | 192 | |
— | — | @@ -202,7 +208,7 @@ |
203 | 209 | * Add a miscellaneous page |
204 | 210 | */ |
205 | 211 | function addPage( $title, $sortkey, $pageLength, $isRedirect = false ) { |
206 | | - global $wgContLang; |
| 212 | + global $wgContLang, $wgExperimentalCategorySort; |
207 | 213 | $this->articles[] = $isRedirect |
208 | 214 | ? '<span class="redirect-in-category">' . |
209 | 215 | $this->getSkin()->link( |
— | — | @@ -213,7 +219,12 @@ |
214 | 220 | array( 'known', 'noclasses' ) |
215 | 221 | ) . '</span>' |
216 | 222 | : $this->getSkin()->makeSizeLinkObj( $pageLength, $title ); |
217 | | - $this->articles_start_char[] = $wgContLang->convert( $wgContLang->firstChar( $sortkey ) ); |
| 223 | + |
| 224 | + if ( $wgExperimentalCategorySort ) { |
| 225 | + $this->articles_start_char[] = $wgContLang->convert( $wgContLang->firstLetterForLists( $sortkey ) ); |
| 226 | + } else { |
| 227 | + $this->articles_start_char[] = $wgContLang->convert( $wgContLang->firstChar( $sortkey ) ); |
| 228 | + } |
218 | 229 | } |
219 | 230 | |
220 | 231 | function finaliseCategoryState() { |
— | — | @@ -259,7 +270,7 @@ |
260 | 271 | foreach ( array( 'page', 'subcat', 'file' ) as $type ) { |
261 | 272 | $res = $dbr->select( |
262 | 273 | $tables, |
263 | | - $fields, |
| 274 | + array_merge( $fields, array( 'cl_raw_sortkey' ) ), |
264 | 275 | $conds + array( 'cl_type' => $type ) + ( $type == 'page' ? array( $pageCondition ) : array() ), |
265 | 276 | __METHOD__, |
266 | 277 | $opts + ( $type == 'page' ? array( 'LIMIT' => $this->limit + 1 ) : array() ), |
— | — | @@ -278,11 +289,11 @@ |
279 | 290 | |
280 | 291 | if ( $title->getNamespace() == NS_CATEGORY ) { |
281 | 292 | $cat = Category::newFromRow( $row, $title ); |
282 | | - $this->addSubcategoryObject( $cat, $row->cl_sortkey, $row->page_len ); |
| 293 | + $this->addSubcategoryObject( $cat, $row->cl_raw_sortkey, $row->page_len ); |
283 | 294 | } elseif ( $this->showGallery && $title->getNamespace() == NS_FILE ) { |
284 | | - $this->addImage( $title, $row->cl_sortkey, $row->page_len, $row->page_is_redirect ); |
| 295 | + $this->addImage( $title, $row->cl_raw_sortkey, $row->page_len, $row->page_is_redirect ); |
285 | 296 | } else { |
286 | | - $this->addPage( $title, $row->cl_sortkey, $row->page_len, $row->page_is_redirect ); |
| 297 | + $this->addPage( $title, $row->cl_raw_sortkey, $row->page_len, $row->page_is_redirect ); |
287 | 298 | } |
288 | 299 | } |
289 | 300 | } |
Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -4474,7 +4474,7 @@ |
4475 | 4475 | * for all rows where cl_collation < $wgCollationVersion and regenerates |
4476 | 4476 | * cl_sortkey based on cl_raw_sortkey. |
4477 | 4477 | */ |
4478 | | -$wgCollationVersion = 0; |
| 4478 | +$wgCollationVersion = 1; |
4479 | 4479 | |
4480 | 4480 | /** @} */ # End categories } |
4481 | 4481 | |
Index: trunk/phase3/languages/Language.php |
— | — | @@ -2945,8 +2945,8 @@ |
2946 | 2946 | * @return string Binary sortkey |
2947 | 2947 | */ |
2948 | 2948 | public function convertToSortkey( $string ) { |
2949 | | - # Stub function for now |
2950 | | - return $string; |
| 2949 | + # Fake function for now |
| 2950 | + return strtoupper( $string ); |
2951 | 2951 | } |
2952 | 2952 | |
2953 | 2953 | /** |
— | — | @@ -2986,6 +2986,6 @@ |
2987 | 2987 | * @return string UTF-8 string corresponding to the first letter of input |
2988 | 2988 | */ |
2989 | 2989 | public function firstLetterForLists( $string ) { |
2990 | | - return mb_substr( $string, 0, 1 ); |
| 2990 | + return strtoupper( mb_substr( $string, 0, 1 ) ); |
2991 | 2991 | } |
2992 | 2992 | } |