Index: branches/querypage-work2/phase3/includes/QueryPage.php |
— | — | @@ -15,7 +15,7 @@ |
16 | 16 | global $wgQueryPages; // not redundant |
17 | 17 | $wgQueryPages = array( |
18 | 18 | // QueryPage subclass Special page name Limit (false for none, none for the default) |
19 | | -//---------------------------------------------------------------------------- |
| 19 | +// ---------------------------------------------------------------------------- |
20 | 20 | array( 'AncientPagesPage', 'Ancientpages' ), |
21 | 21 | array( 'BrokenRedirectsPage', 'BrokenRedirects' ), |
22 | 22 | array( 'DeadendPagesPage', 'Deadendpages' ), |
— | — | @@ -77,7 +77,7 @@ |
78 | 78 | */ |
79 | 79 | var $offset = 0; |
80 | 80 | var $limit = 0; |
81 | | - |
| 81 | + |
82 | 82 | /** |
83 | 83 | * The number of rows returned by the query. Reading this variable |
84 | 84 | * only makes sense in functions that are run after the query has been |
— | — | @@ -116,7 +116,7 @@ |
117 | 117 | * conds => WHERE conditions |
118 | 118 | * options => options |
119 | 119 | * join_conds => JOIN conditions |
120 | | - * |
| 120 | + * |
121 | 121 | * Note that the query itself should return the following three columns: |
122 | 122 | * 'namespace', 'title', and 'value' |
123 | 123 | * *in that order*. 'value' is used for sorting. |
— | — | @@ -131,7 +131,7 @@ |
132 | 132 | * @return array |
133 | 133 | */ |
134 | 134 | abstract function getQueryInfo(); |
135 | | - |
| 135 | + |
136 | 136 | /** |
137 | 137 | * Subclasses return an array of fields to order by here. Don't append |
138 | 138 | * DESC to the field names, that'll be done automatically if |
— | — | @@ -139,7 +139,7 @@ |
140 | 140 | * @return array |
141 | 141 | */ |
142 | 142 | function getOrderFields() { |
143 | | - return array('value'); |
| 143 | + return array( 'value' ); |
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
— | — | @@ -175,7 +175,7 @@ |
176 | 176 | global $wgDisableQueryPages; |
177 | 177 | return $wgDisableQueryPages; |
178 | 178 | } |
179 | | - |
| 179 | + |
180 | 180 | /** |
181 | 181 | * Is the output of this query cacheable? Non-cacheable expensive pages |
182 | 182 | * will be disabled in miser mode and will not have their results written |
— | — | @@ -291,11 +291,11 @@ |
292 | 292 | } else { |
293 | 293 | $value = 0; |
294 | 294 | } |
295 | | - |
296 | | - $vals[] = array('qc_type' => $this->getName(), |
| 295 | + |
| 296 | + $vals[] = array( 'qc_type' => $this->getName(), |
297 | 297 | 'qc_namespace' => $row->namespace, |
298 | 298 | 'qc_title' => $row->title, |
299 | | - 'qc_value' => $value); |
| 299 | + 'qc_value' => $value ); |
300 | 300 | } |
301 | 301 | |
302 | 302 | # Save results into the querycache table on the master |
— | — | @@ -317,7 +317,7 @@ |
318 | 318 | } |
319 | 319 | return $num; |
320 | 320 | } |
321 | | - |
| 321 | + |
322 | 322 | /** |
323 | 323 | * Run the query and return the result |
324 | 324 | * @param $limit mixed Numerical limit or false for no limit |
— | — | @@ -328,24 +328,24 @@ |
329 | 329 | $fname = get_class( $this ) . "::reallyDoQuery"; |
330 | 330 | $query = $this->getQueryInfo(); |
331 | 331 | $order = $this->getOrderFields(); |
332 | | - if( $this->sortDescending() ) { |
333 | | - foreach( $order as &$field ) { |
| 332 | + if ( $this->sortDescending() ) { |
| 333 | + foreach ( $order as &$field ) { |
334 | 334 | $field .= ' DESC'; |
335 | 335 | } |
336 | 336 | } |
337 | | - if( !is_array( @$query['options'] ) ) { |
| 337 | + if ( !is_array( @$query['options'] ) ) { |
338 | 338 | $options = array (); |
339 | 339 | } |
340 | | - if( count( $order ) ) { |
| 340 | + if ( count( $order ) ) { |
341 | 341 | $query['options']['ORDER BY'] = implode( ', ', $order ); |
342 | 342 | } |
343 | | - if( $limit !== false) { |
| 343 | + if ( $limit !== false ) { |
344 | 344 | $query['options']['LIMIT'] = intval( $limit ); |
345 | 345 | } |
346 | | - if( $offset !== false) { |
| 346 | + if ( $offset !== false ) { |
347 | 347 | $query['options']['OFFSET'] = intval( $offset ); |
348 | 348 | } |
349 | | - |
| 349 | + |
350 | 350 | $dbr = wfGetDB( DB_SLAVE ); |
351 | 351 | $res = $dbr->select( (array)@$query['tables'], |
352 | 352 | (array)@$query['fields'], |
— | — | @@ -356,13 +356,13 @@ |
357 | 357 | } |
358 | 358 | |
359 | 359 | function doQuery( $limit, $offset = false ) { |
360 | | - if( $this->isCached() && $this->isCacheable() ) { |
| 360 | + if ( $this->isCached() && $this->isCacheable() ) { |
361 | 361 | return $this->fetchFromCache( $limit, $offset ); |
362 | 362 | } else { |
363 | 363 | return $this->reallyDoQuery( $limit, $offset ); |
364 | 364 | } |
365 | 365 | } |
366 | | - |
| 366 | + |
367 | 367 | /** |
368 | 368 | * Fetch the query results from the query cache |
369 | 369 | * @param $limit mixed Numerical limit or false for no limit |
— | — | @@ -372,10 +372,10 @@ |
373 | 373 | function fetchFromCache( $limit, $offset = false ) { |
374 | 374 | $dbr = wfGetDB( DB_SLAVE ); |
375 | 375 | $options = array (); |
376 | | - if( $limit !== false ) { |
| 376 | + if ( $limit !== false ) { |
377 | 377 | $options['LIMIT'] = intval( $limit ); |
378 | 378 | } |
379 | | - if( $offset !== false) { |
| 379 | + if ( $offset !== false ) { |
380 | 380 | $options['OFFSET'] = intval( $offset ); |
381 | 381 | } |
382 | 382 | $res = $dbr->select( 'querycache', array( 'qc_type', |
— | — | @@ -399,8 +399,8 @@ |
400 | 400 | $this->displayRestrictionError(); |
401 | 401 | return; |
402 | 402 | } |
403 | | - |
404 | | - if( $this->limit == 0 && $this->offset == 0 ) |
| 403 | + |
| 404 | + if ( $this->limit == 0 && $this->offset == 0 ) |
405 | 405 | list( $this->limit, $this->offset ) = wfCheckLimits(); |
406 | 406 | $sname = $this->getName(); |
407 | 407 | $fname = get_class( $this ) . '::doQuery'; |
— | — | @@ -408,7 +408,7 @@ |
409 | 409 | |
410 | 410 | $this->setHeaders(); |
411 | 411 | $wgOut->setSyndicated( $this->isSyndicated() ); |
412 | | - |
| 412 | + |
413 | 413 | if ( $this->isCached() && !$this->isCacheable() ) { |
414 | 414 | $wgOut->setSyndicated( false ); |
415 | 415 | $wgOut->addWikiMsg( 'querypage-disabled' ); |
— | — | @@ -416,19 +416,19 @@ |
417 | 417 | } |
418 | 418 | |
419 | 419 | // TODO: Use doQuery() |
420 | | - //$res = null; |
| 420 | + // $res = null; |
421 | 421 | if ( !$this->isCached() ) { |
422 | 422 | $res = $this->reallyDoQuery( $this->limit, $this->offset ); |
423 | 423 | } else { |
424 | 424 | # Get the cached result |
425 | 425 | $res = $this->fetchFromCache( $this->limit, $this->offset ); |
426 | | - if( !$this->listoutput ) { |
| 426 | + if ( !$this->listoutput ) { |
427 | 427 | |
428 | 428 | # Fetch the timestamp of this update |
429 | 429 | $tRes = $dbr->select( 'querycache_info', array( 'qci_timestamp' ), array( 'qci_type' => $sname ), $fname ); |
430 | 430 | $tRow = $dbr->fetchObject( $tRes ); |
431 | 431 | |
432 | | - if( $tRow ) { |
| 432 | + if ( $tRow ) { |
433 | 433 | $updated = $wgLang->timeanddate( $tRow->qci_timestamp, true, true ); |
434 | 434 | $updateddate = $wgLang->date( $tRow->qci_timestamp, true, true ); |
435 | 435 | $updatedtime = $wgLang->time( $tRow->qci_timestamp, true, true ); |
— | — | @@ -442,7 +442,7 @@ |
443 | 443 | # If updates on this page have been disabled, let the user know |
444 | 444 | # that the data set won't be refreshed for now |
445 | 445 | global $wgDisableQueryPageUpdate; |
446 | | - if( is_array( $wgDisableQueryPageUpdate ) && in_array( $this->getName(), $wgDisableQueryPageUpdate ) ) { |
| 446 | + if ( is_array( $wgDisableQueryPageUpdate ) && in_array( $this->getName(), $wgDisableQueryPageUpdate ) ) { |
447 | 447 | $wgOut->addWikiMsg( 'querypage-no-updates' ); |
448 | 448 | } |
449 | 449 | |
— | — | @@ -454,12 +454,12 @@ |
455 | 455 | |
456 | 456 | $this->preprocessResults( $dbr, $res ); |
457 | 457 | |
458 | | - $wgOut->addHTML( Xml::openElement( 'div', array('class' => 'mw-spcontent') ) ); |
| 458 | + $wgOut->addHTML( Xml::openElement( 'div', array( 'class' => 'mw-spcontent' ) ) ); |
459 | 459 | |
460 | 460 | # Top header and navigation |
461 | | - if( $this->shownavigation ) { |
| 461 | + if ( $this->shownavigation ) { |
462 | 462 | $wgOut->addHTML( $this->getPageHeader() ); |
463 | | - if( $this->numRows > 0 ) { |
| 463 | + if ( $this->numRows > 0 ) { |
464 | 464 | $wgOut->addHTML( '<p>' . wfShowingResults( $this->offset, $this->numRows ) . '</p>' ); |
465 | 465 | # Disable the "next" link when we reach the end |
466 | 466 | $paging = wfViewPrevNext( $this->offset, $this->limit, |
— | — | @@ -486,7 +486,7 @@ |
487 | 487 | $this->offset ); |
488 | 488 | |
489 | 489 | # Repeat the paging links at the bottom |
490 | | - if( $this->shownavigation ) { |
| 490 | + if ( $this->shownavigation ) { |
491 | 491 | $wgOut->addHTML( '<p>' . $paging . '</p>' ); |
492 | 492 | } |
493 | 493 | |
— | — | @@ -509,16 +509,16 @@ |
510 | 510 | protected function outputResults( $out, $skin, $dbr, $res, $num, $offset ) { |
511 | 511 | global $wgContLang; |
512 | 512 | |
513 | | - if( $num > 0 ) { |
| 513 | + if ( $num > 0 ) { |
514 | 514 | $html = array(); |
515 | | - if( !$this->listoutput ) |
| 515 | + if ( !$this->listoutput ) |
516 | 516 | $html[] = $this->openList( $offset ); |
517 | 517 | |
518 | 518 | # $res might contain the whole 1,000 rows, so we read up to |
519 | 519 | # $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++ ) { |
521 | 521 | $line = $this->formatResult( $skin, $row ); |
522 | | - if( $line ) { |
| 522 | + if ( $line ) { |
523 | 523 | $attr = ( isset( $row->usepatrol ) && $row->usepatrol && $row->patrolled == 0 ) |
524 | 524 | ? ' class="not-patrolled"' |
525 | 525 | : ''; |
— | — | @@ -529,10 +529,10 @@ |
530 | 530 | } |
531 | 531 | |
532 | 532 | # Flush the final result |
533 | | - if( $this->tryLastResult() ) { |
| 533 | + if ( $this->tryLastResult() ) { |
534 | 534 | $row = null; |
535 | 535 | $line = $this->formatResult( $skin, $row ); |
536 | | - if( $line ) { |
| 536 | + if ( $line ) { |
537 | 537 | $attr = ( isset( $row->usepatrol ) && $row->usepatrol && $row->patrolled == 0 ) |
538 | 538 | ? ' class="not-patrolled"' |
539 | 539 | : ''; |
— | — | @@ -542,7 +542,7 @@ |
543 | 543 | } |
544 | 544 | } |
545 | 545 | |
546 | | - if( !$this->listoutput ) |
| 546 | + if ( !$this->listoutput ) |
547 | 547 | $html[] = $this->closeList(); |
548 | 548 | |
549 | 549 | $html = $this->listoutput |
— | — | @@ -577,13 +577,13 @@ |
578 | 578 | $wgOut->addWikiMsg( 'feed-unavailable' ); |
579 | 579 | return; |
580 | 580 | } |
581 | | - |
| 581 | + |
582 | 582 | global $wgFeedLimit; |
583 | | - if( $limit > $wgFeedLimit ) { |
| 583 | + if ( $limit > $wgFeedLimit ) { |
584 | 584 | $limit = $wgFeedLimit; |
585 | 585 | } |
586 | 586 | |
587 | | - if( isset($wgFeedClasses[$class]) ) { |
| 587 | + if ( isset( $wgFeedClasses[$class] ) ) { |
588 | 588 | $feed = new $wgFeedClasses[$class]( |
589 | 589 | $this->feedTitle(), |
590 | 590 | $this->feedDesc(), |
— | — | @@ -594,7 +594,7 @@ |
595 | 595 | $res = $this->reallyDoQuery( $limit, 0 ); |
596 | 596 | foreach ( $res as $obj ) { |
597 | 597 | $item = $this->feedResult( $obj ); |
598 | | - if( $item ) { |
| 598 | + if ( $item ) { |
599 | 599 | $feed->outItem( $item ); |
600 | 600 | } |
601 | 601 | } |
— | — | @@ -611,14 +611,14 @@ |
612 | 612 | * feedItemDesc() |
613 | 613 | */ |
614 | 614 | function feedResult( $row ) { |
615 | | - if( !isset( $row->title ) ) { |
| 615 | + if ( !isset( $row->title ) ) { |
616 | 616 | return null; |
617 | 617 | } |
618 | 618 | $title = Title::MakeTitle( intval( $row->namespace ), $row->title ); |
619 | | - if( $title ) { |
| 619 | + if ( $title ) { |
620 | 620 | $date = isset( $row->timestamp ) ? $row->timestamp : ''; |
621 | 621 | $comments = ''; |
622 | | - if( $title ) { |
| 622 | + if ( $title ) { |
623 | 623 | $talkpage = $title->getTalkPage(); |
624 | 624 | $comments = $talkpage->getFullURL(); |
625 | 625 | } |
— | — | @@ -629,7 +629,7 @@ |
630 | 630 | $title->getFullURL(), |
631 | 631 | $date, |
632 | 632 | $this->feedItemAuthor( $row ), |
633 | | - $comments); |
| 633 | + $comments ); |
634 | 634 | } else { |
635 | 635 | return null; |
636 | 636 | } |
— | — | @@ -689,7 +689,7 @@ |
690 | 690 | // If there are no rows we get an error seeking. |
691 | 691 | $db->dataSeek( $res, 0 ); |
692 | 692 | } |
693 | | - |
| 693 | + |
694 | 694 | /** |
695 | 695 | * Should formatResult() always check page existence, even if |
696 | 696 | * the results are fresh? This is a (hopefully temporary) |
— | — | @@ -710,8 +710,8 @@ |
711 | 711 | */ |
712 | 712 | public function formatResult( $skin, $result ) { |
713 | 713 | $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() ) { |
716 | 716 | $pageLink = $title->isKnown() |
717 | 717 | ? '<del>' . $skin->link( $title ) . '</del>' |
718 | 718 | : $skin->link( |
— | — | @@ -736,7 +736,7 @@ |
737 | 737 | return wfMsgHtml( 'wantedpages-badtitle', $tsafe ); |
738 | 738 | } |
739 | 739 | } |
740 | | - |
| 740 | + |
741 | 741 | /** |
742 | 742 | * Make a "what links here" link for a given title |
743 | 743 | * |