From 977be5f40dc1400af8c7d05254b02d2ebec0eef2 Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Mon, 13 Jul 2009 10:40:29 +0000 Subject: [PATCH] * Added ancientpages, deadendpages and disambiguations to ApiQueryQuerypage * Added information about disabledness and cache to result --- includes/QueryPage.php | 5 +-- includes/api/ApiQueryQuerypage.php | 45 ++++++++++++++------ includes/specials/SpecialAncientpages.php | 4 ++ includes/specials/SpecialDisambiguations.php | 6 +++ 4 files changed, 43 insertions(+), 17 deletions(-) diff --git a/includes/QueryPage.php b/includes/QueryPage.php index dc22a8c5cf..0d84235e49 100644 --- a/includes/QueryPage.php +++ b/includes/QueryPage.php @@ -179,9 +179,8 @@ class QueryPage { function formatApiResult( $row ) { $title = Title::makeTitle( $row->namespace, $row->title ); return array( - //'pageid' => intval( $row->id ), - 'ns' => intval( $title->getNamespace() ), - 'title' => $title->getPrefixedText(), + 'ns' => intval( $title->getNamespace() ), + 'title' => $title->getPrefixedText(), ); } diff --git a/includes/api/ApiQueryQuerypage.php b/includes/api/ApiQueryQuerypage.php index f77d411b50..11eec9db96 100644 --- a/includes/api/ApiQueryQuerypage.php +++ b/includes/api/ApiQueryQuerypage.php @@ -35,7 +35,10 @@ if (!defined('MEDIAWIKI')) { */ class ApiQueryQuerypage extends ApiQueryBase { static $queryPages = array( - 'brokenredirects' => 'BrokenRedirectsPage' + 'ancientpages' => 'AncientPagesPage', + 'brokenredirects' => 'BrokenRedirectsPage', + 'deadendpages' => 'DeadendPagesPage', + 'disambiguations' => 'DisambiguationsPage', ); public function __construct($query, $moduleName) { @@ -56,31 +59,35 @@ class ApiQueryQuerypage extends ApiQueryBase { $limit = $params['limit']; // Try to find an entry in $wgQueryPages - $qpName = $params['querypage']; - if ( is_null( $qpName ) ) + $name = $params['querypage']; + if ( is_null( $name ) ) $this->dieUsageMsg( array( 'missingparam', 'querypage' ) ); - if ( !isset( self::$queryPages[$qpName] ) ) + if ( !isset( self::$queryPages[$name] ) ) $this->dieUsage( 'Querypage unrecognized', 'unknownquerypage' ); - $qpClass = self::$queryPages[$qpName]; - $qpInstance = new $qpClass; - $result = $qpInstance->reallyDoQuery( $offset, $limit + 1 ); + // Get the result from the query page + $class = self::$queryPages[$name]; + $queryPage = new $class; + $result = $queryPage->reallyDoQuery( $offset, $limit + 1 ); + // Output the result $apiResult = $this->getResult(); + $resultPath = array( 'query', $this->getModuleName() ); $count = 0; while ( $row = $result['dbr']->fetchObject( $result['result'] ) ) { if ( ++ $count > $limit ) { // We've reached the one extra which shows that there are additional pages to be had. Stop here... $this->setContinueEnumParameter( 'offset', $offset + $count - 1 ); break; - } + } + if ( is_null( $resultPageSet ) ) { // Normal mode; let the query page make a sensible result out of it - $vals = $qpInstance->formatApiResult( $row ); - $fit = $apiResult->addValue( array( 'query', $this->getModuleName() ), null, $vals ); + $vals = $queryPage->formatApiResult( $row ); + $fit = $apiResult->addValue( $resultPath, null, $vals ); if( !$fit ) { - $this->setContinueEnumParameter( 'offset', $params['offset'] + $count ); + $this->setContinueEnumParameter( 'offset', $offset + $count ); break; } } else { @@ -88,15 +95,25 @@ class ApiQueryQuerypage extends ApiQueryBase { $resultPageSet->processDbRow( $row ); } } - - + // Set XML element to 'p' if ( is_null( $resultPageSet ) ) { $apiResult->setIndexedTagName_internal( array( 'query', $this->getModuleName()), 'p' ); + } + + // Set meta information + if ( $result['cached'] ) { + // Set cached date if available, else simply true + $apiResult->addValue( $resultPath, 'cached', + $result === true ? true : wfTimestamp( TS_ISO_8601, $result['cached'] ) ); } + if ( $result['disabled'] ) + // No further updates will be performed + $apiResult->addValue( $resultPath, 'disabled', true ); + + } public function getAllowedParams() { - return array ( 'offset' => 0, 'limit' => array ( diff --git a/includes/specials/SpecialAncientpages.php b/includes/specials/SpecialAncientpages.php index 4738a1a066..0cbf839282 100644 --- a/includes/specials/SpecialAncientpages.php +++ b/includes/specials/SpecialAncientpages.php @@ -62,6 +62,10 @@ class AncientPagesPage extends QueryPage { ); return wfSpecialList($link, htmlspecialchars($d) ); } + function formatApiResult( $row ) { + $result = parent::formatApiResult( $row ); + $result['timestamp'] = wfTimestamp( TS_ISO_8601, $row->value ); + } } function wfSpecialAncientpages() { diff --git a/includes/specials/SpecialDisambiguations.php b/includes/specials/SpecialDisambiguations.php index 0a728b6860..0c5c7babf8 100644 --- a/includes/specials/SpecialDisambiguations.php +++ b/includes/specials/SpecialDisambiguations.php @@ -94,6 +94,12 @@ class DisambiguationsPage extends PageQueryPage { return "$from $edit $arr $to"; } + function formatApiResult( $row ) { + $linkTo = Title::makeTitle( NS_MAIN, $row->value ); + $result = parent::formatApiResult( $row ); + $result['to'] = $linkTo->getPrefixedText(); + return $result; + } } /** -- 2.20.1