r53163 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53162‎ | r53163 | r53164 >
Date:10:40, 13 July 2009
Author:btongminh
Status:reverted
Tags:
Comment:
* Added ancientpages, deadendpages and disambiguations to ApiQueryQuerypage
* Added information about disabledness and cache to result
Modified paths:
  • /trunk/phase3/includes/QueryPage.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryQuerypage.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialAncientpages.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialDisambiguations.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryQuerypage.php
@@ -35,7 +35,10 @@
3636 */
3737 class ApiQueryQuerypage extends ApiQueryBase {
3838 static $queryPages = array(
39 - 'brokenredirects' => 'BrokenRedirectsPage'
 39+ 'ancientpages' => 'AncientPagesPage',
 40+ 'brokenredirects' => 'BrokenRedirectsPage',
 41+ 'deadendpages' => 'DeadendPagesPage',
 42+ 'disambiguations' => 'DisambiguationsPage',
4043 );
4144
4245 public function __construct($query, $moduleName) {
@@ -56,31 +59,35 @@
5760 $limit = $params['limit'];
5861
5962 // Try to find an entry in $wgQueryPages
60 - $qpName = $params['querypage'];
61 - if ( is_null( $qpName ) )
 63+ $name = $params['querypage'];
 64+ if ( is_null( $name ) )
6265 $this->dieUsageMsg( array( 'missingparam', 'querypage' ) );
63 - if ( !isset( self::$queryPages[$qpName] ) )
 66+ if ( !isset( self::$queryPages[$name] ) )
6467 $this->dieUsage( 'Querypage unrecognized', 'unknownquerypage' );
6568
66 - $qpClass = self::$queryPages[$qpName];
67 - $qpInstance = new $qpClass;
68 - $result = $qpInstance->reallyDoQuery( $offset, $limit + 1 );
 69+ // Get the result from the query page
 70+ $class = self::$queryPages[$name];
 71+ $queryPage = new $class;
 72+ $result = $queryPage->reallyDoQuery( $offset, $limit + 1 );
6973
 74+ // Output the result
7075 $apiResult = $this->getResult();
 76+ $resultPath = array( 'query', $this->getModuleName() );
7177 $count = 0;
7278 while ( $row = $result['dbr']->fetchObject( $result['result'] ) ) {
7379 if ( ++ $count > $limit ) {
7480 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
7581 $this->setContinueEnumParameter( 'offset', $offset + $count - 1 );
7682 break;
77 - }
 83+ }
 84+
7885 if ( is_null( $resultPageSet ) ) {
7986 // Normal mode; let the query page make a sensible result out of it
80 - $vals = $qpInstance->formatApiResult( $row );
81 - $fit = $apiResult->addValue( array( 'query', $this->getModuleName() ), null, $vals );
 87+ $vals = $queryPage->formatApiResult( $row );
 88+ $fit = $apiResult->addValue( $resultPath, null, $vals );
8289 if( !$fit )
8390 {
84 - $this->setContinueEnumParameter( 'offset', $params['offset'] + $count );
 91+ $this->setContinueEnumParameter( 'offset', $offset + $count );
8592 break;
8693 }
8794 } else {
@@ -88,15 +95,25 @@
8996 $resultPageSet->processDbRow( $row );
9097 }
9198 }
92 -
93 -
 99+ // Set XML element to 'p'
94100 if ( is_null( $resultPageSet ) ) {
95101 $apiResult->setIndexedTagName_internal( array( 'query', $this->getModuleName()), 'p' );
 102+ }
 103+
 104+ // Set meta information
 105+ if ( $result['cached'] ) {
 106+ // Set cached date if available, else simply true
 107+ $apiResult->addValue( $resultPath, 'cached',
 108+ $result === true ? true : wfTimestamp( TS_ISO_8601, $result['cached'] ) );
96109 }
 110+ if ( $result['disabled'] )
 111+ // No further updates will be performed
 112+ $apiResult->addValue( $resultPath, 'disabled', true );
 113+
 114+
97115 }
98116
99117 public function getAllowedParams() {
100 -
101118 return array (
102119 'offset' => 0,
103120 'limit' => array (
Index: trunk/phase3/includes/specials/SpecialDisambiguations.php
@@ -94,6 +94,12 @@
9595
9696 return "$from $edit $arr $to";
9797 }
 98+ function formatApiResult( $row ) {
 99+ $linkTo = Title::makeTitle( NS_MAIN, $row->value );
 100+ $result = parent::formatApiResult( $row );
 101+ $result['to'] = $linkTo->getPrefixedText();
 102+ return $result;
 103+ }
98104 }
99105
100106 /**
Index: trunk/phase3/includes/specials/SpecialAncientpages.php
@@ -62,6 +62,10 @@
6363 );
6464 return wfSpecialList($link, htmlspecialchars($d) );
6565 }
 66+ function formatApiResult( $row ) {
 67+ $result = parent::formatApiResult( $row );
 68+ $result['timestamp'] = wfTimestamp( TS_ISO_8601, $row->value );
 69+ }
6670 }
6771
6872 function wfSpecialAncientpages() {
Index: trunk/phase3/includes/QueryPage.php
@@ -179,9 +179,8 @@
180180 function formatApiResult( $row ) {
181181 $title = Title::makeTitle( $row->namespace, $row->title );
182182 return array(
183 - //'pageid' => intval( $row->id ),
184 - 'ns' => intval( $title->getNamespace() ),
185 - 'title' => $title->getPrefixedText(),
 183+ 'ns' => intval( $title->getNamespace() ),
 184+ 'title' => $title->getPrefixedText(),
186185 );
187186 }
188187

Follow-up revisions

RevisionCommit summaryAuthorDate
r53167Revert r53147, r53149 and r53163 ("Add API module for QueryPage-based special...catrope12:40, 13 July 2009

Status & tagging log