From 789c20044b3a26251626ac77d6dbdf39d4f8b974 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Thu, 14 Nov 2013 13:56:06 +0100 Subject: [PATCH] Update formatting, return of the API classes Change-Id: I8c3a5b4396a1c3bba22f676137f640c6aa3c8960 --- includes/api/ApiQueryLangBacklinks.php | 6 ++--- includes/api/ApiQueryLangLinks.php | 6 ++--- includes/api/ApiQueryLinks.php | 2 ++ includes/api/ApiQueryLogEvents.php | 6 ++++- includes/api/ApiQueryORM.php | 3 +-- includes/api/ApiQueryPageProps.php | 1 + includes/api/ApiQueryProtectedTitles.php | 4 +++- includes/api/ApiQueryQueryPage.php | 1 + includes/api/ApiQueryRandom.php | 5 +++-- includes/api/ApiQueryRecentChanges.php | 28 ++++++++++++++---------- 10 files changed, 38 insertions(+), 24 deletions(-) diff --git a/includes/api/ApiQueryLangBacklinks.php b/includes/api/ApiQueryLangBacklinks.php index 5bd451b6c8..652fa1122f 100644 --- a/includes/api/ApiQueryLangBacklinks.php +++ b/includes/api/ApiQueryLangBacklinks.php @@ -92,14 +92,14 @@ class ApiQueryLangBacklinks extends ApiQueryGeneratorBase { $this->addOption( 'ORDER BY', array( 'll_title' . $sort, 'll_from' . $sort - )); + ) ); } } else { $this->addOption( 'ORDER BY', array( 'll_lang' . $sort, 'll_title' . $sort, 'll_from' . $sort - )); + ) ); } $this->addOption( 'LIMIT', $params['limit'] + 1 ); @@ -111,7 +111,7 @@ class ApiQueryLangBacklinks extends ApiQueryGeneratorBase { $count = 0; $result = $this->getResult(); foreach ( $res as $row ) { - if ( ++ $count > $params['limit'] ) { + if ( ++$count > $params['limit'] ) { // We've reached the one extra which shows that there are additional pages to be had. Stop here... // Continue string preserved in case the redirect query doesn't pass the limit $this->setContinueEnumParameter( 'continue', "{$row->ll_lang}|{$row->ll_title}|{$row->ll_from}" ); diff --git a/includes/api/ApiQueryLangLinks.php b/includes/api/ApiQueryLangLinks.php index aa796e3109..926a1b6c55 100644 --- a/includes/api/ApiQueryLangLinks.php +++ b/includes/api/ApiQueryLangLinks.php @@ -86,9 +86,9 @@ class ApiQueryLangLinks extends ApiQueryBase { $this->addOption( 'ORDER BY', 'll_lang' . $sort ); } else { $this->addOption( 'ORDER BY', array( - 'll_from' . $sort, - 'll_lang' . $sort - )); + 'll_from' . $sort, + 'll_lang' . $sort + ) ); } } diff --git a/includes/api/ApiQueryLinks.php b/includes/api/ApiQueryLinks.php index 937f4f1376..c3a130b40f 100644 --- a/includes/api/ApiQueryLinks.php +++ b/includes/api/ApiQueryLinks.php @@ -212,6 +212,7 @@ class ApiQueryLinks extends ApiQueryGeneratorBase { public function getParamDescription() { $desc = $this->description; + return array( 'namespace' => "Show {$desc}s in this namespace(s) only", 'limit' => "How many {$desc}s to return", @@ -237,6 +238,7 @@ class ApiQueryLinks extends ApiQueryGeneratorBase { public function getExamples() { $desc = $this->description; $name = $this->getModuleName(); + return array( "api.php?action=query&prop={$name}&titles=Main%20Page" => "Get {$desc}s from the [[Main Page]]", "api.php?action=query&generator={$name}&titles=Main%20Page&prop=info" => "Get information about the {$desc} pages in the [[Main Page]]", diff --git a/includes/api/ApiQueryLogEvents.php b/includes/api/ApiQueryLogEvents.php index 1a2719edc7..d17727960b 100644 --- a/includes/api/ApiQueryLogEvents.php +++ b/includes/api/ApiQueryLogEvents.php @@ -168,7 +168,7 @@ class ApiQueryLogEvents extends ApiQueryBase { $res = $this->select( __METHOD__ ); $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... $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->log_timestamp ) ); break; @@ -285,6 +285,7 @@ class ApiQueryLogEvents extends ApiQueryBase { $result->setIndexedTagName_recursive( $logParams, 'param' ); $vals = array_merge( $vals, $logParams ); } + return $vals; } @@ -392,6 +393,7 @@ class ApiQueryLogEvents extends ApiQueryBase { public function getAllowedParams() { global $wgLogTypes, $wgLogActions, $wgLogActionsHandlers; + return array( 'prop' => array( ApiBase::PARAM_ISMULTI => true, @@ -444,6 +446,7 @@ class ApiQueryLogEvents extends ApiQueryBase { public function getParamDescription() { $p = $this->getModulePrefix(); + return array( 'prop' => array( 'Which properties to get', @@ -473,6 +476,7 @@ class ApiQueryLogEvents extends ApiQueryBase { public function getResultProperties() { global $wgLogTypes; + return array( 'ids' => array( 'logid' => 'integer', diff --git a/includes/api/ApiQueryORM.php b/includes/api/ApiQueryORM.php index a23ff06b27..469b2972b9 100644 --- a/includes/api/ApiQueryORM.php +++ b/includes/api/ApiQueryORM.php @@ -104,7 +104,7 @@ abstract class ApiQueryORM extends ApiQueryBase { protected function getParams() { return array_filter( $this->extractRequestParams(), - function( $prop ) { + function ( $prop ) { return isset( $prop ); } ); @@ -260,5 +260,4 @@ abstract class ApiQueryORM extends ApiQueryBase { return array_merge( $this->getTable()->getFieldDescriptions(), $descriptions ); } - } diff --git a/includes/api/ApiQueryPageProps.php b/includes/api/ApiQueryPageProps.php index 2de57106e9..91a8090a04 100644 --- a/includes/api/ApiQueryPageProps.php +++ b/includes/api/ApiQueryPageProps.php @@ -115,6 +115,7 @@ class ApiQueryPageProps extends ApiQueryBase { if ( !$fit ) { $this->setContinueEnumParameter( 'continue', $page ); } + return $fit; } diff --git a/includes/api/ApiQueryProtectedTitles.php b/includes/api/ApiQueryProtectedTitles.php index 222ad0741a..4273c0dea8 100644 --- a/includes/api/ApiQueryProtectedTitles.php +++ b/includes/api/ApiQueryProtectedTitles.php @@ -80,7 +80,7 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase { $titles = array(); foreach ( $res as $row ) { - if ( ++ $count > $params['limit'] ) { + if ( ++$count > $params['limit'] ) { // We've reached the one extra which shows that there are additional pages to be had. Stop here... $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->pt_timestamp ) ); break; @@ -148,6 +148,7 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase { public function getAllowedParams() { global $wgRestrictionLevels; + return array( 'namespace' => array( ApiBase::PARAM_ISMULTI => true, @@ -216,6 +217,7 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase { public function getResultProperties() { global $wgRestrictionLevels; + return array( '' => array( 'ns' => 'namespace', diff --git a/includes/api/ApiQueryQueryPage.php b/includes/api/ApiQueryQueryPage.php index 79fe0498cf..a6e455f836 100644 --- a/includes/api/ApiQueryQueryPage.php +++ b/includes/api/ApiQueryQueryPage.php @@ -138,6 +138,7 @@ class ApiQueryQueryPage extends ApiQueryGeneratorBase { if ( $qp->getRestriction() != '' ) { return 'private'; } + return 'public'; } diff --git a/includes/api/ApiQueryRandom.php b/includes/api/ApiQueryRandom.php index fae33772f2..b1f5ab93c7 100644 --- a/includes/api/ApiQueryRandom.php +++ b/includes/api/ApiQueryRandom.php @@ -83,8 +83,8 @@ class ApiQueryRandom extends ApiQueryGeneratorBase { // Prevent duplicates if ( !in_array( $row->page_id, $this->pageIDs ) ) { $fit = $this->getResult()->addValue( - array( 'query', $this->getModuleName() ), - null, $this->extractRowInfo( $row ) ); + array( 'query', $this->getModuleName() ), + null, $this->extractRowInfo( $row ) ); if ( !$fit ) { // We can't really query-continue a random list. // Return an insanely high value so @@ -131,6 +131,7 @@ class ApiQueryRandom extends ApiQueryGeneratorBase { $vals = array(); $vals['id'] = intval( $row->page_id ); ApiQueryBase::addTitleInfo( $vals, $title ); + return $vals; } diff --git a/includes/api/ApiQueryRecentChanges.php b/includes/api/ApiQueryRecentChanges.php index 8d969fc120..9abe76b494 100644 --- a/includes/api/ApiQueryRecentChanges.php +++ b/includes/api/ApiQueryRecentChanges.php @@ -37,9 +37,9 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase { } private $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_userid = false, - $fld_flags = false, $fld_timestamp = false, $fld_title = false, $fld_ids = false, - $fld_sizes = false, $fld_redirect = false, $fld_patrolled = false, $fld_loginfo = false, - $fld_tags = false, $fld_sha1 = false, $token = array(); + $fld_flags = false, $fld_timestamp = false, $fld_title = false, $fld_ids = false, + $fld_sizes = false, $fld_redirect = false, $fld_patrolled = false, $fld_loginfo = false, + $fld_tags = false, $fld_sha1 = false, $token = array(); private $tokenFunctions; @@ -64,6 +64,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase { 'patrol' => array( 'ApiQueryRecentChanges', 'getPatrolToken' ) ); wfRunHooks( 'APIQueryRecentChangesTokens', array( &$this->tokenFunctions ) ); + return $this->tokenFunctions; } @@ -80,8 +81,8 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase { if ( $rc ) { if ( ( $wgUser->useRCPatrol() && $rc->getAttribute( 'rc_type' ) == RC_EDIT ) || - ( $wgUser->useNPPatrol() && $rc->getAttribute( 'rc_type' ) == RC_NEW ) ) - { + ( $wgUser->useNPPatrol() && $rc->getAttribute( 'rc_type' ) == RC_NEW ) + ) { $validTokenUser = true; } } else { @@ -96,11 +97,11 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase { if ( is_null( $cachedPatrolToken ) ) { $cachedPatrolToken = $wgUser->getEditToken( 'patrol' ); } + return $cachedPatrolToken; } else { return false; } - } /** @@ -155,7 +156,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase { $cont = explode( '|', $params['continue'] ); if ( count( $cont ) != 2 ) { $this->dieUsage( 'Invalid continue param. You should pass the ' . - 'original value returned by the previous query', '_badcontinue' ); + 'original value returned by the previous query', '_badcontinue' ); } $timestamp = $this->getDB()->addQuotes( wfTimestamp( TS_MW, $cont[0] ) ); @@ -187,10 +188,10 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase { /* Check for conflicting parameters. */ if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) ) - || ( isset( $show['bot'] ) && isset( $show['!bot'] ) ) - || ( isset( $show['anon'] ) && isset( $show['!anon'] ) ) - || ( isset( $show['redirect'] ) && isset( $show['!redirect'] ) ) - || ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) ) + || ( isset( $show['bot'] ) && isset( $show['!bot'] ) ) + || ( isset( $show['anon'] ) && isset( $show['!anon'] ) ) + || ( isset( $show['redirect'] ) && isset( $show['!redirect'] ) ) + || ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) ) ) { $this->dieUsageMsg( 'show' ); } @@ -311,7 +312,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase { /* Iterate through the rows, adding data extracted from them to our query result. */ foreach ( $res as $row ) { - if ( ++ $count > $params['limit'] ) { + if ( ++$count > $params['limit'] ) { // We've reached the one extra which shows that there are additional pages to be had. Stop here... $this->setContinueEnumParameter( 'continue', wfTimestamp( TS_ISO_8601, $row->rc_timestamp ) . '|' . $row->rc_id ); break; @@ -520,6 +521,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase { foreach ( $type as $t ) { $retval[] = $this->parseRCType( $t ); } + return $retval; } switch ( $type ) { @@ -549,6 +551,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase { // formatComment() calls wfMessage() among other things return 'anon-public-user-private'; } + return 'public'; } @@ -640,6 +643,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase { public function getParamDescription() { $p = $this->getModulePrefix(); + return array( 'start' => 'The timestamp to start enumerating from', 'end' => 'The timestamp to end enumerating', -- 2.20.1