From c6630e8bbe4e1b847f8f6072f7f4a1b2ea525b46 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Thu, 14 Nov 2013 13:47:20 +0100 Subject: [PATCH] Update formatting on API classes, Part 3 Change-Id: I526be68e21836201c992b391a81f4d41e1fa801e --- includes/api/ApiOpenSearch.php | 1 + includes/api/ApiPageSet.php | 19 +++++++++++++++---- includes/api/ApiParamInfo.php | 1 + includes/api/ApiParse.php | 19 ++++++++++++++++--- includes/api/ApiPatrol.php | 3 ++- includes/api/ApiProtect.php | 11 ++++++----- includes/api/ApiPurge.php | 2 ++ includes/api/ApiQuery.php | 17 +++++++++++++---- includes/api/ApiQueryAllCategories.php | 2 +- includes/api/ApiQueryAllImages.php | 8 +++++--- 10 files changed, 62 insertions(+), 21 deletions(-) diff --git a/includes/api/ApiOpenSearch.php b/includes/api/ApiOpenSearch.php index 315ace3715..433b743a72 100644 --- a/includes/api/ApiOpenSearch.php +++ b/includes/api/ApiOpenSearch.php @@ -40,6 +40,7 @@ class ApiOpenSearch extends ApiBase { if ( in_array( $format, $allowed ) ) { return $this->getMain()->createPrinterByName( $format ); } + return $this->getMain()->createPrinterByName( $allowed[0] ); } diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index b05cb2b67b..cfbc095096 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -244,6 +244,7 @@ class ApiPageSet extends ApiBase { if ( isset( $this->mParams['revids'] ) ) { return 'revids'; } + return null; } @@ -289,6 +290,7 @@ class ApiPageSet extends ApiBase { $this->mRequestedPageFields = array_diff_key( $this->mRequestedPageFields, $pageFlds ); $pageFlds = array_merge( $pageFlds, $this->mRequestedPageFields ); + return array_keys( $pageFlds ); } @@ -391,6 +393,7 @@ class ApiPageSet extends ApiBase { if ( !empty( $values ) && $result ) { $result->setIndexedTagName( $values, 'r' ); } + return $values; } @@ -421,6 +424,7 @@ class ApiPageSet extends ApiBase { if ( !empty( $values ) && $result ) { $result->setIndexedTagName( $values, 'n' ); } + return $values; } @@ -451,6 +455,7 @@ class ApiPageSet extends ApiBase { if ( !empty( $values ) && $result ) { $result->setIndexedTagName( $values, 'c' ); } + return $values; } @@ -487,6 +492,7 @@ class ApiPageSet extends ApiBase { if ( !empty( $values ) && $result ) { $result->setIndexedTagName( $values, 'i' ); } + return $values; } @@ -522,6 +528,7 @@ class ApiPageSet extends ApiBase { if ( !empty( $values ) && $result ) { $result->setIndexedTagName( $values, 'rev' ); } + return $values; } @@ -642,7 +649,7 @@ class ApiPageSet extends ApiBase { // Get pageIDs data from the `page` table $this->profileDBIn(); $res = $db->select( 'page', $this->getPageTableFields(), $set, - __METHOD__ ); + __METHOD__ ); $this->profileDBOut(); // Hack: get the ns:titles stored in array(ns => array(titles)) format @@ -676,7 +683,7 @@ class ApiPageSet extends ApiBase { // Get pageIDs data from the `page` table $this->profileDBIn(); $res = $db->select( 'page', $this->getPageTableFields(), $set, - __METHOD__ ); + __METHOD__ ); $this->profileDBOut(); } @@ -886,6 +893,7 @@ class ApiPageSet extends ApiBase { unset( $this->mPendingRedirectIDs[$id] ); } } + return $lb; } @@ -941,8 +949,9 @@ class ApiPageSet extends ApiBase { // Variants checking global $wgContLang; if ( $this->mConvertTitles && - count( $wgContLang->getVariants() ) > 1 && - !$titleObj->exists() ) { + count( $wgContLang->getVariants() ) > 1 && + !$titleObj->exists() + ) { // Language::findVariantLink will modify titleText and titleObj into // the canonical variant if possible $titleText = is_string( $title ) ? $title : $titleObj->getPrefixedText(); @@ -1040,6 +1049,7 @@ class ApiPageSet extends ApiBase { $result['generator'] = null; } } + return $result; } @@ -1067,6 +1077,7 @@ class ApiPageSet extends ApiBase { sort( $gens ); self::$generators = $gens; } + return self::$generators; } diff --git a/includes/api/ApiParamInfo.php b/includes/api/ApiParamInfo.php index 3e1a7531a3..7ecf71f3f8 100644 --- a/includes/api/ApiParamInfo.php +++ b/includes/api/ApiParamInfo.php @@ -317,6 +317,7 @@ class ApiParamInfo extends ApiBase { sort( $querymodules ); $formatmodules = $this->getMain()->getModuleManager()->getNames( 'format' ); sort( $formatmodules ); + return array( 'modules' => array( ApiBase::PARAM_ISMULTI => true, diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 301affbc7d..91a3a99fa2 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -125,7 +125,7 @@ class ApiParse extends ApiBase { 'action' => 'query', 'redirects' => '', ); - if ( !is_null ( $pageid ) ) { + if ( !is_null( $pageid ) ) { $reqParams['pageids'] = $pageid; } else { // $page $reqParams['titles'] = $page; @@ -219,6 +219,7 @@ class ApiParse extends ApiBase { ApiResult::setContent( $result_array['wikitext'], $this->content->serialize( $format ) ); } $result->addValue( null, $this->getModuleName(), $result_array ); + return; } @@ -300,8 +301,8 @@ class ApiParse extends ApiBase { if ( isset( $prop['displaytitle'] ) ) { $result_array['displaytitle'] = $p_result->getDisplayTitle() ? - $p_result->getDisplayTitle() : - $titleObj->getPrefixedText(); + $p_result->getDisplayTitle() : + $titleObj->getPrefixedText(); } if ( isset( $prop['headitems'] ) || isset( $prop['headhtml'] ) ) { @@ -395,6 +396,7 @@ class ApiParse extends ApiBase { $popts->setIsSectionPreview( $params['sectionpreview'] ); wfProfileOut( __METHOD__ ); + return $popts; } @@ -425,6 +427,7 @@ class ApiParse extends ApiBase { if ( $getWikitext ) { $this->content = $page->getContent( Revision::RAW ); } + return $pout; } } @@ -439,6 +442,7 @@ class ApiParse extends ApiBase { $this->dieUsage( "Sections are not supported by " . $what, 'nosuchsection' ); $section = false; } + return $section; } @@ -456,6 +460,7 @@ class ApiParse extends ApiBase { ApiResult::setContent( $entry, $bits[1] ); $result[] = $entry; } + return $result; } @@ -502,6 +507,7 @@ class ApiParse extends ApiBase { private function categoriesHtml( $categories ) { $context = $this->getContext(); $context->getOutput()->addCategoryLinks( $categories ); + return $context->getSkin()->getCategories(); } @@ -554,6 +560,7 @@ class ApiParse extends ApiBase { $result[] = $entry; } } + return $result; } @@ -573,6 +580,7 @@ class ApiParse extends ApiBase { $result[] = $entry; } } + return $result; } @@ -584,6 +592,7 @@ class ApiParse extends ApiBase { ApiResult::setContent( $entry, $content ); $result[] = $entry; } + return $result; } @@ -595,6 +604,7 @@ class ApiParse extends ApiBase { ApiResult::setContent( $entry, $value ); $result[] = $entry; } + return $result; } @@ -606,6 +616,7 @@ class ApiParse extends ApiBase { ApiResult::setContent( $entry, $link ); $result[] = $entry; } + return $result; } @@ -674,6 +685,7 @@ class ApiParse extends ApiBase { public function getParamDescription() { $p = $this->getModulePrefix(); $wikitext = CONTENT_MODEL_WIKITEXT; + return array( 'text' => "Text to parse. Use {$p}title or {$p}contentmodel to control the content model", 'summary' => 'Summary to parse', @@ -736,6 +748,7 @@ class ApiParse extends ApiBase { public function getDescription() { $p = $this->getModulePrefix(); + return array( 'Parses content and returns parser output', 'See the various prop-Modules of action=query to get information from the current version of a page', diff --git a/includes/api/ApiPatrol.php b/includes/api/ApiPatrol.php index bd2fde2b39..46bd94e29d 100644 --- a/includes/api/ApiPatrol.php +++ b/includes/api/ApiPatrol.php @@ -123,7 +123,8 @@ class ApiPatrol extends ApiBase { 'code' => 'notpatrollable', 'info' => "The revision can't be patrolled as it's too old" ) - ) ); + ) + ); } public function needsToken() { diff --git a/includes/api/ApiProtect.php b/includes/api/ApiProtect.php index 428eef323f..25727d056d 100644 --- a/includes/api/ApiProtect.php +++ b/includes/api/ApiProtect.php @@ -90,9 +90,9 @@ class ApiProtect extends ApiBase { $expiryarray[$p[0]] = $exp; } $resultProtections[] = array( $p[0] => $protections[$p[0]], - 'expiry' => ( $expiryarray[$p[0]] == $db->getInfinity() ? - 'infinite' : - wfTimestamp( TS_ISO_8601, $expiryarray[$p[0]] ) ) ); + 'expiry' => ( $expiryarray[$p[0]] == $db->getInfinity() ? + 'infinite' : + wfTimestamp( TS_ISO_8601, $expiryarray[$p[0]] ) ) ); } $cascade = $params['cascade']; @@ -167,16 +167,17 @@ class ApiProtect extends ApiBase { public function getParamDescription() { $p = $this->getModulePrefix(); + return array( 'title' => "Title of the page you want to (un)protect. Cannot be used together with {$p}pageid", 'pageid' => "ID of the page you want to (un)protect. Cannot be used together with {$p}title", 'token' => 'A protect token previously retrieved through prop=info', 'protections' => 'List of protection levels, formatted action=group (e.g. edit=sysop)', 'expiry' => array( 'Expiry timestamps. If only one timestamp is set, it\'ll be used for all protections.', - 'Use \'infinite\', \'indefinite\' or \'never\', for a never-expiring protection.' ), + 'Use \'infinite\', \'indefinite\' or \'never\', for a never-expiring protection.' ), 'reason' => 'Reason for (un)protecting', 'cascade' => array( 'Enable cascading protection (i.e. protect pages included in this page)', - 'Ignored if not all protection levels are \'sysop\' or \'protect\'' ), + 'Ignored if not all protection levels are \'sysop\' or \'protect\'' ), 'watch' => 'If set, add the page being (un)protected to your watchlist', 'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch', ); diff --git a/includes/api/ApiPurge.php b/includes/api/ApiPurge.php index 0812ba5171..4c7981ee14 100644 --- a/includes/api/ApiPurge.php +++ b/includes/api/ApiPurge.php @@ -139,6 +139,7 @@ class ApiPurge extends ApiBase { if ( !isset( $this->mPageSet ) ) { $this->mPageSet = new ApiPageSet( $this ); } + return $this->mPageSet; } @@ -159,6 +160,7 @@ class ApiPurge extends ApiBase { if ( $flags ) { $result += $this->getPageSet()->getFinalParams( $flags ); } + return $result; } diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php index e03837fc58..ea57196fef 100644 --- a/includes/api/ApiQuery.php +++ b/includes/api/ApiQuery.php @@ -163,6 +163,7 @@ class ApiQuery extends ApiBase { $this->mNamedDB[$name] = wfGetDB( $db, $groups ); $this->profileDBOut(); } + return $this->mNamedDB[$name]; } @@ -181,6 +182,7 @@ class ApiQuery extends ApiBase { */ public function getModules() { wfDeprecated( __METHOD__, '1.21' ); + return $this->getModuleManager()->getNamesWithClasses(); } @@ -197,6 +199,7 @@ class ApiQuery extends ApiBase { $gens[$name] = $class; } } + return $gens; } @@ -216,8 +219,8 @@ class ApiQuery extends ApiBase { public function getCustomPrinter() { // If &exportnowrap is set, use the raw formatter if ( $this->getParameter( 'export' ) && - $this->getParameter( 'exportnowrap' ) ) - { + $this->getParameter( 'exportnowrap' ) + ) { return new ApiFormatRaw( $this->getMain(), $this->getMain()->createPrinterByName( 'xml' ) ); } else { @@ -407,6 +410,7 @@ class ApiQuery extends ApiBase { } } $this->dieContinueUsageIf( $completeModules !== null && count( $tmp ) !== 0 ); + return $modules; } @@ -429,6 +433,7 @@ class ApiQuery extends ApiBase { } else { // private $cacheMode = 'private'; } + return $cacheMode; } @@ -514,10 +519,12 @@ class ApiQuery extends ApiBase { ApiQueryBase::addTitleInfo( $vals, $title ); $vals['special'] = ''; if ( $title->isSpecialPage() && - !SpecialPageFactory::exists( $title->getDBkey() ) ) { + !SpecialPageFactory::exists( $title->getDBkey() ) + ) { $vals['missing'] = ''; } elseif ( $title->getNamespace() == NS_MEDIA && - !wfFindFile( $title ) ) { + !wfFindFile( $title ) + ) { $vals['missing'] = ''; } $pages[$fakeId] = $vals; @@ -566,6 +573,7 @@ class ApiQuery extends ApiBase { $this->mGeneratorContinue = array(); } $this->mGeneratorContinue[$paramName] = $paramValue; + return true; } @@ -638,6 +646,7 @@ class ApiQuery extends ApiBase { if ( $flags ) { $result += $this->getPageSet()->getFinalParams( $flags ); } + return $result; } diff --git a/includes/api/ApiQueryAllCategories.php b/includes/api/ApiQueryAllCategories.php index 3f5c6ee7ce..5ef71f0b31 100644 --- a/includes/api/ApiQueryAllCategories.php +++ b/includes/api/ApiQueryAllCategories.php @@ -109,7 +109,7 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase { $result = $this->getResult(); $count = 0; foreach ( $res as $row ) { - if ( ++ $count > $params['limit'] ) { + if ( ++$count > $params['limit'] ) { // We've reached the one extra which shows that there are additional cats to be had. Stop here... $this->setContinueEnumParameter( 'continue', $row->cat_title ); break; diff --git a/includes/api/ApiQueryAllImages.php b/includes/api/ApiQueryAllImages.php index ccc7a3a29e..5baee8d71b 100644 --- a/includes/api/ApiQueryAllImages.php +++ b/includes/api/ApiQueryAllImages.php @@ -107,7 +107,7 @@ class ApiQueryAllImages extends ApiQueryGeneratorBase { } } if ( $params['filterbots'] != 'all' ) { - $this->dieUsage( "Parameter '{$prefix}filterbots' can only be used with {$prefix}sort=timestamp", 'badparams' ); + $this->dieUsage( "Parameter '{$prefix}filterbots' can only be used with {$prefix}sort=timestamp", 'badparams' ); } // Pagination @@ -156,7 +156,7 @@ class ApiQueryAllImages extends ApiQueryGeneratorBase { 'ug_user = img_user' ) ) ) ); - $groupCond = ( $params['filterbots'] == 'nobots' ? 'NULL': 'NOT NULL' ); + $groupCond = ( $params['filterbots'] == 'nobots' ? 'NULL' : 'NOT NULL' ); $this->addWhere( "ug_group IS $groupCond" ); } } @@ -222,7 +222,7 @@ class ApiQueryAllImages extends ApiQueryGeneratorBase { $count = 0; $result = $this->getResult(); foreach ( $res as $row ) { - if ( ++ $count > $limit ) { + if ( ++$count > $limit ) { // We've reached the one extra which shows that there are additional pages to be had. Stop here... if ( $params['sort'] == 'name' ) { $this->setContinueEnumParameter( 'continue', $row->img_name ); @@ -326,6 +326,7 @@ class ApiQueryAllImages extends ApiQueryGeneratorBase { public function getParamDescription() { $p = $this->getModulePrefix(); + return array( 'sort' => 'Property to sort by', 'dir' => 'The direction in which to list', @@ -368,6 +369,7 @@ class ApiQueryAllImages extends ApiQueryGeneratorBase { public function getPossibleErrors() { $p = $this->getModulePrefix(); + return array_merge( parent::getPossibleErrors(), array( array( 'code' => 'params', 'info' => 'Use "gaifilterredir=nonredirects" option instead of "redirects" when using allimages as a generator' ), array( 'code' => 'badparams', 'info' => "Parameter'{$p}start' can only be used with {$p}sort=timestamp" ), -- 2.20.1