From: Jack Phoenix Date: Wed, 24 Feb 2010 13:34:11 +0000 (+0000) Subject: API: fix copyright symbol, coding style cleanup, more braces X-Git-Tag: 1.31.0-rc.0~37625 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=96b4f302af4b3c074b0a6c9c6054899230fb388a;p=lhc%2Fweb%2Fwiklou.git API: fix copyright symbol, coding style cleanup, more braces --- diff --git a/includes/api/ApiPurge.php b/includes/api/ApiPurge.php index 6bcecc773d..5c83d34fa4 100644 --- a/includes/api/ApiPurge.php +++ b/includes/api/ApiPurge.php @@ -1,11 +1,11 @@ extractRequestParams(); - if ( !$wgUser->isAllowed( 'purge' ) ) + if ( !$wgUser->isAllowed( 'purge' ) ) { $this->dieUsageMsg( array( 'cantpurge' ) ); - if ( !isset( $params['titles'] ) ) + } + if ( !isset( $params['titles'] ) ) { $this->dieUsageMsg( array( 'missingparam', 'titles' ) ); + } $result = array(); foreach ( $params['titles'] as $t ) { $r = array(); $title = Title::newFromText( $t ); - if ( !$title instanceof Title ) - { + if ( !$title instanceof Title ) { $r['title'] = $t; $r['invalid'] = ''; $result[] = $r; continue; } ApiQueryBase::addTitleInfo( $r, $title ); - if ( !$title->exists() ) - { + if ( !$title->exists() ) { $r['missing'] = ''; $result[] = $r; continue; @@ -84,30 +84,30 @@ class ApiPurge extends ApiBase { } public function getAllowedParams() { - return array ( + return array( 'titles' => array( - ApiBase :: PARAM_ISMULTI => true + ApiBase::PARAM_ISMULTI => true ) ); } public function getParamDescription() { - return array ( + return array( 'titles' => 'A list of titles', ); } public function getDescription() { - return array ( + return array( 'Purge the cache for the given titles.' ); } - - public function getPossibleErrors() { + + public function getPossibleErrors() { return array_merge( parent::getPossibleErrors(), array( array( 'cantpurge' ), array( 'missingparam', 'titles' ), - ) ); + ) ); } protected function getExamples() { diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php index 38f79aac51..16e0352601 100644 --- a/includes/api/ApiQuery.php +++ b/includes/api/ApiQuery.php @@ -1,11 +1,11 @@ @gmail.com + * Copyright © 2006 Yuri Astrakhan @gmail.com * * 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 @@ -25,7 +25,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { // Eclipse helper - will be ignored in production - require_once ( 'ApiBase.php' ); + require_once( 'ApiBase.php' ); } /** @@ -45,7 +45,7 @@ class ApiQuery extends ApiBase { private $mPageSet; private $params, $redirect; - private $mQueryPropModules = array ( + private $mQueryPropModules = array( 'info' => 'ApiQueryInfo', 'revisions' => 'ApiQueryRevisions', 'links' => 'ApiQueryLinks', @@ -59,7 +59,7 @@ class ApiQuery extends ApiBase { 'duplicatefiles' => 'ApiQueryDuplicateFiles', ); - private $mQueryListModules = array ( + private $mQueryListModules = array( 'allimages' => 'ApiQueryAllimages', 'allpages' => 'ApiQueryAllpages', 'alllinks' => 'ApiQueryAllLinks', @@ -84,7 +84,7 @@ class ApiQuery extends ApiBase { 'protectedtitles' => 'ApiQueryProtectedTitles', ); - private $mQueryMetaModules = array ( + private $mQueryMetaModules = array( 'siteinfo' => 'ApiQuerySiteinfo', 'userinfo' => 'ApiQueryUserInfo', 'allmessages' => 'ApiQueryAllmessages', @@ -94,13 +94,13 @@ class ApiQuery extends ApiBase { private $mNamedDB = array(); public function __construct( $main, $action ) { - parent :: __construct( $main, $action ); + parent::__construct( $main, $action ); // Allow custom modules to be added in LocalSettings.php global $wgAPIPropModules, $wgAPIListModules, $wgAPIMetaModules; - self :: appendUserModules( $this->mQueryPropModules, $wgAPIPropModules ); - self :: appendUserModules( $this->mQueryListModules, $wgAPIListModules ); - self :: appendUserModules( $this->mQueryMetaModules, $wgAPIMetaModules ); + self::appendUserModules( $this->mQueryPropModules, $wgAPIPropModules ); + self::appendUserModules( $this->mQueryListModules, $wgAPIListModules ); + self::appendUserModules( $this->mQueryMetaModules, $wgAPIMetaModules ); $this->mPropModuleNames = array_keys( $this->mQueryPropModules ); $this->mListModuleNames = array_keys( $this->mQueryListModules ); @@ -129,7 +129,7 @@ class ApiQuery extends ApiBase { * @return Database */ public function getDB() { - if ( !isset ( $this->mSlaveDB ) ) { + if ( !isset( $this->mSlaveDB ) ) { $this->profileDBIn(); $this->mSlaveDB = wfGetDB( DB_SLAVE, 'api' ); $this->profileDBOut(); @@ -176,10 +176,12 @@ class ApiQuery extends ApiBase { // If &exportnowrap is set, use the raw formatter if ( $this->getParameter( 'export' ) && $this->getParameter( 'exportnowrap' ) ) + { return new ApiFormatRaw( $this->getMain(), $this->getMain()->createPrinterByName( 'xml' ) ); - else + } else { return null; + } } /** @@ -193,7 +195,6 @@ class ApiQuery extends ApiBase { * #5 Execute all requested modules */ public function execute() { - $this->params = $this->extractRequestParams(); $this->redirects = $this->params['redirects']; @@ -201,13 +202,13 @@ class ApiQuery extends ApiBase { $this->mPageSet = new ApiPageSet( $this, $this->redirects ); // Instantiate requested modules - $modules = array (); + $modules = array(); $this->InstantiateModules( $modules, 'prop', $this->mQueryPropModules ); $this->InstantiateModules( $modules, 'list', $this->mQueryListModules ); $this->InstantiateModules( $modules, 'meta', $this->mQueryMetaModules ); // If given, execute generator to substitute user supplied data with generated data. - if ( isset ( $this->params['generator'] ) ) { + if ( isset( $this->params['generator'] ) ) { $this->executeGeneratorModule( $this->params['generator'], $modules ); } else { // Append custom fields and populate page/revision information @@ -249,9 +250,11 @@ class ApiQuery extends ApiBase { */ private function InstantiateModules( &$modules, $param, $moduleList ) { $list = @$this->params[$param]; - if ( !is_null ( $list ) ) - foreach ( $list as $moduleName ) + if ( !is_null ( $list ) ) { + foreach ( $list as $moduleName ) { $modules[] = new $moduleList[$moduleName] ( $this, $moduleName ); + } + } } /** @@ -260,7 +263,6 @@ class ApiQuery extends ApiBase { * and missing or invalid title/pageids/revids. */ private function outputGeneralPageInfo() { - $pageSet = $this->getPageSet(); $result = $this->getResult(); @@ -269,9 +271,9 @@ class ApiQuery extends ApiBase { // and the maximum result size must be even higher than that. // Title normalizations - $normValues = array (); + $normValues = array(); foreach ( $pageSet->getNormalizedTitles() as $rawTitleStr => $titleStr ) { - $normValues[] = array ( + $normValues[] = array( 'from' => $rawTitleStr, 'to' => $titleStr ); @@ -283,9 +285,9 @@ class ApiQuery extends ApiBase { } // Interwiki titles - $intrwValues = array (); + $intrwValues = array(); foreach ( $pageSet->getInterwikiTitles() as $rawTitleStr => $interwikiStr ) { - $intrwValues[] = array ( + $intrwValues[] = array( 'title' => $rawTitleStr, 'iw' => $interwikiStr ); @@ -297,9 +299,9 @@ class ApiQuery extends ApiBase { } // Show redirect information - $redirValues = array (); + $redirValues = array(); foreach ( $pageSet->getRedirectTitles() as $titleStrFrom => $titleStrTo ) { - $redirValues[] = array ( + $redirValues[] = array( 'from' => strval( $titleStrFrom ), 'to' => $titleStrTo ); @@ -315,9 +317,9 @@ class ApiQuery extends ApiBase { // $missingRevIDs = $pageSet->getMissingRevisionIDs(); if ( count( $missingRevIDs ) ) { - $revids = array (); + $revids = array(); foreach ( $missingRevIDs as $revid ) { - $revids[$revid] = array ( + $revids[$revid] = array( 'revid' => $revid ); } @@ -328,21 +330,22 @@ class ApiQuery extends ApiBase { // // Page elements // - $pages = array (); + $pages = array(); // Report any missing titles foreach ( $pageSet->getMissingTitles() as $fakeId => $title ) { $vals = array(); - ApiQueryBase :: addTitleInfo( $vals, $title ); + ApiQueryBase::addTitleInfo( $vals, $title ); $vals['missing'] = ''; $pages[$fakeId] = $vals; } // Report any invalid titles - foreach ( $pageSet->getInvalidTitles() as $fakeId => $title ) + foreach ( $pageSet->getInvalidTitles() as $fakeId => $title ) { $pages[$fakeId] = array( 'title' => $title, 'invalid' => '' ); + } // Report any missing page ids foreach ( $pageSet->getMissingPageIDs() as $pageid ) { - $pages[$pageid] = array ( + $pages[$pageid] = array( 'pageid' => $pageid, 'missing' => '' ); @@ -352,12 +355,11 @@ class ApiQuery extends ApiBase { foreach ( $pageSet->getGoodTitles() as $pageid => $title ) { $vals = array(); $vals['pageid'] = $pageid; - ApiQueryBase :: addTitleInfo( $vals, $title ); + ApiQueryBase::addTitleInfo( $vals, $title ); $pages[$pageid] = $vals; } if ( count( $pages ) ) { - if ( $this->params['indexpageids'] ) { $pageIDs = array_keys( $pages ); // json treats all map keys as strings - converting to match @@ -375,9 +377,11 @@ class ApiQuery extends ApiBase { // output with an ob ob_start(); $exporter->openStream(); - foreach ( @$pageSet->getGoodTitles() as $title ) - if ( $title->userCanRead() ) + foreach ( @$pageSet->getGoodTitles() as $title ) { + if ( $title->userCanRead() ) { $exporter->pageByTitle( $title ); + } + } $exporter->closeStream(); $exportxml = ob_get_contents(); ob_end_clean(); @@ -407,14 +411,13 @@ class ApiQuery extends ApiBase { * @param $modules array of module objects */ protected function executeGeneratorModule( $generatorName, $modules ) { - // Find class that implements requested generator - if ( isset ( $this->mQueryListModules[$generatorName] ) ) { + if ( isset( $this->mQueryListModules[$generatorName] ) ) { $className = $this->mQueryListModules[$generatorName]; - } elseif ( isset ( $this->mQueryPropModules[$generatorName] ) ) { + } elseif ( isset( $this->mQueryPropModules[$generatorName] ) ) { $className = $this->mQueryPropModules[$generatorName]; } else { - ApiBase :: dieDebug( __METHOD__, "Unknown generator=$generatorName" ); + ApiBase::dieDebug( __METHOD__, "Unknown generator=$generatorName" ); } // Generator results @@ -422,8 +425,9 @@ class ApiQuery extends ApiBase { // Create and execute the generator $generator = new $className ( $this, $generatorName ); - if ( !$generator instanceof ApiQueryGeneratorBase ) - $this->dieUsage( "Module $generatorName cannot be used as a generator", "badgenerator" ); + if ( !$generator instanceof ApiQueryGeneratorBase ) { + $this->dieUsage( "Module $generatorName cannot be used as a generator", 'badgenerator' ); + } $generator->setGeneratorMode(); @@ -446,21 +450,21 @@ class ApiQuery extends ApiBase { } public function getAllowedParams() { - return array ( - 'prop' => array ( - ApiBase :: PARAM_ISMULTI => true, - ApiBase :: PARAM_TYPE => $this->mPropModuleNames + return array( + 'prop' => array( + ApiBase::PARAM_ISMULTI => true, + ApiBase::PARAM_TYPE => $this->mPropModuleNames ), - 'list' => array ( - ApiBase :: PARAM_ISMULTI => true, - ApiBase :: PARAM_TYPE => $this->mListModuleNames + 'list' => array( + ApiBase::PARAM_ISMULTI => true, + ApiBase::PARAM_TYPE => $this->mListModuleNames ), - 'meta' => array ( - ApiBase :: PARAM_ISMULTI => true, - ApiBase :: PARAM_TYPE => $this->mMetaModuleNames + 'meta' => array( + ApiBase::PARAM_ISMULTI => true, + ApiBase::PARAM_TYPE => $this->mMetaModuleNames ), - 'generator' => array ( - ApiBase :: PARAM_TYPE => $this->mAllowedGenerators + 'generator' => array( + ApiBase::PARAM_TYPE => $this->mAllowedGenerators ), 'redirects' => false, 'indexpageids' => false, @@ -474,13 +478,12 @@ class ApiQuery extends ApiBase { * @return string */ public function makeHelpMsg() { - $msg = ''; // Make sure the internal object is empty // (just in case a sub-module decides to optimize during instantiation) $this->mPageSet = null; - $this->mAllowedGenerators = array(); // Will be repopulated + $this->mAllowedGenerators = array(); // Will be repopulated $astriks = str_repeat( '--- ', 8 ); $astriks2 = str_repeat( '*** ', 10 ); @@ -495,7 +498,7 @@ class ApiQuery extends ApiBase { // Perform the base call last because the $this->mAllowedGenerators // will be updated inside makeHelpMsgHelper() // Use parent to make default message for the query module - $msg = parent :: makeHelpMsg() . $msg; + $msg = parent::makeHelpMsg() . $msg; return $msg; } @@ -507,16 +510,16 @@ class ApiQuery extends ApiBase { * @return string */ private function makeHelpMsgHelper( $moduleList, $paramName ) { - - $moduleDescriptions = array (); + $moduleDescriptions = array(); foreach ( $moduleList as $moduleName => $moduleClass ) { $module = new $moduleClass ( $this, $moduleName, null ); $msg = ApiMain::makeHelpMsgHeader( $module, $paramName ); $msg2 = $module->makeHelpMsg(); - if ( $msg2 !== false ) + if ( $msg2 !== false ) { $msg .= $msg2; + } if ( $module instanceof ApiQueryGeneratorBase ) { $this->mAllowedGenerators[] = $moduleName; $msg .= "Generator:\n This module may be used as a generator\n"; @@ -533,7 +536,7 @@ class ApiQuery extends ApiBase { */ public function makeHelpMsgParameters() { $psModule = new ApiPageSet( $this ); - return $psModule->makeHelpMsgParameters() . parent :: makeHelpMsgParameters(); + return $psModule->makeHelpMsgParameters() . parent::makeHelpMsgParameters(); } public function shouldCheckMaxlag() { @@ -541,7 +544,7 @@ class ApiQuery extends ApiBase { } public function getParamDescription() { - return array ( + return array( 'prop' => 'Which properties to get for the titles/revisions/pageids', 'list' => 'Which lists to get', 'meta' => 'Which meta data to get about the site', @@ -555,13 +558,13 @@ class ApiQuery extends ApiBase { } public function getDescription() { - return array ( + return array( 'Query API module allows applications to get needed pieces of data from the MediaWiki databases,', 'and is loosely based on the old query.php interface.', 'All data modifications will first have to use query to acquire a token to prevent abuse from malicious sites.' ); } - + public function getPossibleErrors() { return array_merge( parent::getPossibleErrors(), array( array( 'code' => 'badgenerator', 'info' => 'Module $generatorName cannot be used as a generator' ), @@ -569,7 +572,7 @@ class ApiQuery extends ApiBase { } protected function getExamples() { - return array ( + return array( 'api.php?action=query&prop=revisions&meta=siteinfo&titles=Main%20Page&rvprop=user|comment', 'api.php?action=query&generator=allpages&gapprefix=API/&prop=revisions', ); @@ -577,7 +580,7 @@ class ApiQuery extends ApiBase { public function getVersion() { $psModule = new ApiPageSet( $this ); - $vers = array (); + $vers = array(); $vers[] = __CLASS__ . ': $Id$'; $vers[] = $psModule->getVersion(); return $vers; diff --git a/includes/api/ApiQueryAllCategories.php b/includes/api/ApiQueryAllCategories.php index f6a6421294..5a5298d670 100644 --- a/includes/api/ApiQueryAllCategories.php +++ b/includes/api/ApiQueryAllCategories.php @@ -1,11 +1,11 @@ .@home.nl + * Copyright © 2007 Roan Kattouw .@home.nl * * 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 @@ -25,7 +25,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { // Eclipse helper - will be ignored in production - require_once ( 'ApiQueryBase.php' ); + require_once( 'ApiQueryBase.php' ); } /** @@ -37,7 +37,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { class ApiQueryAllCategories extends ApiQueryGeneratorBase { public function __construct( $query, $moduleName ) { - parent :: __construct( $query, $moduleName, 'ac' ); + parent::__construct( $query, $moduleName, 'ac' ); } public function execute() { @@ -49,7 +49,6 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase { } private function run( $resultPageSet = null ) { - $db = $this->getDB(); $params = $this->extractRequestParams(); @@ -59,16 +58,16 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase { $dir = ( $params['dir'] == 'descending' ? 'older' : 'newer' ); $from = ( is_null( $params['from'] ) ? null : $this->titlePartToKey( $params['from'] ) ); $this->addWhereRange( 'cat_title', $dir, $from, null ); - if ( isset ( $params['prefix'] ) ) + if ( isset( $params['prefix'] ) ) { $this->addWhere( 'cat_title' . $db->buildLike( $this->titlePartToKey( $params['prefix'] ), $db->anyString() ) ); + } $this->addOption( 'LIMIT', $params['limit'] + 1 ); $this->addOption( 'ORDER BY', 'cat_title' . ( $params['dir'] == 'descending' ? ' DESC' : '' ) ); $prop = array_flip( $params['prop'] ); $this->addFieldsIf( array( 'cat_pages', 'cat_subcats', 'cat_files' ), isset( $prop['size'] ) ); - if ( isset( $prop['hidden'] ) ) - { + if ( isset( $prop['hidden'] ) ) { $this->addTables( array( 'page', 'page_props' ) ); $this->addJoinConds( array( 'page' => array( 'LEFT JOIN', array( @@ -97,9 +96,9 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase { // Normalize titles $titleObj = Title::makeTitle( NS_CATEGORY, $row->cat_title ); - if ( !is_null( $resultPageSet ) ) + if ( !is_null( $resultPageSet ) ) { $pages[] = $titleObj->getPrefixedText(); - else { + } else { $item = array(); $result->setContent( $item, $titleObj->getText() ); if ( isset( $prop['size'] ) ) { @@ -108,11 +107,11 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase { $item['files'] = intval( $row->cat_files ); $item['subcats'] = intval( $row->cat_subcats ); } - if ( isset( $prop['hidden'] ) && $row->cat_hidden ) + if ( isset( $prop['hidden'] ) && $row->cat_hidden ) { $item['hidden'] = ''; + } $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $item ); - if ( !$fit ) - { + if ( !$fit ) { $this->setContinueEnumParameter( 'from', $this->keyToTitle( $row->cat_title ) ); break; } @@ -128,33 +127,33 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase { } public function getAllowedParams() { - return array ( + return array( 'from' => null, 'prefix' => null, 'dir' => array( - ApiBase :: PARAM_DFLT => 'ascending', - ApiBase :: PARAM_TYPE => array( + ApiBase::PARAM_DFLT => 'ascending', + ApiBase::PARAM_TYPE => array( 'ascending', 'descending' ), ), - '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 + '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 ), - 'prop' => array ( - ApiBase :: PARAM_TYPE => array( 'size', 'hidden' ), - ApiBase :: PARAM_DFLT => '', - ApiBase :: PARAM_ISMULTI => true + 'prop' => array( + ApiBase::PARAM_TYPE => array( 'size', 'hidden' ), + ApiBase::PARAM_DFLT => '', + ApiBase::PARAM_ISMULTI => true ), ); } public function getParamDescription() { - return array ( + return array( 'from' => 'The category to start enumerating from.', 'prefix' => 'Search for all category titles that begin with this value.', 'dir' => 'Direction to sort in.', @@ -168,7 +167,7 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase { } protected function getExamples() { - return array ( + return array( 'api.php?action=query&list=allcategories&acprop=size', 'api.php?action=query&generator=allcategories&gacprefix=List&prop=info', ); diff --git a/includes/api/ApiQueryAllLinks.php b/includes/api/ApiQueryAllLinks.php index 04ec7ffbaa..9e86e469cf 100644 --- a/includes/api/ApiQueryAllLinks.php +++ b/includes/api/ApiQueryAllLinks.php @@ -1,11 +1,11 @@ @gmail.com + * Copyright © 2006 Yuri Astrakhan @gmail.com * * 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 @@ -25,7 +25,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { // Eclipse helper - will be ignored in production - require_once ( 'ApiQueryBase.php' ); + require_once( 'ApiQueryBase.php' ); } /** @@ -36,7 +36,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { class ApiQueryAllLinks extends ApiQueryGeneratorBase { public function __construct( $query, $moduleName ) { - parent :: __construct( $query, $moduleName, 'al' ); + parent::__construct( $query, $moduleName, 'al' ); } public function execute() { @@ -48,7 +48,6 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase { } private function run( $resultPageSet = null ) { - $db = $this->getDB(); $params = $this->extractRequestParams(); @@ -57,36 +56,43 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase { $fld_title = isset( $prop['title'] ); if ( $params['unique'] ) { - if ( !is_null( $resultPageSet ) ) + if ( !is_null( $resultPageSet ) ) { $this->dieUsage( $this->getModuleName() . ' cannot be used as a generator in unique links mode', 'params' ); - if ( $fld_ids ) + } + if ( $fld_ids ) { $this->dieUsage( $this->getModuleName() . ' cannot return corresponding page ids in unique links mode', 'params' ); + } $this->addOption( 'DISTINCT' ); } $this->addTables( 'pagelinks' ); $this->addWhereFld( 'pl_namespace', $params['namespace'] ); - - if ( !is_null( $params['from'] ) && !is_null( $params['continue'] ) ) + + if ( !is_null( $params['from'] ) && !is_null( $params['continue'] ) ) { $this->dieUsage( 'alcontinue and alfrom cannot be used together', 'params' ); - if ( !is_null( $params['continue'] ) ) - { + } + if ( !is_null( $params['continue'] ) ) { $arr = explode( '|', $params['continue'] ); - if ( count( $arr ) != 2 ) - $this->dieUsage( "Invalid continue parameter", 'badcontinue' ); + if ( count( $arr ) != 2 ) { + $this->dieUsage( 'Invalid continue parameter', 'badcontinue' ); + } $from = $this->getDB()->strencode( $this->titleToKey( $arr[0] ) ); $id = intval( $arr[1] ); - $this->addWhere( "pl_title > '$from' OR " . - "(pl_title = '$from' AND " . - "pl_from > $id)" ); + $this->addWhere( + "pl_title > '$from' OR " . + "(pl_title = '$from' AND " . + "pl_from > $id)" + ); } - if ( !is_null( $params['from'] ) ) + if ( !is_null( $params['from'] ) ) { $this->addWhere( 'pl_title>=' . $db->addQuotes( $this->titlePartToKey( $params['from'] ) ) ); - if ( isset ( $params['prefix'] ) ) + } + if ( isset( $params['prefix'] ) ) { $this->addWhere( 'pl_title' . $db->buildLike( $this->titlePartToKey( $params['prefix'] ), $db->anyString() ) ); + } - $this->addFields( array ( + $this->addFields( array( 'pl_title', ) ); $this->addFieldsIf( 'pl_from', !$params['unique'] ); @@ -94,42 +100,45 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase { $this->addOption( 'USE INDEX', 'pl_namespace' ); $limit = $params['limit']; $this->addOption( 'LIMIT', $limit + 1 ); - if ( $params['unique'] ) + if ( $params['unique'] ) { $this->addOption( 'ORDER BY', 'pl_title' ); - else + } else { $this->addOption( 'ORDER BY', 'pl_title, pl_from' ); + } $res = $this->select( __METHOD__ ); - $pageids = array (); + $pageids = array(); $count = 0; $result = $this->getResult(); while ( $row = $db->fetchObject( $res ) ) { if ( ++ $count > $limit ) { // We've reached the one extra which shows that there are additional pages to be had. Stop here... // TODO: Security issue - if the user has no right to view next title, it will still be shown - if ( $params['unique'] ) + if ( $params['unique'] ) { $this->setContinueEnumParameter( 'from', $this->keyToTitle( $row->pl_title ) ); - else + } else { $this->setContinueEnumParameter( 'continue', $this->keyToTitle( $row->pl_title ) . "|" . $row->pl_from ); + } break; } if ( is_null( $resultPageSet ) ) { $vals = array(); - if ( $fld_ids ) + if ( $fld_ids ) { $vals['fromid'] = intval( $row->pl_from ); + } if ( $fld_title ) { - $title = Title :: makeTitle( $params['namespace'], $row->pl_title ); + $title = Title::makeTitle( $params['namespace'], $row->pl_title ); ApiQueryBase::addTitleInfo( $vals, $title ); } $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals ); - if ( !$fit ) - { - if ( $params['unique'] ) + if ( !$fit ) { + if ( $params['unique'] ) { $this->setContinueEnumParameter( 'from', $this->keyToTitle( $row->pl_title ) ); - else + } else { $this->setContinueEnumParameter( 'continue', $this->keyToTitle( $row->pl_title ) . "|" . $row->pl_from ); + } break; } } else { @@ -146,35 +155,35 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase { } public function getAllowedParams() { - return array ( + return array( 'continue' => null, 'from' => null, 'prefix' => null, 'unique' => false, - 'prop' => array ( - ApiBase :: PARAM_ISMULTI => true, - ApiBase :: PARAM_DFLT => 'title', - ApiBase :: PARAM_TYPE => array ( + 'prop' => array( + ApiBase::PARAM_ISMULTI => true, + ApiBase::PARAM_DFLT => 'title', + ApiBase::PARAM_TYPE => array( 'ids', 'title' ) ), - 'namespace' => array ( - ApiBase :: PARAM_DFLT => 0, - ApiBase :: PARAM_TYPE => 'namespace' + 'namespace' => array( + ApiBase::PARAM_DFLT => 0, + ApiBase::PARAM_TYPE => 'namespace' ), - '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 + '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 ) ); } public function getParamDescription() { - return array ( + return array( 'from' => 'The page title to start enumerating from.', 'prefix' => 'Search for all page titles that begin with this value.', 'unique' => 'Only show unique links. Cannot be used with generator or prop=ids', @@ -188,7 +197,7 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase { public function getDescription() { return 'Enumerate all links that point to a given namespace'; } - + public function getPossibleErrors() { return array_merge( parent::getPossibleErrors(), array( array( 'code' => 'params', 'info' => $this->getModuleName() . ' cannot be used as a generator in unique links mode' ), @@ -199,7 +208,7 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase { } protected function getExamples() { - return array ( + return array( 'api.php?action=query&list=alllinks&alunique&alfrom=B', ); } diff --git a/includes/api/ApiQueryAllUsers.php b/includes/api/ApiQueryAllUsers.php index 2149bd84c7..67153c3234 100644 --- a/includes/api/ApiQueryAllUsers.php +++ b/includes/api/ApiQueryAllUsers.php @@ -1,11 +1,11 @@ @gmail.com + * Copyright © 2007 Yuri Astrakhan @gmail.com * * 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 @@ -25,7 +25,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { // Eclipse helper - will be ignored in production - require_once ( 'ApiQueryBase.php' ); + require_once( 'ApiQueryBase.php' ); } /** @@ -36,7 +36,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { class ApiQueryAllUsers extends ApiQueryBase { public function __construct( $query, $moduleName ) { - parent :: __construct( $query, $moduleName, 'au' ); + parent::__construct( $query, $moduleName, 'au' ); } public function execute() { @@ -58,11 +58,13 @@ class ApiQueryAllUsers extends ApiQueryBase { $this->addTables( 'user', 'u1' ); $useIndex = true; - if ( !is_null( $params['from'] ) ) + if ( !is_null( $params['from'] ) ) { $this->addWhere( 'u1.user_name >= ' . $db->addQuotes( $this->keyToTitle( $params['from'] ) ) ); + } - if ( !is_null( $params['prefix'] ) ) + if ( !is_null( $params['prefix'] ) ) { $this->addWhere( 'u1.user_name' . $db->buildLike( $this->keyToTitle( $params['prefix'] ), $db->anyString() ) ); + } if ( !is_null( $params['group'] ) ) { $useIndex = false; @@ -73,8 +75,9 @@ class ApiQueryAllUsers extends ApiQueryBase { 'ug1.ug_group' => $params['group'] ) ) ) ); } - if ( $params['witheditsonly'] ) + if ( $params['witheditsonly'] ) { $this->addWhere( 'user_editcount > 0' ); + } if ( $fld_groups ) { // Show the groups the given users belong to @@ -113,7 +116,7 @@ class ApiQueryAllUsers extends ApiQueryBase { $res = $this->select( __METHOD__ ); - $data = array (); + $data = array(); $count = 0; $lastUserData = false; $lastUser = false; @@ -127,18 +130,15 @@ class ApiQueryAllUsers extends ApiQueryBase { // to make sure all rows that belong to the same user are received. // while ( true ) { - $row = $db->fetchObject( $res ); $count++; if ( !$row || $lastUser !== $row->user_name ) { // Save the last pass's user data - if ( is_array( $lastUserData ) ) - { + if ( is_array( $lastUserData ) ) { $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $lastUserData ); - if ( !$fit ) - { + if ( !$fit ) { $this->setContinueEnumParameter( 'from', $this->keyToTitle( $lastUserData['name'] ) ); break; @@ -146,8 +146,9 @@ class ApiQueryAllUsers extends ApiQueryBase { } // No more rows left - if ( !$row ) + if ( !$row ) { break; + } if ( $count > $limit ) { // We've reached the one extra which shows that there are additional pages to be had. Stop here... @@ -162,18 +163,20 @@ class ApiQueryAllUsers extends ApiQueryBase { $lastUserData['blockedby'] = $row->blocker_name; $lastUserData['blockreason'] = $row->ipb_reason; } - if ( $fld_editcount ) + if ( $fld_editcount ) { $lastUserData['editcount'] = intval( $row->user_editcount ); - if ( $fld_registration ) + } + if ( $fld_registration ) { $lastUserData['registration'] = $row->user_registration ? wfTimestamp( TS_ISO_8601, $row->user_registration ) : ''; + } } if ( $sqlLimit == $count ) { // BUG! database contains group name that User::getAllGroups() does not return // TODO: should handle this more gracefully - ApiBase :: dieDebug( __METHOD__, + ApiBase::dieDebug( __METHOD__, 'MediaWiki configuration error: the database contains more user groups than known to User::getAllGroups() function' ); } @@ -190,34 +193,34 @@ class ApiQueryAllUsers extends ApiQueryBase { } public function getAllowedParams() { - return array ( + return array( 'from' => null, 'prefix' => null, 'group' => array( - ApiBase :: PARAM_TYPE => User::getAllGroups() + ApiBase::PARAM_TYPE => User::getAllGroups() ), - 'prop' => array ( - ApiBase :: PARAM_ISMULTI => true, - ApiBase :: PARAM_TYPE => array ( + 'prop' => array( + ApiBase::PARAM_ISMULTI => true, + ApiBase::PARAM_TYPE => array( 'blockinfo', 'groups', 'editcount', 'registration' ) ), - '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 + '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 ), 'witheditsonly' => false, ); } public function getParamDescription() { - return array ( + return array( 'from' => 'The user name to start enumerating from.', 'prefix' => 'Search for all page titles that begin with this value.', 'group' => 'Limit users to a given group name', @@ -234,7 +237,7 @@ class ApiQueryAllUsers extends ApiQueryBase { } protected function getExamples() { - return array ( + return array( 'api.php?action=query&list=allusers&aufrom=Y', ); } diff --git a/includes/api/ApiQueryAllimages.php b/includes/api/ApiQueryAllimages.php index 363a65c362..8e6774ef4d 100644 --- a/includes/api/ApiQueryAllimages.php +++ b/includes/api/ApiQueryAllimages.php @@ -1,11 +1,11 @@ mRepo = RepoGroup::singleton()->getLocalRepo(); } - + /** * Overide parent method to make sure to make sure the repo's DB is used * which may not necesarilly be the same as the local DB. - * + * * TODO: allow querying non-local repos. */ protected function getDB() { @@ -56,16 +56,18 @@ class ApiQueryAllimages extends ApiQueryGeneratorBase { } public function executeGenerator( $resultPageSet ) { - if ( $resultPageSet->isResolvingRedirects() ) + if ( $resultPageSet->isResolvingRedirects() ) { $this->dieUsage( 'Use "gaifilterredir=nonredirects" option instead of "redirects" when using allimages as a generator', 'params' ); + } $this->run( $resultPageSet ); } private function run( $resultPageSet = null ) { $repo = $this->mRepo; - if ( !$repo instanceof LocalRepo ) + if ( !$repo instanceof LocalRepo ) { $this->dieUsage( 'Local file repository does not support querying all images', 'unsupportedrepo' ); + } $db = $this->getDB(); @@ -75,14 +77,14 @@ class ApiQueryAllimages extends ApiQueryGeneratorBase { $dir = ( $params['dir'] == 'descending' ? 'older' : 'newer' ); $from = ( is_null( $params['from'] ) ? null : $this->titlePartToKey( $params['from'] ) ); $this->addWhereRange( 'img_name', $dir, $from, null ); - if ( isset ( $params['prefix'] ) ) + if ( isset( $params['prefix'] ) ) $this->addWhere( 'img_name' . $db->buildLike( $this->titlePartToKey( $params['prefix'] ), $db->anyString() ) ); - if ( isset ( $params['minsize'] ) ) { + if ( isset( $params['minsize'] ) ) { $this->addWhere( 'img_size>=' . intval( $params['minsize'] ) ); } - if ( isset ( $params['maxsize'] ) ) { + if ( isset( $params['maxsize'] ) ) { $this->addWhere( 'img_size<=' . intval( $params['maxsize'] ) ); } @@ -145,38 +147,38 @@ class ApiQueryAllimages extends ApiQueryGeneratorBase { return array ( 'from' => null, 'prefix' => null, - 'minsize' => array ( - ApiBase :: PARAM_TYPE => 'integer', + 'minsize' => array( + ApiBase::PARAM_TYPE => 'integer', ), - 'maxsize' => array ( - ApiBase :: PARAM_TYPE => 'integer', + 'maxsize' => array( + ApiBase::PARAM_TYPE => 'integer', ), - '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 + '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 ), - 'dir' => array ( - ApiBase :: PARAM_DFLT => 'ascending', - ApiBase :: PARAM_TYPE => array ( + 'dir' => array( + ApiBase::PARAM_DFLT => 'ascending', + ApiBase::PARAM_TYPE => array( 'ascending', 'descending' ) ), 'sha1' => null, 'sha1base36' => null, - 'prop' => array ( - ApiBase :: PARAM_TYPE => ApiQueryImageInfo::getPropertyNames(), - ApiBase :: PARAM_DFLT => 'timestamp|url', - ApiBase :: PARAM_ISMULTI => true + 'prop' => array( + ApiBase::PARAM_TYPE => ApiQueryImageInfo::getPropertyNames(), + ApiBase::PARAM_DFLT => 'timestamp|url', + ApiBase::PARAM_ISMULTI => true ) ); } public function getParamDescription() { - return array ( + return array( 'from' => 'The image title to start enumerating from.', 'prefix' => 'Search for all image titles that begin with this value.', 'dir' => 'The direction in which to list', @@ -192,7 +194,7 @@ class ApiQueryAllimages extends ApiQueryGeneratorBase { public function getDescription() { return 'Enumerate all images sequentially'; } - + public function getPossibleErrors() { return array_merge( parent::getPossibleErrors(), array( array( 'code' => 'params', 'info' => 'Use "gaifilterredir=nonredirects" option instead of "redirects" when using allimages as a generator' ), @@ -201,7 +203,7 @@ class ApiQueryAllimages extends ApiQueryGeneratorBase { } protected function getExamples() { - return array ( + return array( 'Simple Use', ' Show a list of images starting at the letter "B"', ' api.php?action=query&list=allimages&aifrom=B', diff --git a/includes/api/ApiQueryAllmessages.php b/includes/api/ApiQueryAllmessages.php index 4c04a7c68f..da5db4fc27 100644 --- a/includes/api/ApiQueryAllmessages.php +++ b/includes/api/ApiQueryAllmessages.php @@ -1,11 +1,11 @@ @gmail.com + * Copyright © 2006 Yuri Astrakhan @gmail.com * * 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 @@ -25,7 +25,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { // Eclipse helper - will be ignored in production - require_once ( 'ApiQueryBase.php' ); + require_once( 'ApiQueryBase.php' ); } /** @@ -36,18 +36,17 @@ if ( !defined( 'MEDIAWIKI' ) ) { class ApiQueryAllmessages extends ApiQueryBase { public function __construct( $query, $moduleName ) { - parent :: __construct( $query, $moduleName, 'am' ); + parent::__construct( $query, $moduleName, 'am' ); } public function execute() { $params = $this->extractRequestParams(); - if ( !is_null( $params['lang'] ) ) - { + if ( !is_null( $params['lang'] ) ) { global $wgLang; $wgLang = Language::factory( $params['lang'] ); } - + $prop = array_flip( (array)$params['prop'] ); // Determine which messages should we print @@ -64,7 +63,8 @@ class ApiQueryAllmessages extends ApiQueryBase { if ( isset( $params['filter'] ) ) { $messages_filtered = array(); foreach ( $messages_target as $message ) { - if ( strpos( $message, $params['filter'] ) !== false ) { // !== is used because filter can be at the beginnig of the string + // !== is used because filter can be at the beginning of the string + if ( strpos( $message, $params['filter'] ) !== false ) { $messages_filtered[] = $message; } } @@ -77,8 +77,9 @@ class ApiQueryAllmessages extends ApiQueryBase { $result = $this->getResult(); foreach ( $messages_target as $message ) { // Skip all messages up to $params['from'] - if ( $skip && $message === $params['from'] ) + if ( $skip && $message === $params['from'] ) { $skip = false; + } if ( !$skip ) { $a = array( 'name' => $message ); @@ -89,24 +90,25 @@ class ApiQueryAllmessages extends ApiQueryBase { // Check if the parser is enabled: if ( $params['enableparser'] ) { $msg = wfMsgExt( $message, array( 'parsemag' ), $args ); - } else if ( $args ) { + } elseif ( $args ) { $msgString = wfMsgGetKey( $message, true, false, false ); $msg = wfMsgReplaceArgs( $msgString, $args ); } else { $msg = wfMsgGetKey( $message, true, false, false ); } - if ( wfEmptyMsg( $message, $msg ) ) + if ( wfEmptyMsg( $message, $msg ) ) { $a['missing'] = ''; - else { + } else { ApiResult::setContent( $a, $msg ); if ( isset( $prop['default'] ) ) { $default = wfMsgGetKey( $message, false, false, false ); if ( $default !== $msg ) { - if ( wfEmptyMsg( $message, $default ) ) + if ( wfEmptyMsg( $message, $default ) ) { $a['defaultmissing'] = ''; - else + } else { $a['default'] = $default; + } } } } @@ -121,20 +123,20 @@ class ApiQueryAllmessages extends ApiQueryBase { } public function getAllowedParams() { - return array ( - 'messages' => array ( - ApiBase :: PARAM_DFLT => '*', - ApiBase :: PARAM_ISMULTI => true, + return array( + 'messages' => array( + ApiBase::PARAM_DFLT => '*', + ApiBase::PARAM_ISMULTI => true, ), 'prop' => array( - ApiBase :: PARAM_ISMULTI => true, - ApiBase :: PARAM_TYPE => array( + ApiBase::PARAM_ISMULTI => true, + ApiBase::PARAM_TYPE => array( 'default' ) ), 'enableparser' => false, 'args' => array( - ApiBase :: PARAM_ISMULTI => true + ApiBase::PARAM_ISMULTI => true ), 'filter' => array(), 'lang' => null, @@ -143,7 +145,7 @@ class ApiQueryAllmessages extends ApiQueryBase { } public function getParamDescription() { - return array ( + return array( 'messages' => 'Which messages to output. "*" means all messages', 'prop' => 'Which properties to get', 'enableparser' => array( 'Set to enable parser, will preprocess the wikitext of message', @@ -163,7 +165,7 @@ class ApiQueryAllmessages extends ApiQueryBase { return array( 'api.php?action=query&meta=allmessages&amfilter=ipb-', 'api.php?action=query&meta=allmessages&ammessages=august|mainpage&amlang=de', - ); + ); } public function getVersion() { diff --git a/includes/api/ApiQueryAllpages.php b/includes/api/ApiQueryAllpages.php index a8573d828b..c4f86d02dd 100644 --- a/includes/api/ApiQueryAllpages.php +++ b/includes/api/ApiQueryAllpages.php @@ -1,11 +1,11 @@ @gmail.com + * Copyright © 2006 Yuri Astrakhan @gmail.com * * 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 @@ -25,7 +25,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { // Eclipse helper - will be ignored in production - require_once ( 'ApiQueryBase.php' ); + require_once( 'ApiQueryBase.php' ); } /** @@ -36,7 +36,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { class ApiQueryAllpages extends ApiQueryGeneratorBase { public function __construct( $query, $moduleName ) { - parent :: __construct( $query, $moduleName, 'ap' ); + parent::__construct( $query, $moduleName, 'ap' ); } public function execute() { @@ -44,8 +44,9 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { } public function executeGenerator( $resultPageSet ) { - if ( $resultPageSet->isResolvingRedirects() ) + if ( $resultPageSet->isResolvingRedirects() ) { $this->dieUsage( 'Use "gapfilterredir=nonredirects" option instead of "redirects" when using allpages as a generator', 'params' ); + } $this->run( $resultPageSet ); } @@ -57,22 +58,24 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { // Page filters $this->addTables( 'page' ); - - if ( $params['filterredir'] == 'redirects' ) + + if ( $params['filterredir'] == 'redirects' ) { $this->addWhereFld( 'page_is_redirect', 1 ); - else if ( $params['filterredir'] == 'nonredirects' ) + } elseif ( $params['filterredir'] == 'nonredirects' ) { $this->addWhereFld( 'page_is_redirect', 0 ); + } $this->addWhereFld( 'page_namespace', $params['namespace'] ); $dir = ( $params['dir'] == 'descending' ? 'older' : 'newer' ); $from = ( is_null( $params['from'] ) ? null : $this->titlePartToKey( $params['from'] ) ); $this->addWhereRange( 'page_title', $dir, $from, null ); - - if ( isset ( $params['prefix'] ) ) + + if ( isset( $params['prefix'] ) ) { $this->addWhere( 'page_title' . $db->buildLike( $this->titlePartToKey( $params['prefix'] ), $db->anyString() ) ); + } if ( is_null( $resultPageSet ) ) { - $selectFields = array ( + $selectFields = array( 'page_namespace', 'page_title', 'page_id' @@ -83,40 +86,42 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { $this->addFields( $selectFields ); $forceNameTitleIndex = true; - if ( isset ( $params['minsize'] ) ) { + if ( isset( $params['minsize'] ) ) { $this->addWhere( 'page_len>=' . intval( $params['minsize'] ) ); $forceNameTitleIndex = false; } - if ( isset ( $params['maxsize'] ) ) { + if ( isset( $params['maxsize'] ) ) { $this->addWhere( 'page_len<=' . intval( $params['maxsize'] ) ); $forceNameTitleIndex = false; } // Page protection filtering - if ( !empty ( $params['prtype'] ) ) { + if ( !empty( $params['prtype'] ) ) { $this->addTables( 'page_restrictions' ); $this->addWhere( 'page_id=pr_page' ); $this->addWhere( 'pr_expiry>' . $db->addQuotes( $db->timestamp() ) ); $this->addWhereFld( 'pr_type', $params['prtype'] ); - if ( isset ( $params['prlevel'] ) ) { + if ( isset( $params['prlevel'] ) ) { // Remove the empty string and '*' from the prlevel array $prlevel = array_diff( $params['prlevel'], array( '', '*' ) ); - - if ( !empty( $prlevel ) ) + + if ( !empty( $prlevel ) ) { $this->addWhereFld( 'pr_level', $prlevel ); + } } - if ( $params['prfiltercascade'] == 'cascading' ) + if ( $params['prfiltercascade'] == 'cascading' ) { $this->addWhereFld( 'pr_cascade', 1 ); - else if ( $params['prfiltercascade'] == 'noncascading' ) + } elseif ( $params['prfiltercascade'] == 'noncascading' ) { $this->addWhereFld( 'pr_cascade', 0 ); + } $this->addOption( 'DISTINCT' ); $forceNameTitleIndex = false; - } else if ( isset ( $params['prlevel'] ) ) { + } elseif ( isset( $params['prlevel'] ) ) { $this->dieUsage( 'prlevel may not be used without prtype', 'params' ); } @@ -125,7 +130,7 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { $this->addJoinConds( array( 'langlinks' => array( 'LEFT JOIN', 'page_id=ll_from' ) ) ); $this->addWhere( 'll_from IS NULL' ); $forceNameTitleIndex = false; - } else if ( $params['filterlanglinks'] == 'withlanglinks' ) { + } elseif ( $params['filterlanglinks'] == 'withlanglinks' ) { $this->addTables( 'langlinks' ); $this->addWhere( 'page_id=ll_from' ); $this->addOption( 'STRAIGHT_JOIN' ); @@ -135,8 +140,9 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { $forceNameTitleIndex = false; } - if ( $forceNameTitleIndex ) + if ( $forceNameTitleIndex ) { $this->addOption( 'USE INDEX', 'name_title' ); + } $limit = $params['limit']; $this->addOption( 'LIMIT', $limit + 1 ); @@ -153,14 +159,14 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { } if ( is_null( $resultPageSet ) ) { - $title = Title :: makeTitle( $row->page_namespace, $row->page_title ); + $title = Title::makeTitle( $row->page_namespace, $row->page_title ); $vals = array( 'pageid' => intval( $row->page_id ), 'ns' => intval( $title->getNamespace() ), - 'title' => $title->getPrefixedText() ); + 'title' => $title->getPrefixedText() + ); $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals ); - if ( !$fit ) - { + if ( !$fit ) { $this->setContinueEnumParameter( 'from', $this->keyToTitle( $row->page_title ) ); break; } @@ -178,70 +184,70 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { public function getAllowedParams() { global $wgRestrictionTypes, $wgRestrictionLevels; - return array ( + return array( 'from' => null, 'prefix' => null, - 'namespace' => array ( - ApiBase :: PARAM_DFLT => 0, - ApiBase :: PARAM_TYPE => 'namespace', + 'namespace' => array( + ApiBase::PARAM_DFLT => 0, + ApiBase::PARAM_TYPE => 'namespace', ), - 'filterredir' => array ( - ApiBase :: PARAM_DFLT => 'all', - ApiBase :: PARAM_TYPE => array ( + 'filterredir' => array( + ApiBase::PARAM_DFLT => 'all', + ApiBase::PARAM_TYPE => array( 'all', 'redirects', 'nonredirects' ) ), - 'minsize' => array ( - ApiBase :: PARAM_TYPE => 'integer', + 'minsize' => array( + ApiBase::PARAM_TYPE => 'integer', ), - 'maxsize' => array ( - ApiBase :: PARAM_TYPE => 'integer', + 'maxsize' => array( + ApiBase::PARAM_TYPE => 'integer', ), - 'prtype' => array ( - ApiBase :: PARAM_TYPE => $wgRestrictionTypes, - ApiBase :: PARAM_ISMULTI => true + 'prtype' => array( + ApiBase::PARAM_TYPE => $wgRestrictionTypes, + ApiBase::PARAM_ISMULTI => true ), - 'prlevel' => array ( - ApiBase :: PARAM_TYPE => $wgRestrictionLevels, - ApiBase :: PARAM_ISMULTI => true + 'prlevel' => array( + ApiBase::PARAM_TYPE => $wgRestrictionLevels, + ApiBase::PARAM_ISMULTI => true ), - 'prfiltercascade' => array ( - ApiBase :: PARAM_DFLT => 'all', - ApiBase :: PARAM_TYPE => array ( + 'prfiltercascade' => array( + ApiBase::PARAM_DFLT => 'all', + ApiBase::PARAM_TYPE => array( 'cascading', 'noncascading', 'all' ), ), - '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 + '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 ), - 'dir' => array ( - ApiBase :: PARAM_DFLT => 'ascending', - ApiBase :: PARAM_TYPE => array ( + 'dir' => array( + ApiBase::PARAM_DFLT => 'ascending', + ApiBase::PARAM_TYPE => array( 'ascending', 'descending' ) ), 'filterlanglinks' => array( - ApiBase :: PARAM_TYPE => array( + ApiBase::PARAM_TYPE => array( 'withlanglinks', 'withoutlanglinks', 'all' ), - ApiBase :: PARAM_DFLT => 'all' + ApiBase::PARAM_DFLT => 'all' ) ); } public function getParamDescription() { - return array ( + return array( 'from' => 'The page title to start enumerating from.', 'prefix' => 'Search for all page titles that begin with this value.', 'namespace' => 'The namespace to enumerate.', @@ -260,7 +266,7 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { public function getDescription() { return 'Enumerate all pages sequentially in a given namespace'; } - + public function getPossibleErrors() { return array_merge( parent::getPossibleErrors(), array( array( 'code' => 'params', 'info' => 'Use "gapfilterredir=nonredirects" option instead of "redirects" when using allpages as a generator' ), @@ -269,7 +275,7 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { } protected function getExamples() { - return array ( + return array( 'Simple Use', ' Show a list of pages starting at the letter "B"', ' api.php?action=query&list=allpages&apfrom=B', diff --git a/includes/api/ApiQueryBacklinks.php b/includes/api/ApiQueryBacklinks.php index a21502ae9d..b4a3b1bc05 100644 --- a/includes/api/ApiQueryBacklinks.php +++ b/includes/api/ApiQueryBacklinks.php @@ -25,7 +25,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { // Eclipse helper - will be ignored in production - require_once ( "ApiQueryBase.php" ); + require_once( "ApiQueryBase.php" ); } /** @@ -43,18 +43,18 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { private $pageMap, $resultArr; // output element name, database column field prefix, database table - private $backlinksSettings = array ( - 'backlinks' => array ( + private $backlinksSettings = array( + 'backlinks' => array( 'code' => 'bl', 'prefix' => 'pl', 'linktbl' => 'pagelinks' ), - 'embeddedin' => array ( + 'embeddedin' => array( 'code' => 'ei', 'prefix' => 'tl', 'linktbl' => 'templatelinks' ), - 'imageusage' => array ( + 'imageusage' => array( 'code' => 'iu', 'prefix' => 'il', 'linktbl' => 'imagelinks' @@ -65,7 +65,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { extract( $this->backlinksSettings[$moduleName] ); $this->resultArr = array(); - parent :: __construct( $query, $moduleName, $code ); + parent::__construct( $query, $moduleName, $code ); $this->bl_ns = $prefix . '_namespace'; $this->bl_from = $prefix . '_from'; $this->bl_table = $linktbl; @@ -75,14 +75,14 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { if ( $this->hasNS ) { $this->bl_title = $prefix . '_title'; $this->bl_sort = "{$this->bl_ns}, {$this->bl_title}, {$this->bl_from}"; - $this->bl_fields = array ( + $this->bl_fields = array( $this->bl_ns, $this->bl_title ); } else { $this->bl_title = $prefix . '_to'; $this->bl_sort = "{$this->bl_title}, {$this->bl_from}"; - $this->bl_fields = array ( + $this->bl_fields = array( $this->bl_title ); } @@ -105,26 +105,30 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { $db = $this->getDB(); $this->addTables( array( $this->bl_table, 'page' ) ); $this->addWhere( "{$this->bl_from}=page_id" ); - if ( is_null( $resultPageSet ) ) + if ( is_null( $resultPageSet ) ) { $this->addFields( array( 'page_id', 'page_title', 'page_namespace' ) ); - else + } else { $this->addFields( $resultPageSet->getPageTableFields() ); + } $this->addFields( 'page_is_redirect' ); $this->addWhereFld( $this->bl_title, $this->rootTitle->getDBkey() ); - if ( $this->hasNS ) + if ( $this->hasNS ) { $this->addWhereFld( $this->bl_ns, $this->rootTitle->getNamespace() ); + } $this->addWhereFld( 'page_namespace', $this->params['namespace'] ); - if ( !is_null( $this->contID ) ) + if ( !is_null( $this->contID ) ) { $this->addWhere( "{$this->bl_from}>={$this->contID}" ); + } - if ( $this->params['filterredir'] == 'redirects' ) + if ( $this->params['filterredir'] == 'redirects' ) { $this->addWhereFld( 'page_is_redirect', 1 ); - else if ( $this->params['filterredir'] == 'nonredirects' && !$this->redirect ) + } elseif ( $this->params['filterredir'] == 'nonredirects' && !$this->redirect ) { // bug 22245 - Check for !redirect, as filtering nonredirects, when getting what links to them is contradictory $this->addWhereFld( 'page_is_redirect', 0 ); + } $this->addOption( 'LIMIT', $this->params['limit'] + 1 ); $this->addOption( 'ORDER BY', $this->bl_from ); @@ -141,45 +145,48 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { $this->addTables( array( 'page', $this->bl_table ) ); $this->addWhere( "{$this->bl_from}=page_id" ); - if ( is_null( $resultPageSet ) ) + if ( is_null( $resultPageSet ) ) { $this->addFields( array( 'page_id', 'page_title', 'page_namespace', 'page_is_redirect' ) ); - else + } else { $this->addFields( $resultPageSet->getPageTableFields() ); + } $this->addFields( $this->bl_title ); - if ( $this->hasNS ) + if ( $this->hasNS ) { $this->addFields( $this->bl_ns ); + } // We can't use LinkBatch here because $this->hasNS may be false $titleWhere = array(); - foreach ( $this->redirTitles as $t ) + foreach ( $this->redirTitles as $t ) { $titleWhere[] = "{$this->bl_title} = " . $db->addQuotes( $t->getDBkey() ) . - ( $this->hasNS ? " AND {$this->bl_ns} = '{$t->getNamespace()}'" : "" ); + ( $this->hasNS ? " AND {$this->bl_ns} = '{$t->getNamespace()}'" : '' ); + } $this->addWhere( $db->makeList( $titleWhere, LIST_OR ) ); $this->addWhereFld( 'page_namespace', $this->params['namespace'] ); - if ( !is_null( $this->redirID ) ) - { + if ( !is_null( $this->redirID ) ) { $first = $this->redirTitles[0]; $title = $db->strencode( $first->getDBkey() ); $ns = $first->getNamespace(); $from = $this->redirID; - if ( $this->hasNS ) + if ( $this->hasNS ) { $this->addWhere( "{$this->bl_ns} > $ns OR " . "({$this->bl_ns} = $ns AND " . "({$this->bl_title} > '$title' OR " . "({$this->bl_title} = '$title' AND " . "{$this->bl_from} >= $from)))" ); - else + } else { $this->addWhere( "{$this->bl_title} > '$title' OR " . "({$this->bl_title} = '$title' AND " . "{$this->bl_from} >= $from)" ); - + } } - if ( $this->params['filterredir'] == 'redirects' ) + if ( $this->params['filterredir'] == 'redirects' ) { $this->addWhereFld( 'page_is_redirect', 1 ); - else if ( $this->params['filterredir'] == 'nonredirects' ) + } elseif ( $this->params['filterredir'] == 'nonredirects' ) { $this->addWhereFld( 'page_is_redirect', 0 ); + } $this->addOption( 'LIMIT', $this->params['limit'] + 1 ); $this->addOption( 'ORDER BY', $this->bl_sort ); @@ -214,93 +221,91 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { break; } - if ( is_null( $resultPageSet ) ) + if ( is_null( $resultPageSet ) ) { $this->extractRowInfo( $row ); - else - { + } else { $this->pageMap[$row->page_namespace][$row->page_title] = $row->page_id; - if ( $row->page_is_redirect ) + if ( $row->page_is_redirect ) { $this->redirTitles[] = Title::makeTitle( $row->page_namespace, $row->page_title ); + } $resultPageSet->processDbRow( $row ); } } $db->freeResult( $res ); - if ( $this->redirect && count( $this->redirTitles ) ) - { + if ( $this->redirect && count( $this->redirTitles ) ) { $this->resetQueryParams(); $this->prepareSecondQuery( $resultPageSet ); $res = $this->select( __METHOD__ . '::secondQuery' ); $count = 0; - while ( $row = $db->fetchObject( $res ) ) - { - if ( ++$count > $this->params['limit'] ) - { + while ( $row = $db->fetchObject( $res ) ) { + if ( ++$count > $this->params['limit'] ) { // We've reached the one extra which shows that there are additional pages to be had. Stop here... // We need to keep the parent page of this redir in - if ( $this->hasNS ) + if ( $this->hasNS ) { $parentID = $this->pageMap[$row-> { $this->bl_ns } ][$row-> { $this->bl_title } ]; - else - $parentID = $this->pageMap[NS_IMAGE][$row-> { $this->bl_title } ]; + } else { + $parentID = $this->pageMap[NS_IMAGE][$row->{$this->bl_title}]; + } $this->continueStr = $this->getContinueRedirStr( $parentID, $row->page_id ); break; } - if ( is_null( $resultPageSet ) ) + if ( is_null( $resultPageSet ) ) { $this->extractRedirRowInfo( $row ); - else + } else { $resultPageSet->processDbRow( $row ); + } } $db->freeResult( $res ); } if ( is_null( $resultPageSet ) ) { // Try to add the result data in one go and pray that it fits $fit = $this->getResult()->addValue( 'query', $this->getModuleName(), array_values( $this->resultArr ) ); - if ( !$fit ) - { + if ( !$fit ) { // It didn't fit. Add elements one by one until the // result is full. - foreach ( $this->resultArr as $pageID => $arr ) - { + foreach ( $this->resultArr as $pageID => $arr ) { // Add the basic entry without redirlinks first $fit = $this->getResult()->addValue( array( 'query', $this->getModuleName() ), null, array_diff_key( $arr, array( 'redirlinks' => '' ) ) ); - if ( !$fit ) - { + if ( !$fit ) { $this->continueStr = $this->getContinueStr( $pageID ); break; } $hasRedirs = false; - foreach ( (array)@$arr['redirlinks'] as $key => $redir ) - { + foreach ( (array)@$arr['redirlinks'] as $key => $redir ) { $fit = $this->getResult()->addValue( array( 'query', $this->getModuleName(), $pageID, 'redirlinks' ), $key, $redir ); - if ( !$fit ) - { + if ( !$fit ) { $this->continueStr = $this->getContinueRedirStr( $pageID, $redir['pageid'] ); break; } $hasRedirs = true; } - if ( $hasRedirs ) + if ( $hasRedirs ) { $this->getResult()->setIndexedTagName_internal( array( 'query', $this->getModuleName(), $pageID, 'redirlinks' ), $this->bl_code ); - if ( !$fit ) + } + if ( !$fit ) { break; + } } } $this->getResult()->setIndexedTagName_internal( - array( 'query', $this->getModuleName() ), - $this->bl_code ); + array( 'query', $this->getModuleName() ), + $this->bl_code + ); } - if ( !is_null( $this->continueStr ) ) + if ( !is_null( $this->continueStr ) ) { $this->setContinueEnumParameter( 'continue', $this->continueStr ); + } } private function extractRowInfo( $row ) { @@ -308,8 +313,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { $t = Title::makeTitle( $row->page_namespace, $row->page_title ); $a = array( 'pageid' => intval( $row->page_id ) ); ApiQueryBase::addTitleInfo( $a, $t ); - if ( $row->page_is_redirect ) - { + if ( $row->page_is_redirect ) { $a['redirect'] = ''; $this->redirTitles[] = $t; } @@ -317,12 +321,12 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { $this->resultArr[$a['pageid']] = $a; } - private function extractRedirRowInfo( $row ) - { + private function extractRedirRowInfo( $row ) { $a['pageid'] = intval( $row->page_id ); ApiQueryBase::addTitleInfo( $a, Title::makeTitle( $row->page_namespace, $row->page_title ) ); - if ( $row->page_is_redirect ) + if ( $row->page_is_redirect ) { $a['redirect'] = ''; + } $ns = $this->hasNS ? $row-> { $this->bl_ns } : NS_FILE; $parentID = $this->pageMap[$ns][$row-> { $this->bl_title } ]; // Put all the results in an array first @@ -331,10 +335,10 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { } protected function processContinue() { - if ( !is_null( $this->params['continue'] ) ) + if ( !is_null( $this->params['continue'] ) ) { $this->parseContinueParam(); - else { - if ( $this->params['title'] !== "" ) { + } else { + if ( $this->params['title'] !== '' ) { $title = Title::newFromText( $this->params['title'] ); if ( !$title ) { $this->dieUsageMsg( array( 'invalidtitle', $this->params['title'] ) ); @@ -347,8 +351,9 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { } // only image titles are allowed for the root in imageinfo mode - if ( !$this->hasNS && $this->rootTitle->getNamespace() !== NS_FILE ) + if ( !$this->hasNS && $this->rootTitle->getNamespace() !== NS_FILE ) { $this->dieUsage( "The title for {$this->getModuleName()} query must be an image", 'bad_image_title' ); + } } protected function parseContinueParam() { @@ -362,23 +367,27 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { // null stuff out now so we know what's set and what isn't $this->rootTitle = $this->contID = $this->redirID = null; $rootNs = intval( $continueList[0] ); - if ( $rootNs === 0 && $continueList[0] !== '0' ) + if ( $rootNs === 0 && $continueList[0] !== '0' ) { // Illegal continue parameter - $this->dieUsage( "Invalid continue param. You should pass the original value returned by the previous query", "_badcontinue" ); + $this->dieUsage( 'Invalid continue param. You should pass the original value returned by the previous query', '_badcontinue' ); + } $this->rootTitle = Title::makeTitleSafe( $rootNs, $continueList[1] ); - if ( !$this->rootTitle ) - $this->dieUsage( "Invalid continue param. You should pass the original value returned by the previous query", "_badcontinue" ); + if ( !$this->rootTitle ) { + $this->dieUsage( 'Invalid continue param. You should pass the original value returned by the previous query', '_badcontinue' ); + } $contID = intval( $continueList[2] ); - if ( $contID === 0 && $continueList[2] !== '0' ) - $this->dieUsage( "Invalid continue param. You should pass the original value returned by the previous query", "_badcontinue" ); + if ( $contID === 0 && $continueList[2] !== '0' ) { + $this->dieUsage( 'Invalid continue param. You should pass the original value returned by the previous query', '_badcontinue' ); + } $this->contID = $contID; $redirID = intval( @$continueList[3] ); - - if ( $redirID === 0 && @$continueList[3] !== '0' ) + + if ( $redirID === 0 && @$continueList[3] !== '0' ) { // This one isn't required return; + } $this->redirID = $redirID; } @@ -394,47 +403,49 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { } public function getAllowedParams() { - $retval = array ( + $retval = array( 'title' => null, 'continue' => null, - 'namespace' => array ( - ApiBase :: PARAM_ISMULTI => true, - ApiBase :: PARAM_TYPE => 'namespace' + 'namespace' => array( + ApiBase::PARAM_ISMULTI => true, + ApiBase::PARAM_TYPE => 'namespace' ), 'filterredir' => array( - ApiBase :: PARAM_DFLT => 'all', - ApiBase :: PARAM_TYPE => array( + ApiBase::PARAM_DFLT => 'all', + ApiBase::PARAM_TYPE => array( 'all', 'redirects', 'nonredirects' ) ), - '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 + '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 ) ); - if ( $this->getModuleName() == 'embeddedin' ) + if ( $this->getModuleName() == 'embeddedin' ) { return $retval; + } $retval['redirect'] = false; return $retval; } public function getParamDescription() { - $retval = array ( + $retval = array( 'title' => 'Title to search.', 'continue' => 'When more results are available, use this to continue.', 'namespace' => 'The namespace to enumerate.', ); - if ( $this->getModuleName() != 'embeddedin' ) + if ( $this->getModuleName() != 'embeddedin' ) { return array_merge( $retval, array( 'redirect' => 'If linking page is a redirect, find all pages that link to that redirect as well. Maximum limit is halved.', 'filterredir' => "How to filter for redirects. If set to nonredirects when {$this->bl_code}redirect is enabled, this is only applied to the second level", 'limit' => "How many total pages to return. If {$this->bl_code}redirect is enabled, limit applies to each level separately (which means you may get up to 2 * limit results)." ) ); + } return array_merge( $retval, array( 'filterredir' => 'How to filter for redirects', 'limit' => 'How many total pages to return.' @@ -443,17 +454,17 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { public function getDescription() { switch ( $this->getModuleName() ) { - case 'backlinks' : + case 'backlinks': return 'Find all pages that link to the given page'; - case 'embeddedin' : + case 'embeddedin': return 'Find all pages that embed (transclude) the given title'; - case 'imageusage' : + case 'imageusage': return 'Find all pages that use the given image title.'; - default : - ApiBase :: dieDebug( __METHOD__, 'Unknown module name' ); + default: + ApiBase::dieDebug( __METHOD__, 'Unknown module name' ); } } - + public function getPossibleErrors() { return array_merge( parent::getPossibleErrors(), array( array( 'invalidtitle', 'title' ), @@ -464,18 +475,18 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { } protected function getExamples() { - static $examples = array ( - 'backlinks' => array ( - "api.php?action=query&list=backlinks&bltitle=Main%20Page", - "api.php?action=query&generator=backlinks&gbltitle=Main%20Page&prop=info" + static $examples = array( + 'backlinks' => array( + 'api.php?action=query&list=backlinks&bltitle=Main%20Page', + 'api.php?action=query&generator=backlinks&gbltitle=Main%20Page&prop=info' ), - 'embeddedin' => array ( - "api.php?action=query&list=embeddedin&eititle=Template:Stub", - "api.php?action=query&generator=embeddedin&geititle=Template:Stub&prop=info" + 'embeddedin' => array( + 'api.php?action=query&list=embeddedin&eititle=Template:Stub', + 'api.php?action=query&generator=embeddedin&geititle=Template:Stub&prop=info' ), - 'imageusage' => array ( - "api.php?action=query&list=imageusage&iutitle=File:Albert%20Einstein%20Head.jpg", - "api.php?action=query&generator=imageusage&giutitle=File:Albert%20Einstein%20Head.jpg&prop=info" + 'imageusage' => array( + 'api.php?action=query&list=imageusage&iutitle=File:Albert%20Einstein%20Head.jpg', + 'api.php?action=query&generator=imageusage&giutitle=File:Albert%20Einstein%20Head.jpg&prop=info' ) ); diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index cdfb5b9045..917948d075 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -1,11 +1,11 @@ @gmail.com + * Copyright © 2006 Yuri Astrakhan @gmail.com * * 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 @@ -25,7 +25,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { // Eclipse helper - will be ignored in production - require_once ( 'ApiBase.php' ); + require_once( 'ApiBase.php' ); } /** @@ -40,7 +40,7 @@ abstract class ApiQueryBase extends ApiBase { private $mQueryModule, $mDb, $tables, $where, $fields, $options, $join_conds; public function __construct( $query, $moduleName, $paramPrefix = '' ) { - parent :: __construct( $query->getMain(), $moduleName, $paramPrefix ); + parent::__construct( $query->getMain(), $moduleName, $paramPrefix ); $this->mQueryModule = $query; $this->mDb = null; $this->resetQueryParams(); @@ -50,11 +50,11 @@ abstract class ApiQueryBase extends ApiBase { * Blank the internal arrays with query parameters */ protected function resetQueryParams() { - $this->tables = array (); - $this->where = array (); - $this->fields = array (); - $this->options = array (); - $this->join_conds = array (); + $this->tables = array(); + $this->where = array(); + $this->fields = array(); + $this->options = array(); + $this->join_conds = array(); } /** @@ -65,16 +65,18 @@ abstract class ApiQueryBase extends ApiBase { */ protected function addTables( $tables, $alias = null ) { if ( is_array( $tables ) ) { - if ( !is_null( $alias ) ) - ApiBase :: dieDebug( __METHOD__, 'Multiple table aliases not supported' ); + if ( !is_null( $alias ) ) { + ApiBase::dieDebug( __METHOD__, 'Multiple table aliases not supported' ); + } $this->tables = array_merge( $this->tables, $tables ); } else { - if ( !is_null( $alias ) ) + if ( !is_null( $alias ) ) { $tables = $this->getAliasedName( $tables, $alias ); + } $this->tables[] = $tables; } } - + /** * Get the SQL for a table name with alias * @param $table string Table name @@ -84,7 +86,7 @@ abstract class ApiQueryBase extends ApiBase { protected function getAliasedName( $table, $alias ) { return $this->getDB()->tableName( $table ) . ' ' . $alias; } - + /** * Add a set of JOIN conditions to the internal array * @@ -95,8 +97,9 @@ abstract class ApiQueryBase extends ApiBase { * @param $join_conds array JOIN conditions */ protected function addJoinConds( $join_conds ) { - if ( !is_array( $join_conds ) ) + if ( !is_array( $join_conds ) ) { ApiBase::dieDebug( __METHOD__, 'Join conditions have to be arrays' ); + } $this->join_conds = array_merge( $this->join_conds, $join_conds ); } @@ -105,10 +108,11 @@ abstract class ApiQueryBase extends ApiBase { * @param $value mixed Field name or array of field names */ protected function addFields( $value ) { - if ( is_array( $value ) ) + if ( is_array( $value ) ) { $this->fields = array_merge( $this->fields, $value ); - else + } else { $this->fields[] = $value; + } } /** @@ -140,11 +144,12 @@ abstract class ApiQueryBase extends ApiBase { if ( is_array( $value ) ) { // Sanity check: don't insert empty arrays, // Database::makeList() chokes on them - if ( count( $value ) ) + if ( count( $value ) ) { $this->where = array_merge( $this->where, $value ); - } - else + } + } else { $this->where[] = $value; + } } /** @@ -167,10 +172,11 @@ abstract class ApiQueryBase extends ApiBase { * @param $value string Value; ignored if null or empty array; */ protected function addWhereFld( $field, $value ) { - // Use count() to its full documented capabilities to simultaneously + // Use count() to its full documented capabilities to simultaneously // test for null, empty array or empty countable object - if ( count( $value ) ) + if ( count( $value ) ) { $this->where[$field] = $value; + } } /** @@ -191,18 +197,21 @@ abstract class ApiQueryBase extends ApiBase { $before = ( $isDirNewer ? '<=' : '>=' ); $db = $this->getDB(); - if ( !is_null( $start ) ) + if ( !is_null( $start ) ) { $this->addWhere( $field . $after . $db->addQuotes( $start ) ); + } - if ( !is_null( $end ) ) + if ( !is_null( $end ) ) { $this->addWhere( $field . $before . $db->addQuotes( $end ) ); + } if ( $sort ) { $order = $field . ( $isDirNewer ? '' : ' DESC' ); - if ( !isset( $this->options['ORDER BY'] ) ) + if ( !isset( $this->options['ORDER BY'] ) ) { $this->addOption( 'ORDER BY', $order ); - else + } else { $this->addOption( 'ORDER BY', $this->options['ORDER BY'] . ', ' . $order ); + } } } @@ -213,10 +222,11 @@ abstract class ApiQueryBase extends ApiBase { * @param $value string Option value */ protected function addOption( $name, $value = null ) { - if ( is_null( $value ) ) + if ( is_null( $value ) ) { $this->options[] = $name; - else + } else { $this->options[$name] = $value; + } } /** @@ -248,8 +258,9 @@ abstract class ApiQueryBase extends ApiBase { $this->profileDBOut(); global $wgAPIMaxDBRows; - if ( $rowcount > $wgAPIMaxDBRows ) + if ( $rowcount > $wgAPIMaxDBRows ) { return false; + } return true; } @@ -284,7 +295,7 @@ abstract class ApiQueryBase extends ApiBase { /** * Add a sub-element under the page element with the given page ID * @param $pageId int Page ID - * @param $data array Data array à la ApiResult + * @param $data array Data array à la ApiResult * @return bool Whether the element fit in the result */ protected function addPageSubItems( $pageId, $data ) { @@ -294,7 +305,7 @@ abstract class ApiQueryBase extends ApiBase { $this->getModuleName(), $data ); } - + /** * Same as addPageSubItems(), but one element of $data at a time * @param $pageId int Page ID @@ -304,13 +315,15 @@ abstract class ApiQueryBase extends ApiBase { * @return bool Whether the element fit in the result */ protected function addPageSubItem( $pageId, $item, $elemname = null ) { - if ( is_null( $elemname ) ) + if ( is_null( $elemname ) ) { $elemname = $this->getModulePrefix(); + } $result = $this->getResult(); $fit = $result->addValue( array( 'query', 'pages', $pageId, $this->getModuleName() ), null, $item ); - if ( !$fit ) + if ( !$fit ) { return false; + } $result->setIndexedTagName_internal( array( 'query', 'pages', $pageId, $this->getModuleName() ), $elemname ); return true; @@ -334,8 +347,9 @@ abstract class ApiQueryBase extends ApiBase { * @return Database */ protected function getDB() { - if ( is_null( $this->mDb ) ) + if ( is_null( $this->mDb ) ) { $this->mDb = $this->getQuery()->getDB(); + } return $this->mDb; } @@ -345,7 +359,7 @@ abstract class ApiQueryBase extends ApiBase { * @param $name string Name to assign to the database connection * @param $db int One of the DB_* constants * @param $groups array Query groups - * @return Database + * @return Database */ public function selectNamedDB( $name, $db, $groups ) { $this->mDb = $this->getQuery()->getNamedDB( $name, $db, $groups ); @@ -366,11 +380,13 @@ abstract class ApiQueryBase extends ApiBase { */ public function titleToKey( $title ) { // Don't throw an error if we got an empty string - if ( trim( $title ) == '' ) + if ( trim( $title ) == '' ) { return ''; + } $t = Title::newFromText( $title ); - if ( !$t ) + if ( !$t ) { $this->dieUsageMsg( array( 'invalidtitle', $title ) ); + } return $t->getPrefixedDbKey(); } @@ -381,15 +397,17 @@ abstract class ApiQueryBase extends ApiBase { */ public function keyToTitle( $key ) { // Don't throw an error if we got an empty string - if ( trim( $key ) == '' ) + if ( trim( $key ) == '' ) { return ''; + } $t = Title::newFromDbKey( $key ); // This really shouldn't happen but we gotta check anyway - if ( !$t ) + if ( !$t ) { $this->dieUsageMsg( array( 'invalidtitle', $key ) ); + } return $t->getPrefixedText(); } - + /** * An alternative to titleToKey() that doesn't trim trailing spaces * @param $titlePart string Title part with spaces @@ -398,7 +416,7 @@ abstract class ApiQueryBase extends ApiBase { public function titlePartToKey( $titlePart ) { return substr( $this->titleToKey( $titlePart . 'x' ), 0, - 1 ); } - + /** * An alternative to keyToTitle() that doesn't trim trailing spaces * @param $keyPart string Key part with spaces @@ -407,7 +425,7 @@ abstract class ApiQueryBase extends ApiBase { public function keyPartToTitle( $keyPart ) { return substr( $this->keyToTitle( $keyPart . 'x' ), 0, - 1 ); } - + public function getPossibleErrors() { return array_merge( parent::getPossibleErrors(), array( array( 'invalidtitle', 'title' ), @@ -432,7 +450,7 @@ abstract class ApiQueryGeneratorBase extends ApiQueryBase { private $mIsGenerator; public function __construct( $query, $moduleName, $paramPrefix = '' ) { - parent :: __construct( $query, $moduleName, $paramPrefix ); + parent::__construct( $query, $moduleName, $paramPrefix ); $this->mIsGenerator = false; } @@ -450,10 +468,11 @@ abstract class ApiQueryGeneratorBase extends ApiQueryBase { * @return string Prefixed parameter name */ public function encodeParamName( $paramName ) { - if ( $this->mIsGenerator ) - return 'g' . parent :: encodeParamName( $paramName ); - else - return parent :: encodeParamName( $paramName ); + if ( $this->mIsGenerator ) { + return 'g' . parent::encodeParamName( $paramName ); + } else { + return parent::encodeParamName( $paramName ); + } } /**