From: Roan Kattouw Date: Mon, 13 Jul 2009 12:40:19 +0000 (+0000) Subject: Revert r53147, r53149 and r53163 ("Add API module for QueryPage-based special pages... X-Git-Tag: 1.31.0-rc.0~40980 X-Git-Url: http://git.cyclocoop.org/fichier?a=commitdiff_plain;h=562dfb5de4db3bf0a947e62de421b6aa46b6a228;p=lhc%2Fweb%2Fwiklou.git Revert r53147, r53149 and r53163 ("Add API module for QueryPage-based special pages"): this has already been worked on more extensively and cleanly in the querypage-work branch, if you wanna work on this please finalize the implementation there rather than reinventing the wheel. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index d324719cad..23465f4764 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -292,7 +292,6 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Added snippet field to list=search output * (bug 17809) Add number of users in user groups to meta=siteinfo * (bug 18533) Add readonly reason to readonly exception -* (bug 14869) Allow access to QueryPage-based special pages via API === Languages updated in 1.16 === diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 53966a87f3..6174b36e49 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -302,7 +302,6 @@ $wgAutoloadLocalClasses = array( 'ApiQueryLangLinks' => 'includes/api/ApiQueryLangLinks.php', 'ApiQueryLinks' => 'includes/api/ApiQueryLinks.php', 'ApiQueryLogEvents' => 'includes/api/ApiQueryLogEvents.php', - 'ApiQueryQuerypage' => 'includes/api/ApiQueryQuerypage.php', 'ApiQueryProtectedTitles' => 'includes/api/ApiQueryProtectedTitles.php', 'ApiQueryRandom' => 'includes/api/ApiQueryRandom.php', 'ApiQueryRecentChanges'=> 'includes/api/ApiQueryRecentChanges.php', diff --git a/includes/QueryPage.php b/includes/QueryPage.php index 0d84235e49..a8abee3385 100644 --- a/includes/QueryPage.php +++ b/includes/QueryPage.php @@ -176,11 +176,12 @@ class QueryPage { * Formats the result as something that can be understood by the API. * Defaults to setting id, ns and title */ - function formatApiResult( $row ) { + function formatApiResult( $result ) { $title = Title::makeTitle( $row->namespace, $row->title ); return array( - 'ns' => intval( $title->getNamespace() ), - 'title' => $title->getPrefixedText(), + 'pageid' => intval( $row->id ), + 'ns' => intval( $title->getNamespace() ), + 'title' => $title->getPrefixedText(), ); } @@ -360,7 +361,7 @@ class QueryPage { * 'count' => number of results, * 'dbr' => the database used for fetching the data */ - public function reallyDoQuery( $offset, $limit ) { + protected function reallyDoQuery( $offset, $limit ) { $result = array( 'disabled' => false ); $this->offset = $offset; diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php index 4836533e6d..e3719e0d50 100644 --- a/includes/api/ApiQuery.php +++ b/includes/api/ApiQuery.php @@ -81,7 +81,6 @@ class ApiQuery extends ApiBase { 'users' => 'ApiQueryUsers', 'random' => 'ApiQueryRandom', 'protectedtitles' => 'ApiQueryProtectedTitles', - 'querypage' => 'ApiQueryQuerypage', ); private $mQueryMetaModules = array ( diff --git a/includes/api/ApiQueryQuerypage.php b/includes/api/ApiQueryQuerypage.php deleted file mode 100644 index 11eec9db96..0000000000 --- a/includes/api/ApiQueryQuerypage.php +++ /dev/null @@ -1,154 +0,0 @@ - - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * http://www.gnu.org/copyleft/gpl.html - */ - -if (!defined('MEDIAWIKI')) { - // Eclipse helper - will be ignored in production - require_once ('ApiQueryBase.php'); -} - -/** - * Query module to access querypages - * - * @ingroup API - */ -class ApiQueryQuerypage extends ApiQueryBase { - static $queryPages = array( - 'ancientpages' => 'AncientPagesPage', - 'brokenredirects' => 'BrokenRedirectsPage', - 'deadendpages' => 'DeadendPagesPage', - 'disambiguations' => 'DisambiguationsPage', - ); - - public function __construct($query, $moduleName) { - parent :: __construct($query, $moduleName, 'qp'); - } - - public function execute() { - $this->run(); - } - - public function executeGenerator($resultPageSet) { - $this->run( $resultPageSet ); - } - - private function run($resultPageSet = null) { - $params = $this->extractRequestParams(); - $offset = $params['offset']; - $limit = $params['limit']; - - // Try to find an entry in $wgQueryPages - $name = $params['querypage']; - if ( is_null( $name ) ) - $this->dieUsageMsg( array( 'missingparam', 'querypage' ) ); - if ( !isset( self::$queryPages[$name] ) ) - $this->dieUsage( 'Querypage unrecognized', 'unknownquerypage' ); - - // 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 = $queryPage->formatApiResult( $row ); - $fit = $apiResult->addValue( $resultPath, null, $vals ); - if( !$fit ) - { - $this->setContinueEnumParameter( 'offset', $offset + $count ); - break; - } - } else { - // Generator mode; not yet supported - $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 ( - ApiBase :: PARAM_DFLT => 10, - ApiBase :: PARAM_TYPE => 'limit', - ApiBase :: PARAM_MIN => 1, - ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1, - ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2 - ), - 'querypage' => array( - ApiBase :: PARAM_TYPE => array_keys( self::$queryPages ) - ), - ); - } - - public function getParamDescription() { - return array ( - 'offset' => 'The offset to start enumerating from.', - 'limit' => 'How many total pages to return.', - 'querypage' => 'Which querypage to use', - ); - } - - public function getDescription() { - return 'Query one of the builtin query pages.'; - } - - protected function getExamples() { - return array ( - ' Query a list of broken redirects', - ' api.php?action=query&list=querypage&qpquerypage=brokenredirects', - ); - } - - public function getVersion() { - return __CLASS__ . ': $Id:$'; - } -} \ No newline at end of file diff --git a/includes/specials/SpecialAncientpages.php b/includes/specials/SpecialAncientpages.php index 0cbf839282..4738a1a066 100644 --- a/includes/specials/SpecialAncientpages.php +++ b/includes/specials/SpecialAncientpages.php @@ -62,10 +62,6 @@ 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 0c5c7babf8..0a728b6860 100644 --- a/includes/specials/SpecialDisambiguations.php +++ b/includes/specials/SpecialDisambiguations.php @@ -94,12 +94,6 @@ 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; - } } /**