r78720 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78719‎ | r78720 | r78721 >
Date:19:41, 21 December 2010
Author:catrope
Status:ok
Tags:
Comment:
Stylize QueryPage.php
Modified paths:
  • /branches/querypage-work2/phase3/includes/QueryPage.php (modified) (history)

Diff [purge]

Index: branches/querypage-work2/phase3/includes/QueryPage.php
@@ -15,7 +15,7 @@
1616 global $wgQueryPages; // not redundant
1717 $wgQueryPages = array(
1818 // QueryPage subclass Special page name Limit (false for none, none for the default)
19 -//----------------------------------------------------------------------------
 19+// ----------------------------------------------------------------------------
2020 array( 'AncientPagesPage', 'Ancientpages' ),
2121 array( 'BrokenRedirectsPage', 'BrokenRedirects' ),
2222 array( 'DeadendPagesPage', 'Deadendpages' ),
@@ -77,7 +77,7 @@
7878 */
7979 var $offset = 0;
8080 var $limit = 0;
81 -
 81+
8282 /**
8383 * The number of rows returned by the query. Reading this variable
8484 * only makes sense in functions that are run after the query has been
@@ -116,7 +116,7 @@
117117 * conds => WHERE conditions
118118 * options => options
119119 * join_conds => JOIN conditions
120 - *
 120+ *
121121 * Note that the query itself should return the following three columns:
122122 * 'namespace', 'title', and 'value'
123123 * *in that order*. 'value' is used for sorting.
@@ -131,7 +131,7 @@
132132 * @return array
133133 */
134134 abstract function getQueryInfo();
135 -
 135+
136136 /**
137137 * Subclasses return an array of fields to order by here. Don't append
138138 * DESC to the field names, that'll be done automatically if
@@ -139,7 +139,7 @@
140140 * @return array
141141 */
142142 function getOrderFields() {
143 - return array('value');
 143+ return array( 'value' );
144144 }
145145
146146 /**
@@ -175,7 +175,7 @@
176176 global $wgDisableQueryPages;
177177 return $wgDisableQueryPages;
178178 }
179 -
 179+
180180 /**
181181 * Is the output of this query cacheable? Non-cacheable expensive pages
182182 * will be disabled in miser mode and will not have their results written
@@ -291,11 +291,11 @@
292292 } else {
293293 $value = 0;
294294 }
295 -
296 - $vals[] = array('qc_type' => $this->getName(),
 295+
 296+ $vals[] = array( 'qc_type' => $this->getName(),
297297 'qc_namespace' => $row->namespace,
298298 'qc_title' => $row->title,
299 - 'qc_value' => $value);
 299+ 'qc_value' => $value );
300300 }
301301
302302 # Save results into the querycache table on the master
@@ -317,7 +317,7 @@
318318 }
319319 return $num;
320320 }
321 -
 321+
322322 /**
323323 * Run the query and return the result
324324 * @param $limit mixed Numerical limit or false for no limit
@@ -328,24 +328,24 @@
329329 $fname = get_class( $this ) . "::reallyDoQuery";
330330 $query = $this->getQueryInfo();
331331 $order = $this->getOrderFields();
332 - if( $this->sortDescending() ) {
333 - foreach( $order as &$field ) {
 332+ if ( $this->sortDescending() ) {
 333+ foreach ( $order as &$field ) {
334334 $field .= ' DESC';
335335 }
336336 }
337 - if( !is_array( @$query['options'] ) ) {
 337+ if ( !is_array( @$query['options'] ) ) {
338338 $options = array ();
339339 }
340 - if( count( $order ) ) {
 340+ if ( count( $order ) ) {
341341 $query['options']['ORDER BY'] = implode( ', ', $order );
342342 }
343 - if( $limit !== false) {
 343+ if ( $limit !== false ) {
344344 $query['options']['LIMIT'] = intval( $limit );
345345 }
346 - if( $offset !== false) {
 346+ if ( $offset !== false ) {
347347 $query['options']['OFFSET'] = intval( $offset );
348348 }
349 -
 349+
350350 $dbr = wfGetDB( DB_SLAVE );
351351 $res = $dbr->select( (array)@$query['tables'],
352352 (array)@$query['fields'],
@@ -356,13 +356,13 @@
357357 }
358358
359359 function doQuery( $limit, $offset = false ) {
360 - if( $this->isCached() && $this->isCacheable() ) {
 360+ if ( $this->isCached() && $this->isCacheable() ) {
361361 return $this->fetchFromCache( $limit, $offset );
362362 } else {
363363 return $this->reallyDoQuery( $limit, $offset );
364364 }
365365 }
366 -
 366+
367367 /**
368368 * Fetch the query results from the query cache
369369 * @param $limit mixed Numerical limit or false for no limit
@@ -372,10 +372,10 @@
373373 function fetchFromCache( $limit, $offset = false ) {
374374 $dbr = wfGetDB( DB_SLAVE );
375375 $options = array ();
376 - if( $limit !== false ) {
 376+ if ( $limit !== false ) {
377377 $options['LIMIT'] = intval( $limit );
378378 }
379 - if( $offset !== false) {
 379+ if ( $offset !== false ) {
380380 $options['OFFSET'] = intval( $offset );
381381 }
382382 $res = $dbr->select( 'querycache', array( 'qc_type',
@@ -399,8 +399,8 @@
400400 $this->displayRestrictionError();
401401 return;
402402 }
403 -
404 - if( $this->limit == 0 && $this->offset == 0 )
 403+
 404+ if ( $this->limit == 0 && $this->offset == 0 )
405405 list( $this->limit, $this->offset ) = wfCheckLimits();
406406 $sname = $this->getName();
407407 $fname = get_class( $this ) . '::doQuery';
@@ -408,7 +408,7 @@
409409
410410 $this->setHeaders();
411411 $wgOut->setSyndicated( $this->isSyndicated() );
412 -
 412+
413413 if ( $this->isCached() && !$this->isCacheable() ) {
414414 $wgOut->setSyndicated( false );
415415 $wgOut->addWikiMsg( 'querypage-disabled' );
@@ -416,19 +416,19 @@
417417 }
418418
419419 // TODO: Use doQuery()
420 - //$res = null;
 420+ // $res = null;
421421 if ( !$this->isCached() ) {
422422 $res = $this->reallyDoQuery( $this->limit, $this->offset );
423423 } else {
424424 # Get the cached result
425425 $res = $this->fetchFromCache( $this->limit, $this->offset );
426 - if( !$this->listoutput ) {
 426+ if ( !$this->listoutput ) {
427427
428428 # Fetch the timestamp of this update
429429 $tRes = $dbr->select( 'querycache_info', array( 'qci_timestamp' ), array( 'qci_type' => $sname ), $fname );
430430 $tRow = $dbr->fetchObject( $tRes );
431431
432 - if( $tRow ) {
 432+ if ( $tRow ) {
433433 $updated = $wgLang->timeanddate( $tRow->qci_timestamp, true, true );
434434 $updateddate = $wgLang->date( $tRow->qci_timestamp, true, true );
435435 $updatedtime = $wgLang->time( $tRow->qci_timestamp, true, true );
@@ -442,7 +442,7 @@
443443 # If updates on this page have been disabled, let the user know
444444 # that the data set won't be refreshed for now
445445 global $wgDisableQueryPageUpdate;
446 - if( is_array( $wgDisableQueryPageUpdate ) && in_array( $this->getName(), $wgDisableQueryPageUpdate ) ) {
 446+ if ( is_array( $wgDisableQueryPageUpdate ) && in_array( $this->getName(), $wgDisableQueryPageUpdate ) ) {
447447 $wgOut->addWikiMsg( 'querypage-no-updates' );
448448 }
449449
@@ -454,12 +454,12 @@
455455
456456 $this->preprocessResults( $dbr, $res );
457457
458 - $wgOut->addHTML( Xml::openElement( 'div', array('class' => 'mw-spcontent') ) );
 458+ $wgOut->addHTML( Xml::openElement( 'div', array( 'class' => 'mw-spcontent' ) ) );
459459
460460 # Top header and navigation
461 - if( $this->shownavigation ) {
 461+ if ( $this->shownavigation ) {
462462 $wgOut->addHTML( $this->getPageHeader() );
463 - if( $this->numRows > 0 ) {
 463+ if ( $this->numRows > 0 ) {
464464 $wgOut->addHTML( '<p>' . wfShowingResults( $this->offset, $this->numRows ) . '</p>' );
465465 # Disable the "next" link when we reach the end
466466 $paging = wfViewPrevNext( $this->offset, $this->limit,
@@ -486,7 +486,7 @@
487487 $this->offset );
488488
489489 # Repeat the paging links at the bottom
490 - if( $this->shownavigation ) {
 490+ if ( $this->shownavigation ) {
491491 $wgOut->addHTML( '<p>' . $paging . '</p>' );
492492 }
493493
@@ -509,16 +509,16 @@
510510 protected function outputResults( $out, $skin, $dbr, $res, $num, $offset ) {
511511 global $wgContLang;
512512
513 - if( $num > 0 ) {
 513+ if ( $num > 0 ) {
514514 $html = array();
515 - if( !$this->listoutput )
 515+ if ( !$this->listoutput )
516516 $html[] = $this->openList( $offset );
517517
518518 # $res might contain the whole 1,000 rows, so we read up to
519519 # $num [should update this to use a Pager]
520 - for( $i = 0; $i < $num && $row = $dbr->fetchObject( $res ); $i++ ) {
 520+ for ( $i = 0; $i < $num && $row = $dbr->fetchObject( $res ); $i++ ) {
521521 $line = $this->formatResult( $skin, $row );
522 - if( $line ) {
 522+ if ( $line ) {
523523 $attr = ( isset( $row->usepatrol ) && $row->usepatrol && $row->patrolled == 0 )
524524 ? ' class="not-patrolled"'
525525 : '';
@@ -529,10 +529,10 @@
530530 }
531531
532532 # Flush the final result
533 - if( $this->tryLastResult() ) {
 533+ if ( $this->tryLastResult() ) {
534534 $row = null;
535535 $line = $this->formatResult( $skin, $row );
536 - if( $line ) {
 536+ if ( $line ) {
537537 $attr = ( isset( $row->usepatrol ) && $row->usepatrol && $row->patrolled == 0 )
538538 ? ' class="not-patrolled"'
539539 : '';
@@ -542,7 +542,7 @@
543543 }
544544 }
545545
546 - if( !$this->listoutput )
 546+ if ( !$this->listoutput )
547547 $html[] = $this->closeList();
548548
549549 $html = $this->listoutput
@@ -577,13 +577,13 @@
578578 $wgOut->addWikiMsg( 'feed-unavailable' );
579579 return;
580580 }
581 -
 581+
582582 global $wgFeedLimit;
583 - if( $limit > $wgFeedLimit ) {
 583+ if ( $limit > $wgFeedLimit ) {
584584 $limit = $wgFeedLimit;
585585 }
586586
587 - if( isset($wgFeedClasses[$class]) ) {
 587+ if ( isset( $wgFeedClasses[$class] ) ) {
588588 $feed = new $wgFeedClasses[$class](
589589 $this->feedTitle(),
590590 $this->feedDesc(),
@@ -594,7 +594,7 @@
595595 $res = $this->reallyDoQuery( $limit, 0 );
596596 foreach ( $res as $obj ) {
597597 $item = $this->feedResult( $obj );
598 - if( $item ) {
 598+ if ( $item ) {
599599 $feed->outItem( $item );
600600 }
601601 }
@@ -611,14 +611,14 @@
612612 * feedItemDesc()
613613 */
614614 function feedResult( $row ) {
615 - if( !isset( $row->title ) ) {
 615+ if ( !isset( $row->title ) ) {
616616 return null;
617617 }
618618 $title = Title::MakeTitle( intval( $row->namespace ), $row->title );
619 - if( $title ) {
 619+ if ( $title ) {
620620 $date = isset( $row->timestamp ) ? $row->timestamp : '';
621621 $comments = '';
622 - if( $title ) {
 622+ if ( $title ) {
623623 $talkpage = $title->getTalkPage();
624624 $comments = $talkpage->getFullURL();
625625 }
@@ -629,7 +629,7 @@
630630 $title->getFullURL(),
631631 $date,
632632 $this->feedItemAuthor( $row ),
633 - $comments);
 633+ $comments );
634634 } else {
635635 return null;
636636 }
@@ -689,7 +689,7 @@
690690 // If there are no rows we get an error seeking.
691691 $db->dataSeek( $res, 0 );
692692 }
693 -
 693+
694694 /**
695695 * Should formatResult() always check page existence, even if
696696 * the results are fresh? This is a (hopefully temporary)
@@ -710,8 +710,8 @@
711711 */
712712 public function formatResult( $skin, $result ) {
713713 $title = Title::makeTitleSafe( $result->namespace, $result->title );
714 - if( $title instanceof Title ) {
715 - if( $this->isCached() || $this->forceExistenceCheck() ) {
 714+ if ( $title instanceof Title ) {
 715+ if ( $this->isCached() || $this->forceExistenceCheck() ) {
716716 $pageLink = $title->isKnown()
717717 ? '<del>' . $skin->link( $title ) . '</del>'
718718 : $skin->link(
@@ -736,7 +736,7 @@
737737 return wfMsgHtml( 'wantedpages-badtitle', $tsafe );
738738 }
739739 }
740 -
 740+
741741 /**
742742 * Make a "what links here" link for a given title
743743 *

Status & tagging log