r69812 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69811‎ | r69812 | r69813 >
Date:20:12, 23 July 2010
Author:simetrical
Status:ok
Tags:
Comment:
Saner code formatting, fix a couple of bugs
Modified paths:
  • /trunk/phase3/includes/CategoryPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/CategoryPage.php
@@ -244,16 +244,58 @@
245245 $fields = array( 'page_title', 'page_namespace', 'page_len',
246246 'page_is_redirect', 'cl_sortkey', 'cat_id', 'cat_title',
247247 'cat_subcats', 'cat_pages', 'cat_files' );
248 - $conds = array( $pageCondition, 'cl_to' => $this->title->getDBkey() );
 248+ $conds = array( 'cl_to' => $this->title->getDBkey() );
249249 $opts = array( 'ORDER BY' => $this->flip ? 'cl_sortkey DESC' :
250250 'cl_sortkey', 'USE INDEX' => array( 'categorylinks' => 'cl_sortkey' ) );
251251 $joins = array( 'categorylinks' => array( 'INNER JOIN', 'cl_from = page_id' ),
252252 'category' => array( 'LEFT JOIN', 'cat_title = page_title AND page_namespace = ' . NS_CATEGORY ) );
253253
 254+ if ( $wgExperimentalCategorySort ) {
 255+ # Copy-pasted from below, but that's okay, because the stuff below
 256+ # will be deleted when this becomes the default.
 257+ $count = 0;
 258+ $this->nextPage = null;
 259+
 260+ foreach ( array( 'page', 'subcat', 'file' ) as $type ) {
 261+ $res = $dbr->select(
 262+ $tables,
 263+ $fields,
 264+ $conds + array( 'cl_type' => $type ) + ( $type == 'page' ? array( $pageCondition ) : array() ),
 265+ __METHOD__,
 266+ $opts + ( $type == 'page' ? array( 'LIMIT' => $this->limit + 1 ) : array() ),
 267+ $joins
 268+ );
 269+
 270+ foreach ( $res as $row ) {
 271+ if ( $type == 'page' && ++$count > $this->limit ) {
 272+ # We've reached the one extra which shows that there
 273+ # are additional pages to be had. Stop here...
 274+ $this->nextPage = $row->cl_sortkey;
 275+ break;
 276+ }
 277+
 278+ $title = Title::newFromRow( $row );
 279+
 280+ if ( $title->getNamespace() == NS_CATEGORY ) {
 281+ $cat = Category::newFromRow( $row, $title );
 282+ $this->addSubcategoryObject( $cat, $row->cl_sortkey, $row->page_len );
 283+ } elseif ( $this->showGallery && $title->getNamespace() == NS_FILE ) {
 284+ $this->addImage( $title, $row->cl_sortkey, $row->page_len, $row->page_is_redirect );
 285+ } else {
 286+ $this->addPage( $title, $row->cl_sortkey, $row->page_len, $row->page_is_redirect );
 287+ }
 288+ }
 289+ }
 290+
 291+ return;
 292+ }
 293+
 294+ # Non-$wgExperimentalCategorySort stuff
 295+
254296 $res = $dbr->select(
255297 $tables,
256298 $fields,
257 - $conds + ( $wgExperimentalCategorySort ? array( 'cl_type' => 'page' ) : array() ),
 299+ $conds + array( $pageCondition ),
258300 __METHOD__,
259301 $opts + array( 'LIMIT' => $this->limit + 1 ),
260302 $joins
@@ -281,45 +323,6 @@
282324 $this->addPage( $title, $row->cl_sortkey, $row->page_len, $row->page_is_redirect );
283325 }
284326 }
285 -
286 - if ( $wgExperimentalCategorySort ) {
287 - # Now add all subcategories and files. TODO: rewrite to be sane
288 - # (this is basically a proof-of-concept, e.g., no pagination here).
289 - $subcatsRes = $dbr->select(
290 - $tables, $fields,
291 - $conds + array( 'cl_type' => 'subcat' ),
292 - __METHOD__, $opts, $joins
293 - );
294 -
295 - foreach ( $subcatsRes as $row ) {
296 - $title = Title::newFromRow( $row );
297 -
298 - if ( $title->getNamespace() == NS_CATEGORY ) {
299 - $cat = Category::newFromRow( $row, $title );
300 - $this->addSubcategoryObject( $cat, $row->cl_sortkey, $row->page_len );
301 - } else {
302 - # Will handle this sanely in final code
303 - throw new MWException( 'Debug: cl_type = subcat but not category' );
304 - }
305 - }
306 -
307 - $filesRes = $dbr->select(
308 - $tables, $fields,
309 - $conds + array( 'cl_type' => 'file' ),
310 - __METHOD__, $opts, $joins
311 - );
312 -
313 - foreach ( $filesRes as $row ) {
314 - $title = Title::newFromRow( $row );
315 -
316 - if ( $this->showGallery && $title->getNamespace() == NS_FILE ) {
317 - $this->addImage( $title, $row->cl_sortkey, $row->page_len, $row->page_is_redirect );
318 - } else {
319 - # More temporary debugging
320 - throw new MWException( 'Debug: cl_type = file but not file' );
321 - }
322 - }
323 - }
324327 }
325328
326329 function getCategoryTop() {

Status & tagging log