Index: branches/wmf/1.17wmf1/extensions/FlaggedRevs/specialpages/UnreviewedPages_body.php |
— | — | @@ -272,6 +272,14 @@ |
273 | 273 | $fields[] = 'cl_sortkey'; |
274 | 274 | $conds['cl_to'] = $this->category; |
275 | 275 | $conds[] = 'cl_from = page_id'; |
| 276 | + # Note: single NS always specified |
| 277 | + if( $this->namespace == NS_FILE ) { |
| 278 | + $conds['cl_type'] = 'file'; |
| 279 | + } elseif( $this->namespace == NS_CATEGORY ) { |
| 280 | + $conds['cl_type'] = 'subcat'; |
| 281 | + } else { |
| 282 | + $conds['cl_type'] = 'page'; |
| 283 | + } |
276 | 284 | $this->mIndexField = 'cl_sortkey'; |
277 | 285 | $useIndex = array( 'categorylinks' => 'cl_sortkey' ); |
278 | 286 | $groupBy = 'cl_sortkey,cl_from'; |
Index: branches/wmf/1.17wmf1/extensions/Collection/Collection.body.php |
— | — | @@ -631,10 +631,10 @@ |
632 | 632 | } |
633 | 633 | $db = wfGetDB( DB_SLAVE ); |
634 | 634 | $tables = array( 'page', 'categorylinks' ); |
635 | | - $fields = array( 'cl_from', 'cl_sortkey', 'page_namespace', 'page_title' ); |
| 635 | + $fields = array( 'page_namespace', 'page_title' ); |
636 | 636 | $options = array( |
637 | 637 | 'USE INDEX' => 'cl_sortkey', |
638 | | - 'ORDER BY' => 'cl_sortkey', |
| 638 | + 'ORDER BY' => 'cl_type, cl_sortkey', |
639 | 639 | 'LIMIT' => $limit + 1, |
640 | 640 | ); |
641 | 641 | $where = array( |
Index: branches/wmf/1.17wmf1/extensions/intersection/DynamicPageList.php |
— | — | @@ -497,7 +497,7 @@ |
498 | 498 | $sSqlSort = 'page_id'; # Since they're never reused and increasing |
499 | 499 | break; |
500 | 500 | case 'categorysortkey': |
501 | | - $sSqlSort = 'c1.cl_sortkey'; |
| 501 | + $sSqlSort = "c1.cl_type $sSqlOrder, c1.cl_sortkey"; |
502 | 502 | break; |
503 | 503 | case 'popularity': |
504 | 504 | $sSqlSort = 'page_counter'; |
Index: branches/wmf/1.17wmf1/extensions/CategoryTree/CategoryTreeFunctions.php |
— | — | @@ -427,7 +427,7 @@ |
428 | 428 | 'cl_from' ); |
429 | 429 | $where = array(); |
430 | 430 | $joins = array(); |
431 | | - $options = array( 'ORDER BY' => 'cl_sortkey', 'LIMIT' => $wgCategoryTreeMaxChildren ); |
| 431 | + $options = array( 'ORDER BY' => 'cl_type, cl_sortkey', 'LIMIT' => $wgCategoryTreeMaxChildren ); |
432 | 432 | |
433 | 433 | if ( $inverse ) { |
434 | 434 | $joins['categorylinks'] = array( 'RIGHT JOIN', 'cl_to = page_title AND page_namespace = ' . NS_CATEGORY ); |
— | — | @@ -443,9 +443,9 @@ |
444 | 444 | $where['page_namespace'] = $namespaces; |
445 | 445 | } elseif ( $mode != CT_MODE_ALL ) { |
446 | 446 | if ( $mode == CT_MODE_PAGES ) { |
447 | | - $where = array_merge( $where, array( 'page_namespace != ' . NS_IMAGE ) ); |
| 447 | + $where['cl_type'] = array( 'page', 'subcat' ); |
448 | 448 | } else { |
449 | | - $where['page_namespace'] = NS_CATEGORY; |
| 449 | + $where['cl_type'] = 'subcat'; |
450 | 450 | } |
451 | 451 | } |
452 | 452 | } |
Index: branches/wmf/1.17wmf1/includes/CategoryPage.php |
— | — | @@ -1,33 +1,41 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * Special handling for category description pages |
5 | | - * Modelled after ImagePage.php |
| 4 | + * Special handling for category description pages. |
| 5 | + * Modelled after ImagePage.php. |
6 | 6 | * |
| 7 | + * @file |
7 | 8 | */ |
8 | 9 | |
9 | 10 | if ( !defined( 'MEDIAWIKI' ) ) |
10 | 11 | die( 1 ); |
11 | 12 | |
12 | 13 | /** |
| 14 | + * Special handling for category description pages, showing pages, |
| 15 | + * subcategories and file that belong to the category |
13 | 16 | */ |
14 | 17 | class CategoryPage extends Article { |
| 18 | + # Subclasses can change this to override the viewer class. |
| 19 | + protected $mCategoryViewerClass = 'CategoryViewer'; |
| 20 | + |
15 | 21 | function view() { |
16 | 22 | global $wgRequest, $wgUser; |
17 | 23 | |
18 | 24 | $diff = $wgRequest->getVal( 'diff' ); |
19 | 25 | $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) ); |
20 | 26 | |
21 | | - if ( isset( $diff ) && $diffOnly ) |
22 | | - return Article::view(); |
| 27 | + if ( isset( $diff ) && $diffOnly ) { |
| 28 | + return parent::view(); |
| 29 | + } |
23 | 30 | |
24 | | - if ( !wfRunHooks( 'CategoryPageView', array( &$this ) ) ) |
| 31 | + if ( !wfRunHooks( 'CategoryPageView', array( &$this ) ) ) { |
25 | 32 | return; |
| 33 | + } |
26 | 34 | |
27 | 35 | if ( NS_CATEGORY == $this->mTitle->getNamespace() ) { |
28 | 36 | $this->openShowCategory(); |
29 | 37 | } |
30 | 38 | |
31 | | - Article::view(); |
| 39 | + parent::view(); |
32 | 40 | |
33 | 41 | if ( NS_CATEGORY == $this->mTitle->getNamespace() ) { |
34 | 42 | $this->closeShowCategory(); |
— | — | @@ -52,10 +60,14 @@ |
53 | 61 | |
54 | 62 | function closeShowCategory() { |
55 | 63 | global $wgOut, $wgRequest; |
56 | | - $from = $wgRequest->getVal( 'from' ); |
57 | | - $until = $wgRequest->getVal( 'until' ); |
58 | 64 | |
59 | | - $viewer = new CategoryViewer( $this->mTitle, $from, $until ); |
| 65 | + $from = $until = array(); |
| 66 | + foreach ( array( 'page', 'subcat', 'file' ) as $type ) { |
| 67 | + $from[$type] = $wgRequest->getVal( "{$type}from" ); |
| 68 | + $until[$type] = $wgRequest->getVal( "{$type}until" ); |
| 69 | + } |
| 70 | + |
| 71 | + $viewer = new $this->mCategoryViewerClass( $this->mTitle, $from, $until, $wgRequest->getValues() ); |
60 | 72 | $wgOut->addHTML( $viewer->getHTML() ); |
61 | 73 | } |
62 | 74 | } |
— | — | @@ -65,27 +77,32 @@ |
66 | 78 | $articles, $articles_start_char, |
67 | 79 | $children, $children_start_char, |
68 | 80 | $showGallery, $gallery, |
69 | | - $skin; |
70 | | - /** Category object for this page */ |
| 81 | + $imgsNoGalley, $imgsNoGallery_start_char, |
| 82 | + $skin, $collation; |
| 83 | + # Category object for this page |
71 | 84 | private $cat; |
| 85 | + # The original query array, to be used in generating paging links. |
| 86 | + private $query; |
72 | 87 | |
73 | | - function __construct( $title, $from = '', $until = '' ) { |
| 88 | + function __construct( $title, $from = '', $until = '', $query = array() ) { |
74 | 89 | global $wgCategoryPagingLimit; |
75 | 90 | $this->title = $title; |
76 | 91 | $this->from = $from; |
77 | 92 | $this->until = $until; |
78 | 93 | $this->limit = $wgCategoryPagingLimit; |
79 | 94 | $this->cat = Category::newFromTitle( $title ); |
| 95 | + $this->query = $query; |
| 96 | + $this->collation = Collation::singleton(); |
| 97 | + unset( $this->query['title'] ); |
80 | 98 | } |
81 | 99 | |
82 | 100 | /** |
83 | 101 | * Format the category data list. |
84 | 102 | * |
85 | 103 | * @return string HTML output |
86 | | - * @private |
87 | 104 | */ |
88 | | - function getHTML() { |
89 | | - global $wgOut, $wgCategoryMagicGallery, $wgCategoryPagingLimit, $wgContLang; |
| 105 | + public function getHTML() { |
| 106 | + global $wgOut, $wgCategoryMagicGallery, $wgContLang; |
90 | 107 | wfProfileIn( __METHOD__ ); |
91 | 108 | |
92 | 109 | $this->showGallery = $wgCategoryMagicGallery && !$wgOut->mNoGallery; |
— | — | @@ -128,6 +145,9 @@ |
129 | 146 | if ( $this->showGallery ) { |
130 | 147 | $this->gallery = new ImageGallery(); |
131 | 148 | $this->gallery->setHideBadImages(); |
| 149 | + } else { |
| 150 | + $this->imgsNoGallery = array(); |
| 151 | + $this->imgsNoGallery_start_char = array(); |
132 | 152 | } |
133 | 153 | } |
134 | 154 | |
— | — | @@ -142,26 +162,29 @@ |
143 | 163 | /** |
144 | 164 | * Add a subcategory to the internal lists, using a Category object |
145 | 165 | */ |
146 | | - function addSubcategoryObject( $cat, $sortkey, $pageLength ) { |
| 166 | + function addSubcategoryObject( Category $cat, $sortkey, $pageLength ) { |
| 167 | + // Subcategory; strip the 'Category' namespace from the link text. |
147 | 168 | $title = $cat->getTitle(); |
148 | | - $this->addSubcategory( $title, $sortkey, $pageLength ); |
| 169 | + |
| 170 | + $link = $this->getSkin()->link( $title, $title->getText() ); |
| 171 | + if ( $title->isRedirect() ) { |
| 172 | + // This didn't used to add redirect-in-category, but might |
| 173 | + // as well be consistent with the rest of the sections |
| 174 | + // on a category page. |
| 175 | + $link = '<span class="redirect-in-category">' . $link . '</span>'; |
| 176 | + } |
| 177 | + $this->children[] = $link; |
| 178 | + |
| 179 | + $this->children_start_char[] = |
| 180 | + $this->getSubcategorySortChar( $cat->getTitle(), $sortkey ); |
149 | 181 | } |
150 | 182 | |
151 | 183 | /** |
152 | 184 | * Add a subcategory to the internal lists, using a title object |
153 | 185 | * @deprecated kept for compatibility, please use addSubcategoryObject instead |
154 | 186 | */ |
155 | | - function addSubcategory( $title, $sortkey, $pageLength ) { |
156 | | - // Subcategory; strip the 'Category' namespace from the link text. |
157 | | - $this->children[] = $this->getSkin()->link( |
158 | | - $title, |
159 | | - null, |
160 | | - array(), |
161 | | - array(), |
162 | | - array( 'known', 'noclasses' ) |
163 | | - ); |
164 | | - |
165 | | - $this->children_start_char[] = $this->getSubcategorySortChar( $title, $sortkey ); |
| 187 | + function addSubcategory( Title $title, $sortkey, $pageLength ) { |
| 188 | + $this->addSubcategoryObject( Category::newFromTitle( $title ), $sortkey, $pageLength ); |
166 | 189 | } |
167 | 190 | |
168 | 191 | /** |
— | — | @@ -175,11 +198,13 @@ |
176 | 199 | global $wgContLang; |
177 | 200 | |
178 | 201 | if ( $title->getPrefixedText() == $sortkey ) { |
179 | | - $firstChar = $wgContLang->firstChar( $title->getDBkey() ); |
| 202 | + $word = $title->getDBkey(); |
180 | 203 | } else { |
181 | | - $firstChar = $wgContLang->firstChar( $sortkey ); |
| 204 | + $word = $sortkey; |
182 | 205 | } |
183 | 206 | |
| 207 | + $firstChar = $this->collation->getFirstLetter( $word ); |
| 208 | + |
184 | 209 | return $wgContLang->convert( $firstChar ); |
185 | 210 | } |
186 | 211 | |
— | — | @@ -187,14 +212,25 @@ |
188 | 213 | * Add a page in the image namespace |
189 | 214 | */ |
190 | 215 | function addImage( Title $title, $sortkey, $pageLength, $isRedirect = false ) { |
| 216 | + global $wgContLang; |
191 | 217 | if ( $this->showGallery ) { |
192 | | - if ( $this->flip ) { |
| 218 | + $flip = $this->flip['file']; |
| 219 | + if ( $flip ) { |
193 | 220 | $this->gallery->insert( $title ); |
194 | 221 | } else { |
195 | 222 | $this->gallery->add( $title ); |
196 | 223 | } |
197 | 224 | } else { |
198 | | - $this->addPage( $title, $sortkey, $pageLength, $isRedirect ); |
| 225 | + $link = $this->getSkin()->link( $title ); |
| 226 | + if ( $isRedirect ) { |
| 227 | + // This seems kind of pointless given 'mw-redirect' class, |
| 228 | + // but keeping for back-compatibility with user css. |
| 229 | + $link = '<span class="redirect-in-category">' . $link . '</span>'; |
| 230 | + } |
| 231 | + $this->imgsNoGallery[] = $link; |
| 232 | + |
| 233 | + $this->imgsNoGallery_start_char[] = $wgContLang->convert( |
| 234 | + $this->collation->getFirstLetter( $sortkey ) ); |
199 | 235 | } |
200 | 236 | } |
201 | 237 | |
— | — | @@ -203,74 +239,96 @@ |
204 | 240 | */ |
205 | 241 | function addPage( $title, $sortkey, $pageLength, $isRedirect = false ) { |
206 | 242 | global $wgContLang; |
207 | | - $this->articles[] = $isRedirect |
208 | | - ? '<span class="redirect-in-category">' . |
209 | | - $this->getSkin()->link( |
210 | | - $title, |
211 | | - null, |
212 | | - array(), |
213 | | - array(), |
214 | | - array( 'known', 'noclasses' ) |
215 | | - ) . '</span>' |
216 | | - : $this->getSkin()->makeSizeLinkObj( $pageLength, $title ); |
217 | | - $this->articles_start_char[] = $wgContLang->convert( $wgContLang->firstChar( $sortkey ) ); |
| 243 | + |
| 244 | + $link = $this->getSkin()->link( $title ); |
| 245 | + if ( $isRedirect ) { |
| 246 | + // This seems kind of pointless given 'mw-redirect' class, |
| 247 | + // but keeping for back-compatiability with user css. |
| 248 | + $link = '<span class="redirect-in-category">' . $link . '</span>'; |
| 249 | + } |
| 250 | + $this->articles[] = $link; |
| 251 | + |
| 252 | + $this->articles_start_char[] = $wgContLang->convert( |
| 253 | + $this->collation->getFirstLetter( $sortkey ) ); |
218 | 254 | } |
219 | 255 | |
220 | 256 | function finaliseCategoryState() { |
221 | | - if ( $this->flip ) { |
| 257 | + if ( $this->flip['subcat'] ) { |
222 | 258 | $this->children = array_reverse( $this->children ); |
223 | 259 | $this->children_start_char = array_reverse( $this->children_start_char ); |
| 260 | + } |
| 261 | + if ( $this->flip['page'] ) { |
224 | 262 | $this->articles = array_reverse( $this->articles ); |
225 | 263 | $this->articles_start_char = array_reverse( $this->articles_start_char ); |
226 | 264 | } |
| 265 | + if ( !$this->showGallery && $this->flip['file'] ) { |
| 266 | + $this->imgsNoGallery = array_reverse( $this->imgsNoGallery ); |
| 267 | + $this->imgsNoGallery_start_char = array_reverse( $this->imgsNoGallery_start_char ); |
| 268 | + } |
227 | 269 | } |
228 | 270 | |
229 | 271 | function doCategoryQuery() { |
230 | 272 | $dbr = wfGetDB( DB_SLAVE, 'category' ); |
231 | | - if ( $this->from != '' ) { |
232 | | - $pageCondition = 'cl_sortkey >= ' . $dbr->addQuotes( $this->from ); |
233 | | - $this->flip = false; |
234 | | - } elseif ( $this->until != '' ) { |
235 | | - $pageCondition = 'cl_sortkey < ' . $dbr->addQuotes( $this->until ); |
236 | | - $this->flip = true; |
237 | | - } else { |
238 | | - $pageCondition = '1 = 1'; |
239 | | - $this->flip = false; |
240 | | - } |
241 | 273 | |
242 | | - $res = $dbr->select( |
243 | | - array( 'page', 'categorylinks', 'category' ), |
244 | | - array( 'page_title', 'page_namespace', 'page_len', 'page_is_redirect', 'cl_sortkey', |
245 | | - 'cat_id', 'cat_title', 'cat_subcats', 'cat_pages', 'cat_files' ), |
246 | | - array( $pageCondition, 'cl_to' => $this->title->getDBkey() ), |
247 | | - __METHOD__, |
248 | | - array( 'ORDER BY' => $this->flip ? 'cl_sortkey DESC' : 'cl_sortkey', |
249 | | - 'USE INDEX' => array( 'categorylinks' => 'cl_sortkey' ), |
250 | | - 'LIMIT' => $this->limit + 1 ), |
251 | | - array( 'categorylinks' => array( 'INNER JOIN', 'cl_from = page_id' ), |
252 | | - 'category' => array( 'LEFT JOIN', 'cat_title = page_title AND page_namespace = ' . NS_CATEGORY ) ) |
| 274 | + $this->nextPage = array( |
| 275 | + 'page' => null, |
| 276 | + 'subcat' => null, |
| 277 | + 'file' => null, |
253 | 278 | ); |
| 279 | + $this->flip = array( 'page' => false, 'subcat' => false, 'file' => false ); |
254 | 280 | |
255 | | - $count = 0; |
256 | | - $this->nextPage = null; |
257 | | - |
258 | | - while ( $x = $dbr->fetchObject ( $res ) ) { |
259 | | - if ( ++$count > $this->limit ) { |
260 | | - // We've reached the one extra which shows that there are |
261 | | - // additional pages to be had. Stop here... |
262 | | - $this->nextPage = $x->cl_sortkey; |
263 | | - break; |
| 281 | + foreach ( array( 'page', 'subcat', 'file' ) as $type ) { |
| 282 | + # Get the sortkeys for start/end, if applicable. Note that if |
| 283 | + # the collation in the database differs from the one |
| 284 | + # set in $wgCategoryCollation, pagination might go totally haywire. |
| 285 | + $extraConds = array( 'cl_type' => $type ); |
| 286 | + if ( $this->from[$type] !== null ) { |
| 287 | + $extraConds[] = 'cl_sortkey >= ' |
| 288 | + . $dbr->addQuotes( $this->collation->getSortKey( $this->from[$type] ) ); |
| 289 | + } elseif ( $this->until[$type] !== null ) { |
| 290 | + $extraConds[] = 'cl_sortkey < ' |
| 291 | + . $dbr->addQuotes( $this->collation->getSortKey( $this->until[$type] ) ); |
| 292 | + $this->flip[$type] = true; |
264 | 293 | } |
265 | 294 | |
266 | | - $title = Title::makeTitle( $x->page_namespace, $x->page_title ); |
| 295 | + $res = $dbr->select( |
| 296 | + array( 'page', 'categorylinks', 'category' ), |
| 297 | + array( 'page_id', 'page_title', 'page_namespace', 'page_len', |
| 298 | + 'page_is_redirect', 'cl_sortkey', 'cat_id', 'cat_title', |
| 299 | + 'cat_subcats', 'cat_pages', 'cat_files', 'cl_sortkey_prefix' ), |
| 300 | + array( 'cl_to' => $this->title->getDBkey() ) + $extraConds, |
| 301 | + __METHOD__, |
| 302 | + array( |
| 303 | + 'USE INDEX' => array( 'categorylinks' => 'cl_sortkey' ), |
| 304 | + 'LIMIT' => $this->limit + 1, |
| 305 | + 'ORDER BY' => $this->flip[$type] ? 'cl_sortkey DESC' : 'cl_sortkey', |
| 306 | + ), |
| 307 | + array( |
| 308 | + 'categorylinks' => array( 'INNER JOIN', 'cl_from = page_id' ), |
| 309 | + 'category' => array( 'LEFT JOIN', 'cat_title = page_title AND page_namespace = ' . NS_CATEGORY ) |
| 310 | + ) |
| 311 | + ); |
267 | 312 | |
268 | | - if ( $title->getNamespace() == NS_CATEGORY ) { |
269 | | - $cat = Category::newFromRow( $x, $title ); |
270 | | - $this->addSubcategoryObject( $cat, $x->cl_sortkey, $x->page_len ); |
271 | | - } elseif ( $this->showGallery && $title->getNamespace() == NS_FILE ) { |
272 | | - $this->addImage( $title, $x->cl_sortkey, $x->page_len, $x->page_is_redirect ); |
273 | | - } else { |
274 | | - $this->addPage( $title, $x->cl_sortkey, $x->page_len, $x->page_is_redirect ); |
| 313 | + $count = 0; |
| 314 | + foreach ( $res as $row ) { |
| 315 | + $title = Title::newFromRow( $row ); |
| 316 | + $rawSortkey = $title->getCategorySortkey( $row->cl_sortkey_prefix ); |
| 317 | + |
| 318 | + if ( ++$count > $this->limit ) { |
| 319 | + # We've reached the one extra which shows that there |
| 320 | + # are additional pages to be had. Stop here... |
| 321 | + $this->nextPage[$type] = $rawSortkey; |
| 322 | + break; |
| 323 | + } |
| 324 | + |
| 325 | + if ( $title->getNamespace() == NS_CATEGORY ) { |
| 326 | + $cat = Category::newFromRow( $row, $title ); |
| 327 | + $this->addSubcategoryObject( $cat, $rawSortkey, $row->page_len ); |
| 328 | + } elseif ( $title->getNamespace() == NS_FILE ) { |
| 329 | + $this->addImage( $title, $rawSortkey, $row->page_len, $row->page_is_redirect ); |
| 330 | + } else { |
| 331 | + $this->addPage( $title, $rawSortkey, $row->page_len, $row->page_is_redirect ); |
| 332 | + } |
275 | 333 | } |
276 | 334 | } |
277 | 335 | } |
— | — | @@ -294,7 +352,9 @@ |
295 | 353 | $r .= "<div id=\"mw-subcategories\">\n"; |
296 | 354 | $r .= '<h2>' . wfMsg( 'subcategories' ) . "</h2>\n"; |
297 | 355 | $r .= $countmsg; |
| 356 | + $r .= $this->getSectionPagingLinks( 'subcat' ); |
298 | 357 | $r .= $this->formatList( $this->children, $this->children_start_char ); |
| 358 | + $r .= $this->getSectionPagingLinks( 'subcat' ); |
299 | 359 | $r .= "\n</div>"; |
300 | 360 | } |
301 | 361 | return $r; |
— | — | @@ -318,36 +378,57 @@ |
319 | 379 | $r = "<div id=\"mw-pages\">\n"; |
320 | 380 | $r .= '<h2>' . wfMsg( 'category_header', $ti ) . "</h2>\n"; |
321 | 381 | $r .= $countmsg; |
| 382 | + $r .= $this->getSectionPagingLinks( 'page' ); |
322 | 383 | $r .= $this->formatList( $this->articles, $this->articles_start_char ); |
| 384 | + $r .= $this->getSectionPagingLinks( 'page' ); |
323 | 385 | $r .= "\n</div>"; |
324 | 386 | } |
325 | 387 | return $r; |
326 | 388 | } |
327 | 389 | |
328 | 390 | function getImageSection() { |
329 | | - if ( $this->showGallery && ! $this->gallery->isEmpty() ) { |
| 391 | + $r = ''; |
| 392 | + $rescnt = $this->showGallery ? $this->gallery->count() : count( $this->imgsNoGallery ); |
| 393 | + if ( $rescnt > 0 ) { |
330 | 394 | $dbcnt = $this->cat->getFileCount(); |
331 | | - $rescnt = $this->gallery->count(); |
332 | 395 | $countmsg = $this->getCountMessage( $rescnt, $dbcnt, 'file' ); |
333 | 396 | |
334 | | - return "<div id=\"mw-category-media\">\n" . |
335 | | - '<h2>' . wfMsg( 'category-media-header', htmlspecialchars( $this->title->getText() ) ) . "</h2>\n" . |
336 | | - $countmsg . $this->gallery->toHTML() . "\n</div>"; |
337 | | - } else { |
338 | | - return ''; |
| 397 | + $r .= "<div id=\"mw-category-media\">\n"; |
| 398 | + $r .= '<h2>' . wfMsg( 'category-media-header', htmlspecialchars( $this->title->getText() ) ) . "</h2>\n"; |
| 399 | + $r .= $countmsg; |
| 400 | + $r .= $this->getSectionPagingLinks( 'file' ); |
| 401 | + if ( $this->showGallery ) { |
| 402 | + $r .= $this->gallery->toHTML(); |
| 403 | + } else { |
| 404 | + $r .= $this->formatList( $this->imgsNoGallery, $this->imgsNoGallery_start_char ); |
| 405 | + } |
| 406 | + $r .= $this->getSectionPagingLinks( 'file' ); |
| 407 | + $r .= "\n</div>"; |
339 | 408 | } |
| 409 | + return $r; |
340 | 410 | } |
341 | 411 | |
342 | | - function getCategoryBottom() { |
343 | | - if ( $this->until != '' ) { |
344 | | - return $this->pagingLinks( $this->title, $this->nextPage, $this->until, $this->limit ); |
345 | | - } elseif ( $this->nextPage != '' || $this->from != '' ) { |
346 | | - return $this->pagingLinks( $this->title, $this->from, $this->nextPage, $this->limit ); |
| 412 | + /** |
| 413 | + * Get the paging links for a section (subcats/pages/files), to go at the top and bottom |
| 414 | + * of the output. |
| 415 | + * |
| 416 | + * @param $type String: 'page', 'subcat', or 'file' |
| 417 | + * @return String: HTML output, possibly empty if there are no other pages |
| 418 | + */ |
| 419 | + private function getSectionPagingLinks( $type ) { |
| 420 | + if ( $this->until[$type] !== null ) { |
| 421 | + return $this->pagingLinks( $this->nextPage[$type], $this->until[$type], $type ); |
| 422 | + } elseif ( $this->nextPage[$type] !== null || $this->from[$type] !== null ) { |
| 423 | + return $this->pagingLinks( $this->from[$type], $this->nextPage[$type], $type ); |
347 | 424 | } else { |
348 | 425 | return ''; |
349 | 426 | } |
350 | 427 | } |
351 | 428 | |
| 429 | + function getCategoryBottom() { |
| 430 | + return ''; |
| 431 | + } |
| 432 | + |
352 | 433 | /** |
353 | 434 | * Format a list of articles chunked by letter, either as a |
354 | 435 | * bullet list or a columnar format, depending on the length. |
— | — | @@ -360,10 +441,10 @@ |
361 | 442 | */ |
362 | 443 | function formatList( $articles, $articles_start_char, $cutoff = 6 ) { |
363 | 444 | if ( count ( $articles ) > $cutoff ) { |
364 | | - return $this->columnList( $articles, $articles_start_char ); |
| 445 | + return self::columnList( $articles, $articles_start_char ); |
365 | 446 | } elseif ( count( $articles ) > 0 ) { |
366 | 447 | // for short lists of articles in categories. |
367 | | - return $this->shortList( $articles, $articles_start_char ); |
| 448 | + return self::shortList( $articles, $articles_start_char ); |
368 | 449 | } |
369 | 450 | return ''; |
370 | 451 | } |
— | — | @@ -383,7 +464,7 @@ |
384 | 465 | * @return String |
385 | 466 | * @private |
386 | 467 | */ |
387 | | - function columnList( $articles, $articles_start_char ) { |
| 468 | + static function columnList( $articles, $articles_start_char ) { |
388 | 469 | $columns = array_combine( $articles, $articles_start_char ); |
389 | 470 | # Split into three columns |
390 | 471 | $columns = array_chunk( $columns, ceil( count( $columns ) / 3 ), true /* preserve keys */ ); |
— | — | @@ -435,7 +516,7 @@ |
436 | 517 | * @return String |
437 | 518 | * @private |
438 | 519 | */ |
439 | | - function shortList( $articles, $articles_start_char ) { |
| 520 | + static function shortList( $articles, $articles_start_char ) { |
440 | 521 | $r = '<h3>' . htmlspecialchars( $articles_start_char[0] ) . "</h3>\n"; |
441 | 522 | $r .= '<ul><li>' . $articles[0] . '</li>'; |
442 | 523 | for ( $index = 1; $index < count( $articles ); $index++ ) |
— | — | @@ -452,26 +533,27 @@ |
453 | 534 | } |
454 | 535 | |
455 | 536 | /** |
456 | | - * @param $title Title object |
457 | | - * @param $first String |
458 | | - * @param $last String |
459 | | - * @param $limit Int |
460 | | - * @param $query Array: additional query options to pass |
461 | | - * @return String |
462 | | - * @private |
| 537 | + * Create paging links, as a helper method to getSectionPagingLinks(). |
| 538 | + * |
| 539 | + * @param $first String The 'until' parameter for the generated URL |
| 540 | + * @param $last String The 'from' parameter for the genererated URL |
| 541 | + * @param $type String A prefix for parameters, 'page' or 'subcat' or |
| 542 | + * 'file' |
| 543 | + * @return String HTML |
463 | 544 | */ |
464 | | - function pagingLinks( $title, $first, $last, $limit, $query = array() ) { |
| 545 | + private function pagingLinks( $first, $last, $type = '' ) { |
465 | 546 | global $wgLang; |
466 | 547 | $sk = $this->getSkin(); |
467 | | - $limitText = $wgLang->formatNum( $limit ); |
| 548 | + $limitText = $wgLang->formatNum( $this->limit ); |
468 | 549 | |
469 | 550 | $prevLink = wfMsgExt( 'prevn', array( 'escape', 'parsemag' ), $limitText ); |
470 | 551 | |
471 | 552 | if ( $first != '' ) { |
472 | | - $prevQuery = $query; |
473 | | - $prevQuery['until'] = $first; |
| 553 | + $prevQuery = $this->query; |
| 554 | + $prevQuery["{$type}until"] = $first; |
| 555 | + unset( $prevQuery["{$type}from"] ); |
474 | 556 | $prevLink = $sk->linkKnown( |
475 | | - $title, |
| 557 | + $this->title, |
476 | 558 | $prevLink, |
477 | 559 | array(), |
478 | 560 | $prevQuery |
— | — | @@ -481,10 +563,11 @@ |
482 | 564 | $nextLink = wfMsgExt( 'nextn', array( 'escape', 'parsemag' ), $limitText ); |
483 | 565 | |
484 | 566 | if ( $last != '' ) { |
485 | | - $lastQuery = $query; |
486 | | - $lastQuery['from'] = $last; |
| 567 | + $lastQuery = $this->query; |
| 568 | + $lastQuery["{$type}from"] = $last; |
| 569 | + unset( $lastQuery["{$type}until"] ); |
487 | 570 | $nextLink = $sk->linkKnown( |
488 | | - $title, |
| 571 | + $this->title, |
489 | 572 | $nextLink, |
490 | 573 | array(), |
491 | 574 | $lastQuery |
— | — | @@ -496,8 +579,8 @@ |
497 | 580 | |
498 | 581 | /** |
499 | 582 | * What to do if the category table conflicts with the number of results |
500 | | - * returned? This function says what. It works the same whether the |
501 | | - * things being counted are articles, subcategories, or files. |
| 583 | + * returned? This function says what. Each type is considered independantly |
| 584 | + * of the other types. |
502 | 585 | * |
503 | 586 | * Note for grepping: uses the messages category-article-count, |
504 | 587 | * category-article-count-limited, category-subcat-count, |
— | — | @@ -520,15 +603,28 @@ |
521 | 604 | # than $this->limit and there's no offset. In this case we still |
522 | 605 | # know the right figure. |
523 | 606 | # 3) We have no idea. |
524 | | - $totalrescnt = count( $this->articles ) + count( $this->children ) + |
525 | | - ( $this->showGallery ? $this->gallery->count() : 0 ); |
526 | 607 | |
527 | | - if ( $dbcnt == $rescnt || ( ( $totalrescnt == $this->limit || $this->from |
528 | | - || $this->until ) && $dbcnt > $rescnt ) ) |
| 608 | + # Check if there's a "from" or "until" for anything |
| 609 | + |
| 610 | + // This is a little ugly, but we seem to use different names |
| 611 | + // for the paging types then for the messages. |
| 612 | + if ( $type === 'article' ) { |
| 613 | + $pagingType = 'page'; |
| 614 | + } else { |
| 615 | + $pagingType = $type; |
| 616 | + } |
| 617 | + |
| 618 | + $fromOrUntil = false; |
| 619 | + if ( $this->from[$pagingType] !== null || $this->until[$pagingType] !== null ) { |
| 620 | + $fromOrUntil = true; |
| 621 | + } |
| 622 | + |
| 623 | + if ( $dbcnt == $rescnt || ( ( $rescnt == $this->limit || $fromOrUntil ) |
| 624 | + && $dbcnt > $rescnt ) ) |
529 | 625 | { |
530 | 626 | # Case 1: seems sane. |
531 | 627 | $totalcnt = $dbcnt; |
532 | | - } elseif ( $totalrescnt < $this->limit && !$this->from && !$this->until ) { |
| 628 | + } elseif ( $rescnt < $this->limit && !$fromOrUntil ) { |
533 | 629 | # Case 2: not sane, but salvageable. Use the number of results. |
534 | 630 | # Since there are fewer than 200, we can also take this opportunity |
535 | 631 | # to refresh the incorrect category table entry -- which should be |
Index: branches/wmf/1.17wmf1/includes/parser/Parser.php |
— | — | @@ -5001,15 +5001,19 @@ |
5002 | 5002 | |
5003 | 5003 | /** |
5004 | 5004 | * Accessor for $mDefaultSort |
5005 | | - * Will use the title/prefixed title if none is set |
| 5005 | + * Will use the empty string if none is set. |
5006 | 5006 | * |
| 5007 | + * This value is treated as a prefix, so the |
| 5008 | + * empty string is equivalent to sorting by |
| 5009 | + * page name. |
| 5010 | + * |
5007 | 5011 | * @return string |
5008 | 5012 | */ |
5009 | 5013 | public function getDefaultSort() { |
5010 | 5014 | if ( $this->mDefaultSort !== false ) { |
5011 | 5015 | return $this->mDefaultSort; |
5012 | 5016 | } else { |
5013 | | - return $this->mTitle->getCategorySortkey(); |
| 5017 | + return ''; |
5014 | 5018 | } |
5015 | 5019 | } |
5016 | 5020 | |
Property changes on: branches/wmf/1.17wmf1/includes/parser/Parser.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
5017 | 5021 | Merged /trunk/phase3/includes/parser/Parser.php:r81554 |
Index: branches/wmf/1.17wmf1/includes/api/ApiQueryCategoryMembers.php |
— | — | @@ -65,28 +65,28 @@ |
66 | 66 | $fld_ids = isset( $prop['ids'] ); |
67 | 67 | $fld_title = isset( $prop['title'] ); |
68 | 68 | $fld_sortkey = isset( $prop['sortkey'] ); |
| 69 | + $fld_sortkeyprefix = isset( $prop['sortkeyprefix'] ); |
69 | 70 | $fld_timestamp = isset( $prop['timestamp'] ); |
| 71 | + $fld_type = isset( $prop['type'] ); |
70 | 72 | |
71 | 73 | if ( is_null( $resultPageSet ) ) { |
72 | | - $this->addFields( array( 'cl_from', 'cl_sortkey', 'page_namespace', 'page_title' ) ); |
| 74 | + $this->addFields( array( 'cl_from', 'page_namespace', 'page_title' ) ); |
73 | 75 | $this->addFieldsIf( 'page_id', $fld_ids ); |
| 76 | + $this->addFieldsIf( 'cl_sortkey_prefix', $fld_sortkeyprefix ); |
| 77 | + $this->addFieldsIf( 'cl_sortkey', $fld_sortkey ); |
74 | 78 | } else { |
75 | 79 | $this->addFields( $resultPageSet->getPageTableFields() ); // will include page_ id, ns, title |
76 | 80 | $this->addFields( array( 'cl_from', 'cl_sortkey' ) ); |
77 | 81 | } |
78 | 82 | |
79 | 83 | $this->addFieldsIf( 'cl_timestamp', $fld_timestamp || $params['sort'] == 'timestamp' ); |
| 84 | + $this->addFieldsIf( 'cl_type', $fld_type ); |
| 85 | + |
80 | 86 | $this->addTables( array( 'page', 'categorylinks' ) ); // must be in this order for 'USE INDEX' |
81 | | - // Not needed after bug 10280 is applied to servers |
82 | | - if ( $params['sort'] == 'timestamp' ) { |
83 | | - $this->addOption( 'USE INDEX', 'cl_timestamp' ); |
84 | | - } else { |
85 | | - $this->addOption( 'USE INDEX', 'cl_sortkey' ); |
86 | | - } |
87 | 87 | |
88 | | - $this->addWhere( 'cl_from=page_id' ); |
89 | | - $this->setContinuation( $params['continue'], $params['dir'] ); |
90 | 88 | $this->addWhereFld( 'cl_to', $categoryTitle->getDBkey() ); |
| 89 | + $this->addWhereFld( 'cl_type', $params['type'] ); |
| 90 | + |
91 | 91 | // Scanning large datasets for rare categories sucks, and I already told |
92 | 92 | // how to have efficient subcategory access :-) ~~~~ (oh well, domas) |
93 | 93 | global $wgMiserMode; |
— | — | @@ -96,18 +96,35 @@ |
97 | 97 | } else { |
98 | 98 | $this->addWhereFld( 'page_namespace', $params['namespace'] ); |
99 | 99 | } |
| 100 | + |
| 101 | + $dir = $params['dir'] == 'asc' ? 'newer' : 'older'; |
| 102 | + |
100 | 103 | if ( $params['sort'] == 'timestamp' ) { |
101 | | - $this->addWhereRange( 'cl_timestamp', ( $params['dir'] == 'asc' ? 'newer' : 'older' ), $params['start'], $params['end'] ); |
| 104 | + $this->addWhereRange( 'cl_timestamp', |
| 105 | + $dir, |
| 106 | + $params['start'], |
| 107 | + $params['end'] ); |
| 108 | + |
| 109 | + $this->addOption( 'USE INDEX', 'cl_timestamp' ); |
102 | 110 | } else { |
103 | | - $this->addWhereRange( 'cl_sortkey', ( $params['dir'] == 'asc' ? 'newer' : 'older' ), $params['startsortkey'], $params['endsortkey'] ); |
104 | | - $this->addWhereRange( 'cl_from', ( $params['dir'] == 'asc' ? 'newer' : 'older' ), null, null ); |
| 111 | + // The below produces ORDER BY cl_type, cl_sortkey, cl_from, possibly with DESC added to each of them |
| 112 | + $this->addWhereRange( 'cl_type', $dir, null, null ); |
| 113 | + $this->addWhereRange( 'cl_sortkey', |
| 114 | + $dir, |
| 115 | + $params['startsortkey'], |
| 116 | + $params['endsortkey'] ); |
| 117 | + $this->addWhereRange( 'cl_from', $dir, null, null ); |
| 118 | + $this->addOption( 'USE INDEX', 'cl_sortkey' ); |
105 | 119 | } |
106 | 120 | |
| 121 | + $this->setContinuation( $params['continue'], $params['dir'] ); |
| 122 | + |
| 123 | + $this->addWhere( 'cl_from=page_id' ); |
| 124 | + |
107 | 125 | $limit = $params['limit']; |
108 | 126 | $this->addOption( 'LIMIT', $limit + 1 ); |
109 | 127 | |
110 | 128 | $count = 0; |
111 | | - $lastSortKey = null; |
112 | 129 | $res = $this->select( __METHOD__ ); |
113 | 130 | foreach ( $res as $row ) { |
114 | 131 | if ( ++ $count > $limit ) { |
— | — | @@ -116,7 +133,7 @@ |
117 | 134 | if ( $params['sort'] == 'timestamp' ) { |
118 | 135 | $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->cl_timestamp ) ); |
119 | 136 | } else { |
120 | | - $this->setContinueEnumParameter( 'continue', $this->getContinueStr( $row, $lastSortKey ) ); |
| 137 | + $this->setContinueEnumParameter( 'continue', $row->cl_from ); |
121 | 138 | } |
122 | 139 | break; |
123 | 140 | } |
— | — | @@ -141,6 +158,12 @@ |
142 | 159 | if ( $fld_sortkey ) { |
143 | 160 | $vals['sortkey'] = $row->cl_sortkey; |
144 | 161 | } |
| 162 | + if ( $fld_sortkeyprefix ) { |
| 163 | + $vals['sortkeyprefix'] = $row->cl_sortkey_prefix; |
| 164 | + } |
| 165 | + if ( $fld_type ) { |
| 166 | + $vals['type'] = $row->cl_type; |
| 167 | + } |
145 | 168 | if ( $fld_timestamp ) { |
146 | 169 | $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->cl_timestamp ); |
147 | 170 | } |
— | — | @@ -150,14 +173,13 @@ |
151 | 174 | if ( $params['sort'] == 'timestamp' ) { |
152 | 175 | $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->cl_timestamp ) ); |
153 | 176 | } else { |
154 | | - $this->setContinueEnumParameter( 'continue', $this->getContinueStr( $row, $lastSortKey ) ); |
| 177 | + $this->setContinueEnumParameter( 'continue', $row->cl_from ); |
155 | 178 | } |
156 | 179 | break; |
157 | 180 | } |
158 | 181 | } else { |
159 | 182 | $resultPageSet->processDbRow( $row ); |
160 | 183 | } |
161 | | - $lastSortKey = $row->cl_sortkey; // detect duplicate sortkeys |
162 | 184 | } |
163 | 185 | |
164 | 186 | if ( is_null( $resultPageSet ) ) { |
— | — | @@ -166,14 +188,6 @@ |
167 | 189 | } |
168 | 190 | } |
169 | 191 | |
170 | | - private function getContinueStr( $row, $lastSortKey ) { |
171 | | - $ret = $row->cl_sortkey . '|'; |
172 | | - if ( $row->cl_sortkey == $lastSortKey ) { // duplicate sort key, add cl_from |
173 | | - $ret .= $row->cl_from; |
174 | | - } |
175 | | - return $ret; |
176 | | - } |
177 | | - |
178 | 192 | /** |
179 | 193 | * Add DB WHERE clause to continue previous query based on 'continue' parameter |
180 | 194 | */ |
— | — | @@ -182,26 +196,11 @@ |
183 | 197 | return; // This is not a continuation request |
184 | 198 | } |
185 | 199 | |
186 | | - $pos = strrpos( $continue, '|' ); |
187 | | - $sortkey = substr( $continue, 0, $pos ); |
188 | | - $fromstr = substr( $continue, $pos + 1 ); |
189 | | - $from = intval( $fromstr ); |
| 200 | + $encFrom = $this->getDB()->addQuotes( intval( $continue ) ); |
190 | 201 | |
191 | | - if ( $from == 0 && strlen( $fromstr ) > 0 ) { |
192 | | - $this->dieUsage( 'Invalid continue param. You should pass the original value returned by the previous query', 'badcontinue' ); |
193 | | - } |
| 202 | + $op = ( $dir == 'desc' ? '<=' : '>=' ); |
194 | 203 | |
195 | | - $encSortKey = $this->getDB()->addQuotes( $sortkey ); |
196 | | - $encFrom = $this->getDB()->addQuotes( $from ); |
197 | | - |
198 | | - $op = ( $dir == 'desc' ? '<' : '>' ); |
199 | | - |
200 | | - if ( $from != 0 ) { |
201 | | - // Duplicate sort key continue |
202 | | - $this->addWhere( "cl_sortkey$op$encSortKey OR (cl_sortkey=$encSortKey AND cl_from$op=$encFrom)" ); |
203 | | - } else { |
204 | | - $this->addWhere( "cl_sortkey$op=$encSortKey" ); |
205 | | - } |
| 204 | + $this->addWhere( "cl_from $op $encFrom" ); |
206 | 205 | } |
207 | 206 | |
208 | 207 | public function getAllowedParams() { |
— | — | @@ -217,6 +216,8 @@ |
218 | 217 | 'ids', |
219 | 218 | 'title', |
220 | 219 | 'sortkey', |
| 220 | + 'sortkeyprefix', |
| 221 | + 'type', |
221 | 222 | 'timestamp', |
222 | 223 | ) |
223 | 224 | ), |
— | — | @@ -224,6 +225,15 @@ |
225 | 226 | ApiBase::PARAM_ISMULTI => true, |
226 | 227 | ApiBase::PARAM_TYPE => 'namespace', |
227 | 228 | ), |
| 229 | + 'type' => array( |
| 230 | + ApiBase::PARAM_ISMULTI => true, |
| 231 | + ApiBase::PARAM_DFLT => 'page|subcat|file', |
| 232 | + ApiBase::PARAM_TYPE => array( |
| 233 | + 'page', |
| 234 | + 'subcat', |
| 235 | + 'file' |
| 236 | + ) |
| 237 | + ), |
228 | 238 | 'continue' => null, |
229 | 239 | 'limit' => array( |
230 | 240 | ApiBase::PARAM_TYPE => 'limit', |
— | — | @@ -264,12 +274,15 @@ |
265 | 275 | 'title' => 'Which category to enumerate (required). Must include Category: prefix', |
266 | 276 | 'prop' => array( |
267 | 277 | 'What pieces of information to include', |
268 | | - ' ids - Adds the page id', |
269 | | - ' title - Adds the title and namespace id of the page', |
270 | | - ' sortkey - Adds the sortkey used for the category', |
271 | | - ' timestamp - Adds the timestamp of when the page was included', |
| 278 | + ' ids - Adds the page ID', |
| 279 | + ' title - Adds the title and namespace ID of the page', |
| 280 | + ' sortkey - Adds the sortkey used for sorting in the category (may not be human-readble)', |
| 281 | + ' sortkeyprefix - Adds the sortkey prefix used for sorting in the category (human-readable part of the sortkey)', |
| 282 | + ' type - Adds the type that the page has been categorised as (page, subcat or file)', |
| 283 | + ' timestamp - Adds the timestamp of when the page was included', |
272 | 284 | ), |
273 | 285 | 'namespace' => 'Only include pages in these namespaces', |
| 286 | + 'type' => 'What type of category members to include', |
274 | 287 | 'sort' => 'Property to sort by', |
275 | 288 | 'dir' => 'In which direction to sort', |
276 | 289 | 'start' => "Timestamp to start listing from. Can only be used with {$p}sort=timestamp", |
Index: branches/wmf/1.17wmf1/includes/LinksUpdate.php |
— | — | @@ -72,7 +72,10 @@ |
73 | 73 | # it truncated by DB, and then doesn't get |
74 | 74 | # matched when comparing existing vs current |
75 | 75 | # categories, causing bug 25254. |
76 | | - $sortkey = substr( $sortkey, 0, 255 ); |
| 76 | + # Also. substr behaves weird when given "". |
| 77 | + if ( $sortkey !== '' ) { |
| 78 | + $sortkey = substr( $sortkey, 0, 255 ); |
| 79 | + } |
77 | 80 | } |
78 | 81 | |
79 | 82 | $this->mRecursive = $recursive; |
— | — | @@ -432,20 +435,39 @@ |
433 | 436 | * @private |
434 | 437 | */ |
435 | 438 | function getCategoryInsertions( $existing = array() ) { |
436 | | - global $wgContLang; |
| 439 | + global $wgContLang, $wgCategoryCollation; |
437 | 440 | $diffs = array_diff_assoc( $this->mCategories, $existing ); |
438 | 441 | $arr = array(); |
439 | | - foreach ( $diffs as $name => $sortkey ) { |
| 442 | + foreach ( $diffs as $name => $prefix ) { |
440 | 443 | $nt = Title::makeTitleSafe( NS_CATEGORY, $name ); |
441 | 444 | $wgContLang->findVariantLink( $name, $nt, true ); |
| 445 | + |
| 446 | + if ( $this->mTitle->getNamespace() == NS_CATEGORY ) { |
| 447 | + $type = 'subcat'; |
| 448 | + } elseif ( $this->mTitle->getNamespace() == NS_FILE ) { |
| 449 | + $type = 'file'; |
| 450 | + } else { |
| 451 | + $type = 'page'; |
| 452 | + } |
| 453 | + |
| 454 | + # Treat custom sortkeys as a prefix, so that if multiple |
| 455 | + # things are forced to sort as '*' or something, they'll |
| 456 | + # sort properly in the category rather than in page_id |
| 457 | + # order or such. |
| 458 | + $sortkey = Collation::singleton()->getSortKey( |
| 459 | + $this->mTitle->getCategorySortkey( $prefix ) ); |
| 460 | + |
442 | 461 | $arr[] = array( |
443 | 462 | 'cl_from' => $this->mId, |
444 | 463 | 'cl_to' => $name, |
445 | 464 | 'cl_sortkey' => $sortkey, |
446 | | - 'cl_timestamp' => $this->mDb->timestamp() |
| 465 | + 'cl_timestamp' => $this->mDb->timestamp(), |
| 466 | + 'cl_sortkey_prefix' => $prefix, |
| 467 | + 'cl_collation' => $wgCategoryCollation, |
| 468 | + 'cl_type' => $type, |
447 | 469 | ); |
448 | 470 | } |
449 | | - return $arr; |
| 471 | + return $arr; |
450 | 472 | } |
451 | 473 | |
452 | 474 | /** |
— | — | @@ -665,14 +687,13 @@ |
666 | 688 | * @private |
667 | 689 | */ |
668 | 690 | function getExistingCategories() { |
669 | | - $res = $this->mDb->select( 'categorylinks', array( 'cl_to', 'cl_sortkey' ), |
| 691 | + $res = $this->mDb->select( 'categorylinks', array( 'cl_to', 'cl_sortkey_prefix' ), |
670 | 692 | array( 'cl_from' => $this->mId ), __METHOD__, $this->mOptions ); |
671 | 693 | $arr = array(); |
672 | | - while ( $row = $this->mDb->fetchObject( $res ) ) { |
673 | | - $arr[$row->cl_to] = $row->cl_sortkey; |
| 694 | + foreach ( $res as $row ) { |
| 695 | + $arr[$row->cl_to] = $row->cl_sortkey_prefix; |
674 | 696 | } |
675 | | - $this->mDb->freeResult( $res ); |
676 | | - return $arr; |
| 697 | + return $arr; |
677 | 698 | } |
678 | 699 | |
679 | 700 | /** |
Index: branches/wmf/1.17wmf1/includes/Title.php |
— | — | @@ -3096,27 +3096,22 @@ |
3097 | 3097 | } |
3098 | 3098 | $redirid = $this->getArticleID(); |
3099 | 3099 | |
3100 | | - // Category memberships include a sort key which may be customized. |
3101 | | - // If it's left as the default (the page title), we need to update |
3102 | | - // the sort key to match the new title. |
3103 | | - // |
3104 | | - // Be careful to avoid resetting cl_timestamp, which may disturb |
3105 | | - // time-based lists on some sites. |
3106 | | - // |
3107 | | - // Warning -- if the sort key is *explicitly* set to the old title, |
3108 | | - // we can't actually distinguish it from a default here, and it'll |
3109 | | - // be set to the new title even though it really shouldn't. |
3110 | | - // It'll get corrected on the next edit, but resetting cl_timestamp. |
| 3100 | + // Refresh the sortkey for this row. Be careful to avoid resetting |
| 3101 | + // cl_timestamp, which may disturb time-based lists on some sites. |
| 3102 | + $prefix = $dbw->selectField( |
| 3103 | + 'categorylinks', |
| 3104 | + 'cl_sortkey_prefix', |
| 3105 | + array( 'cl_from' => $pageid ), |
| 3106 | + __METHOD__ |
| 3107 | + ); |
3111 | 3108 | $dbw->update( 'categorylinks', |
3112 | 3109 | array( |
3113 | | - 'cl_sortkey' => $nt->getPrefixedText(), |
| 3110 | + 'cl_sortkey' => Collation::singleton()->getSortKey( |
| 3111 | + $nt->getCategorySortkey( $prefix ) ), |
3114 | 3112 | 'cl_timestamp=cl_timestamp' ), |
3115 | | - array( |
3116 | | - 'cl_from' => $pageid, |
3117 | | - 'cl_sortkey' => $this->getPrefixedText() ), |
| 3113 | + array( 'cl_from' => $pageid ), |
3118 | 3114 | __METHOD__ ); |
3119 | 3115 | |
3120 | | - |
3121 | 3116 | if ( $protected ) { |
3122 | 3117 | # Protect the redirect title as the title used to be... |
3123 | 3118 | $dbw->insertSelect( 'page_restrictions', 'page_restrictions', |