summaryrefslogtreecommitdiff
path: root/includes/api
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2015-06-04 07:31:04 +0200
committerPierre Schmitz <pierre@archlinux.de>2015-06-04 07:58:39 +0200
commitf6d65e533c62f6deb21342d4901ece24497b433e (patch)
treef28adf0362d14bcd448f7b65a7aaf38650f923aa /includes/api
parentc27b2e832fe25651ef2410fae85b41072aae7519 (diff)
Update to MediaWiki 1.25.1
Diffstat (limited to 'includes/api')
-rw-r--r--includes/api/ApiBase.php1084
-rw-r--r--includes/api/ApiBlock.php62
-rw-r--r--includes/api/ApiCheckToken.php81
-rw-r--r--includes/api/ApiClearHasMsg.php9
-rw-r--r--includes/api/ApiComparePages.php25
-rw-r--r--includes/api/ApiContinuationManager.php238
-rw-r--r--includes/api/ApiCreateAccount.php48
-rw-r--r--includes/api/ApiDelete.php29
-rw-r--r--includes/api/ApiDisabled.php16
-rw-r--r--includes/api/ApiEditPage.php143
-rw-r--r--includes/api/ApiEmailUser.php19
-rw-r--r--includes/api/ApiErrorFormatter.php303
-rw-r--r--includes/api/ApiExpandTemplates.php85
-rw-r--r--includes/api/ApiFeedContributions.php54
-rw-r--r--includes/api/ApiFeedRecentChanges.php35
-rw-r--r--includes/api/ApiFeedWatchlist.php90
-rw-r--r--includes/api/ApiFileRevert.php22
-rw-r--r--includes/api/ApiFormatBase.php332
-rw-r--r--includes/api/ApiFormatDbg.php11
-rw-r--r--includes/api/ApiFormatDump.php11
-rw-r--r--includes/api/ApiFormatFeedWrapper.php30
-rw-r--r--includes/api/ApiFormatJson.php96
-rw-r--r--includes/api/ApiFormatNone.php4
-rw-r--r--includes/api/ApiFormatPhp.php35
-rw-r--r--includes/api/ApiFormatRaw.php31
-rw-r--r--includes/api/ApiFormatTxt.php11
-rw-r--r--includes/api/ApiFormatWddx.php73
-rw-r--r--includes/api/ApiFormatXml.php302
-rw-r--r--includes/api/ApiFormatYaml.php4
-rw-r--r--includes/api/ApiHelp.php675
-rw-r--r--includes/api/ApiHelpParamValueMessage.php72
-rw-r--r--includes/api/ApiImageRotate.php42
-rw-r--r--includes/api/ApiImport.php35
-rw-r--r--includes/api/ApiLogin.php35
-rw-r--r--includes/api/ApiLogout.php19
-rw-r--r--includes/api/ApiMain.php541
-rw-r--r--includes/api/ApiManageTags.php107
-rw-r--r--includes/api/ApiMessage.php191
-rw-r--r--includes/api/ApiMove.php97
-rw-r--r--includes/api/ApiOpenSearch.php349
-rw-r--r--includes/api/ApiOptions.php37
-rw-r--r--includes/api/ApiPageSet.php337
-rw-r--r--includes/api/ApiParamInfo.php455
-rw-r--r--includes/api/ApiParse.php294
-rw-r--r--includes/api/ApiPatrol.php21
-rw-r--r--includes/api/ApiProtect.php46
-rw-r--r--includes/api/ApiPurge.php39
-rw-r--r--includes/api/ApiQuery.php117
-rw-r--r--includes/api/ApiQueryAllCategories.php42
-rw-r--r--includes/api/ApiQueryAllDeletedRevisions.php427
-rw-r--r--includes/api/ApiQueryAllImages.php99
-rw-r--r--includes/api/ApiQueryAllLinks.php95
-rw-r--r--includes/api/ApiQueryAllMessages.php43
-rw-r--r--includes/api/ApiQueryAllPages.php79
-rw-r--r--includes/api/ApiQueryAllUsers.php273
-rw-r--r--includes/api/ApiQueryBacklinks.php483
-rw-r--r--includes/api/ApiQueryBacklinksprop.php114
-rw-r--r--includes/api/ApiQueryBase.php42
-rw-r--r--includes/api/ApiQueryBlocks.php114
-rw-r--r--includes/api/ApiQueryCategories.php42
-rw-r--r--includes/api/ApiQueryCategoryInfo.php26
-rw-r--r--includes/api/ApiQueryCategoryMembers.php89
-rw-r--r--includes/api/ApiQueryContributors.php37
-rw-r--r--includes/api/ApiQueryDeletedRevisions.php304
-rw-r--r--includes/api/ApiQueryDeletedrevs.php158
-rw-r--r--includes/api/ApiQueryDisabled.php14
-rw-r--r--includes/api/ApiQueryDuplicateFiles.php33
-rw-r--r--includes/api/ApiQueryExtLinksUsage.php60
-rw-r--r--includes/api/ApiQueryExternalLinks.php31
-rw-r--r--includes/api/ApiQueryFileRepoInfo.php27
-rw-r--r--includes/api/ApiQueryFilearchive.php69
-rw-r--r--includes/api/ApiQueryIWBacklinks.php39
-rw-r--r--includes/api/ApiQueryIWLinks.php51
-rw-r--r--includes/api/ApiQueryImageInfo.php121
-rw-r--r--includes/api/ApiQueryImages.php28
-rw-r--r--includes/api/ApiQueryInfo.php122
-rw-r--r--includes/api/ApiQueryLangBacklinks.php40
-rw-r--r--includes/api/ApiQueryLangLinks.php55
-rw-r--r--includes/api/ApiQueryLinks.php43
-rw-r--r--includes/api/ApiQueryLogEvents.php184
-rw-r--r--includes/api/ApiQueryORM.php11
-rw-r--r--includes/api/ApiQueryPagePropNames.php22
-rw-r--r--includes/api/ApiQueryPageProps.php22
-rw-r--r--includes/api/ApiQueryPagesWithProp.php39
-rw-r--r--includes/api/ApiQueryPrefixSearch.php40
-rw-r--r--includes/api/ApiQueryProtectedTitles.php40
-rw-r--r--includes/api/ApiQueryQueryPage.php28
-rw-r--r--includes/api/ApiQueryRandom.php27
-rw-r--r--includes/api/ApiQueryRecentChanges.php122
-rw-r--r--includes/api/ApiQueryRevisions.php616
-rw-r--r--includes/api/ApiQueryRevisionsBase.php477
-rw-r--r--includes/api/ApiQuerySearch.php160
-rw-r--r--includes/api/ApiQuerySiteinfo.php260
-rw-r--r--includes/api/ApiQueryStashImageInfo.php52
-rw-r--r--includes/api/ApiQueryTags.php169
-rw-r--r--includes/api/ApiQueryTokens.php30
-rw-r--r--includes/api/ApiQueryUserContributions.php92
-rw-r--r--includes/api/ApiQueryUserInfo.php89
-rw-r--r--includes/api/ApiQueryUsers.php69
-rw-r--r--includes/api/ApiQueryWatchlist.php122
-rw-r--r--includes/api/ApiQueryWatchlistRaw.php36
-rw-r--r--includes/api/ApiResult.php1553
-rw-r--r--includes/api/ApiRevisionDelete.php36
-rw-r--r--includes/api/ApiRollback.php36
-rw-r--r--includes/api/ApiRsd.php44
-rw-r--r--includes/api/ApiSerializable.php47
-rw-r--r--includes/api/ApiSetNotificationTimestamp.php67
-rw-r--r--includes/api/ApiStashEdit.php412
-rw-r--r--includes/api/ApiTag.php177
-rw-r--r--includes/api/ApiTokens.php39
-rw-r--r--includes/api/ApiUnblock.php24
-rw-r--r--includes/api/ApiUndelete.php36
-rw-r--r--includes/api/ApiUpload.php138
-rw-r--r--includes/api/ApiUserrights.php56
-rw-r--r--includes/api/ApiWatch.php58
-rw-r--r--includes/api/i18n/ar.json28
-rw-r--r--includes/api/i18n/av.json8
-rw-r--r--includes/api/i18n/awa.json11
-rw-r--r--includes/api/i18n/be-tarask.json55
-rw-r--r--includes/api/i18n/bn.json8
-rw-r--r--includes/api/i18n/bs.json16
-rw-r--r--includes/api/i18n/ca.json43
-rw-r--r--includes/api/i18n/ce.json12
-rw-r--r--includes/api/i18n/cs.json223
-rw-r--r--includes/api/i18n/cv.json8
-rw-r--r--includes/api/i18n/de.json433
-rw-r--r--includes/api/i18n/el.json12
-rw-r--r--includes/api/i18n/en-gb.json156
-rw-r--r--includes/api/i18n/en.json1169
-rw-r--r--includes/api/i18n/es.json206
-rw-r--r--includes/api/i18n/eu.json57
-rw-r--r--includes/api/i18n/fa.json240
-rw-r--r--includes/api/i18n/fi.json10
-rw-r--r--includes/api/i18n/fr.json1054
-rw-r--r--includes/api/i18n/frc.json19
-rw-r--r--includes/api/i18n/fy.json15
-rw-r--r--includes/api/i18n/gl.json1030
-rw-r--r--includes/api/i18n/he.json180
-rw-r--r--includes/api/i18n/hsb.json8
-rw-r--r--includes/api/i18n/hu.json17
-rw-r--r--includes/api/i18n/ia.json28
-rw-r--r--includes/api/i18n/it.json31
-rw-r--r--includes/api/i18n/ja.json213
-rw-r--r--includes/api/i18n/jam.json8
-rw-r--r--includes/api/i18n/ko.json36
-rw-r--r--includes/api/i18n/ksh.json311
-rw-r--r--includes/api/i18n/ku-latn.json9
-rw-r--r--includes/api/i18n/lb.json94
-rw-r--r--includes/api/i18n/ln.json8
-rw-r--r--includes/api/i18n/lv.json8
-rw-r--r--includes/api/i18n/lzh.json8
-rw-r--r--includes/api/i18n/mg.json11
-rw-r--r--includes/api/i18n/mk.json398
-rw-r--r--includes/api/i18n/ms.json61
-rw-r--r--includes/api/i18n/nap.json10
-rw-r--r--includes/api/i18n/nb.json24
-rw-r--r--includes/api/i18n/nds.json8
-rw-r--r--includes/api/i18n/nl.json61
-rw-r--r--includes/api/i18n/oc.json17
-rw-r--r--includes/api/i18n/pa.json8
-rw-r--r--includes/api/i18n/pam.json31
-rw-r--r--includes/api/i18n/pl.json117
-rw-r--r--includes/api/i18n/ps.json29
-rw-r--r--includes/api/i18n/pt-br.json14
-rw-r--r--includes/api/i18n/pt.json104
-rw-r--r--includes/api/i18n/qqq.json1069
-rw-r--r--includes/api/i18n/roa-tara.json11
-rw-r--r--includes/api/i18n/ru.json55
-rw-r--r--includes/api/i18n/si.json70
-rw-r--r--includes/api/i18n/sr-ec.json24
-rw-r--r--includes/api/i18n/sr-el.json11
-rw-r--r--includes/api/i18n/sv.json372
-rw-r--r--includes/api/i18n/te.json8
-rw-r--r--includes/api/i18n/tl.json35
-rw-r--r--includes/api/i18n/tr.json40
-rw-r--r--includes/api/i18n/uk.json30
-rw-r--r--includes/api/i18n/vi.json156
-rw-r--r--includes/api/i18n/zh-hans.json782
-rw-r--r--includes/api/i18n/zh-hant.json244
179 files changed, 19056 insertions, 5938 deletions
diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php
index 944e4895..5a1eb995 100644
--- a/includes/api/ApiBase.php
+++ b/includes/api/ApiBase.php
@@ -32,9 +32,6 @@
* Module parameters: Derived classes can define getAllowedParams() to specify
* which parameters to expect, how to parse and validate them.
*
- * Profiling: various methods to allow keeping tabs on various tasks and their
- * time costs
- *
* Self-documentation: code to allow the API to document its own state
*
* @ingroup API
@@ -64,6 +61,30 @@ abstract class ApiBase extends ContextSource {
// Boolean, if MIN/MAX are set, enforce (die) these?
// Only applies if TYPE='integer' Use with extreme caution
const PARAM_RANGE_ENFORCE = 9;
+ /// @since 1.25
+ // Specify an alternative i18n message for this help parameter.
+ // Value is $msg for ApiBase::makeMessage()
+ const PARAM_HELP_MSG = 10;
+ /// @since 1.25
+ // Specify additional i18n messages to append to the normal message. Value
+ // is an array of $msg for ApiBase::makeMessage()
+ const PARAM_HELP_MSG_APPEND = 11;
+ /// @since 1.25
+ // Specify additional information tags for the parameter. Value is an array
+ // of arrays, with the first member being the 'tag' for the info and the
+ // remaining members being the values. In the help, this is formatted using
+ // apihelp-{$path}-paraminfo-{$tag}, which is passed $1 = count, $2 =
+ // comma-joined list of values, $3 = module prefix.
+ const PARAM_HELP_MSG_INFO = 12;
+ /// @since 1.25
+ // When PARAM_TYPE is an array, this may be an array mapping those values
+ // to page titles which will be linked in the help.
+ const PARAM_VALUE_LINKS = 13;
+ /// @since 1.25
+ // When PARAM_TYPE is an array, this is an array mapping those values to
+ // $msg for ApiBase::makeMessage(). Any value not having a mapping will use
+ // apihelp-{$path}-paramvalue-{$param}-{$value} is used.
+ const PARAM_HELP_MSG_PER_VALUE = 14;
const LIMIT_BIG1 = 500; // Fast query, std user limit
const LIMIT_BIG2 = 5000; // Fast query, bot/sysop limit
@@ -136,6 +157,9 @@ abstract class ApiBase extends ContextSource {
* If the module may only be used with a certain format module,
* it should override this method to return an instance of that formatter.
* A value of null means the default format will be used.
+ * @note Do not use this just because you don't want to support non-json
+ * formats. This should be used only when there is a fundamental
+ * requirement for a specific format.
* @return mixed Instance of a derived class of ApiFormatBase, or null
*/
public function getCustomPrinter() {
@@ -143,27 +167,64 @@ abstract class ApiBase extends ContextSource {
}
/**
- * Returns the description string for this module
- * @return string|array
+ * Returns usage examples for this module.
+ *
+ * Return value has query strings as keys, with values being either strings
+ * (message key), arrays (message key + parameter), or Message objects.
+ *
+ * Do not call this base class implementation when overriding this method.
+ *
+ * @since 1.25
+ * @return array
*/
- protected function getDescription() {
- return false;
- }
+ protected function getExamplesMessages() {
+ // Fall back to old non-localised method
+ $ret = array();
+
+ $examples = $this->getExamples();
+ if ( $examples ) {
+ if ( !is_array( $examples ) ) {
+ $examples = array( $examples );
+ } elseif ( $examples && ( count( $examples ) & 1 ) == 0 &&
+ array_keys( $examples ) === range( 0, count( $examples ) - 1 ) &&
+ !preg_match( '/^\s*api\.php\?/', $examples[0] )
+ ) {
+ // Fix up the ugly "even numbered elements are description, odd
+ // numbered elemts are the link" format (see doc for self::getExamples)
+ $tmp = array();
+ for ( $i = 0; $i < count( $examples ); $i += 2 ) {
+ $tmp[$examples[$i + 1]] = $examples[$i];
+ }
+ $examples = $tmp;
+ }
- /**
- * Returns usage examples for this module. Return false if no examples are available.
- * @return bool|string|array
- */
- protected function getExamples() {
- return false;
+ foreach ( $examples as $k => $v ) {
+ if ( is_numeric( $k ) ) {
+ $qs = $v;
+ $msg = '';
+ } else {
+ $qs = $k;
+ $msg = self::escapeWikiText( $v );
+ if ( is_array( $msg ) ) {
+ $msg = join( " ", $msg );
+ }
+ }
+
+ $qs = preg_replace( '/^\s*api\.php\?/', '', $qs );
+ $ret[$qs] = $this->msg( 'api-help-fallback-example', array( $msg ) );
+ }
+ }
+
+ return $ret;
}
/**
- * @return bool|string|array Returns a false if the module has no help URL,
- * else returns a (array of) string
+ * Return links to more detailed help pages about the module.
+ * @since 1.25, returning boolean false is deprecated
+ * @return string|array
*/
public function getHelpUrls() {
- return false;
+ return array();
}
/**
@@ -176,22 +237,12 @@ abstract class ApiBase extends ContextSource {
* in the overriding methods. Callers of this method can pass zero or
* more OR-ed flags like GET_VALUES_FOR_HELP.
*
- * @return array|bool
+ * @return array
*/
protected function getAllowedParams( /* $flags = 0 */ ) {
// int $flags is not declared because it causes "Strict standards"
// warning. Most derived classes do not implement it.
- return false;
- }
-
- /**
- * Returns an array of parameter descriptions.
- * Don't call this function directly: use getFinalParamDescription() to
- * allow hooks to modify descriptions as needed.
- * @return array|bool False on no parameter descriptions
- */
- protected function getParamDescription() {
- return false;
+ return array();
}
/**
@@ -227,6 +278,25 @@ abstract class ApiBase extends ContextSource {
}
/**
+ * Indicates whether this module is deprecated
+ * @since 1.25
+ * @return bool
+ */
+ public function isDeprecated() {
+ return false;
+ }
+
+ /**
+ * Indicates whether this module is "internal"
+ * Internal API modules are not (yet) intended for 3rd party use and may be unstable.
+ * @since 1.25
+ * @return bool
+ */
+ public function isInternal() {
+ return false;
+ }
+
+ /**
* Returns the token type this module requires in order to execute.
*
* Modules are strongly encouraged to use the core 'csrf' type unless they
@@ -234,11 +304,9 @@ abstract class ApiBase extends ContextSource {
* core types, you must use the ApiQueryTokensRegisterTypes hook to
* register it.
*
- * Returning a non-falsey value here will cause self::getFinalParams() to
- * return a required string 'token' parameter and
- * self::getFinalParamDescription() to ensure there is standardized
- * documentation for it. Also, self::mustBePosted() must return true when
- * tokens are used.
+ * Returning a non-falsey value here will force the addition of an
+ * appropriate 'token' parameter in self::getFinalParams(). Also,
+ * self::mustBePosted() must return true when tokens are used.
*
* In previous versions of MediaWiki, true was a valid return value.
* Returning true will generate errors indicating that the API module needs
@@ -304,6 +372,87 @@ abstract class ApiBase extends ContextSource {
}
/**
+ * Get the parent of this module
+ * @since 1.25
+ * @return ApiBase|null
+ */
+ public function getParent() {
+ return $this->isMain() ? null : $this->getMain();
+ }
+
+ /**
+ * Returns true if the current request breaks the same-origin policy.
+ *
+ * For example, json with callbacks.
+ *
+ * https://en.wikipedia.org/wiki/Same-origin_policy
+ *
+ * @since 1.25
+ * @return bool
+ */
+ public function lacksSameOriginSecurity() {
+ return $this->getMain()->getRequest()->getVal( 'callback' ) !== null;
+ }
+
+ /**
+ * Get the path to this module
+ *
+ * @since 1.25
+ * @return string
+ */
+ public function getModulePath() {
+ if ( $this->isMain() ) {
+ return 'main';
+ } elseif ( $this->getParent()->isMain() ) {
+ return $this->getModuleName();
+ } else {
+ return $this->getParent()->getModulePath() . '+' . $this->getModuleName();
+ }
+ }
+
+ /**
+ * Get a module from its module path
+ *
+ * @since 1.25
+ * @param string $path
+ * @return ApiBase|null
+ * @throws UsageException
+ */
+ public function getModuleFromPath( $path ) {
+ $module = $this->getMain();
+ if ( $path === 'main' ) {
+ return $module;
+ }
+
+ $parts = explode( '+', $path );
+ if ( count( $parts ) === 1 ) {
+ // In case the '+' was typed into URL, it resolves as a space
+ $parts = explode( ' ', $path );
+ }
+
+ $count = count( $parts );
+ for ( $i = 0; $i < $count; $i++ ) {
+ $parent = $module;
+ $manager = $parent->getModuleManager();
+ if ( $manager === null ) {
+ $errorPath = join( '+', array_slice( $parts, 0, $i ) );
+ $this->dieUsage( "The module \"$errorPath\" has no submodules", 'badmodule' );
+ }
+ $module = $manager->getModule( $parts[$i] );
+
+ if ( $module === null ) {
+ $errorPath = $i ? join( '+', array_slice( $parts, 0, $i ) ) : $parent->getModuleName();
+ $this->dieUsage(
+ "The module \"$errorPath\" does not have a submodule \"{$parts[$i]}\"",
+ 'badmodule'
+ );
+ }
+ }
+
+ return $module;
+ }
+
+ /**
* Get the result object
* @return ApiResult
*/
@@ -318,11 +467,17 @@ abstract class ApiBase extends ContextSource {
}
/**
- * Get the result data array (read-only)
- * @return array
+ * Get the error formatter
+ * @return ApiErrorFormatter
*/
- public function getResultData() {
- return $this->getResult()->getData();
+ public function getErrorFormatter() {
+ // Main module has getErrorFormatter() method overridden
+ // Safety - avoid infinite loop:
+ if ( $this->isMain() ) {
+ ApiBase::dieDebug( __METHOD__, 'base method was called on main module. ' );
+ }
+
+ return $this->getMain()->getErrorFormatter();
}
/**
@@ -331,76 +486,38 @@ abstract class ApiBase extends ContextSource {
*/
protected function getDB() {
if ( !isset( $this->mSlaveDB ) ) {
- $this->profileDBIn();
$this->mSlaveDB = wfGetDB( DB_SLAVE, 'api' );
- $this->profileDBOut();
}
return $this->mSlaveDB;
}
/**
- * Get final module description, after hooks have had a chance to tweak it as
- * needed.
- *
- * @return array|bool False on no parameters
- */
- public function getFinalDescription() {
- $desc = $this->getDescription();
- wfRunHooks( 'APIGetDescription', array( &$this, &$desc ) );
-
- return $desc;
- }
-
- /**
- * Get final list of parameters, after hooks have had a chance to
- * tweak it as needed.
- *
- * @param int $flags Zero or more flags like GET_VALUES_FOR_HELP
- * @return array|bool False on no parameters
- * @since 1.21 $flags param added
+ * Get the continuation manager
+ * @return ApiContinuationManager|null
*/
- public function getFinalParams( $flags = 0 ) {
- $params = $this->getAllowedParams( $flags );
-
- if ( $this->needsToken() ) {
- $params['token'] = array(
- ApiBase::PARAM_TYPE => 'string',
- ApiBase::PARAM_REQUIRED => true,
- );
+ public function getContinuationManager() {
+ // Main module has getContinuationManager() method overridden
+ // Safety - avoid infinite loop:
+ if ( $this->isMain() ) {
+ ApiBase::dieDebug( __METHOD__, 'base method was called on main module. ' );
}
- wfRunHooks( 'APIGetAllowedParams', array( &$this, &$params, $flags ) );
-
- return $params;
+ return $this->getMain()->getContinuationManager();
}
/**
- * Get final parameter descriptions, after hooks have had a chance to tweak it as
- * needed.
- *
- * @return array|bool False on no parameter descriptions
+ * Set the continuation manager
+ * @param ApiContinuationManager|null
*/
- public function getFinalParamDescription() {
- $desc = $this->getParamDescription();
-
- $tokenType = $this->needsToken();
- if ( $tokenType ) {
- if ( !isset( $desc['token'] ) ) {
- $desc['token'] = array();
- } elseif ( !is_array( $desc['token'] ) ) {
- // We ignore a plain-string token, because it's probably an
- // extension that is supplying the string for BC.
- $desc['token'] = array();
- }
- array_unshift( $desc['token'],
- "A '$tokenType' token retrieved from action=query&meta=tokens"
- );
+ public function setContinuationManager( $manager ) {
+ // Main module has setContinuationManager() method overridden
+ // Safety - avoid infinite loop:
+ if ( $this->isMain() ) {
+ ApiBase::dieDebug( __METHOD__, 'base method was called on main module. ' );
}
- wfRunHooks( 'APIGetParamDescription', array( &$this, &$desc ) );
-
- return $desc;
+ $this->getMain()->setContinuationManager( $manager );
}
/**@}*/
@@ -782,7 +899,7 @@ abstract class ApiBase extends ContextSource {
$value = $this->getMain()->canApiHighLimits()
? $paramSettings[self::PARAM_MAX2]
: $paramSettings[self::PARAM_MAX];
- $this->getResult()->setParsedLimit( $this->getModuleName(), $value );
+ $this->getResult()->addParsedLimit( $this->getModuleName(), $value );
} else {
$value = intval( $value );
$this->validateLimit(
@@ -974,8 +1091,9 @@ abstract class ApiBase extends ContextSource {
* @param string $token Supplied token
* @param array $params All supplied parameters for the module
* @return bool
+ * @throws MWException
*/
- public final function validateToken( $token, array $params ) {
+ final public function validateToken( $token, array $params ) {
$tokenType = $this->needsToken();
$salts = ApiQueryTokens::getTokenTypeSalts();
if ( !isset( $salts[$tokenType] ) ) {
@@ -1093,6 +1211,55 @@ abstract class ApiBase extends ContextSource {
return $user;
}
+ /**
+ * A subset of wfEscapeWikiText for BC texts
+ *
+ * @since 1.25
+ * @param string|array $v
+ * @return string|array
+ */
+ private static function escapeWikiText( $v ) {
+ if ( is_array( $v ) ) {
+ return array_map( 'self::escapeWikiText', $v );
+ } else {
+ return strtr( $v, array(
+ '__' => '_&#95;', '{' => '&#123;', '}' => '&#125;',
+ '[[Category:' => '[[:Category:',
+ '[[File:' => '[[:File:', '[[Image:' => '[[:Image:',
+ ) );
+ }
+ }
+
+ /**
+ * Create a Message from a string or array
+ *
+ * A string is used as a message key. An array has the message key as the
+ * first value and message parameters as subsequent values.
+ *
+ * @since 1.25
+ * @param string|array|Message $msg
+ * @param IContextSource $context
+ * @param array $params
+ * @return Message|null
+ */
+ public static function makeMessage( $msg, IContextSource $context, array $params = null ) {
+ if ( is_string( $msg ) ) {
+ $msg = wfMessage( $msg );
+ } elseif ( is_array( $msg ) ) {
+ $msg = call_user_func_array( 'wfMessage', $msg );
+ }
+ if ( !$msg instanceof Message ) {
+ return null;
+ }
+
+ $msg->setContext( $context );
+ if ( $params ) {
+ $msg->params( $params );
+ }
+
+ return $msg;
+ }
+
/**@}*/
/************************************************************************//**
@@ -1108,28 +1275,8 @@ abstract class ApiBase extends ContextSource {
* @param string $warning Warning message
*/
public function setWarning( $warning ) {
- $result = $this->getResult();
- $data = $result->getData();
- $moduleName = $this->getModuleName();
- if ( isset( $data['warnings'][$moduleName] ) ) {
- // Don't add duplicate warnings
- $oldWarning = $data['warnings'][$moduleName]['*'];
- $warnPos = strpos( $oldWarning, $warning );
- // If $warning was found in $oldWarning, check if it starts at 0 or after "\n"
- if ( $warnPos !== false && ( $warnPos === 0 || $oldWarning[$warnPos - 1] === "\n" ) ) {
- // Check if $warning is followed by "\n" or the end of the $oldWarning
- $warnPos += strlen( $warning );
- if ( strlen( $oldWarning ) <= $warnPos || $oldWarning[$warnPos] === "\n" ) {
- return;
- }
- }
- // If there is a warning already, append it to the existing one
- $warning = "$oldWarning\n$warning";
- }
- $msg = array();
- ApiResult::setContent( $msg, $warning );
- $result->addValue( 'warnings', $moduleName,
- $msg, ApiResult::OVERRIDE | ApiResult::ADD_ON_TOP | ApiResult::NO_SIZE_CHECK );
+ $msg = new ApiRawMessage( $warning, 'warning' );
+ $this->getErrorFormatter()->addWarning( $this->getModuleName(), $msg );
}
/**
@@ -1159,7 +1306,6 @@ abstract class ApiBase extends ContextSource {
* @throws UsageException
*/
public function dieUsage( $description, $errorCode, $httpRespCode = 0, $extradata = null ) {
- Profiler::instance()->close();
throw new UsageException(
$description,
$this->encodeParamName( $errorCode ),
@@ -1174,6 +1320,7 @@ abstract class ApiBase extends ContextSource {
* @since 1.23
* @param Status $status
* @return array Array of code and error string
+ * @throws MWException
*/
public function getErrorFromStatus( $status ) {
if ( $status->isGood() ) {
@@ -1530,6 +1677,10 @@ abstract class ApiBase extends ContextSource {
'code' => 'nosuchrcid',
'info' => "There is no change with rcid \"\$1\""
),
+ 'nosuchlogid' => array(
+ 'code' => 'nosuchlogid',
+ 'info' => "There is no log entry with ID \"\$1\""
+ ),
'protect-invalidaction' => array(
'code' => 'protect-invalidaction',
'info' => "Invalid protection type \"\$1\""
@@ -1815,6 +1966,21 @@ abstract class ApiBase extends ContextSource {
throw new MWException( "Internal error in $method: $message" );
}
+ /**
+ * Write logging information for API features to a debug log, for usage
+ * analysis.
+ * @param string $feature Feature being used.
+ */
+ protected function logFeatureUsage( $feature ) {
+ $request = $this->getRequest();
+ $s = '"' . addslashes( $feature ) . '"' .
+ ' "' . wfUrlencode( str_replace( ' ', '_', $this->getUser()->getName() ) ) . '"' .
+ ' "' . $request->getIP() . '"' .
+ ' "' . addslashes( $request->getHeader( 'Referer' ) ) . '"' .
+ ' "' . addslashes( $this->getMain()->getUserAgent() ) . '"';
+ wfDebugLog( 'api-feature-usage', $s, 'private' );
+ }
+
/**@}*/
/************************************************************************//**
@@ -1823,10 +1989,424 @@ abstract class ApiBase extends ContextSource {
*/
/**
+ * Return the description message.
+ *
+ * @return string|array|Message
+ */
+ protected function getDescriptionMessage() {
+ return "apihelp-{$this->getModulePath()}-description";
+ }
+
+ /**
+ * Get final module description, after hooks have had a chance to tweak it as
+ * needed.
+ *
+ * @since 1.25, returns Message[] rather than string[]
+ * @return Message[]
+ */
+ public function getFinalDescription() {
+ $desc = $this->getDescription();
+ Hooks::run( 'APIGetDescription', array( &$this, &$desc ) );
+ $desc = self::escapeWikiText( $desc );
+ if ( is_array( $desc ) ) {
+ $desc = join( "\n", $desc );
+ } else {
+ $desc = (string)$desc;
+ }
+
+ $msg = ApiBase::makeMessage( $this->getDescriptionMessage(), $this->getContext(), array(
+ $this->getModulePrefix(),
+ $this->getModuleName(),
+ $this->getModulePath(),
+ ) );
+ if ( !$msg->exists() ) {
+ $msg = $this->msg( 'api-help-fallback-description', $desc );
+ }
+ $msgs = array( $msg );
+
+ Hooks::run( 'APIGetDescriptionMessages', array( $this, &$msgs ) );
+
+ return $msgs;
+ }
+
+ /**
+ * Get final list of parameters, after hooks have had a chance to
+ * tweak it as needed.
+ *
+ * @param int $flags Zero or more flags like GET_VALUES_FOR_HELP
+ * @return array|bool False on no parameters
+ * @since 1.21 $flags param added
+ */
+ public function getFinalParams( $flags = 0 ) {
+ $params = $this->getAllowedParams( $flags );
+ if ( !$params ) {
+ $params = array();
+ }
+
+ if ( $this->needsToken() ) {
+ $params['token'] = array(
+ ApiBase::PARAM_TYPE => 'string',
+ ApiBase::PARAM_REQUIRED => true,
+ ApiBase::PARAM_HELP_MSG => array(
+ 'api-help-param-token',
+ $this->needsToken(),
+ ),
+ ) + ( isset( $params['token'] ) ? $params['token'] : array() );
+ }
+
+ Hooks::run( 'APIGetAllowedParams', array( &$this, &$params, $flags ) );
+
+ return $params;
+ }
+
+ /**
+ * Get final parameter descriptions, after hooks have had a chance to tweak it as
+ * needed.
+ *
+ * @since 1.25, returns array of Message[] rather than array of string[]
+ * @return array Keys are parameter names, values are arrays of Message objects
+ */
+ public function getFinalParamDescription() {
+ $prefix = $this->getModulePrefix();
+ $name = $this->getModuleName();
+ $path = $this->getModulePath();
+
+ $desc = $this->getParamDescription();
+ Hooks::run( 'APIGetParamDescription', array( &$this, &$desc ) );
+
+ if ( !$desc ) {
+ $desc = array();
+ }
+ $desc = self::escapeWikiText( $desc );
+
+ $params = $this->getFinalParams( ApiBase::GET_VALUES_FOR_HELP );
+ $msgs = array();
+ foreach ( $params as $param => $settings ) {
+ if ( !is_array( $settings ) ) {
+ $settings = array();
+ }
+
+ $d = isset( $desc[$param] ) ? $desc[$param] : '';
+ if ( is_array( $d ) ) {
+ // Special handling for prop parameters
+ $d = array_map( function ( $line ) {
+ if ( preg_match( '/^\s+(\S+)\s+-\s+(.+)$/', $line, $m ) ) {
+ $line = "\n;{$m[1]}:{$m[2]}";
+ }
+ return $line;
+ }, $d );
+ $d = join( ' ', $d );
+ }
+
+ if ( isset( $settings[ApiBase::PARAM_HELP_MSG] ) ) {
+ $msg = $settings[ApiBase::PARAM_HELP_MSG];
+ } else {
+ $msg = $this->msg( "apihelp-{$path}-param-{$param}" );
+ if ( !$msg->exists() ) {
+ $msg = $this->msg( 'api-help-fallback-parameter', $d );
+ }
+ }
+ $msg = ApiBase::makeMessage( $msg, $this->getContext(),
+ array( $prefix, $param, $name, $path ) );
+ if ( !$msg ) {
+ $this->dieDebug( __METHOD__,
+ 'Value in ApiBase::PARAM_HELP_MSG is not valid' );
+ }
+ $msgs[$param] = array( $msg );
+
+ if ( isset( $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE] ) ) {
+ if ( !is_array( $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE] ) ) {
+ $this->dieDebug( __METHOD__,
+ 'ApiBase::PARAM_HELP_MSG_PER_VALUE is not valid' );
+ }
+ if ( !is_array( $settings[ApiBase::PARAM_TYPE] ) ) {
+ $this->dieDebug( __METHOD__,
+ 'ApiBase::PARAM_HELP_MSG_PER_VALUE may only be used when ' .
+ 'ApiBase::PARAM_TYPE is an array' );
+ }
+
+ $valueMsgs = $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE];
+ foreach ( $settings[ApiBase::PARAM_TYPE] as $value ) {
+ if ( isset( $valueMsgs[$value] ) ) {
+ $msg = $valueMsgs[$value];
+ } else {
+ $msg = "apihelp-{$path}-paramvalue-{$param}-{$value}";
+ }
+ $m = ApiBase::makeMessage( $msg, $this->getContext(),
+ array( $prefix, $param, $name, $path, $value ) );
+ if ( $m ) {
+ $m = new ApiHelpParamValueMessage(
+ $value,
+ array( $m->getKey(), 'api-help-param-no-description' ),
+ $m->getParams()
+ );
+ $msgs[$param][] = $m->setContext( $this->getContext() );
+ } else {
+ $this->dieDebug( __METHOD__,
+ "Value in ApiBase::PARAM_HELP_MSG_PER_VALUE for $value is not valid" );
+ }
+ }
+ }
+
+ if ( isset( $settings[ApiBase::PARAM_HELP_MSG_APPEND] ) ) {
+ if ( !is_array( $settings[ApiBase::PARAM_HELP_MSG_APPEND] ) ) {
+ $this->dieDebug( __METHOD__,
+ 'Value for ApiBase::PARAM_HELP_MSG_APPEND is not an array' );
+ }
+ foreach ( $settings[ApiBase::PARAM_HELP_MSG_APPEND] as $m ) {
+ $m = ApiBase::makeMessage( $m, $this->getContext(),
+ array( $prefix, $param, $name, $path ) );
+ if ( $m ) {
+ $msgs[$param][] = $m;
+ } else {
+ $this->dieDebug( __METHOD__,
+ 'Value in ApiBase::PARAM_HELP_MSG_APPEND is not valid' );
+ }
+ }
+ }
+ }
+
+ Hooks::run( 'APIGetParamDescriptionMessages', array( $this, &$msgs ) );
+
+ return $msgs;
+ }
+
+ /**
+ * Generates the list of flags for the help screen and for action=paraminfo
+ *
+ * Corresponding messages: api-help-flag-deprecated,
+ * api-help-flag-internal, api-help-flag-readrights,
+ * api-help-flag-writerights, api-help-flag-mustbeposted
+ *
+ * @return string[]
+ */
+ protected function getHelpFlags() {
+ $flags = array();
+
+ if ( $this->isDeprecated() ) {
+ $flags[] = 'deprecated';
+ }
+ if ( $this->isInternal() ) {
+ $flags[] = 'internal';
+ }
+ if ( $this->isReadMode() ) {
+ $flags[] = 'readrights';
+ }
+ if ( $this->isWriteMode() ) {
+ $flags[] = 'writerights';
+ }
+ if ( $this->mustBePosted() ) {
+ $flags[] = 'mustbeposted';
+ }
+
+ return $flags;
+ }
+
+ /**
+ * Called from ApiHelp before the pieces are joined together and returned.
+ *
+ * This exists mainly for ApiMain to add the Permissions and Credits
+ * sections. Other modules probably don't need it.
+ *
+ * @param string[] &$help Array of help data
+ * @param array $options Options passed to ApiHelp::getHelp
+ */
+ public function modifyHelp( array &$help, array $options ) {
+ }
+
+ /**@}*/
+
+ /************************************************************************//**
+ * @name Deprecated
+ * @{
+ */
+
+ /// @deprecated since 1.24
+ const PROP_ROOT = 'ROOT';
+ /// @deprecated since 1.24
+ const PROP_LIST = 'LIST';
+ /// @deprecated since 1.24
+ const PROP_TYPE = 0;
+ /// @deprecated since 1.24
+ const PROP_NULLABLE = 1;
+
+ /**
+ * Formerly returned a string that identifies the version of the extending
+ * class. Typically included the class name, the svn revision, timestamp,
+ * and last author. Usually done with SVN's Id keyword
+ *
+ * @deprecated since 1.21, version string is no longer supported
+ * @return string
+ */
+ public function getVersion() {
+ wfDeprecated( __METHOD__, '1.21' );
+ return '';
+ }
+
+ /**
+ * Formerly used to fetch a list of possible properites in the result,
+ * somehow organized with respect to the prop parameter that causes them to
+ * be returned. The specific semantics of the return value was never
+ * specified. Since this was never possible to be accurately updated, it
+ * has been removed.
+ *
+ * @deprecated since 1.24
+ * @return array|bool
+ */
+ protected function getResultProperties() {
+ wfDeprecated( __METHOD__, '1.24' );
+ return false;
+ }
+
+ /**
+ * @see self::getResultProperties()
+ * @deprecated since 1.24
+ * @return array|bool
+ */
+ public function getFinalResultProperties() {
+ wfDeprecated( __METHOD__, '1.24' );
+ return array();
+ }
+
+ /**
+ * @see self::getResultProperties()
+ * @deprecated since 1.24
+ */
+ protected static function addTokenProperties( &$props, $tokenFunctions ) {
+ wfDeprecated( __METHOD__, '1.24' );
+ }
+
+ /**
+ * @see self::getPossibleErrors()
+ * @deprecated since 1.24
+ * @return array
+ */
+ public function getRequireOnlyOneParameterErrorMessages( $params ) {
+ wfDeprecated( __METHOD__, '1.24' );
+ return array();
+ }
+
+ /**
+ * @see self::getPossibleErrors()
+ * @deprecated since 1.24
+ * @return array
+ */
+ public function getRequireMaxOneParameterErrorMessages( $params ) {
+ wfDeprecated( __METHOD__, '1.24' );
+ return array();
+ }
+
+ /**
+ * @see self::getPossibleErrors()
+ * @deprecated since 1.24
+ * @return array
+ */
+ public function getRequireAtLeastOneParameterErrorMessages( $params ) {
+ wfDeprecated( __METHOD__, '1.24' );
+ return array();
+ }
+
+ /**
+ * @see self::getPossibleErrors()
+ * @deprecated since 1.24
+ * @return array
+ */
+ public function getTitleOrPageIdErrorMessage() {
+ wfDeprecated( __METHOD__, '1.24' );
+ return array();
+ }
+
+ /**
+ * This formerly attempted to return a list of all possible errors returned
+ * by the module. However, this was impossible to maintain in many cases
+ * since errors could come from other areas of MediaWiki and in some cases
+ * from arbitrary extension hooks. Since a partial list claiming to be
+ * comprehensive is unlikely to be useful, it was removed.
+ *
+ * @deprecated since 1.24
+ * @return array
+ */
+ public function getPossibleErrors() {
+ wfDeprecated( __METHOD__, '1.24' );
+ return array();
+ }
+
+ /**
+ * @see self::getPossibleErrors()
+ * @deprecated since 1.24
+ * @return array
+ */
+ public function getFinalPossibleErrors() {
+ wfDeprecated( __METHOD__, '1.24' );
+ return array();
+ }
+
+ /**
+ * @see self::getPossibleErrors()
+ * @deprecated since 1.24
+ * @return array
+ */
+ public function parseErrors( $errors ) {
+ wfDeprecated( __METHOD__, '1.24' );
+ return array();
+ }
+
+ /**
+ * Returns the description string for this module
+ *
+ * Ignored if an i18n message exists for
+ * "apihelp-{$this->getModulePathString()}-description".
+ *
+ * @deprecated since 1.25
+ * @return Message|string|array
+ */
+ protected function getDescription() {
+ return false;
+ }
+
+ /**
+ * Returns an array of parameter descriptions.
+ *
+ * For each parameter, ignored if an i18n message exists for the parameter.
+ * By default that message is
+ * "apihelp-{$this->getModulePathString()}-param-{$param}", but it may be
+ * overridden using ApiBase::PARAM_HELP_MSG in the data returned by
+ * self::getFinalParams().
+ *
+ * @deprecated since 1.25
+ * @return array|bool False on no parameter descriptions
+ */
+ protected function getParamDescription() {
+ return array();
+ }
+
+ /**
+ * Returns usage examples for this module.
+ *
+ * Return value as an array is either:
+ * - numeric keys with partial URLs ("api.php?" plus a query string) as
+ * values
+ * - sequential numeric keys with even-numbered keys being display-text
+ * and odd-numbered keys being partial urls
+ * - partial URLs as keys with display-text (string or array-to-be-joined)
+ * as values
+ * Return value as a string is the same as an array with a numeric key and
+ * that value, and boolean false means "no examples".
+ *
+ * @deprecated since 1.25, use getExamplesMessages() instead
+ * @return bool|string|array
+ */
+ protected function getExamples() {
+ return false;
+ }
+
+ /**
* Generates help message for this module, or false if there is no description
+ * @deprecated since 1.25
* @return string|bool
*/
public function makeHelpMsg() {
+ wfDeprecated( __METHOD__, '1.25' );
static $lnPrfx = "\n ";
$msg = $this->getFinalDescription();
@@ -1891,6 +2471,7 @@ abstract class ApiBase extends ContextSource {
}
/**
+ * @deprecated since 1.25
* @param string $item
* @return string
*/
@@ -1899,12 +2480,14 @@ abstract class ApiBase extends ContextSource {
}
/**
+ * @deprecated since 1.25
* @param string $prefix Text to split output items
* @param string $title What is being output
* @param string|array $input
* @return string
*/
protected function makeHelpArrayToString( $prefix, $title, $input ) {
+ wfDeprecated( __METHOD__, '1.25' );
if ( $input === false ) {
return '';
}
@@ -1929,9 +2512,11 @@ abstract class ApiBase extends ContextSource {
/**
* Generates the parameter descriptions for this module, to be displayed in the
* module's help.
+ * @deprecated since 1.25
* @return string|bool
*/
public function makeHelpMsgParameters() {
+ wfDeprecated( __METHOD__, '1.25' );
$params = $this->getFinalParams( ApiBase::GET_VALUES_FOR_HELP );
if ( $params ) {
@@ -2081,292 +2666,79 @@ abstract class ApiBase extends ContextSource {
return false;
}
- /**@}*/
-
- /************************************************************************//**
- * @name Profiling
- * @{
- */
-
/**
- * Profiling: total module execution time
- */
- private $mTimeIn = 0, $mModuleTime = 0;
-
- /**
- * Get the name of the module as shown in the profiler log
- *
+ * @deprecated since 1.25, always returns empty string
* @param DatabaseBase|bool $db
- *
* @return string
*/
public function getModuleProfileName( $db = false ) {
- if ( $db ) {
- return 'API:' . $this->mModuleName . '-DB';
- }
-
- return 'API:' . $this->mModuleName;
+ wfDeprecated( __METHOD__, '1.25' );
+ return '';
}
/**
- * Start module profiling
+ * @deprecated since 1.25
*/
public function profileIn() {
- if ( $this->mTimeIn !== 0 ) {
- ApiBase::dieDebug( __METHOD__, 'Called twice without calling profileOut()' );
- }
- $this->mTimeIn = microtime( true );
- wfProfileIn( $this->getModuleProfileName() );
+ // No wfDeprecated() yet because extensions call this and might need to
+ // keep doing so for BC.
}
/**
- * End module profiling
+ * @deprecated since 1.25
*/
public function profileOut() {
- if ( $this->mTimeIn === 0 ) {
- ApiBase::dieDebug( __METHOD__, 'Called without calling profileIn() first' );
- }
- if ( $this->mDBTimeIn !== 0 ) {
- ApiBase::dieDebug(
- __METHOD__,
- 'Must be called after database profiling is done with profileDBOut()'
- );
- }
-
- $this->mModuleTime += microtime( true ) - $this->mTimeIn;
- $this->mTimeIn = 0;
- wfProfileOut( $this->getModuleProfileName() );
+ // No wfDeprecated() yet because extensions call this and might need to
+ // keep doing so for BC.
}
/**
- * When modules crash, sometimes it is needed to do a profileOut() regardless
- * of the profiling state the module was in. This method does such cleanup.
+ * @deprecated since 1.25
*/
public function safeProfileOut() {
- if ( $this->mTimeIn !== 0 ) {
- if ( $this->mDBTimeIn !== 0 ) {
- $this->profileDBOut();
- }
- $this->profileOut();
- }
+ wfDeprecated( __METHOD__, '1.25' );
}
/**
- * Total time the module was executed
+ * @deprecated since 1.25, always returns 0
* @return float
*/
public function getProfileTime() {
- if ( $this->mTimeIn !== 0 ) {
- ApiBase::dieDebug( __METHOD__, 'Called without calling profileOut() first' );
- }
-
- return $this->mModuleTime;
+ wfDeprecated( __METHOD__, '1.25' );
+ return 0;
}
/**
- * Profiling: database execution time
- */
- private $mDBTimeIn = 0, $mDBTime = 0;
-
- /**
- * Start module profiling
+ * @deprecated since 1.25
*/
public function profileDBIn() {
- if ( $this->mTimeIn === 0 ) {
- ApiBase::dieDebug(
- __METHOD__,
- 'Must be called while profiling the entire module with profileIn()'
- );
- }
- if ( $this->mDBTimeIn !== 0 ) {
- ApiBase::dieDebug( __METHOD__, 'Called twice without calling profileDBOut()' );
- }
- $this->mDBTimeIn = microtime( true );
- wfProfileIn( $this->getModuleProfileName( true ) );
+ wfDeprecated( __METHOD__, '1.25' );
}
/**
- * End database profiling
+ * @deprecated since 1.25
*/
public function profileDBOut() {
- if ( $this->mTimeIn === 0 ) {
- ApiBase::dieDebug( __METHOD__, 'Must be called while profiling ' .
- 'the entire module with profileIn()' );
- }
- if ( $this->mDBTimeIn === 0 ) {
- ApiBase::dieDebug( __METHOD__, 'Called without calling profileDBIn() first' );
- }
-
- $time = microtime( true ) - $this->mDBTimeIn;
- $this->mDBTimeIn = 0;
-
- $this->mDBTime += $time;
- $this->getMain()->mDBTime += $time;
- wfProfileOut( $this->getModuleProfileName( true ) );
+ wfDeprecated( __METHOD__, '1.25' );
}
/**
- * Total time the module used the database
+ * @deprecated since 1.25, always returns 0
* @return float
*/
public function getProfileDBTime() {
- if ( $this->mDBTimeIn !== 0 ) {
- ApiBase::dieDebug( __METHOD__, 'Called without calling profileDBOut() first' );
- }
-
- return $this->mDBTime;
- }
-
- /**
- * Write logging information for API features to a debug log, for usage
- * analysis.
- * @param string $feature Feature being used.
- */
- protected function logFeatureUsage( $feature ) {
- $request = $this->getRequest();
- $s = '"' . addslashes( $feature ) . '"' .
- ' "' . wfUrlencode( str_replace( ' ', '_', $this->getUser()->getName() ) ) . '"' .
- ' "' . $request->getIP() . '"' .
- ' "' . addslashes( $request->getHeader( 'Referer' ) ) . '"' .
- ' "' . addslashes( $request->getHeader( 'User-agent' ) ) . '"';
- wfDebugLog( 'api-feature-usage', $s, 'private' );
- }
-
- /**@}*/
-
- /************************************************************************//**
- * @name Deprecated
- * @{
- */
-
- /// @deprecated since 1.24
- const PROP_ROOT = 'ROOT';
- /// @deprecated since 1.24
- const PROP_LIST = 'LIST';
- /// @deprecated since 1.24
- const PROP_TYPE = 0;
- /// @deprecated since 1.24
- const PROP_NULLABLE = 1;
-
- /**
- * Formerly returned a string that identifies the version of the extending
- * class. Typically included the class name, the svn revision, timestamp,
- * and last author. Usually done with SVN's Id keyword
- *
- * @deprecated since 1.21, version string is no longer supported
- * @return string
- */
- public function getVersion() {
- wfDeprecated( __METHOD__, '1.21' );
- return '';
- }
-
- /**
- * Formerly used to fetch a list of possible properites in the result,
- * somehow organized with respect to the prop parameter that causes them to
- * be returned. The specific semantics of the return value was never
- * specified. Since this was never possible to be accurately updated, it
- * has been removed.
- *
- * @deprecated since 1.24
- * @return array|bool
- */
- protected function getResultProperties() {
- wfDeprecated( __METHOD__, '1.24' );
- return false;
- }
-
- /**
- * @see self::getResultProperties()
- * @deprecated since 1.24
- * @return array|bool
- */
- public function getFinalResultProperties() {
- wfDeprecated( __METHOD__, '1.24' );
- return array();
+ wfDeprecated( __METHOD__, '1.25' );
+ return 0;
}
/**
- * @see self::getResultProperties()
- * @deprecated since 1.24
- */
- protected static function addTokenProperties( &$props, $tokenFunctions ) {
- wfDeprecated( __METHOD__, '1.24' );
- }
-
- /**
- * @see self::getPossibleErrors()
- * @deprecated since 1.24
- * @return array
- */
- public function getRequireOnlyOneParameterErrorMessages( $params ) {
- wfDeprecated( __METHOD__, '1.24' );
- return array();
- }
-
- /**
- * @see self::getPossibleErrors()
- * @deprecated since 1.24
- * @return array
- */
- public function getRequireMaxOneParameterErrorMessages( $params ) {
- wfDeprecated( __METHOD__, '1.24' );
- return array();
- }
-
- /**
- * @see self::getPossibleErrors()
- * @deprecated since 1.24
- * @return array
- */
- public function getRequireAtLeastOneParameterErrorMessages( $params ) {
- wfDeprecated( __METHOD__, '1.24' );
- return array();
- }
-
- /**
- * @see self::getPossibleErrors()
- * @deprecated since 1.24
- * @return array
- */
- public function getTitleOrPageIdErrorMessage() {
- wfDeprecated( __METHOD__, '1.24' );
- return array();
- }
-
- /**
- * This formerly attempted to return a list of all possible errors returned
- * by the module. However, this was impossible to maintain in many cases
- * since errors could come from other areas of MediaWiki and in some cases
- * from arbitrary extension hooks. Since a partial list claiming to be
- * comprehensive is unlikely to be useful, it was removed.
- *
- * @deprecated since 1.24
- * @return array
- */
- public function getPossibleErrors() {
- wfDeprecated( __METHOD__, '1.24' );
- return array();
- }
-
- /**
- * @see self::getPossibleErrors()
- * @deprecated since 1.24
- * @return array
- */
- public function getFinalPossibleErrors() {
- wfDeprecated( __METHOD__, '1.24' );
- return array();
- }
-
- /**
- * @see self::getPossibleErrors()
- * @deprecated since 1.24
+ * Get the result data array (read-only)
+ * @deprecated since 1.25, use $this->getResult() methods instead
* @return array
*/
- public function parseErrors( $errors ) {
- wfDeprecated( __METHOD__, '1.24' );
- return array();
+ public function getResultData() {
+ wfDeprecated( __METHOD__, '1.25' );
+ return $this->getResult()->getData();
}
/**@}*/
diff --git a/includes/api/ApiBlock.php b/includes/api/ApiBlock.php
index 07f62c66..4d39ce1b 100644
--- a/includes/api/ApiBlock.php
+++ b/includes/api/ApiBlock.php
@@ -78,7 +78,7 @@ class ApiBlock extends ApiBase {
'other',
$params['reason']
),
- 'Expiry' => $params['expiry'] == 'never' ? 'infinite' : $params['expiry'],
+ 'Expiry' => $params['expiry'],
'HardBlock' => !$params['anononly'],
'CreateAccount' => $params['nocreate'],
'AutoBlock' => $params['autoblock'],
@@ -113,27 +113,13 @@ class ApiBlock extends ApiBase {
}
$res['reason'] = $params['reason'];
- if ( $params['anononly'] ) {
- $res['anononly'] = '';
- }
- if ( $params['nocreate'] ) {
- $res['nocreate'] = '';
- }
- if ( $params['autoblock'] ) {
- $res['autoblock'] = '';
- }
- if ( $params['noemail'] ) {
- $res['noemail'] = '';
- }
- if ( $params['hidename'] ) {
- $res['hidename'] = '';
- }
- if ( $params['allowusertalk'] ) {
- $res['allowusertalk'] = '';
- }
- if ( $params['watchuser'] ) {
- $res['watchuser'] = '';
- }
+ $res['anononly'] = $params['anononly'];
+ $res['nocreate'] = $params['nocreate'];
+ $res['autoblock'] = $params['autoblock'];
+ $res['noemail'] = $params['noemail'];
+ $res['hidename'] = $params['hidename'];
+ $res['allowusertalk'] = $params['allowusertalk'];
+ $res['watchuser'] = $params['watchuser'];
$this->getResult()->addValue( null, $this->getModuleName(), $res );
}
@@ -165,38 +151,16 @@ class ApiBlock extends ApiBase {
);
}
- public function getParamDescription() {
- return array(
- 'user' => 'Username, IP address or IP range you want to block',
- 'expiry' => 'Relative expiry time, e.g. \'5 months\' or \'2 weeks\'. ' .
- 'If set to \'infinite\', \'indefinite\' or \'never\', the block will never expire.',
- 'reason' => 'Reason for block',
- 'anononly' => 'Block anonymous users only (i.e. disable anonymous edits for this IP)',
- 'nocreate' => 'Prevent account creation',
- 'autoblock' => 'Automatically block the last used IP address, and ' .
- 'any subsequent IP addresses they try to login from',
- 'noemail'
- => 'Prevent user from sending email through the wiki. (Requires the "blockemail" right.)',
- 'hidename' => 'Hide the username from the block log. (Requires the "hideuser" right.)',
- 'allowusertalk'
- => 'Allow the user to edit their own talk page (depends on $wgBlockAllowsUTEdit)',
- 'reblock' => 'If the user is already blocked, overwrite the existing block',
- 'watchuser' => 'Watch the user/IP\'s user and talk pages',
- );
- }
-
- public function getDescription() {
- return 'Block a user.';
- }
-
public function needsToken() {
return 'csrf';
}
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=block&user=123.5.5.12&expiry=3%20days&reason=First%20strike&token=123ABC',
- 'api.php?action=block&user=Vandal&expiry=never&reason=Vandalism&nocreate=&autoblock=&noemail=&token=123ABC'
+ 'action=block&user=192.0.2.5&expiry=3%20days&reason=First%20strike&token=123ABC'
+ => 'apihelp-block-example-ip-simple',
+ 'action=block&user=Vandal&expiry=never&reason=Vandalism&nocreate=&autoblock=&noemail=&token=123ABC'
+ => 'apihelp-block-example-user-complex',
);
}
diff --git a/includes/api/ApiCheckToken.php b/includes/api/ApiCheckToken.php
new file mode 100644
index 00000000..28c6ece7
--- /dev/null
+++ b/includes/api/ApiCheckToken.php
@@ -0,0 +1,81 @@
+<?php
+/**
+ * Created on Jan 29, 2015
+ *
+ * Copyright © 2015 Brad Jorsch bjorsch@wikimedia.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * @since 1.25
+ * @ingroup API
+ */
+class ApiCheckToken extends ApiBase {
+
+ public function execute() {
+ $params = $this->extractRequestParams();
+ $token = $params['token'];
+ $maxage = $params['maxtokenage'];
+ $request = $this->getRequest();
+ $salts = ApiQueryTokens::getTokenTypeSalts();
+ $salt = $salts[$params['type']];
+
+ $res = array();
+
+ if ( $this->getUser()->matchEditToken( $token, $salt, $request, $maxage ) ) {
+ $res['result'] = 'valid';
+ } elseif ( $maxage !== null && $this->getUser()->matchEditToken( $token, $salt, $request ) ) {
+ $res['result'] = 'expired';
+ } else {
+ $res['result'] = 'invalid';
+ }
+
+ $ts = User::getEditTokenTimestamp( $token );
+ if ( $ts !== null ) {
+ $mwts = new MWTimestamp();
+ $mwts->timestamp->setTimestamp( $ts );
+ $res['generated'] = $mwts->getTimestamp( TS_ISO_8601 );
+ }
+
+ $this->getResult()->addValue( null, $this->getModuleName(), $res );
+ }
+
+ public function getAllowedParams() {
+ return array(
+ 'type' => array(
+ ApiBase::PARAM_TYPE => array_keys( ApiQueryTokens::getTokenTypeSalts() ),
+ ApiBase::PARAM_REQUIRED => true,
+ ),
+ 'token' => array(
+ ApiBase::PARAM_TYPE => 'string',
+ ApiBase::PARAM_REQUIRED => true,
+ ),
+ 'maxtokenage' => array(
+ ApiBase::PARAM_TYPE => 'integer',
+ ),
+ );
+ }
+
+ protected function getExamplesMessages() {
+ return array(
+ 'action=checktoken&type=csrf&token=123ABC'
+ => 'apihelp-checktoken-example-simple',
+ );
+ }
+}
diff --git a/includes/api/ApiClearHasMsg.php b/includes/api/ApiClearHasMsg.php
index 32e20e80..eb471ae6 100644
--- a/includes/api/ApiClearHasMsg.php
+++ b/includes/api/ApiClearHasMsg.php
@@ -42,13 +42,10 @@ class ApiClearHasMsg extends ApiBase {
return false;
}
- public function getDescription() {
- return array( 'Clears the hasmsg flag for current user.' );
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=clearhasmsg' => 'Clears the hasmsg flag for current user',
+ 'action=clearhasmsg'
+ => 'apihelp-clearhasmsg-example-1',
);
}
diff --git a/includes/api/ApiComparePages.php b/includes/api/ApiComparePages.php
index 48559268..23009123 100644
--- a/includes/api/ApiComparePages.php
+++ b/includes/api/ApiComparePages.php
@@ -72,7 +72,7 @@ class ApiComparePages extends ApiBase {
);
}
- ApiResult::setContent( $vals, $difftext );
+ ApiResult::setContentValue( $vals, 'body', $difftext );
$this->getResult()->addValue( null, $this->getModuleName(), $vals );
}
@@ -126,27 +126,10 @@ class ApiComparePages extends ApiBase {
);
}
- public function getParamDescription() {
+ protected function getExamplesMessages() {
return array(
- 'fromtitle' => 'First title to compare',
- 'fromid' => 'First page ID to compare',
- 'fromrev' => 'First revision to compare',
- 'totitle' => 'Second title to compare',
- 'toid' => 'Second page ID to compare',
- 'torev' => 'Second revision to compare',
- );
- }
-
- public function getDescription() {
- return array(
- 'Get the difference between 2 pages.',
- 'You must pass a revision number or a page title or a page ID id for each part (1 and 2).'
- );
- }
-
- public function getExamples() {
- return array(
- 'api.php?action=compare&fromrev=1&torev=2' => 'Create a diff between revision 1 and 2',
+ 'action=compare&fromrev=1&torev=2'
+ => 'apihelp-compare-example-1',
);
}
}
diff --git a/includes/api/ApiContinuationManager.php b/includes/api/ApiContinuationManager.php
new file mode 100644
index 00000000..354f4e7d
--- /dev/null
+++ b/includes/api/ApiContinuationManager.php
@@ -0,0 +1,238 @@
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * This manages continuation state.
+ * @since 1.25 this is no longer a subclass of ApiBase
+ * @ingroup API
+ */
+class ApiContinuationManager {
+ private $source;
+
+ private $allModules = array();
+ private $generatedModules = array();
+
+ private $continuationData = array();
+ private $generatorContinuationData = array();
+
+ private $generatorParams = array();
+ private $generatorDone = false;
+
+ /**
+ * @param ApiBase $module Module starting the continuation
+ * @param ApiBase[] $allModules Contains ApiBase instances that will be executed
+ * @param array $generatedModules Names of modules that depend on the generator
+ */
+ public function __construct(
+ ApiBase $module, array $allModules = array(), array $generatedModules = array()
+ ) {
+ $this->source = get_class( $module );
+ $request = $module->getRequest();
+
+ $this->generatedModules = $generatedModules
+ ? array_combine( $generatedModules, $generatedModules )
+ : array();
+
+ $skip = array();
+ $continue = $request->getVal( 'continue', '' );
+ if ( $continue !== '' ) {
+ $continue = explode( '||', $continue );
+ if ( count( $continue ) !== 2 ) {
+ throw new UsageException(
+ 'Invalid continue param. You should pass the original value returned by the previous query',
+ 'badcontinue'
+ );
+ }
+ $this->generatorDone = ( $continue[0] === '-' );
+ $skip = explode( '|', $continue[1] );
+ if ( !$this->generatorDone ) {
+ $params = explode( '|', $continue[0] );
+ if ( $params ) {
+ $this->generatorParams = array_intersect_key(
+ $request->getValues(),
+ array_flip( $params )
+ );
+ }
+ } else {
+ // When the generator is complete, don't run any modules that
+ // depend on it.
+ $skip += $this->generatedModules;
+ }
+ }
+
+ foreach ( $allModules as $module ) {
+ $name = $module->getModuleName();
+ if ( in_array( $name, $skip, true ) ) {
+ $this->allModules[$name] = false;
+ // Prevent spurious "unused parameter" warnings
+ $module->extractRequestParams();
+ } else {
+ $this->allModules[$name] = $module;
+ }
+ }
+ }
+
+ /**
+ * Get the class that created this manager
+ * @return string
+ */
+ public function getSource() {
+ return $this->source;
+ }
+
+ /**
+ * Is the generator done?
+ * @return bool
+ */
+ public function isGeneratorDone() {
+ return $this->generatorDone;
+ }
+
+ /**
+ * Get the list of modules that should actually be run
+ * @return ApiBase[]
+ */
+ public function getRunModules() {
+ return array_values( array_filter( $this->allModules ) );
+ }
+
+ /**
+ * Set the continuation parameter for a module
+ * @param ApiBase $module
+ * @param string $paramName
+ * @param string|array $paramValue
+ * @throws UnexpectedValueException
+ */
+ public function addContinueParam( ApiBase $module, $paramName, $paramValue ) {
+ $name = $module->getModuleName();
+ if ( !isset( $this->allModules[$name] ) ) {
+ throw new UnexpectedValueException(
+ "Module '$name' called " . __METHOD__ .
+ ' but was not passed to ' . __CLASS__ . '::__construct'
+ );
+ }
+ if ( !$this->allModules[$name] ) {
+ throw new UnexpectedValueException(
+ "Module '$name' was not supposed to have been executed, but " .
+ 'it was executed anyway'
+ );
+ }
+ $paramName = $module->encodeParamName( $paramName );
+ if ( is_array( $paramValue ) ) {
+ $paramValue = join( '|', $paramValue );
+ }
+ $this->continuationData[$name][$paramName] = $paramValue;
+ }
+
+ /**
+ * Set the continuation parameter for the generator module
+ * @param ApiBase $module
+ * @param string $paramName
+ * @param string|array $paramValue
+ */
+ public function addGeneratorContinueParam( ApiBase $module, $paramName, $paramValue ) {
+ $name = $module->getModuleName();
+ $paramName = $module->encodeParamName( $paramName );
+ if ( is_array( $paramValue ) ) {
+ $paramValue = join( '|', $paramValue );
+ }
+ $this->generatorContinuationData[$name][$paramName] = $paramValue;
+ }
+
+ /**
+ * Fetch raw continuation data
+ * @return array
+ */
+ public function getRawContinuation() {
+ return array_merge_recursive( $this->continuationData, $this->generatorContinuationData );
+ }
+
+ /**
+ * Fetch continuation result data
+ * @return array Array( (array)$data, (bool)$batchcomplete )
+ */
+ public function getContinuation() {
+ $data = array();
+ $batchcomplete = false;
+
+ $finishedModules = array_diff(
+ array_keys( $this->allModules ),
+ array_keys( $this->continuationData )
+ );
+
+ // First, grab the non-generator-using continuation data
+ $continuationData = array_diff_key( $this->continuationData, $this->generatedModules );
+ foreach ( $continuationData as $module => $kvp ) {
+ $data += $kvp;
+ }
+
+ // Next, handle the generator-using continuation data
+ $continuationData = array_intersect_key( $this->continuationData, $this->generatedModules );
+ if ( $continuationData ) {
+ // Some modules are unfinished: include those params, and copy
+ // the generator params.
+ foreach ( $continuationData as $module => $kvp ) {
+ $data += $kvp;
+ }
+ $data += $this->generatorParams;
+ $generatorKeys = join( '|', array_keys( $this->generatorParams ) );
+ } elseif ( $this->generatorContinuationData ) {
+ // All the generator-using modules are complete, but the
+ // generator isn't. Continue the generator and restart the
+ // generator-using modules
+ $generatorParams = array();
+ foreach ( $this->generatorContinuationData as $kvp ) {
+ $generatorParams += $kvp;
+ }
+ $data += $generatorParams;
+ $finishedModules = array_diff( $finishedModules, $this->generatedModules );
+ $generatorKeys = join( '|', array_keys( $generatorParams ) );
+ $batchcomplete = true;
+ } else {
+ // Generator and prop modules are all done. Mark it so.
+ $generatorKeys = '-';
+ $batchcomplete = true;
+ }
+
+ // Set 'continue' if any continuation data is set or if the generator
+ // still needs to run
+ if ( $data || $generatorKeys !== '-' ) {
+ $data['continue'] = $generatorKeys . '||' . join( '|', $finishedModules );
+ }
+
+ return array( $data, $batchcomplete );
+ }
+
+ /**
+ * Store the continuation data into the result
+ * @param ApiResult $result
+ */
+ public function setContinuationIntoResult( ApiResult $result ) {
+ list( $data, $batchcomplete ) = $this->getContinuation();
+ if ( $data ) {
+ $result->addValue( null, 'continue', $data,
+ ApiResult::ADD_ON_TOP | ApiResult::NO_SIZE_CHECK );
+ }
+ if ( $batchcomplete ) {
+ $result->addValue( null, 'batchcomplete', true,
+ ApiResult::ADD_ON_TOP | ApiResult::NO_SIZE_CHECK );
+ }
+ }
+}
diff --git a/includes/api/ApiCreateAccount.php b/includes/api/ApiCreateAccount.php
index 2ce532b9..455540b4 100644
--- a/includes/api/ApiCreateAccount.php
+++ b/includes/api/ApiCreateAccount.php
@@ -29,9 +29,12 @@
*/
class ApiCreateAccount extends ApiBase {
public function execute() {
- // If we're in JSON callback mode, no tokens can be obtained
- if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) {
- $this->dieUsage( 'Cannot create account when using a callback', 'aborted' );
+ // If we're in a mode that breaks the same-origin policy, no tokens can
+ // be obtained
+ if ( $this->lacksSameOriginSecurity() ) {
+ $this->dieUsage(
+ 'Cannot create account when the same-origin policy is not applied', 'aborted'
+ );
}
// $loginForm->addNewaccountInternal will throw exceptions
@@ -83,7 +86,7 @@ class ApiCreateAccount extends ApiBase {
$loginForm = new LoginForm();
$loginForm->setContext( $context );
- wfRunHooks( 'AddNewAccountApiForm', array( $this, $loginForm ) );
+ Hooks::run( 'AddNewAccountApiForm', array( $this, $loginForm ) );
$loginForm->load();
$status = $loginForm->addNewaccountInternal();
@@ -113,7 +116,7 @@ class ApiCreateAccount extends ApiBase {
// Save settings (including confirmation token)
$user->saveSettings();
- wfRunHooks( 'AddNewAccount', array( $user, $params['mailpassword'] ) );
+ Hooks::run( 'AddNewAccount', array( $user, $params['mailpassword'] ) );
if ( $params['mailpassword'] ) {
$logAction = 'byemail';
@@ -149,9 +152,9 @@ class ApiCreateAccount extends ApiBase {
$warnings = $status->getErrorsByType( 'warning' );
if ( $warnings ) {
foreach ( $warnings as &$warning ) {
- $apiResult->setIndexedTagName( $warning['params'], 'param' );
+ ApiResult::setIndexedTagName( $warning['params'], 'param' );
}
- $apiResult->setIndexedTagName( $warnings, 'warning' );
+ ApiResult::setIndexedTagName( $warnings, 'warning' );
$result['warnings'] = $warnings;
}
} else {
@@ -160,15 +163,11 @@ class ApiCreateAccount extends ApiBase {
}
// Give extensions a chance to modify the API result data
- wfRunHooks( 'AddNewAccountApiResult', array( $this, $loginForm, &$result ) );
+ Hooks::run( 'AddNewAccountApiResult', array( $this, $loginForm, &$result ) );
$apiResult->addValue( null, 'createaccount', $result );
}
- public function getDescription() {
- return 'Create a new user account.';
- }
-
public function mustBePosted() {
return true;
}
@@ -204,27 +203,12 @@ class ApiCreateAccount extends ApiBase {
);
}
- public function getParamDescription() {
- $p = $this->getModulePrefix();
-
- return array(
- 'name' => 'Username',
- 'password' => "Password (ignored if {$p}mailpassword is set)",
- 'domain' => 'Domain for external authentication (optional)',
- 'token' => 'Account creation token obtained in first request',
- 'email' => 'Email address of user (optional)',
- 'realname' => 'Real name of user (optional)',
- 'mailpassword' => 'If set to any value, a random password will be emailed to the user',
- 'reason' => 'Optional reason for creating the account to be put in the logs',
- 'language'
- => 'Language code to set as default for the user (optional, defaults to content language)'
- );
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=createaccount&name=testuser&password=test123',
- 'api.php?action=createaccount&name=testmailuser&mailpassword=true&reason=MyReason',
+ 'action=createaccount&name=testuser&password=test123'
+ => 'apihelp-createaccount-example-pass',
+ 'action=createaccount&name=testmailuser&mailpassword=true&reason=MyReason'
+ => 'apihelp-createaccount-example-mail',
);
}
diff --git a/includes/api/ApiDelete.php b/includes/api/ApiDelete.php
index abca8245..d8b57182 100644
--- a/includes/api/ApiDelete.php
+++ b/includes/api/ApiDelete.php
@@ -210,35 +210,16 @@ class ApiDelete extends ApiBase {
);
}
- public function getParamDescription() {
- $p = $this->getModulePrefix();
-
- return array(
- 'title' => "Title of the page you want to delete. Cannot be used together with {$p}pageid",
- 'pageid' => "Page ID of the page you want to delete. Cannot be used together with {$p}title",
- 'reason'
- => 'Reason for the deletion. If not set, an automatically generated reason will be used',
- 'watch' => 'Add the page to your watchlist',
- 'watchlist' => 'Unconditionally add or remove the page from your ' .
- 'watchlist, use preferences or do not change watch',
- 'unwatch' => 'Remove the page from your watchlist',
- 'oldimage' => 'The name of the old image to delete as provided by iiprop=archivename'
- );
- }
-
- public function getDescription() {
- return 'Delete a page.';
- }
-
public function needsToken() {
return 'csrf';
}
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=delete&title=Main%20Page&token=123ABC' => 'Delete the Main Page',
- 'api.php?action=delete&title=Main%20Page&token=123ABC&reason=Preparing%20for%20move'
- => 'Delete the Main Page with the reason "Preparing for move"',
+ 'action=delete&title=Main%20Page&token=123ABC'
+ => 'apihelp-delete-example-simple',
+ 'action=delete&title=Main%20Page&token=123ABC&reason=Preparing%20for%20move'
+ => 'apihelp-delete-example-reason',
);
}
diff --git a/includes/api/ApiDisabled.php b/includes/api/ApiDisabled.php
index 6ea5d202..fc975220 100644
--- a/includes/api/ApiDisabled.php
+++ b/includes/api/ApiDisabled.php
@@ -44,19 +44,7 @@ class ApiDisabled extends ApiBase {
return false;
}
- public function getAllowedParams() {
- return array();
- }
-
- public function getParamDescription() {
- return array();
- }
-
- public function getDescription() {
- return 'This module has been disabled.';
- }
-
- public function getExamples() {
- return array();
+ protected function getDescriptionMessage() {
+ return 'apihelp-disabled-description';
}
}
diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php
index a423b560..54a83915 100644
--- a/includes/api/ApiEditPage.php
+++ b/includes/api/ApiEditPage.php
@@ -28,7 +28,9 @@
* A module that allows for editing and creating pages.
*
* Currently, this wraps around the EditPage class in an ugly way,
- * EditPage.php should be rewritten to provide a cleaner interface
+ * EditPage.php should be rewritten to provide a cleaner interface,
+ * see T20654 if you're inspired to fix this.
+ *
* @ingroup API
*/
class ApiEditPage extends ApiBase {
@@ -48,8 +50,12 @@ class ApiEditPage extends ApiBase {
$apiResult = $this->getResult();
if ( $params['redirect'] ) {
- if ( $params['prependtext'] === null && $params['appendtext'] === null && $params['section'] !== 'new' ) {
- $this->dieUsage( 'You have attempted to edit using the "redirect"-following mode, which must be used in conjuction with section=new, prependtext, or appendtext.', 'redirect-appendonly' );
+ if ( $params['prependtext'] === null && $params['appendtext'] === null
+ && $params['section'] !== 'new'
+ ) {
+ $this->dieUsage( 'You have attempted to edit using the "redirect"-following'
+ . ' mode, which must be used in conjuction with section=new, prependtext'
+ . ', or appendtext.', 'redirect-appendonly' );
}
if ( $titleObj->isRedirect() ) {
$oldTitle = $titleObj;
@@ -76,7 +82,7 @@ class ApiEditPage extends ApiBase {
$titleObj = $newTitle;
}
- $apiResult->setIndexedTagName( $redirValues, 'r' );
+ ApiResult::setIndexedTagName( $redirValues, 'r' );
$apiResult->addValue( null, 'redirects', $redirValues );
// Since the page changed, update $pageObj
@@ -195,9 +201,9 @@ class ApiEditPage extends ApiBase {
list( $params['undo'], $params['undoafter'] ) =
array( $params['undoafter'], $params['undo'] );
}
- $undoafterRev = Revision::newFromID( $params['undoafter'] );
+ $undoafterRev = Revision::newFromId( $params['undoafter'] );
}
- $undoRev = Revision::newFromID( $params['undo'] );
+ $undoRev = Revision::newFromId( $params['undo'] );
if ( is_null( $undoRev ) || $undoRev->isDeleted( Revision::DELETED_TEXT ) ) {
$this->dieUsageMsg( array( 'nosuchrevid', $params['undo'] ) );
}
@@ -252,8 +258,10 @@ class ApiEditPage extends ApiBase {
'format' => $contentFormat,
'model' => $contentHandler->getModelID(),
'wpEditToken' => $params['token'],
- 'wpIgnoreBlankSummary' => '',
- 'wpIgnoreBlankArticle' => true
+ 'wpIgnoreBlankSummary' => true,
+ 'wpIgnoreBlankArticle' => true,
+ 'wpIgnoreSelfRedirect' => true,
+ 'bot' => $params['bot'],
);
if ( !is_null( $params['summary'] ) ) {
@@ -294,10 +302,13 @@ class ApiEditPage extends ApiBase {
if ( !is_null( $params['section'] ) ) {
$section = $params['section'];
if ( !preg_match( '/^((T-)?\d+|new)$/', $section ) ) {
- $this->dieUsage( "The section parameter must be a valid section id or 'new'", "invalidsection" );
+ $this->dieUsage( "The section parameter must be a valid section id or 'new'",
+ "invalidsection" );
}
$content = $pageObj->getContent();
- if ( $section !== '0' && $section != 'new' && ( !$content || !$content->getSection( $section ) ) ) {
+ if ( $section !== '0' && $section != 'new'
+ && ( !$content || !$content->getSection( $section ) )
+ ) {
$this->dieUsage( "There is no section {$section}.", 'nosuchsection' );
}
$requestArray['wpSection'] = $params['section'];
@@ -320,6 +331,15 @@ class ApiEditPage extends ApiBase {
$requestArray['wpWatchthis'] = '';
}
+ // Apply change tags
+ if ( count( $params['tags'] ) ) {
+ if ( $user->isAllowed( 'applychangetags' ) ) {
+ $requestArray['wpChangeTags'] = implode( ',', $params['tags'] );
+ } else {
+ $this->dieUsage( 'You don\'t have permission to set change tags.', 'taggingnotallowed' );
+ }
+ }
+
// Pass through anything else we might have been given, to support extensions
// This is kind of a hack but it's the best we can do to make extensions work
$requestArray += $this->getRequest()->getValues();
@@ -381,7 +401,7 @@ class ApiEditPage extends ApiBase {
// Run hooks
// Handle APIEditBeforeSave parameters
$r = array();
- if ( !wfRunHooks( 'APIEditBeforeSave', array( $ep, $content, &$r ) ) ) {
+ if ( !Hooks::run( 'APIEditBeforeSave', array( $ep, $content, &$r ) ) ) {
if ( count( $r ) ) {
$r['result'] = 'Failure';
$apiResult->addValue( null, $this->getModuleName(), $r );
@@ -400,13 +420,20 @@ class ApiEditPage extends ApiBase {
$oldRequest = $wgRequest;
$wgRequest = $req;
- $status = $ep->internalAttemptSave( $result, $user->isAllowed( 'bot' ) && $params['bot'] );
+ $status = $ep->attemptSave( $result );
$wgRequest = $oldRequest;
switch ( $status->value ) {
case EditPage::AS_HOOK_ERROR:
case EditPage::AS_HOOK_ERROR_EXPECTED:
- $this->dieUsageMsg( 'hookaborted' );
+ if ( isset( $status->apiHookResult ) ) {
+ $r = $status->apiHookResult;
+ $r['result'] = 'Failure';
+ $apiResult->addValue( null, $this->getModuleName(), $r );
+ return;
+ } else {
+ $this->dieUsageMsg( 'hookaborted' );
+ }
case EditPage::AS_PARSE_ERROR:
$this->dieUsage( $status->getMessage(), 'parseerror' );
@@ -454,12 +481,14 @@ class ApiEditPage extends ApiBase {
case EditPage::AS_CONFLICT_DETECTED:
$this->dieUsageMsg( 'editconflict' );
- // case EditPage::AS_SUMMARY_NEEDED: Can't happen since we set wpIgnoreBlankSummary
case EditPage::AS_TEXTBOX_EMPTY:
$this->dieUsageMsg( 'emptynewsection' );
+ case EditPage::AS_CHANGE_TAG_ERROR:
+ $this->dieStatus( $status );
+
case EditPage::AS_SUCCESS_NEW_ARTICLE:
- $r['new'] = '';
+ $r['new'] = true;
// fall-through
case EditPage::AS_SUCCESS_UPDATE:
@@ -469,7 +498,7 @@ class ApiEditPage extends ApiBase {
$r['contentmodel'] = $titleObj->getContentModel();
$newRevId = $articleObject->getLatest();
if ( $newRevId == $oldRevId ) {
- $r['nochange'] = '';
+ $r['nochange'] = true;
} else {
$r['oldrevid'] = intval( $oldRevId );
$r['newrevid'] = intval( $newRevId );
@@ -479,6 +508,7 @@ class ApiEditPage extends ApiBase {
break;
case EditPage::AS_SUMMARY_NEEDED:
+ // Shouldn't happen since we set wpIgnoreBlankSummary, but just in case
$this->dieUsageMsg( 'summaryrequired' );
case EditPage::AS_END:
@@ -499,10 +529,6 @@ class ApiEditPage extends ApiBase {
return true;
}
- public function getDescription() {
- return 'Create and edit pages.';
- }
-
public function getAllowedParams() {
return array(
'title' => array(
@@ -517,6 +543,10 @@ class ApiEditPage extends ApiBase {
),
'text' => null,
'summary' => null,
+ 'tags' => array(
+ ApiBase::PARAM_TYPE => ChangeTags::listExplicitlyDefinedTags(),
+ ApiBase::PARAM_ISMULTI => true,
+ ),
'minor' => false,
'notminor' => false,
'bot' => false,
@@ -560,58 +590,11 @@ class ApiEditPage extends ApiBase {
),
'contentmodel' => array(
ApiBase::PARAM_TYPE => ContentHandler::getContentModels(),
- )
- );
- }
-
- public function getParamDescription() {
- $p = $this->getModulePrefix();
-
- return array(
- 'title' => "Title of the page you want to edit. Cannot be used together with {$p}pageid",
- 'pageid' => "Page ID of the page you want to edit. Cannot be used together with {$p}title",
- 'section' => 'Section number. 0 for the top section, \'new\' for a new section',
- 'sectiontitle' => 'The title for a new section',
- 'text' => 'Page content',
- 'token' => array(
- /* Standard description is automatically prepended */
- 'The token should always be sent as the last parameter, or at ' .
- "least, after the {$p}text parameter"
- ),
- 'summary'
- => "Edit summary. Also section title when {$p}section=new and {$p}sectiontitle is not set",
- 'minor' => 'Minor edit',
- 'notminor' => 'Non-minor edit',
- 'bot' => 'Mark this edit as bot',
- 'basetimestamp' => array(
- 'Timestamp of the base revision (obtained through prop=revisions&rvprop=timestamp).',
- 'Used to detect edit conflicts; leave unset to ignore conflicts'
),
- 'starttimestamp' => array(
- 'Timestamp when you began the editing process, e.g. when the current page content ' .
- 'was loaded for editing.',
- 'Used to detect edit conflicts; leave unset to ignore conflicts'
- ),
- 'recreate' => 'Override any errors about the article having been deleted in the meantime',
- 'createonly' => 'Don\'t edit the page if it exists already',
- 'nocreate' => 'Throw an error if the page doesn\'t exist',
- 'watch' => 'Add the page to your watchlist',
- 'unwatch' => 'Remove the page from your watchlist',
- 'watchlist' => 'Unconditionally add or remove the page from your ' .
- 'watchlist, use preferences or do not change watch',
- 'md5' => array(
- "The MD5 hash of the {$p}text parameter, or the {$p}prependtext " .
- "and {$p}appendtext parameters concatenated.",
- 'If set, the edit won\'t be done unless the hash is correct'
+ 'token' => array(
+ // Standard definition automatically inserted
+ ApiBase::PARAM_HELP_MSG_APPEND => array( 'apihelp-edit-param-token' ),
),
- 'prependtext' => "Add this text to the beginning of the page. Overrides {$p}text",
- 'appendtext' => array( "Add this text to the end of the page. Overrides {$p}text.",
- "Use {$p}section=new to append a new section" ),
- 'undo' => "Undo this revision. Overrides {$p}text, {$p}prependtext and {$p}appendtext",
- 'undoafter' => 'Undo all revisions from undo to this one. If not set, just undo one revision',
- 'redirect' => 'Automatically resolve redirects',
- 'contentformat' => 'Content serialization format used for the input text',
- 'contentmodel' => 'Content model of the new content',
);
}
@@ -619,17 +602,17 @@ class ApiEditPage extends ApiBase {
return 'csrf';
}
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=edit&title=Test&summary=test%20summary&' .
- 'text=article%20content&basetimestamp=20070824123454&token=%2B\\'
- => 'Edit a page (anonymous user)',
- 'api.php?action=edit&title=Test&summary=NOTOC&minor=&' .
- 'prependtext=__NOTOC__%0A&basetimestamp=20070824123454&token=%2B\\'
- => 'Prepend __NOTOC__ to a page (anonymous user)',
- 'api.php?action=edit&title=Test&undo=13585&undoafter=13579&' .
- 'basetimestamp=20070824123454&token=%2B\\'
- => 'Undo r13579 through r13585 with autosummary (anonymous user)',
+ 'action=edit&title=Test&summary=test%20summary&' .
+ 'text=article%20content&basetimestamp=2007-08-24T12:34:54Z&token=123ABC'
+ => 'apihelp-edit-example-edit',
+ 'action=edit&title=Test&summary=NOTOC&minor=&' .
+ 'prependtext=__NOTOC__%0A&basetimestamp=2007-08-24T12:34:54Z&token=123ABC'
+ => 'apihelp-edit-example-prepend',
+ 'action=edit&title=Test&undo=13585&undoafter=13579&' .
+ 'basetimestamp=2007-08-24T12:34:54Z&token=123ABC'
+ => 'apihelp-edit-example-undo',
);
}
diff --git a/includes/api/ApiEmailUser.php b/includes/api/ApiEmailUser.php
index 9870b2de..15eb475e 100644
--- a/includes/api/ApiEmailUser.php
+++ b/includes/api/ApiEmailUser.php
@@ -102,27 +102,14 @@ class ApiEmailUser extends ApiBase {
);
}
- public function getParamDescription() {
- return array(
- 'target' => 'User to send email to',
- 'subject' => 'Subject header',
- 'text' => 'Mail body',
- 'ccme' => 'Send a copy of this mail to me',
- );
- }
-
- public function getDescription() {
- return 'Email a user.';
- }
-
public function needsToken() {
return 'csrf';
}
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=emailuser&target=WikiSysop&text=Content&token=123ABC'
- => 'Send an email to the User "WikiSysop" with the text "Content"',
+ 'action=emailuser&target=WikiSysop&text=Content&token=123ABC'
+ => 'apihelp-emailuser-example-email',
);
}
diff --git a/includes/api/ApiErrorFormatter.php b/includes/api/ApiErrorFormatter.php
new file mode 100644
index 00000000..94143291
--- /dev/null
+++ b/includes/api/ApiErrorFormatter.php
@@ -0,0 +1,303 @@
+<?php
+/**
+ * This file contains the ApiErrorFormatter definition, plus implementations of
+ * specific formatters.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * Formats errors and warnings for the API, and add them to the associated
+ * ApiResult.
+ * @since 1.25
+ * @ingroup API
+ */
+class ApiErrorFormatter {
+ /** @var Title Dummy title to silence warnings from MessageCache::parse() */
+ private static $dummyTitle = null;
+
+ /** @var ApiResult */
+ protected $result;
+
+ /** @var Language */
+ protected $lang;
+ protected $useDB = false;
+ protected $format = 'none';
+
+ /**
+ * @param ApiResult $result Into which data will be added
+ * @param Language $lang Used for i18n
+ * @param string $format
+ * - text: Error message as wikitext
+ * - html: Error message as HTML
+ * - raw: Raw message key and parameters, no human-readable text
+ * - none: Code and data only, no human-readable text
+ * @param bool $useDB Whether to use local translations for errors and warnings.
+ */
+ public function __construct( ApiResult $result, Language $lang, $format, $useDB = false ) {
+ $this->result = $result;
+ $this->lang = $lang;
+ $this->useDB = $useDB;
+ $this->format = $format;
+ }
+
+ /**
+ * Fetch a dummy title to set on Messages
+ * @return Title
+ */
+ protected function getDummyTitle() {
+ if ( self::$dummyTitle === null ) {
+ self::$dummyTitle = Title::makeTitle( NS_SPECIAL, 'Badtitle/' . __METHOD__ );
+ }
+ return self::$dummyTitle;
+ }
+
+ /**
+ * Add a warning to the result
+ * @param string $moduleName
+ * @param MessageSpecifier|array|string $msg i18n message for the warning
+ * @param string $code Machine-readable code for the warning. Defaults as
+ * for IApiMessage::getApiCode().
+ * @param array $data Machine-readable data for the warning, if any.
+ * Uses IApiMessage::getApiData() if $msg implements that interface.
+ */
+ public function addWarning( $moduleName, $msg, $code = null, $data = null ) {
+ $msg = ApiMessage::create( $msg, $code, $data )
+ ->inLanguage( $this->lang )
+ ->title( $this->getDummyTitle() )
+ ->useDatabase( $this->useDB );
+ $this->addWarningOrError( 'warning', $moduleName, $msg );
+ }
+
+ /**
+ * Add an error to the result
+ * @param string $moduleName
+ * @param MessageSpecifier|array|string $msg i18n message for the error
+ * @param string $code Machine-readable code for the warning. Defaults as
+ * for IApiMessage::getApiCode().
+ * @param array $data Machine-readable data for the warning, if any.
+ * Uses IApiMessage::getApiData() if $msg implements that interface.
+ */
+ public function addError( $moduleName, $msg, $code = null, $data = null ) {
+ $msg = ApiMessage::create( $msg, $code, $data )
+ ->inLanguage( $this->lang )
+ ->title( $this->getDummyTitle() )
+ ->useDatabase( $this->useDB );
+ $this->addWarningOrError( 'error', $moduleName, $msg );
+ }
+
+ /**
+ * Add warnings and errors from a Status object to the result
+ * @param string $moduleName
+ * @param Status $status
+ * @param string[] $types 'warning' and/or 'error'
+ */
+ public function addMessagesFromStatus(
+ $moduleName, Status $status, $types = array( 'warning', 'error' )
+ ) {
+ if ( $status->isGood() || !$status->errors ) {
+ return;
+ }
+
+ $types = (array)$types;
+ foreach ( $status->errors as $error ) {
+ if ( !in_array( $error['type'], $types, true ) ) {
+ continue;
+ }
+
+ if ( $error['type'] === 'error' ) {
+ $tag = 'error';
+ } else {
+ // Assume any unknown type is a warning
+ $tag = 'warning';
+ }
+
+ if ( is_array( $error ) && isset( $error['message'] ) ) {
+ // Normal case
+ if ( $error['message'] instanceof Message ) {
+ $msg = ApiMessage::create( $error['message'], null, array() );
+ } else {
+ $args = isset( $error['params'] ) ? $error['params'] : array();
+ array_unshift( $args, $error['message'] );
+ $error += array( 'params' => array() );
+ $msg = ApiMessage::create( $args, null, array() );
+ }
+ } elseif ( is_array( $error ) ) {
+ // Weird case handled by Message::getErrorMessage
+ $msg = ApiMessage::create( $error, null, array() );
+ } else {
+ // Another weird case handled by Message::getErrorMessage
+ $msg = ApiMessage::create( $error, null, array() );
+ }
+
+ $msg->inLanguage( $this->lang )
+ ->title( $this->getDummyTitle() )
+ ->useDatabase( $this->useDB );
+ $this->addWarningOrError( $tag, $moduleName, $msg );
+ }
+ }
+
+ /**
+ * Format messages from a Status as an array
+ * @param Status $status
+ * @param string $type 'warning' or 'error'
+ * @param string|null $format
+ * @return array
+ */
+ public function arrayFromStatus( Status $status, $type = 'error', $format = null ) {
+ if ( $status->isGood() || !$status->errors ) {
+ return array();
+ }
+
+ $result = new ApiResult( 1e6 );
+ $formatter = new ApiErrorFormatter(
+ $result, $this->lang, $format ?: $this->format, $this->useDB
+ );
+ $formatter->addMessagesFromStatus( 'dummy', $status, array( $type ) );
+ switch ( $type ) {
+ case 'error':
+ return (array)$result->getResultData( array( 'errors', 'dummy' ) );
+ case 'warning':
+ return (array)$result->getResultData( array( 'warnings', 'dummy' ) );
+ }
+ }
+
+ /**
+ * Actually add the warning or error to the result
+ * @param string $tag 'warning' or 'error'
+ * @param string $moduleName
+ * @param ApiMessage|ApiRawMessage $msg
+ */
+ protected function addWarningOrError( $tag, $moduleName, $msg ) {
+ $value = array( 'code' => $msg->getApiCode() );
+ switch ( $this->format ) {
+ case 'wikitext':
+ $value += array(
+ 'text' => $msg->text(),
+ ApiResult::META_CONTENT => 'text',
+ );
+ break;
+
+ case 'html':
+ $value += array(
+ 'html' => $msg->parse(),
+ ApiResult::META_CONTENT => 'html',
+ );
+ break;
+
+ case 'raw':
+ $value += array(
+ 'message' => $msg->getKey(),
+ 'params' => $msg->getParams(),
+ );
+ ApiResult::setIndexedTagName( $value['params'], 'param' );
+ break;
+
+ case 'none':
+ break;
+ }
+ $value += $msg->getApiData();
+
+ $path = array( $tag . 's', $moduleName );
+ $existing = $this->result->getResultData( $path );
+ if ( $existing === null || !in_array( $value, $existing ) ) {
+ $flags = ApiResult::NO_SIZE_CHECK;
+ if ( $existing === null ) {
+ $flags |= ApiResult::ADD_ON_TOP;
+ }
+ $this->result->addValue( $path, null, $value, $flags );
+ $this->result->addIndexedTagName( $path, $tag );
+ }
+ }
+}
+
+/**
+ * Format errors and warnings in the old style, for backwards compatibility.
+ * @since 1.25
+ * @deprecated Only for backwards compatibility, do not use
+ * @ingroup API
+ */
+class ApiErrorFormatter_BackCompat extends ApiErrorFormatter {
+ /**
+ * @param ApiResult $result Into which data will be added
+ */
+ public function __construct( ApiResult $result ) {
+ parent::__construct( $result, Language::factory( 'en' ), 'none', false );
+ }
+
+ public function arrayFromStatus( Status $status, $type = 'error', $format = null ) {
+ if ( $status->isGood() || !$status->errors ) {
+ return array();
+ }
+
+ $result = array();
+ foreach ( $status->getErrorsByType( $type ) as $error ) {
+ if ( $error['message'] instanceof Message ) {
+ $error = array(
+ 'message' => $error['message']->getKey(),
+ 'params' => $error['message']->getParams(),
+ ) + $error;
+ }
+ ApiResult::setIndexedTagName( $error['params'], 'param' );
+ $result[] = $error;
+ }
+ ApiResult::setIndexedTagName( $result, $type );
+
+ return $result;
+ }
+
+ protected function addWarningOrError( $tag, $moduleName, $msg ) {
+ $value = $msg->plain();
+
+ if ( $tag === 'error' ) {
+ // In BC mode, only one error
+ $code = $msg->getApiCode();
+ if ( isset( ApiBase::$messageMap[$code] ) ) {
+ // Backwards compatibility
+ $code = ApiBase::$messageMap[$code]['code'];
+ }
+
+ $value = array(
+ 'code' => $code,
+ 'info' => $value,
+ ) + $msg->getApiData();
+ $this->result->addValue( null, 'error', $value,
+ ApiResult::OVERRIDE | ApiResult::ADD_ON_TOP | ApiResult::NO_SIZE_CHECK );
+ } else {
+ // Don't add duplicate warnings
+ $tag .= 's';
+ $path = array( $tag, $moduleName );
+ $oldWarning = $this->result->getResultData( array( $tag, $moduleName, $tag ) );
+ if ( $oldWarning !== null ) {
+ $warnPos = strpos( $oldWarning, $value );
+ // If $value was found in $oldWarning, check if it starts at 0 or after "\n"
+ if ( $warnPos !== false && ( $warnPos === 0 || $oldWarning[$warnPos - 1] === "\n" ) ) {
+ // Check if $value is followed by "\n" or the end of the $oldWarning
+ $warnPos += strlen( $value );
+ if ( strlen( $oldWarning ) <= $warnPos || $oldWarning[$warnPos] === "\n" ) {
+ return;
+ }
+ }
+ // If there is a warning already, append it to the existing one
+ $value = "$oldWarning\n$value";
+ }
+ $this->result->addContentValue( $path, $tag, $value,
+ ApiResult::OVERRIDE | ApiResult::ADD_ON_TOP | ApiResult::NO_SIZE_CHECK );
+ }
+ }
+}
diff --git a/includes/api/ApiExpandTemplates.php b/includes/api/ApiExpandTemplates.php
index 8a3b534d..6d064eb2 100644
--- a/includes/api/ApiExpandTemplates.php
+++ b/includes/api/ApiExpandTemplates.php
@@ -52,10 +52,19 @@ class ApiExpandTemplates extends ApiBase {
$prop = array_flip( $params['prop'] );
}
- // Create title for parser
- $title_obj = Title::newFromText( $params['title'] );
- if ( !$title_obj || $title_obj->isExternal() ) {
- $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
+ // Get title and revision ID for parser
+ $revid = $params['revid'];
+ if ( $revid !== null ) {
+ $rev = Revision::newFromId( $revid );
+ if ( !$rev ) {
+ $this->dieUsage( "There is no revision ID $revid", 'missingrev' );
+ }
+ $title_obj = $rev->getTitle();
+ } else {
+ $title_obj = Title::newFromText( $params['title'] );
+ if ( !$title_obj || $title_obj->isExternal() ) {
+ $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
+ }
}
$result = $this->getResult();
@@ -75,7 +84,7 @@ class ApiExpandTemplates extends ApiBase {
$this->logFeatureUsage( 'action=expandtemplates&generatexml' );
}
- $wgParser->startExternalParse( $title_obj, $options, OT_PREPROCESS );
+ $wgParser->startExternalParse( $title_obj, $options, Parser::OT_PREPROCESS );
$dom = $wgParser->preprocessToDom( $params['text'] );
if ( is_callable( array( $dom, 'saveXML' ) ) ) {
$xml = $dom->saveXML();
@@ -87,38 +96,45 @@ class ApiExpandTemplates extends ApiBase {
$retval['parsetree'] = $xml;
} else {
// the old way
- $xml_result = array();
- ApiResult::setContent( $xml_result, $xml );
- $result->addValue( null, 'parsetree', $xml_result );
+ $result->addValue( null, 'parsetree', $xml );
+ $result->addValue( null, ApiResult::META_BC_SUBELEMENTS, array( 'parsetree' ) );
}
}
// if they didn't want any output except (probably) the parse tree,
// then don't bother actually fully expanding it
if ( $prop || $params['prop'] === null ) {
- $wgParser->startExternalParse( $title_obj, $options, OT_PREPROCESS );
+ $wgParser->startExternalParse( $title_obj, $options, Parser::OT_PREPROCESS );
$frame = $wgParser->getPreprocessor()->newFrame();
- $wikitext = $wgParser->preprocess( $params['text'], $title_obj, $options, null, $frame );
+ $wikitext = $wgParser->preprocess( $params['text'], $title_obj, $options, $revid, $frame );
if ( $params['prop'] === null ) {
// the old way
- ApiResult::setContent( $retval, $wikitext );
+ ApiResult::setContentValue( $retval, 'wikitext', $wikitext );
} else {
if ( isset( $prop['categories'] ) ) {
$categories = $wgParser->getOutput()->getCategories();
- if ( !empty( $categories ) ) {
+ if ( $categories ) {
$categories_result = array();
foreach ( $categories as $category => $sortkey ) {
$entry = array();
$entry['sortkey'] = $sortkey;
- ApiResult::setContent( $entry, $category );
+ ApiResult::setContentValue( $entry, 'category', $category );
$categories_result[] = $entry;
}
- $result->setIndexedTagName( $categories_result, 'category' );
+ ApiResult::setIndexedTagName( $categories_result, 'category' );
$retval['categories'] = $categories_result;
}
}
- if ( isset( $prop['volatile'] ) && $frame->isVolatile() ) {
- $retval['volatile'] = '';
+ if ( isset( $prop['properties'] ) ) {
+ $properties = $wgParser->getOutput()->getProperties();
+ if ( $properties ) {
+ ApiResult::setArrayType( $properties, 'BCkvp', 'name' );
+ ApiResult::setIndexedTagName( $properties, 'property' );
+ $retval['properties'] = $properties;
+ }
+ }
+ if ( isset( $prop['volatile'] ) ) {
+ $retval['volatile'] = $frame->isVolatile();
}
if ( isset( $prop['ttl'] ) && $frame->getTTL() !== null ) {
$retval['ttl'] = $frame->getTTL();
@@ -128,7 +144,7 @@ class ApiExpandTemplates extends ApiBase {
}
}
}
- $result->setSubelements( $retval, array( 'wikitext', 'parsetree' ) );
+ ApiResult::setSubelementsList( $retval, array( 'wikitext', 'parsetree' ) );
$result->addValue( null, $this->getModuleName(), $retval );
}
@@ -141,10 +157,14 @@ class ApiExpandTemplates extends ApiBase {
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => true,
),
+ 'revid' => array(
+ ApiBase::PARAM_TYPE => 'integer',
+ ),
'prop' => array(
ApiBase::PARAM_TYPE => array(
'wikitext',
'categories',
+ 'properties',
'volatile',
'ttl',
'parsetree',
@@ -159,35 +179,10 @@ class ApiExpandTemplates extends ApiBase {
);
}
- public function getParamDescription() {
- return array(
- 'text' => 'Wikitext to convert',
- 'title' => 'Title of page',
- 'prop' => array(
- 'Which pieces of information to get',
- ' wikitext - The expanded wikitext',
- ' categories - Any categories present in the input that are not represented in ' .
- 'the wikitext output',
- ' volatile - Whether the output is volatile and should not be reused ' .
- 'elsewhere within the page',
- ' ttl - The maximum time after which caches of the result should be ' .
- 'invalidated',
- ' parsetree - The XML parse tree of the input',
- 'Note that if no values are selected, the result will contain the wikitext,',
- 'but the output will be in a deprecated format.',
- ),
- 'includecomments' => 'Whether to include HTML comments in the output',
- 'generatexml' => 'Generate XML parse tree (replaced by prop=parsetree)',
- );
- }
-
- public function getDescription() {
- return 'Expands all templates in wikitext.';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=expandtemplates&text={{Project:Sandbox}}'
+ 'action=expandtemplates&text={{Project:Sandbox}}'
+ => 'apihelp-expandtemplates-example-simple',
);
}
diff --git a/includes/api/ApiFeedContributions.php b/includes/api/ApiFeedContributions.php
index 374203eb..edda6723 100644
--- a/includes/api/ApiFeedContributions.php
+++ b/includes/api/ApiFeedContributions.php
@@ -95,7 +95,10 @@ class ApiFeedContributions extends ApiBase {
if ( ++$count > $limit ) {
break;
}
- $feedItems[] = $this->feedItem( $row );
+ $item = $this->feedItem( $row );
+ if ( $item !== null ) {
+ $feedItems[] = $item;
+ }
}
}
@@ -103,6 +106,23 @@ class ApiFeedContributions extends ApiBase {
}
protected function feedItem( $row ) {
+ // This hook is the api contributions equivalent to the
+ // ContributionsLineEnding hook. Hook implementers may cancel
+ // the hook to signal the user is not allowed to read this item.
+ $feedItem = null;
+ $hookResult = Hooks::run(
+ 'ApiFeedContributions::feedItem',
+ array( $row, $this->getContext(), &$feedItem )
+ );
+ // Hook returned a valid feed item
+ if ( $feedItem instanceof FeedItem ) {
+ return $feedItem;
+ // Hook was canceled and did not return a valid feed item
+ } elseif ( !$hookResult ) {
+ return null;
+ }
+
+ // Hook completed and did not return a valid feed item
$title = Title::makeTitle( intval( $row->page_namespace ), $row->page_title );
if ( $title && $title->userCan( 'read', $this->getUser() ) ) {
$date = $row->rev_timestamp;
@@ -161,7 +181,7 @@ class ApiFeedContributions extends ApiBase {
public function getAllowedParams() {
$feedFormatNames = array_keys( $this->getConfig()->get( 'FeedClasses' ) );
- return array(
+ $ret = array(
'feedformat' => array(
ApiBase::PARAM_DFLT => 'rss',
ApiBase::PARAM_TYPE => $feedFormatNames
@@ -187,32 +207,22 @@ class ApiFeedContributions extends ApiBase {
'deletedonly' => false,
'toponly' => false,
'newonly' => false,
- 'showsizediff' => false,
+ 'showsizediff' => array(
+ ApiBase::PARAM_DFLT => false,
+ ),
);
- }
- public function getParamDescription() {
- return array(
- 'feedformat' => 'The format of the feed',
- 'user' => 'What users to get the contributions for',
- 'namespace' => 'What namespace to filter the contributions by',
- 'year' => 'From year (and earlier)',
- 'month' => 'From month (and earlier)',
- 'tagfilter' => 'Filter contributions that have these tags',
- 'deletedonly' => 'Show only deleted contributions',
- 'toponly' => 'Only show edits that are latest revisions',
- 'newonly' => 'Only show edits that are page creations',
- 'showsizediff' => 'Show the size difference between revisions. Disabled in Miser Mode',
- );
- }
+ if ( $this->getConfig()->get( 'MiserMode' ) ) {
+ $ret['showsizediff'][ApiBase::PARAM_HELP_MSG] = 'api-help-param-disabled-in-miser-mode';
+ }
- public function getDescription() {
- return 'Returns a user contributions feed.';
+ return $ret;
}
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=feedcontributions&user=Reedy',
+ 'action=feedcontributions&user=Example'
+ => 'apihelp-feedcontributions-example-simple',
);
}
}
diff --git a/includes/api/ApiFeedRecentChanges.php b/includes/api/ApiFeedRecentChanges.php
index 7239a296..d452bbd6 100644
--- a/includes/api/ApiFeedRecentChanges.php
+++ b/includes/api/ApiFeedRecentChanges.php
@@ -171,37 +171,12 @@ class ApiFeedRecentChanges extends ApiBase {
return $ret;
}
- public function getParamDescription() {
+ protected function getExamplesMessages() {
return array(
- 'feedformat' => 'The format of the feed',
- 'namespace' => 'Namespace to limit the results to',
- 'invert' => 'All namespaces but the selected one',
- 'associated' => 'Include associated (talk or main) namespace',
- 'days' => 'Days to limit the results to',
- 'limit' => 'Maximum number of results to return',
- 'from' => 'Show changes since then',
- 'hideminor' => 'Hide minor changes',
- 'hidebots' => 'Hide changes made by bots',
- 'hideanons' => 'Hide changes made by anonymous users',
- 'hideliu' => 'Hide changes made by registered users',
- 'hidepatrolled' => 'Hide patrolled changes',
- 'hidemyself' => 'Hide changes made by yourself',
- 'tagfilter' => 'Filter by tag',
- 'target' => 'Show only changes on pages linked from this page',
- 'showlinkedto' => 'Show changes on pages linked to the selected page instead',
- 'categories' => 'Show only changes on pages in all of these categories',
- 'categories_any' => 'Show only changes on pages in any of the categories instead',
- );
- }
-
- public function getDescription() {
- return 'Returns a recent changes feed';
- }
-
- public function getExamples() {
- return array(
- 'api.php?action=feedrecentchanges',
- 'api.php?action=feedrecentchanges&days=30'
+ 'action=feedrecentchanges'
+ => 'apihelp-feedrecentchanges-example-simple',
+ 'action=feedrecentchanges&days=30'
+ => 'apihelp-feedrecentchanges-example-30days',
);
}
}
diff --git a/includes/api/ApiFeedWatchlist.php b/includes/api/ApiFeedWatchlist.php
index 6aef8fc2..d1beef8a 100644
--- a/includes/api/ApiFeedWatchlist.php
+++ b/includes/api/ApiFeedWatchlist.php
@@ -112,12 +112,16 @@ class ApiFeedWatchlist extends ApiBase {
$module = new ApiMain( $fauxReq );
$module->execute();
- // Get data array
- $data = $module->getResultData();
-
+ $data = $module->getResult()->getResultData( array( 'query', 'watchlist' ) );
$feedItems = array();
- foreach ( (array)$data['query']['watchlist'] as $info ) {
- $feedItems[] = $this->createFeedItem( $info );
+ foreach ( (array)$data as $key => $info ) {
+ if ( ApiResult::isMetadataKey( $key ) ) {
+ continue;
+ }
+ $feedItem = $this->createFeedItem( $info );
+ if ( $feedItem ) {
+ $feedItems[] = $feedItem;
+ }
}
$msg = wfMessage( 'watchlist' )->inContentLanguage()->text();
@@ -166,10 +170,22 @@ class ApiFeedWatchlist extends ApiBase {
private function createFeedItem( $info ) {
$titleStr = $info['title'];
$title = Title::newFromText( $titleStr );
+ $curidParam = array();
+ if ( !$title || $title->isExternal() ) {
+ // Probably a formerly-valid title that's now conflicting with an
+ // interwiki prefix or the like.
+ if ( isset( $info['pageid'] ) ) {
+ $title = Title::newFromId( $info['pageid'] );
+ $curidParam = array( 'curid' => $info['pageid'] );
+ }
+ if ( !$title || $title->isExternal() ) {
+ return null;
+ }
+ }
if ( isset( $info['revid'] ) ) {
$titleUrl = $title->getFullURL( array( 'diff' => $info['revid'] ) );
} else {
- $titleUrl = $title->getFullURL();
+ $titleUrl = $title->getFullURL( $curidParam );
}
$comment = isset( $info['comment'] ) ? $info['comment'] : null;
@@ -219,50 +235,42 @@ class ApiFeedWatchlist extends ApiBase {
),
'linktosections' => false,
);
+
+ $copyParams = array(
+ 'allrev' => 'allrev',
+ 'owner' => 'wlowner',
+ 'token' => 'wltoken',
+ 'show' => 'wlshow',
+ 'type' => 'wltype',
+ 'excludeuser' => 'wlexcludeuser',
+ );
if ( $flags ) {
$wlparams = $this->getWatchlistModule()->getAllowedParams( $flags );
- $ret['allrev'] = $wlparams['allrev'];
- $ret['wlowner'] = $wlparams['owner'];
- $ret['wltoken'] = $wlparams['token'];
- $ret['wlshow'] = $wlparams['show'];
- $ret['wltype'] = $wlparams['type'];
- $ret['wlexcludeuser'] = $wlparams['excludeuser'];
+ foreach ( $copyParams as $from => $to ) {
+ $p = $wlparams[$from];
+ if ( !is_array( $p ) ) {
+ $p = array( ApiBase::PARAM_DFLT => $p );
+ }
+ if ( !isset( $p[ApiBase::PARAM_HELP_MSG] ) ) {
+ $p[ApiBase::PARAM_HELP_MSG] = "apihelp-query+watchlist-param-$from";
+ }
+ $ret[$to] = $p;
+ }
} else {
- $ret['allrev'] = null;
- $ret['wlowner'] = null;
- $ret['wltoken'] = null;
- $ret['wlshow'] = null;
- $ret['wltype'] = null;
- $ret['wlexcludeuser'] = null;
+ foreach ( $copyParams as $from => $to ) {
+ $ret[$to] = null;
+ }
}
return $ret;
}
- public function getParamDescription() {
- $wldescr = $this->getWatchlistModule()->getParamDescription();
-
- return array(
- 'feedformat' => 'The format of the feed',
- 'hours' => 'List pages modified within this many hours from now',
- 'linktosections' => 'Link directly to changed sections if possible',
- 'allrev' => $wldescr['allrev'],
- 'wlowner' => $wldescr['owner'],
- 'wltoken' => $wldescr['token'],
- 'wlshow' => $wldescr['show'],
- 'wltype' => $wldescr['type'],
- 'wlexcludeuser' => $wldescr['excludeuser'],
- );
- }
-
- public function getDescription() {
- return 'Returns a watchlist feed.';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=feedwatchlist',
- 'api.php?action=feedwatchlist&allrev=&hours=6'
+ 'action=feedwatchlist'
+ => 'apihelp-feedwatchlist-example-default',
+ 'action=feedwatchlist&allrev=&hours=6'
+ => 'apihelp-feedwatchlist-example-all6hrs',
);
}
diff --git a/includes/api/ApiFileRevert.php b/includes/api/ApiFileRevert.php
index f518e172..5517ee08 100644
--- a/includes/api/ApiFileRevert.php
+++ b/includes/api/ApiFileRevert.php
@@ -61,7 +61,7 @@ class ApiFileRevert extends ApiBase {
} else {
$result = array(
'result' => 'Failure',
- 'errors' => $this->getResult()->convertStatusToArray( $status ),
+ 'errors' => $this->getErrorFormatter()->arrayFromStatus( $status ),
);
}
@@ -135,29 +135,15 @@ class ApiFileRevert extends ApiBase {
);
}
- public function getParamDescription() {
- return array(
- 'filename' => 'Target filename without the File: prefix',
- 'comment' => 'Upload comment',
- 'archivename' => 'Archive name of the revision to revert to',
- );
- }
-
- public function getDescription() {
- return array(
- 'Revert a file to an old version.'
- );
- }
-
public function needsToken() {
return 'csrf';
}
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=filerevert&filename=Wiki.png&comment=Revert&' .
+ 'action=filerevert&filename=Wiki.png&comment=Revert&' .
'archivename=20110305152740!Wiki.png&token=123ABC'
- => 'Revert Wiki.png to the version of 20110305152740',
+ => 'apihelp-filerevert-example-revert',
);
}
}
diff --git a/includes/api/ApiFormatBase.php b/includes/api/ApiFormatBase.php
index 9165ce88..d078dc45 100644
--- a/includes/api/ApiFormatBase.php
+++ b/includes/api/ApiFormatBase.php
@@ -30,8 +30,9 @@
* @ingroup API
*/
abstract class ApiFormatBase extends ApiBase {
- private $mIsHtml, $mFormat, $mUnescapeAmps, $mHelp, $mCleared;
- private $mBufferResult = false, $mBuffer, $mDisabled = false;
+ private $mIsHtml, $mFormat, $mUnescapeAmps, $mHelp;
+ private $mBuffer, $mDisabled = false;
+ protected $mForceDefaultParams = false;
/**
* If $format ends with 'fm', pretty-print the output in HTML.
@@ -48,25 +49,19 @@ abstract class ApiFormatBase extends ApiBase {
$this->mFormat = $format;
}
$this->mFormat = strtoupper( $this->mFormat );
- $this->mCleared = false;
}
/**
* Overriding class returns the MIME type that should be sent to the client.
- * This method is not called if getIsHtml() returns true.
+ *
+ * When getIsHtml() returns true, the return value here is used for syntax
+ * highlighting but the client sees text/html.
+ *
* @return string
*/
abstract public function getMimeType();
/**
- * Whether this formatter needs raw data such as _element tags
- * @return bool
- */
- public function getNeedsRawData() {
- return false;
- }
-
- /**
* Get the internal format name
* @return string
*/
@@ -75,19 +70,6 @@ abstract class ApiFormatBase extends ApiBase {
}
/**
- * Specify whether or not sequences like &amp;quot; should be unescaped
- * to &quot; . This should only be set to true for the help message
- * when rendered in the default (xmlfm) format. This is a temporary
- * special-case fix that should be removed once the help has been
- * reworked to use a fully HTML interface.
- *
- * @param bool $b Whether or not ampersands should be escaped.
- */
- public function setUnescapeAmps( $b ) {
- $this->mUnescapeAmps = $b;
- }
-
- /**
* Returns true when the HTML pretty-printer should be used.
* The default implementation assumes that formats ending with 'fm'
* should be formatted in HTML.
@@ -98,30 +80,27 @@ abstract class ApiFormatBase extends ApiBase {
}
/**
- * Whether this formatter can format the help message in a nice way.
- * By default, this returns the same as getIsHtml().
- * When action=help is set explicitly, the help will always be shown
- * @return bool
- */
- public function getWantsHelp() {
- return $this->getIsHtml();
- }
-
- /**
- * Disable the formatter completely. This causes calls to initPrinter(),
- * printText() and closePrinter() to be ignored.
+ * Disable the formatter.
+ *
+ * This causes calls to initPrinter() and closePrinter() to be ignored.
*/
public function disable() {
$this->mDisabled = true;
}
+ /**
+ * Whether the printer is disabled
+ * @return bool
+ */
public function isDisabled() {
return $this->mDisabled;
}
/**
- * Whether this formatter can handle printing API errors. If this returns
- * false, then on API errors the default printer will be instantiated.
+ * Whether this formatter can handle printing API errors.
+ *
+ * If this returns false, then on API errors the default printer will be
+ * instantiated.
* @since 1.23
* @return bool
*/
@@ -130,24 +109,47 @@ abstract class ApiFormatBase extends ApiBase {
}
/**
- * Initialize the printer function and prepare the output headers, etc.
- * This method must be the first outputting method during execution.
- * A human-targeted notice about available formats is printed for the HTML-based output,
- * except for help screens (caused by either an error in the API parameters,
- * the calling of action=help, or requesting the root script api.php).
- * @param bool $isHelpScreen Whether a help screen is going to be shown
+ * Ignore request parameters, force a default.
+ *
+ * Used as a fallback if errors are being thrown.
+ * @since 1.26
*/
- function initPrinter( $isHelpScreen ) {
+ public function forceDefaultParams() {
+ $this->mForceDefaultParams = true;
+ }
+
+ /**
+ * Overridden to honor $this->forceDefaultParams(), if applicable
+ * @since 1.26
+ */
+ protected function getParameterFromSettings( $paramName, $paramSettings, $parseLimit ) {
+ if ( !$this->mForceDefaultParams ) {
+ return parent::getParameterFromSettings( $paramName, $paramSettings, $parseLimit );
+ }
+
+ if ( !is_array( $paramSettings ) ) {
+ return $paramSettings;
+ } elseif ( isset( $paramSettings[self::PARAM_DFLT] ) ) {
+ return $paramSettings[self::PARAM_DFLT];
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Initialize the printer function and prepare the output headers.
+ * @param bool $unused Always false since 1.25
+ */
+ function initPrinter( $unused = false ) {
if ( $this->mDisabled ) {
return;
}
- $isHtml = $this->getIsHtml();
- $mime = $isHtml ? 'text/html' : $this->getMimeType();
- $script = wfScript( 'api' );
+
+ $mime = $this->getIsHtml() ? 'text/html' : $this->getMimeType();
// Some printers (ex. Feed) do their own header settings,
// in which case $mime will be set to null
- if ( is_null( $mime ) ) {
+ if ( $mime === null ) {
return; // skip any initialization
}
@@ -158,91 +160,64 @@ abstract class ApiFormatBase extends ApiBase {
if ( $apiFrameOptions ) {
$this->getMain()->getRequest()->response()->header( "X-Frame-Options: $apiFrameOptions" );
}
-
- if ( $isHtml ) {
-?>
-<!DOCTYPE HTML>
-<html>
-<head>
-<?php
- if ( $this->mUnescapeAmps ) {
-?> <title>MediaWiki API</title>
-<?php
- } else {
-?> <title>MediaWiki API Result</title>
-<?php
- }
-?>
-</head>
-<body>
-<?php
- if ( !$isHelpScreen ) {
-// @codingStandardsIgnoreStart Exclude long line from CodeSniffer checks
-?>
-<br />
-<small>
-You are looking at the HTML representation of the <?php echo $this->mFormat; ?> format.<br />
-HTML is good for debugging, but is unsuitable for application use.<br />
-Specify the format parameter to change the output format.<br />
-To see the non HTML representation of the <?php echo $this->mFormat; ?> format, set format=<?php echo strtolower( $this->mFormat ); ?>.<br />
-See the <a href='https://www.mediawiki.org/wiki/API'>complete documentation</a>, or
-<a href='<?php echo $script; ?>'>API help</a> for more information.
-</small>
-<pre style='white-space: pre-wrap;'>
-<?php
-// @codingStandardsIgnoreEnd
- // don't wrap the contents of the <pre> for help screens
- // because these are actually formatted to rely on
- // the monospaced font for layout purposes
- } else {
-?>
-<pre>
-<?php
- }
- }
}
/**
- * Finish printing. Closes HTML tags.
+ * Finish printing and output buffered data.
*/
public function closePrinter() {
if ( $this->mDisabled ) {
return;
}
- if ( $this->getIsHtml() ) {
-?>
-</pre>
-</body>
-</html>
-<?php
+ $mime = $this->getMimeType();
+ if ( $this->getIsHtml() && $mime !== null ) {
+ $format = $this->getFormat();
+ $result = $this->getBuffer();
+
+ $context = new DerivativeContext( $this->getMain() );
+ $context->setSkin( SkinFactory::getDefaultInstance()->makeSkin( 'apioutput' ) );
+ $context->setTitle( SpecialPage::getTitleFor( 'ApiHelp' ) );
+ $out = new OutputPage( $context );
+ $context->setOutput( $out );
+
+ $out->addModules( 'mediawiki.apipretty' );
+ $out->setPageTitle( $context->msg( 'api-format-title' ) );
+
+ $header = $context->msg( 'api-format-prettyprint-header' )
+ ->params( $format, strtolower( $format ) )
+ ->parseAsBlock();
+ $out->addHTML(
+ Html::rawElement( 'div', array( 'class' => 'api-pretty-header' ),
+ ApiHelp::fixHelpLinks( $header )
+ )
+ );
+
+ if ( Hooks::run( 'ApiFormatHighlight', array( $context, $result, $mime, $format ) ) ) {
+ $out->addHTML(
+ Html::element( 'pre', array( 'class' => 'api-pretty-content' ), $result )
+ );
+ }
+
+ // API handles its own clickjacking protection.
+ // Note, that $wgBreakFrames will still override $wgApiFrameOptions for format mode.
+ $out->allowClickJacking();
+ $out->output();
+ } else {
+ // For non-HTML output, clear all errors that might have been
+ // displayed if display_errors=On
+ ob_clean();
+
+ echo $this->getBuffer();
}
}
/**
- * The main format printing function. Call it to output the result
- * string to the user. This function will automatically output HTML
- * when format name ends in 'fm'.
+ * Append text to the output buffer.
* @param string $text
*/
public function printText( $text ) {
- if ( $this->mDisabled ) {
- return;
- }
- if ( $this->mBufferResult ) {
- $this->mBuffer = $text;
- } elseif ( $this->getIsHtml() ) {
- echo $this->formatHTML( $text );
- } else {
- // For non-HTML output, clear all errors that might have been
- // displayed if display_errors=On
- // Do this only once, of course
- if ( !$this->mCleared ) {
- ob_clean();
- $this->mCleared = true;
- }
- echo $text;
- }
+ $this->mBuffer .= $text;
}
/**
@@ -253,34 +228,89 @@ See the <a href='https://www.mediawiki.org/wiki/API'>complete documentation</a>,
return $this->mBuffer;
}
+ protected function getExamplesMessages() {
+ return array(
+ 'action=query&meta=siteinfo&siprop=namespaces&format=' . $this->getModuleName()
+ => array( 'apihelp-format-example-generic', $this->getFormat() )
+ );
+ }
+
+ public function getHelpUrls() {
+ return 'https://www.mediawiki.org/wiki/API:Data_formats';
+ }
+
/**
- * Set the flag to buffer the result instead of printing it.
- * @param bool $value
+ * To avoid code duplication with the deprecation of dbg, dump, txt, wddx,
+ * and yaml, this method is added to do the necessary work. It should be
+ * removed when those deprecated formats are removed.
*/
- public function setBufferResult( $value ) {
- $this->mBufferResult = $value;
+ protected function markDeprecated() {
+ $fm = $this->getIsHtml() ? 'fm' : '';
+ $name = $this->getModuleName();
+ $this->logFeatureUsage( "format=$name" );
+ $this->setWarning( "format=$name has been deprecated. Please use format=json$fm instead." );
+ }
+
+ /************************************************************************//**
+ * @name Deprecated
+ * @{
+ */
+
+ /**
+ * Specify whether or not sequences like &amp;quot; should be unescaped
+ * to &quot; . This should only be set to true for the help message
+ * when rendered in the default (xmlfm) format. This is a temporary
+ * special-case fix that should be removed once the help has been
+ * reworked to use a fully HTML interface.
+ *
+ * @deprecated since 1.25
+ * @param bool $b Whether or not ampersands should be escaped.
+ */
+ public function setUnescapeAmps( $b ) {
+ wfDeprecated( __METHOD__, '1.25' );
+ $this->mUnescapeAmps = $b;
+ }
+
+ /**
+ * Whether this formatter can format the help message in a nice way.
+ * By default, this returns the same as getIsHtml().
+ * When action=help is set explicitly, the help will always be shown
+ * @deprecated since 1.25
+ * @return bool
+ */
+ public function getWantsHelp() {
+ wfDeprecated( __METHOD__, '1.25' );
+ return $this->getIsHtml();
}
/**
* Sets whether the pretty-printer should format *bold*
+ * @deprecated since 1.25
* @param bool $help
*/
public function setHelp( $help = true ) {
+ wfDeprecated( __METHOD__, '1.25' );
$this->mHelp = $help;
}
/**
* Pretty-print various elements in HTML format, such as xml tags and
* URLs. This method also escapes characters like <
+ * @deprecated since 1.25
* @param string $text
* @return string
*/
protected function formatHTML( $text ) {
+ wfDeprecated( __METHOD__, '1.25' );
+
// Escape everything first for full coverage
$text = htmlspecialchars( $text );
- // encode all comments or tags as safe blue strings
- $text = str_replace( '&lt;', '<span style="color:blue;">&lt;', $text );
- $text = str_replace( '&gt;', '&gt;</span>', $text );
+
+ if ( $this->mFormat === 'XML' || $this->mFormat === 'WDDX' ) {
+ // encode all comments or tags as safe blue strings
+ $text = str_replace( '&lt;', '<span style="color:blue;">&lt;', $text );
+ $text = str_replace( '&gt;', '&gt;</span>', $text );
+ }
// identify requests to api.php
$text = preg_replace( '#^(\s*)(api\.php\?[^ <\n\t]+)$#m', '\1<a href="\2">\2</a>', $text );
@@ -325,30 +355,42 @@ See the <a href='https://www.mediawiki.org/wiki/API'>complete documentation</a>,
return $text;
}
- public function getExamples() {
- return array(
- 'api.php?action=query&meta=siteinfo&siprop=namespaces&format=' . $this->getModuleName()
- => "Format the query result in the {$this->getModuleName()} format",
- );
- }
-
- public function getHelpUrls() {
- return 'https://www.mediawiki.org/wiki/API:Data_formats';
- }
-
+ /**
+ * @see ApiBase::getDescription
+ * @deprecated since 1.25
+ */
public function getDescription() {
return $this->getIsHtml() ? ' (pretty-print in HTML)' : '';
}
/**
- * To avoid code duplication with the deprecation of dbg, dump, txt, wddx,
- * and yaml, this method is added to do the necessary work. It should be
- * removed when those deprecated formats are removed.
+ * Set the flag to buffer the result instead of printing it.
+ * @deprecated since 1.25, output is always buffered
+ * @param bool $value
*/
- protected function markDeprecated() {
- $fm = $this->getIsHtml() ? 'fm' : '';
- $name = $this->getModuleName();
- $this->logFeatureUsage( "format=$name" );
- $this->setWarning( "format=$name has been deprecated. Please use format=json$fm instead." );
+ public function setBufferResult( $value ) {
}
+
+ /**
+ * Formerly indicated whether the formatter needed metadata from ApiResult.
+ *
+ * ApiResult previously (indirectly) used this to decide whether to add
+ * metadata or to ignore calls to metadata-setting methods, which
+ * unfortunately made several methods that should have been static have to
+ * be dynamic instead. Now ApiResult always stores metadata and formatters
+ * are required to ignore it or filter it out.
+ *
+ * @deprecated since 1.25
+ * @return bool
+ */
+ public function getNeedsRawData() {
+ return false;
+ }
+
+ /**@}*/
}
+
+/**
+ * For really cool vim folding this needs to be at the end:
+ * vim: foldmarker=@{,@} foldmethod=marker
+ */
diff --git a/includes/api/ApiFormatDbg.php b/includes/api/ApiFormatDbg.php
index 5ec518b3..7d359ad4 100644
--- a/includes/api/ApiFormatDbg.php
+++ b/includes/api/ApiFormatDbg.php
@@ -40,10 +40,15 @@ class ApiFormatDbg extends ApiFormatBase {
public function execute() {
$this->markDeprecated();
- $this->printText( var_export( $this->getResultData(), true ) );
+ $data = $this->getResult()->getResultData( null, array(
+ 'BC' => array(),
+ 'Types' => array(),
+ 'Strip' => 'all',
+ ) );
+ $this->printText( var_export( $data, true ) );
}
- public function getDescription() {
- return 'DEPRECATED! Output data in PHP\'s var_export() format' . parent::getDescription();
+ public function isDeprecated() {
+ return true;
}
}
diff --git a/includes/api/ApiFormatDump.php b/includes/api/ApiFormatDump.php
index d4c7cab4..f34e1ae4 100644
--- a/includes/api/ApiFormatDump.php
+++ b/includes/api/ApiFormatDump.php
@@ -40,14 +40,19 @@ class ApiFormatDump extends ApiFormatBase {
public function execute() {
$this->markDeprecated();
+ $data = $this->getResult()->getResultData( null, array(
+ 'BC' => array(),
+ 'Types' => array(),
+ 'Strip' => 'all',
+ ) );
ob_start();
- var_dump( $this->getResultData() );
+ var_dump( $data );
$result = ob_get_contents();
ob_end_clean();
$this->printText( $result );
}
- public function getDescription() {
- return 'DEPRECATED! Output data in PHP\'s var_dump() format' . parent::getDescription();
+ public function isDeprecated() {
+ return true;
}
}
diff --git a/includes/api/ApiFormatFeedWrapper.php b/includes/api/ApiFormatFeedWrapper.php
index 92600067..00747eef 100644
--- a/includes/api/ApiFormatFeedWrapper.php
+++ b/includes/api/ApiFormatFeedWrapper.php
@@ -46,8 +46,8 @@ class ApiFormatFeedWrapper extends ApiFormatBase {
// Disable size checking for this because we can't continue
// cleanly; size checking would cause more problems than it'd
// solve
- $result->addValue( null, '_feed', $feed, ApiResult::NO_SIZE_CHECK );
- $result->addValue( null, '_feeditems', $feedItems, ApiResult::NO_SIZE_CHECK );
+ $result->addValue( null, '_feed', $feed, ApiResult::NO_VALIDATE );
+ $result->addValue( null, '_feeditems', $feedItems, ApiResult::NO_VALIDATE );
}
/**
@@ -82,17 +82,41 @@ class ApiFormatFeedWrapper extends ApiFormatBase {
* $result['_feed'] - an instance of one of the $wgFeedClasses classes
* $result['_feeditems'] - an array of FeedItem instances
*/
+ public function initPrinter( $unused = false ) {
+ parent::initPrinter( $unused );
+
+ if ( $this->isDisabled() ) {
+ return;
+ }
+
+ $data = $this->getResult()->getResultData();
+ if ( isset( $data['_feed'] ) && isset( $data['_feeditems'] ) ) {
+ $data['_feed']->httpHeaders();
+ } else {
+ // Error has occurred, print something useful
+ ApiBase::dieDebug( __METHOD__, 'Invalid feed class/item' );
+ }
+ }
+
+ /**
+ * This class expects the result data to be in a custom format set by self::setResult()
+ * $result['_feed'] - an instance of one of the $wgFeedClasses classes
+ * $result['_feeditems'] - an array of FeedItem instances
+ */
public function execute() {
- $data = $this->getResultData();
+ $data = $this->getResult()->getResultData();
if ( isset( $data['_feed'] ) && isset( $data['_feeditems'] ) ) {
$feed = $data['_feed'];
$items = $data['_feeditems'];
+ // execute() needs to pass strings to $this->printText, not produce output itself.
+ ob_start();
$feed->outHeader();
foreach ( $items as & $item ) {
$feed->outItem( $item );
}
$feed->outFooter();
+ $this->printText( ob_get_clean() );
} else {
// Error has occurred, print something useful
ApiBase::dieDebug( __METHOD__, 'Invalid feed class/item' );
diff --git a/includes/api/ApiFormatJson.php b/includes/api/ApiFormatJson.php
index d9f9d46a..43877b78 100644
--- a/includes/api/ApiFormatJson.php
+++ b/includes/api/ApiFormatJson.php
@@ -30,39 +30,72 @@
*/
class ApiFormatJson extends ApiFormatBase {
- private $mIsRaw;
+ private $isRaw;
public function __construct( ApiMain $main, $format ) {
parent::__construct( $main, $format );
- $this->mIsRaw = ( $format === 'rawfm' );
+ $this->isRaw = ( $format === 'rawfm' );
}
public function getMimeType() {
$params = $this->extractRequestParams();
// callback:
- if ( $params['callback'] ) {
+ if ( isset( $params['callback'] ) ) {
return 'text/javascript';
}
return 'application/json';
}
+ /**
+ * @deprecated since 1.25
+ */
public function getNeedsRawData() {
- return $this->mIsRaw;
+ return $this->isRaw;
}
+ /**
+ * @deprecated since 1.25
+ */
public function getWantsHelp() {
+ wfDeprecated( __METHOD__, '1.25' );
// Help is always ugly in JSON
return false;
}
public function execute() {
$params = $this->extractRequestParams();
- $json = FormatJson::encode(
- $this->getResultData(),
- $this->getIsHtml(),
- $params['utf8'] ? FormatJson::ALL_OK : FormatJson::XMLMETA_OK
- );
+
+ $opt = 0;
+ if ( $this->isRaw ) {
+ $opt |= FormatJson::ALL_OK;
+ $transform = array();
+ } else {
+ switch ( $params['formatversion'] ) {
+ case 1:
+ $opt |= $params['utf8'] ? FormatJson::ALL_OK : FormatJson::XMLMETA_OK;
+ $transform = array(
+ 'BC' => array(),
+ 'Types' => array( 'AssocAsObject' => true ),
+ 'Strip' => 'all',
+ );
+ break;
+
+ case 2:
+ case 'latest':
+ $opt |= $params['ascii'] ? FormatJson::XMLMETA_OK : FormatJson::ALL_OK;
+ $transform = array(
+ 'Types' => array( 'AssocAsObject' => true ),
+ 'Strip' => 'all',
+ );
+ break;
+
+ default:
+ $this->dieUsage( __METHOD__ . ': Unknown value for \'formatversion\'', 'unknownformatversion' );
+ }
+ }
+ $data = $this->getResult()->getResultData( null, $transform );
+ $json = FormatJson::encode( $data, $this->getIsHtml(), $opt );
// Bug 66776: wfMangleFlashPolicy() is needed to avoid a nasty bug in
// Flash, but what it does isn't friendly for the API, so we need to
@@ -73,9 +106,8 @@ class ApiFormatJson extends ApiFormatBase {
);
}
- $callback = $params['callback'];
- if ( $callback !== null ) {
- $callback = preg_replace( "/[^][.\\'\\\"_A-Za-z0-9]/", '', $callback );
+ if ( isset( $params['callback'] ) ) {
+ $callback = preg_replace( "/[^][.\\'\\\"_A-Za-z0-9]/", '', $params['callback'] );
# Prepend a comment to try to avoid attacks against content
# sniffers, such as bug 68187.
$this->printText( "/**/$callback($json)" );
@@ -85,26 +117,28 @@ class ApiFormatJson extends ApiFormatBase {
}
public function getAllowedParams() {
- return array(
- 'callback' => null,
- 'utf8' => false,
- );
- }
-
- public function getParamDescription() {
- return array(
- 'callback' => 'If specified, wraps the output into a given function ' .
- 'call. For safety, all user-specific data will be restricted.',
- 'utf8' => 'If specified, encodes most (but not all) non-ASCII ' .
- 'characters as UTF-8 instead of replacing them with hexadecimal escape sequences.',
- );
- }
-
- public function getDescription() {
- if ( $this->mIsRaw ) {
- return 'Output data with the debugging elements in JSON format' . parent::getDescription();
+ if ( $this->isRaw ) {
+ return array();
}
- return 'Output data in JSON format' . parent::getDescription();
+ $ret = array(
+ 'callback' => array(
+ ApiBase::PARAM_HELP_MSG => 'apihelp-json-param-callback',
+ ),
+ 'utf8' => array(
+ ApiBase::PARAM_DFLT => false,
+ ApiBase::PARAM_HELP_MSG => 'apihelp-json-param-utf8',
+ ),
+ 'ascii' => array(
+ ApiBase::PARAM_DFLT => false,
+ ApiBase::PARAM_HELP_MSG => 'apihelp-json-param-ascii',
+ ),
+ 'formatversion' => array(
+ ApiBase::PARAM_TYPE => array( 1, 2, 'latest' ),
+ ApiBase::PARAM_DFLT => 1,
+ ApiBase::PARAM_HELP_MSG => 'apihelp-json-param-formatversion',
+ ),
+ );
+ return $ret;
}
}
diff --git a/includes/api/ApiFormatNone.php b/includes/api/ApiFormatNone.php
index 78023af3..dc623ac1 100644
--- a/includes/api/ApiFormatNone.php
+++ b/includes/api/ApiFormatNone.php
@@ -36,8 +36,4 @@ class ApiFormatNone extends ApiFormatBase {
public function execute() {
}
-
- public function getDescription() {
- return 'Output nothing' . parent::getDescription();
- }
}
diff --git a/includes/api/ApiFormatPhp.php b/includes/api/ApiFormatPhp.php
index 73ce80ef..d88dd40b 100644
--- a/includes/api/ApiFormatPhp.php
+++ b/includes/api/ApiFormatPhp.php
@@ -35,7 +35,29 @@ class ApiFormatPhp extends ApiFormatBase {
}
public function execute() {
- $text = serialize( $this->getResultData() );
+ $params = $this->extractRequestParams();
+
+ switch ( $params['formatversion'] ) {
+ case 1:
+ $transforms = array(
+ 'BC' => array(),
+ 'Types' => array(),
+ 'Strip' => 'all',
+ );
+ break;
+
+ case 2:
+ case 'latest':
+ $transforms = array(
+ 'Types' => array(),
+ 'Strip' => 'all',
+ );
+ break;
+
+ default:
+ $this->dieUsage( __METHOD__ . ': Unknown value for \'formatversion\'', 'unknownformatversion' );
+ }
+ $text = serialize( $this->getResult()->getResultData( null, $transforms ) );
// Bug 66776: wfMangleFlashPolicy() is needed to avoid a nasty bug in
// Flash, but what it does isn't friendly for the API. There's nothing
@@ -54,7 +76,14 @@ class ApiFormatPhp extends ApiFormatBase {
$this->printText( $text );
}
- public function getDescription() {
- return 'Output data in serialized PHP format' . parent::getDescription();
+ public function getAllowedParams() {
+ $ret = array(
+ 'formatversion' => array(
+ ApiBase::PARAM_TYPE => array( 1, 2, 'latest' ),
+ ApiBase::PARAM_DFLT => 1,
+ ApiBase::PARAM_HELP_MSG => 'apihelp-php-param-formatversion',
+ ),
+ );
+ return $ret;
}
}
diff --git a/includes/api/ApiFormatRaw.php b/includes/api/ApiFormatRaw.php
index 3f5c8b73..7bb2453d 100644
--- a/includes/api/ApiFormatRaw.php
+++ b/includes/api/ApiFormatRaw.php
@@ -30,20 +30,22 @@
*/
class ApiFormatRaw extends ApiFormatBase {
+ private $errorFallback;
+
/**
* @param ApiMain $main
* @param ApiFormatBase $errorFallback Object to fall back on for errors
*/
public function __construct( ApiMain $main, ApiFormatBase $errorFallback ) {
parent::__construct( $main, 'raw' );
- $this->mErrorFallback = $errorFallback;
+ $this->errorFallback = $errorFallback;
}
public function getMimeType() {
- $data = $this->getResultData();
+ $data = $this->getResult()->getResultData();
if ( isset( $data['error'] ) ) {
- return $this->mErrorFallback->getMimeType();
+ return $this->errorFallback->getMimeType();
}
if ( !isset( $data['mime'] ) ) {
@@ -53,11 +55,28 @@ class ApiFormatRaw extends ApiFormatBase {
return $data['mime'];
}
- public function execute() {
- $data = $this->getResultData();
+ public function initPrinter( $unused = false ) {
+ $data = $this->getResult()->getResultData();
+ if ( isset( $data['error'] ) ) {
+ $this->errorFallback->initPrinter( $unused );
+ } else {
+ parent::initPrinter( $unused );
+ }
+ }
+
+ public function closePrinter() {
+ $data = $this->getResult()->getResultData();
if ( isset( $data['error'] ) ) {
- $this->mErrorFallback->execute();
+ $this->errorFallback->closePrinter();
+ } else {
+ parent::closePrinter();
+ }
+ }
+ public function execute() {
+ $data = $this->getResult()->getResultData();
+ if ( isset( $data['error'] ) ) {
+ $this->errorFallback->execute();
return;
}
diff --git a/includes/api/ApiFormatTxt.php b/includes/api/ApiFormatTxt.php
index c451ed77..e739d5a4 100644
--- a/includes/api/ApiFormatTxt.php
+++ b/includes/api/ApiFormatTxt.php
@@ -40,10 +40,15 @@ class ApiFormatTxt extends ApiFormatBase {
public function execute() {
$this->markDeprecated();
- $this->printText( print_r( $this->getResultData(), true ) );
+ $data = $this->getResult()->getResultData( null, array(
+ 'BC' => array(),
+ 'Types' => array(),
+ 'Strip' => 'all',
+ ) );
+ $this->printText( print_r( $data, true ) );
}
- public function getDescription() {
- return 'DEPRECATED! Output data in PHP\'s print_r() format' . parent::getDescription();
+ public function isDeprecated() {
+ return true;
}
}
diff --git a/includes/api/ApiFormatWddx.php b/includes/api/ApiFormatWddx.php
index ec3dc2d9..c18353fe 100644
--- a/includes/api/ApiFormatWddx.php
+++ b/includes/api/ApiFormatWddx.php
@@ -38,18 +38,30 @@ class ApiFormatWddx extends ApiFormatBase {
public function execute() {
$this->markDeprecated();
+ $data = $this->getResult()->getResultData( null, array(
+ 'BC' => array(),
+ 'Types' => array( 'AssocAsObject' => true ),
+ 'Strip' => 'all',
+ ) );
+
if ( !$this->getIsHtml() && !static::useSlowPrinter() ) {
- $this->printText( wddx_serialize_value( $this->getResultData() ) );
+ $txt = wddx_serialize_value( $data );
+ $txt = str_replace(
+ '<struct><var name=\'php_class_name\'><string>stdClass</string></var>',
+ '<struct>',
+ $txt
+ );
+ $this->printText( $txt );
} else {
// Don't do newlines and indentation if we weren't asked
// for pretty output
$nl = ( $this->getIsHtml() ? "\n" : '' );
- $indstr = ' ';
+ $indstr = ( $this->getIsHtml() ? ' ' : '' );
$this->printText( "<?xml version=\"1.0\"?>$nl" );
$this->printText( "<wddxPacket version=\"1.0\">$nl" );
- $this->printText( "$indstr<header/>$nl" );
+ $this->printText( "$indstr<header />$nl" );
$this->printText( "$indstr<data>$nl" );
- $this->slowWddxPrinter( $this->getResultData(), 4 );
+ $this->slowWddxPrinter( $data, 4 );
$this->printText( "$indstr</data>$nl" );
$this->printText( "</wddxPacket>$nl" );
}
@@ -102,44 +114,49 @@ class ApiFormatWddx extends ApiFormatBase {
$indstr = ( $this->getIsHtml() ? str_repeat( ' ', $indent ) : '' );
$indstr2 = ( $this->getIsHtml() ? str_repeat( ' ', $indent + 2 ) : '' );
$nl = ( $this->getIsHtml() ? "\n" : '' );
+
if ( is_array( $elemValue ) ) {
- // Check whether we've got an associative array (<struct>)
- // or a regular array (<array>)
$cnt = count( $elemValue );
- if ( $cnt == 0 || array_keys( $elemValue ) === range( 0, $cnt - 1 ) ) {
- // Regular array
- $this->printText( $indstr . Xml::element( 'array', array(
- 'length' => $cnt ), null ) . $nl );
- foreach ( $elemValue as $subElemValue ) {
- $this->slowWddxPrinter( $subElemValue, $indent + 2 );
- }
- $this->printText( "$indstr</array>$nl" );
- } else {
- // Associative array (<struct>)
- $this->printText( "$indstr<struct>$nl" );
- foreach ( $elemValue as $subElemName => $subElemValue ) {
- $this->printText( $indstr2 . Xml::element( 'var', array(
- 'name' => $subElemName
- ), null ) . $nl );
- $this->slowWddxPrinter( $subElemValue, $indent + 4 );
- $this->printText( "$indstr2</var>$nl" );
- }
- $this->printText( "$indstr</struct>$nl" );
+ if ( $cnt != 0 && array_keys( $elemValue ) !== range( 0, $cnt - 1 ) ) {
+ $elemValue = (object)$elemValue;
+ }
+ }
+
+ if ( is_array( $elemValue ) ) {
+ // Regular array
+ $this->printText( $indstr . Xml::element( 'array', array(
+ 'length' => count( $elemValue ) ), null ) . $nl );
+ foreach ( $elemValue as $subElemValue ) {
+ $this->slowWddxPrinter( $subElemValue, $indent + 2 );
+ }
+ $this->printText( "$indstr</array>$nl" );
+ } elseif ( is_object( $elemValue ) ) {
+ // Associative array (<struct>)
+ $this->printText( "$indstr<struct>$nl" );
+ foreach ( $elemValue as $subElemName => $subElemValue ) {
+ $this->printText( $indstr2 . Xml::element( 'var', array(
+ 'name' => $subElemName
+ ), null ) . $nl );
+ $this->slowWddxPrinter( $subElemValue, $indent + 4 );
+ $this->printText( "$indstr2</var>$nl" );
}
+ $this->printText( "$indstr</struct>$nl" );
} elseif ( is_int( $elemValue ) || is_float( $elemValue ) ) {
$this->printText( $indstr . Xml::element( 'number', null, $elemValue ) . $nl );
} elseif ( is_string( $elemValue ) ) {
- $this->printText( $indstr . Xml::element( 'string', null, $elemValue ) . $nl );
+ $this->printText( $indstr . Xml::element( 'string', null, $elemValue, false ) . $nl );
} elseif ( is_bool( $elemValue ) ) {
$this->printText( $indstr . Xml::element( 'boolean',
array( 'value' => $elemValue ? 'true' : 'false' ) ) . $nl
);
+ } elseif ( $elemValue === null ) {
+ $this->printText( $indstr . Xml::element( 'null', array() ) . $nl );
} else {
ApiBase::dieDebug( __METHOD__, 'Unknown type ' . gettype( $elemValue ) );
}
}
- public function getDescription() {
- return 'DEPRECATED! Output data in WDDX format' . parent::getDescription();
+ public function isDeprecated() {
+ return true;
}
}
diff --git a/includes/api/ApiFormatXml.php b/includes/api/ApiFormatXml.php
index b3d59379..fa0bac34 100644
--- a/includes/api/ApiFormatXml.php
+++ b/includes/api/ApiFormatXml.php
@@ -39,6 +39,9 @@ class ApiFormatXml extends ApiFormatBase {
return 'text/xml';
}
+ /**
+ * @deprecated since 1.25
+ */
public function getNeedsRawData() {
return true;
}
@@ -56,18 +59,32 @@ class ApiFormatXml extends ApiFormatBase {
if ( !is_null( $this->mXslt ) ) {
$this->addXslt();
}
- if ( $this->mIncludeNamespace ) {
+
+ $result = $this->getResult();
+ if ( $this->mIncludeNamespace && $result->getResultData( 'xmlns' ) === null ) {
// If the result data already contains an 'xmlns' namespace added
// for custom XML output types, it will override the one for the
// generic API results.
// This allows API output of other XML types like Atom, RSS, RSD.
- $data = $this->getResultData() + array( 'xmlns' => self::$namespace );
- } else {
- $data = $this->getResultData();
+ $result->addValue( null, 'xmlns', self::$namespace, ApiResult::NO_SIZE_CHECK );
}
+ $data = $result->getResultData( null, array(
+ 'Custom' => function ( &$data, &$metadata ) {
+ if ( isset( $metadata[ApiResult::META_TYPE] ) ) {
+ // We want to use non-BC for BCassoc to force outputting of _idx.
+ switch( $metadata[ApiResult::META_TYPE] ) {
+ case 'BCassoc':
+ $metadata[ApiResult::META_TYPE] = 'assoc';
+ break;
+ }
+ }
+ },
+ 'BC' => array( 'nobool', 'no*', 'nosub' ),
+ 'Types' => array( 'ArmorKVP' => '_name' ),
+ ) );
$this->printText(
- self::recXmlPrint( $this->mRootElemName,
+ static::recXmlPrint( $this->mRootElemName,
$data,
$this->getIsHtml() ? -2 : null
)
@@ -77,143 +94,185 @@ class ApiFormatXml extends ApiFormatBase {
/**
* This method takes an array and converts it to XML.
*
- * There are several noteworthy cases:
- *
- * If array contains a key '_element', then the code assumes that ALL
- * other keys are not important and replaces them with the
- * value['_element'].
- *
- * @par Example:
- * @verbatim
- * name='root', value = array( '_element'=>'page', 'x', 'y', 'z')
- * @endverbatim
- * creates:
- * @verbatim
- * <root> <page>x</page> <page>y</page> <page>z</page> </root>
- * @endverbatim
- *
- * If any of the array's element key is '*', then the code treats all
- * other key->value pairs as attributes, and the value['*'] as the
- * element's content.
- *
- * @par Example:
- * @verbatim
- * name='root', value = array( '*'=>'text', 'lang'=>'en', 'id'=>10)
- * @endverbatim
- * creates:
- * @verbatim
- * <root lang='en' id='10'>text</root>
- * @endverbatim
- *
- * Finally neither key is found, all keys become element names, and values
- * become element content.
- *
- * @note The method is recursive, so the same rules apply to any
- * sub-arrays.
- *
- * @param string $elemName
- * @param mixed $elemValue
- * @param int $indent
- *
+ * @param string|null $name Tag name
+ * @param mixed $value Tag value (attributes/content/subelements)
+ * @param int|null $indent Indentation
+ * @param array $attributes Additional attributes
* @return string
*/
- public static function recXmlPrint( $elemName, $elemValue, $indent ) {
+ public static function recXmlPrint( $name, $value, $indent, $attributes = array() ) {
$retval = '';
- if ( !is_null( $indent ) ) {
- $indent += 2;
+ if ( $indent !== null ) {
+ if ( $name !== null ) {
+ $indent += 2;
+ }
$indstr = "\n" . str_repeat( ' ', $indent );
} else {
$indstr = '';
}
- $elemName = str_replace( ' ', '_', $elemName );
-
- if ( is_array( $elemValue ) ) {
- if ( isset( $elemValue['*'] ) ) {
- $subElemContent = $elemValue['*'];
- unset( $elemValue['*'] );
- // Add xml:space="preserve" to the
- // element so XML parsers will leave
- // whitespace in the content alone
- $elemValue['xml:space'] = 'preserve';
- } else {
- $subElemContent = null;
+ if ( is_object( $value ) ) {
+ $value = (array)$value;
+ }
+ if ( is_array( $value ) ) {
+ $contentKey = isset( $value[ApiResult::META_CONTENT] )
+ ? $value[ApiResult::META_CONTENT]
+ : '*';
+ $subelementKeys = isset( $value[ApiResult::META_SUBELEMENTS] )
+ ? $value[ApiResult::META_SUBELEMENTS]
+ : array();
+ if ( isset( $value[ApiResult::META_BC_SUBELEMENTS] ) ) {
+ $subelementKeys = array_merge(
+ $subelementKeys, $value[ApiResult::META_BC_SUBELEMENTS]
+ );
}
+ $preserveKeys = isset( $value[ApiResult::META_PRESERVE_KEYS] )
+ ? $value[ApiResult::META_PRESERVE_KEYS]
+ : array();
+ $indexedTagName = isset( $value[ApiResult::META_INDEXED_TAG_NAME] )
+ ? self::mangleName( $value[ApiResult::META_INDEXED_TAG_NAME], $preserveKeys )
+ : '_v';
+ $bcBools = isset( $value[ApiResult::META_BC_BOOLS] )
+ ? $value[ApiResult::META_BC_BOOLS]
+ : array();
+ $indexSubelements = isset( $value[ApiResult::META_TYPE] )
+ ? $value[ApiResult::META_TYPE] !== 'array'
+ : false;
- if ( isset( $elemValue['_element'] ) ) {
- $subElemIndName = $elemValue['_element'];
- unset( $elemValue['_element'] );
- } else {
- $subElemIndName = null;
- }
+ $content = null;
+ $subelements = array();
+ $indexedSubelements = array();
+ foreach ( $value as $k => $v ) {
+ if ( ApiResult::isMetadataKey( $k ) && !in_array( $k, $preserveKeys, true ) ) {
+ continue;
+ }
- if ( isset( $elemValue['_subelements'] ) ) {
- foreach ( $elemValue['_subelements'] as $subElemId ) {
- if ( isset( $elemValue[$subElemId] ) && !is_array( $elemValue[$subElemId] ) ) {
- $elemValue[$subElemId] = array( '*' => $elemValue[$subElemId] );
- }
+ $oldv = $v;
+ if ( is_bool( $v ) && !in_array( $k, $bcBools, true ) ) {
+ $v = $v ? 'true' : 'false';
}
- unset( $elemValue['_subelements'] );
- }
- $indElements = array();
- $subElements = array();
- foreach ( $elemValue as $subElemId => & $subElemValue ) {
- if ( is_int( $subElemId ) ) {
- $indElements[] = $subElemValue;
- unset( $elemValue[$subElemId] );
- } elseif ( is_array( $subElemValue ) ) {
- $subElements[$subElemId] = $subElemValue;
- unset( $elemValue[$subElemId] );
- } elseif ( is_bool( $subElemValue ) ) {
- // treat true as empty string, skip false in xml format
- if ( $subElemValue === true ) {
- $subElemValue = '';
- } else {
- unset( $elemValue[$subElemId] );
+ if ( $name !== null && $k === $contentKey ) {
+ $content = $v;
+ } elseif ( is_int( $k ) ) {
+ $indexedSubelements[$k] = $v;
+ } elseif ( is_array( $v ) || is_object( $v ) ) {
+ $subelements[self::mangleName( $k, $preserveKeys )] = $v;
+ } elseif ( in_array( $k, $subelementKeys, true ) || $name === null ) {
+ $subelements[self::mangleName( $k, $preserveKeys )] = array(
+ 'content' => $v,
+ ApiResult::META_CONTENT => 'content',
+ ApiResult::META_TYPE => 'assoc',
+ );
+ } elseif ( is_bool( $oldv ) ) {
+ if ( $oldv ) {
+ $attributes[self::mangleName( $k, $preserveKeys )] = '';
}
+ } elseif ( $v !== null ) {
+ $attributes[self::mangleName( $k, $preserveKeys )] = $v;
}
}
- if ( is_null( $subElemIndName ) && count( $indElements ) ) {
- ApiBase::dieDebug( __METHOD__, "($elemName, ...) has integer keys " .
- "without _element value. Use ApiResult::setIndexedTagName()." );
- }
-
- if ( count( $subElements ) && count( $indElements ) && !is_null( $subElemContent ) ) {
- ApiBase::dieDebug( __METHOD__, "($elemName, ...) has content and subelements" );
+ if ( $content !== null ) {
+ if ( $subelements || $indexedSubelements ) {
+ $subelements[self::mangleName( $contentKey, $preserveKeys )] = array(
+ 'content' => $content,
+ ApiResult::META_CONTENT => 'content',
+ ApiResult::META_TYPE => 'assoc',
+ );
+ $content = null;
+ } elseif ( is_scalar( $content ) ) {
+ // Add xml:space="preserve" to the element so XML parsers
+ // will leave whitespace in the content alone
+ $attributes += array( 'xml:space' => 'preserve' );
+ }
}
- if ( !is_null( $subElemContent ) ) {
- $retval .= $indstr . Xml::element( $elemName, $elemValue, $subElemContent );
- } elseif ( !count( $indElements ) && !count( $subElements ) ) {
- $retval .= $indstr . Xml::element( $elemName, $elemValue );
+ if ( $content !== null ) {
+ if ( is_scalar( $content ) ) {
+ $retval .= $indstr . Xml::element( $name, $attributes, $content );
+ } else {
+ if ( $name !== null ) {
+ $retval .= $indstr . Xml::element( $name, $attributes, null );
+ }
+ $retval .= static::recXmlPrint( null, $content, $indent );
+ if ( $name !== null ) {
+ $retval .= $indstr . Xml::closeElement( $name );
+ }
+ }
+ } elseif ( !$indexedSubelements && !$subelements ) {
+ if ( $name !== null ) {
+ $retval .= $indstr . Xml::element( $name, $attributes );
+ }
} else {
- $retval .= $indstr . Xml::element( $elemName, $elemValue, null );
-
- foreach ( $subElements as $subElemId => & $subElemValue ) {
- $retval .= self::recXmlPrint( $subElemId, $subElemValue, $indent );
+ if ( $name !== null ) {
+ $retval .= $indstr . Xml::element( $name, $attributes, null );
}
-
- foreach ( $indElements as &$subElemValue ) {
- $retval .= self::recXmlPrint( $subElemIndName, $subElemValue, $indent );
+ foreach ( $subelements as $k => $v ) {
+ $retval .= static::recXmlPrint( $k, $v, $indent );
+ }
+ foreach ( $indexedSubelements as $k => $v ) {
+ $retval .= static::recXmlPrint( $indexedTagName, $v, $indent,
+ $indexSubelements ? array( '_idx' => $k ) : array()
+ );
+ }
+ if ( $name !== null ) {
+ $retval .= $indstr . Xml::closeElement( $name );
}
-
- $retval .= $indstr . Xml::closeElement( $elemName );
}
- } elseif ( !is_object( $elemValue ) ) {
+ } else {
// to make sure null value doesn't produce unclosed element,
- // which is what Xml::element( $elemName, null, null ) returns
- if ( $elemValue === null ) {
- $retval .= $indstr . Xml::element( $elemName );
+ // which is what Xml::element( $name, null, null ) returns
+ if ( $value === null ) {
+ $retval .= $indstr . Xml::element( $name, $attributes );
} else {
- $retval .= $indstr . Xml::element( $elemName, null, $elemValue );
+ $retval .= $indstr . Xml::element( $name, $attributes, $value );
}
}
return $retval;
}
+ /**
+ * Mangle XML-invalid names to be valid in XML
+ * @param string $name
+ * @param array $preserveKeys Names to not mangle
+ * @return string Mangled name
+ */
+ private static function mangleName( $name, $preserveKeys = array() ) {
+ static $nsc = null, $nc = null;
+
+ if ( in_array( $name, $preserveKeys, true ) ) {
+ return $name;
+ }
+
+ if ( $name === '' ) {
+ return '_';
+ }
+
+ if ( $nsc === null ) {
+ // Note we omit ':' from $nsc and $nc because it's reserved for XML
+ // namespacing, and we omit '_' from $nsc (but not $nc) because we
+ // reserve it.
+ $nsc = 'A-Za-z\x{C0}-\x{D6}\x{D8}-\x{F6}\x{F8}-\x{2FF}\x{370}-\x{37D}\x{37F}-\x{1FFF}' .
+ '\x{200C}-\x{200D}\x{2070}-\x{218F}\x{2C00}-\x{2FEF}\x{3001}-\x{D7FF}' .
+ '\x{F900}-\x{FDCF}\x{FDF0}-\x{FFFD}\x{10000}-\x{EFFFF}';
+ $nc = $nsc . '_\-.0-9\x{B7}\x{300}-\x{36F}\x{203F}-\x{2040}';
+ }
+
+ if ( preg_match( "/^[$nsc][$nc]*$/uS", $name ) ) {
+ return $name;
+ }
+
+ return '_' . preg_replace_callback(
+ "/[^$nc]/uS",
+ function ( $m ) {
+ return sprintf( '.%X.', utf8ToCodepoint( $m[0] ) );
+ },
+ str_replace( '.', '.2E.', $name )
+ );
+ }
+
function addXslt() {
$nt = Title::newFromText( $this->mXslt );
if ( is_null( $nt ) || !$nt->exists() ) {
@@ -237,20 +296,13 @@ class ApiFormatXml extends ApiFormatBase {
public function getAllowedParams() {
return array(
- 'xslt' => null,
- 'includexmlnamespace' => false,
+ 'xslt' => array(
+ ApiBase::PARAM_HELP_MSG => 'apihelp-xml-param-xslt',
+ ),
+ 'includexmlnamespace' => array(
+ ApiBase::PARAM_DFLT => false,
+ ApiBase::PARAM_HELP_MSG => 'apihelp-xml-param-includexmlnamespace',
+ ),
);
}
-
- public function getParamDescription() {
- return array(
- 'xslt' => 'If specified, adds <xslt> as stylesheet. This should be a wiki page '
- . 'in the MediaWiki namespace whose page name ends with ".xsl"',
- 'includexmlnamespace' => 'If specified, adds an XML namespace'
- );
- }
-
- public function getDescription() {
- return 'Output data in XML format' . parent::getDescription();
- }
}
diff --git a/includes/api/ApiFormatYaml.php b/includes/api/ApiFormatYaml.php
index 3798f894..c9089a7d 100644
--- a/includes/api/ApiFormatYaml.php
+++ b/includes/api/ApiFormatYaml.php
@@ -40,7 +40,7 @@ class ApiFormatYaml extends ApiFormatJson {
parent::execute();
}
- public function getDescription() {
- return 'DEPRECATED! Output data in YAML format' . ApiFormatBase::getDescription();
+ public function isDeprecated() {
+ return true;
}
}
diff --git a/includes/api/ApiHelp.php b/includes/api/ApiHelp.php
index bcd6c12e..53e8c343 100644
--- a/includes/api/ApiHelp.php
+++ b/includes/api/ApiHelp.php
@@ -2,9 +2,9 @@
/**
*
*
- * Created on Sep 6, 2006
+ * Created on Aug 29, 2014
*
- * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
+ * Copyright © 2014 Brad Jorsch <bjorsch@wikimedia.org>
*
* 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,102 +25,596 @@
*/
/**
- * This is a simple class to handle action=help
+ * Class to output help for an API module
*
+ * @since 1.25 completely rewritten
* @ingroup API
*/
class ApiHelp extends ApiBase {
- /**
- * Module for displaying help
- */
public function execute() {
- // Get parameters
$params = $this->extractRequestParams();
+ $modules = array();
- if ( !isset( $params['modules'] ) && !isset( $params['querymodules'] ) ) {
- $this->dieUsage( '', 'help' );
+ foreach ( $params['modules'] as $path ) {
+ $modules[] = $this->getModuleFromPath( $path );
}
- $this->getMain()->setHelp();
- $result = $this->getResult();
+ // Get the help
+ $context = new DerivativeContext( $this->getMain()->getContext() );
+ $context->setSkin( SkinFactory::getDefaultInstance()->makeSkin( 'apioutput' ) );
+ $context->setLanguage( $this->getMain()->getLanguage() );
+ $context->setTitle( SpecialPage::getTitleFor( 'ApiHelp' ) );
+ $out = new OutputPage( $context );
+ $context->setOutput( $out );
+
+ self::getHelp( $context, $modules, $params );
- if ( is_array( $params['modules'] ) ) {
- $modules = $params['modules'];
+ // Grab the output from the skin
+ ob_start();
+ $context->getOutput()->output();
+ $html = ob_get_clean();
+
+ $result = $this->getResult();
+ if ( $params['wrap'] ) {
+ $data = array(
+ 'mime' => 'text/html',
+ 'help' => $html,
+ );
+ ApiResult::setSubelementsList( $data, 'help' );
+ $result->addValue( null, $this->getModuleName(), $data );
} else {
- $modules = array();
+ $result->reset();
+ $result->addValue( null, 'text', $html, ApiResult::NO_SIZE_CHECK );
+ $result->addValue( null, 'mime', 'text/html', ApiResult::NO_SIZE_CHECK );
+ }
+ }
+
+ /**
+ * Generate help for the specified modules
+ *
+ * Help is placed into the OutputPage object returned by
+ * $context->getOutput().
+ *
+ * Recognized options include:
+ * - headerlevel: (int) Header tag level
+ * - nolead: (bool) Skip the inclusion of api-help-lead
+ * - noheader: (bool) Skip the inclusion of the top-level section headers
+ * - submodules: (bool) Include help for submodules of the current module
+ * - recursivesubmodules: (bool) Include help for submodules recursively
+ * - helptitle: (string) Title to link for additional modules' help. Should contain $1.
+ *
+ * @param IContextSource $context
+ * @param ApiBase[]|ApiBase $modules
+ * @param array $options Formatting options (described above)
+ * @return string
+ */
+ public static function getHelp( IContextSource $context, $modules, array $options ) {
+ global $wgMemc, $wgContLang;
+
+ if ( !is_array( $modules ) ) {
+ $modules = array( $modules );
}
- if ( is_array( $params['querymodules'] ) ) {
- $this->logFeatureUsage( 'action=help&querymodules' );
- $queryModules = $params['querymodules'];
- foreach ( $queryModules as $m ) {
- $modules[] = 'query+' . $m;
+ $out = $context->getOutput();
+ $out->addModules( 'mediawiki.apihelp' );
+ $out->setPageTitle( $context->msg( 'api-help-title' ) );
+
+ $cacheKey = null;
+ if ( count( $modules ) == 1 && $modules[0] instanceof ApiMain &&
+ $options['recursivesubmodules'] && $context->getLanguage() === $wgContLang
+ ) {
+ $cacheHelpTimeout = $context->getConfig()->get( 'APICacheHelpTimeout' );
+ if ( $cacheHelpTimeout > 0 ) {
+ // Get help text from cache if present
+ $cacheKey = wfMemcKey( 'apihelp', $modules[0]->getModulePath(),
+ str_replace( ' ', '_', SpecialVersion::getVersion( 'nodb' ) ) );
+ $cached = $wgMemc->get( $cacheKey );
+ if ( $cached ) {
+ $out->addHTML( $cached );
+ return;
+ }
}
- } else {
- $queryModules = array();
}
+ if ( $out->getHTML() !== '' ) {
+ // Don't save to cache, there's someone else's content in the page
+ // already
+ $cacheKey = null;
+ }
+
+ $options['recursivesubmodules'] = !empty( $options['recursivesubmodules'] );
+ $options['submodules'] = $options['recursivesubmodules'] || !empty( $options['submodules'] );
- $r = array();
- foreach ( $modules as $m ) {
- // sub-modules could be given in the form of "name[+name[+name...]]"
- $subNames = explode( '+', $m );
- if ( count( $subNames ) === 1 ) {
- // In case the '+' was typed into URL, it resolves as a space
- $subNames = explode( ' ', $m );
+ // Prepend lead
+ if ( empty( $options['nolead'] ) ) {
+ $msg = $context->msg( 'api-help-lead' );
+ if ( !$msg->isDisabled() ) {
+ $out->addHTML( $msg->parseAsBlock() );
}
+ }
- $module = $this->getMain();
- $subNamesCount = count( $subNames );
- for ( $i = 0; $i < $subNamesCount; $i++ ) {
- $subs = $module->getModuleManager();
- if ( $subs === null ) {
- $module = null;
- } else {
- $module = $subs->getModule( $subNames[$i] );
- }
+ $haveModules = array();
+ $out->addHTML( self::getHelpInternal( $context, $modules, $options, $haveModules ) );
- if ( $module === null ) {
- if ( count( $subNames ) === 2
- && $i === 1
- && $subNames[0] === 'query'
- && in_array( $subNames[1], $queryModules )
- ) {
- // Legacy: This is one of the renamed 'querymodule=...' parameters,
- // do not use '+' notation in the output, use submodule's name instead.
- $name = $subNames[1];
- } else {
- $name = implode( '+', array_slice( $subNames, 0, $i + 1 ) );
- }
- $r[] = array( 'name' => $name, 'missing' => '' );
- break;
+ $helptitle = isset( $options['helptitle'] ) ? $options['helptitle'] : null;
+ $html = self::fixHelpLinks( $out->getHTML(), $helptitle, $haveModules );
+ $out->clearHTML();
+ $out->addHTML( $html );
+
+ if ( $cacheKey !== null ) {
+ $wgMemc->set( $cacheKey, $out->getHTML(), $cacheHelpTimeout );
+ }
+ }
+
+ /**
+ * Replace Special:ApiHelp links with links to api.php
+ *
+ * @param string $html
+ * @param string|null $helptitle Title to link to rather than api.php, must contain '$1'
+ * @param array $localModules Modules to link within the current page
+ * @return string
+ */
+ public static function fixHelpLinks( $html, $helptitle = null, $localModules = array() ) {
+ $formatter = new HtmlFormatter( $html );
+ $doc = $formatter->getDoc();
+ $xpath = new DOMXPath( $doc );
+ $nodes = $xpath->query( '//a[@href][not(contains(@class,\'apihelp-linktrail\'))]' );
+ foreach ( $nodes as $node ) {
+ $href = $node->getAttribute( 'href' );
+ do {
+ $old = $href;
+ $href = rawurldecode( $href );
+ } while ( $old !== $href );
+ if ( preg_match( '!Special:ApiHelp/([^&/|]+)!', $href, $m ) ) {
+ if ( isset( $localModules[$m[1]] ) ) {
+ $href = '#' . $m[1];
+ } elseif ( $helptitle !== null ) {
+ $href = Title::newFromText( str_replace( '$1', $m[1], $helptitle ) )
+ ->getFullUrl();
} else {
- $type = $subs->getModuleGroup( $subNames[$i] );
+ $href = wfAppendQuery( wfScript( 'api' ), array(
+ 'action' => 'help',
+ 'modules' => $m[1],
+ ) );
}
- }
-
- if ( $module !== null ) {
- $r[] = $this->buildModuleHelp( $module, $type );
+ $node->setAttribute( 'href', $href );
+ $node->removeAttribute( 'title' );
}
}
- $result->setIndexedTagName( $r, 'module' );
- $result->addValue( null, $this->getModuleName(), $r );
+ return $formatter->getText();
}
/**
- * @param ApiBase $module
- * @param string $type What type of request is this? e.g. action, query, list, prop, meta, format
+ * Wrap a message in HTML with a class.
+ *
+ * @param Message $msg
+ * @param string $class
+ * @param string $tag
* @return string
*/
- private function buildModuleHelp( $module, $type ) {
- $msg = ApiMain::makeHelpMsgHeader( $module, $type );
+ private static function wrap( Message $msg, $class, $tag = 'span' ) {
+ return Html::rawElement( $tag, array( 'class' => $class ),
+ $msg->parse()
+ );
+ }
+
+ /**
+ * Recursively-called function to actually construct the help
+ *
+ * @param IContextSource $context
+ * @param ApiBase[] $modules
+ * @param array $options
+ * @param array &$haveModules
+ * @return string
+ */
+ private static function getHelpInternal( IContextSource $context, array $modules,
+ array $options, &$haveModules
+ ) {
+ $out = '';
+
+ $level = min( 6, empty( $options['headerlevel'] ) ? 2 : $options['headerlevel'] );
+ $options['headerlevel'] = $level;
+
+ foreach ( $modules as $module ) {
+ $haveModules[$module->getModulePath()] = true;
+ $module->setContext( $context );
+ $help = array(
+ 'header' => '',
+ 'flags' => '',
+ 'description' => '',
+ 'help-urls' => '',
+ 'parameters' => '',
+ 'examples' => '',
+ 'submodules' => '',
+ );
+
+ if ( empty( $options['noheader'] ) ) {
+ $path = $module->getModulePath();
+ if ( $module->isMain() ) {
+ $header = $context->msg( 'api-help-main-header' )->parse();
+ } else {
+ $name = $module->getModuleName();
+ $header = $module->getParent()->getModuleManager()->getModuleGroup( $name ) .
+ "=$name";
+ if ( $module->getModulePrefix() !== '' ) {
+ $header .= ' ' .
+ $context->msg( 'parentheses', $module->getModulePrefix() )->parse();
+ }
+ }
+ $help['header'] .= Html::element( "h$level",
+ array( 'id' => $path, 'class' => 'apihelp-header' ),
+ $header
+ );
+ }
+
+ $links = array();
+ $any = false;
+ for ( $m = $module; $m !== null; $m = $m->getParent() ) {
+ $name = $m->getModuleName();
+ if ( $name === 'main_int' ) {
+ $name = 'main';
+ }
- $msg2 = $module->makeHelpMsg();
- if ( $msg2 !== false ) {
- $msg .= $msg2;
+ if ( count( $modules ) === 1 && $m === $modules[0] &&
+ !( !empty( $options['submodules'] ) && $m->getModuleManager() )
+ ) {
+ $link = Html::element( 'b', null, $name );
+ } else {
+ $link = SpecialPage::getTitleFor( 'ApiHelp', $m->getModulePath() )->getLocalURL();
+ $link = Html::element( 'a',
+ array( 'href' => $link, 'class' => 'apihelp-linktrail' ),
+ $name
+ );
+ $any = true;
+ }
+ array_unshift( $links, $link );
+ }
+ if ( $any ) {
+ $help['header'] .= self::wrap(
+ $context->msg( 'parentheses' )
+ ->rawParams( $context->getLanguage()->pipeList( $links ) ),
+ 'apihelp-linktrail', 'div'
+ );
+ }
+
+ $flags = $module->getHelpFlags();
+ if ( $flags ) {
+ $help['flags'] .= Html::openElement( 'div',
+ array( 'class' => 'apihelp-block apihelp-flags' ) );
+ $msg = $context->msg( 'api-help-flags' );
+ if ( !$msg->isDisabled() ) {
+ $help['flags'] .= self::wrap(
+ $msg->numParams( count( $flags ) ), 'apihelp-block-head', 'div'
+ );
+ }
+ $help['flags'] .= Html::openElement( 'ul' );
+ foreach ( $flags as $flag ) {
+ $help['flags'] .= Html::rawElement( 'li', null,
+ self::wrap( $context->msg( "api-help-flag-$flag" ), "apihelp-flag-$flag" )
+ );
+ }
+ $help['flags'] .= Html::closeElement( 'ul' );
+ $help['flags'] .= Html::closeElement( 'div' );
+ }
+
+ foreach ( $module->getFinalDescription() as $msg ) {
+ $msg->setContext( $context );
+ $help['description'] .= $msg->parseAsBlock();
+ }
+
+ $urls = $module->getHelpUrls();
+ if ( $urls ) {
+ $help['help-urls'] .= Html::openElement( 'div',
+ array( 'class' => 'apihelp-block apihelp-help-urls' )
+ );
+ $msg = $context->msg( 'api-help-help-urls' );
+ if ( !$msg->isDisabled() ) {
+ $help['help-urls'] .= self::wrap(
+ $msg->numParams( count( $urls ) ), 'apihelp-block-head', 'div'
+ );
+ }
+ if ( !is_array( $urls ) ) {
+ $urls = array( $urls );
+ }
+ $help['help-urls'] .= Html::openElement( 'ul' );
+ foreach ( $urls as $url ) {
+ $help['help-urls'] .= Html::rawElement( 'li', null,
+ Html::element( 'a', array( 'href' => $url ), $url )
+ );
+ }
+ $help['help-urls'] .= Html::closeElement( 'ul' );
+ $help['help-urls'] .= Html::closeElement( 'div' );
+ }
+
+ $params = $module->getFinalParams( ApiBase::GET_VALUES_FOR_HELP );
+ $groups = array();
+ if ( $params ) {
+ $help['parameters'] .= Html::openElement( 'div',
+ array( 'class' => 'apihelp-block apihelp-parameters' )
+ );
+ $msg = $context->msg( 'api-help-parameters' );
+ if ( !$msg->isDisabled() ) {
+ $help['parameters'] .= self::wrap(
+ $msg->numParams( count( $params ) ), 'apihelp-block-head', 'div'
+ );
+ }
+ $help['parameters'] .= Html::openElement( 'dl' );
+
+ $descriptions = $module->getFinalParamDescription();
+
+ foreach ( $params as $name => $settings ) {
+ if ( !is_array( $settings ) ) {
+ $settings = array( ApiBase::PARAM_DFLT => $settings );
+ }
+
+ $help['parameters'] .= Html::element( 'dt', null,
+ $module->encodeParamName( $name ) );
+
+ // Add description
+ $description = array();
+ if ( isset( $descriptions[$name] ) ) {
+ foreach ( $descriptions[$name] as $msg ) {
+ $msg->setContext( $context );
+ $description[] = $msg->parseAsBlock();
+ }
+ }
+
+ // Add usage info
+ $info = array();
+
+ // Required?
+ if ( !empty( $settings[ApiBase::PARAM_REQUIRED] ) ) {
+ $info[] = $context->msg( 'api-help-param-required' )->parse();
+ }
+
+ // Custom info?
+ if ( !empty( $settings[ApiBase::PARAM_HELP_MSG_INFO] ) ) {
+ foreach ( $settings[ApiBase::PARAM_HELP_MSG_INFO] as $i ) {
+ $tag = array_shift( $i );
+ $info[] = $context->msg( "apihelp-{$path}-paraminfo-{$tag}" )
+ ->numParams( count( $i ) )
+ ->params( $context->getLanguage()->commaList( $i ) )
+ ->params( $module->getModulePrefix() )
+ ->parse();
+ }
+ }
+
+ // Type documentation
+ if ( !isset( $settings[ApiBase::PARAM_TYPE] ) ) {
+ $dflt = isset( $settings[ApiBase::PARAM_DFLT] )
+ ? $settings[ApiBase::PARAM_DFLT]
+ : null;
+ if ( is_bool( $dflt ) ) {
+ $settings[ApiBase::PARAM_TYPE] = 'boolean';
+ } elseif ( is_string( $dflt ) || is_null( $dflt ) ) {
+ $settings[ApiBase::PARAM_TYPE] = 'string';
+ } elseif ( is_int( $dflt ) ) {
+ $settings[ApiBase::PARAM_TYPE] = 'integer';
+ }
+ }
+ if ( isset( $settings[ApiBase::PARAM_TYPE] ) ) {
+ $type = $settings[ApiBase::PARAM_TYPE];
+ $multi = !empty( $settings[ApiBase::PARAM_ISMULTI] );
+ $hintPipeSeparated = true;
+ $count = ApiBase::LIMIT_SML2 + 1;
+
+ if ( is_array( $type ) ) {
+ $count = count( $type );
+ $links = isset( $settings[ApiBase::PARAM_VALUE_LINKS] )
+ ? $settings[ApiBase::PARAM_VALUE_LINKS]
+ : array();
+ $type = array_map( function ( $v ) use ( $links ) {
+ $ret = wfEscapeWikiText( $v );
+ if ( isset( $links[$v] ) ) {
+ $ret = "[[{$links[$v]}|$ret]]";
+ }
+ return $ret;
+ }, $type );
+ $i = array_search( '', $type, true );
+ if ( $i === false ) {
+ $type = $context->getLanguage()->commaList( $type );
+ } else {
+ unset( $type[$i] );
+ $type = $context->msg( 'api-help-param-list-can-be-empty' )
+ ->numParams( count( $type ) )
+ ->params( $context->getLanguage()->commaList( $type ) )
+ ->parse();
+ }
+ $info[] = $context->msg( 'api-help-param-list' )
+ ->params( $multi ? 2 : 1 )
+ ->params( $type )
+ ->parse();
+ $hintPipeSeparated = false;
+ } else {
+ switch ( $type ) {
+ case 'submodule':
+ $groups[] = $name;
+ $submodules = $module->getModuleManager()->getNames( $name );
+ $count = count( $submodules );
+ sort( $submodules );
+ $prefix = $module->isMain()
+ ? '' : ( $module->getModulePath() . '+' );
+ $submodules = array_map( function ( $name ) use ( $prefix ) {
+ return "[[Special:ApiHelp/{$prefix}{$name}|{$name}]]";
+ }, $submodules );
+ $info[] = $context->msg( 'api-help-param-list' )
+ ->params( $multi ? 2 : 1 )
+ ->params( $context->getLanguage()->commaList( $submodules ) )
+ ->parse();
+ $hintPipeSeparated = false;
+ break;
+
+ case 'namespace':
+ $namespaces = MWNamespace::getValidNamespaces();
+ $count = count( $namespaces );
+ $info[] = $context->msg( 'api-help-param-list' )
+ ->params( $multi ? 2 : 1 )
+ ->params( $context->getLanguage()->commaList( $namespaces ) )
+ ->parse();
+ $hintPipeSeparated = false;
+ break;
+
+ case 'limit':
+ if ( isset( $settings[ApiBase::PARAM_MAX2] ) ) {
+ $info[] = $context->msg( 'api-help-param-limit2' )
+ ->numParams( $settings[ApiBase::PARAM_MAX] )
+ ->numParams( $settings[ApiBase::PARAM_MAX2] )
+ ->parse();
+ } else {
+ $info[] = $context->msg( 'api-help-param-limit' )
+ ->numParams( $settings[ApiBase::PARAM_MAX] )
+ ->parse();
+ }
+ break;
+
+ case 'integer':
+ // Possible messages:
+ // api-help-param-integer-min,
+ // api-help-param-integer-max,
+ // api-help-param-integer-minmax
+ $suffix = '';
+ $min = $max = 0;
+ if ( isset( $settings[ApiBase::PARAM_MIN] ) ) {
+ $suffix .= 'min';
+ $min = $settings[ApiBase::PARAM_MIN];
+ }
+ if ( isset( $settings[ApiBase::PARAM_MAX] ) ) {
+ $suffix .= 'max';
+ $max = $settings[ApiBase::PARAM_MAX];
+ }
+ if ( $suffix !== '' ) {
+ $info[] =
+ $context->msg( "api-help-param-integer-$suffix" )
+ ->params( $multi ? 2 : 1 )
+ ->numParams( $min, $max )
+ ->parse();
+ }
+ break;
+
+ case 'upload':
+ $info[] = $context->msg( 'api-help-param-upload' )
+ ->parse();
+ break;
+ }
+ }
+
+ if ( $multi ) {
+ $extra = array();
+ if ( $hintPipeSeparated ) {
+ $extra[] = $context->msg( 'api-help-param-multi-separate' )->parse();
+ }
+ if ( $count > ApiBase::LIMIT_SML1 ) {
+ $extra[] = $context->msg( 'api-help-param-multi-max' )
+ ->numParams( ApiBase::LIMIT_SML1, ApiBase::LIMIT_SML2 )
+ ->parse();
+ }
+ if ( $extra ) {
+ $info[] = join( ' ', $extra );
+ }
+ }
+ }
+
+ // Add default
+ $default = isset( $settings[ApiBase::PARAM_DFLT] )
+ ? $settings[ApiBase::PARAM_DFLT]
+ : null;
+ if ( $default === '' ) {
+ $info[] = $context->msg( 'api-help-param-default-empty' )
+ ->parse();
+ } elseif ( $default !== null && $default !== false ) {
+ $info[] = $context->msg( 'api-help-param-default' )
+ ->params( wfEscapeWikiText( $default ) )
+ ->parse();
+ }
+
+ if ( !array_filter( $description ) ) {
+ $description = array( self::wrap(
+ $context->msg( 'api-help-param-no-description' ),
+ 'apihelp-empty'
+ ) );
+ }
+
+ // Add "deprecated" flag
+ if ( !empty( $settings[ApiBase::PARAM_DEPRECATED] ) ) {
+ $help['parameters'] .= Html::openElement( 'dd',
+ array( 'class' => 'info' ) );
+ $help['parameters'] .= self::wrap(
+ $context->msg( 'api-help-param-deprecated' ),
+ 'apihelp-deprecated', 'strong'
+ );
+ $help['parameters'] .= Html::closeElement( 'dd' );
+ }
+
+ if ( $description ) {
+ $description = join( '', $description );
+ $description = preg_replace( '!\s*</([oud]l)>\s*<\1>\s*!', "\n", $description );
+ $help['parameters'] .= Html::rawElement( 'dd',
+ array( 'class' => 'description' ), $description );
+ }
+
+ foreach ( $info as $i ) {
+ $help['parameters'] .= Html::rawElement( 'dd', array( 'class' => 'info' ), $i );
+ }
+ }
+
+ $help['parameters'] .= Html::closeElement( 'dl' );
+ $help['parameters'] .= Html::closeElement( 'div' );
+ }
+
+ $examples = $module->getExamplesMessages();
+ if ( $examples ) {
+ $help['examples'] .= Html::openElement( 'div',
+ array( 'class' => 'apihelp-block apihelp-examples' ) );
+ $msg = $context->msg( 'api-help-examples' );
+ if ( !$msg->isDisabled() ) {
+ $help['examples'] .= self::wrap(
+ $msg->numParams( count( $examples ) ), 'apihelp-block-head', 'div'
+ );
+ }
+
+ $help['examples'] .= Html::openElement( 'dl' );
+ foreach ( $examples as $qs => $msg ) {
+ $msg = ApiBase::makeMessage( $msg, $context, array(
+ $module->getModulePrefix(),
+ $module->getModuleName(),
+ $module->getModulePath()
+ ) );
+
+ $link = wfAppendQuery( wfScript( 'api' ), $qs );
+ $help['examples'] .= Html::rawElement( 'dt', null, $msg->parse() );
+ $help['examples'] .= Html::rawElement( 'dd', null,
+ Html::element( 'a', array( 'href' => $link ), "api.php?$qs" )
+ );
+ }
+ $help['examples'] .= Html::closeElement( 'dl' );
+ $help['examples'] .= Html::closeElement( 'div' );
+ }
+
+ if ( $options['submodules'] && $module->getModuleManager() ) {
+ $manager = $module->getModuleManager();
+ $submodules = array();
+ foreach ( $groups as $group ) {
+ $names = $manager->getNames( $group );
+ sort( $names );
+ foreach ( $names as $name ) {
+ $submodules[] = $manager->getModule( $name );
+ }
+ }
+ $help['submodules'] .= self::getHelpInternal( $context, $submodules, array(
+ 'submodules' => $options['recursivesubmodules'],
+ 'headerlevel' => $level + 1,
+ 'noheader' => false,
+ ) + $options, $haveModules );
+ }
+
+ $module->modifyHelp( $help, $options );
+
+ Hooks::run( 'APIHelpModifyOutput', array( $module, &$help, $options ) );
+
+ $out .= join( "\n", $help );
}
- return $msg;
+ return $out;
}
public function shouldCheckMaxlag() {
@@ -131,39 +625,40 @@ class ApiHelp extends ApiBase {
return false;
}
+ public function getCustomPrinter() {
+ $params = $this->extractRequestParams();
+ if ( $params['wrap'] ) {
+ return null;
+ }
+
+ $main = $this->getMain();
+ $errorPrinter = $main->createPrinterByName( $main->getParameter( 'format' ) );
+ return new ApiFormatRaw( $main, $errorPrinter );
+ }
+
public function getAllowedParams() {
return array(
'modules' => array(
- ApiBase::PARAM_ISMULTI => true
- ),
- 'querymodules' => array(
+ ApiBase::PARAM_DFLT => 'main',
ApiBase::PARAM_ISMULTI => true,
- ApiBase::PARAM_DEPRECATED => true
),
+ 'submodules' => false,
+ 'recursivesubmodules' => false,
+ 'wrap' => false,
+ 'toc' => false,
);
}
- public function getParamDescription() {
- return array(
- 'modules' => 'List of module names (value of the action= parameter). ' .
- 'Can specify submodules with a \'+\'',
- 'querymodules' => 'Use modules=query+value instead. List of query ' .
- 'module names (value of prop=, meta= or list= parameter)',
- );
- }
-
- public function getDescription() {
- return 'Display this help screen. Or the help screen for the specified module.';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=help' => 'Whole help page',
- 'api.php?action=help&modules=protect' => 'Module (action) help page',
- 'api.php?action=help&modules=query+categorymembers'
- => 'Help for the query/categorymembers module',
- 'api.php?action=help&modules=login|query+info'
- => 'Help for the login and query/info modules',
+ 'action=help'
+ => 'apihelp-help-example-main',
+ 'action=help&recursivesubmodules=1'
+ => 'apihelp-help-example-recursive',
+ 'action=help&modules=help'
+ => 'apihelp-help-example-help',
+ 'action=help&modules=query+info|query+categorymembers'
+ => 'apihelp-help-example-query',
);
}
diff --git a/includes/api/ApiHelpParamValueMessage.php b/includes/api/ApiHelpParamValueMessage.php
new file mode 100644
index 00000000..7cf3d6ed
--- /dev/null
+++ b/includes/api/ApiHelpParamValueMessage.php
@@ -0,0 +1,72 @@
+<?php
+/**
+ *
+ *
+ * Created on Dec 22, 2014
+ *
+ * Copyright © 2014 Brad Jorsch <bjorsch@wikimedia.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * Message subclass that prepends wikitext for API help.
+ *
+ * This exists so the apihelp-*-paramvalue-*-* messages don't all have to
+ * include markup wikitext while still keeping the
+ * 'APIGetParamDescriptionMessages' hook simple.
+ *
+ * @since 1.25
+ */
+class ApiHelpParamValueMessage extends Message {
+
+ protected $paramValue;
+
+ /**
+ * @see Message::__construct
+ *
+ * @param string $paramValue Parameter value being documented
+ * @param string $text Message to use.
+ * @param array $params Parameters for the message.
+ * @throws InvalidArgumentException
+ */
+ public function __construct( $paramValue, $text, $params = array() ) {
+ parent::__construct( $text, $params );
+ $this->paramValue = $paramValue;
+ }
+
+ /**
+ * Fetch the parameter value
+ * @return string
+ */
+ public function getParamValue() {
+ return $this->paramValue;
+ }
+
+ /**
+ * Fetch the message.
+ * @return string
+ */
+ public function fetchMessage() {
+ if ( $this->message === null ) {
+ $this->message = ";{$this->paramValue}:" . parent::fetchMessage();
+ }
+ return $this->message;
+ }
+
+}
diff --git a/includes/api/ApiImageRotate.php b/includes/api/ApiImageRotate.php
index 20396dd7..865d39fa 100644
--- a/includes/api/ApiImageRotate.php
+++ b/includes/api/ApiImageRotate.php
@@ -42,7 +42,7 @@ class ApiImageRotate extends ApiBase {
$v = $val;
}
if ( $flag !== null ) {
- $v[$flag] = '';
+ $v[$flag] = true;
}
$result[] = $v;
}
@@ -52,7 +52,8 @@ class ApiImageRotate extends ApiBase {
$params = $this->extractRequestParams();
$rotation = $params['rotation'];
- $this->getResult()->beginContinuation( $params['continue'], array(), array() );
+ $continuationManager = new ApiContinuationManager( $this, array(), array() );
+ $this->setContinuationManager( $continuationManager );
$pageSet = $this->getPageSet();
$pageSet->execute();
@@ -70,10 +71,10 @@ class ApiImageRotate extends ApiBase {
$r['id'] = $title->getArticleID();
ApiQueryBase::addTitleInfo( $r, $title );
if ( !$title->exists() ) {
- $r['missing'] = '';
+ $r['missing'] = true;
}
- $file = wfFindFile( $title );
+ $file = wfFindFile( $title, array( 'latest' => true ) );
if ( !$file ) {
$r['result'] = 'Failure';
$r['errormessage'] = 'File does not exist';
@@ -122,7 +123,7 @@ class ApiImageRotate extends ApiBase {
$r['result'] = 'Success';
} else {
$r['result'] = 'Failure';
- $r['errormessage'] = $this->getResult()->convertStatusToArray( $status );
+ $r['errormessage'] = $this->getErrorFormatter()->arrayFromStatus( $status );
}
} else {
$r['result'] = 'Failure';
@@ -131,9 +132,11 @@ class ApiImageRotate extends ApiBase {
$result[] = $r;
}
$apiResult = $this->getResult();
- $apiResult->setIndexedTagName( $result, 'page' );
+ ApiResult::setIndexedTagName( $result, 'page' );
$apiResult->addValue( null, $this->getModuleName(), $result );
- $apiResult->endContinuation();
+
+ $this->setContinuationManager( null );
+ $continuationManager->setContinuationIntoResult( $apiResult );
}
/**
@@ -184,7 +187,9 @@ class ApiImageRotate extends ApiBase {
ApiBase::PARAM_TYPE => array( '90', '180', '270' ),
ApiBase::PARAM_REQUIRED => true
),
- 'continue' => '',
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ),
);
if ( $flags ) {
$result += $this->getPageSet()->getFinalParams( $flags );
@@ -193,26 +198,17 @@ class ApiImageRotate extends ApiBase {
return $result;
}
- public function getParamDescription() {
- $pageSet = $this->getPageSet();
-
- return $pageSet->getFinalParamDescription() + array(
- 'rotation' => 'Degrees to rotate image clockwise',
- 'continue' => 'When more results are available, use this to continue',
- );
- }
-
- public function getDescription() {
- return 'Rotate one or more images.';
- }
-
public function needsToken() {
return 'csrf';
}
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=imagerotate&titles=Example.jpg&rotation=90&token=123ABC',
+ 'action=imagerotate&titles=File:Example.jpg&rotation=90&token=123ABC'
+ => 'apihelp-imagerotate-example-simple',
+ 'action=imagerotate&generator=categorymembers&gcmtitle=Category:Flip&gcmtype=file&' .
+ 'rotation=180&token=123ABC'
+ => 'apihelp-imagerotate-example-generator',
);
}
}
diff --git a/includes/api/ApiImport.php b/includes/api/ApiImport.php
index b11348e5..2e87d22d 100644
--- a/includes/api/ApiImport.php
+++ b/includes/api/ApiImport.php
@@ -60,7 +60,7 @@ class ApiImport extends ApiBase {
$this->dieStatus( $source );
}
- $importer = new WikiImporter( $source->value );
+ $importer = new WikiImporter( $source->value, $this->getConfig() );
if ( isset( $params['namespace'] ) ) {
$importer->setTargetNamespace( $params['namespace'] );
}
@@ -79,13 +79,13 @@ class ApiImport extends ApiBase {
try {
$importer->doImport();
- } catch ( MWException $e ) {
+ } catch ( Exception $e ) {
$this->dieUsageMsg( array( 'import-unknownerror', $e->getMessage() ) );
}
$resultData = $reporter->getData();
$result = $this->getResult();
- $result->setIndexedTagName( $resultData, 'page' );
+ ApiResult::setIndexedTagName( $resultData, 'page' );
$result->addValue( null, $this->getModuleName(), $resultData );
}
@@ -116,36 +116,15 @@ class ApiImport extends ApiBase {
);
}
- public function getParamDescription() {
- return array(
- 'summary' => 'Import summary',
- 'xml' => 'Uploaded XML file',
- 'interwikisource' => 'For interwiki imports: wiki to import from',
- 'interwikipage' => 'For interwiki imports: page to import',
- 'fullhistory' => 'For interwiki imports: import the full history, not just the current version',
- 'templates' => 'For interwiki imports: import all included templates as well',
- 'namespace' => 'For interwiki imports: import to this namespace',
- 'rootpage' => 'Import as subpage of this page',
- );
- }
-
- public function getDescription() {
- return array(
- 'Import a page from another wiki, or an XML file.',
- 'Note that the HTTP POST must be done as a file upload (i.e. using multipart/form-data) when',
- 'sending a file for the "xml" parameter.'
- );
- }
-
public function needsToken() {
return 'csrf';
}
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=import&interwikisource=meta&interwikipage=Help:ParserFunctions&' .
+ 'action=import&interwikisource=meta&interwikipage=Help:ParserFunctions&' .
'namespace=100&fullhistory=&token=123ABC'
- => 'Import [[meta:Help:Parserfunctions]] to namespace 100 with full history',
+ => 'apihelp-import-example-import',
);
}
@@ -176,7 +155,7 @@ class ApiImportReporter extends ImportReporter {
if ( $title === null ) {
# Invalid or non-importable title
$r['title'] = $pageInfo['title'];
- $r['invalid'] = '';
+ $r['invalid'] = true;
} else {
ApiQueryBase::addTitleInfo( $r, $title );
$r['revisions'] = intval( $successCount );
diff --git a/includes/api/ApiLogin.php b/includes/api/ApiLogin.php
index 976f4c12..5480d940 100644
--- a/includes/api/ApiLogin.php
+++ b/includes/api/ApiLogin.php
@@ -46,11 +46,12 @@ class ApiLogin extends ApiBase {
* is reached. The expiry is $this->mLoginThrottle.
*/
public function execute() {
- // If we're in JSON callback mode, no tokens can be obtained
- if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) {
+ // If we're in a mode that breaks the same-origin policy, no tokens can
+ // be obtained
+ if ( $this->lacksSameOriginSecurity() ) {
$this->getResult()->addValue( null, 'login', array(
'result' => 'Aborted',
- 'reason' => 'Cannot log in when using a callback',
+ 'reason' => 'Cannot log in when the same-origin policy is not applied',
) );
return;
@@ -92,7 +93,7 @@ class ApiLogin extends ApiBase {
// @todo FIXME: Split back and frontend from this hook.
// @todo FIXME: This hook should be placed in the backend
$injected_html = '';
- wfRunHooks( 'UserLoginComplete', array( &$user, &$injected_html ) );
+ Hooks::run( 'UserLoginComplete', array( &$user, &$injected_html ) );
$result['result'] = 'Success';
$result['lguserid'] = intval( $user->getId() );
@@ -184,28 +185,12 @@ class ApiLogin extends ApiBase {
);
}
- public function getParamDescription() {
+ protected function getExamplesMessages() {
return array(
- 'name' => 'User Name',
- 'password' => 'Password',
- 'domain' => 'Domain (optional)',
- 'token' => 'Login token obtained in first request',
- );
- }
-
- public function getDescription() {
- return array(
- 'Log in and get the authentication tokens.',
- 'In the event of a successful log-in, a cookie will be attached to your session.',
- 'In the event of a failed log-in, you will not be able to attempt another log-in',
- 'through this method for 5 seconds. This is to prevent password guessing by',
- 'automated password crackers.'
- );
- }
-
- public function getExamples() {
- return array(
- 'api.php?action=login&lgname=user&lgpassword=password'
+ 'action=login&lgname=user&lgpassword=password'
+ => 'apihelp-login-example-gettoken',
+ 'action=login&lgname=user&lgpassword=password&lgtoken=123ABC'
+ => 'apihelp-login-example-login',
);
}
diff --git a/includes/api/ApiLogout.php b/includes/api/ApiLogout.php
index 324f4b2f..bf0ca9c6 100644
--- a/includes/api/ApiLogout.php
+++ b/includes/api/ApiLogout.php
@@ -39,28 +39,17 @@ class ApiLogout extends ApiBase {
// Give extensions to do something after user logout
$injected_html = '';
- wfRunHooks( 'UserLogoutComplete', array( &$user, &$injected_html, $oldName ) );
+ Hooks::run( 'UserLogoutComplete', array( &$user, &$injected_html, $oldName ) );
}
public function isReadMode() {
return false;
}
- public function getAllowedParams() {
- return array();
- }
-
- public function getParamDescription() {
- return array();
- }
-
- public function getDescription() {
- return 'Log out and clear session data.';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=logout' => 'Log the current user out',
+ 'action=logout'
+ => 'apihelp-logout-example-logout',
);
}
diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php
index 119d7b48..3bf066cf 100644
--- a/includes/api/ApiMain.php
+++ b/includes/api/ApiMain.php
@@ -42,7 +42,7 @@ class ApiMain extends ApiBase {
/**
* When no format parameter is given, this format will be used
*/
- const API_DEFAULT_FORMAT = 'xmlfm';
+ const API_DEFAULT_FORMAT = 'jsonfm';
/**
* List of available modules: action name => module class
@@ -54,6 +54,7 @@ class ApiMain extends ApiBase {
'query' => 'ApiQuery',
'expandtemplates' => 'ApiExpandTemplates',
'parse' => 'ApiParse',
+ 'stashedit' => 'ApiStashEdit',
'opensearch' => 'ApiOpenSearch',
'feedcontributions' => 'ApiFeedContributions',
'feedrecentchanges' => 'ApiFeedRecentChanges',
@@ -63,6 +64,7 @@ class ApiMain extends ApiBase {
'rsd' => 'ApiRsd',
'compare' => 'ApiComparePages',
'tokens' => 'ApiTokens',
+ 'checktoken' => 'ApiCheckToken',
// Write modules
'purge' => 'ApiPurge',
@@ -86,6 +88,8 @@ class ApiMain extends ApiBase {
'options' => 'ApiOptions',
'imagerotate' => 'ApiImageRotate',
'revisiondelete' => 'ApiRevisionDelete',
+ 'managetags' => 'ApiManageTags',
+ 'tag' => 'ApiTag',
);
/**
@@ -121,11 +125,11 @@ class ApiMain extends ApiBase {
*/
private static $mRights = array(
'writeapi' => array(
- 'msg' => 'Use of the write API',
+ 'msg' => 'right-writeapi',
'params' => array()
),
'apihighlimits' => array(
- 'msg' => 'Use higher limits in API queries (Slow queries: $1 results; Fast queries: $2 results). The limits for slow queries also apply to multivalue parameters.',
+ 'msg' => 'api-help-right-apihighlimits',
'params' => array( ApiBase::LIMIT_SML2, ApiBase::LIMIT_BIG2 )
)
);
@@ -136,7 +140,7 @@ class ApiMain extends ApiBase {
*/
private $mPrinter;
- private $mModuleMgr, $mResult;
+ private $mModuleMgr, $mResult, $mErrorFormatter, $mContinuationManager;
private $mAction;
private $mEnableWrite;
private $mInternalMode, $mSquidMaxage, $mModule;
@@ -178,15 +182,33 @@ class ApiMain extends ApiBase {
// Remove all modules other than login
global $wgUser;
- if ( $this->getVal( 'callback' ) !== null ) {
- // JSON callback allows cross-site reads.
- // For safety, strip user credentials.
- wfDebug( "API: stripping user credentials for JSON callback\n" );
+ if ( $this->lacksSameOriginSecurity() ) {
+ // If we're in a mode that breaks the same-origin policy, strip
+ // user credentials for security.
+ wfDebug( "API: stripping user credentials when the same-origin policy is not applied\n" );
$wgUser = new User();
$this->getContext()->setUser( $wgUser );
}
}
+ $uselang = $this->getParameter( 'uselang' );
+ if ( $uselang === 'user' ) {
+ // Assume the parent context is going to return the user language
+ // for uselang=user (see T85635).
+ } else {
+ if ( $uselang === 'content' ) {
+ global $wgContLang;
+ $uselang = $wgContLang->getCode();
+ }
+ $code = RequestContext::sanitizeLangCode( $uselang );
+ $this->getContext()->setLanguage( $code );
+ if ( !$this->mInternalMode ) {
+ global $wgLang;
+ $wgLang = $this->getContext()->getLanguage();
+ RequestContext::getMain()->setLanguage( $wgLang );
+ }
+ }
+
$config = $this->getConfig();
$this->mModuleMgr = new ApiModuleManager( $this );
$this->mModuleMgr->addModules( self::$Modules, 'action' );
@@ -194,7 +216,13 @@ class ApiMain extends ApiBase {
$this->mModuleMgr->addModules( self::$Formats, 'format' );
$this->mModuleMgr->addModules( $config->get( 'APIFormatModules' ), 'format' );
- $this->mResult = new ApiResult( $this );
+ Hooks::run( 'ApiMain::moduleManager', array( $this->mModuleMgr ) );
+
+ $this->mResult = new ApiResult( $this->getConfig()->get( 'APIMaxResultSize' ) );
+ $this->mErrorFormatter = new ApiErrorFormatter_BackCompat( $this->mResult );
+ $this->mResult->setErrorFormatter( $this->mErrorFormatter );
+ $this->mResult->setMainForContinuation( $this );
+ $this->mContinuationManager = null;
$this->mEnableWrite = $enableWrite;
$this->mSquidMaxage = -1; // flag for executeActionWithErrorHandling()
@@ -219,6 +247,43 @@ class ApiMain extends ApiBase {
}
/**
+ * Get the ApiErrorFormatter object associated with current request
+ * @return ApiErrorFormatter
+ */
+ public function getErrorFormatter() {
+ return $this->mErrorFormatter;
+ }
+
+ /**
+ * Get the continuation manager
+ * @return ApiContinuationManager|null
+ */
+ public function getContinuationManager() {
+ return $this->mContinuationManager;
+ }
+
+ /**
+ * Set the continuation manager
+ * @param ApiContinuationManager|null
+ */
+ public function setContinuationManager( $manager ) {
+ if ( $manager !== null ) {
+ if ( !$manager instanceof ApiContinuationManager ) {
+ throw new InvalidArgumentException( __METHOD__ . ': Was passed ' .
+ is_object( $manager ) ? get_class( $manager ) : gettype( $manager )
+ );
+ }
+ if ( $this->mContinuationManager !== null ) {
+ throw new UnexpectedValueException(
+ __METHOD__ . ': tried to set manager from ' . $manager->getSource() .
+ ' when a manager is already set from ' . $this->mContinuationManager->getSource()
+ );
+ }
+ }
+ $this->mContinuationManager = $manager;
+ }
+
+ /**
* Get the API module object. Only works after executeAction()
*
* @return ApiBase
@@ -290,6 +355,16 @@ class ApiMain extends ApiBase {
}
}
+ if ( $mode === 'public' && $this->getParameter( 'uselang' ) === 'user' ) {
+ // User language is used for i18n, so we don't want to publicly
+ // cache. Anons are ok, because if they have non-default language
+ // then there's an appropriate Vary header set by whatever set
+ // their non-default language.
+ wfDebug( __METHOD__ . ": downgrading cache mode 'public' to " .
+ "'anon-public-user-private' due to uselang=user\n" );
+ $mode = 'anon-public-user-private';
+ }
+
wfDebug( __METHOD__ . ": setting cache mode $mode\n" );
$this->mCacheMode = $mode;
}
@@ -328,14 +403,11 @@ class ApiMain extends ApiBase {
* Execute api request. Any errors will be handled if the API was called by the remote client.
*/
public function execute() {
- $this->profileIn();
if ( $this->mInternalMode ) {
$this->executeAction();
} else {
$this->executeActionWithErrorHandling();
}
-
- $this->profileOut();
}
/**
@@ -373,10 +445,6 @@ class ApiMain extends ApiBase {
// avoid sending public cache headers for errors.
$this->sendCacheHeaders();
- if ( $this->mPrinter->getIsHtml() && !$this->mPrinter->isDisabled() ) {
- echo wfReportTime();
- }
-
ob_end_flush();
}
@@ -390,11 +458,17 @@ class ApiMain extends ApiBase {
// Bug 63145: Rollback any open database transactions
if ( !( $e instanceof UsageException ) ) {
// UsageExceptions are intentional, so don't rollback if that's the case
- MWExceptionHandler::rollbackMasterChangesAndLog( $e );
+ try {
+ MWExceptionHandler::rollbackMasterChangesAndLog( $e );
+ } catch ( DBError $e2 ) {
+ // Rollback threw an exception too. Log it, but don't interrupt
+ // our regularly scheduled exception handling.
+ MWExceptionHandler::logException( $e2 );
+ }
}
// Allow extra cleanup and logging
- wfRunHooks( 'ApiMain::onException', array( $this, $e ) );
+ Hooks::run( 'ApiMain::onException', array( $this, $e ) );
// Log it
if ( !( $e instanceof UsageException ) ) {
@@ -421,9 +495,22 @@ class ApiMain extends ApiBase {
// Reset and print just the error message
ob_clean();
- // If the error occurred during printing, do a printer->profileOut()
- $this->mPrinter->safeProfileOut();
- $this->printResult( true );
+ // Printer may not be initialized if the extractRequestParams() fails for the main module
+ $this->createErrorPrinter();
+
+ try {
+ $this->printResult( true );
+ } catch ( UsageException $ex ) {
+ // The error printer itself is failing. Try suppressing its request
+ // parameters and redo.
+ $this->setWarning(
+ 'Error printer failed (will retry without params): ' . $ex->getMessage()
+ );
+ $this->mPrinter = null;
+ $this->createErrorPrinter();
+ $this->mPrinter->forceDefaultParams();
+ $this->printResult( true );
+ }
}
/**
@@ -434,6 +521,7 @@ class ApiMain extends ApiBase {
*
* @since 1.23
* @param Exception $e
+ * @throws Exception
*/
public static function handleApiBeforeMainException( Exception $e ) {
ob_start();
@@ -462,6 +550,8 @@ class ApiMain extends ApiBase {
* If the parameter and the header do match, the header is checked against $wgCrossSiteAJAXdomains
* and $wgCrossSiteAJAXdomainExceptions, and if the origin qualifies, the appropriate CORS
* headers are set.
+ * http://www.w3.org/TR/cors/#resource-requests
+ * http://www.w3.org/TR/cors/#resource-preflight-requests
*
* @return bool False if the caller should abort (403 case), true otherwise (all other cases)
*/
@@ -474,12 +564,14 @@ class ApiMain extends ApiBase {
$request = $this->getRequest();
$response = $request->response();
+
// Origin: header is a space-separated list of origins, check all of them
$originHeader = $request->getHeader( 'Origin' );
if ( $originHeader === false ) {
$origins = array();
} else {
- $origins = explode( ' ', $originHeader );
+ $originHeader = trim( $originHeader );
+ $origins = preg_split( '/\s+/', $originHeader );
}
if ( !in_array( $originParam, $origins ) ) {
@@ -494,18 +586,44 @@ class ApiMain extends ApiBase {
}
$config = $this->getConfig();
- $matchOrigin = self::matchOrigin(
+ $matchOrigin = count( $origins ) === 1 && self::matchOrigin(
$originParam,
$config->get( 'CrossSiteAJAXdomains' ),
$config->get( 'CrossSiteAJAXdomainExceptions' )
);
if ( $matchOrigin ) {
- $response->header( "Access-Control-Allow-Origin: $originParam" );
+ $requestedMethod = $request->getHeader( 'Access-Control-Request-Method' );
+ $preflight = $request->getMethod() === 'OPTIONS' && $requestedMethod !== false;
+ if ( $preflight ) {
+ // This is a CORS preflight request
+ if ( $requestedMethod !== 'POST' && $requestedMethod !== 'GET' ) {
+ // If method is not a case-sensitive match, do not set any additional headers and terminate.
+ return true;
+ }
+ // We allow the actual request to send the following headers
+ $requestedHeaders = $request->getHeader( 'Access-Control-Request-Headers' );
+ if ( $requestedHeaders !== false ) {
+ if ( !self::matchRequestedHeaders( $requestedHeaders ) ) {
+ return true;
+ }
+ $response->header( 'Access-Control-Allow-Headers: ' . $requestedHeaders );
+ }
+
+ // We only allow the actual request to be GET or POST
+ $response->header( 'Access-Control-Allow-Methods: POST, GET' );
+ }
+
+ $response->header( "Access-Control-Allow-Origin: $originHeader" );
$response->header( 'Access-Control-Allow-Credentials: true' );
- $this->getOutput()->addVaryHeader( 'Origin' );
+ $response->header( "Timing-Allow-Origin: $originHeader" ); # http://www.w3.org/TR/resource-timing/#timing-allow-origin
+
+ if ( !$preflight ) {
+ $response->header( 'Access-Control-Expose-Headers: MediaWiki-API-Error, Retry-After, X-Database-Lag' );
+ }
}
+ $this->getOutput()->addVaryHeader( 'Origin' );
return true;
}
@@ -535,6 +653,41 @@ class ApiMain extends ApiBase {
}
/**
+ * Attempt to validate the value of Access-Control-Request-Headers against a list
+ * of headers that we allow the follow up request to send.
+ *
+ * @param string $requestedHeaders Comma seperated list of HTTP headers
+ * @return bool True if all requested headers are in the list of allowed headers
+ */
+ protected static function matchRequestedHeaders( $requestedHeaders ) {
+ if ( trim( $requestedHeaders ) === '' ) {
+ return true;
+ }
+ $requestedHeaders = explode( ',', $requestedHeaders );
+ $allowedAuthorHeaders = array_flip( array(
+ /* simple headers (see spec) */
+ 'accept',
+ 'accept-language',
+ 'content-language',
+ 'content-type',
+ /* non-authorable headers in XHR, which are however requested by some UAs */
+ 'accept-encoding',
+ 'dnt',
+ 'origin',
+ /* MediaWiki whitelist */
+ 'api-user-agent',
+ ) );
+ foreach ( $requestedHeaders as $rHeader ) {
+ $rHeader = strtolower( trim( $rHeader ) );
+ if ( !isset( $allowedAuthorHeaders[$rHeader] ) ) {
+ wfDebugLog( 'api', 'CORS preflight failed on requested header: ' . $rHeader );
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
* Helper function to convert wildcard string into a regex
* '*' => '.*?'
* '?' => '.'
@@ -563,8 +716,24 @@ class ApiMain extends ApiBase {
$out->addVaryHeader( 'X-Forwarded-Proto' );
}
+ // The logic should be:
+ // $this->mCacheControl['max-age'] is set?
+ // Use it, the module knows better than our guess.
+ // !$this->mModule || $this->mModule->isWriteMode(), and mCacheMode is private?
+ // Use 0 because we can guess caching is probably the wrong thing to do.
+ // Use $this->getParameter( 'maxage' ), which already defaults to 0.
+ $maxage = 0;
+ if ( isset( $this->mCacheControl['max-age'] ) ) {
+ $maxage = $this->mCacheControl['max-age'];
+ } elseif ( ( $this->mModule && !$this->mModule->isWriteMode() ) ||
+ $this->mCacheMode !== 'private'
+ ) {
+ $maxage = $this->getParameter( 'maxage' );
+ }
+ $privateCache = 'private, must-revalidate, max-age=' . $maxage;
+
if ( $this->mCacheMode == 'private' ) {
- $response->header( 'Cache-Control: private' );
+ $response->header( "Cache-Control: $privateCache" );
return;
}
@@ -576,14 +745,14 @@ class ApiMain extends ApiBase {
$response->header( $out->getXVO() );
if ( $out->haveCacheVaryCookies() ) {
// Logged in, mark this request private
- $response->header( 'Cache-Control: private' );
+ $response->header( "Cache-Control: $privateCache" );
return;
}
// Logged out, send normal public headers below
} elseif ( session_id() != '' ) {
// Logged in or otherwise has session (e.g. anonymous users who have edited)
// Mark request private
- $response->header( 'Cache-Control: private' );
+ $response->header( "Cache-Control: $privateCache" );
return;
} // else no XVO and anonymous, send public headers below
@@ -607,7 +776,7 @@ class ApiMain extends ApiBase {
// Public cache not requested
// Sending a Vary header in this case is harmless, and protects us
// against conditional calls of setCacheMaxAge().
- $response->header( 'Cache-Control: private' );
+ $response->header( "Cache-Control: $privateCache" );
return;
}
@@ -638,45 +807,39 @@ class ApiMain extends ApiBase {
}
/**
- * Replace the result data with the information about an exception.
- * Returns the error code
- * @param Exception $e
- * @return string
+ * Create the printer for error output
*/
- protected function substituteResultWithError( $e ) {
- $result = $this->getResult();
-
- // Printer may not be initialized if the extractRequestParams() fails for the main module
+ private function createErrorPrinter() {
if ( !isset( $this->mPrinter ) ) {
- // The printer has not been created yet. Try to manually get formatter value.
$value = $this->getRequest()->getVal( 'format', self::API_DEFAULT_FORMAT );
if ( !$this->mModuleMgr->isDefined( $value, 'format' ) ) {
$value = self::API_DEFAULT_FORMAT;
}
-
$this->mPrinter = $this->createPrinterByName( $value );
}
// Printer may not be able to handle errors. This is particularly
// likely if the module returns something for getCustomPrinter().
if ( !$this->mPrinter->canPrintErrors() ) {
- $this->mPrinter->safeProfileOut();
$this->mPrinter = $this->createPrinterByName( self::API_DEFAULT_FORMAT );
}
+ }
- // Update raw mode flag for the selected printer.
- $result->setRawMode( $this->mPrinter->getNeedsRawData() );
-
+ /**
+ * Replace the result data with the information about an exception.
+ * Returns the error code
+ * @param Exception $e
+ * @return string
+ */
+ protected function substituteResultWithError( $e ) {
+ $result = $this->getResult();
$config = $this->getConfig();
if ( $e instanceof UsageException ) {
- // User entered incorrect parameters - print usage screen
+ // User entered incorrect parameters - generate error response
$errMessage = $e->getMessageArray();
-
- // Only print the help message when this is for the developer, not runtime
- if ( $this->mPrinter->getWantsHelp() || $this->mAction == 'help' ) {
- ApiResult::setContent( $errMessage, $this->makeHelpMsg() );
- }
+ $link = wfExpandUrl( wfScript( 'api' ) );
+ ApiResult::setContentValue( $errMessage, 'docref', "See $link for API usage" );
} else {
// Something is seriously wrong
if ( ( $e instanceof DBQueryError ) && !$config->get( 'ShowSQLErrors' ) ) {
@@ -687,17 +850,19 @@ class ApiMain extends ApiBase {
$errMessage = array(
'code' => 'internal_api_error_' . get_class( $e ),
- 'info' => $info,
- );
- ApiResult::setContent(
- $errMessage,
- $config->get( 'ShowExceptionDetails' ) ? "\n\n{$e->getTraceAsString()}\n\n" : ''
+ 'info' => '[' . MWExceptionHandler::getLogId( $e ) . '] ' . $info,
);
+ if ( $config->get( 'ShowExceptionDetails' ) ) {
+ ApiResult::setContentValue(
+ $errMessage,
+ 'trace',
+ MWExceptionHandler::getRedactedTraceAsString( $e )
+ );
+ }
}
// Remember all the warnings to re-add them later
- $oldResult = $result->getData();
- $warnings = isset( $oldResult['warnings'] ) ? $oldResult['warnings'] : null;
+ $warnings = $result->getResultData( array( 'warnings' ) );
$result->reset();
// Re-add the id
@@ -756,6 +921,8 @@ class ApiMain extends ApiBase {
/**
* Set up the module for response
* @return ApiBase The module that will handle this action
+ * @throws MWException
+ * @throws UsageException
*/
protected function setupModule() {
// Instantiate the module requested by the user
@@ -856,7 +1023,7 @@ class ApiMain extends ApiBase {
// Allow extensions to stop execution for arbitrary reasons.
$message = false;
- if ( !wfRunHooks( 'ApiCheckCanExecute', array( $module, $user, &$message ) ) ) {
+ if ( !Hooks::run( 'ApiCheckCanExecute', array( $module, $user, &$message ) ) ) {
$this->dieUsageMsg( $message );
}
}
@@ -928,10 +1095,8 @@ class ApiMain extends ApiBase {
$this->checkAsserts( $params );
// Execute
- $module->profileIn();
$module->execute();
- wfRunHooks( 'APIAfterExecute', array( &$module ) );
- $module->profileOut();
+ Hooks::run( 'APIAfterExecute', array( &$module ) );
$this->reportUnusedParams();
@@ -1080,23 +1245,10 @@ class ApiMain extends ApiBase {
$this->setWarning( 'SECURITY WARNING: $wgDebugAPI is enabled' );
}
- $this->getResult()->cleanUpUTF8();
$printer = $this->mPrinter;
- $printer->profileIn();
-
- /**
- * If the help message is requested in the default (xmlfm) format,
- * tell the printer not to escape ampersands so that our links do
- * not break.
- */
- $isHelp = $isError || $this->mAction == 'help';
- $printer->setUnescapeAmps( $isHelp && $printer->getFormat() == 'XML' && $printer->getIsHtml() );
-
- $printer->initPrinter( $isHelp );
-
+ $printer->initPrinter( false );
$printer->execute();
$printer->closePrinter();
- $printer->profileOut();
}
/**
@@ -1113,14 +1265,14 @@ class ApiMain extends ApiBase {
*/
public function getAllowedParams() {
return array(
- 'format' => array(
- ApiBase::PARAM_DFLT => ApiMain::API_DEFAULT_FORMAT,
- ApiBase::PARAM_TYPE => 'submodule',
- ),
'action' => array(
ApiBase::PARAM_DFLT => 'help',
ApiBase::PARAM_TYPE => 'submodule',
),
+ 'format' => array(
+ ApiBase::PARAM_DFLT => ApiMain::API_DEFAULT_FORMAT,
+ ApiBase::PARAM_TYPE => 'submodule',
+ ),
'maxlag' => array(
ApiBase::PARAM_TYPE => 'integer'
),
@@ -1139,126 +1291,136 @@ class ApiMain extends ApiBase {
'servedby' => false,
'curtimestamp' => false,
'origin' => null,
+ 'uselang' => array(
+ ApiBase::PARAM_DFLT => 'user',
+ ),
);
}
- /**
- * See ApiBase for description.
- *
- * @return array
- */
- public function getParamDescription() {
+ /** @see ApiBase::getExamplesMessages() */
+ protected function getExamplesMessages() {
return array(
- 'format' => 'The format of the output',
- 'action' => 'What action you would like to perform. See below for module help',
- 'maxlag' => array(
- 'Maximum lag can be used when MediaWiki is installed on a database replicated cluster.',
- 'To save actions causing any more site replication lag, this parameter can make the client',
- 'wait until the replication lag is less than the specified value.',
- 'In case of a replag error, error code "maxlag" is returned, with the message like',
- '"Waiting for $host: $lag seconds lagged\n".',
- 'See https://www.mediawiki.org/wiki/Manual:Maxlag_parameter for more information',
- ),
- 'smaxage' => 'Set the s-maxage header to this many seconds. Errors are never cached',
- 'maxage' => 'Set the max-age header to this many seconds. Errors are never cached',
- 'assert' => 'Verify the user is logged in if set to "user", or has the bot userright if "bot"',
- 'requestid' => 'Request ID to distinguish requests. This will just be output back to you',
- 'servedby' => 'Include the hostname that served the request in the ' .
- 'results. Unconditionally shown on error',
- 'curtimestamp' => 'Include the current timestamp in the result.',
- 'origin' => array(
- 'When accessing the API using a cross-domain AJAX request (CORS), set this to the',
- 'originating domain. This must be included in any pre-flight request, and',
- 'therefore must be part of the request URI (not the POST body). This must match',
- 'one of the origins in the Origin: header exactly, so it has to be set to ',
- 'something like http://en.wikipedia.org or https://meta.wikimedia.org . If this',
- 'parameter does not match the Origin: header, a 403 response will be returned. If',
- 'this parameter matches the Origin: header and the origin is whitelisted, an',
- 'Access-Control-Allow-Origin header will be set.',
- ),
+ 'action=help'
+ => 'apihelp-help-example-main',
+ 'action=help&recursivesubmodules=1'
+ => 'apihelp-help-example-recursive',
);
}
+ public function modifyHelp( array &$help, array $options ) {
+ // Wish PHP had an "array_insert_before". Instead, we have to manually
+ // reindex the array to get 'permissions' in the right place.
+ $oldHelp = $help;
+ $help = array();
+ foreach ( $oldHelp as $k => $v ) {
+ if ( $k === 'submodules' ) {
+ $help['permissions'] = '';
+ }
+ $help[$k] = $v;
+ }
+ $help['credits'] = '';
+
+ // Fill 'permissions'
+ $help['permissions'] .= Html::openElement( 'div',
+ array( 'class' => 'apihelp-block apihelp-permissions' ) );
+ $m = $this->msg( 'api-help-permissions' );
+ if ( !$m->isDisabled() ) {
+ $help['permissions'] .= Html::rawElement( 'div', array( 'class' => 'apihelp-block-head' ),
+ $m->numParams( count( self::$mRights ) )->parse()
+ );
+ }
+ $help['permissions'] .= Html::openElement( 'dl' );
+ foreach ( self::$mRights as $right => $rightMsg ) {
+ $help['permissions'] .= Html::element( 'dt', null, $right );
+
+ $rightMsg = $this->msg( $rightMsg['msg'], $rightMsg['params'] )->parse();
+ $help['permissions'] .= Html::rawElement( 'dd', null, $rightMsg );
+
+ $groups = array_map( function ( $group ) {
+ return $group == '*' ? 'all' : $group;
+ }, User::getGroupsWithPermission( $right ) );
+
+ $help['permissions'] .= Html::rawElement( 'dd', null,
+ $this->msg( 'api-help-permissions-granted-to' )
+ ->numParams( count( $groups ) )
+ ->params( $this->getLanguage()->commaList( $groups ) )
+ ->parse()
+ );
+ }
+ $help['permissions'] .= Html::closeElement( 'dl' );
+ $help['permissions'] .= Html::closeElement( 'div' );
+
+ // Fill 'credits', if applicable
+ if ( empty( $options['nolead'] ) ) {
+ $help['credits'] .= Html::element( 'h' . min( 6, $options['headerlevel'] + 1 ),
+ array( 'id' => '+credits', 'class' => 'apihelp-header' ),
+ $this->msg( 'api-credits-header' )->parse()
+ );
+ $help['credits'] .= $this->msg( 'api-credits' )->useDatabase( false )->parseAsBlock();
+ }
+ }
+
+ private $mCanApiHighLimits = null;
+
/**
- * See ApiBase for description.
- *
- * @return array
+ * Check whether the current user is allowed to use high limits
+ * @return bool
*/
- public function getDescription() {
- return array(
- '',
- '',
- '**********************************************************************************************',
- '** **',
- '** This is an auto-generated MediaWiki API documentation page **',
- '** **',
- '** Documentation and Examples: **',
- '** https://www.mediawiki.org/wiki/API **',
- '** **',
- '**********************************************************************************************',
- '',
- 'Status: All features shown on this page should be working, but the API',
- ' is still in active development, and may change at any time.',
- ' Make sure to monitor our mailing list for any updates.',
- '',
- 'Erroneous requests: When erroneous requests are sent to the API, a HTTP header will be sent',
- ' with the key "MediaWiki-API-Error" and then both the value of the',
- ' header and the error code sent back will be set to the same value.',
- '',
- ' In the case of an invalid action being passed, these will have a value',
- ' of "unknown_action".',
- '',
- ' For more information see https://www.mediawiki.org' .
- '/wiki/API:Errors_and_warnings',
- '',
- 'Documentation: https://www.mediawiki.org/wiki/API:Main_page',
- 'FAQ https://www.mediawiki.org/wiki/API:FAQ',
- 'Mailing list: https://lists.wikimedia.org/mailman/listinfo/mediawiki-api',
- 'Api Announcements: https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce',
- 'Bugs & Requests: https://bugzilla.wikimedia.org/buglist.cgi?component=API&' .
- 'bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&order=bugs.delta_ts',
- '',
- '',
- '',
- '',
- '',
- );
+ public function canApiHighLimits() {
+ if ( !isset( $this->mCanApiHighLimits ) ) {
+ $this->mCanApiHighLimits = $this->getUser()->isAllowed( 'apihighlimits' );
+ }
+
+ return $this->mCanApiHighLimits;
}
/**
- * Returns an array of strings with credits for the API
- * @return array
+ * Overrides to return this instance's module manager.
+ * @return ApiModuleManager
*/
- protected function getCredits() {
- return array(
- 'API developers:',
- ' Roan Kattouw (lead developer Sep 2007-2009)',
- ' Victor Vasiliev',
- ' Bryan Tong Minh',
- ' Sam Reed',
- ' Yuri Astrakhan (creator, lead developer Sep 2006-Sep 2007, 2012-2013)',
- ' Brad Jorsch (lead developer 2013-now)',
- '',
- 'Please send your comments, suggestions and questions to mediawiki-api@lists.wikimedia.org',
- 'or file a bug report at https://bugzilla.wikimedia.org/'
+ public function getModuleManager() {
+ return $this->mModuleMgr;
+ }
+
+ /**
+ * Fetches the user agent used for this request
+ *
+ * The value will be the combination of the 'Api-User-Agent' header (if
+ * any) and the standard User-Agent header (if any).
+ *
+ * @return string
+ */
+ public function getUserAgent() {
+ return trim(
+ $this->getRequest()->getHeader( 'Api-user-agent' ) . ' ' .
+ $this->getRequest()->getHeader( 'User-agent' )
);
}
+ /************************************************************************//**
+ * @name Deprecated
+ * @{
+ */
+
/**
* Sets whether the pretty-printer should format *bold* and $italics$
*
+ * @deprecated since 1.25
* @param bool $help
*/
public function setHelp( $help = true ) {
+ wfDeprecated( __METHOD__, '1.25' );
$this->mPrinter->setHelp( $help );
}
/**
* Override the parent to generate help messages for all available modules.
*
+ * @deprecated since 1.25
* @return string
*/
public function makeHelpMsg() {
+ wfDeprecated( __METHOD__, '1.25' );
global $wgMemc;
$this->setHelp();
// Get help text from cache if present
@@ -1281,9 +1443,11 @@ class ApiMain extends ApiBase {
}
/**
+ * @deprecated since 1.25
* @return mixed|string
*/
public function reallyMakeHelpMsg() {
+ wfDeprecated( __METHOD__, '1.25' );
$this->setHelp();
// Use parent to make default message for the main module
@@ -1305,8 +1469,12 @@ class ApiMain extends ApiBase {
$msg .= "\n$astriks Permissions $astriks\n\n";
foreach ( self::$mRights as $right => $rightMsg ) {
+ $rightsMsg = $this->msg( $rightMsg['msg'], $rightMsg['params'] )
+ ->useDatabase( false )
+ ->inLanguage( 'en' )
+ ->text();
$groups = User::getGroupsWithPermission( $right );
- $msg .= "* " . $right . " *\n " . wfMsgReplaceArgs( $rightMsg['msg'], $rightMsg['params'] ) .
+ $msg .= "* " . $right . " *\n $rightsMsg" .
"\nGranted to:\n " . str_replace( '*', 'all', implode( ', ', $groups ) ) . "\n\n";
}
@@ -1321,18 +1489,22 @@ class ApiMain extends ApiBase {
$msg .= "\n";
}
- $msg .= "\n*** Credits: ***\n " . implode( "\n ", $this->getCredits() ) . "\n";
+ $credits = $this->msg( 'api-credits' )->useDatabase( 'false' )->inLanguage( 'en' )->text();
+ $credits = str_replace( "\n", "\n ", $credits );
+ $msg .= "\n*** Credits: ***\n $credits\n";
return $msg;
}
/**
+ * @deprecated since 1.25
* @param ApiBase $module
* @param string $paramName What type of request is this? e.g. action,
* query, list, prop, meta, format
* @return string
*/
public static function makeHelpMsgHeader( $module, $paramName ) {
+ wfDeprecated( __METHOD__, '1.25' );
$modulePrefix = $module->getModulePrefix();
if ( strval( $modulePrefix ) !== '' ) {
$modulePrefix = "($modulePrefix) ";
@@ -1341,20 +1513,6 @@ class ApiMain extends ApiBase {
return "* $paramName={$module->getModuleName()} $modulePrefix*";
}
- private $mCanApiHighLimits = null;
-
- /**
- * Check whether the current user is allowed to use high limits
- * @return bool
- */
- public function canApiHighLimits() {
- if ( !isset( $this->mCanApiHighLimits ) ) {
- $this->mCanApiHighLimits = $this->getUser()->isAllowed( 'apihighlimits' );
- }
-
- return $this->mCanApiHighLimits;
- }
-
/**
* Check whether the user wants us to show version information in the API help
* @return bool
@@ -1367,14 +1525,6 @@ class ApiMain extends ApiBase {
}
/**
- * Overrides to return this instance's module manager.
- * @return ApiModuleManager
- */
- public function getModuleManager() {
- return $this->mModuleMgr;
- }
-
- /**
* Add or overwrite a module in this ApiMain instance. Intended for use by extending
* classes who wish to add their own modules to their lexicon or override the
* behavior of inherent ones.
@@ -1418,11 +1568,13 @@ class ApiMain extends ApiBase {
public function getFormats() {
return $this->getModuleManager()->getNamesWithClasses( 'format' );
}
+
+ /**@}*/
+
}
/**
* This exception will be thrown when dieUsage is called to stop module execution.
- * The exception handling code will print a help screen explaining how this API may be used.
*
* @ingroup API
*/
@@ -1476,3 +1628,8 @@ class UsageException extends MWException {
return "{$this->getCodeString()}: {$this->getMessage()}";
}
}
+
+/**
+ * For really cool vim folding this needs to be at the end:
+ * vim: foldmarker=@{,@} foldmethod=marker
+ */
diff --git a/includes/api/ApiManageTags.php b/includes/api/ApiManageTags.php
new file mode 100644
index 00000000..240d3506
--- /dev/null
+++ b/includes/api/ApiManageTags.php
@@ -0,0 +1,107 @@
+<?php
+
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * @ingroup API
+ * @since 1.25
+ */
+class ApiManageTags extends ApiBase {
+
+ public function execute() {
+ $params = $this->extractRequestParams();
+
+ // make sure the user is allowed
+ if ( !$this->getUser()->isAllowed( 'managechangetags' ) ) {
+ $this->dieUsage( "You don't have permission to manage change tags", 'permissiondenied' );
+ }
+
+ $result = $this->getResult();
+ $funcName = "{$params['operation']}TagWithChecks";
+ $status = ChangeTags::$funcName( $params['tag'], $params['reason'],
+ $this->getUser(), $params['ignorewarnings'] );
+
+ if ( !$status->isOK() ) {
+ $this->dieStatus( $status );
+ }
+
+ $ret = array(
+ 'operation' => $params['operation'],
+ 'tag' => $params['tag'],
+ );
+ if ( !$status->isGood() ) {
+ $ret['warnings'] = $this->getErrorFormatter()->arrayFromStatus( $status, 'warning' );
+ }
+ $ret['success'] = $status->value !== null;
+ if ( $ret['success'] ) {
+ $ret['logid'] = $status->value;
+ }
+ $result->addValue( null, $this->getModuleName(), $ret );
+ }
+
+ public function mustBePosted() {
+ return true;
+ }
+
+ public function isWriteMode() {
+ return true;
+ }
+
+ public function getAllowedParams() {
+ return array(
+ 'operation' => array(
+ ApiBase::PARAM_TYPE => array( 'create', 'delete', 'activate', 'deactivate' ),
+ ApiBase::PARAM_REQUIRED => true,
+ ),
+ 'tag' => array(
+ ApiBase::PARAM_TYPE => 'string',
+ ApiBase::PARAM_REQUIRED => true,
+ ),
+ 'reason' => array(
+ ApiBase::PARAM_TYPE => 'string',
+ ),
+ 'ignorewarnings' => array(
+ ApiBase::PARAM_TYPE => 'boolean',
+ ApiBase::PARAM_DFLT => false,
+ ),
+ );
+ }
+
+ public function needsToken() {
+ return 'csrf';
+ }
+
+ protected function getExamplesMessages() {
+ return array(
+ 'action=managetags&operation=create&tag=spam&reason=For+use+in+edit+patrolling&token=123ABC'
+ => 'apihelp-managetags-example-create',
+ 'action=managetags&operation=delete&tag=vandlaism&reason=Misspelt&token=123ABC'
+ => 'apihelp-managetags-example-delete',
+ 'action=managetags&operation=activate&tag=spam&reason=For+use+in+edit+patrolling&token=123ABC'
+ => 'apihelp-managetags-example-activate',
+ 'action=managetags&operation=deactivate&tag=spam&reason=No+longer+required&token=123ABC'
+ => 'apihelp-managetags-example-deactivate',
+ );
+ }
+
+ public function getHelpUrls() {
+ return 'https://www.mediawiki.org/wiki/API:Tag_management';
+ }
+}
diff --git a/includes/api/ApiMessage.php b/includes/api/ApiMessage.php
new file mode 100644
index 00000000..6717c390
--- /dev/null
+++ b/includes/api/ApiMessage.php
@@ -0,0 +1,191 @@
+<?php
+/**
+ * Defines an interface for messages with additional machine-readable data for
+ * use by the API, and provides concrete implementations of that interface.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * Interface for messages with machine-readable data for use by the API
+ * @since 1.25
+ * @ingroup API
+ */
+interface IApiMessage extends MessageSpecifier {
+ /**
+ * Returns a machine-readable code for use by the API
+ *
+ * The message key is often sufficient, but sometimes there are multiple
+ * messages used for what is really the same underlying condition (e.g.
+ * badaccess-groups and badaccess-group0)
+ * @return string
+ */
+ public function getApiCode();
+
+ /**
+ * Returns additional machine-readable data about the error condition
+ * @return array
+ */
+ public function getApiData();
+
+ /**
+ * Sets the machine-readable code for use by the API
+ * @param string|null $code If null, the message key should be returned by self::getApiCode()
+ * @param array|null $data If non-null, passed to self::setApiData()
+ */
+ public function setApiCode( $code, array $data = null );
+
+ /**
+ * Sets additional machine-readable data about the error condition
+ * @param array $data
+ */
+ public function setApiData( array $data );
+}
+
+/**
+ * Extension of Message implementing IApiMessage
+ * @since 1.25
+ * @ingroup API
+ * @todo: Would be nice to use a Trait here to avoid code duplication
+ */
+class ApiMessage extends Message implements IApiMessage {
+ protected $apiCode = null;
+ protected $apiData = array();
+
+ /**
+ * Create an IApiMessage for the message
+ *
+ * This returns $msg if it's an IApiMessage, calls 'new ApiRawMessage' if
+ * $msg is a RawMessage, or calls 'new ApiMessage' in all other cases.
+ *
+ * @param Message|RawMessage|array|string $msg
+ * @param string|null $code
+ * @param array|null $data
+ * @return ApiMessage
+ */
+ public static function create( $msg, $code = null, array $data = null ) {
+ if ( $msg instanceof IApiMessage ) {
+ return $msg;
+ } elseif ( $msg instanceof RawMessage ) {
+ return new ApiRawMessage( $msg, $code, $data );
+ } else {
+ return new ApiMessage( $msg, $code, $data );
+ }
+ }
+
+ /**
+ * @param Message|string|array $msg
+ * - Message: is cloned
+ * - array: first element is $key, rest are $params to Message::__construct
+ * - string: passed to Message::__construct
+ * @param string|null $code
+ * @param array|null $data
+ * @return ApiMessage
+ */
+ public function __construct( $msg, $code = null, array $data = null ) {
+ if ( $msg instanceof Message ) {
+ foreach ( get_class_vars( get_class( $this ) ) as $key => $value ) {
+ if ( isset( $msg->$key ) ) {
+ $this->$key = $msg->$key;
+ }
+ }
+ } elseif ( is_array( $msg ) ) {
+ $key = array_shift( $msg );
+ parent::__construct( $key, $msg );
+ } else {
+ parent::__construct( $msg );
+ }
+ $this->apiCode = $code;
+ $this->apiData = (array)$data;
+ }
+
+ public function getApiCode() {
+ return $this->apiCode === null ? $this->getKey() : $this->apiCode;
+ }
+
+ public function setApiCode( $code, array $data = null ) {
+ $this->apiCode = $code;
+ if ( $data !== null ) {
+ $this->setApiData( $data );
+ }
+ }
+
+ public function getApiData() {
+ return $this->apiData;
+ }
+
+ public function setApiData( array $data ) {
+ $this->apiData = $data;
+ }
+}
+
+/**
+ * Extension of RawMessage implementing IApiMessage
+ * @since 1.25
+ * @ingroup API
+ * @todo: Would be nice to use a Trait here to avoid code duplication
+ */
+class ApiRawMessage extends RawMessage implements IApiMessage {
+ protected $apiCode = null;
+ protected $apiData = array();
+
+ /**
+ * @param RawMessage|string|array $msg
+ * - RawMessage: is cloned
+ * - array: first element is $key, rest are $params to RawMessage::__construct
+ * - string: passed to RawMessage::__construct
+ * @param string|null $code
+ * @param array|null $data
+ * @return ApiMessage
+ */
+ public function __construct( $msg, $code = null, array $data = null ) {
+ if ( $msg instanceof RawMessage ) {
+ foreach ( get_class_vars( get_class( $this ) ) as $key => $value ) {
+ if ( isset( $msg->$key ) ) {
+ $this->$key = $msg->$key;
+ }
+ }
+ } elseif ( is_array( $msg ) ) {
+ $key = array_shift( $msg );
+ parent::__construct( $key, $msg );
+ } else {
+ parent::__construct( $msg );
+ }
+ $this->apiCode = $code;
+ $this->apiData = (array)$data;
+ }
+
+ public function getApiCode() {
+ return $this->apiCode === null ? $this->getKey() : $this->apiCode;
+ }
+
+ public function setApiCode( $code, array $data = null ) {
+ $this->apiCode = $code;
+ if ( $data !== null ) {
+ $this->setApiData( $data );
+ }
+ }
+
+ public function getApiData() {
+ return $this->apiData;
+ }
+
+ public function setApiData( array $data ) {
+ $this->apiData = $data;
+ }
+}
diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php
index 04e931d2..e42958bf 100644
--- a/includes/api/ApiMove.php
+++ b/includes/api/ApiMove.php
@@ -72,9 +72,9 @@ class ApiMove extends ApiBase {
// Move the page
$toTitleExists = $toTitle->exists();
- $retval = $fromTitle->moveTo( $toTitle, true, $params['reason'], !$params['noredirect'] );
- if ( $retval !== true ) {
- $this->dieUsageMsg( reset( $retval ) );
+ $status = $this->movePage( $fromTitle, $toTitle, $params['reason'], !$params['noredirect'] );
+ if ( !$status->isOK() ) {
+ $this->dieStatus( $status );
}
$r = array(
@@ -83,34 +83,28 @@ class ApiMove extends ApiBase {
'reason' => $params['reason']
);
- if ( $fromTitle->exists() ) {
- //NOTE: we assume that if the old title exists, it's because it was re-created as
- // a redirect to the new title. This is not safe, but what we did before was
- // even worse: we just determined whether a redirect should have been created,
- // and reported that it was created if it should have, without any checks.
- // Also note that isRedirect() is unreliable because of bug 37209.
- $r['redirectcreated'] = '';
- }
+ //NOTE: we assume that if the old title exists, it's because it was re-created as
+ // a redirect to the new title. This is not safe, but what we did before was
+ // even worse: we just determined whether a redirect should have been created,
+ // and reported that it was created if it should have, without any checks.
+ // Also note that isRedirect() is unreliable because of bug 37209.
+ $r['redirectcreated'] = $fromTitle->exists();
- if ( $toTitleExists ) {
- $r['moveoverredirect'] = '';
- }
+ $r['moveoverredirect'] = $toTitleExists;
// Move the talk page
if ( $params['movetalk'] && $fromTalk->exists() && !$fromTitle->isTalkPage() ) {
$toTalkExists = $toTalk->exists();
- $retval = $fromTalk->moveTo( $toTalk, true, $params['reason'], !$params['noredirect'] );
- if ( $retval === true ) {
+ $status = $this->movePage( $fromTalk, $toTalk, $params['reason'], !$params['noredirect'] );
+ if ( $status->isOK() ) {
$r['talkfrom'] = $fromTalk->getPrefixedText();
$r['talkto'] = $toTalk->getPrefixedText();
- if ( $toTalkExists ) {
- $r['talkmoveoverredirect'] = '';
- }
+ $r['talkmoveoverredirect'] = $toTalkExists;
} else {
// We're not gonna dieUsage() on failure, since we already changed something
- $parsed = $this->parseMsg( reset( $retval ) );
- $r['talkmove-error-code'] = $parsed['code'];
- $r['talkmove-error-info'] = $parsed['info'];
+ $error = $this->getErrorFromStatus( $status );
+ $r['talkmove-error-code'] = $error[0];
+ $r['talkmove-error-info'] = $error[1];
}
}
@@ -120,12 +114,12 @@ class ApiMove extends ApiBase {
if ( $params['movesubpages'] ) {
$r['subpages'] = $this->moveSubpages( $fromTitle, $toTitle,
$params['reason'], $params['noredirect'] );
- $result->setIndexedTagName( $r['subpages'], 'subpage' );
+ ApiResult::setIndexedTagName( $r['subpages'], 'subpage' );
if ( $params['movetalk'] ) {
$r['subpages-talk'] = $this->moveSubpages( $fromTalk, $toTalk,
$params['reason'], $params['noredirect'] );
- $result->setIndexedTagName( $r['subpages-talk'], 'subpage' );
+ ApiResult::setIndexedTagName( $r['subpages-talk'], 'subpage' );
}
}
@@ -148,6 +142,33 @@ class ApiMove extends ApiBase {
}
/**
+ * @param Title $from
+ * @param Title $to
+ * @param string $reason
+ * @param bool $createRedirect
+ * @return Status
+ */
+ protected function movePage( Title $from, Title $to, $reason, $createRedirect ) {
+ $mp = new MovePage( $from, $to );
+ $valid = $mp->isValidMove();
+ if ( !$valid->isOK() ) {
+ return $valid;
+ }
+
+ $permStatus = $mp->checkPermissions( $this->getUser(), $reason );
+ if ( !$permStatus->isOK() ) {
+ return $permStatus;
+ }
+
+ // Check suppressredirect permission
+ if ( !$this->getUser()->isAllowed( 'suppressredirect' ) ) {
+ $createRedirect = true;
+ }
+
+ return $mp->move( $this->getUser(), $reason, $createRedirect );
+ }
+
+ /**
* @param Title $fromTitle
* @param Title $toTitle
* @param string $reason
@@ -220,37 +241,15 @@ class ApiMove extends ApiBase {
);
}
- public function getParamDescription() {
- $p = $this->getModulePrefix();
-
- return array(
- 'from' => "Title of the page you want to move. Cannot be used together with {$p}fromid",
- 'fromid' => "Page ID of the page you want to move. Cannot be used together with {$p}from",
- 'to' => 'Title you want to rename the page to',
- 'reason' => 'Reason for the move',
- 'movetalk' => 'Move the talk page, if it exists',
- 'movesubpages' => 'Move subpages, if applicable',
- 'noredirect' => 'Don\'t create a redirect',
- 'watch' => 'Add the page and the redirect to your watchlist',
- 'unwatch' => 'Remove the page and the redirect from your watchlist',
- 'watchlist' => 'Unconditionally add or remove the page from your ' .
- 'watchlist, use preferences or do not change watch',
- 'ignorewarnings' => 'Ignore any warnings'
- );
- }
-
- public function getDescription() {
- return 'Move a page.';
- }
-
public function needsToken() {
return 'csrf';
}
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=move&from=Badtitle&to=Goodtitle&token=123ABC&' .
+ 'action=move&from=Badtitle&to=Goodtitle&token=123ABC&' .
'reason=Misspelled%20title&movetalk=&noredirect='
+ => 'apihelp-move-example-move',
);
}
diff --git a/includes/api/ApiOpenSearch.php b/includes/api/ApiOpenSearch.php
index 7fb045e3..a93b7cc6 100644
--- a/includes/api/ApiOpenSearch.php
+++ b/includes/api/ApiOpenSearch.php
@@ -3,6 +3,8 @@
* Created on Oct 13, 2006
*
* Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
+ * Copyright © 2008 Brion Vibber <brion@wikimedia.org>
+ * Copyright © 2014 Brad Jorsch <bjorsch@wikimedia.org>
*
* 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
@@ -27,21 +29,50 @@
*/
class ApiOpenSearch extends ApiBase {
+ private $format = null;
+ private $fm = null;
+
/**
- * Override built-in handling of format parameter.
- * Only JSON is supported.
+ * Get the output format
*
- * @return ApiFormatBase
+ * @return string
*/
- public function getCustomPrinter() {
- $params = $this->extractRequestParams();
- $format = $params['format'];
- $allowed = array( 'json', 'jsonfm' );
- if ( in_array( $format, $allowed ) ) {
- return $this->getMain()->createPrinterByName( $format );
+ protected function getFormat() {
+ if ( $this->format === null ) {
+ $params = $this->extractRequestParams();
+ $format = $params['format'];
+
+ $allowedParams = $this->getAllowedParams();
+ if ( !in_array( $format, $allowedParams['format'][ApiBase::PARAM_TYPE] ) ) {
+ $format = $allowedParams['format'][ApiBase::PARAM_DFLT];
+ }
+
+ if ( substr( $format, -2 ) === 'fm' ) {
+ $this->format = substr( $format, 0, -2 );
+ $this->fm = 'fm';
+ } else {
+ $this->format = $format;
+ $this->fm = '';
+ }
}
+ return $this->format;
+ }
+
+ public function getCustomPrinter() {
+ switch ( $this->getFormat() ) {
+ case 'json':
+ return new ApiOpenSearchFormatJson(
+ $this->getMain(), $this->fm, $this->getParameter( 'warningsaserror' )
+ );
+
+ case 'xml':
+ $printer = $this->getMain()->createPrinterByName( 'xml' . $this->fm );
+ $printer->setRootElement( 'SearchSuggestion' );
+ return $printer;
- return $this->getMain()->createPrinterByName( $allowed[0] );
+ default:
+ ApiBase::dieDebug( __METHOD__, "Unsupported format '{$this->getFormat()}'" );
+ }
}
public function execute() {
@@ -51,21 +82,188 @@ class ApiOpenSearch extends ApiBase {
$namespaces = $params['namespace'];
$suggest = $params['suggest'];
- // Some script that was loaded regardless of wgEnableOpenSearchSuggest, likely cached.
- if ( $suggest && !$this->getConfig()->get( 'EnableOpenSearchSuggest' ) ) {
- $searches = array();
+ if ( $params['redirects'] === null ) {
+ // Backwards compatibility, don't resolve for JSON.
+ $resolveRedir = $this->getFormat() !== 'json';
} else {
+ $resolveRedir = $params['redirects'] === 'resolve';
+ }
+
+ $results = array();
+
+ if ( !$suggest || $this->getConfig()->get( 'EnableOpenSearchSuggest' ) ) {
// Open search results may be stored for a very long time
$this->getMain()->setCacheMaxAge( $this->getConfig()->get( 'SearchSuggestCacheExpiry' ) );
$this->getMain()->setCacheMode( 'public' );
+ $this->search( $search, $limit, $namespaces, $resolveRedir, $results );
+
+ // Allow hooks to populate extracts and images
+ Hooks::run( 'ApiOpenSearchSuggest', array( &$results ) );
+
+ // Trim extracts, if necessary
+ $length = $this->getConfig()->get( 'OpenSearchDescriptionLength' );
+ foreach ( $results as &$r ) {
+ if ( is_string( $r['extract'] ) && !$r['extract trimmed'] ) {
+ $r['extract'] = self::trimExtract( $r['extract'], $length );
+ }
+ }
+ }
+
+ // Populate result object
+ $this->populateResult( $search, $results );
+ }
- $searcher = new StringPrefixSearch;
- $searches = $searcher->searchWithVariants( $search, $limit, $namespaces );
+ /**
+ * Perform the search
+ *
+ * @param string $search Text to search
+ * @param int $limit Maximum items to return
+ * @param array $namespaces Namespaces to search
+ * @param bool $resolveRedir Whether to resolve redirects
+ * @param array &$results Put results here. Keys have to be integers.
+ */
+ protected function search( $search, $limit, $namespaces, $resolveRedir, &$results ) {
+ // Find matching titles as Title objects
+ $searcher = new TitlePrefixSearch;
+ $titles = $searcher->searchWithVariants( $search, $limit, $namespaces );
+ if ( !$titles ) {
+ return;
}
- // Set top level elements
+
+ // Special pages need unique integer ids in the return list, so we just
+ // assign them negative numbers because those won't clash with the
+ // always positive articleIds that non-special pages get.
+ $nextSpecialPageId = -1;
+
+ if ( $resolveRedir ) {
+ // Query for redirects
+ $redirects = array();
+ $lb = new LinkBatch( $titles );
+ if ( !$lb->isEmpty() ) {
+ $db = $this->getDb();
+ $res = $db->select(
+ array( 'page', 'redirect' ),
+ array( 'page_namespace', 'page_title', 'rd_namespace', 'rd_title' ),
+ array(
+ 'rd_from = page_id',
+ 'rd_interwiki IS NULL OR rd_interwiki = ' . $db->addQuotes( '' ),
+ $lb->constructSet( 'page', $db ),
+ ),
+ __METHOD__
+ );
+ foreach ( $res as $row ) {
+ $redirects[$row->page_namespace][$row->page_title] =
+ array( $row->rd_namespace, $row->rd_title );
+ }
+ }
+
+ // Bypass any redirects
+ $seen = array();
+ foreach ( $titles as $title ) {
+ $ns = $title->getNamespace();
+ $dbkey = $title->getDBkey();
+ $from = null;
+ if ( isset( $redirects[$ns][$dbkey] ) ) {
+ list( $ns, $dbkey ) = $redirects[$ns][$dbkey];
+ $from = $title;
+ $title = Title::makeTitle( $ns, $dbkey );
+ }
+ if ( !isset( $seen[$ns][$dbkey] ) ) {
+ $seen[$ns][$dbkey] = true;
+ $resultId = $title->getArticleId();
+ if ( $resultId === 0 ) {
+ $resultId = $nextSpecialPageId;
+ $nextSpecialPageId -= 1;
+ }
+ $results[$resultId] = array(
+ 'title' => $title,
+ 'redirect from' => $from,
+ 'extract' => false,
+ 'extract trimmed' => false,
+ 'image' => false,
+ 'url' => wfExpandUrl( $title->getFullUrl(), PROTO_CURRENT ),
+ );
+ }
+ }
+ } else {
+ foreach ( $titles as $title ) {
+ $resultId = $title->getArticleId();
+ if ( $resultId === 0 ) {
+ $resultId = $nextSpecialPageId;
+ $nextSpecialPageId -= 1;
+ }
+ $results[$resultId] = array(
+ 'title' => $title,
+ 'redirect from' => null,
+ 'extract' => false,
+ 'extract trimmed' => false,
+ 'image' => false,
+ 'url' => wfExpandUrl( $title->getFullUrl(), PROTO_CURRENT ),
+ );
+ }
+ }
+ }
+
+ /**
+ * @param string $search
+ * @param array &$results
+ */
+ protected function populateResult( $search, &$results ) {
$result = $this->getResult();
- $result->addValue( null, 0, $search );
- $result->addValue( null, 1, $searches );
+
+ switch ( $this->getFormat() ) {
+ case 'json':
+ // http://www.opensearch.org/Specifications/OpenSearch/Extensions/Suggestions/1.1
+ $result->addArrayType( null, 'array' );
+ $result->addValue( null, 0, strval( $search ) );
+ $terms = array();
+ $descriptions = array();
+ $urls = array();
+ foreach ( $results as $r ) {
+ $terms[] = $r['title']->getPrefixedText();
+ $descriptions[] = strval( $r['extract'] );
+ $urls[] = $r['url'];
+ }
+ $result->addValue( null, 1, $terms );
+ $result->addValue( null, 2, $descriptions );
+ $result->addValue( null, 3, $urls );
+ break;
+
+ case 'xml':
+ // http://msdn.microsoft.com/en-us/library/cc891508%28v=vs.85%29.aspx
+ $imageKeys = array(
+ 'source' => true,
+ 'alt' => true,
+ 'width' => true,
+ 'height' => true,
+ 'align' => true,
+ );
+ $items = array();
+ foreach ( $results as $r ) {
+ $item = array(
+ 'Text' => $r['title']->getPrefixedText(),
+ 'Url' => $r['url'],
+ );
+ if ( is_string( $r['extract'] ) && $r['extract'] !== '' ) {
+ $item['Description'] = $r['extract'];
+ }
+ if ( is_array( $r['image'] ) && isset( $r['image']['source'] ) ) {
+ $item['Image'] = array_intersect_key( $r['image'], $imageKeys );
+ }
+ ApiResult::setSubelementsList( $item, array_keys( $item ) );
+ $items[] = $item;
+ }
+ ApiResult::setIndexedTagName( $items, 'Item' );
+ $result->addValue( null, 'version', '2.0' );
+ $result->addValue( null, 'xmlns', 'http://opensearch.org/searchsuggest2' );
+ $result->addValue( null, 'Query', strval( $search ) );
+ $result->addSubelementsList( null, 'Query' );
+ $result->addValue( null, 'Section', $items );
+ break;
+
+ default:
+ ApiBase::dieDebug( __METHOD__, "Unsupported format '{$this->getFormat()}'" );
+ }
}
public function getAllowedParams() {
@@ -84,34 +282,117 @@ class ApiOpenSearch extends ApiBase {
ApiBase::PARAM_ISMULTI => true
),
'suggest' => false,
+ 'redirects' => array(
+ ApiBase::PARAM_TYPE => array( 'return', 'resolve' ),
+ ),
'format' => array(
ApiBase::PARAM_DFLT => 'json',
- ApiBase::PARAM_TYPE => array( 'json', 'jsonfm' ),
- )
+ ApiBase::PARAM_TYPE => array( 'json', 'jsonfm', 'xml', 'xmlfm' ),
+ ),
+ 'warningsaserror' => false,
);
}
- public function getParamDescription() {
+ protected function getExamplesMessages() {
return array(
- 'search' => 'Search string',
- 'limit' => 'Maximum amount of results to return',
- 'namespace' => 'Namespaces to search',
- 'suggest' => 'Do nothing if $wgEnableOpenSearchSuggest is false',
- 'format' => 'The format of the output',
+ 'action=opensearch&search=Te'
+ => 'apihelp-opensearch-example-te',
);
}
- public function getDescription() {
- return 'Search the wiki using the OpenSearch protocol.';
+ public function getHelpUrls() {
+ return 'https://www.mediawiki.org/wiki/API:Opensearch';
}
- public function getExamples() {
- return array(
- 'api.php?action=opensearch&search=Te'
- );
+ /**
+ * Trim an extract to a sensible length.
+ *
+ * Adapted from Extension:OpenSearchXml, which adapted it from
+ * Extension:ActiveAbstract.
+ *
+ * @param string $text
+ * @param int $len Target length; actual result will continue to the end of a sentence.
+ * @return string
+ */
+ public static function trimExtract( $text, $length ) {
+ static $regex = null;
+
+ if ( $regex === null ) {
+ $endchars = array(
+ '([^\d])\.\s', '\!\s', '\?\s', // regular ASCII
+ '。', // full-width ideographic full-stop
+ '.', '!', '?', // double-width roman forms
+ '。', // half-width ideographic full stop
+ );
+ $endgroup = implode( '|', $endchars );
+ $end = "(?:$endgroup)";
+ $sentence = ".{{$length},}?$end+";
+ $regex = "/^($sentence)/u";
+ }
+
+ $matches = array();
+ if ( preg_match( $regex, $text, $matches ) ) {
+ return trim( $matches[1] );
+ } else {
+ // Just return the first line
+ $lines = explode( "\n", $text );
+ return trim( $lines[0] );
+ }
}
- public function getHelpUrls() {
- return 'https://www.mediawiki.org/wiki/API:Opensearch';
+ /**
+ * Fetch the template for a type.
+ *
+ * @param string $type MIME type
+ * @return string
+ * @throws MWException
+ */
+ public static function getOpenSearchTemplate( $type ) {
+ global $wgOpenSearchTemplate, $wgCanonicalServer;
+
+ if ( $wgOpenSearchTemplate && $type === 'application/x-suggestions+json' ) {
+ return $wgOpenSearchTemplate;
+ }
+
+ $ns = implode( '|', SearchEngine::defaultNamespaces() );
+ if ( !$ns ) {
+ $ns = "0";
+ }
+
+ switch ( $type ) {
+ case 'application/x-suggestions+json':
+ return $wgCanonicalServer . wfScript( 'api' )
+ . '?action=opensearch&search={searchTerms}&namespace=' . $ns;
+
+ case 'application/x-suggestions+xml':
+ return $wgCanonicalServer . wfScript( 'api' )
+ . '?action=opensearch&format=xml&search={searchTerms}&namespace=' . $ns;
+
+ default:
+ throw new MWException( __METHOD__ . ": Unknown type '$type'" );
+ }
+ }
+}
+
+class ApiOpenSearchFormatJson extends ApiFormatJson {
+ private $warningsAsError = false;
+
+ public function __construct( ApiMain $main, $fm, $warningsAsError ) {
+ parent::__construct( $main, "json$fm" );
+ $this->warningsAsError = $warningsAsError;
+ }
+
+ public function execute() {
+ if ( !$this->getResult()->getResultData( 'error' ) ) {
+ $warnings = $this->getResult()->removeValue( 'warnings', null );
+ if ( $this->warningsAsError && $warnings ) {
+ $this->dieUsage(
+ 'Warnings cannot be represented in OpenSearch JSON format', 'warnings', 0,
+ array( 'warnings' => $warnings )
+ );
+ }
+ }
+
+ parent::execute();
}
}
diff --git a/includes/api/ApiOptions.php b/includes/api/ApiOptions.php
index b01dc3e2..8ef06299 100644
--- a/includes/api/ApiOptions.php
+++ b/includes/api/ApiOptions.php
@@ -153,30 +153,6 @@ class ApiOptions extends ApiBase {
);
}
- public function getParamDescription() {
- return array(
- 'reset' => 'Resets preferences to the site defaults',
- 'resetkinds' => 'List of types of options to reset when the "reset" option is set',
- 'change' => array( 'List of changes, formatted name=value (e.g. skin=vector), ' .
- 'value cannot contain pipe characters. If no value is given (not ',
- 'even an equals sign), e.g., optionname|otheroption|..., the ' .
- 'option will be reset to its default value'
- ),
- 'optionname' => 'A name of a option which should have an optionvalue set',
- 'optionvalue' => 'A value of the option specified by the optionname, ' .
- 'can contain pipe characters',
- );
- }
-
- public function getDescription() {
- return array(
- 'Change preferences of the current user.',
- 'Only options which are registered in core or in one of installed extensions,',
- 'or as options with keys prefixed with \'userjs-\' (intended to be used by user',
- 'scripts), can be set.'
- );
- }
-
public function needsToken() {
return 'csrf';
}
@@ -185,12 +161,15 @@ class ApiOptions extends ApiBase {
return 'https://www.mediawiki.org/wiki/API:Options';
}
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=options&reset=&token=123ABC',
- 'api.php?action=options&change=skin=vector|hideminor=1&token=123ABC',
- 'api.php?action=options&reset=&change=skin=monobook&optionname=nickname&' .
- 'optionvalue=[[User:Beau|Beau]]%20([[User_talk:Beau|talk]])&token=123ABC',
+ 'action=options&reset=&token=123ABC'
+ => 'apihelp-options-example-reset',
+ 'action=options&change=skin=vector|hideminor=1&token=123ABC'
+ => 'apihelp-options-example-change',
+ 'action=options&reset=&change=skin=monobook&optionname=nickname&' .
+ 'optionvalue=[[User:Beau|Beau]]%20([[User_talk:Beau|talk]])&token=123ABC'
+ => 'apihelp-options-example-complex',
);
}
}
diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php
index 0f264675..e6f218d6 100644
--- a/includes/api/ApiPageSet.php
+++ b/includes/api/ApiPageSet.php
@@ -53,7 +53,10 @@ class ApiPageSet extends ApiBase {
private $mAllPages = array(); // [ns][dbkey] => page_id or negative when missing
private $mTitles = array();
+ private $mGoodAndMissingPages = array(); // [ns][dbkey] => page_id or negative when missing
+ private $mGoodPages = array(); // [ns][dbkey] => page_id
private $mGoodTitles = array();
+ private $mMissingPages = array(); // [ns][dbkey] => fake page_id
private $mMissingTitles = array();
private $mInvalidTitles = array();
private $mMissingPageIDs = array();
@@ -65,7 +68,10 @@ class ApiPageSet extends ApiBase {
private $mPendingRedirectIDs = array();
private $mConvertedTitles = array();
private $mGoodRevIDs = array();
+ private $mLiveRevIDs = array();
+ private $mDeletedRevIDs = array();
private $mMissingRevIDs = array();
+ private $mGeneratorData = array(); // [ns][dbkey] => data array
private $mFakePageId = -1;
private $mCacheMode = 'public';
private $mRequestedPageFields = array();
@@ -90,7 +96,7 @@ class ApiPageSet extends ApiBase {
$v = $val;
}
if ( $flag !== null ) {
- $v[$flag] = '';
+ $v[$flag] = true;
}
$result[] = $v;
}
@@ -109,11 +115,9 @@ class ApiPageSet extends ApiBase {
$this->mAllowGenerator = ( $flags & ApiPageSet::DISABLE_GENERATORS ) == 0;
$this->mDefaultNamespace = $defaultNamespace;
- $this->profileIn();
$this->mParams = $this->extractRequestParams();
$this->mResolveRedirects = $this->mParams['redirects'];
$this->mConvertTitles = $this->mParams['converttitles'];
- $this->profileOut();
}
/**
@@ -137,17 +141,12 @@ class ApiPageSet extends ApiBase {
* relevant parameters as used
*/
private function executeInternal( $isDryRun ) {
- $this->profileIn();
-
$generatorName = $this->mAllowGenerator ? $this->mParams['generator'] : null;
if ( isset( $generatorName ) ) {
$dbSource = $this->mDbSource;
- $isQuery = $dbSource instanceof ApiQuery;
- if ( !$isQuery ) {
+ if ( !$dbSource instanceof ApiQuery ) {
// If the parent container of this pageset is not ApiQuery, we must create it to run generator
$dbSource = $this->getMain()->getModuleManager()->getModule( 'query' );
- // Enable profiling for query module because it will be used for db sql profiling
- $dbSource->profileIn();
}
$generator = $dbSource->getModuleManager()->getModule( $generatorName, null, true );
if ( $generator === null ) {
@@ -168,12 +167,9 @@ class ApiPageSet extends ApiBase {
$tmpPageSet->executeInternal( $isDryRun );
// populate this pageset with the generator output
- $this->profileOut();
- $generator->profileIn();
-
if ( !$isDryRun ) {
$generator->executeGenerator( $this );
- wfRunHooks( 'APIQueryGeneratorAfterExecute', array( &$generator, &$this ) );
+ Hooks::run( 'APIQueryGeneratorAfterExecute', array( &$generator, &$this ) );
} else {
// Prevent warnings from being reported on these parameters
$main = $this->getMain();
@@ -181,17 +177,10 @@ class ApiPageSet extends ApiBase {
$main->getVal( $generator->encodeParamName( $paramName ) );
}
}
- $generator->profileOut();
- $this->profileIn();
if ( !$isDryRun ) {
$this->resolvePendingRedirects();
}
-
- if ( !$isQuery ) {
- // If this pageset is not part of the query, we called profileIn() above
- $dbSource->profileOut();
- }
} else {
// Only one of the titles/pageids/revids is allowed at the same time
$dataSource = null;
@@ -235,7 +224,6 @@ class ApiPageSet extends ApiBase {
}
}
}
- $this->profileOut();
}
/**
@@ -309,6 +297,10 @@ class ApiPageSet extends ApiBase {
$pageFlds['page_is_redirect'] = null;
}
+ if ( $this->getConfig()->get( 'ContentHandlerUseDB' ) ) {
+ $pageFlds['page_content_model'] = null;
+ }
+
// only store non-default fields
$this->mRequestedPageFields = array_diff_key( $this->mRequestedPageFields, $pageFlds );
@@ -344,6 +336,14 @@ class ApiPageSet extends ApiBase {
}
/**
+ * Returns an array [ns][dbkey] => page_id for all good titles.
+ * @return array
+ */
+ public function getGoodTitlesByNamespace() {
+ return $this->mGoodPages;
+ }
+
+ /**
* Title objects that were found in the database.
* @return Title[] Array page_id (int) => Title (obj)
*/
@@ -360,6 +360,15 @@ class ApiPageSet extends ApiBase {
}
/**
+ * Returns an array [ns][dbkey] => fake_page_id for all missing titles.
+ * fake_page_id is a unique negative number.
+ * @return array
+ */
+ public function getMissingTitlesByNamespace() {
+ return $this->mMissingPages;
+ }
+
+ /**
* Title objects that were NOT found in the database.
* The array's index will be negative for each item
* @return Title[]
@@ -369,6 +378,22 @@ class ApiPageSet extends ApiBase {
}
/**
+ * Returns an array [ns][dbkey] => page_id for all good and missing titles.
+ * @return array
+ */
+ public function getGoodAndMissingTitlesByNamespace() {
+ return $this->mGoodAndMissingPages;
+ }
+
+ /**
+ * Title objects for good and missing titles.
+ * @return array
+ */
+ public function getGoodAndMissingTitles() {
+ return $this->mGoodTitles + $this->mMissingTitles;
+ }
+
+ /**
* Titles that were deemed invalid by Title::newFromText()
* The array's index will be unique and negative for each item
* @return string[] Array of strings (not Title objects)
@@ -411,10 +436,13 @@ class ApiPageSet extends ApiBase {
if ( $titleTo->hasFragment() ) {
$r['tofragment'] = $titleTo->getFragment();
}
+ if ( $titleTo->isExternal() ) {
+ $r['tointerwiki'] = $titleTo->getInterwiki();
+ }
$values[] = $r;
}
if ( !empty( $values ) && $result ) {
- $result->setIndexedTagName( $values, 'r' );
+ ApiResult::setIndexedTagName( $values, 'r' );
}
return $values;
@@ -445,7 +473,7 @@ class ApiPageSet extends ApiBase {
);
}
if ( !empty( $values ) && $result ) {
- $result->setIndexedTagName( $values, 'n' );
+ ApiResult::setIndexedTagName( $values, 'n' );
}
return $values;
@@ -476,7 +504,7 @@ class ApiPageSet extends ApiBase {
);
}
if ( !empty( $values ) && $result ) {
- $result->setIndexedTagName( $values, 'c' );
+ ApiResult::setIndexedTagName( $values, 'c' );
}
return $values;
@@ -513,7 +541,7 @@ class ApiPageSet extends ApiBase {
$values[] = $item;
}
if ( !empty( $values ) && $result ) {
- $result->setIndexedTagName( $values, 'i' );
+ ApiResult::setIndexedTagName( $values, 'i' );
}
return $values;
@@ -560,7 +588,7 @@ class ApiPageSet extends ApiBase {
}
/**
- * Get the list of revision IDs (requested with the revids= parameter)
+ * Get the list of valid revision IDs (requested with the revids= parameter)
* @return array Array of revID (int) => pageID (int)
*/
public function getRevisionIDs() {
@@ -568,6 +596,22 @@ class ApiPageSet extends ApiBase {
}
/**
+ * Get the list of non-deleted revision IDs (requested with the revids= parameter)
+ * @return array Array of revID (int) => pageID (int)
+ */
+ public function getLiveRevisionIDs() {
+ return $this->mLiveRevIDs;
+ }
+
+ /**
+ * Get the list of revision IDs that were associated with deleted titles.
+ * @return array Array of revID (int) => pageID (int)
+ */
+ public function getDeletedRevisionIDs() {
+ return $this->mDeletedRevIDs;
+ }
+
+ /**
* Revision IDs that were not found in the database
* @return array Array of revision IDs
*/
@@ -589,7 +633,7 @@ class ApiPageSet extends ApiBase {
);
}
if ( !empty( $values ) && $result ) {
- $result->setIndexedTagName( $values, 'rev' );
+ ApiResult::setIndexedTagName( $values, 'rev' );
}
return $values;
@@ -616,9 +660,7 @@ class ApiPageSet extends ApiBase {
* @param array $titles Array of Title objects
*/
public function populateFromTitles( $titles ) {
- $this->profileIn();
$this->initFromTitles( $titles );
- $this->profileOut();
}
/**
@@ -626,20 +668,20 @@ class ApiPageSet extends ApiBase {
* @param array $pageIDs Array of page IDs
*/
public function populateFromPageIDs( $pageIDs ) {
- $this->profileIn();
$this->initFromPageIds( $pageIDs );
- $this->profileOut();
}
/**
* Populate this PageSet from a rowset returned from the database
+ *
+ * Note that the query result must include the columns returned by
+ * $this->getPageTableFields().
+ *
* @param DatabaseBase $db
* @param ResultWrapper $queryResult Query result object
*/
public function populateFromQueryResult( $db, $queryResult ) {
- $this->profileIn();
$this->initFromQueryResult( $queryResult );
- $this->profileOut();
}
/**
@@ -647,9 +689,7 @@ class ApiPageSet extends ApiBase {
* @param array $revIDs Array of revision IDs
*/
public function populateFromRevisionIDs( $revIDs ) {
- $this->profileIn();
$this->initFromRevIDs( $revIDs );
- $this->profileOut();
}
/**
@@ -667,6 +707,8 @@ class ApiPageSet extends ApiBase {
if ( $this->mResolveRedirects && $row->page_is_redirect == '1' ) {
$this->mPendingRedirectIDs[$pageId] = $title;
} else {
+ $this->mGoodPages[$row->page_namespace][$row->page_title] = $pageId;
+ $this->mGoodAndMissingPages[$row->page_namespace][$row->page_title] = $pageId;
$this->mGoodTitles[$pageId] = $title;
}
@@ -710,10 +752,8 @@ class ApiPageSet extends ApiBase {
$set = $linkBatch->constructSet( 'page', $db );
// Get pageIDs data from the `page` table
- $this->profileDBIn();
$res = $db->select( 'page', $this->getPageTableFields(), $set,
__METHOD__ );
- $this->profileDBOut();
// Hack: get the ns:titles stored in array(ns => array(titles)) format
$this->initFromQueryResult( $res, $linkBatch->data, true ); // process Titles
@@ -744,10 +784,8 @@ class ApiPageSet extends ApiBase {
$db = $this->getDB();
// Get pageIDs data from the `page` table
- $this->profileDBIn();
$res = $db->select( 'page', $this->getPageTableFields(), $set,
__METHOD__ );
- $this->profileDBOut();
}
$this->initFromQueryResult( $res, $remaining, false ); // process PageIDs
@@ -803,6 +841,8 @@ class ApiPageSet extends ApiBase {
foreach ( array_keys( $dbkeys ) as $dbkey ) {
$title = Title::makeTitle( $ns, $dbkey );
$this->mAllPages[$ns][$dbkey] = $this->mFakePageId;
+ $this->mMissingPages[$ns][$dbkey] = $this->mFakePageId;
+ $this->mGoodAndMissingPages[$ns][$dbkey] = $this->mFakePageId;
$this->mMissingTitles[$this->mFakePageId] = $title;
$this->mFakePageId--;
$this->mTitles[] = $title;
@@ -851,22 +891,64 @@ class ApiPageSet extends ApiBase {
$where = array( 'rev_id' => $revids, 'rev_page = page_id' );
// Get pageIDs data from the `page` table
- $this->profileDBIn();
$res = $db->select( $tables, $fields, $where, __METHOD__ );
foreach ( $res as $row ) {
$revid = intval( $row->rev_id );
$pageid = intval( $row->rev_page );
$this->mGoodRevIDs[$revid] = $pageid;
+ $this->mLiveRevIDs[$revid] = $pageid;
$pageids[$pageid] = '';
unset( $remaining[$revid] );
}
- $this->profileDBOut();
}
$this->mMissingRevIDs = array_keys( $remaining );
// Populate all the page information
$this->initFromPageIds( array_keys( $pageids ) );
+
+ // If the user can see deleted revisions, pull out the corresponding
+ // titles from the archive table and include them too. We ignore
+ // ar_page_id because deleted revisions are tied by title, not page_id.
+ if ( !empty( $this->mMissingRevIDs ) && $this->getUser()->isAllowed( 'deletedhistory' ) ) {
+ $remaining = array_flip( $this->mMissingRevIDs );
+ $tables = array( 'archive' );
+ $fields = array( 'ar_rev_id', 'ar_namespace', 'ar_title' );
+ $where = array( 'ar_rev_id' => $this->mMissingRevIDs );
+
+ $res = $db->select( $tables, $fields, $where, __METHOD__ );
+ $titles = array();
+ foreach ( $res as $row ) {
+ $revid = intval( $row->ar_rev_id );
+ $titles[$revid] = Title::makeTitle( $row->ar_namespace, $row->ar_title );
+ unset( $remaining[$revid] );
+ }
+
+ $this->initFromTitles( $titles );
+
+ foreach ( $titles as $revid => $title ) {
+ $ns = $title->getNamespace();
+ $dbkey = $title->getDBkey();
+
+ // Handle converted titles
+ if ( !isset( $this->mAllPages[$ns][$dbkey] ) &&
+ isset( $this->mConvertedTitles[$title->getPrefixedText()] )
+ ) {
+ $title = Title::newFromText( $this->mConvertedTitles[$title->getPrefixedText()] );
+ $ns = $title->getNamespace();
+ $dbkey = $title->getDBkey();
+ }
+
+ if ( isset( $this->mAllPages[$ns][$dbkey] ) ) {
+ $this->mGoodRevIDs[$revid] = $this->mAllPages[$ns][$dbkey];
+ $this->mDeletedRevIDs[$revid] = $this->mAllPages[$ns][$dbkey];
+ } else {
+ $remaining[$revid] = true;
+ }
+ }
+
+ $this->mMissingRevIDs = array_keys( $remaining );
+ }
}
/**
@@ -896,9 +978,7 @@ class ApiPageSet extends ApiBase {
}
// Get pageIDs data from the `page` table
- $this->profileDBIn();
$res = $db->select( 'page', $pageFlds, $set, __METHOD__ );
- $this->profileDBOut();
// Hack: get the ns:titles stored in array(ns => array(titles)) format
$this->initFromQueryResult( $res, $linkBatch->data, true );
@@ -917,7 +997,6 @@ class ApiPageSet extends ApiBase {
$lb = new LinkBatch();
$db = $this->getDB();
- $this->profileDBIn();
$res = $db->select(
'redirect',
array(
@@ -929,7 +1008,6 @@ class ApiPageSet extends ApiBase {
), array( 'rd_from' => array_keys( $this->mPendingRedirectIDs ) ),
__METHOD__
);
- $this->profileDBOut();
foreach ( $res as $row ) {
$rdfrom = intval( $row->rd_from );
$from = $this->mPendingRedirectIDs[$rdfrom]->getPrefixedText();
@@ -940,7 +1018,9 @@ class ApiPageSet extends ApiBase {
$row->rd_interwiki
);
unset( $this->mPendingRedirectIDs[$rdfrom] );
- if ( !$to->isExternal() && !isset( $this->mAllPages[$row->rd_namespace][$row->rd_title] ) ) {
+ if ( $to->isExternal() ) {
+ $this->mInterwikiTitles[$to->getPrefixedText()] = $to->getInterwiki();
+ } elseif ( !isset( $this->mAllPages[$row->rd_namespace][$row->rd_title] ) ) {
$lb->add( $row->rd_namespace, $row->rd_title );
}
$this->mRedirectTitles[$from] = $to;
@@ -1066,6 +1146,103 @@ class ApiPageSet extends ApiBase {
}
/**
+ * Set data for a title.
+ *
+ * This data may be extracted into an ApiResult using
+ * self::populateGeneratorData. This should generally be limited to
+ * data that is likely to be particularly useful to end users rather than
+ * just being a dump of everything returned in non-generator mode.
+ *
+ * Redirects here will *not* be followed, even if 'redirects' was
+ * specified, since in the case of multiple redirects we can't know which
+ * source's data to use on the target.
+ *
+ * @param Title $title
+ * @param array $data
+ */
+ public function setGeneratorData( Title $title, array $data ) {
+ $ns = $title->getNamespace();
+ $dbkey = $title->getDBkey();
+ $this->mGeneratorData[$ns][$dbkey] = $data;
+ }
+
+ /**
+ * Populate the generator data for all titles in the result
+ *
+ * The page data may be inserted into an ApiResult object or into an
+ * associative array. The $path parameter specifies the path within the
+ * ApiResult or array to find the "pages" node.
+ *
+ * The "pages" node itself must be an associative array mapping the page ID
+ * or fake page ID values returned by this pageset (see
+ * self::getAllTitlesByNamespace() and self::getSpecialTitles()) to
+ * associative arrays of page data. Each of those subarrays will have the
+ * data from self::setGeneratorData() merged in.
+ *
+ * Data that was set by self::setGeneratorData() for pages not in the
+ * "pages" node will be ignored.
+ *
+ * @param ApiResult|array &$result
+ * @param array $path
+ * @return bool Whether the data fit
+ */
+ public function populateGeneratorData( &$result, array $path = array() ) {
+ if ( $result instanceof ApiResult ) {
+ $data = $result->getResultData( $path );
+ if ( $data === null ) {
+ return true;
+ }
+ } else {
+ $data = &$result;
+ foreach ( $path as $key ) {
+ if ( !isset( $data[$key] ) ) {
+ // Path isn't in $result, so nothing to add, so everything
+ // "fits"
+ return true;
+ }
+ $data = &$data[$key];
+ }
+ }
+ foreach ( $this->mGeneratorData as $ns => $dbkeys ) {
+ if ( $ns === -1 ) {
+ $pages = array();
+ foreach ( $this->mSpecialTitles as $id => $title ) {
+ $pages[$title->getDBkey()] = $id;
+ }
+ } else {
+ if ( !isset( $this->mAllPages[$ns] ) ) {
+ // No known titles in the whole namespace. Skip it.
+ continue;
+ }
+ $pages = $this->mAllPages[$ns];
+ }
+ foreach ( $dbkeys as $dbkey => $genData ) {
+ if ( !isset( $pages[$dbkey] ) ) {
+ // Unknown title. Forget it.
+ continue;
+ }
+ $pageId = $pages[$dbkey];
+ if ( !isset( $data[$pageId] ) ) {
+ // $pageId didn't make it into the result. Ignore it.
+ continue;
+ }
+
+ if ( $result instanceof ApiResult ) {
+ $path2 = array_merge( $path, array( $pageId ) );
+ foreach ( $genData as $key => $value ) {
+ if ( !$result->addValue( $path2, $key, $value ) ) {
+ return false;
+ }
+ }
+ } else {
+ $data[$pageId] = array_merge( $data[$pageId], $genData );
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
* Get the database connection (read-only)
* @return DatabaseBase
*/
@@ -1095,26 +1272,51 @@ class ApiPageSet extends ApiBase {
public function getAllowedParams( $flags = 0 ) {
$result = array(
'titles' => array(
- ApiBase::PARAM_ISMULTI => true
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_HELP_MSG => 'api-pageset-param-titles',
),
'pageids' => array(
ApiBase::PARAM_TYPE => 'integer',
- ApiBase::PARAM_ISMULTI => true
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_HELP_MSG => 'api-pageset-param-pageids',
),
'revids' => array(
ApiBase::PARAM_TYPE => 'integer',
- ApiBase::PARAM_ISMULTI => true
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_HELP_MSG => 'api-pageset-param-revids',
+ ),
+ 'generator' => array(
+ ApiBase::PARAM_TYPE => null,
+ ApiBase::PARAM_VALUE_LINKS => array(),
+ ApiBase::PARAM_HELP_MSG => 'api-pageset-param-generator',
+ ),
+ 'redirects' => array(
+ ApiBase::PARAM_DFLT => false,
+ ApiBase::PARAM_HELP_MSG => $this->mAllowGenerator
+ ? 'api-pageset-param-redirects-generator'
+ : 'api-pageset-param-redirects-nogenerator',
+ ),
+ 'converttitles' => array(
+ ApiBase::PARAM_DFLT => false,
+ ApiBase::PARAM_HELP_MSG => array(
+ 'api-pageset-param-converttitles',
+ new DeferredStringifier(
+ function ( IContextSource $context ) {
+ return $context->getLanguage()
+ ->commaList( LanguageConverter::$languagesWithVariants );
+ },
+ $this
+ )
+ ),
),
- 'redirects' => false,
- 'converttitles' => false,
);
- if ( $this->mAllowGenerator ) {
- if ( $flags & ApiBase::GET_VALUES_FOR_HELP ) {
- $result['generator'] = array(
- ApiBase::PARAM_TYPE => $this->getGenerators()
- );
- } else {
- $result['generator'] = null;
+
+ if ( !$this->mAllowGenerator ) {
+ unset( $result['generator'] );
+ } elseif ( $flags & ApiBase::GET_VALUES_FOR_HELP ) {
+ foreach ( $this->getGenerators() as $g ) {
+ $result['generator'][ApiBase::PARAM_TYPE][] = $g;
+ $result['generator'][ApiBase::PARAM_VALUE_LINKS][$g] = "Special:ApiHelp/query+$g";
}
}
@@ -1148,23 +1350,4 @@ class ApiPageSet extends ApiBase {
return self::$generators;
}
-
- public function getParamDescription() {
- return array(
- 'titles' => 'A list of titles to work on',
- 'pageids' => 'A list of page IDs to work on',
- 'revids' => 'A list of revision IDs to work on',
- 'generator' => array(
- 'Get the list of pages to work on by executing the specified query module.',
- 'NOTE: generator parameter names must be prefixed with a \'g\', see examples'
- ),
- 'redirects' => 'Automatically resolve redirects',
- 'converttitles' => array(
- 'Convert titles to other variants if necessary. Only works if ' .
- 'the wiki\'s content language supports variant conversion.',
- 'Languages that support variant conversion include ' .
- implode( ', ', LanguageConverter::$languagesWithVariants )
- ),
- );
- }
}
diff --git a/includes/api/ApiParamInfo.php b/includes/api/ApiParamInfo.php
index 067b2f59..4dcaf78e 100644
--- a/includes/api/ApiParamInfo.php
+++ b/includes/api/ApiParamInfo.php
@@ -29,232 +29,329 @@
*/
class ApiParamInfo extends ApiBase {
- /**
- * @var ApiQuery
- */
- protected $queryObj;
+ private $helpFormat;
+ private $context;
public function __construct( ApiMain $main, $action ) {
parent::__construct( $main, $action );
- $this->queryObj = new ApiQuery( $this->getMain(), 'query' );
}
public function execute() {
// Get parameters
$params = $this->extractRequestParams();
- $resultObj = $this->getResult();
+
+ $this->helpFormat = $params['helpformat'];
+ $this->context = new RequestContext;
+ $this->context->setUser( new User ); // anon to avoid caching issues
+ $this->context->setLanguage( $this->getMain()->getLanguage() );
+
+ if ( is_array( $params['modules'] ) ) {
+ $modules = $params['modules'];
+ } else {
+ $modules = array();
+ }
+
+ if ( is_array( $params['querymodules'] ) ) {
+ $this->logFeatureUsage( 'action=paraminfo&querymodules' );
+ $queryModules = $params['querymodules'];
+ foreach ( $queryModules as $m ) {
+ $modules[] = 'query+' . $m;
+ }
+ } else {
+ $queryModules = array();
+ }
+
+ if ( is_array( $params['formatmodules'] ) ) {
+ $this->logFeatureUsage( 'action=paraminfo&formatmodules' );
+ $formatModules = $params['formatmodules'];
+ foreach ( $formatModules as $m ) {
+ $modules[] = $m;
+ }
+ } else {
+ $formatModules = array();
+ }
$res = array();
- $this->addModulesInfo( $params, 'modules', $res, $resultObj );
+ foreach ( $modules as $m ) {
+ try {
+ $module = $this->getModuleFromPath( $m );
+ } catch ( UsageException $ex ) {
+ $this->setWarning( $ex->getMessage() );
+ continue;
+ }
+ $key = 'modules';
+
+ // Back compat
+ $isBCQuery = false;
+ if ( $module->getParent() && $module->getParent()->getModuleName() == 'query' &&
+ in_array( $module->getModuleName(), $queryModules )
+ ) {
+ $isBCQuery = true;
+ $key = 'querymodules';
+ }
+ if ( in_array( $module->getModuleName(), $formatModules ) ) {
+ $key = 'formatmodules';
+ }
- $this->addModulesInfo( $params, 'querymodules', $res, $resultObj );
+ $item = $this->getModuleInfo( $module );
+ if ( $isBCQuery ) {
+ $item['querytype'] = $item['group'];
+ }
+ $res[$key][] = $item;
+ }
+
+ $result = $this->getResult();
+ $result->addValue( array( $this->getModuleName() ), 'helpformat', $this->helpFormat );
+
+ foreach ( $res as $key => $stuff ) {
+ ApiResult::setIndexedTagName( $res[$key], 'module' );
+ }
if ( $params['mainmodule'] ) {
- $res['mainmodule'] = $this->getClassInfo( $this->getMain() );
+ $this->logFeatureUsage( 'action=paraminfo&mainmodule' );
+ $res['mainmodule'] = $this->getModuleInfo( $this->getMain() );
}
if ( $params['pagesetmodule'] ) {
- $pageSet = new ApiPageSet( $this->queryObj );
- $res['pagesetmodule'] = $this->getClassInfo( $pageSet );
+ $this->logFeatureUsage( 'action=paraminfo&pagesetmodule' );
+ $pageSet = new ApiPageSet( $this->getMain()->getModuleManager()->getModule( 'query' ) );
+ $res['pagesetmodule'] = $this->getModuleInfo( $pageSet );
+ unset( $res['pagesetmodule']['name'] );
+ unset( $res['pagesetmodule']['path'] );
+ unset( $res['pagesetmodule']['group'] );
}
- $this->addModulesInfo( $params, 'formatmodules', $res, $resultObj );
-
- $resultObj->addValue( null, $this->getModuleName(), $res );
+ $result->addValue( null, $this->getModuleName(), $res );
}
/**
- * If the type is requested in parameters, adds a section to res with module info.
- * @param array $params User parameters array
- * @param string $type Parameter name
- * @param array $res Store results in this array
- * @param ApiResult $resultObj Results object to set indexed tag.
+ * @param array $res Result array
+ * @param string $key Result key
+ * @param Message[] $msgs
+ * @param bool $joinLists
*/
- private function addModulesInfo( $params, $type, &$res, $resultObj ) {
- if ( !is_array( $params[$type] ) ) {
- return;
- }
- $isQuery = ( $type === 'querymodules' );
- if ( $isQuery ) {
- $mgr = $this->queryObj->getModuleManager();
- } else {
- $mgr = $this->getMain()->getModuleManager();
- }
- $res[$type] = array();
- foreach ( $params[$type] as $mod ) {
- if ( !$mgr->isDefined( $mod ) ) {
- $res[$type][] = array( 'name' => $mod, 'missing' => '' );
- continue;
- }
- $obj = $mgr->getModule( $mod );
- $item = $this->getClassInfo( $obj );
- $item['name'] = $mod;
- if ( $isQuery ) {
- $item['querytype'] = $mgr->getModuleGroup( $mod );
- }
- $res[$type][] = $item;
+ protected function formatHelpMessages( array &$res, $key, array $msgs, $joinLists = false ) {
+ switch ( $this->helpFormat ) {
+ case 'none':
+ break;
+
+ case 'wikitext':
+ $ret = array();
+ foreach ( $msgs as $m ) {
+ $ret[] = $m->setContext( $this->context )->text();
+ }
+ $res[$key] = join( "\n\n", $ret );
+ if ( $joinLists ) {
+ $res[$key] = preg_replace( '!^(([*#:;])[^\n]*)\n\n(?=\2)!m', "$1\n", $res[$key] );
+ }
+ break;
+
+ case 'html':
+ $ret = array();
+ foreach ( $msgs as $m ) {
+ $ret[] = $m->setContext( $this->context )->parseAsBlock();
+ }
+ $ret = join( "\n", $ret );
+ if ( $joinLists ) {
+ $ret = preg_replace( '!\s*</([oud]l)>\s*<\1>\s*!', "\n", $ret );
+ }
+ $res[$key] = Parser::stripOuterParagraph( $ret );
+ break;
+
+ case 'raw':
+ $res[$key] = array();
+ foreach ( $msgs as $m ) {
+ $a = array(
+ 'key' => $m->getKey(),
+ 'params' => $m->getParams(),
+ );
+ if ( $m instanceof ApiHelpParamValueMessage ) {
+ $a['forvalue'] = $m->getParamValue();
+ }
+ $res[$key][] = $a;
+ }
+ ApiResult::setIndexedTagName( $res[$key], 'msg' );
+ break;
}
- $resultObj->setIndexedTagName( $res[$type], 'module' );
}
/**
- * @param ApiBase $obj
+ * @param ApiBase $module
* @return ApiResult
*/
- private function getClassInfo( $obj ) {
+ private function getModuleInfo( $module ) {
$result = $this->getResult();
- $retval['classname'] = get_class( $obj );
- $retval['description'] = implode( "\n", (array)$obj->getFinalDescription() );
- $retval['examples'] = '';
-
- // version is deprecated since 1.21, but needs to be returned for v1
- $retval['version'] = '';
- $retval['prefix'] = $obj->getModulePrefix();
-
- if ( $obj->isReadMode() ) {
- $retval['readrights'] = '';
- }
- if ( $obj->isWriteMode() ) {
- $retval['writerights'] = '';
- }
- if ( $obj->mustBePosted() ) {
- $retval['mustbeposted'] = '';
- }
- if ( $obj instanceof ApiQueryGeneratorBase ) {
- $retval['generator'] = '';
+ $ret = array();
+ $path = $module->getModulePath();
+
+ $ret['name'] = $module->getModuleName();
+ $ret['classname'] = get_class( $module );
+ $ret['path'] = $path;
+ if ( !$module->isMain() ) {
+ $ret['group'] = $module->getParent()->getModuleManager()->getModuleGroup(
+ $module->getModuleName()
+ );
}
+ $ret['prefix'] = $module->getModulePrefix();
- $allowedParams = $obj->getFinalParams( ApiBase::GET_VALUES_FOR_HELP );
- if ( !is_array( $allowedParams ) ) {
- return $retval;
- }
+ $this->formatHelpMessages( $ret, 'description', $module->getFinalDescription() );
- $retval['helpurls'] = (array)$obj->getHelpUrls();
- if ( isset( $retval['helpurls'][0] ) && $retval['helpurls'][0] === false ) {
- $retval['helpurls'] = array();
+ foreach ( $module->getHelpFlags() as $flag ) {
+ $ret[$flag] = true;
}
- $result->setIndexedTagName( $retval['helpurls'], 'helpurl' );
- $examples = $obj->getExamples();
- $retval['allexamples'] = array();
- if ( $examples !== false ) {
- if ( is_string( $examples ) ) {
- $examples = array( $examples );
- }
- foreach ( $examples as $k => $v ) {
- if ( strlen( $retval['examples'] ) ) {
- $retval['examples'] .= ' ';
- }
- $item = array();
- if ( is_numeric( $k ) ) {
- $retval['examples'] .= $v;
- ApiResult::setContent( $item, $v );
- } else {
- if ( !is_array( $v ) ) {
- $item['description'] = $v;
+ $ret['helpurls'] = (array)$module->getHelpUrls();
+ if ( isset( $ret['helpurls'][0] ) && $ret['helpurls'][0] === false ) {
+ $ret['helpurls'] = array();
+ }
+ ApiResult::setIndexedTagName( $ret['helpurls'], 'helpurl' );
+
+ if ( $this->helpFormat !== 'none' ) {
+ $ret['examples'] = array();
+ $examples = $module->getExamplesMessages();
+ foreach ( $examples as $qs => $msg ) {
+ $item = array(
+ 'query' => $qs
+ );
+ $msg = ApiBase::makeMessage( $msg, $this->context, array(
+ $module->getModulePrefix(),
+ $module->getModuleName(),
+ $module->getModulePath()
+ ) );
+ $this->formatHelpMessages( $item, 'description', array( $msg ) );
+ if ( isset( $item['description'] ) ) {
+ if ( is_array( $item['description'] ) ) {
+ $item['description'] = $item['description'][0];
} else {
- $item['description'] = implode( $v, "\n" );
+ ApiResult::setSubelementsList( $item, 'description' );
}
- $retval['examples'] .= $item['description'] . ' ' . $k;
- ApiResult::setContent( $item, $k );
}
- $retval['allexamples'][] = $item;
+ $ret['examples'][] = $item;
}
+ ApiResult::setIndexedTagName( $ret['examples'], 'example' );
}
- $result->setIndexedTagName( $retval['allexamples'], 'example' );
-
- $retval['parameters'] = array();
- $paramDesc = $obj->getFinalParamDescription();
- foreach ( $allowedParams as $n => $p ) {
- $a = array( 'name' => $n );
- if ( isset( $paramDesc[$n] ) ) {
- $a['description'] = implode( "\n", (array)$paramDesc[$n] );
- }
- //handle shorthand
- if ( !is_array( $p ) ) {
- $p = array(
- ApiBase::PARAM_DFLT => $p,
- );
+ $ret['parameters'] = array();
+ $params = $module->getFinalParams( ApiBase::GET_VALUES_FOR_HELP );
+ $paramDesc = $module->getFinalParamDescription();
+ foreach ( $params as $name => $settings ) {
+ if ( !is_array( $settings ) ) {
+ $settings = array( ApiBase::PARAM_DFLT => $settings );
}
- //handle missing type
- if ( !isset( $p[ApiBase::PARAM_TYPE] ) ) {
- $dflt = isset( $p[ApiBase::PARAM_DFLT] ) ? $p[ApiBase::PARAM_DFLT] : null;
- if ( is_bool( $dflt ) ) {
- $p[ApiBase::PARAM_TYPE] = 'boolean';
- } elseif ( is_string( $dflt ) || is_null( $dflt ) ) {
- $p[ApiBase::PARAM_TYPE] = 'string';
- } elseif ( is_int( $dflt ) ) {
- $p[ApiBase::PARAM_TYPE] = 'integer';
- }
+ $item = array(
+ 'name' => $name
+ );
+ if ( isset( $paramDesc[$name] ) ) {
+ $this->formatHelpMessages( $item, 'description', $paramDesc[$name], true );
}
- if ( isset( $p[ApiBase::PARAM_DEPRECATED] ) && $p[ApiBase::PARAM_DEPRECATED] ) {
- $a['deprecated'] = '';
+ $item['required'] = !empty( $settings[ApiBase::PARAM_REQUIRED] );
+
+ if ( !empty( $settings[ApiBase::PARAM_DEPRECATED] ) ) {
+ $item['deprecated'] = true;
}
- if ( isset( $p[ApiBase::PARAM_REQUIRED] ) && $p[ApiBase::PARAM_REQUIRED] ) {
- $a['required'] = '';
+
+ if ( $name === 'token' && $module->needsToken() ) {
+ $item['tokentype'] = $module->needsToken();
}
- if ( $n === 'token' && $obj->needsToken() ) {
- $a['tokentype'] = $obj->needsToken();
+ if ( !isset( $settings[ApiBase::PARAM_TYPE] ) ) {
+ $dflt = isset( $settings[ApiBase::PARAM_DFLT] )
+ ? $settings[ApiBase::PARAM_DFLT]
+ : null;
+ if ( is_bool( $dflt ) ) {
+ $settings[ApiBase::PARAM_TYPE] = 'boolean';
+ } elseif ( is_string( $dflt ) || is_null( $dflt ) ) {
+ $settings[ApiBase::PARAM_TYPE] = 'string';
+ } elseif ( is_int( $dflt ) ) {
+ $settings[ApiBase::PARAM_TYPE] = 'integer';
+ }
}
- if ( isset( $p[ApiBase::PARAM_DFLT] ) ) {
- $type = $p[ApiBase::PARAM_TYPE];
- if ( $type === 'boolean' ) {
- $a['default'] = ( $p[ApiBase::PARAM_DFLT] ? 'true' : 'false' );
- } elseif ( $type === 'string' ) {
- $a['default'] = strval( $p[ApiBase::PARAM_DFLT] );
- } elseif ( $type === 'integer' ) {
- $a['default'] = intval( $p[ApiBase::PARAM_DFLT] );
- } else {
- $a['default'] = $p[ApiBase::PARAM_DFLT];
+ if ( isset( $settings[ApiBase::PARAM_DFLT] ) ) {
+ switch ( $settings[ApiBase::PARAM_TYPE] ) {
+ case 'boolean':
+ $item['default'] = ( $settings[ApiBase::PARAM_DFLT] ? 'true' : 'false' );
+ break;
+ case 'string':
+ $item['default'] = strval( $settings[ApiBase::PARAM_DFLT] );
+ break;
+ case 'integer':
+ $item['default'] = intval( $settings[ApiBase::PARAM_DFLT] );
+ break;
+ default:
+ $item['default'] = $settings[ApiBase::PARAM_DFLT];
+ break;
}
}
- if ( isset( $p[ApiBase::PARAM_ISMULTI] ) && $p[ApiBase::PARAM_ISMULTI] ) {
- $a['multi'] = '';
- $a['limit'] = $this->getMain()->canApiHighLimits() ?
+
+ $item['multi'] = !empty( $settings[ApiBase::PARAM_ISMULTI] );
+ if ( $item['multi'] ) {
+ $item['limit'] = $this->getMain()->canApiHighLimits() ?
ApiBase::LIMIT_SML2 :
ApiBase::LIMIT_SML1;
- $a['lowlimit'] = ApiBase::LIMIT_SML1;
- $a['highlimit'] = ApiBase::LIMIT_SML2;
+ $item['lowlimit'] = ApiBase::LIMIT_SML1;
+ $item['highlimit'] = ApiBase::LIMIT_SML2;
}
- if ( isset( $p[ApiBase::PARAM_ALLOW_DUPLICATES] ) && $p[ApiBase::PARAM_ALLOW_DUPLICATES] ) {
- $a['allowsduplicates'] = '';
+ if ( !empty( $settings[ApiBase::PARAM_ALLOW_DUPLICATES] ) ) {
+ $item['allowsduplicates'] = true;
}
- if ( isset( $p[ApiBase::PARAM_TYPE] ) ) {
- if ( $p[ApiBase::PARAM_TYPE] === 'submodule' ) {
- $a['type'] = $obj->getModuleManager()->getNames( $n );
- sort( $a['type'] );
- $a['submodules'] = '';
+ if ( isset( $settings[ApiBase::PARAM_TYPE] ) ) {
+ if ( $settings[ApiBase::PARAM_TYPE] === 'submodule' ) {
+ $item['type'] = $module->getModuleManager()->getNames( $name );
+ sort( $item['type'] );
+ $item['submodules'] = true;
} else {
- $a['type'] = $p[ApiBase::PARAM_TYPE];
+ $item['type'] = $settings[ApiBase::PARAM_TYPE];
}
- if ( is_array( $a['type'] ) ) {
+ if ( is_array( $item['type'] ) ) {
// To prevent sparse arrays from being serialized to JSON as objects
- $a['type'] = array_values( $a['type'] );
- $result->setIndexedTagName( $a['type'], 't' );
+ $item['type'] = array_values( $item['type'] );
+ ApiResult::setIndexedTagName( $item['type'], 't' );
}
}
- if ( isset( $p[ApiBase::PARAM_MAX] ) ) {
- $a['max'] = $p[ApiBase::PARAM_MAX];
+ if ( isset( $settings[ApiBase::PARAM_MAX] ) ) {
+ $item['max'] = $settings[ApiBase::PARAM_MAX];
+ }
+ if ( isset( $settings[ApiBase::PARAM_MAX2] ) ) {
+ $item['highmax'] = $settings[ApiBase::PARAM_MAX2];
}
- if ( isset( $p[ApiBase::PARAM_MAX2] ) ) {
- $a['highmax'] = $p[ApiBase::PARAM_MAX2];
+ if ( isset( $settings[ApiBase::PARAM_MIN] ) ) {
+ $item['min'] = $settings[ApiBase::PARAM_MIN];
}
- if ( isset( $p[ApiBase::PARAM_MIN] ) ) {
- $a['min'] = $p[ApiBase::PARAM_MIN];
+
+ if ( !empty( $settings[ApiBase::PARAM_HELP_MSG_INFO] ) ) {
+ $item['info'] = array();
+ foreach ( $settings[ApiBase::PARAM_HELP_MSG_INFO] as $i ) {
+ $tag = array_shift( $i );
+ $info = array(
+ 'name' => $tag,
+ );
+ if ( count( $i ) ) {
+ $info['values'] = $i;
+ ApiResult::setIndexedTagName( $info['values'], 'v' );
+ }
+ $this->formatHelpMessages( $info, 'text', array(
+ $this->context->msg( "apihelp-{$path}-paraminfo-{$tag}" )
+ ->numParams( count( $i ) )
+ ->params( $this->context->getLanguage()->commaList( $i ) )
+ ->params( $module->getModulePrefix() )
+ ) );
+ ApiResult::setSubelementsList( $info, 'text' );
+ $item['info'][] = $info;
+ }
+ ApiResult::setIndexedTagName( $item['info'], 'i' );
}
- $retval['parameters'][] = $a;
+
+ $ret['parameters'][] = $item;
}
- $result->setIndexedTagName( $retval['parameters'], 'param' );
+ ApiResult::setIndexedTagName( $ret['parameters'], 'param' );
- return $retval;
+ return $ret;
}
public function isReadMode() {
@@ -262,9 +359,9 @@ class ApiParamInfo extends ApiBase {
}
public function getAllowedParams() {
- $modules = $this->getMain()->getModuleManager()->getNames( 'action' );
- sort( $modules );
- $querymodules = $this->queryObj->getModuleManager()->getNames();
+ // back compat
+ $querymodules = $this->getMain()->getModuleManager()
+ ->getModule( 'query' )->getModuleManager()->getNames();
sort( $querymodules );
$formatmodules = $this->getMain()->getModuleManager()->getNames( 'format' );
sort( $formatmodules );
@@ -272,39 +369,35 @@ class ApiParamInfo extends ApiBase {
return array(
'modules' => array(
ApiBase::PARAM_ISMULTI => true,
- ApiBase::PARAM_TYPE => $modules,
),
+ 'helpformat' => array(
+ ApiBase::PARAM_DFLT => 'none',
+ ApiBase::PARAM_TYPE => array( 'html', 'wikitext', 'raw', 'none' ),
+ ),
+
'querymodules' => array(
+ ApiBase::PARAM_DEPRECATED => true,
ApiBase::PARAM_ISMULTI => true,
ApiBase::PARAM_TYPE => $querymodules,
),
- 'mainmodule' => false,
- 'pagesetmodule' => false,
+ 'mainmodule' => array(
+ ApiBase::PARAM_DEPRECATED => true,
+ ),
+ 'pagesetmodule' => array(
+ ApiBase::PARAM_DEPRECATED => true,
+ ),
'formatmodules' => array(
+ ApiBase::PARAM_DEPRECATED => true,
ApiBase::PARAM_ISMULTI => true,
ApiBase::PARAM_TYPE => $formatmodules,
)
);
}
- public function getParamDescription() {
- return array(
- 'modules' => 'List of module names (value of the action= parameter)',
- 'querymodules' => 'List of query module names (value of prop=, meta= or list= parameter)',
- 'mainmodule' => 'Get information about the main (top-level) module as well',
- 'pagesetmodule' => 'Get information about the pageset module ' .
- '(providing titles= and friends) as well',
- 'formatmodules' => 'List of format module names (value of format= parameter)',
- );
- }
-
- public function getDescription() {
- return 'Obtain information about certain API parameters and errors.';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=paraminfo&modules=parse&querymodules=allpages|siteinfo'
+ 'action=paraminfo&modules=parse|phpfm|query+allpages|query+siteinfo'
+ => 'apihelp-paraminfo-example-1',
);
}
diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php
index 06fdf85b..1b5e2658 100644
--- a/includes/api/ApiParse.php
+++ b/includes/api/ApiParse.php
@@ -70,6 +70,9 @@ class ApiParse extends ApiBase {
if ( isset( $params['section'] ) ) {
$this->section = $params['section'];
+ if ( !preg_match( '/^((T-)?\d+|new)$/', $this->section ) ) {
+ $this->dieUsage( "The section parameter must be a valid section id or 'new'", "invalidsection" );
+ }
} else {
$this->section = false;
}
@@ -79,25 +82,18 @@ class ApiParse extends ApiBase {
// TODO: Does this still need $wgTitle?
global $wgParser, $wgTitle;
- // Currently unnecessary, code to act as a safeguard against any change
- // in current behavior of uselang
- $oldLang = null;
- if ( isset( $params['uselang'] )
- && $params['uselang'] != $this->getContext()->getLanguage()->getCode()
- ) {
- $oldLang = $this->getContext()->getLanguage(); // Backup language
- $this->getContext()->setLanguage( Language::factory( $params['uselang'] ) );
- }
-
$redirValues = null;
// Return result
$result = $this->getResult();
if ( !is_null( $oldid ) || !is_null( $pageid ) || !is_null( $page ) ) {
+ if ( $this->section === 'new' ) {
+ $this->dieUsage( 'section=new cannot be combined with oldid, pageid or page parameters. Please use text', 'params' );
+ }
if ( !is_null( $oldid ) ) {
// Don't use the parser cache
- $rev = Revision::newFromID( $oldid );
+ $rev = Revision::newFromId( $oldid );
if ( !$rev ) {
$this->dieUsage( "There is no revision ID $oldid", 'missingrev' );
}
@@ -128,7 +124,6 @@ class ApiParse extends ApiBase {
} else { // Not $oldid, but $pageid or $page
if ( $params['redirects'] ) {
$reqParams = array(
- 'action' => 'query',
'redirects' => '',
);
if ( !is_null( $pageid ) ) {
@@ -138,14 +133,13 @@ class ApiParse extends ApiBase {
}
$req = new FauxRequest( $reqParams );
$main = new ApiMain( $req );
- $main->execute();
- $data = $main->getResultData();
- $redirValues = isset( $data['query']['redirects'] )
- ? $data['query']['redirects']
- : array();
+ $pageSet = new ApiPageSet( $main );
+ $pageSet->execute();
+ $redirValues = $pageSet->getRedirectTitlesAsResult( $this->getResult() );
+
$to = $page;
- foreach ( (array)$redirValues as $r ) {
- $to = $r['to'];
+ foreach ( $pageSet->getRedirectTitles() as $title ) {
+ $to = $title->getFullText();
}
$pageParams = array( 'title' => $to );
} elseif ( !is_null( $pageid ) ) {
@@ -213,7 +207,14 @@ class ApiParse extends ApiBase {
}
if ( $this->section !== false ) {
- $this->content = $this->getSectionContent( $this->content, $titleObj->getPrefixedText() );
+ if ( $this->section === 'new' ) {
+ // Insert the section title above the content.
+ if ( !is_null( $params['sectiontitle'] ) && $params['sectiontitle'] !== '' ) {
+ $this->content = $this->content->addSectionHeader( $params['sectiontitle'] );
+ }
+ } else {
+ $this->content = $this->getSectionContent( $this->content, $titleObj->getPrefixedText() );
+ }
}
if ( $params['pst'] || $params['onlypst'] ) {
@@ -222,12 +223,19 @@ class ApiParse extends ApiBase {
if ( $params['onlypst'] ) {
// Build a result and bail out
$result_array = array();
- $result_array['text'] = array();
- ApiResult::setContent( $result_array['text'], $this->pstContent->serialize( $format ) );
+ $result_array['text'] = $this->pstContent->serialize( $format );
+ $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'text';
if ( isset( $prop['wikitext'] ) ) {
- $result_array['wikitext'] = array();
- ApiResult::setContent( $result_array['wikitext'], $this->content->serialize( $format ) );
+ $result_array['wikitext'] = $this->content->serialize( $format );
+ $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'wikitext';
}
+ if ( !is_null( $params['summary'] ) ||
+ ( !is_null( $params['sectiontitle'] ) && $this->section === 'new' )
+ ) {
+ $result_array['parsedsummary'] = $this->formatSummary( $titleObj, $params );
+ $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'parsedsummary';
+ }
+
$result->addValue( null, $this->getModuleName(), $result_array );
return;
@@ -258,16 +266,15 @@ class ApiParse extends ApiBase {
}
if ( isset( $prop['text'] ) ) {
- $result_array['text'] = array();
- ApiResult::setContent( $result_array['text'], $p_result->getText() );
+ $result_array['text'] = $p_result->getText();
+ $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'text';
}
- if ( !is_null( $params['summary'] ) ) {
- $result_array['parsedsummary'] = array();
- ApiResult::setContent(
- $result_array['parsedsummary'],
- Linker::formatComment( $params['summary'], $titleObj )
- );
+ if ( !is_null( $params['summary'] ) ||
+ ( !is_null( $params['sectiontitle'] ) && $this->section === 'new' )
+ ) {
+ $result_array['parsedsummary'] = $this->formatSummary( $titleObj, $params );
+ $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'parsedsummary';
}
if ( isset( $prop['langlinks'] ) ) {
@@ -277,7 +284,7 @@ class ApiParse extends ApiBase {
// Link flags are ignored for now, but may in the future be
// included in the result.
$linkFlags = array();
- wfRunHooks( 'LanguageLinks', array( $titleObj, &$langlinks, &$linkFlags ) );
+ Hooks::run( 'LanguageLinks', array( $titleObj, &$langlinks, &$linkFlags ) );
}
} else {
$langlinks = false;
@@ -290,9 +297,8 @@ class ApiParse extends ApiBase {
$result_array['categories'] = $this->formatCategoryLinks( $p_result->getCategories() );
}
if ( isset( $prop['categorieshtml'] ) ) {
- $categoriesHtml = $this->categoriesHtml( $p_result->getCategories() );
- $result_array['categorieshtml'] = array();
- ApiResult::setContent( $result_array['categorieshtml'], $categoriesHtml );
+ $result_array['categorieshtml'] = $this->categoriesHtml( $p_result->getCategories() );
+ $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'categorieshtml';
}
if ( isset( $prop['links'] ) ) {
$result_array['links'] = $this->formatLinks( $p_result->getLinks() );
@@ -332,11 +338,8 @@ class ApiParse extends ApiBase {
}
if ( isset( $prop['headhtml'] ) ) {
- $result_array['headhtml'] = array();
- ApiResult::setContent(
- $result_array['headhtml'],
- $context->getOutput()->headElement( $context->getSkin() )
- );
+ $result_array['headhtml'] = $context->getOutput()->headElement( $context->getSkin() );
+ $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'headhtml';
}
}
@@ -347,20 +350,26 @@ class ApiParse extends ApiBase {
$result_array['modulemessages'] = array_values( array_unique( $p_result->getModuleMessages() ) );
}
+ if ( isset( $prop['indicators'] ) ) {
+ $result_array['indicators'] = (array)$p_result->getIndicators();
+ ApiResult::setArrayType( $result_array['indicators'], 'BCkvp', 'name' );
+ }
+
if ( isset( $prop['iwlinks'] ) ) {
$result_array['iwlinks'] = $this->formatIWLinks( $p_result->getInterwikiLinks() );
}
if ( isset( $prop['wikitext'] ) ) {
- $result_array['wikitext'] = array();
- ApiResult::setContent( $result_array['wikitext'], $this->content->serialize( $format ) );
+ $result_array['wikitext'] = $this->content->serialize( $format );
+ $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'wikitext';
if ( !is_null( $this->pstContent ) ) {
- $result_array['psttext'] = array();
- ApiResult::setContent( $result_array['psttext'], $this->pstContent->serialize( $format ) );
+ $result_array['psttext'] = $this->pstContent->serialize( $format );
+ $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'psttext';
}
}
if ( isset( $prop['properties'] ) ) {
- $result_array['properties'] = $this->formatProperties( $p_result->getProperties() );
+ $result_array['properties'] = (array)$p_result->getProperties();
+ ApiResult::setArrayType( $result_array['properties'], 'BCkvp', 'name' );
}
if ( isset( $prop['limitreportdata'] ) ) {
@@ -368,9 +377,8 @@ class ApiParse extends ApiBase {
$this->formatLimitReportData( $p_result->getLimitReportData() );
}
if ( isset( $prop['limitreporthtml'] ) ) {
- $limitreportHtml = EditPage::getPreviewLimitReport( $p_result );
- $result_array['limitreporthtml'] = array();
- ApiResult::setContent( $result_array['limitreporthtml'], $limitreportHtml );
+ $result_array['limitreporthtml'] = EditPage::getPreviewLimitReport( $p_result );
+ $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'limitreporthtml';
}
if ( $params['generatexml'] ) {
@@ -378,15 +386,15 @@ class ApiParse extends ApiBase {
$this->dieUsage( "generatexml is only supported for wikitext content", "notwikitext" );
}
- $wgParser->startExternalParse( $titleObj, $popts, OT_PREPROCESS );
+ $wgParser->startExternalParse( $titleObj, $popts, Parser::OT_PREPROCESS );
$dom = $wgParser->preprocessToDom( $this->content->getNativeData() );
if ( is_callable( array( $dom, 'saveXML' ) ) ) {
$xml = $dom->saveXML();
} else {
$xml = $dom->__toString();
}
- $result_array['parsetree'] = array();
- ApiResult::setContent( $result_array['parsetree'], $xml );
+ $result_array['parsetree'] = $xml;
+ $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'parsetree';
}
$result_mapping = array(
@@ -401,6 +409,7 @@ class ApiParse extends ApiBase {
'sections' => 's',
'headitems' => 'hi',
'modules' => 'm',
+ 'indicators' => 'ind',
'modulescripts' => 'm',
'modulestyles' => 'm',
'modulemessages' => 'm',
@@ -409,10 +418,6 @@ class ApiParse extends ApiBase {
);
$this->setIndexedTagNames( $result_array, $result_mapping );
$result->addValue( null, $this->getModuleName(), $result_array );
-
- if ( !is_null( $oldLang ) ) {
- $this->getContext()->setLanguage( $oldLang ); // Reset language to $oldLang
- }
}
/**
@@ -424,7 +429,6 @@ class ApiParse extends ApiBase {
* @return ParserOptions
*/
protected function makeParserOptions( WikiPage $pageObj, array $params ) {
- wfProfileIn( __METHOD__ );
$popts = $pageObj->makeParserOptions( $this->getContext() );
$popts->enableLimitReport( !$params['disablepp'] );
@@ -432,8 +436,6 @@ class ApiParse extends ApiBase {
$popts->setIsSectionPreview( $params['sectionpreview'] );
$popts->setEditSection( !$params['disableeditsection'] );
- wfProfileOut( __METHOD__ );
-
return $popts;
}
@@ -489,6 +491,30 @@ class ApiParse extends ApiBase {
return $section;
}
+ /**
+ * This mimicks the behavior of EditPage in formatting a summary
+ *
+ * @param Title $title of the page being parsed
+ * @param Array $params the API parameters of the request
+ * @return Content|bool
+ */
+ private function formatSummary( $title, $params ) {
+ global $wgParser;
+ $summary = !is_null( $params['summary'] ) ? $params['summary'] : '';
+ $sectionTitle = !is_null( $params['sectiontitle'] ) ? $params['sectiontitle'] : '';
+
+ if ( $this->section === 'new' && ( $sectionTitle === '' || $summary === '' ) ) {
+ if( $sectionTitle !== '' ) {
+ $summary = $params['sectiontitle'];
+ }
+ if ( $summary !== '' ) {
+ $summary = wfMessage( 'newsectionsummary' )->rawParams( $wgParser->stripSectionName( $summary ) )
+ ->inContentLanguage()->text();
+ }
+ }
+ return Linker::formatComment( $summary, $title, $this->section === 'new' );
+ }
+
private function formatLangLinks( $links ) {
$result = array();
foreach ( $links as $link ) {
@@ -499,7 +525,7 @@ class ApiParse extends ApiBase {
$entry['lang'] = $bits[0];
if ( $title ) {
$entry['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
- // localised language name in user language (maybe set by uselang=)
+ // localised language name in 'uselang' language
$entry['langname'] = Language::fetchLanguageName(
$title->getInterwiki(),
$this->getLanguage()->getCode()
@@ -508,7 +534,7 @@ class ApiParse extends ApiBase {
// native language name
$entry['autonym'] = Language::fetchLanguageName( $title->getInterwiki() );
}
- ApiResult::setContent( $entry, $bits[1] );
+ ApiResult::setContentValue( $entry, 'title', $bits[1] );
$result[] = $entry;
}
@@ -543,11 +569,11 @@ class ApiParse extends ApiBase {
foreach ( $links as $link => $sortkey ) {
$entry = array();
$entry['sortkey'] = $sortkey;
- ApiResult::setContent( $entry, $link );
+ ApiResult::setContentValue( $entry, 'category', $link );
if ( !isset( $hiddencats[$link] ) ) {
- $entry['missing'] = '';
+ $entry['missing'] = true;
} elseif ( $hiddencats[$link] ) {
- $entry['hidden'] = '';
+ $entry['hidden'] = true;
}
$result[] = $entry;
}
@@ -568,10 +594,8 @@ class ApiParse extends ApiBase {
foreach ( $nslinks as $title => $id ) {
$entry = array();
$entry['ns'] = $ns;
- ApiResult::setContent( $entry, Title::makeTitle( $ns, $title )->getFullText() );
- if ( $id != 0 ) {
- $entry['exists'] = '';
- }
+ ApiResult::setContentValue( $entry, 'title', Title::makeTitle( $ns, $title )->getFullText() );
+ $entry['exists'] = $id != 0;
$result[] = $entry;
}
}
@@ -591,7 +615,7 @@ class ApiParse extends ApiBase {
$entry['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
}
- ApiResult::setContent( $entry, $title->getFullText() );
+ ApiResult::setContentValue( $entry, 'title', $title->getFullText() );
$result[] = $entry;
}
}
@@ -604,19 +628,7 @@ class ApiParse extends ApiBase {
foreach ( $headItems as $tag => $content ) {
$entry = array();
$entry['tag'] = $tag;
- ApiResult::setContent( $entry, $content );
- $result[] = $entry;
- }
-
- return $result;
- }
-
- private function formatProperties( $properties ) {
- $result = array();
- foreach ( $properties as $name => $value ) {
- $entry = array();
- $entry['name'] = $name;
- ApiResult::setContent( $entry, $value );
+ ApiResult::setContentValue( $entry, 'content', $content );
$result[] = $entry;
}
@@ -628,7 +640,7 @@ class ApiParse extends ApiBase {
foreach ( $css as $file => $link ) {
$entry = array();
$entry['file'] = $file;
- ApiResult::setContent( $entry, $link );
+ ApiResult::setContentValue( $entry, 'link', $link );
$result[] = $entry;
}
@@ -645,8 +657,7 @@ class ApiParse extends ApiBase {
if ( !is_array( $value ) ) {
$value = array( $value );
}
- $apiResult->setIndexedTagName( $value, 'param' );
- $apiResult->setIndexedTagName_recursive( $value, 'param' );
+ ApiResult::setIndexedTagNameRecursive( $value, 'param' );
$entry = array_merge( $entry, $value );
$result[] = $entry;
}
@@ -657,7 +668,7 @@ class ApiParse extends ApiBase {
private function setIndexedTagNames( &$array, $mapping ) {
foreach ( $mapping as $key => $name ) {
if ( isset( $array[$key] ) ) {
- $this->getResult()->setIndexedTagName( $array[$key], $name );
+ ApiResult::setIndexedTagName( $array[$key], $name );
}
}
}
@@ -694,6 +705,7 @@ class ApiParse extends ApiBase {
'headitems',
'headhtml',
'modules',
+ 'indicators',
'iwlinks',
'wikitext',
'properties',
@@ -704,11 +716,18 @@ class ApiParse extends ApiBase {
'pst' => false,
'onlypst' => false,
'effectivelanglinks' => false,
- 'uselang' => null,
'section' => null,
+ 'sectiontitle' => array(
+ ApiBase::PARAM_TYPE => 'string',
+ ),
'disablepp' => false,
'disableeditsection' => false,
- 'generatexml' => false,
+ 'generatexml' => array(
+ ApiBase::PARAM_DFLT => false,
+ ApiBase::PARAM_HELP_MSG => array(
+ 'apihelp-parse-param-generatexml', CONTENT_MODEL_WIKITEXT
+ ),
+ ),
'preview' => false,
'sectionpreview' => false,
'disabletoc' => false,
@@ -721,97 +740,16 @@ 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',
- 'redirects' => "If the {$p}page or the {$p}pageid parameter is set to a redirect, resolve it",
- 'title' => "Title of page the text belongs to. " .
- "If omitted, {$p}contentmodel must be specified, and \"API\" will be used as the title",
- 'page' => "Parse the content of this page. Cannot be used together with {$p}text and {$p}title",
- 'pageid' => "Parse the content of this page. Overrides {$p}page",
- 'oldid' => "Parse the content of this revision. Overrides {$p}page and {$p}pageid",
- 'prop' => array(
- 'Which pieces of information to get',
- ' text - Gives the parsed text of the wikitext',
- ' langlinks - Gives the language links in the parsed wikitext',
- ' categories - Gives the categories in the parsed wikitext',
- ' categorieshtml - Gives the HTML version of the categories',
- ' links - Gives the internal links in the parsed wikitext',
- ' templates - Gives the templates in the parsed wikitext',
- ' images - Gives the images in the parsed wikitext',
- ' externallinks - Gives the external links in the parsed wikitext',
- ' sections - Gives the sections in the parsed wikitext',
- ' revid - Adds the revision ID of the parsed page',
- ' displaytitle - Adds the title of the parsed wikitext',
- ' headitems - Gives items to put in the <head> of the page',
- ' headhtml - Gives parsed <head> of the page',
- ' modules - Gives the ResourceLoader modules used on the page',
- ' iwlinks - Gives interwiki links in the parsed wikitext',
- ' wikitext - Gives the original wikitext that was parsed',
- ' properties - Gives various properties defined in the parsed wikitext',
- ' limitreportdata - Gives the limit report in a structured way.',
- " Gives no data, when {$p}disablepp is set.",
- ' limitreporthtml - Gives the HTML version of the limit report.',
- " Gives no data, when {$p}disablepp is set.",
- ),
- 'effectivelanglinks' => array(
- 'Includes language links supplied by extensions',
- '(for use with prop=langlinks)',
- ),
- 'pst' => array(
- 'Do a pre-save transform on the input before parsing it',
- "Only valid when used with {$p}text",
- ),
- 'onlypst' => array(
- 'Do a pre-save transform (PST) on the input, but don\'t parse it',
- 'Returns the same wikitext, after a PST has been applied.',
- "Only valid when used with {$p}text",
- ),
- 'uselang' => 'Which language to parse the request in',
- 'section' => 'Only retrieve the content of this section number',
- 'disablepp' => 'Disable the PP Report from the parser output',
- 'disableeditsection' => 'Disable edit section links from the parser output',
- 'generatexml' => "Generate XML parse tree (requires contentmodel=$wikitext)",
- 'preview' => 'Parse in preview mode',
- 'sectionpreview' => 'Parse in section preview mode (enables preview mode too)',
- 'disabletoc' => 'Disable table of contents in output',
- 'contentformat' => array(
- 'Content serialization format used for the input text',
- "Only valid when used with {$p}text",
- ),
- 'contentmodel' => array(
- "Content model of the input text. If omitted, ${p}title must be specified, " .
- "and default will be the model of the specified ${p}title",
- "Only valid when used with {$p}text",
- ),
- );
- }
-
- 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.',
- 'There are several ways to specify the text to parse:',
- "1) Specify a page or revision, using {$p}page, {$p}pageid, or {$p}oldid.",
- "2) Specify content explicitly, using {$p}text, {$p}title, and {$p}contentmodel.",
- "3) Specify only a summary to parse. {$p}prop should be given an empty value.",
- );
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=parse&page=Project:Sandbox' => 'Parse a page',
- 'api.php?action=parse&text={{Project:Sandbox}}&contentmodel=wikitext' => 'Parse wikitext',
- 'api.php?action=parse&text={{PAGENAME}}&title=Test'
- => 'Parse wikitext, specifying the page title',
- 'api.php?action=parse&summary=Some+[[link]]&prop=' => 'Parse a summary',
+ 'action=parse&page=Project:Sandbox'
+ => 'apihelp-parse-example-page',
+ 'action=parse&text={{Project:Sandbox}}&contentmodel=wikitext'
+ => 'apihelp-parse-example-text',
+ 'action=parse&text={{PAGENAME}}&title=Test'
+ => 'apihelp-parse-example-texttitle',
+ 'action=parse&summary=Some+[[link]]&prop='
+ => 'apihelp-parse-example-summary',
);
}
diff --git a/includes/api/ApiPatrol.php b/includes/api/ApiPatrol.php
index 8b66781a..779c4188 100644
--- a/includes/api/ApiPatrol.php
+++ b/includes/api/ApiPatrol.php
@@ -38,7 +38,7 @@ class ApiPatrol extends ApiBase {
$this->requireOnlyOneParameter( $params, 'rcid', 'revid' );
if ( isset( $params['rcid'] ) ) {
- $rc = RecentChange::newFromID( $params['rcid'] );
+ $rc = RecentChange::newFromId( $params['rcid'] );
if ( !$rc ) {
$this->dieUsageMsg( array( 'nosuchrcid', $params['rcid'] ) );
}
@@ -86,25 +86,16 @@ class ApiPatrol extends ApiBase {
);
}
- public function getParamDescription() {
- return array(
- 'rcid' => 'Recentchanges ID to patrol',
- 'revid' => 'Revision ID to patrol',
- );
- }
-
- public function getDescription() {
- return 'Patrol a page or revision.';
- }
-
public function needsToken() {
return 'patrol';
}
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=patrol&token=123ABC&rcid=230672766',
- 'api.php?action=patrol&token=123ABC&revid=230672766'
+ 'action=patrol&token=123ABC&rcid=230672766'
+ => 'apihelp-patrol-example-rcid',
+ 'action=patrol&token=123ABC&revid=230672766'
+ => 'apihelp-patrol-example-revid',
);
}
diff --git a/includes/api/ApiProtect.php b/includes/api/ApiProtect.php
index a3d12b7f..ad028375 100644
--- a/includes/api/ApiProtect.php
+++ b/includes/api/ApiProtect.php
@@ -77,7 +77,7 @@ class ApiProtect extends ApiBase {
$this->dieUsageMsg( array( 'protect-invalidlevel', $p[1] ) );
}
- if ( in_array( $expiry[$i], array( 'infinite', 'indefinite', 'infinity', 'never' ) ) ) {
+ if ( wfIsInfinity( $expiry[$i] ) ) {
$expiryarray[$p[0]] = $db->getInfinity();
} else {
$exp = strtotime( $expiry[$i] );
@@ -124,11 +124,11 @@ class ApiProtect extends ApiBase {
'reason' => $params['reason']
);
if ( $cascade ) {
- $res['cascade'] = '';
+ $res['cascade'] = true;
}
$res['protections'] = $resultProtections;
$result = $this->getResult();
- $result->setIndexedTagName( $res['protections'], 'protection' );
+ ApiResult::setIndexedTagName( $res['protections'], 'protection' );
$result->addValue( null, $this->getModuleName(), $res );
}
@@ -175,43 +175,21 @@ 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",
- '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\', \'infinity\' 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\''
- ),
- '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',
- );
- }
-
- public function getDescription() {
- return 'Change the protection level of a page.';
- }
-
public function needsToken() {
return 'csrf';
}
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=protect&title=Main%20Page&token=123ABC&' .
- 'protections=edit=sysop|move=sysop&cascade=&expiry=20070901163000|never',
- 'api.php?action=protect&title=Main%20Page&token=123ABC&' .
+ 'action=protect&title=Main%20Page&token=123ABC&' .
+ 'protections=edit=sysop|move=sysop&cascade=&expiry=20070901163000|never'
+ => 'apihelp-protect-example-protect',
+ 'action=protect&title=Main%20Page&token=123ABC&' .
'protections=edit=all|move=all&reason=Lifting%20restrictions'
+ => 'apihelp-protect-example-unprotect',
+ 'action=protect&title=Main%20Page&token=123ABC&' .
+ 'protections=&reason=Lifting%20restrictions'
+ => 'apihelp-protect-example-unprotect2',
);
}
diff --git a/includes/api/ApiPurge.php b/includes/api/ApiPurge.php
index 7667b235..a22be498 100644
--- a/includes/api/ApiPurge.php
+++ b/includes/api/ApiPurge.php
@@ -38,7 +38,8 @@ class ApiPurge extends ApiBase {
public function execute() {
$params = $this->extractRequestParams();
- $this->getResult()->beginContinuation( $params['continue'], array(), array() );
+ $continuationManager = new ApiContinuationManager( $this, array(), array() );
+ $this->setContinuationManager( $continuationManager );
$forceLinkUpdate = $params['forcelinkupdate'];
$forceRecursiveLinkUpdate = $params['forcerecursivelinkupdate'];
@@ -52,7 +53,7 @@ class ApiPurge extends ApiBase {
ApiQueryBase::addTitleInfo( $r, $title );
$page = WikiPage::factory( $title );
$page->doPurge(); // Directly purge and skip the UI part of purge().
- $r['purged'] = '';
+ $r['purged'] = true;
if ( $forceLinkUpdate || $forceRecursiveLinkUpdate ) {
if ( !$this->getUser()->pingLimiter( 'linkpurge' ) ) {
@@ -73,7 +74,7 @@ class ApiPurge extends ApiBase {
$title, null, $forceRecursiveLinkUpdate, $p_result );
DataUpdate::runUpdates( $updates );
- $r['linkupdate'] = '';
+ $r['linkupdate'] = true;
if ( $enableParserCache ) {
$pcache = ParserCache::singleton();
@@ -89,7 +90,7 @@ class ApiPurge extends ApiBase {
$result[] = $r;
}
$apiResult = $this->getResult();
- $apiResult->setIndexedTagName( $result, 'page' );
+ ApiResult::setIndexedTagName( $result, 'page' );
$apiResult->addValue( null, $this->getModuleName(), $result );
$values = $pageSet->getNormalizedTitlesAsResult( $apiResult );
@@ -105,7 +106,8 @@ class ApiPurge extends ApiBase {
$apiResult->addValue( null, 'redirects', $values );
}
- $apiResult->endContinuation();
+ $this->setContinuationManager( null );
+ $continuationManager->setContinuationIntoResult( $apiResult );
}
/**
@@ -133,7 +135,9 @@ class ApiPurge extends ApiBase {
$result = array(
'forcelinkupdate' => false,
'forcerecursivelinkupdate' => false,
- 'continue' => '',
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ),
);
if ( $flags ) {
$result += $this->getPageSet()->getFinalParams( $flags );
@@ -142,25 +146,12 @@ class ApiPurge extends ApiBase {
return $result;
}
- public function getParamDescription() {
- return $this->getPageSet()->getFinalParamDescription()
- + array(
- 'forcelinkupdate' => 'Update the links tables',
- 'forcerecursivelinkupdate' => 'Update the links table, and update ' .
- 'the links tables for any page that uses this page as a template',
- 'continue' => 'When more results are available, use this to continue',
- );
- }
-
- public function getDescription() {
- return array( 'Purge the cache for the given titles.',
- 'Requires a POST request if the user is not logged in.'
- );
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=purge&titles=Main_Page|API' => 'Purge the "Main Page" and the "API" page',
+ 'action=purge&titles=Main_Page|API'
+ => 'apihelp-purge-example-simple',
+ 'action=purge&generator=allpages&gapnamespace=0&gaplimit=10'
+ => 'apihelp-purge-example-generator',
);
}
diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php
index 7c750e41..bfe32052 100644
--- a/includes/api/ApiQuery.php
+++ b/includes/api/ApiQuery.php
@@ -45,6 +45,7 @@ class ApiQuery extends ApiBase {
'categories' => 'ApiQueryCategories',
'categoryinfo' => 'ApiQueryCategoryInfo',
'contributors' => 'ApiQueryContributors',
+ 'deletedrevisions' => 'ApiQueryDeletedRevisions',
'duplicatefiles' => 'ApiQueryDuplicateFiles',
'extlinks' => 'ApiQueryExternalLinks',
'fileusage' => 'ApiQueryBacklinksprop',
@@ -69,6 +70,7 @@ class ApiQuery extends ApiBase {
*/
private static $QueryListModules = array(
'allcategories' => 'ApiQueryAllCategories',
+ 'alldeletedrevisions' => 'ApiQueryAllDeletedRevisions',
'allfileusages' => 'ApiQueryAllLinks',
'allimages' => 'ApiQueryAllImages',
'alllinks' => 'ApiQueryAllLinks',
@@ -141,6 +143,8 @@ class ApiQuery extends ApiBase {
$this->mModuleMgr->addModules( self::$QueryMetaModules, 'meta' );
$this->mModuleMgr->addModules( $config->get( 'APIMetaModules' ), 'meta' );
+ Hooks::run( 'ApiQuery::moduleManager', array( $this->mModuleMgr ) );
+
// Create PageSet that will process titles/pageids/revids/generator
$this->mPageSet = new ApiPageSet( $this );
}
@@ -165,9 +169,7 @@ class ApiQuery extends ApiBase {
*/
public function getNamedDB( $name, $db, $groups ) {
if ( !array_key_exists( $name, $this->mNamedDB ) ) {
- $this->profileDBIn();
$this->mNamedDB[$name] = wfGetDB( $db, $groups );
- $this->profileDBOut();
}
return $this->mNamedDB[$name];
@@ -255,11 +257,11 @@ class ApiQuery extends ApiBase {
$this->instantiateModules( $allModules, 'meta' );
// Filter modules based on continue parameter
- list( $generatorDone, $modules ) = $this->getResult()->beginContinuation(
- $this->mParams['continue'], $allModules, $propModules
- );
+ $continuationManager = new ApiContinuationManager( $this, $allModules, $propModules );
+ $this->setContinuationManager( $continuationManager );
+ $modules = $continuationManager->getRunModules();
- if ( !$generatorDone ) {
+ if ( !$continuationManager->isGeneratorDone() ) {
// Query modules may optimize data requests through the $this->getPageSet()
// object by adding extra fields from the page table.
foreach ( $modules as $module ) {
@@ -281,19 +283,36 @@ class ApiQuery extends ApiBase {
$params = $module->extractRequestParams();
$cacheMode = $this->mergeCacheMode(
$cacheMode, $module->getCacheMode( $params ) );
- $module->profileIn();
$module->execute();
- wfRunHooks( 'APIQueryAfterExecute', array( &$module ) );
- $module->profileOut();
+ Hooks::run( 'APIQueryAfterExecute', array( &$module ) );
}
// Set the cache mode
$this->getMain()->setCacheMode( $cacheMode );
// Write the continuation data into the result
- $this->getResult()->endContinuation(
- $this->mParams['continue'] === null ? 'raw' : 'standard'
- );
+ $this->setContinuationManager( null );
+ if ( $this->mParams['continue'] === null ) {
+ $data = $continuationManager->getRawContinuation();
+ if ( $data ) {
+ $this->getResult()->addValue( null, 'query-continue', $data,
+ ApiResult::ADD_ON_TOP | ApiResult::NO_SIZE_CHECK );
+ }
+ } else {
+ $continuationManager->setContinuationIntoResult( $this->getResult() );
+ }
+
+ if ( $this->mParams['continue'] === null && !$this->mParams['rawcontinue'] &&
+ $this->getResult()->getResultData( 'query-continue' ) !== null
+ ) {
+ $this->logFeatureUsage( 'action=query&!rawcontinue&!continue' );
+ $this->setWarning(
+ 'Formatting of continuation data will be changing soon. ' .
+ 'To continue using the current formatting, use the \'rawcontinue\' parameter. ' .
+ 'To begin using the new format, pass an empty string for \'continue\' ' .
+ 'in the initial query.'
+ );
+ }
}
/**
@@ -384,18 +403,18 @@ class ApiQuery extends ApiBase {
foreach ( $pageSet->getMissingTitles() as $fakeId => $title ) {
$vals = array();
ApiQueryBase::addTitleInfo( $vals, $title );
- $vals['missing'] = '';
+ $vals['missing'] = true;
$pages[$fakeId] = $vals;
}
// Report any invalid titles
foreach ( $pageSet->getInvalidTitles() as $fakeId => $title ) {
- $pages[$fakeId] = array( 'title' => $title, 'invalid' => '' );
+ $pages[$fakeId] = array( 'title' => $title, 'invalid' => true );
}
// Report any missing page ids
foreach ( $pageSet->getMissingPageIDs() as $pageid ) {
$pages[$pageid] = array(
'pageid' => $pageid,
- 'missing' => ''
+ 'missing' => true
);
}
// Report special pages
@@ -403,15 +422,15 @@ class ApiQuery extends ApiBase {
foreach ( $pageSet->getSpecialTitles() as $fakeId => $title ) {
$vals = array();
ApiQueryBase::addTitleInfo( $vals, $title );
- $vals['special'] = '';
+ $vals['special'] = true;
if ( $title->isSpecialPage() &&
!SpecialPageFactory::exists( $title->getDBkey() )
) {
- $vals['missing'] = '';
+ $vals['missing'] = true;
} elseif ( $title->getNamespace() == NS_MEDIA &&
!wfFindFile( $title )
) {
- $vals['missing'] = '';
+ $vals['missing'] = true;
}
$pages[$fakeId] = $vals;
}
@@ -425,15 +444,18 @@ class ApiQuery extends ApiBase {
}
if ( count( $pages ) ) {
+ $pageSet->populateGeneratorData( $pages );
+ ApiResult::setArrayType( $pages, 'BCarray' );
+
if ( $this->mParams['indexpageids'] ) {
- $pageIDs = array_keys( $pages );
+ $pageIDs = array_keys( ApiResult::stripMetadataNonRecursive( $pages ) );
// json treats all map keys as strings - converting to match
$pageIDs = array_map( 'strval', $pageIDs );
- $result->setIndexedTagName( $pageIDs, 'id' );
+ ApiResult::setIndexedTagName( $pageIDs, 'id' );
$fit = $fit && $result->addValue( 'query', 'pageids', $pageIDs );
}
- $result->setIndexedTagName( $pages, 'page' );
+ ApiResult::setIndexedTagName( $pages, 'page' );
$fit = $fit && $result->addValue( 'query', 'pages', $pages );
}
@@ -462,7 +484,7 @@ class ApiQuery extends ApiBase {
*/
public function setGeneratorContinue( $module, $paramName, $paramValue ) {
wfDeprecated( __METHOD__, '1.24' );
- $this->getResult()->setGeneratorContinueParam( $module, $paramName, $paramValue );
+ $this->getContinuationManager()->addGeneratorContinueParam( $module, $paramName, $paramValue );
return $this->getParameter( 'continue' ) !== null;
}
@@ -504,9 +526,8 @@ class ApiQuery extends ApiBase {
$result->addValue( null, 'text', $exportxml, ApiResult::NO_SIZE_CHECK );
$result->addValue( null, 'mime', 'text/xml', ApiResult::NO_SIZE_CHECK );
} else {
- $r = array();
- ApiResult::setContent( $r, $exportxml );
- $result->addValue( 'query', 'export', $r, ApiResult::NO_SIZE_CHECK );
+ $result->addValue( 'query', 'export', $exportxml, ApiResult::NO_SIZE_CHECK );
+ $result->addValue( 'query', ApiResult::META_BC_SUBELEMENTS, array( 'export' ) );
}
}
@@ -540,9 +561,11 @@ class ApiQuery extends ApiBase {
/**
* Override the parent to generate help messages for all available query modules.
+ * @deprecated since 1.25
* @return string
*/
public function makeHelpMsg() {
+ wfDeprecated( __METHOD__, '1.25' );
// Use parent to make default message for the query module
$msg = parent::makeHelpMsg();
@@ -562,6 +585,7 @@ class ApiQuery extends ApiBase {
/**
* For all modules of a given group, generate help messages and join them together
+ * @deprecated since 1.25
* @param string $group Module group
* @return string
*/
@@ -594,44 +618,13 @@ class ApiQuery extends ApiBase {
return true;
}
- public function getParamDescription() {
- return $this->getPageSet()->getFinalParamDescription() + array(
- 'prop' => 'Which properties to get for the titles/revisions/pageids. ' .
- 'Module help is available below',
- 'list' => 'Which lists to get. Module help is available below',
- 'meta' => 'Which metadata to get about the site. Module help is available below',
- 'indexpageids' => 'Include an additional pageids section listing all returned page IDs',
- 'export' => 'Export the current revisions of all given or generated pages',
- 'exportnowrap' => 'Return the export XML without wrapping it in an ' .
- 'XML result (same format as Special:Export). Can only be used with export',
- 'iwurl' => 'Whether to get the full URL if the title is an interwiki link',
- 'continue' => array(
- 'When present, formats query-continue as key-value pairs that ' .
- 'should simply be merged into the original request.',
- 'This parameter must be set to an empty string in the initial query.',
- 'This parameter is recommended for all new development, and ' .
- 'will be made default in the next API version.'
- ),
- 'rawcontinue' => 'Currently ignored. In the future, \'continue=\' will become the ' .
- 'default and this will be needed to receive the raw query-continue data.',
- );
- }
-
- public function getDescription() {
- 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 getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&prop=revisions&meta=siteinfo&' .
- 'titles=Main%20Page&rvprop=user|comment&continue=',
- 'api.php?action=query&generator=allpages&gapprefix=API/&prop=revisions&continue=',
+ 'action=query&prop=revisions&meta=siteinfo&' .
+ 'titles=Main%20Page&rvprop=user|comment&continue='
+ => 'apihelp-query-example-revisions',
+ 'action=query&generator=allpages&gapprefix=API/&prop=revisions&continue='
+ => 'apihelp-query-example-allpages',
);
}
diff --git a/includes/api/ApiQueryAllCategories.php b/includes/api/ApiQueryAllCategories.php
index 79fab727..cc0b71af 100644
--- a/includes/api/ApiQueryAllCategories.php
+++ b/includes/api/ApiQueryAllCategories.php
@@ -128,15 +128,15 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
$pages[] = $titleObj;
} else {
$item = array();
- ApiResult::setContent( $item, $titleObj->getText() );
+ ApiResult::setContentValue( $item, 'category', $titleObj->getText() );
if ( isset( $prop['size'] ) ) {
$item['size'] = intval( $row->cat_pages );
$item['pages'] = $row->cat_pages - $row->cat_subcats - $row->cat_files;
$item['files'] = intval( $row->cat_files );
$item['subcats'] = intval( $row->cat_subcats );
}
- if ( isset( $prop['hidden'] ) && $row->cat_hidden ) {
- $item['hidden'] = '';
+ if ( isset( $prop['hidden'] ) ) {
+ $item['hidden'] = (bool)$row->cat_hidden;
}
$fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $item );
if ( !$fit ) {
@@ -147,7 +147,7 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
}
if ( is_null( $resultPageSet ) ) {
- $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'c' );
+ $result->addIndexedTagName( array( 'query', $this->getModuleName() ), 'c' );
} else {
$resultPageSet->populateFromTitles( $pages );
}
@@ -156,7 +156,9 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
public function getAllowedParams() {
return array(
'from' => null,
- 'continue' => null,
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ),
'to' => null,
'prefix' => null,
'dir' => array(
@@ -189,32 +191,12 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
);
}
- public function getParamDescription() {
- return array(
- 'from' => 'The category to start enumerating from',
- 'continue' => 'When more results are available, use this to continue',
- 'to' => 'The category to stop enumerating at',
- 'prefix' => 'Search for all category titles that begin with this value',
- 'dir' => 'Direction to sort in',
- 'min' => 'Minimum number of category members',
- 'max' => 'Maximum number of category members',
- 'limit' => 'How many categories to return',
- 'prop' => array(
- 'Which properties to get',
- ' size - Adds number of pages in the category',
- ' hidden - Tags categories that are hidden with __HIDDENCAT__',
- ),
- );
- }
-
- public function getDescription() {
- return 'Enumerate all categories.';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&list=allcategories&acprop=size',
- 'api.php?action=query&generator=allcategories&gacprefix=List&prop=info',
+ 'action=query&list=allcategories&acprop=size'
+ => 'apihelp-query+allcategories-example-size',
+ 'action=query&generator=allcategories&gacprefix=List&prop=info'
+ => 'apihelp-query+allcategories-example-generator',
);
}
diff --git a/includes/api/ApiQueryAllDeletedRevisions.php b/includes/api/ApiQueryAllDeletedRevisions.php
new file mode 100644
index 00000000..4e4d2af7
--- /dev/null
+++ b/includes/api/ApiQueryAllDeletedRevisions.php
@@ -0,0 +1,427 @@
+<?php
+/**
+ * Created on Oct 3, 2014
+ *
+ * Copyright © 2014 Brad Jorsch "bjorsch@wikimedia.org"
+ *
+ * Heavily based on ApiQueryDeletedrevs,
+ * Copyright © 2007 Roan Kattouw "<Firstname>.<Lastname>@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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * Query module to enumerate all deleted revisions.
+ *
+ * @ingroup API
+ */
+class ApiQueryAllDeletedRevisions extends ApiQueryRevisionsBase {
+
+ public function __construct( ApiQuery $query, $moduleName ) {
+ parent::__construct( $query, $moduleName, 'adr' );
+ }
+
+ /**
+ * @param ApiPageSet $resultPageSet
+ * @return void
+ */
+ protected function run( ApiPageSet $resultPageSet = null ) {
+ $user = $this->getUser();
+ // Before doing anything at all, let's check permissions
+ if ( !$user->isAllowed( 'deletedhistory' ) ) {
+ $this->dieUsage(
+ 'You don\'t have permission to view deleted revision information',
+ 'permissiondenied'
+ );
+ }
+
+ $db = $this->getDB();
+ $params = $this->extractRequestParams( false );
+
+ $result = $this->getResult();
+ $pageSet = $this->getPageSet();
+ $titles = $pageSet->getTitles();
+
+ // This module operates in two modes:
+ // 'user': List deleted revs by a certain user
+ // 'all': List all deleted revs in NS
+ $mode = 'all';
+ if ( !is_null( $params['user'] ) ) {
+ $mode = 'user';
+ }
+
+ if ( $mode == 'user' ) {
+ foreach ( array( 'from', 'to', 'prefix', 'excludeuser' ) as $param ) {
+ if ( !is_null( $params[$param] ) ) {
+ $p = $this->getModulePrefix();
+ $this->dieUsage( "The '{$p}{$param}' parameter cannot be used with '{$p}user'",
+ 'badparams' );
+ }
+ }
+ } else {
+ foreach ( array( 'start', 'end' ) as $param ) {
+ if ( !is_null( $params[$param] ) ) {
+ $p = $this->getModulePrefix();
+ $this->dieUsage( "The '{$p}{$param}' parameter may only be used with '{$p}user'",
+ 'badparams' );
+ }
+ }
+ }
+
+ $this->addTables( 'archive' );
+ if ( $resultPageSet === null ) {
+ $this->parseParameters( $params );
+ $this->addFields( Revision::selectArchiveFields() );
+ $this->addFields( array( 'ar_title', 'ar_namespace' ) );
+ } else {
+ $this->limit = $this->getParameter( 'limit' ) ?: 10;
+ $this->addFields( array( 'ar_title', 'ar_namespace', 'ar_timestamp', 'ar_rev_id', 'ar_id' ) );
+ }
+
+ if ( $this->fld_tags ) {
+ $this->addTables( 'tag_summary' );
+ $this->addJoinConds(
+ array( 'tag_summary' => array( 'LEFT JOIN', array( 'ar_rev_id=ts_rev_id' ) ) )
+ );
+ $this->addFields( 'ts_tags' );
+ }
+
+ if ( !is_null( $params['tag'] ) ) {
+ $this->addTables( 'change_tag' );
+ $this->addJoinConds(
+ array( 'change_tag' => array( 'INNER JOIN', array( 'ar_rev_id=ct_rev_id' ) ) )
+ );
+ $this->addWhereFld( 'ct_tag', $params['tag'] );
+ }
+
+ if ( $this->fetchContent ) {
+ // Modern MediaWiki has the content for deleted revs in the 'text'
+ // table using fields old_text and old_flags. But revisions deleted
+ // pre-1.5 store the content in the 'archive' table directly using
+ // fields ar_text and ar_flags, and no corresponding 'text' row. So
+ // we have to LEFT JOIN and fetch all four fields.
+ $this->addTables( 'text' );
+ $this->addJoinConds(
+ array( 'text' => array( 'LEFT JOIN', array( 'ar_text_id=old_id' ) ) )
+ );
+ $this->addFields( array( 'ar_text', 'ar_flags', 'old_text', 'old_flags' ) );
+
+ // This also means stricter restrictions
+ if ( !$user->isAllowedAny( 'undelete', 'deletedtext' ) ) {
+ $this->dieUsage(
+ 'You don\'t have permission to view deleted revision content',
+ 'permissiondenied'
+ );
+ }
+ }
+
+ $dir = $params['dir'];
+ $miser_ns = null;
+
+ if ( $mode == 'all' ) {
+ if ( $params['namespace'] !== null ) {
+ $namespaces = $params['namespace'];
+ $this->addWhereFld( 'ar_namespace', $namespaces );
+ } else {
+ $namespaces = MWNamespace::getValidNamespaces();
+ }
+
+ // For from/to/prefix, we have to consider the potential
+ // transformations of the title in all specified namespaces.
+ // Generally there will be only one transformation, but wikis with
+ // some namespaces case-sensitive could have two.
+ if ( $params['from'] !== null || $params['to'] !== null ) {
+ $isDirNewer = ( $dir === 'newer' );
+ $after = ( $isDirNewer ? '>=' : '<=' );
+ $before = ( $isDirNewer ? '<=' : '>=' );
+ $where = array();
+ foreach ( $namespaces as $ns ) {
+ $w = array();
+ if ( $params['from'] !== null ) {
+ $w[] = 'ar_title' . $after .
+ $db->addQuotes( $this->titlePartToKey( $params['from'], $ns ) );
+ }
+ if ( $params['to'] !== null ) {
+ $w[] = 'ar_title' . $before .
+ $db->addQuotes( $this->titlePartToKey( $params['to'], $ns ) );
+ }
+ $w = $db->makeList( $w, LIST_AND );
+ $where[$w][] = $ns;
+ }
+ if ( count( $where ) == 1 ) {
+ $where = key( $where );
+ $this->addWhere( $where );
+ } else {
+ $where2 = array();
+ foreach ( $where as $w => $ns ) {
+ $where2[] = $db->makeList( array( $w, 'ar_namespace' => $ns ), LIST_AND );
+ }
+ $this->addWhere( $db->makeList( $where2, LIST_OR ) );
+ }
+ }
+
+ if ( isset( $params['prefix'] ) ) {
+ $where = array();
+ foreach ( $namespaces as $ns ) {
+ $w = 'ar_title' . $db->buildLike(
+ $this->titlePartToKey( $params['prefix'], $ns ),
+ $db->anyString() );
+ $where[$w][] = $ns;
+ }
+ if ( count( $where ) == 1 ) {
+ $where = key( $where );
+ $this->addWhere( $where );
+ } else {
+ $where2 = array();
+ foreach ( $where as $w => $ns ) {
+ $where2[] = $db->makeList( array( $w, 'ar_namespace' => $ns ), LIST_AND );
+ }
+ $this->addWhere( $db->makeList( $where2, LIST_OR ) );
+ }
+ }
+ } else {
+ if ( $this->getConfig()->get( 'MiserMode' ) ) {
+ $miser_ns = $params['namespace'];
+ } else {
+ $this->addWhereFld( 'ar_namespace', $params['namespace'] );
+ }
+ $this->addTimestampWhereRange( 'ar_timestamp', $dir, $params['start'], $params['end'] );
+ }
+
+ if ( !is_null( $params['user'] ) ) {
+ $this->addWhereFld( 'ar_user_text', $params['user'] );
+ } elseif ( !is_null( $params['excludeuser'] ) ) {
+ $this->addWhere( 'ar_user_text != ' .
+ $db->addQuotes( $params['excludeuser'] ) );
+ }
+
+ if ( !is_null( $params['user'] ) || !is_null( $params['excludeuser'] ) ) {
+ // Paranoia: avoid brute force searches (bug 17342)
+ // (shouldn't be able to get here without 'deletedhistory', but
+ // check it again just in case)
+ if ( !$user->isAllowed( 'deletedhistory' ) ) {
+ $bitmask = Revision::DELETED_USER;
+ } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
+ $bitmask = Revision::DELETED_USER | Revision::DELETED_RESTRICTED;
+ } else {
+ $bitmask = 0;
+ }
+ if ( $bitmask ) {
+ $this->addWhere( $db->bitAnd( 'ar_deleted', $bitmask ) . " != $bitmask" );
+ }
+ }
+
+ if ( !is_null( $params['continue'] ) ) {
+ $cont = explode( '|', $params['continue'] );
+ $op = ( $dir == 'newer' ? '>' : '<' );
+ if ( $mode == 'all' ) {
+ $this->dieContinueUsageIf( count( $cont ) != 4 );
+ $ns = intval( $cont[0] );
+ $this->dieContinueUsageIf( strval( $ns ) !== $cont[0] );
+ $title = $db->addQuotes( $cont[1] );
+ $ts = $db->addQuotes( $db->timestamp( $cont[2] ) );
+ $ar_id = (int)$cont[3];
+ $this->dieContinueUsageIf( strval( $ar_id ) !== $cont[3] );
+ $this->addWhere( "ar_namespace $op $ns OR " .
+ "(ar_namespace = $ns AND " .
+ "(ar_title $op $title OR " .
+ "(ar_title = $title AND " .
+ "(ar_timestamp $op $ts OR " .
+ "(ar_timestamp = $ts AND " .
+ "ar_id $op= $ar_id)))))" );
+ } else {
+ $this->dieContinueUsageIf( count( $cont ) != 2 );
+ $ts = $db->addQuotes( $db->timestamp( $cont[0] ) );
+ $ar_id = (int)$cont[1];
+ $this->dieContinueUsageIf( strval( $ar_id ) !== $cont[1] );
+ $this->addWhere( "ar_timestamp $op $ts OR " .
+ "(ar_timestamp = $ts AND " .
+ "ar_id $op= $ar_id)" );
+ }
+ }
+
+ $this->addOption( 'LIMIT', $this->limit + 1 );
+
+ $sort = ( $dir == 'newer' ? '' : ' DESC' );
+ $orderby = array();
+ if ( $mode == 'all' ) {
+ // Targeting index name_title_timestamp
+ if ( $params['namespace'] === null || count( array_unique( $params['namespace'] ) ) > 1 ) {
+ $orderby[] = "ar_namespace $sort";
+ }
+ $orderby[] = "ar_title $sort";
+ $orderby[] = "ar_timestamp $sort";
+ $orderby[] = "ar_id $sort";
+ } else {
+ // Targeting index usertext_timestamp
+ // 'user' is always constant.
+ $orderby[] = "ar_timestamp $sort";
+ $orderby[] = "ar_id $sort";
+ }
+ $this->addOption( 'ORDER BY', $orderby );
+
+ $res = $this->select( __METHOD__ );
+ $pageMap = array(); // Maps ns&title to array index
+ $count = 0;
+ $nextIndex = 0;
+ $generated = array();
+ foreach ( $res as $row ) {
+ if ( ++$count > $this->limit ) {
+ // We've had enough
+ if ( $mode == 'all' ) {
+ $this->setContinueEnumParameter( 'continue',
+ "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
+ );
+ } else {
+ $this->setContinueEnumParameter( 'continue', "$row->ar_timestamp|$row->ar_id" );
+ }
+ break;
+ }
+
+ // Miser mode namespace check
+ if ( $miser_ns !== null && !in_array( $row->ar_namespace, $miser_ns ) ) {
+ continue;
+ }
+
+ if ( $resultPageSet !== null ) {
+ if ( $params['generatetitles'] ) {
+ $key = "{$row->ar_namespace}:{$row->ar_title}";
+ if ( !isset( $generated[$key] ) ) {
+ $generated[$key] = Title::makeTitle( $row->ar_namespace, $row->ar_title );
+ }
+ } else {
+ $generated[] = $row->ar_rev_id;
+ }
+ } else {
+ $revision = Revision::newFromArchiveRow( $row );
+ $rev = $this->extractRevisionInfo( $revision, $row );
+
+ if ( !isset( $pageMap[$row->ar_namespace][$row->ar_title] ) ) {
+ $index = $nextIndex++;
+ $pageMap[$row->ar_namespace][$row->ar_title] = $index;
+ $title = $revision->getTitle();
+ $a = array(
+ 'pageid' => $title->getArticleID(),
+ 'revisions' => array( $rev ),
+ );
+ ApiResult::setIndexedTagName( $a['revisions'], 'rev' );
+ ApiQueryBase::addTitleInfo( $a, $title );
+ $fit = $result->addValue( array( 'query', $this->getModuleName() ), $index, $a );
+ } else {
+ $index = $pageMap[$row->ar_namespace][$row->ar_title];
+ $fit = $result->addValue(
+ array( 'query', $this->getModuleName(), $index, 'revisions' ),
+ null, $rev );
+ }
+ if ( !$fit ) {
+ if ( $mode == 'all' ) {
+ $this->setContinueEnumParameter( 'continue',
+ "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
+ );
+ } else {
+ $this->setContinueEnumParameter( 'continue', "$row->ar_timestamp|$row->ar_id" );
+ }
+ break;
+ }
+ }
+ }
+
+ if ( $resultPageSet !== null ) {
+ if ( $params['generatetitles'] ) {
+ $resultPageSet->populateFromTitles( $generated );
+ } else {
+ $resultPageSet->populateFromRevisionIDs( $generated );
+ }
+ } else {
+ $result->addIndexedTagName( array( 'query', $this->getModuleName() ), 'page' );
+ }
+ }
+
+ public function getAllowedParams() {
+ $ret = parent::getAllowedParams() + array(
+ 'user' => array(
+ ApiBase::PARAM_TYPE => 'user'
+ ),
+ 'namespace' => array(
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_TYPE => 'namespace',
+ ApiBase::PARAM_DFLT => null,
+ ),
+ 'start' => array(
+ ApiBase::PARAM_TYPE => 'timestamp',
+ ApiBase::PARAM_HELP_MSG_INFO => array( array( 'useronly' ) ),
+ ),
+ 'end' => array(
+ ApiBase::PARAM_TYPE => 'timestamp',
+ ApiBase::PARAM_HELP_MSG_INFO => array( array( 'useronly' ) ),
+ ),
+ 'dir' => array(
+ ApiBase::PARAM_TYPE => array(
+ 'newer',
+ 'older'
+ ),
+ ApiBase::PARAM_DFLT => 'older',
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
+ ),
+ 'from' => array(
+ ApiBase::PARAM_HELP_MSG_INFO => array( array( 'nonuseronly' ) ),
+ ),
+ 'to' => array(
+ ApiBase::PARAM_HELP_MSG_INFO => array( array( 'nonuseronly' ) ),
+ ),
+ 'prefix' => array(
+ ApiBase::PARAM_HELP_MSG_INFO => array( array( 'nonuseronly' ) ),
+ ),
+ 'excludeuser' => array(
+ ApiBase::PARAM_TYPE => 'user',
+ ApiBase::PARAM_HELP_MSG_INFO => array( array( 'nonuseronly' ) ),
+ ),
+ 'tag' => null,
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ),
+ 'generatetitles' => array(
+ ApiBase::PARAM_DFLT => false
+ ),
+ );
+
+ if ( $this->getConfig()->get( 'MiserMode' ) ) {
+ $ret['user'][ApiBase::PARAM_HELP_MSG_APPEND] = array(
+ 'apihelp-query+alldeletedrevisions-param-miser-user-namespace',
+ );
+ $ret['namespace'][ApiBase::PARAM_HELP_MSG_APPEND] = array(
+ 'apihelp-query+alldeletedrevisions-param-miser-user-namespace',
+ );
+ }
+
+ return $ret;
+ }
+
+ protected function getExamplesMessages() {
+ return array(
+ 'action=query&list=alldeletedrevisions&adruser=Example&adrlimit=50'
+ => 'apihelp-query+alldeletedrevisions-example-user',
+ 'action=query&list=alldeletedrevisions&adrdir=newer&adrlimit=50'
+ => 'apihelp-query+alldeletedrevisions-example-ns-main',
+ );
+ }
+
+ public function getHelpUrls() {
+ return 'https://www.mediawiki.org/wiki/API:Alldeletedrevisions';
+ }
+}
diff --git a/includes/api/ApiQueryAllImages.php b/includes/api/ApiQueryAllImages.php
index 9dc5f69a..381938bd 100644
--- a/includes/api/ApiQueryAllImages.php
+++ b/includes/api/ApiQueryAllImages.php
@@ -232,10 +232,25 @@ class ApiQueryAllImages extends ApiQueryGeneratorBase {
$this->dieUsage( 'MIME search disabled in Miser Mode', 'mimesearchdisabled' );
}
- list( $major, $minor ) = File::splitMime( $params['mime'] );
-
- $this->addWhereFld( 'img_major_mime', $major );
- $this->addWhereFld( 'img_minor_mime', $minor );
+ $mimeConds = array();
+ foreach ( $params['mime'] as $mime ) {
+ list( $major, $minor ) = File::splitMime( $mime );
+ $mimeConds[] = $db->makeList(
+ array(
+ 'img_major_mime' => $major,
+ 'img_minor_mime' => $minor,
+ ),
+ LIST_AND
+ );
+ }
+ // safeguard against internal_api_error_DBQueryError
+ if ( count( $mimeConds ) > 0 ) {
+ $this->addWhere( $db->makeList( $mimeConds, LIST_OR ) );
+ } else {
+ // no MIME types, no files
+ $this->getResult()->addValue( 'query', $this->getModuleName(), array() );
+ return;
+ }
}
$limit = $params['limit'];
@@ -293,14 +308,14 @@ class ApiQueryAllImages extends ApiQueryGeneratorBase {
}
if ( is_null( $resultPageSet ) ) {
- $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'img' );
+ $result->addIndexedTagName( array( 'query', $this->getModuleName() ), 'img' );
} else {
$resultPageSet->populateFromTitles( $titles );
}
}
public function getAllowedParams() {
- return array(
+ $ret = array(
'sort' => array(
ApiBase::PARAM_DFLT => 'name',
ApiBase::PARAM_TYPE => array(
@@ -321,7 +336,9 @@ class ApiQueryAllImages extends ApiQueryGeneratorBase {
),
'from' => null,
'to' => null,
- 'continue' => null,
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ),
'start' => array(
ApiBase::PARAM_TYPE => 'timestamp'
),
@@ -331,7 +348,9 @@ class ApiQueryAllImages extends ApiQueryGeneratorBase {
'prop' => array(
ApiBase::PARAM_TYPE => ApiQueryImageInfo::getPropertyNames( $this->propertyFilter ),
ApiBase::PARAM_DFLT => 'timestamp|url',
- ApiBase::PARAM_ISMULTI => true
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_HELP_MSG => 'apihelp-query+imageinfo-param-prop',
+ ApiBase::PARAM_HELP_MSG_PER_VALUE => ApiQueryImageInfo::getPropertyMessages( $this->propertyFilter ),
),
'prefix' => null,
'minsize' => array(
@@ -353,7 +372,10 @@ class ApiQueryAllImages extends ApiQueryGeneratorBase {
'nobots'
)
),
- 'mime' => null,
+ 'mime' => array(
+ ApiBase::PARAM_DFLT => null,
+ ApiBase::PARAM_ISMULTI => true,
+ ),
'limit' => array(
ApiBase::PARAM_DFLT => 10,
ApiBase::PARAM_TYPE => 'limit',
@@ -362,57 +384,28 @@ class ApiQueryAllImages extends ApiQueryGeneratorBase {
ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
),
);
- }
- public function getParamDescription() {
- $p = $this->getModulePrefix();
+ if ( $this->getConfig()->get( 'MiserMode' ) ) {
+ $ret['mime'][ApiBase::PARAM_HELP_MSG] = 'api-help-param-disabled-in-miser-mode';
+ }
- return array(
- 'sort' => 'Property to sort by',
- 'dir' => 'The direction in which to list',
- 'from' => "The image title to start enumerating from. Can only be used with {$p}sort=name",
- 'to' => "The image title to stop enumerating at. Can only be used with {$p}sort=name",
- 'continue' => 'When more results are available, use this to continue',
- 'start' => "The timestamp to start enumerating from. Can only be used with {$p}sort=timestamp",
- 'end' => "The timestamp to end enumerating. Can only be used with {$p}sort=timestamp",
- 'prop' => ApiQueryImageInfo::getPropertyDescriptions( $this->propertyFilter ),
- 'prefix' => "Search for all image titles that begin with this " .
- "value. Can only be used with {$p}sort=name",
- 'minsize' => 'Limit to images with at least this many bytes',
- 'maxsize' => 'Limit to images with at most this many bytes',
- 'sha1' => "SHA1 hash of image. Overrides {$p}sha1base36",
- 'sha1base36' => 'SHA1 hash of image in base 36 (used in MediaWiki)',
- 'user' => "Only return files uploaded by this user. Can only be used " .
- "with {$p}sort=timestamp. Cannot be used together with {$p}filterbots",
- 'filterbots' => "How to filter files uploaded by bots. Can only be " .
- "used with {$p}sort=timestamp. Cannot be used together with {$p}user",
- 'mime' => 'What MIME type to search for. e.g. image/jpeg. Disabled in Miser Mode',
- 'limit' => 'How many images in total to return',
- );
+ return $ret;
}
private $propertyFilter = array( 'archivename', 'thumbmime', 'uploadwarning' );
- public function getDescription() {
- return 'Enumerate all images sequentially.';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&list=allimages&aifrom=B' => array(
- 'Simple Use',
- 'Show a list of files starting at the letter "B"',
- ),
- 'api.php?action=query&list=allimages&aiprop=user|timestamp|url&' .
- 'aisort=timestamp&aidir=older' => array(
- 'Simple Use',
- 'Show a list of recently uploaded files similar to Special:NewFiles',
- ),
- 'api.php?action=query&generator=allimages&gailimit=4&' .
- 'gaifrom=T&prop=imageinfo' => array(
- 'Using as Generator',
- 'Show info about 4 files starting at the letter "T"',
- ),
+ 'action=query&list=allimages&aifrom=B'
+ => 'apihelp-query+allimages-example-B',
+ 'action=query&list=allimages&aiprop=user|timestamp|url&' .
+ 'aisort=timestamp&aidir=older'
+ => 'apihelp-query+allimages-example-recent',
+ 'action=query&list=allimages&aimime=image/png|image/gif'
+ => 'apihelp-query+allimages-example-mimetypes',
+ 'action=query&generator=allimages&gailimit=4&' .
+ 'gaifrom=T&prop=imageinfo'
+ => 'apihelp-query+allimages-example-generator',
);
}
diff --git a/includes/api/ApiQueryAllLinks.php b/includes/api/ApiQueryAllLinks.php
index 903dee42..fadecfb4 100644
--- a/includes/api/ApiQueryAllLinks.php
+++ b/includes/api/ApiQueryAllLinks.php
@@ -31,13 +31,12 @@
*/
class ApiQueryAllLinks extends ApiQueryGeneratorBase {
- private $table, $tablePrefix, $indexTag,
- $description, $descriptionWhat, $descriptionTargets, $descriptionLinking;
+ private $table, $tablePrefix, $indexTag;
private $fieldTitle = 'title';
private $dfltNamespace = NS_MAIN;
private $hasNamespace = true;
private $useIndex = null;
- private $props = array(), $propHelp = array();
+ private $props = array();
public function __construct( ApiQuery $query, $moduleName ) {
switch ( $moduleName ) {
@@ -47,10 +46,6 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
$this->tablePrefix = 'pl_';
$this->useIndex = 'pl_namespace';
$this->indexTag = 'l';
- $this->description = 'Enumerate all links that point to a given namespace';
- $this->descriptionWhat = 'link';
- $this->descriptionTargets = 'linked titles';
- $this->descriptionLinking = 'linking';
break;
case 'alltransclusions':
$prefix = 'at';
@@ -59,11 +54,6 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
$this->dfltNamespace = NS_TEMPLATE;
$this->useIndex = 'tl_namespace';
$this->indexTag = 't';
- $this->description =
- 'List all transclusions (pages embedded using {{x}}), including non-existing';
- $this->descriptionWhat = 'transclusion';
- $this->descriptionTargets = 'transcluded titles';
- $this->descriptionLinking = 'transcluding';
break;
case 'allfileusages':
$prefix = 'af';
@@ -73,28 +63,16 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
$this->dfltNamespace = NS_FILE;
$this->hasNamespace = false;
$this->indexTag = 'f';
- $this->description = 'List all file usages, including non-existing';
- $this->descriptionWhat = 'file';
- $this->descriptionTargets = 'file titles';
- $this->descriptionLinking = 'using';
break;
case 'allredirects':
$prefix = 'ar';
$this->table = 'redirect';
$this->tablePrefix = 'rd_';
$this->indexTag = 'r';
- $this->description = 'List all redirects to a namespace';
- $this->descriptionWhat = 'redirect';
- $this->descriptionTargets = 'target pages';
- $this->descriptionLinking = 'redirecting';
$this->props = array(
'fragment' => 'rd_fragment',
'interwiki' => 'rd_interwiki',
);
- $this->propHelp = array(
- ' fragment - Adds the fragment from the redirect, if any',
- ' interwiki - Adds the interwiki prefix from the redirect, if any',
- );
break;
default:
ApiBase::dieDebug( __METHOD__, 'Unknown module name' );
@@ -222,7 +200,9 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
}
if ( is_null( $resultPageSet ) ) {
- $vals = array();
+ $vals = array(
+ ApiResult::META_TYPE => 'assoc',
+ );
if ( $fld_ids ) {
$vals['fromid'] = intval( $row->pl_from );
}
@@ -252,7 +232,7 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
}
if ( is_null( $resultPageSet ) ) {
- $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), $this->indexTag );
+ $result->addIndexedTagName( array( 'query', $this->getModuleName() ), $this->indexTag );
} elseif ( $params['unique'] ) {
$resultPageSet->populateFromTitles( $titles );
} else {
@@ -262,7 +242,9 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
public function getAllowedParams() {
$allowedParams = array(
- 'continue' => null,
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ),
'from' => null,
'to' => null,
'prefix' => null,
@@ -300,59 +282,20 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
return $allowedParams;
}
- public function getParamDescription() {
- $p = $this->getModulePrefix();
- $what = $this->descriptionWhat;
- $targets = $this->descriptionTargets;
- $linking = $this->descriptionLinking;
- $paramDescription = array(
- 'from' => "The title of the $what to start enumerating from",
- 'to' => "The title of the $what to stop enumerating at",
- 'prefix' => "Search for all $targets that begin with this value",
- 'unique' => array(
- "Only show distinct $targets. Cannot be used with {$p}prop=" .
- join( '|', array_keys( array( 'ids' => 1 ) + $this->props ) ) . '.',
- 'When used as a generator, yields target pages instead of source pages.',
- ),
- 'prop' => array(
- 'What pieces of information to include',
- " ids - Adds the pageid of the $linking page (Cannot be used with {$p}unique)",
- " title - Adds the title of the $what",
- ),
- 'namespace' => 'The namespace to enumerate',
- 'limit' => 'How many total items to return',
- 'continue' => 'When more results are available, use this to continue',
- 'dir' => 'The direction in which to list',
- );
- foreach ( $this->propHelp as $help ) {
- $paramDescription['prop'][] = "$help (Cannot be used with {$p}unique)";
- }
- if ( !$this->hasNamespace ) {
- unset( $paramDescription['namespace'] );
- }
-
- return $paramDescription;
- }
-
- public function getDescription() {
- return $this->description;
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
$p = $this->getModulePrefix();
$name = $this->getModuleName();
- $what = $this->descriptionWhat;
- $targets = $this->descriptionTargets;
+ $path = $this->getModulePath();
return array(
- "api.php?action=query&list={$name}&{$p}from=B&{$p}prop=ids|title"
- => "List $targets with page ids they are from, including missing ones. Start at B",
- "api.php?action=query&list={$name}&{$p}unique=&{$p}from=B"
- => "List unique $targets",
- "api.php?action=query&generator={$name}&g{$p}unique=&g{$p}from=B"
- => "Gets all $targets, marking the missing ones",
- "api.php?action=query&generator={$name}&g{$p}from=B"
- => "Gets pages containing the {$what}s",
+ "action=query&list={$name}&{$p}from=B&{$p}prop=ids|title"
+ => "apihelp-$path-example-B",
+ "action=query&list={$name}&{$p}unique=&{$p}from=B"
+ => "apihelp-$path-example-unique",
+ "action=query&generator={$name}&g{$p}unique=&g{$p}from=B"
+ => "apihelp-$path-example-unique-generator",
+ "action=query&generator={$name}&g{$p}from=B"
+ => "apihelp-$path-example-generator",
);
}
diff --git a/includes/api/ApiQueryAllMessages.php b/includes/api/ApiQueryAllMessages.php
index a75a16fc..44af83d0 100644
--- a/includes/api/ApiQueryAllMessages.php
+++ b/includes/api/ApiQueryAllMessages.php
@@ -146,7 +146,7 @@ class ApiQueryAllMessages extends ApiQueryBase {
$messageIsCustomised = isset( $customisedMessages['pages'][$langObj->ucfirst( $message )] );
if ( $customised === $messageIsCustomised ) {
if ( $customised ) {
- $a['customised'] = '';
+ $a['customised'] = true;
}
} else {
continue;
@@ -156,7 +156,7 @@ class ApiQueryAllMessages extends ApiQueryBase {
$msg = wfMessage( $message, $args )->inLanguage( $langObj );
if ( !$msg->exists() ) {
- $a['missing'] = '';
+ $a['missing'] = true;
} else {
// Check if the parser is enabled:
if ( $params['enableparser'] ) {
@@ -165,12 +165,12 @@ class ApiQueryAllMessages extends ApiQueryBase {
$msgString = $msg->plain();
}
if ( !$params['nocontent'] ) {
- ApiResult::setContent( $a, $msgString );
+ ApiResult::setContentValue( $a, 'content', $msgString );
}
if ( isset( $prop['default'] ) ) {
$default = wfMessage( $message )->inLanguage( $langObj )->useDatabase( false );
if ( !$default->exists() ) {
- $a['defaultmissing'] = '';
+ $a['defaultmissing'] = true;
} elseif ( $default->plain() != $msgString ) {
$a['default'] = $default->plain();
}
@@ -183,7 +183,7 @@ class ApiQueryAllMessages extends ApiQueryBase {
}
}
}
- $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'message' );
+ $result->addIndexedTagName( array( 'query', $this->getModuleName() ), 'message' );
}
public function getCacheMode( $params ) {
@@ -235,35 +235,12 @@ class ApiQueryAllMessages extends ApiQueryBase {
);
}
- public function getParamDescription() {
+ protected function getExamplesMessages() {
return array(
- 'messages' => 'Which messages to output. "*" (default) means all messages',
- 'prop' => 'Which properties to get',
- 'enableparser' => array( 'Set to enable parser, will preprocess the wikitext of message',
- 'Will substitute magic words, handle templates etc.' ),
- 'nocontent' => 'If set, do not include the content of the messages in the output.',
- 'includelocal' => array( "Also include local messages, i.e. messages that don't exist in the software but do exist as a MediaWiki: page.",
- "This lists all MediaWiki: pages, so it will also list those that aren't 'really' messages such as Common.js",
- ),
- 'title' => 'Page name to use as context when parsing message (for enableparser option)',
- 'args' => 'Arguments to be substituted into message',
- 'prefix' => 'Return messages with this prefix',
- 'filter' => 'Return only messages with names that contain this string',
- 'customised' => 'Return only messages in this customisation state',
- 'lang' => 'Return messages in this language',
- 'from' => 'Return messages starting at this message',
- 'to' => 'Return messages ending at this message',
- );
- }
-
- public function getDescription() {
- return 'Return messages from this site.';
- }
-
- public function getExamples() {
- return array(
- 'api.php?action=query&meta=allmessages&amprefix=ipb-',
- 'api.php?action=query&meta=allmessages&ammessages=august|mainpage&amlang=de',
+ 'action=query&meta=allmessages&amprefix=ipb-'
+ => 'apihelp-query+allmessages-example-ipb',
+ 'action=query&meta=allmessages&ammessages=august|mainpage&amlang=de'
+ => 'apihelp-query+allmessages-example-de',
);
}
diff --git a/includes/api/ApiQueryAllPages.php b/includes/api/ApiQueryAllPages.php
index b7bd65a5..0149ad2f 100644
--- a/includes/api/ApiQueryAllPages.php
+++ b/includes/api/ApiQueryAllPages.php
@@ -168,9 +168,23 @@ class ApiQueryAllPages extends ApiQueryGeneratorBase {
$this->addTables( 'langlinks' );
$this->addWhere( 'page_id=ll_from' );
$this->addOption( 'STRAIGHT_JOIN' );
- // We have to GROUP BY all selected fields to stop
- // PostgreSQL from whining
- $this->addOption( 'GROUP BY', $selectFields );
+
+ // MySQL filesorts if we use a GROUP BY that works with the rules
+ // in the 1992 SQL standard (it doesn't like having the
+ // constant-in-WHERE page_namespace column in there). Using the
+ // 1999 rules works fine, but that breaks other DBs. Sigh.
+ /// @todo Once we drop support for 1992-rule DBs, we can simplify this.
+ $dbType = $db->getType();
+ if ( $dbType === 'mysql' || $dbType === 'sqlite' ||
+ $dbType === 'postgres' && $db->getServerVersion() >= 9.1
+ ) {
+ // 1999 rules, or screw-the-rules
+ $this->addOption( 'GROUP BY', array( 'page_title', 'page_id' ) );
+ } else {
+ // 1992 rules
+ $this->addOption( 'GROUP BY', $selectFields );
+ }
+
$forceNameTitleIndex = false;
}
@@ -220,14 +234,16 @@ class ApiQueryAllPages extends ApiQueryGeneratorBase {
}
if ( is_null( $resultPageSet ) ) {
- $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'p' );
+ $result->addIndexedTagName( array( 'query', $this->getModuleName() ), 'p' );
}
}
public function getAllowedParams() {
return array(
'from' => null,
- 'continue' => null,
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ),
'to' => null,
'prefix' => null,
'namespace' => array(
@@ -297,54 +313,15 @@ class ApiQueryAllPages extends ApiQueryGeneratorBase {
);
}
- public function getParamDescription() {
- $p = $this->getModulePrefix();
-
- return array(
- 'from' => 'The page title to start enumerating from',
- 'continue' => 'When more results are available, use this to continue',
- 'to' => 'The page title to stop enumerating at',
- 'prefix' => 'Search for all page titles that begin with this value',
- 'namespace' => 'The namespace to enumerate',
- 'filterredir' => 'Which pages to list',
- 'dir' => 'The direction in which to list',
- 'minsize' => 'Limit to pages with at least this many bytes',
- 'maxsize' => 'Limit to pages with at most this many bytes',
- 'prtype' => 'Limit to protected pages only',
- 'prlevel' => "The protection level (must be used with {$p}prtype= parameter)",
- 'prfiltercascade'
- => "Filter protections based on cascadingness (ignored when {$p}prtype isn't set)",
- 'filterlanglinks' => array(
- 'Filter based on whether a page has langlinks',
- 'Note that this may not consider langlinks added by extensions.',
- ),
- 'limit' => 'How many total pages to return.',
- 'prexpiry' => array(
- 'Which protection expiry to filter the page on',
- ' indefinite - Get only pages with indefinite protection expiry',
- ' definite - Get only pages with a definite (specific) protection expiry',
- ' all - Get pages with any protections expiry'
- ),
- );
- }
-
- public function getDescription() {
- return 'Enumerate all pages sequentially in a given namespace.';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&list=allpages&apfrom=B' => array(
- 'Simple Use',
- 'Show a list of pages starting at the letter "B"',
- ),
- 'api.php?action=query&generator=allpages&gaplimit=4&gapfrom=T&prop=info' => array(
- 'Using as Generator',
- 'Show info about 4 pages starting at the letter "T"',
- ),
- 'api.php?action=query&generator=allpages&gaplimit=2&' .
+ 'action=query&list=allpages&apfrom=B'
+ => 'apihelp-query+allpages-example-B',
+ 'action=query&generator=allpages&gaplimit=4&gapfrom=T&prop=info'
+ => 'apihelp-query+allpages-example-generator',
+ 'action=query&generator=allpages&gaplimit=2&' .
'gapfilterredir=nonredirects&gapfrom=Re&prop=revisions&rvprop=content'
- => array( 'Show content of first 2 non-redirect pages beginning at "Re"' )
+ => 'apihelp-query+allpages-example-generator-revisions',
);
}
diff --git a/includes/api/ApiQueryAllUsers.php b/includes/api/ApiQueryAllUsers.php
index affddda7..0cea84f8 100644
--- a/includes/api/ApiQueryAllUsers.php
+++ b/includes/api/ApiQueryAllUsers.php
@@ -48,11 +48,6 @@ class ApiQueryAllUsers extends ApiQueryBase {
$params = $this->extractRequestParams();
$activeUserDays = $this->getConfig()->get( 'ActiveUserDays' );
- if ( $params['activeusers'] ) {
- // Update active user cache
- SpecialActiveUsers::mergeActiveUsers( 600, $activeUserDays );
- }
-
$db = $this->getDB();
$prop = $params['prop'];
@@ -72,7 +67,6 @@ class ApiQueryAllUsers extends ApiQueryBase {
$limit = $params['limit'];
$this->addTables( 'user' );
- $useIndex = true;
$dir = ( $params['dir'] == 'descending' ? 'older' : 'newer' );
$from = is_null( $params['from'] ) ? null : $this->getCanonicalUserName( $params['from'] );
@@ -82,6 +76,10 @@ class ApiQueryAllUsers extends ApiQueryBase {
# despite the JOIN condition, so manually sort on the correct one.
$userFieldToSort = $params['activeusers'] ? 'qcc_title' : 'user_name';
+ # Some of these subtable joins are going to give us duplicate rows, so
+ # calculate the maximum number of duplicates we might see.
+ $maxDuplicateRows = 1;
+
$this->addWhereRange( $userFieldToSort, $dir, $from, $to );
if ( !is_null( $params['prefix'] ) ) {
@@ -97,7 +95,7 @@ class ApiQueryAllUsers extends ApiQueryBase {
// no group with the given right(s) exists, no need for a query
if ( !count( $groups ) ) {
- $this->getResult()->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), '' );
+ $this->getResult()->addIndexedTagName( array( 'query', $this->getModuleName() ), '' );
return;
}
@@ -116,16 +114,17 @@ class ApiQueryAllUsers extends ApiQueryBase {
}
if ( !is_null( $params['group'] ) && count( $params['group'] ) ) {
- $useIndex = false;
- // Filter only users that belong to a given group
+ // Filter only users that belong to a given group. This might
+ // produce as many rows-per-user as there are groups being checked.
$this->addTables( 'user_groups', 'ug1' );
$this->addJoinConds( array( 'ug1' => array( 'INNER JOIN', array( 'ug1.ug_user=user_id',
'ug1.ug_group' => $params['group'] ) ) ) );
+ $maxDuplicateRows *= count( $params['group'] );
}
if ( !is_null( $params['excludegroup'] ) && count( $params['excludegroup'] ) ) {
- $useIndex = false;
- // Filter only users don't belong to a given group
+ // Filter only users don't belong to a given group. This can only
+ // produce one row-per-user, because we only keep on "no match".
$this->addTables( 'user_groups', 'ug1' );
if ( count( $params['excludegroup'] ) == 1 ) {
@@ -149,22 +148,16 @@ class ApiQueryAllUsers extends ApiQueryBase {
$this->showHiddenUsersAddBlockInfo( $fld_blockinfo );
if ( $fld_groups || $fld_rights ) {
- // Show the groups the given users belong to
- // request more than needed to avoid not getting all rows that belong to one user
- $groupCount = count( User::getAllGroups() );
- $sqlLimit = $limit + $groupCount + 1;
-
- $this->addTables( 'user_groups', 'ug2' );
- $this->addJoinConds( array( 'ug2' => array( 'LEFT JOIN', 'ug2.ug_user=user_id' ) ) );
- $this->addFields( array( 'ug_group2' => 'ug2.ug_group' ) );
- } else {
- $sqlLimit = $limit + 1;
+ $this->addFields( array( 'groups' =>
+ $db->buildGroupConcatField( '|', 'user_groups', 'ug_group', 'ug_user=user_id' )
+ ) );
}
if ( $params['activeusers'] ) {
$activeUserSeconds = $activeUserDays * 86400;
- // Filter query to only include users in the active users cache
+ // Filter query to only include users in the active users cache.
+ // There shouldn't be any duplicate rows in querycachetwo here.
$this->addTables( 'querycachetwo' );
$this->addJoinConds( array( 'querycachetwo' => array(
'INNER JOIN', array(
@@ -190,6 +183,7 @@ class ApiQueryAllUsers extends ApiQueryBase {
) );
}
+ $sqlLimit = $limit + $maxDuplicateRows;
$this->addOption( 'LIMIT', $sqlLimit );
$this->addFields( array(
@@ -199,148 +193,112 @@ class ApiQueryAllUsers extends ApiQueryBase {
$this->addFieldsIf( 'user_editcount', $fld_editcount );
$this->addFieldsIf( 'user_registration', $fld_registration );
- if ( $useIndex ) {
- $this->addOption( 'USE INDEX', array( 'user' => 'user_name' ) );
- }
-
$res = $this->select( __METHOD__ );
-
$count = 0;
- $lastUserData = false;
+ $countDuplicates = 0;
$lastUser = false;
$result = $this->getResult();
-
- // This loop keeps track of the last entry. For each new row, if the
- // new row is for different user then the last, the last entry is added
- // to results. Otherwise, the group of the new row is appended to the
- // last entry. The setContinue... is more complex because of this, and
- // takes into account the higher sql limit to make sure all rows that
- // belong to the same user are received.
-
foreach ( $res as $row ) {
$count++;
- if ( $lastUser !== $row->user_name ) {
- // Save the last pass's user data
- if ( is_array( $lastUserData ) ) {
- if ( $params['activeusers'] && $lastUserData['recentactions'] === 0 ) {
- // activeusers cache was out of date
- $fit = true;
- } else {
- $fit = $result->addValue( array( 'query', $this->getModuleName() ),
- null, $lastUserData );
- }
-
- $lastUserData = null;
-
- if ( !$fit ) {
- $this->setContinueEnumParameter( 'from', $lastUserData['name'] );
- break;
- }
+ if ( $lastUser === $row->user_name ) {
+ // Duplicate row due to one of the needed subtable joins.
+ // Ignore it, but count the number of them to sanely handle
+ // miscalculation of $maxDuplicateRows.
+ $countDuplicates++;
+ if ( $countDuplicates == $maxDuplicateRows ) {
+ ApiBase::dieDebug( __METHOD__, 'Saw more duplicate rows than expected' );
}
+ continue;
+ }
- if ( $count > $limit ) {
- // We've reached the one extra which shows that there are
- // additional pages to be had. Stop here...
- $this->setContinueEnumParameter( 'from', $row->user_name );
- break;
- }
+ $countDuplicates = 0;
+ $lastUser = $row->user_name;
- // Record new user's data
- $lastUser = $row->user_name;
- $lastUserData = array(
- 'userid' => $row->user_id,
- 'name' => $lastUser,
- );
- if ( $fld_blockinfo && !is_null( $row->ipb_by_text ) ) {
- $lastUserData['blockid'] = $row->ipb_id;
- $lastUserData['blockedby'] = $row->ipb_by_text;
- $lastUserData['blockedbyid'] = $row->ipb_by;
- $lastUserData['blockedtimestamp'] = wfTimestamp( TS_ISO_8601, $row->ipb_timestamp );
- $lastUserData['blockreason'] = $row->ipb_reason;
- $lastUserData['blockexpiry'] = $row->ipb_expiry;
- }
- if ( $row->ipb_deleted ) {
- $lastUserData['hidden'] = '';
- }
- if ( $fld_editcount ) {
- $lastUserData['editcount'] = intval( $row->user_editcount );
- }
- if ( $params['activeusers'] ) {
- $lastUserData['recentactions'] = intval( $row->recentactions );
- // @todo 'recenteditcount' is set for BC, remove in 1.25
- $lastUserData['recenteditcount'] = $lastUserData['recentactions'];
- }
- if ( $fld_registration ) {
- $lastUserData['registration'] = $row->user_registration ?
- wfTimestamp( TS_ISO_8601, $row->user_registration ) : '';
- }
+ if ( $count > $limit ) {
+ // We've reached the one extra which shows that there are
+ // additional pages to be had. Stop here...
+ $this->setContinueEnumParameter( 'from', $row->user_name );
+ break;
}
- if ( $sqlLimit == $count ) {
- // @todo BUG! database contains group name that User::getAllGroups() does not return
- // Should handle this more gracefully
- ApiBase::dieDebug(
- __METHOD__,
- 'MediaWiki configuration error: The database contains more ' .
- 'user groups than known to User::getAllGroups() function'
- );
+ if ( $count == $sqlLimit ) {
+ // Should never hit this (either the $countDuplicates check or
+ // the $count > $limit check should hit first), but check it
+ // anyway just in case.
+ ApiBase::dieDebug( __METHOD__, 'Saw more duplicate rows than expected' );
}
- $lastUserObj = User::newFromId( $row->user_id );
-
- // Add user's group info
- if ( $fld_groups ) {
- if ( !isset( $lastUserData['groups'] ) ) {
- if ( $lastUserObj ) {
- $lastUserData['groups'] = $lastUserObj->getAutomaticGroups();
- } else {
- // This should not normally happen
- $lastUserData['groups'] = array();
- }
- }
-
- if ( !is_null( $row->ug_group2 ) ) {
- $lastUserData['groups'][] = $row->ug_group2;
- }
-
- $result->setIndexedTagName( $lastUserData['groups'], 'g' );
+ if ( $params['activeusers'] && $row->recentactions === 0 ) {
+ // activeusers cache was out of date
+ continue;
}
- if ( $fld_implicitgroups && !isset( $lastUserData['implicitgroups'] ) && $lastUserObj ) {
- $lastUserData['implicitgroups'] = $lastUserObj->getAutomaticGroups();
- $result->setIndexedTagName( $lastUserData['implicitgroups'], 'g' );
+ $data = array(
+ 'userid' => $row->user_id,
+ 'name' => $row->user_name,
+ );
+
+ if ( $fld_blockinfo && !is_null( $row->ipb_by_text ) ) {
+ $data['blockid'] = $row->ipb_id;
+ $data['blockedby'] = $row->ipb_by_text;
+ $data['blockedbyid'] = $row->ipb_by;
+ $data['blockedtimestamp'] = wfTimestamp( TS_ISO_8601, $row->ipb_timestamp );
+ $data['blockreason'] = $row->ipb_reason;
+ $data['blockexpiry'] = $row->ipb_expiry;
+ }
+ if ( $row->ipb_deleted ) {
+ $data['hidden'] = true;
+ }
+ if ( $fld_editcount ) {
+ $data['editcount'] = intval( $row->user_editcount );
+ }
+ if ( $params['activeusers'] ) {
+ $data['recentactions'] = intval( $row->recentactions );
+ // @todo 'recenteditcount' is set for BC, remove in 1.25
+ $data['recenteditcount'] = $data['recentactions'];
}
- if ( $fld_rights ) {
- if ( !isset( $lastUserData['rights'] ) ) {
- if ( $lastUserObj ) {
- $lastUserData['rights'] = User::getGroupPermissions( $lastUserObj->getAutomaticGroups() );
- } else {
- // This should not normally happen
- $lastUserData['rights'] = array();
- }
+ if ( $fld_registration ) {
+ $data['registration'] = $row->user_registration ?
+ wfTimestamp( TS_ISO_8601, $row->user_registration ) : '';
+ }
+
+ if ( $fld_implicitgroups || $fld_groups || $fld_rights ) {
+ $user = User::newFromId( $row->user_id );
+ $implicitGroups = User::newFromId( $row->user_id )->getAutomaticGroups();
+ if ( isset( $row->groups ) && $row->groups !== '' ) {
+ $groups = array_merge( $implicitGroups, explode( '|', $row->groups ) );
+ } else {
+ $groups = $implicitGroups;
}
- if ( !is_null( $row->ug_group2 ) ) {
- $lastUserData['rights'] = array_unique( array_merge( $lastUserData['rights'],
- User::getGroupPermissions( array( $row->ug_group2 ) ) ) );
+ if ( $fld_groups ) {
+ $data['groups'] = $groups;
+ ApiResult::setIndexedTagName( $data['groups'], 'g' );
+ ApiResult::setArrayType( $data['groups'], 'array' );
}
- $result->setIndexedTagName( $lastUserData['rights'], 'r' );
+ if ( $fld_implicitgroups ) {
+ $data['implicitgroups'] = $implicitGroups;
+ ApiResult::setIndexedTagName( $data['implicitgroups'], 'g' );
+ ApiResult::setArrayType( $data['implicitgroups'], 'array' );
+ }
+
+ if ( $fld_rights ) {
+ $data['rights'] = User::getGroupPermissions( $groups );
+ ApiResult::setIndexedTagName( $data['rights'], 'r' );
+ ApiResult::setArrayType( $data['rights'], 'array' );
+ }
}
- }
- if ( is_array( $lastUserData ) &&
- !( $params['activeusers'] && $lastUserData['recentactions'] === 0 )
- ) {
- $fit = $result->addValue( array( 'query', $this->getModuleName() ),
- null, $lastUserData );
+ $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $data );
if ( !$fit ) {
- $this->setContinueEnumParameter( 'from', $lastUserData['name'] );
+ $this->setContinueEnumParameter( 'from', $data['name'] );
+ break;
}
}
- $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'u' );
+ $result->addIndexedTagName( array( 'query', $this->getModuleName() ), 'u' );
}
public function getCacheMode( $params ) {
@@ -392,43 +350,20 @@ class ApiQueryAllUsers extends ApiQueryBase {
ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
),
'witheditsonly' => false,
- 'activeusers' => false,
- );
- }
-
- public function getParamDescription() {
- return array(
- 'from' => 'The user name to start enumerating from',
- 'to' => 'The user name to stop enumerating at',
- 'prefix' => 'Search for all users that begin with this value',
- 'dir' => 'Direction to sort in',
- 'group' => 'Limit users to given group name(s)',
- 'excludegroup' => 'Exclude users in given group name(s)',
- 'rights' => 'Limit users to given right(s) (does not include rights ' .
- 'granted by implicit or auto-promoted groups like *, user, or autoconfirmed)',
- 'prop' => array(
- 'What pieces of information to include.',
- ' blockinfo - Adds the information about a current block on the user',
- ' groups - Lists groups that the user is in. This uses ' .
- 'more server resources and may return fewer results than the limit',
- ' implicitgroups - Lists all the groups the user is automatically in',
- ' rights - Lists rights that the user has',
- ' editcount - Adds the edit count of the user',
- ' registration - Adds the timestamp of when the user registered if available (may be blank)',
+ 'activeusers' => array(
+ ApiBase::PARAM_DFLT => false,
+ ApiBase::PARAM_HELP_MSG => array(
+ 'apihelp-query+allusers-param-activeusers',
+ $this->getConfig()->get( 'ActiveUserDays' )
+ ),
),
- 'limit' => 'How many total user names to return',
- 'witheditsonly' => 'Only list users who have made edits',
- 'activeusers' => "Only list users active in the last {$this->getConfig()->get( 'ActiveUserDays' )} days(s)"
);
}
- public function getDescription() {
- return 'Enumerate all registered users.';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&list=allusers&aufrom=Y',
+ 'action=query&list=allusers&aufrom=Y'
+ => 'apihelp-query+allusers-example-Y',
);
}
diff --git a/includes/api/ApiQueryBacklinks.php b/includes/api/ApiQueryBacklinks.php
index c141246d..1df14e0b 100644
--- a/includes/api/ApiQueryBacklinks.php
+++ b/includes/api/ApiQueryBacklinks.php
@@ -39,8 +39,8 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
*/
private $rootTitle;
- private $params, $contID, $redirID, $redirect;
- private $bl_ns, $bl_from, $bl_table, $bl_code, $bl_title, $bl_fields, $hasNS;
+ private $params, $cont, $redirect;
+ private $bl_ns, $bl_from, $bl_from_ns, $bl_table, $bl_code, $bl_title, $bl_fields, $hasNS;
/**
* Maps ns and title to pageid
@@ -84,6 +84,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
parent::__construct( $query, $moduleName, $code );
$this->bl_ns = $prefix . '_namespace';
$this->bl_from = $prefix . '_from';
+ $this->bl_from_ns = $prefix . '_from_namespace';
$this->bl_table = $settings['linktbl'];
$this->bl_code = $code;
$this->helpUrl = $settings['helpurl'];
@@ -119,12 +120,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
* @param ApiPageSet $resultPageSet
* @return void
*/
- private function prepareFirstQuery( $resultPageSet = null ) {
- /* SELECT page_id, page_title, page_namespace, page_is_redirect
- * FROM pagelinks, page WHERE pl_from=page_id
- * AND pl_title='Foo' AND pl_namespace=0
- * LIMIT 11 ORDER BY pl_from
- */
+ private function runFirstQuery( $resultPageSet = null ) {
$this->addTables( array( $this->bl_table, 'page' ) );
$this->addWhere( "{$this->bl_from}=page_id" );
if ( is_null( $resultPageSet ) ) {
@@ -132,18 +128,25 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
} else {
$this->addFields( $resultPageSet->getPageTableFields() );
}
+ $this->addFields( array( 'page_is_redirect', 'from_ns' => 'page_namespace' ) );
- $this->addFields( 'page_is_redirect' );
$this->addWhereFld( $this->bl_title, $this->rootTitle->getDBkey() );
-
if ( $this->hasNS ) {
$this->addWhereFld( $this->bl_ns, $this->rootTitle->getNamespace() );
}
- $this->addWhereFld( 'page_namespace', $this->params['namespace'] );
+ $this->addWhereFld( $this->bl_from_ns, $this->params['namespace'] );
- if ( !is_null( $this->contID ) ) {
+ if ( count( $this->cont ) >= 2 ) {
$op = $this->params['dir'] == 'descending' ? '<' : '>';
- $this->addWhere( "{$this->bl_from}$op={$this->contID}" );
+ if ( count( $this->params['namespace'] ) > 1 ) {
+ $this->addWhere(
+ "{$this->bl_from_ns} $op {$this->cont[0]} OR " .
+ "({$this->bl_from_ns} = {$this->cont[0]} AND " .
+ "{$this->bl_from} $op= {$this->cont[1]})"
+ );
+ } else {
+ $this->addWhere( "{$this->bl_from} $op= {$this->cont[1]}" );
+ }
}
if ( $this->params['filterredir'] == 'redirects' ) {
@@ -156,20 +159,56 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
$this->addOption( 'LIMIT', $this->params['limit'] + 1 );
$sort = ( $this->params['dir'] == 'descending' ? ' DESC' : '' );
- $this->addOption( 'ORDER BY', $this->bl_from . $sort );
+ $orderBy = array();
+ if ( count( $this->params['namespace'] ) > 1 ) {
+ $orderBy[] = $this->bl_from_ns . $sort;
+ }
+ $orderBy[] = $this->bl_from . $sort;
+ $this->addOption( 'ORDER BY', $orderBy );
$this->addOption( 'STRAIGHT_JOIN' );
+
+ $res = $this->select( __METHOD__ );
+ $count = 0;
+ foreach ( $res as $row ) {
+ if ( ++$count > $this->params['limit'] ) {
+ // We've reached the one extra which shows that there are
+ // additional pages to be had. Stop here...
+ // Continue string may be overridden at a later step
+ $this->continueStr = "{$row->from_ns}|{$row->page_id}";
+ break;
+ }
+
+ // Fill in continuation fields for later steps
+ if ( count( $this->cont ) < 2 ) {
+ $this->cont[] = $row->from_ns;
+ $this->cont[] = $row->page_id;
+ }
+
+ $this->pageMap[$row->page_namespace][$row->page_title] = $row->page_id;
+ $t = Title::makeTitle( $row->page_namespace, $row->page_title );
+ if ( $row->page_is_redirect ) {
+ $this->redirTitles[] = $t;
+ }
+
+ if ( is_null( $resultPageSet ) ) {
+ $a = array( 'pageid' => intval( $row->page_id ) );
+ ApiQueryBase::addTitleInfo( $a, $t );
+ if ( $row->page_is_redirect ) {
+ $a['redirect'] = true;
+ }
+ // Put all the results in an array first
+ $this->resultArr[$a['pageid']] = $a;
+ } else {
+ $resultPageSet->processDbRow( $row );
+ }
+ }
}
/**
* @param ApiPageSet $resultPageSet
* @return void
*/
- private function prepareSecondQuery( $resultPageSet = null ) {
- /* SELECT page_id, page_title, page_namespace, page_is_redirect, pl_title, pl_namespace
- FROM pagelinks, page WHERE pl_from=page_id
- AND (pl_title='Foo' AND pl_namespace=0) OR (pl_title='Bar' AND pl_namespace=1)
- ORDER BY pl_namespace, pl_title, pl_from LIMIT 11
- */
+ private function runSecondQuery( $resultPageSet = null ) {
$db = $this->getDB();
$this->addTables( array( 'page', $this->bl_table ) );
$this->addWhere( "{$this->bl_from}=page_id" );
@@ -180,7 +219,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
$this->addFields( $resultPageSet->getPageTableFields() );
}
- $this->addFields( $this->bl_title );
+ $this->addFields( array( $this->bl_title, 'from_ns' => 'page_namespace' ) );
if ( $this->hasNS ) {
$this->addFields( $this->bl_ns );
}
@@ -195,30 +234,33 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
$redirDBkey = $t->getDBkey();
$titleWhere[] = "{$this->bl_title} = " . $db->addQuotes( $redirDBkey ) .
( $this->hasNS ? " AND {$this->bl_ns} = {$redirNs}" : '' );
- $allRedirNs[] = $redirNs;
- $allRedirDBkey[] = $redirDBkey;
+ $allRedirNs[$redirNs] = true;
+ $allRedirDBkey[$redirDBkey] = true;
}
$this->addWhere( $db->makeList( $titleWhere, LIST_OR ) );
$this->addWhereFld( 'page_namespace', $this->params['namespace'] );
- if ( !is_null( $this->redirID ) ) {
+ if ( count( $this->cont ) >= 6 ) {
$op = $this->params['dir'] == 'descending' ? '<' : '>';
- /** @var $first Title */
- $first = $this->redirTitles[0];
- $title = $db->addQuotes( $first->getDBkey() );
- $ns = $first->getNamespace();
- $from = $this->redirID;
- if ( $this->hasNS ) {
- $this->addWhere( "{$this->bl_ns} $op $ns OR " .
- "({$this->bl_ns} = $ns AND " .
- "({$this->bl_title} $op $title OR " .
- "({$this->bl_title} = $title AND " .
- "{$this->bl_from} $op= $from)))" );
- } else {
- $this->addWhere( "{$this->bl_title} $op $title OR " .
- "({$this->bl_title} = $title AND " .
- "{$this->bl_from} $op= $from)" );
+
+ $where = "{$this->bl_from} $op= {$this->cont[5]}";
+ // Don't bother with namespace, title, or from_namespace if it's
+ // otherwise constant in the where clause.
+ if ( count( $this->params['namespace'] ) > 1 ) {
+ $where = "{$this->bl_from_ns} $op {$this->cont[4]} OR " .
+ "({$this->bl_from_ns} = {$this->cont[4]} AND ($where))";
+ }
+ if ( count( $allRedirDBkey ) > 1 ) {
+ $title = $db->addQuotes( $this->cont[3] );
+ $where = "{$this->bl_title} $op $title OR " .
+ "({$this->bl_title} = $title AND ($where))";
+ }
+ if ( $this->hasNS && count( $allRedirNs ) > 1 ) {
+ $where = "{$this->bl_ns} $op {$this->cont[2]} OR " .
+ "({$this->bl_ns} = {$this->cont[2]} AND ($where))";
}
+
+ $this->addWhere( $where );
}
if ( $this->params['filterredir'] == 'redirects' ) {
$this->addWhereFld( 'page_is_redirect', 1 );
@@ -229,16 +271,57 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
$this->addOption( 'LIMIT', $this->params['limit'] + 1 );
$orderBy = array();
$sort = ( $this->params['dir'] == 'descending' ? ' DESC' : '' );
- // Don't order by namespace/title if it's constant in the WHERE clause
- if ( $this->hasNS && count( array_unique( $allRedirNs ) ) != 1 ) {
+ // Don't order by namespace/title/from_namespace if it's constant in the WHERE clause
+ if ( $this->hasNS && count( $allRedirNs ) > 1 ) {
$orderBy[] = $this->bl_ns . $sort;
}
- if ( count( array_unique( $allRedirDBkey ) ) != 1 ) {
+ if ( count( $allRedirDBkey ) > 1 ) {
$orderBy[] = $this->bl_title . $sort;
}
+ if ( count( $this->params['namespace'] ) > 1 ) {
+ $orderBy[] = $this->bl_from_ns . $sort;
+ }
$orderBy[] = $this->bl_from . $sort;
$this->addOption( 'ORDER BY', $orderBy );
$this->addOption( 'USE INDEX', array( 'page' => 'PRIMARY' ) );
+
+ $res = $this->select( __METHOD__ );
+ $count = 0;
+ foreach ( $res as $row ) {
+ $ns = $this->hasNS ? $row->{$this->bl_ns} : NS_FILE;
+
+ if ( ++$count > $this->params['limit'] ) {
+ // We've reached the one extra which shows that there are
+ // additional pages to be had. Stop here...
+ // Note we must keep the parameters for the first query constant
+ // This may be overridden at a later step
+ $title = $row->{$this->bl_title};
+ $this->continueStr = join( '|', array_slice( $this->cont, 0, 2 ) ) .
+ "|$ns|$title|{$row->from_ns}|{$row->page_id}";
+ break;
+ }
+
+ // Fill in continuation fields for later steps
+ if ( count( $this->cont ) < 6 ) {
+ $this->cont[] = $ns;
+ $this->cont[] = $row->{$this->bl_title};
+ $this->cont[] = $row->from_ns;
+ $this->cont[] = $row->page_id;
+ }
+
+ if ( is_null( $resultPageSet ) ) {
+ $a['pageid'] = intval( $row->page_id );
+ ApiQueryBase::addTitleInfo( $a, Title::makeTitle( $row->page_namespace, $row->page_title ) );
+ if ( $row->page_is_redirect ) {
+ $a['redirect'] = true;
+ }
+ $parentID = $this->pageMap[$ns][$row->{$this->bl_title}];
+ // Put all the results in an array first
+ $this->resultArr[$parentID]['redirlinks'][$row->page_id] = $a;
+ } else {
+ $resultPageSet->processDbRow( $row );
+ }
+ }
}
/**
@@ -255,106 +338,163 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
if ( $this->params['limit'] == 'max' ) {
$this->params['limit'] = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
- $result->setParsedLimit( $this->getModuleName(), $this->params['limit'] );
+ $result->addParsedLimit( $this->getModuleName(), $this->params['limit'] );
} else {
$this->params['limit'] = intval( $this->params['limit'] );
$this->validateLimit( 'limit', $this->params['limit'], 1, $userMax, $botMax );
}
- $this->processContinue();
- $this->prepareFirstQuery( $resultPageSet );
+ $this->rootTitle = $this->getTitleOrPageId( $this->params )->getTitle();
+
+ // only image titles are allowed for the root in imageinfo mode
+ if ( !$this->hasNS && $this->rootTitle->getNamespace() !== NS_FILE ) {
+ $this->dieUsage(
+ "The title for {$this->getModuleName()} query must be a file",
+ 'bad_image_title'
+ );
+ }
- $res = $this->select( __METHOD__ . '::firstQuery' );
+ // Parse and validate continuation parameter
+ $this->cont = array();
+ if ( $this->params['continue'] !== null ) {
+ $db = $this->getDB();
+ $cont = explode( '|', $this->params['continue'] );
- $count = 0;
+ switch ( count( $cont ) ) {
+ case 8:
+ // redirect page ID for result adding
+ $this->cont[7] = (int)$cont[7];
+ $this->dieContinueUsageIf( $cont[7] !== (string)$this->cont[7] );
- foreach ( $res as $row ) {
- if ( ++$count > $this->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->continueStr = $this->getContinueStr( $row->page_id );
- break;
- }
+ /* Fall through */
- if ( is_null( $resultPageSet ) ) {
- $this->extractRowInfo( $row );
- } else {
- $this->pageMap[$row->page_namespace][$row->page_title] = $row->page_id;
- if ( $row->page_is_redirect ) {
- $this->redirTitles[] = Title::makeTitle( $row->page_namespace, $row->page_title );
- }
+ case 7:
+ // top-level page ID for result adding
+ $this->cont[6] = (int)$cont[6];
+ $this->dieContinueUsageIf( $cont[6] !== (string)$this->cont[6] );
- $resultPageSet->processDbRow( $row );
+ /* Fall through */
+
+ case 6:
+ // ns for 2nd query (even for imageusage)
+ $this->cont[2] = (int)$cont[2];
+ $this->dieContinueUsageIf( $cont[2] !== (string)$this->cont[2] );
+
+ // title for 2nd query
+ $this->cont[3] = $cont[3];
+
+ // from_ns for 2nd query
+ $this->cont[4] = (int)$cont[4];
+ $this->dieContinueUsageIf( $cont[4] !== (string)$this->cont[4] );
+
+ // from_id for 1st query
+ $this->cont[5] = (int)$cont[5];
+ $this->dieContinueUsageIf( $cont[5] !== (string)$this->cont[5] );
+
+ /* Fall through */
+
+ case 2:
+ // from_ns for 1st query
+ $this->cont[0] = (int)$cont[0];
+ $this->dieContinueUsageIf( $cont[0] !== (string)$this->cont[0] );
+
+ // from_id for 1st query
+ $this->cont[1] = (int)$cont[1];
+ $this->dieContinueUsageIf( $cont[1] !== (string)$this->cont[1] );
+
+ break;
+
+ default:
+ $this->dieContinueUsageIf( true );
}
+
+ ksort( $this->cont );
}
+ $this->runFirstQuery( $resultPageSet );
if ( $this->redirect && count( $this->redirTitles ) ) {
$this->resetQueryParams();
- $this->prepareSecondQuery( $resultPageSet );
- $res = $this->select( __METHOD__ . '::secondQuery' );
- $count = 0;
- foreach ( $res as $row ) {
- 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 ) {
- $parentID = $this->pageMap[$row->{$this->bl_ns}][$row->{$this->bl_title}];
- } else {
- $parentID = $this->pageMap[NS_FILE][$row->{$this->bl_title}];
- }
- $this->continueStr = $this->getContinueRedirStr( $parentID, $row->page_id );
- break;
- }
-
- if ( is_null( $resultPageSet ) ) {
- $this->extractRedirRowInfo( $row );
- } else {
- $resultPageSet->processDbRow( $row );
- }
- }
+ $this->runSecondQuery( $resultPageSet );
}
+
+ // Fill in any missing fields in case it's needed below
+ $this->cont += array( 0, 0, 0, '', 0, 0, 0 );
+
if ( is_null( $resultPageSet ) ) {
// Try to add the result data in one go and pray that it fits
- $fit = $result->addValue( 'query', $this->getModuleName(), array_values( $this->resultArr ) );
+ $code = $this->bl_code;
+ $data = array_map( function ( $arr ) use ( $result, $code ) {
+ if ( isset( $arr['redirlinks'] ) ) {
+ $arr['redirlinks'] = array_values( $arr['redirlinks'] );
+ ApiResult::setIndexedTagName( $arr['redirlinks'], $code );
+ }
+ return $arr;
+ }, array_values( $this->resultArr ) );
+ $fit = $result->addValue( 'query', $this->getModuleName(), $data );
if ( !$fit ) {
// It didn't fit. Add elements one by one until the
// result is full.
+ ksort( $this->resultArr );
+ if ( count( $this->cont ) >= 7 ) {
+ $startAt = $this->cont[6];
+ } else {
+ reset( $this->resultArr );
+ $startAt = key( $this->resultArr );
+ }
+ $idx = 0;
foreach ( $this->resultArr as $pageID => $arr ) {
+ if ( $pageID < $startAt ) {
+ continue;
+ }
+
// Add the basic entry without redirlinks first
$fit = $result->addValue(
array( 'query', $this->getModuleName() ),
- null, array_diff_key( $arr, array( 'redirlinks' => '' ) ) );
+ $idx, array_diff_key( $arr, array( 'redirlinks' => '' ) ) );
if ( !$fit ) {
- $this->continueStr = $this->getContinueStr( $pageID );
+ $this->continueStr = join( '|', array_slice( $this->cont, 0, 6 ) ) .
+ "|$pageID";
break;
}
$hasRedirs = false;
- $redirLinks = isset( $arr['redirlinks'] ) ? $arr['redirlinks'] : array();
- foreach ( (array)$redirLinks as $key => $redir ) {
+ $redirLinks = isset( $arr['redirlinks'] ) ? (array)$arr['redirlinks'] : array();
+ ksort( $redirLinks );
+ if ( count( $this->cont ) >= 8 && $pageID == $startAt ) {
+ $redirStartAt = $this->cont[7];
+ } else {
+ reset( $redirLinks );
+ $redirStartAt = key( $redirLinks );
+ }
+ foreach ( $redirLinks as $key => $redir ) {
+ if ( $key < $redirStartAt ) {
+ continue;
+ }
+
$fit = $result->addValue(
- array( 'query', $this->getModuleName(), $pageID, 'redirlinks' ),
- $key, $redir );
+ array( 'query', $this->getModuleName(), $idx, 'redirlinks' ),
+ null, $redir );
if ( !$fit ) {
- $this->continueStr = $this->getContinueRedirStr( $pageID, $redir['pageid'] );
+ $this->continueStr = join( '|', array_slice( $this->cont, 0, 6 ) ) .
+ "|$pageID|$key";
break;
}
$hasRedirs = true;
}
if ( $hasRedirs ) {
- $result->setIndexedTagName_internal(
- array( 'query', $this->getModuleName(), $pageID, 'redirlinks' ),
+ $result->addIndexedTagName(
+ array( 'query', $this->getModuleName(), $idx, 'redirlinks' ),
$this->bl_code );
}
if ( !$fit ) {
break;
}
+
+ $idx++;
}
}
- $result->setIndexedTagName_internal(
+ $result->addIndexedTagName(
array( 'query', $this->getModuleName() ),
$this->bl_code
);
@@ -364,91 +504,6 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
}
}
- private function extractRowInfo( $row ) {
- $this->pageMap[$row->page_namespace][$row->page_title] = $row->page_id;
- $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 ) {
- $a['redirect'] = '';
- $this->redirTitles[] = $t;
- }
- // Put all the results in an array first
- $this->resultArr[$a['pageid']] = $a;
- }
-
- 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 ) {
- $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
- $this->resultArr[$parentID]['redirlinks'][] = $a;
- $this->getResult()->setIndexedTagName(
- $this->resultArr[$parentID]['redirlinks'],
- $this->bl_code
- );
- }
-
- protected function processContinue() {
- if ( !is_null( $this->params['continue'] ) ) {
- $this->parseContinueParam();
- } else {
- $this->rootTitle = $this->getTitleOrPageId( $this->params )->getTitle();
- }
-
- // only image titles are allowed for the root in imageinfo mode
- 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() {
- $continueList = explode( '|', $this->params['continue'] );
- // expected format:
- // ns | key | id1 [| id2]
- // ns+key: root title
- // id1: first-level page ID to continue from
- // id2: second-level page ID to continue from
-
- // 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] );
- $this->dieContinueUsageIf( $rootNs === 0 && $continueList[0] !== '0' );
-
- $this->rootTitle = Title::makeTitleSafe( $rootNs, $continueList[1] );
- $this->dieContinueUsageIf( !$this->rootTitle );
-
- $contID = intval( $continueList[2] );
- $this->dieContinueUsageIf( $contID === 0 && $continueList[2] !== '0' );
-
- $this->contID = $contID;
- $id2 = isset( $continueList[3] ) ? $continueList[3] : null;
- $redirID = intval( $id2 );
-
- if ( $redirID === 0 && $id2 !== '0' ) {
- // This one isn't required
- return;
- }
- $this->redirID = $redirID;
- }
-
- protected function getContinueStr( $lastPageID ) {
- return $this->rootTitle->getNamespace() .
- '|' . $this->rootTitle->getDBkey() .
- '|' . $lastPageID;
- }
-
- protected function getContinueRedirStr( $lastPageID, $lastRedirID ) {
- return $this->getContinueStr( $lastPageID ) . '|' . $lastRedirID;
- }
-
public function getAllowedParams() {
$retval = array(
'title' => array(
@@ -457,7 +512,9 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
'pageid' => array(
ApiBase::PARAM_TYPE => 'integer',
),
- 'continue' => null,
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ),
'namespace' => array(
ApiBase::PARAM_ISMULTI => true,
ApiBase::PARAM_TYPE => 'namespace'
@@ -493,59 +550,25 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
return $retval;
}
- public function getParamDescription() {
- $retval = array(
- 'title' => "Title to search. Cannot be used together with {$this->bl_code}pageid",
- 'pageid' => "Pageid to search. Cannot be used together with {$this->bl_code}title",
- 'continue' => 'When more results are available, use this to continue',
- 'namespace' => 'The namespace to enumerate',
- 'dir' => 'The direction in which to list',
- );
- 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'
- ) );
- }
-
- public function getDescription() {
- switch ( $this->getModuleName() ) {
- case 'backlinks':
- return 'Find all pages that link to the given page.';
- case 'embeddedin':
- return 'Find all pages that embed (transclude) the given title.';
- case 'imageusage':
- return 'Find all pages that use the given image title.';
- default:
- ApiBase::dieDebug( __METHOD__, 'Unknown module name.' );
- }
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
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'
+ 'action=query&list=backlinks&bltitle=Main%20Page'
+ => 'apihelp-query+backlinks-example-simple',
+ 'action=query&generator=backlinks&gbltitle=Main%20Page&prop=info'
+ => 'apihelp-query+backlinks-example-generator',
),
'embeddedin' => array(
- 'api.php?action=query&list=embeddedin&eititle=Template:Stub',
- 'api.php?action=query&generator=embeddedin&geititle=Template:Stub&prop=info'
+ 'action=query&list=embeddedin&eititle=Template:Stub'
+ => 'apihelp-query+embeddedin-example-simple',
+ 'action=query&generator=embeddedin&geititle=Template:Stub&prop=info'
+ => 'apihelp-query+embeddedin-example-generator',
),
'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'
+ 'action=query&list=imageusage&iutitle=File:Albert%20Einstein%20Head.jpg'
+ => 'apihelp-query+imageusage-example-simple',
+ 'action=query&generator=imageusage&giutitle=File:Albert%20Einstein%20Head.jpg&prop=info'
+ => 'apihelp-query+imageusage-example-generator',
)
);
diff --git a/includes/api/ApiQueryBacklinksprop.php b/includes/api/ApiQueryBacklinksprop.php
index cd682612..8e271e7b 100644
--- a/includes/api/ApiQueryBacklinksprop.php
+++ b/includes/api/ApiQueryBacklinksprop.php
@@ -40,15 +40,13 @@ class ApiQueryBacklinksprop extends ApiQueryGeneratorBase {
'code' => 'rd',
'prefix' => 'rd',
'linktable' => 'redirect',
- 'what' => 'redirects to',
- 'description' => 'Returns all redirects to the given pages.',
'props' => array(
- 'fragment' => 'Fragment of each redirect, if any',
+ 'fragment',
),
'showredirects' => false,
'show' => array(
- 'fragment' => 'Only show redirects with a fragment',
- '!fragment' => 'Only show redirects without a fragment',
+ 'fragment',
+ '!fragment',
),
),
'linkshere' => array(
@@ -56,8 +54,6 @@ class ApiQueryBacklinksprop extends ApiQueryGeneratorBase {
'prefix' => 'pl',
'linktable' => 'pagelinks',
'from_namespace' => true,
- 'what' => 'pages linking to',
- 'description' => 'Find all pages that link to the given pages.',
'showredirects' => true,
),
'transcludedin' => array(
@@ -65,8 +61,6 @@ class ApiQueryBacklinksprop extends ApiQueryGeneratorBase {
'prefix' => 'tl',
'linktable' => 'templatelinks',
'from_namespace' => true,
- 'what' => 'pages transcluding',
- 'description' => 'Find all pages that transclude the given pages.',
'showredirects' => true,
),
'fileusage' => array(
@@ -75,9 +69,7 @@ class ApiQueryBacklinksprop extends ApiQueryGeneratorBase {
'linktable' => 'imagelinks',
'from_namespace' => true,
'to_namespace' => NS_FILE,
- 'what' => 'pages using',
'exampletitle' => 'File:Example.jpg',
- 'description' => 'Find all pages that use the given files.',
'showredirects' => true,
),
);
@@ -106,8 +98,8 @@ class ApiQueryBacklinksprop extends ApiQueryGeneratorBase {
$emptyString = $db->addQuotes( '' );
$pageSet = $this->getPageSet();
- $titles = $pageSet->getGoodTitles() + $pageSet->getMissingTitles();
- $map = $pageSet->getAllTitlesByNamespace();
+ $titles = $pageSet->getGoodAndMissingTitles();
+ $map = $pageSet->getGoodAndMissingTitlesByNamespace();
// Determine our fields to query on
$p = $settings['prefix'];
@@ -295,8 +287,8 @@ class ApiQueryBacklinksprop extends ApiQueryGeneratorBase {
if ( $fld_fragment && $row->rd_fragment !== null && $row->rd_fragment !== '' ) {
$vals['fragment'] = $row->rd_fragment;
}
- if ( $fld_redirect && $row->page_is_redirect ) {
- $vals['redirect'] = '';
+ if ( $fld_redirect ) {
+ $vals['redirect'] = (bool)$row->page_is_redirect;
}
$fit = $this->addPageSubItem( $id, $vals );
if ( !$fit ) {
@@ -348,6 +340,7 @@ class ApiQueryBacklinksprop extends ApiQueryGeneratorBase {
ApiBase::PARAM_ISMULTI => true,
ApiBase::PARAM_TYPE => 'namespace',
),
+ 'show' => null, // Will be filled/removed below
'limit' => array(
ApiBase::PARAM_DFLT => 10,
ApiBase::PARAM_TYPE => 'limit',
@@ -355,16 +348,24 @@ class ApiQueryBacklinksprop extends ApiQueryGeneratorBase {
ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
),
- 'continue' => null,
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ),
);
+ if ( empty( $settings['from_namespace'] ) && $this->getConfig()->get( 'MiserMode' ) ) {
+ $ret['namespace'][ApiBase::PARAM_HELP_MSG_APPEND] = array(
+ 'api-help-param-limited-in-miser-mode',
+ );
+ }
+
if ( !empty( $settings['showredirects'] ) ) {
$ret['prop'][ApiBase::PARAM_TYPE][] = 'redirect';
$ret['prop'][ApiBase::PARAM_DFLT] .= '|redirect';
}
if ( isset( $settings['props'] ) ) {
$ret['prop'][ApiBase::PARAM_TYPE] = array_merge(
- $ret['prop'][ApiBase::PARAM_TYPE], array_keys( $settings['props'] )
+ $ret['prop'][ApiBase::PARAM_TYPE], $settings['props']
);
}
@@ -374,93 +375,32 @@ class ApiQueryBacklinksprop extends ApiQueryGeneratorBase {
$show[] = '!redirect';
}
if ( isset( $settings['show'] ) ) {
- $show = array_merge( $show, array_keys( $settings['show'] ) );
+ $show = array_merge( $show, $settings['show'] );
}
if ( $show ) {
$ret['show'] = array(
ApiBase::PARAM_TYPE => $show,
ApiBase::PARAM_ISMULTI => true,
);
+ } else {
+ unset( $ret['show'] );
}
return $ret;
}
- public function getParamDescription() {
- $settings = self::$settings[$this->getModuleName()];
- $p = $this->getModulePrefix();
-
- $ret = array(
- 'prop' => array(
- 'Which properties to get:',
- ),
- 'show' => array(
- 'Show only items that meet this criteria.',
- ),
- 'namespace' => 'Only include pages in these namespaces',
- 'limit' => 'How many to return',
- 'continue' => 'When more results are available, use this to continue',
- );
-
- if ( empty( $settings['from_namespace'] ) && $this->getConfig()->get( 'MiserMode' ) ) {
- $ret['namespace'] = array(
- $ret['namespace'],
- "NOTE: Due to \$wgMiserMode, using this may result in fewer than \"{$p}limit\" results",
- 'returned before continuing; in extreme cases, zero results may be returned.',
- );
- if ( isset( $ret['type'] ) ) {
- $ret['namespace'][] = "Note that you can use {$p}type=subcat or {$p}type=file " .
- "instead of {$p}namespace=14 or 6.";
- }
- }
-
- $props = array(
- 'pageid' => 'Adds the ID of page',
- 'title' => 'Adds the title and namespace ID of the page',
- );
- if ( !empty( $settings['showredirects'] ) ) {
- $props['redirect'] = 'Indicate if the page is a redirect';
- }
- if ( isset( $settings['props'] ) ) {
- $props += $settings['props'];
- }
- foreach ( $props as $k => $v ) {
- $ret['props'][] = sprintf( "%-9s - %s", $k, $v );
- }
-
- $show = array();
- if ( !empty( $settings['showredirects'] ) ) {
- $show += array(
- 'redirect' => 'Only show redirects',
- '!redirect' => 'Only show non-redirects',
- );
- }
- if ( isset( $settings['show'] ) ) {
- $show += $settings['show'];
- }
- foreach ( $show as $k => $v ) {
- $ret['show'][] = sprintf( "%-9s - %s", $k, $v );
- }
-
- return $ret;
- }
-
- public function getDescription() {
- return self::$settings[$this->getModuleName()]['description'];
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
$settings = self::$settings[$this->getModuleName()];
$name = $this->getModuleName();
- $what = $settings['what'];
+ $path = $this->getModulePath();
$title = isset( $settings['exampletitle'] ) ? $settings['exampletitle'] : 'Main Page';
$etitle = rawurlencode( $title );
return array(
- "api.php?action=query&prop={$name}&titles={$etitle}"
- => "Get a list of $what [[$title]]",
- "api.php?action=query&generator={$name}&titles={$etitle}&prop=info"
- => "Get information about $what [[$title]]",
+ "action=query&prop={$name}&titles={$etitle}"
+ => "apihelp-$path-example-simple",
+ "action=query&generator={$name}&titles={$etitle}&prop=info"
+ => "apihelp-$path-example-generator",
);
}
diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php
index 65e10ab7..a15754ce 100644
--- a/includes/api/ApiQueryBase.php
+++ b/includes/api/ApiQueryBase.php
@@ -70,6 +70,10 @@ abstract class ApiQueryBase extends ApiBase {
/**
* Override this method to request extra fields from the pageSet
* using $pageSet->requestField('fieldName')
+ *
+ * Note this only makes sense for 'prop' modules, as 'list' and 'meta'
+ * modules should not be using the pageset.
+ *
* @param ApiPageSet $pageSet
*/
public function requestExtraData( $pageSet ) {
@@ -91,6 +95,13 @@ abstract class ApiQueryBase extends ApiBase {
}
/**
+ * @see ApiBase::getParent()
+ */
+ public function getParent() {
+ return $this->getQuery();
+ }
+
+ /**
* Get the Query database connection (read-only)
* @return DatabaseBase
*/
@@ -361,12 +372,7 @@ abstract class ApiQueryBase extends ApiBase {
isset( $extraQuery['join_conds'] ) ? (array)$extraQuery['join_conds'] : array()
);
- // getDB has its own profileDBIn/Out calls
- $db = $this->getDB();
-
- $this->profileDBIn();
- $res = $db->select( $tables, $fields, $where, $method, $options, $join_conds );
- $this->profileDBOut();
+ $res = $this->getDB()->select( $tables, $fields, $where, $method, $options, $join_conds );
return $res;
}
@@ -450,7 +456,7 @@ abstract class ApiQueryBase extends ApiBase {
*/
protected function addPageSubItems( $pageId, $data ) {
$result = $this->getResult();
- $result->setIndexedTagName( $data, $this->getModulePrefix() );
+ ApiResult::setIndexedTagName( $data, $this->getModulePrefix() );
return $result->addValue( array( 'query', 'pages', intval( $pageId ) ),
$this->getModuleName(),
@@ -475,7 +481,7 @@ abstract class ApiQueryBase extends ApiBase {
if ( !$fit ) {
return false;
}
- $result->setIndexedTagName_internal( array( 'query', 'pages', $pageId,
+ $result->addIndexedTagName( array( 'query', 'pages', $pageId,
$this->getModuleName() ), $elemname );
return true;
@@ -487,7 +493,7 @@ abstract class ApiQueryBase extends ApiBase {
* @param string|array $paramValue Parameter value
*/
protected function setContinueEnumParameter( $paramName, $paramValue ) {
- $this->getResult()->setContinueParam( $this, $paramName, $paramValue );
+ $this->getContinuationManager()->addContinueParam( $this, $paramName, $paramValue );
}
/**
@@ -502,7 +508,8 @@ abstract class ApiQueryBase extends ApiBase {
*/
public function titlePartToKey( $titlePart, $namespace = NS_MAIN ) {
$t = Title::makeTitleSafe( $namespace, $titlePart . 'x' );
- if ( !$t ) {
+ if ( !$t || $t->hasFragment() ) {
+ // Invalid title (e.g. bad chars) or contained a '#'.
$this->dieUsageMsg( array( 'invalidtitle', $titlePart ) );
}
if ( $namespace != $t->getNamespace() || $t->isExternal() ) {
@@ -578,7 +585,6 @@ abstract class ApiQueryBase extends ApiBase {
protected function checkRowCount() {
wfDeprecated( __METHOD__, '1.24' );
$db = $this->getDB();
- $this->profileDBIn();
$rowcount = $db->estimateRowCount(
$this->tables,
$this->fields,
@@ -586,7 +592,6 @@ abstract class ApiQueryBase extends ApiBase {
__METHOD__,
$this->options
);
- $this->profileDBOut();
if ( $rowcount > $this->getConfig()->get( 'APIMaxDBRows' ) ) {
return false;
@@ -705,13 +710,24 @@ abstract class ApiQueryGeneratorBase extends ApiQueryBase {
*/
protected function setContinueEnumParameter( $paramName, $paramValue ) {
if ( $this->mGeneratorPageSet !== null ) {
- $this->getResult()->setGeneratorContinueParam( $this, $paramName, $paramValue );
+ $this->getContinuationManager()->addGeneratorContinueParam( $this, $paramName, $paramValue );
} else {
parent::setContinueEnumParameter( $paramName, $paramValue );
}
}
/**
+ * @see ApiBase::getHelpFlags()
+ *
+ * Corresponding messages: api-help-flag-generator
+ */
+ protected function getHelpFlags() {
+ $flags = parent::getHelpFlags();
+ $flags[] = 'generator';
+ return $flags;
+ }
+
+ /**
* Execute this module as a generator
* @param ApiPageSet $resultPageSet All output should be appended to this object
*/
diff --git a/includes/api/ApiQueryBlocks.php b/includes/api/ApiQueryBlocks.php
index 33b25fd9..4a7023b7 100644
--- a/includes/api/ApiQueryBlocks.php
+++ b/includes/api/ApiQueryBlocks.php
@@ -31,11 +31,6 @@
*/
class ApiQueryBlocks extends ApiQueryBase {
- /**
- * @var array
- */
- protected $usernames;
-
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'bk' );
}
@@ -62,12 +57,11 @@ class ApiQueryBlocks extends ApiQueryBase {
$result = $this->getResult();
$this->addTables( 'ipblocks' );
- $this->addFields( array( 'ipb_auto', 'ipb_id' ) );
+ $this->addFields( array( 'ipb_auto', 'ipb_id', 'ipb_timestamp' ) );
$this->addFieldsIf( array( 'ipb_address', 'ipb_user' ), $fld_user || $fld_userid );
$this->addFieldsIf( 'ipb_by_text', $fld_by );
$this->addFieldsIf( 'ipb_by', $fld_byid );
- $this->addFieldsIf( 'ipb_timestamp', $fld_timestamp );
$this->addFieldsIf( 'ipb_expiry', $fld_expiry );
$this->addFieldsIf( 'ipb_reason', $fld_reason );
$this->addFieldsIf( array( 'ipb_range_start', 'ipb_range_end' ), $fld_range );
@@ -102,10 +96,11 @@ class ApiQueryBlocks extends ApiQueryBase {
$this->addWhereFld( 'ipb_id', $params['ids'] );
}
if ( isset( $params['users'] ) ) {
+ $usernames = array();
foreach ( (array)$params['users'] as $u ) {
- $this->prepareUsername( $u );
+ $usernames[] = $this->prepareUsername( $u );
}
- $this->addWhereFld( 'ipb_address', $this->usernames );
+ $this->addWhereFld( 'ipb_address', $usernames );
$this->addWhereFld( 'ipb_auto', 0 );
}
if ( isset( $params['ip'] ) ) {
@@ -192,7 +187,9 @@ class ApiQueryBlocks extends ApiQueryBase {
$this->setContinueEnumParameter( 'continue', "$row->ipb_timestamp|$row->ipb_id" );
break;
}
- $block = array();
+ $block = array(
+ ApiResult::META_TYPE => 'assoc',
+ );
if ( $fld_id ) {
$block['id'] = $row->ipb_id;
}
@@ -223,27 +220,13 @@ class ApiQueryBlocks extends ApiQueryBase {
}
if ( $fld_flags ) {
// For clarity, these flags use the same names as their action=block counterparts
- if ( $row->ipb_auto ) {
- $block['automatic'] = '';
- }
- if ( $row->ipb_anon_only ) {
- $block['anononly'] = '';
- }
- if ( $row->ipb_create_account ) {
- $block['nocreate'] = '';
- }
- if ( $row->ipb_enable_autoblock ) {
- $block['autoblock'] = '';
- }
- if ( $row->ipb_block_email ) {
- $block['noemail'] = '';
- }
- if ( $row->ipb_deleted ) {
- $block['hidden'] = '';
- }
- if ( $row->ipb_allow_usertalk ) {
- $block['allowusertalk'] = '';
- }
+ $block['automatic'] = (bool)$row->ipb_auto;
+ $block['anononly'] = (bool)$row->ipb_anon_only;
+ $block['nocreate'] = (bool)$row->ipb_create_account;
+ $block['autoblock'] = (bool)$row->ipb_enable_autoblock;
+ $block['noemail'] = (bool)$row->ipb_block_email;
+ $block['hidden'] = (bool)$row->ipb_deleted;
+ $block['allowusertalk'] = (bool)$row->ipb_allow_usertalk;
}
$fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $block );
if ( !$fit ) {
@@ -251,7 +234,7 @@ class ApiQueryBlocks extends ApiQueryBase {
break;
}
}
- $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'block' );
+ $result->addIndexedTagName( array( 'query', $this->getModuleName() ), 'block' );
}
protected function prepareUsername( $user ) {
@@ -264,10 +247,12 @@ class ApiQueryBlocks extends ApiQueryBase {
if ( $name === false ) {
$this->dieUsage( "User name {$user} is not valid", 'param_user' );
}
- $this->usernames[] = $name;
+ return $name;
}
public function getAllowedParams() {
+ $blockCIDRLimit = $this->getConfig()->get( 'BlockCIDRLimit' );
+
return array(
'start' => array(
ApiBase::PARAM_TYPE => 'timestamp'
@@ -280,7 +265,8 @@ class ApiQueryBlocks extends ApiQueryBase {
'newer',
'older'
),
- ApiBase::PARAM_DFLT => 'older'
+ ApiBase::PARAM_DFLT => 'older',
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
),
'ids' => array(
ApiBase::PARAM_TYPE => 'integer',
@@ -289,7 +275,13 @@ class ApiQueryBlocks extends ApiQueryBase {
'users' => array(
ApiBase::PARAM_ISMULTI => true
),
- 'ip' => null,
+ 'ip' => array(
+ ApiBase::PARAM_HELP_MSG => array(
+ 'apihelp-query+blocks-param-ip',
+ $blockCIDRLimit['IPv4'],
+ $blockCIDRLimit['IPv6'],
+ ),
+ ),
'limit' => array(
ApiBase::PARAM_DFLT => 10,
ApiBase::PARAM_TYPE => 'limit',
@@ -326,56 +318,18 @@ class ApiQueryBlocks extends ApiQueryBase {
),
ApiBase::PARAM_ISMULTI => true
),
- 'continue' => null,
- );
- }
-
- public function getParamDescription() {
- $blockCIDRLimit = $this->getConfig()->get( 'BlockCIDRLimit' );
- $p = $this->getModulePrefix();
-
- return array(
- 'start' => 'The timestamp to start enumerating from',
- 'end' => 'The timestamp to stop enumerating at',
- 'dir' => $this->getDirectionDescription( $p ),
- 'ids' => 'List of block IDs to list (optional)',
- 'users' => 'List of users to search for (optional)',
- 'ip' => array(
- 'Get all blocks applying to this IP or CIDR range, including range blocks.',
- "Cannot be used together with bkusers. CIDR ranges broader than " .
- "IPv4/{$blockCIDRLimit['IPv4']} or IPv6/{$blockCIDRLimit['IPv6']} " .
- "are not accepted"
- ),
- 'limit' => 'The maximum amount of blocks to list',
- 'prop' => array(
- 'Which properties to get',
- ' id - Adds the ID of the block',
- ' user - Adds the username of the blocked user',
- ' userid - Adds the user ID of the blocked user',
- ' by - Adds the username of the blocking user',
- ' byid - Adds the user ID of the blocking user',
- ' timestamp - Adds the timestamp of when the block was given',
- ' expiry - Adds the timestamp of when the block expires',
- ' reason - Adds the reason given for the block',
- ' range - Adds the range of IPs affected by the block',
- ' flags - Tags the ban with (autoblock, anononly, etc)',
- ),
- 'show' => array(
- 'Show only items that meet this criteria.',
- "For example, to see only indefinite blocks on IPs, set {$p}show=ip|!temp"
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
),
- 'continue' => 'When more results are available, use this to continue',
);
}
- public function getDescription() {
- return 'List all blocked users and IP addresses.';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&list=blocks',
- 'api.php?action=query&list=blocks&bkusers=Alice|Bob'
+ 'action=query&list=blocks'
+ => 'apihelp-query+blocks-example-simple',
+ 'action=query&list=blocks&bkusers=Alice|Bob'
+ => 'apihelp-query+blocks-example-users',
);
}
diff --git a/includes/api/ApiQueryCategories.php b/includes/api/ApiQueryCategories.php
index 1926dd09..35fa56ef 100644
--- a/includes/api/ApiQueryCategories.php
+++ b/includes/api/ApiQueryCategories.php
@@ -117,8 +117,6 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
}
}
- $this->addOption( 'USE INDEX', array( 'categorylinks' => 'cl_from' ) );
-
$sort = ( $params['dir'] == 'descending' ? ' DESC' : '' );
// Don't order by cl_from if it's constant in the WHERE clause
if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) {
@@ -152,8 +150,8 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
if ( isset( $prop['timestamp'] ) ) {
$vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->cl_timestamp );
}
- if ( isset( $prop['hidden'] ) && !is_null( $row->pp_propname ) ) {
- $vals['hidden'] = '';
+ if ( isset( $prop['hidden'] ) ) {
+ $vals['hidden'] = !is_null( $row->pp_propname );
}
$fit = $this->addPageSubItem( $row->cl_from, $vals );
@@ -202,7 +200,9 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
),
- 'continue' => null,
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ),
'categories' => array(
ApiBase::PARAM_ISMULTI => true,
),
@@ -216,34 +216,12 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
);
}
- public function getParamDescription() {
- return array(
- 'prop' => array(
- 'Which additional properties to get for each category',
- ' sortkey - Adds the sortkey (hexadecimal string) and sortkey prefix',
- ' (human-readable part) for the category',
- ' timestamp - Adds timestamp of when the category was added',
- ' hidden - Tags categories that are hidden with __HIDDENCAT__',
- ),
- 'limit' => 'How many categories to return',
- 'show' => 'Which kind of categories to show',
- 'continue' => 'When more results are available, use this to continue',
- 'categories' => 'Only list these categories. Useful for checking ' .
- 'whether a certain page is in a certain category',
- 'dir' => 'The direction in which to list',
- );
- }
-
- public function getDescription() {
- return 'List all categories the page(s) belong to.';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&prop=categories&titles=Albert%20Einstein'
- => 'Get a list of categories [[Albert Einstein]] belongs to',
- 'api.php?action=query&generator=categories&titles=Albert%20Einstein&prop=info'
- => 'Get information about all categories used in the [[Albert Einstein]]',
+ 'action=query&prop=categories&titles=Albert%20Einstein'
+ => 'apihelp-query+categories-example-simple',
+ 'action=query&generator=categories&titles=Albert%20Einstein&prop=info'
+ => 'apihelp-query+categories-example-generator',
);
}
diff --git a/includes/api/ApiQueryCategoryInfo.php b/includes/api/ApiQueryCategoryInfo.php
index 6e9f33c1..9f6c6044 100644
--- a/includes/api/ApiQueryCategoryInfo.php
+++ b/includes/api/ApiQueryCategoryInfo.php
@@ -38,14 +38,13 @@ class ApiQueryCategoryInfo extends ApiQueryBase {
public function execute() {
$params = $this->extractRequestParams();
- $alltitles = $this->getPageSet()->getAllTitlesByNamespace();
+ $alltitles = $this->getPageSet()->getGoodAndMissingTitlesByNamespace();
if ( empty( $alltitles[NS_CATEGORY] ) ) {
return;
}
$categories = $alltitles[NS_CATEGORY];
- $titles = $this->getPageSet()->getGoodTitles() +
- $this->getPageSet()->getMissingTitles();
+ $titles = $this->getPageSet()->getGoodAndMissingTitles();
$cattitles = array();
foreach ( $categories as $c ) {
/** @var $t Title */
@@ -87,9 +86,7 @@ class ApiQueryCategoryInfo extends ApiQueryBase {
$vals['pages'] = $row->cat_pages - $row->cat_subcats - $row->cat_files;
$vals['files'] = intval( $row->cat_files );
$vals['subcats'] = intval( $row->cat_subcats );
- if ( $row->cat_hidden ) {
- $vals['hidden'] = '';
- }
+ $vals['hidden'] = (bool)$row->cat_hidden;
$fit = $this->addPageSubItems( $catids[$row->cat_title], $vals );
if ( !$fit ) {
$this->setContinueEnumParameter( 'continue', $row->cat_title );
@@ -104,24 +101,19 @@ class ApiQueryCategoryInfo extends ApiQueryBase {
public function getAllowedParams() {
return array(
- 'continue' => null,
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ),
);
}
- public function getParamDescription() {
+ protected function getExamplesMessages() {
return array(
- 'continue' => 'When more results are available, use this to continue',
+ 'action=query&prop=categoryinfo&titles=Category:Foo|Category:Bar'
+ => 'apihelp-query+categoryinfo-example-simple',
);
}
- public function getDescription() {
- return 'Returns information about the given categories.';
- }
-
- public function getExamples() {
- return 'api.php?action=query&prop=categoryinfo&titles=Category:Foo|Category:Bar';
- }
-
public function getHelpUrls() {
return 'https://www.mediawiki.org/wiki/API:Properties#categoryinfo_.2F_ci';
}
diff --git a/includes/api/ApiQueryCategoryMembers.php b/includes/api/ApiQueryCategoryMembers.php
index a88a9cb1..ec0c1d14 100644
--- a/includes/api/ApiQueryCategoryMembers.php
+++ b/includes/api/ApiQueryCategoryMembers.php
@@ -48,6 +48,15 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
}
/**
+ * @param string $hexSortkey
+ * @return bool
+ */
+ private function validateHexSortkey( $hexSortkey ) {
+ // A hex sortkey has an unbound number of 2 letter pairs
+ return preg_match( '/^(?:[a-fA-F0-9]{2})*$/', $hexSortkey );
+ }
+
+ /**
* @param ApiPageSet $resultPageSet
* @return void
*/
@@ -128,6 +137,7 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
$queryTypes = array_slice( $queryTypes, $contTypeIndex );
// Add a WHERE clause for sortkey and from
+ $this->dieContinueUsageIf( !$this->validateHexSortkey( $cont[1] ) );
// pack( "H*", $foo ) is used to convert hex back to binary
$escSortkey = $this->getDB()->addQuotes( pack( 'H*', $cont[1] ) );
$from = intval( $cont[2] );
@@ -143,6 +153,9 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
if ( $params['startsortkeyprefix'] !== null ) {
$startsortkey = Collation::singleton()->getSortkey( $params['startsortkeyprefix'] );
} elseif ( $params['starthexsortkey'] !== null ) {
+ if ( !$this->validateHexSortkey( $params['starthexsortkey'] ) ) {
+ $this->dieUsage( 'The starthexsortkey provided is not valid', 'bad_starthexsortkey' );
+ }
$startsortkey = pack( 'H*', $params['starthexsortkey'] );
} else {
$this->logFeatureUsage( 'list=categorymembers&cmstartsortkey' );
@@ -151,6 +164,9 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
if ( $params['endsortkeyprefix'] !== null ) {
$endsortkey = Collation::singleton()->getSortkey( $params['endsortkeyprefix'] );
} elseif ( $params['endhexsortkey'] !== null ) {
+ if ( !$this->validateHexSortkey( $params['endhexsortkey'] ) ) {
+ $this->dieUsage( 'The endhexsortkey provided is not valid', 'bad_endhexsortkey' );
+ }
$endsortkey = pack( 'H*', $params['endhexsortkey'] );
} else {
$this->logFeatureUsage( 'list=categorymembers&cmendsortkey' );
@@ -230,7 +246,9 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
}
if ( is_null( $resultPageSet ) ) {
- $vals = array();
+ $vals = array(
+ ApiResult::META_TYPE => 'assoc',
+ );
if ( $fld_ids ) {
$vals['pageid'] = intval( $row->page_id );
}
@@ -269,13 +287,13 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
}
if ( is_null( $resultPageSet ) ) {
- $result->setIndexedTagName_internal(
+ $result->addIndexedTagName(
array( 'query', $this->getModuleName() ), 'cm' );
}
}
public function getAllowedParams() {
- return array(
+ $ret = array(
'title' => array(
ApiBase::PARAM_TYPE => 'string',
),
@@ -307,7 +325,9 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
'file'
)
),
- 'continue' => null,
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ),
'limit' => array(
ApiBase::PARAM_TYPE => 'limit',
ApiBase::PARAM_DFLT => 10,
@@ -351,67 +371,22 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase {
ApiBase::PARAM_DEPRECATED => true,
),
);
- }
-
- public function getParamDescription() {
- $p = $this->getModulePrefix();
- $desc = array(
- 'title' => "Which category to enumerate (required). Must include " .
- "'Category:' prefix. Cannot be used together with {$p}pageid",
- 'pageid' => "Page ID of the category to enumerate. Cannot be used together with {$p}title",
- 'prop' => array(
- 'What pieces of information to include',
- ' ids - Adds the page ID',
- ' title - Adds the title and namespace ID of the page',
- ' sortkey - Adds the sortkey used for sorting in the category (hexadecimal string)',
- ' sortkeyprefix - Adds the sortkey prefix used for sorting in the ' .
- 'category (human-readable part of the sortkey)',
- ' type - Adds the type that the page has been categorised as (page, subcat or file)',
- ' timestamp - Adds the timestamp of when the page was included',
- ),
- 'namespace' => 'Only include pages in these namespaces',
- 'type' => "What type of category members to include. Ignored when {$p}sort=timestamp is set",
- 'sort' => 'Property to sort by',
- 'dir' => 'In which direction to sort',
- 'start' => "Timestamp to start listing from. Can only be used with {$p}sort=timestamp",
- 'end' => "Timestamp to end listing at. Can only be used with {$p}sort=timestamp",
- 'starthexsortkey' => "Sortkey to start listing from, as returned by prop=sortkey. " .
- "Can only be used with {$p}sort=sortkey",
- 'endhexsortkey' => "Sortkey to end listing from, as returned by prop=sortkey. " .
- "Can only be used with {$p}sort=sortkey",
- 'startsortkeyprefix' => "Sortkey prefix to start listing from. Can " .
- "only be used with {$p}sort=sortkey. Overrides {$p}starthexsortkey",
- 'endsortkeyprefix' => "Sortkey prefix to end listing BEFORE (not at, " .
- "if this value occurs it will not be included!). Can only be used with " .
- "{$p}sort=sortkey. Overrides {$p}endhexsortkey",
- 'startsortkey' => "Use starthexsortkey instead",
- 'endsortkey' => "Use endhexsortkey instead",
- 'continue' => 'For large categories, give the value returned from previous query',
- 'limit' => 'The maximum number of pages to return.',
- );
if ( $this->getConfig()->get( 'MiserMode' ) ) {
- $desc['namespace'] = array(
- $desc['namespace'],
- "NOTE: Due to \$wgMiserMode, using this may result in fewer than \"{$p}limit\" results",
- 'returned before continuing; in extreme cases, zero results may be returned.',
- "Note that you can use {$p}type=subcat or {$p}type=file instead of {$p}namespace=14 or 6.",
+ $ret['namespace'][ApiBase::PARAM_HELP_MSG_APPEND] = array(
+ 'api-help-param-limited-in-miser-mode',
);
}
- return $desc;
- }
-
- public function getDescription() {
- return 'List all pages in a given category.';
+ return $ret;
}
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&list=categorymembers&cmtitle=Category:Physics'
- => 'Get first 10 pages in [[Category:Physics]]',
- 'api.php?action=query&generator=categorymembers&gcmtitle=Category:Physics&prop=info'
- => 'Get page info about first 10 pages in [[Category:Physics]]',
+ 'action=query&list=categorymembers&cmtitle=Category:Physics'
+ => 'apihelp-query+categorymembers-example-simple',
+ 'action=query&generator=categorymembers&gcmtitle=Category:Physics&prop=info'
+ => 'apihelp-query+categorymembers-example-generator',
);
}
diff --git a/includes/api/ApiQueryContributors.php b/includes/api/ApiQueryContributors.php
index 55ea4702..7e76db25 100644
--- a/includes/api/ApiQueryContributors.php
+++ b/includes/api/ApiQueryContributors.php
@@ -236,43 +236,16 @@ class ApiQueryContributors extends ApiQueryBase {
ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
),
- 'continue' => null,
- );
- }
-
- public function getParamDescription() {
- return array(
- 'group' => array(
- 'Limit users to given group name(s)',
- 'Does not include implicit or auto-promoted groups like *, user, or autoconfirmed'
- ),
- 'excludegroup' => array(
- 'Exclude users in given group name(s)',
- 'Does not include implicit or auto-promoted groups like *, user, or autoconfirmed'
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
),
- 'rights' => array(
- 'Limit users to those having given right(s)',
- 'Does not include rights granted by implicit or auto-promoted groups ' .
- 'like *, user, or autoconfirmed'
- ),
- 'excluderights' => array(
- 'Limit users to those not having given right(s)',
- 'Does not include rights granted by implicit or auto-promoted groups ' .
- 'like *, user, or autoconfirmed'
- ),
- 'limit' => 'How many contributors to return',
- 'continue' => 'When more results are available, use this to continue',
);
}
- public function getDescription() {
- return 'Get the list of logged-in contributors and ' .
- 'the count of anonymous contributors to a page.';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&prop=contributors&titles=Main_Page',
+ 'action=query&prop=contributors&titles=Main_Page'
+ => 'apihelp-query+contributors-example-simple',
);
}
diff --git a/includes/api/ApiQueryDeletedRevisions.php b/includes/api/ApiQueryDeletedRevisions.php
new file mode 100644
index 00000000..26ae2668
--- /dev/null
+++ b/includes/api/ApiQueryDeletedRevisions.php
@@ -0,0 +1,304 @@
+<?php
+/**
+ * Created on Oct 3, 2014
+ *
+ * Copyright © 2014 Brad Jorsch "bjorsch@wikimedia.org"
+ *
+ * Heavily based on ApiQueryDeletedrevs,
+ * Copyright © 2007 Roan Kattouw "<Firstname>.<Lastname>@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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * Query module to enumerate deleted revisions for pages.
+ *
+ * @ingroup API
+ */
+class ApiQueryDeletedRevisions extends ApiQueryRevisionsBase {
+
+ public function __construct( ApiQuery $query, $moduleName ) {
+ parent::__construct( $query, $moduleName, 'drv' );
+ }
+
+ protected function run( ApiPageSet $resultPageSet = null ) {
+ $user = $this->getUser();
+ // Before doing anything at all, let's check permissions
+ if ( !$user->isAllowed( 'deletedhistory' ) ) {
+ $this->dieUsage(
+ 'You don\'t have permission to view deleted revision information',
+ 'permissiondenied'
+ );
+ }
+
+ $result = $this->getResult();
+ $pageSet = $this->getPageSet();
+ $pageMap = $pageSet->getGoodAndMissingTitlesByNamespace();
+ $pageCount = count( $pageSet->getGoodAndMissingTitles() );
+ $revCount = $pageSet->getRevisionCount();
+ if ( $revCount === 0 && $pageCount === 0 ) {
+ // Nothing to do
+ return;
+ }
+ if ( $revCount !== 0 && count( $pageSet->getDeletedRevisionIDs() ) === 0 ) {
+ // Nothing to do, revisions were supplied but none are deleted
+ return;
+ }
+
+ $params = $this->extractRequestParams( false );
+
+ $db = $this->getDB();
+
+ if ( !is_null( $params['user'] ) && !is_null( $params['excludeuser'] ) ) {
+ $this->dieUsage( 'user and excludeuser cannot be used together', 'badparams' );
+ }
+
+ $this->addTables( 'archive' );
+ if ( $resultPageSet === null ) {
+ $this->parseParameters( $params );
+ $this->addFields( Revision::selectArchiveFields() );
+ $this->addFields( array( 'ar_title', 'ar_namespace' ) );
+ } else {
+ $this->limit = $this->getParameter( 'limit' ) ?: 10;
+ $this->addFields( array( 'ar_title', 'ar_namespace', 'ar_timestamp', 'ar_rev_id', 'ar_id' ) );
+ }
+
+ if ( $this->fld_tags ) {
+ $this->addTables( 'tag_summary' );
+ $this->addJoinConds(
+ array( 'tag_summary' => array( 'LEFT JOIN', array( 'ar_rev_id=ts_rev_id' ) ) )
+ );
+ $this->addFields( 'ts_tags' );
+ }
+
+ if ( !is_null( $params['tag'] ) ) {
+ $this->addTables( 'change_tag' );
+ $this->addJoinConds(
+ array( 'change_tag' => array( 'INNER JOIN', array( 'ar_rev_id=ct_rev_id' ) ) )
+ );
+ $this->addWhereFld( 'ct_tag', $params['tag'] );
+ }
+
+ if ( $this->fetchContent ) {
+ // Modern MediaWiki has the content for deleted revs in the 'text'
+ // table using fields old_text and old_flags. But revisions deleted
+ // pre-1.5 store the content in the 'archive' table directly using
+ // fields ar_text and ar_flags, and no corresponding 'text' row. So
+ // we have to LEFT JOIN and fetch all four fields.
+ $this->addTables( 'text' );
+ $this->addJoinConds(
+ array( 'text' => array( 'LEFT JOIN', array( 'ar_text_id=old_id' ) ) )
+ );
+ $this->addFields( array( 'ar_text', 'ar_flags', 'old_text', 'old_flags' ) );
+
+ // This also means stricter restrictions
+ if ( !$user->isAllowedAny( 'undelete', 'deletedtext' ) ) {
+ $this->dieUsage(
+ 'You don\'t have permission to view deleted revision content',
+ 'permissiondenied'
+ );
+ }
+ }
+
+ $dir = $params['dir'];
+
+ if ( $revCount !== 0 ) {
+ $this->addWhere( array(
+ 'ar_rev_id' => array_keys( $pageSet->getDeletedRevisionIDs() )
+ ) );
+ } else {
+ // We need a custom WHERE clause that matches all titles.
+ $lb = new LinkBatch( $pageSet->getGoodAndMissingTitles() );
+ $where = $lb->constructSet( 'ar', $db );
+ $this->addWhere( $where );
+ }
+
+ if ( !is_null( $params['user'] ) ) {
+ $this->addWhereFld( 'ar_user_text', $params['user'] );
+ } elseif ( !is_null( $params['excludeuser'] ) ) {
+ $this->addWhere( 'ar_user_text != ' .
+ $db->addQuotes( $params['excludeuser'] ) );
+ }
+
+ if ( !is_null( $params['user'] ) || !is_null( $params['excludeuser'] ) ) {
+ // Paranoia: avoid brute force searches (bug 17342)
+ // (shouldn't be able to get here without 'deletedhistory', but
+ // check it again just in case)
+ if ( !$user->isAllowed( 'deletedhistory' ) ) {
+ $bitmask = Revision::DELETED_USER;
+ } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
+ $bitmask = Revision::DELETED_USER | Revision::DELETED_RESTRICTED;
+ } else {
+ $bitmask = 0;
+ }
+ if ( $bitmask ) {
+ $this->addWhere( $db->bitAnd( 'ar_deleted', $bitmask ) . " != $bitmask" );
+ }
+ }
+
+ if ( !is_null( $params['continue'] ) ) {
+ $cont = explode( '|', $params['continue'] );
+ $op = ( $dir == 'newer' ? '>' : '<' );
+ if ( $revCount !== 0 ) {
+ $this->dieContinueUsageIf( count( $cont ) != 2 );
+ $rev = intval( $cont[0] );
+ $this->dieContinueUsageIf( strval( $rev ) !== $cont[0] );
+ $ar_id = (int)$cont[1];
+ $this->dieContinueUsageIf( strval( $ar_id ) !== $cont[1] );
+ $this->addWhere( "ar_rev_id $op $rev OR " .
+ "(ar_rev_id = $rev AND " .
+ "ar_id $op= $ar_id)" );
+ } else {
+ $this->dieContinueUsageIf( count( $cont ) != 4 );
+ $ns = intval( $cont[0] );
+ $this->dieContinueUsageIf( strval( $ns ) !== $cont[0] );
+ $title = $db->addQuotes( $cont[1] );
+ $ts = $db->addQuotes( $db->timestamp( $cont[2] ) );
+ $ar_id = (int)$cont[3];
+ $this->dieContinueUsageIf( strval( $ar_id ) !== $cont[3] );
+ $this->addWhere( "ar_namespace $op $ns OR " .
+ "(ar_namespace = $ns AND " .
+ "(ar_title $op $title OR " .
+ "(ar_title = $title AND " .
+ "(ar_timestamp $op $ts OR " .
+ "(ar_timestamp = $ts AND " .
+ "ar_id $op= $ar_id)))))" );
+ }
+ }
+
+ $this->addOption( 'LIMIT', $this->limit + 1 );
+
+ if ( $revCount !== 0 ) {
+ // Sort by ar_rev_id when querying by ar_rev_id
+ $this->addWhereRange( 'ar_rev_id', $dir, null, null );
+ } else {
+ // Sort by ns and title in the same order as timestamp for efficiency
+ // But only when not already unique in the query
+ if ( count( $pageMap ) > 1 ) {
+ $this->addWhereRange( 'ar_namespace', $dir, null, null );
+ }
+ $oneTitle = key( reset( $pageMap ) );
+ foreach ( $pageMap as $pages ) {
+ if ( count( $pages ) > 1 || key( $pages ) !== $oneTitle ) {
+ $this->addWhereRange( 'ar_title', $dir, null, null );
+ break;
+ }
+ }
+ $this->addTimestampWhereRange( 'ar_timestamp', $dir, $params['start'], $params['end'] );
+ }
+ // Include in ORDER BY for uniqueness
+ $this->addWhereRange( 'ar_id', $dir, null, null );
+
+ $res = $this->select( __METHOD__ );
+ $count = 0;
+ $generated = array();
+ foreach ( $res as $row ) {
+ if ( ++$count > $this->limit ) {
+ // We've had enough
+ $this->setContinueEnumParameter( 'continue',
+ $revCount
+ ? "$row->ar_rev_id|$row->ar_id"
+ : "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
+ );
+ break;
+ }
+
+ if ( $resultPageSet !== null ) {
+ $generated[] = $row->ar_rev_id;
+ } else {
+ if ( !isset( $pageMap[$row->ar_namespace][$row->ar_title] ) ) {
+ // Was it converted?
+ $title = Title::makeTitle( $row->ar_namespace, $row->ar_title );
+ $converted = $pageSet->getConvertedTitles();
+ if ( $title && isset( $converted[$title->getPrefixedText()] ) ) {
+ $title = Title::newFromText( $converted[$title->getPrefixedText()] );
+ if ( $title && isset( $pageMap[$title->getNamespace()][$title->getDBkey()] ) ) {
+ $pageMap[$row->ar_namespace][$row->ar_title] =
+ $pageMap[$title->getNamespace()][$title->getDBkey()];
+ }
+ }
+ }
+ if ( !isset( $pageMap[$row->ar_namespace][$row->ar_title] ) ) {
+ ApiBase::dieDebug( "Found row in archive (ar_id={$row->ar_id}) that didn't " .
+ "get processed by ApiPageSet" );
+ }
+
+ $fit = $this->addPageSubItem(
+ $pageMap[$row->ar_namespace][$row->ar_title],
+ $this->extractRevisionInfo( Revision::newFromArchiveRow( $row ), $row ),
+ 'rev'
+ );
+ if ( !$fit ) {
+ $this->setContinueEnumParameter( 'continue',
+ $revCount
+ ? "$row->ar_rev_id|$row->ar_id"
+ : "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
+ );
+ break;
+ }
+ }
+ }
+
+ if ( $resultPageSet !== null ) {
+ $resultPageSet->populateFromRevisionIDs( $generated );
+ }
+ }
+
+ public function getAllowedParams() {
+ return parent::getAllowedParams() + array(
+ 'start' => array(
+ ApiBase::PARAM_TYPE => 'timestamp',
+ ),
+ 'end' => array(
+ ApiBase::PARAM_TYPE => 'timestamp',
+ ),
+ 'dir' => array(
+ ApiBase::PARAM_TYPE => array(
+ 'newer',
+ 'older'
+ ),
+ ApiBase::PARAM_DFLT => 'older',
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
+ ),
+ 'tag' => null,
+ 'user' => array(
+ ApiBase::PARAM_TYPE => 'user'
+ ),
+ 'excludeuser' => array(
+ ApiBase::PARAM_TYPE => 'user'
+ ),
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ),
+ );
+ }
+
+ protected function getExamplesMessages() {
+ return array(
+ 'action=query&prop=deletedrevisions&titles=Main%20Page|Talk:Main%20Page&' .
+ 'drvprop=user|comment|content'
+ => 'apihelp-query+deletedrevisions-example-titles',
+ 'action=query&prop=deletedrevisions&revids=123456'
+ => 'apihelp-query+deletedrevisions-example-revids',
+ );
+ }
+
+ public function getHelpUrls() {
+ return 'https://www.mediawiki.org/wiki/API:Properties#deletedrevisions_.2F_drv';
+ }
+}
diff --git a/includes/api/ApiQueryDeletedrevs.php b/includes/api/ApiQueryDeletedrevs.php
index 9042696b..72a331f1 100644
--- a/includes/api/ApiQueryDeletedrevs.php
+++ b/includes/api/ApiQueryDeletedrevs.php
@@ -28,6 +28,7 @@
* Query module to enumerate all deleted revisions.
*
* @ingroup API
+ * @deprecated since 1.25
*/
class ApiQueryDeletedrevs extends ApiQueryBase {
@@ -45,6 +46,12 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
);
}
+ $this->setWarning(
+ 'list=deletedrevs has been deprecated. Please use prop=deletedrevisions or ' .
+ 'list=alldeletedrevisions instead.'
+ );
+ $this->logFeatureUsage( 'action=query&list=deletedrevs' );
+
$db = $this->getDB();
$params = $this->extractRequestParams( false );
$prop = array_flip( $params['prop'] );
@@ -68,8 +75,9 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
);
}
- // If we're in JSON callback mode, no tokens can be obtained
- if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) {
+ // If we're in a mode that breaks the same-origin policy, no tokens can
+ // be obtained
+ if ( $this->lacksSameOriginSecurity() ) {
$fld_token = false;
}
@@ -169,7 +177,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
if ( $limit == 'max' ) {
$limit = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
- $this->getResult()->setParsedLimit( $this->getModuleName(), $limit );
+ $this->getResult()->addParsedLimit( $this->getModuleName(), $limit );
}
$this->validateLimit( 'limit', $limit, 1, $userMax, $botMax );
@@ -312,7 +320,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
}
if ( $fld_user || $fld_userid ) {
if ( $row->ar_deleted & Revision::DELETED_USER ) {
- $rev['userhidden'] = '';
+ $rev['userhidden'] = true;
$anyHidden = true;
}
if ( Revision::userCanBitfield( $row->ar_deleted, Revision::DELETED_USER, $user ) ) {
@@ -327,7 +335,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
if ( $fld_comment || $fld_parsedcomment ) {
if ( $row->ar_deleted & Revision::DELETED_COMMENT ) {
- $rev['commenthidden'] = '';
+ $rev['commenthidden'] = true;
$anyHidden = true;
}
if ( Revision::userCanBitfield( $row->ar_deleted, Revision::DELETED_COMMENT, $user ) ) {
@@ -341,15 +349,15 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
}
}
- if ( $fld_minor && $row->ar_minor_edit == 1 ) {
- $rev['minor'] = '';
+ if ( $fld_minor ) {
+ $rev['minor'] = $row->ar_minor_edit == 1;
}
if ( $fld_len ) {
$rev['len'] = $row->ar_len;
}
if ( $fld_sha1 ) {
if ( $row->ar_deleted & Revision::DELETED_TEXT ) {
- $rev['sha1hidden'] = '';
+ $rev['sha1hidden'] = true;
$anyHidden = true;
}
if ( Revision::userCanBitfield( $row->ar_deleted, Revision::DELETED_TEXT, $user ) ) {
@@ -362,15 +370,15 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
}
if ( $fld_content ) {
if ( $row->ar_deleted & Revision::DELETED_TEXT ) {
- $rev['texthidden'] = '';
+ $rev['texthidden'] = true;
$anyHidden = true;
}
if ( Revision::userCanBitfield( $row->ar_deleted, Revision::DELETED_TEXT, $user ) ) {
if ( isset( $row->ar_text ) && !$row->ar_text_id ) {
// Pre-1.5 ar_text row (if condition from Revision::newFromArchiveRow)
- ApiResult::setContent( $rev, Revision::getRevisionText( $row, 'ar_' ) );
+ ApiResult::setContentValue( $rev, 'text', Revision::getRevisionText( $row, 'ar_' ) );
} else {
- ApiResult::setContent( $rev, Revision::getRevisionText( $row ) );
+ ApiResult::setContentValue( $rev, 'text', Revision::getRevisionText( $row ) );
}
}
}
@@ -378,7 +386,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
if ( $fld_tags ) {
if ( $row->ts_tags ) {
$tags = explode( ',', $row->ts_tags );
- $this->getResult()->setIndexedTagName( $tags, 'tag' );
+ ApiResult::setIndexedTagName( $tags, 'tag' );
$rev['tags'] = $tags;
} else {
$rev['tags'] = array();
@@ -386,14 +394,14 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
}
if ( $anyHidden && ( $row->ar_deleted & Revision::DELETED_RESTRICTED ) ) {
- $rev['suppressed'] = '';
+ $rev['suppressed'] = true;
}
if ( !isset( $pageMap[$row->ar_namespace][$row->ar_title] ) ) {
$pageID = $newPageID++;
$pageMap[$row->ar_namespace][$row->ar_title] = $pageID;
$a['revisions'] = array( $rev );
- $result->setIndexedTagName( $a['revisions'], 'rev' );
+ ApiResult::setIndexedTagName( $a['revisions'], 'rev' );
$title = Title::makeTitle( $row->ar_namespace, $row->ar_title );
ApiQueryBase::addTitleInfo( $a, $title );
if ( $fld_token ) {
@@ -417,46 +425,56 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
break;
}
}
- $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'page' );
+ $result->addIndexedTagName( array( 'query', $this->getModuleName() ), 'page' );
+ }
+
+ public function isDeprecated() {
+ return true;
}
public function getAllowedParams() {
return array(
'start' => array(
- ApiBase::PARAM_TYPE => 'timestamp'
+ ApiBase::PARAM_TYPE => 'timestamp',
+ ApiBase::PARAM_HELP_MSG_INFO => array( array( 'modes', 1, 2 ) ),
),
'end' => array(
ApiBase::PARAM_TYPE => 'timestamp',
+ ApiBase::PARAM_HELP_MSG_INFO => array( array( 'modes', 1, 2 ) ),
),
'dir' => array(
ApiBase::PARAM_TYPE => array(
'newer',
'older'
),
- ApiBase::PARAM_DFLT => 'older'
+ ApiBase::PARAM_DFLT => 'older',
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
+ ApiBase::PARAM_HELP_MSG_INFO => array( array( 'modes', 1, 3 ) ),
),
- 'from' => null,
- 'to' => null,
- 'prefix' => null,
- 'continue' => null,
- 'unique' => false,
- 'tag' => null,
- 'user' => array(
- ApiBase::PARAM_TYPE => 'user'
+ 'from' => array(
+ ApiBase::PARAM_HELP_MSG_INFO => array( array( 'modes', 3 ) ),
),
- 'excludeuser' => array(
- ApiBase::PARAM_TYPE => 'user'
+ 'to' => array(
+ ApiBase::PARAM_HELP_MSG_INFO => array( array( 'modes', 3 ) ),
+ ),
+ 'prefix' => array(
+ ApiBase::PARAM_HELP_MSG_INFO => array( array( 'modes', 3 ) ),
+ ),
+ 'unique' => array(
+ ApiBase::PARAM_DFLT => false,
+ ApiBase::PARAM_HELP_MSG_INFO => array( array( 'modes', 3 ) ),
),
'namespace' => array(
ApiBase::PARAM_TYPE => 'namespace',
ApiBase::PARAM_DFLT => NS_MAIN,
+ ApiBase::PARAM_HELP_MSG_INFO => array( array( 'modes', 3 ) ),
),
- '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
+ 'tag' => null,
+ 'user' => array(
+ ApiBase::PARAM_TYPE => 'user'
+ ),
+ 'excludeuser' => array(
+ ApiBase::PARAM_TYPE => 'user'
),
'prop' => array(
ApiBase::PARAM_DFLT => 'user|comment',
@@ -476,68 +494,30 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
),
ApiBase::PARAM_ISMULTI => true
),
- );
- }
-
- public function getParamDescription() {
- return array(
- 'start' => 'The timestamp to start enumerating from (1, 2)',
- 'end' => 'The timestamp to stop enumerating at (1, 2)',
- 'dir' => $this->getDirectionDescription( $this->getModulePrefix(), ' (1, 3)' ),
- 'from' => 'Start listing at this title (3)',
- 'to' => 'Stop listing at this title (3)',
- 'prefix' => 'Search for all page titles that begin with this value (3)',
- 'limit' => 'The maximum amount of revisions to list',
- 'prop' => array(
- 'Which properties to get',
- ' revid - Adds the revision ID of the deleted revision',
- ' parentid - Adds the revision ID of the previous revision to the page',
- ' user - Adds the user who made the revision',
- ' userid - Adds the user ID whom made the revision',
- ' comment - Adds the comment of the revision',
- ' parsedcomment - Adds the parsed comment of the revision',
- ' minor - Tags if the revision is minor',
- ' len - Adds the length (bytes) of the revision',
- ' sha1 - Adds the SHA-1 (base 16) of the revision',
- ' content - Adds the content of the revision',
- ' token - DEPRECATED! Gives the edit token',
- ' tags - Tags for the revision',
+ '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
+ ),
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
),
- 'namespace' => 'Only list pages in this namespace (3)',
- 'user' => 'Only list revisions by this user',
- 'excludeuser' => 'Don\'t list revisions by this user',
- 'continue' => 'When more results are available, use this to continue',
- 'unique' => 'List only one revision for each page (3)',
- 'tag' => 'Only list revisions tagged with this tag',
- );
- }
-
- public function getDescription() {
- $p = $this->getModulePrefix();
-
- return array(
- 'List deleted revisions.',
- 'Operates in three modes:',
- ' 1) List deleted revisions for the given title(s), sorted by timestamp.',
- ' 2) List deleted contributions for the given user, sorted by timestamp (no titles specified).',
- ' 3) List all deleted revisions in the given namespace, sorted by title and timestamp',
- " (no titles specified, {$p}user not set).",
- 'Certain parameters only apply to some modes and are ignored in others.',
- 'For instance, a parameter marked (1) only applies to mode 1 and is ignored in modes 2 and 3.',
);
}
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&list=deletedrevs&titles=Main%20Page|Talk:Main%20Page&' .
+ 'action=query&list=deletedrevs&titles=Main%20Page|Talk:Main%20Page&' .
'drprop=user|comment|content'
- => 'List the last deleted revisions of Main Page and Talk:Main Page, with content (mode 1)',
- 'api.php?action=query&list=deletedrevs&druser=Bob&drlimit=50'
- => 'List the last 50 deleted contributions by Bob (mode 2)',
- 'api.php?action=query&list=deletedrevs&drdir=newer&drlimit=50'
- => 'List the first 50 deleted revisions in the main namespace (mode 3)',
- 'api.php?action=query&list=deletedrevs&drdir=newer&drlimit=50&drnamespace=1&drunique='
- => 'List the first 50 deleted pages in the Talk namespace (mode 3):',
+ => 'apihelp-query+deletedrevs-example-mode1',
+ 'action=query&list=deletedrevs&druser=Bob&drlimit=50'
+ => 'apihelp-query+deletedrevs-example-mode2',
+ 'action=query&list=deletedrevs&drdir=newer&drlimit=50'
+ => 'apihelp-query+deletedrevs-example-mode3-main',
+ 'action=query&list=deletedrevs&drdir=newer&drlimit=50&drnamespace=1&drunique='
+ => 'apihelp-query+deletedrevs-example-mode3-talk',
);
}
diff --git a/includes/api/ApiQueryDisabled.php b/includes/api/ApiQueryDisabled.php
index cf0d841e..a6509d41 100644
--- a/includes/api/ApiQueryDisabled.php
+++ b/includes/api/ApiQueryDisabled.php
@@ -44,17 +44,7 @@ class ApiQueryDisabled extends ApiQueryBase {
return array();
}
- public function getParamDescription() {
- return array();
- }
-
- public function getDescription() {
- return array(
- 'This module has been disabled.'
- );
- }
-
- public function getExamples() {
- return array();
+ public function getDescriptionMessage() {
+ return 'apihelp-query+disabled-description';
}
}
diff --git a/includes/api/ApiQueryDuplicateFiles.php b/includes/api/ApiQueryDuplicateFiles.php
index 6d836cd5..4d0bcfed 100644
--- a/includes/api/ApiQueryDuplicateFiles.php
+++ b/includes/api/ApiQueryDuplicateFiles.php
@@ -52,7 +52,7 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase {
*/
private function run( $resultPageSet = null ) {
$params = $this->extractRequestParams();
- $namespaces = $this->getPageSet()->getAllTitlesByNamespace();
+ $namespaces = $this->getPageSet()->getGoodAndMissingTitlesByNamespace();
if ( empty( $namespaces[NS_FILE] ) ) {
return;
}
@@ -137,11 +137,9 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase {
$r = array(
'name' => $dupName,
'user' => $dupFile->getUser( 'text' ),
- 'timestamp' => wfTimestamp( TS_ISO_8601, $dupFile->getTimestamp() )
+ 'timestamp' => wfTimestamp( TS_ISO_8601, $dupFile->getTimestamp() ),
+ 'shared' => !$dupFile->isLocal(),
);
- if ( !$dupFile->isLocal() ) {
- $r['shared'] = '';
- }
$fit = $this->addPageSubItem( $pageId, $r );
if ( !$fit ) {
$this->setContinueEnumParameter( 'continue', $image . '|' . $dupName );
@@ -167,7 +165,9 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase {
ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
),
- 'continue' => null,
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ),
'dir' => array(
ApiBase::PARAM_DFLT => 'ascending',
ApiBase::PARAM_TYPE => array(
@@ -179,23 +179,12 @@ class ApiQueryDuplicateFiles extends ApiQueryGeneratorBase {
);
}
- public function getParamDescription() {
- return array(
- 'limit' => 'How many duplicate files to return',
- 'continue' => 'When more results are available, use this to continue',
- 'dir' => 'The direction in which to list',
- 'localonly' => 'Look only for files in the local repository',
- );
- }
-
- public function getDescription() {
- return 'List all files that are duplicates of the given file(s) based on hash values.';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&titles=File:Albert_Einstein_Head.jpg&prop=duplicatefiles',
- 'api.php?action=query&generator=allimages&prop=duplicatefiles',
+ 'action=query&titles=File:Albert_Einstein_Head.jpg&prop=duplicatefiles'
+ => 'apihelp-query+duplicatefiles-example-simple',
+ 'action=query&generator=allimages&prop=duplicatefiles'
+ => 'apihelp-query+duplicatefiles-example-generated',
);
}
diff --git a/includes/api/ApiQueryExtLinksUsage.php b/includes/api/ApiQueryExtLinksUsage.php
index faabb920..3f65a19e 100644
--- a/includes/api/ApiQueryExtLinksUsage.php
+++ b/includes/api/ApiQueryExtLinksUsage.php
@@ -112,7 +112,9 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
}
if ( is_null( $resultPageSet ) ) {
- $vals = array();
+ $vals = array(
+ ApiResult::META_TYPE => 'assoc',
+ );
if ( $fld_ids ) {
$vals['pageid'] = intval( $row->page_id );
}
@@ -139,13 +141,13 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
}
if ( is_null( $resultPageSet ) ) {
- $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ),
+ $result->addIndexedTagName( array( 'query', $this->getModuleName() ),
$this->getModulePrefix() );
}
}
public function getAllowedParams() {
- return array(
+ $ret = array(
'prop' => array(
ApiBase::PARAM_ISMULTI => true,
ApiBase::PARAM_DFLT => 'ids|title|url',
@@ -156,7 +158,8 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
)
),
'offset' => array(
- ApiBase::PARAM_TYPE => 'integer'
+ ApiBase::PARAM_TYPE => 'integer',
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
),
'protocol' => array(
ApiBase::PARAM_TYPE => self::prepareProtocols(),
@@ -176,6 +179,14 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
),
'expandurl' => false,
);
+
+ if ( $this->getConfig()->get( 'MiserMode' ) ) {
+ $ret['namespace'][ApiBase::PARAM_HELP_MSG_APPEND] = array(
+ 'api-help-param-limited-in-miser-mode',
+ );
+ }
+
+ return $ret;
}
public static function prepareProtocols() {
@@ -207,45 +218,10 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
}
}
- public function getParamDescription() {
- $p = $this->getModulePrefix();
- $desc = array(
- 'prop' => array(
- 'What pieces of information to include',
- ' ids - Adds the ID of page',
- ' title - Adds the title and namespace ID of the page',
- ' url - Adds the URL used in the page',
- ),
- 'offset' => 'Used for paging. Use the value returned for "continue"',
- 'protocol' => array(
- "Protocol of the URL. If empty and {$p}query set, the protocol is http.",
- "Leave both this and {$p}query empty to list all external links"
- ),
- 'query' => 'Search string without protocol. See [[Special:LinkSearch]]. ' .
- 'Leave empty to list all external links',
- 'namespace' => 'The page namespace(s) to enumerate.',
- 'limit' => 'How many pages to return.',
- 'expandurl' => 'Expand protocol-relative URLs with the canonical protocol',
- );
-
- if ( $this->getConfig()->get( 'MiserMode' ) ) {
- $desc['namespace'] = array(
- $desc['namespace'],
- "NOTE: Due to \$wgMiserMode, using this may result in fewer than \"{$p}limit\" results",
- 'returned before continuing; in extreme cases, zero results may be returned',
- );
- }
-
- return $desc;
- }
-
- public function getDescription() {
- return 'Enumerate pages that contain a given URL.';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&list=exturlusage&euquery=www.mediawiki.org'
+ 'action=query&list=exturlusage&euquery=www.mediawiki.org'
+ => 'apihelp-query+exturlusage-example-simple',
);
}
diff --git a/includes/api/ApiQueryExternalLinks.php b/includes/api/ApiQueryExternalLinks.php
index 95666354..ec3d9d27 100644
--- a/includes/api/ApiQueryExternalLinks.php
+++ b/includes/api/ApiQueryExternalLinks.php
@@ -91,7 +91,7 @@ class ApiQueryExternalLinks extends ApiQueryBase {
if ( $params['expandurl'] ) {
$to = wfExpandUrl( $to, PROTO_CANONICAL );
}
- ApiResult::setContent( $entry, $to );
+ ApiResult::setContentValue( $entry, 'url', $to );
$fit = $this->addPageSubItem( $row->el_from, $entry );
if ( !$fit ) {
$this->setContinueEnumParameter( 'offset', $offset + $count - 1 );
@@ -114,7 +114,8 @@ class ApiQueryExternalLinks extends ApiQueryBase {
ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
),
'offset' => array(
- ApiBase::PARAM_TYPE => 'integer'
+ ApiBase::PARAM_TYPE => 'integer',
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
),
'protocol' => array(
ApiBase::PARAM_TYPE => ApiQueryExtLinksUsage::prepareProtocols(),
@@ -125,30 +126,10 @@ class ApiQueryExternalLinks extends ApiQueryBase {
);
}
- public function getParamDescription() {
- $p = $this->getModulePrefix();
-
- return array(
- 'limit' => 'How many links to return',
- 'offset' => 'When more results are available, use this to continue',
- 'protocol' => array(
- "Protocol of the URL. If empty and {$p}query set, the protocol is http.",
- "Leave both this and {$p}query empty to list all external links"
- ),
- 'query' => 'Search string without protocol. Useful for checking ' .
- 'whether a certain page contains a certain external url',
- 'expandurl' => 'Expand protocol-relative URLs with the canonical protocol',
- );
- }
-
- public function getDescription() {
- return 'Returns all external URLs (not interwikis) from the given page(s).';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&prop=extlinks&titles=Main%20Page'
- => 'Get a list of external links on the [[Main Page]]',
+ 'action=query&prop=extlinks&titles=Main%20Page'
+ => 'apihelp-query+extlinks-example-simple',
);
}
diff --git a/includes/api/ApiQueryFileRepoInfo.php b/includes/api/ApiQueryFileRepoInfo.php
index d1600efe..9ad7e27e 100644
--- a/includes/api/ApiQueryFileRepoInfo.php
+++ b/includes/api/ApiQueryFileRepoInfo.php
@@ -55,7 +55,9 @@ class ApiQueryFileRepoInfo extends ApiQueryBase {
$repos[] = array_intersect_key( $repoGroup->getLocalRepo()->getInfo(), $props );
$result = $this->getResult();
- $result->setIndexedTagName( $repos, 'repo' );
+ ApiResult::setIndexedTagName( $repos, 'repo' );
+ ApiResult::setArrayTypeRecursive( $repos, 'assoc' );
+ ApiResult::setArrayType( $repos, 'array' );
$result->addValue( array( 'query' ), 'repos', $repos );
}
@@ -89,27 +91,10 @@ class ApiQueryFileRepoInfo extends ApiQueryBase {
) ) );
}
- public function getParamDescription() {
+ protected function getExamplesMessages() {
return array(
- 'prop' => array(
- 'Which repository properties to get (there may be more available on some wikis):',
- ' apiurl - URL to the repository API - helpful for getting image info from the host.',
- ' name - The key of the repository - used in e.g. ' .
- '$wgForeignFileRepos and imageinfo return values.',
- ' displayname - The human-readable name of the repository wiki.',
- ' rooturl - Root URL for image paths.',
- ' local - Whether that repository is the local one or not.',
- ),
- );
- }
-
- public function getDescription() {
- return 'Return meta information about image repositories configured on the wiki.';
- }
-
- public function getExamples() {
- return array(
- 'api.php?action=query&meta=filerepoinfo&friprop=apiurl|name|displayname',
+ 'action=query&meta=filerepoinfo&friprop=apiurl|name|displayname'
+ => 'apihelp-query+filerepoinfo-example-simple',
);
}
}
diff --git a/includes/api/ApiQueryFilearchive.php b/includes/api/ApiQueryFilearchive.php
index f047d8d4..4d357a7f 100644
--- a/includes/api/ApiQueryFilearchive.php
+++ b/includes/api/ApiQueryFilearchive.php
@@ -193,7 +193,7 @@ class ApiQueryFilearchive extends ApiQueryBase {
$pageCount = ArchivedFile::newFromRow( $row )->pageCount();
if ( $pageCount !== false ) {
- $vals['pagecount'] = $pageCount;
+ $file['pagecount'] = $pageCount;
}
$file['height'] = $row->fa_height;
@@ -218,17 +218,17 @@ class ApiQueryFilearchive extends ApiQueryBase {
}
if ( $row->fa_deleted & File::DELETED_FILE ) {
- $file['filehidden'] = '';
+ $file['filehidden'] = true;
}
if ( $row->fa_deleted & File::DELETED_COMMENT ) {
- $file['commenthidden'] = '';
+ $file['commenthidden'] = true;
}
if ( $row->fa_deleted & File::DELETED_USER ) {
- $file['userhidden'] = '';
+ $file['userhidden'] = true;
}
if ( $row->fa_deleted & File::DELETED_RESTRICTED ) {
// This file is deleted for normal admins
- $file['suppressed'] = '';
+ $file['suppressed'] = true;
}
$fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $file );
@@ -240,22 +240,14 @@ class ApiQueryFilearchive extends ApiQueryBase {
}
}
- $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'fa' );
+ $result->addIndexedTagName( array( 'query', $this->getModuleName() ), 'fa' );
}
public function getAllowedParams() {
return array(
'from' => null,
- 'continue' => null,
'to' => null,
'prefix' => null,
- '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(
@@ -283,48 +275,23 @@ class ApiQueryFilearchive extends ApiQueryBase {
'archivename',
),
),
- );
- }
-
- public function getParamDescription() {
- return array(
- 'from' => 'The image title to start enumerating from',
- 'continue' => 'When more results are available, use this to continue',
- 'to' => 'The image title to stop enumerating at',
- 'prefix' => 'Search for all image titles that begin with this value',
- 'dir' => 'The direction in which to list',
- 'limit' => 'How many images to return in total',
- 'sha1' => "SHA1 hash of image. Overrides {$this->getModulePrefix()}sha1base36",
- 'sha1base36' => 'SHA1 hash of image in base 36 (used in MediaWiki)',
- 'prop' => array(
- 'What image information to get:',
- ' sha1 - Adds SHA-1 hash for the image',
- ' timestamp - Adds timestamp for the uploaded version',
- ' user - Adds user who uploaded the image version',
- ' size - Adds the size of the image in bytes and the height, ' .
- 'width and page count (if applicable)',
- ' dimensions - Alias for size',
- ' description - Adds description the image version',
- ' parseddescription - Parse the description on the version',
- ' mime - Adds MIME of the image',
- ' mediatype - Adds the media type of the image',
- ' metadata - Lists Exif metadata for the version of the image',
- ' bitdepth - Adds the bit depth of the version',
- ' archivename - Adds the file name of the archive version for non-latest versions'
+ '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
+ ),
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
),
);
}
- public function getDescription() {
- return 'Enumerate all deleted files sequentially.';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&list=filearchive' => array(
- 'Simple Use',
- 'Show a list of all deleted files',
- ),
+ 'action=query&list=filearchive'
+ => 'apihelp-query+filearchive-example-simple',
);
}
diff --git a/includes/api/ApiQueryIWBacklinks.php b/includes/api/ApiQueryIWBacklinks.php
index b5aa45bf..618387d2 100644
--- a/includes/api/ApiQueryIWBacklinks.php
+++ b/includes/api/ApiQueryIWBacklinks.php
@@ -132,7 +132,7 @@ class ApiQueryIWBacklinks extends ApiQueryGeneratorBase {
ApiQueryBase::addTitleInfo( $entry, $title );
if ( $row->page_is_redirect ) {
- $entry['redirect'] = '';
+ $entry['redirect'] = true;
}
if ( $iwprefix ) {
@@ -155,7 +155,7 @@ class ApiQueryIWBacklinks extends ApiQueryGeneratorBase {
}
if ( is_null( $resultPageSet ) ) {
- $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'iw' );
+ $result->addIndexedTagName( array( 'query', $this->getModuleName() ), 'iw' );
} else {
$resultPageSet->populateFromTitles( $pages );
}
@@ -169,7 +169,9 @@ class ApiQueryIWBacklinks extends ApiQueryGeneratorBase {
return array(
'prefix' => null,
'title' => null,
- 'continue' => null,
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ),
'limit' => array(
ApiBase::PARAM_DFLT => 10,
ApiBase::PARAM_TYPE => 'limit',
@@ -195,33 +197,12 @@ class ApiQueryIWBacklinks extends ApiQueryGeneratorBase {
);
}
- public function getParamDescription() {
- return array(
- 'prefix' => 'Prefix for the interwiki',
- 'title' => "Interwiki link to search for. Must be used with {$this->getModulePrefix()}prefix",
- 'continue' => 'When more results are available, use this to continue',
- 'prop' => array(
- 'Which properties to get',
- ' iwprefix - Adds the prefix of the interwiki',
- ' iwtitle - Adds the title of the interwiki',
- ),
- 'limit' => 'How many total pages to return',
- 'dir' => 'The direction in which to list',
- );
- }
-
- public function getDescription() {
- return array( 'Find all pages that link to the given interwiki link.',
- 'Can be used to find all links with a prefix, or',
- 'all links to a title (with a given prefix).',
- 'Using neither parameter is effectively "All IW Links".',
- );
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&list=iwbacklinks&iwbltitle=Test&iwblprefix=wikibooks',
- 'api.php?action=query&generator=iwbacklinks&giwbltitle=Test&giwblprefix=wikibooks&prop=info'
+ 'action=query&list=iwbacklinks&iwbltitle=Test&iwblprefix=wikibooks'
+ => 'apihelp-query+iwbacklinks-example-simple',
+ 'action=query&generator=iwbacklinks&giwbltitle=Test&giwblprefix=wikibooks&prop=info'
+ => 'apihelp-query+iwbacklinks-example-generator',
);
}
diff --git a/includes/api/ApiQueryIWLinks.php b/includes/api/ApiQueryIWLinks.php
index a185ee24..aca3f700 100644
--- a/includes/api/ApiQueryIWLinks.php
+++ b/includes/api/ApiQueryIWLinks.php
@@ -129,7 +129,7 @@ class ApiQueryIWLinks extends ApiQueryBase {
}
}
- ApiResult::setContent( $entry, $row->iwl_title );
+ ApiResult::setContentValue( $entry, 'title', $row->iwl_title );
$fit = $this->addPageSubItem( $row->iwl_from, $entry );
if ( !$fit ) {
$this->setContinueEnumParameter(
@@ -147,24 +147,12 @@ class ApiQueryIWLinks extends ApiQueryBase {
public function getAllowedParams() {
return array(
- 'url' => array(
- ApiBase::PARAM_DFLT => false,
- ApiBase::PARAM_DEPRECATED => true,
- ),
'prop' => array(
ApiBase::PARAM_ISMULTI => true,
ApiBase::PARAM_TYPE => array(
'url',
)
),
- '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
- ),
- 'continue' => null,
'prefix' => null,
'title' => null,
'dir' => array(
@@ -174,32 +162,27 @@ class ApiQueryIWLinks extends ApiQueryBase {
'descending'
)
),
- );
- }
-
- public function getParamDescription() {
- return array(
- 'prop' => array(
- 'Which additional properties to get for each interlanguage link',
- ' url - Adds the full URL',
+ '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
+ ),
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ),
+ 'url' => array(
+ ApiBase::PARAM_DFLT => false,
+ ApiBase::PARAM_DEPRECATED => true,
),
- 'url' => "Whether to get the full URL (Cannot be used with {$this->getModulePrefix()}prop)",
- 'limit' => 'How many interwiki links to return',
- 'continue' => 'When more results are available, use this to continue',
- 'prefix' => 'Prefix for the interwiki',
- 'title' => "Interwiki link to search for. Must be used with {$this->getModulePrefix()}prefix",
- 'dir' => 'The direction in which to list',
);
}
- public function getDescription() {
- return 'Returns all interwiki links from the given page(s).';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&prop=iwlinks&titles=Main%20Page'
- => 'Get interwiki links from the [[Main Page]]',
+ 'action=query&prop=iwlinks&titles=Main%20Page'
+ => 'apihelp-query+iwlinks-example-simple',
);
}
diff --git a/includes/api/ApiQueryImageInfo.php b/includes/api/ApiQueryImageInfo.php
index 945374b1..94b4bbdb 100644
--- a/includes/api/ApiQueryImageInfo.php
+++ b/includes/api/ApiQueryImageInfo.php
@@ -58,7 +58,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
'revdelUser' => $this->getUser(),
);
- $pageIds = $this->getPageSet()->getAllTitlesByNamespace();
+ $pageIds = $this->getPageSet()->getGoodAndMissingTitlesByNamespace();
if ( !empty( $pageIds[NS_FILE] ) ) {
$titles = array_keys( $pageIds[NS_FILE] );
asort( $titles ); // Ensure the order is always the same
@@ -373,7 +373,9 @@ class ApiQueryImageInfo extends ApiQueryBase {
);
}
$version = $opts['version'];
- $vals = array();
+ $vals = array(
+ ApiResult::META_TYPE => 'assoc',
+ );
// Timestamp is shown even if the file is revdelete'd in interface
// so do same here.
if ( isset( $prop['timestamp'] ) ) {
@@ -397,7 +399,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
if ( $user || $userid ) {
if ( $file->isDeleted( File::DELETED_USER ) ) {
- $vals['userhidden'] = '';
+ $vals['userhidden'] = true;
$anyHidden = true;
}
if ( $canShowField( File::DELETED_USER ) ) {
@@ -408,7 +410,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
$vals['userid'] = $file->getUser( 'id' );
}
if ( !$file->getUser( 'id' ) ) {
- $vals['anon'] = '';
+ $vals['anon'] = true;
}
}
}
@@ -438,7 +440,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
if ( $pcomment || $comment ) {
if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
- $vals['commenthidden'] = '';
+ $vals['commenthidden'] = true;
$anyHidden = true;
}
if ( $canShowField( File::DELETED_COMMENT ) ) {
@@ -469,7 +471,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
}
if ( $file->isDeleted( File::DELETED_FILE ) ) {
- $vals['filehidden'] = '';
+ $vals['filehidden'] = true;
$anyHidden = true;
}
@@ -599,7 +601,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
$retval[] = $r;
}
}
- $result->setIndexedTagName( $retval, 'metadata' );
+ ApiResult::setIndexedTagName( $retval, 'metadata' );
return $retval;
}
@@ -632,7 +634,8 @@ class ApiQueryImageInfo extends ApiQueryBase {
'prop' => array(
ApiBase::PARAM_ISMULTI => true,
ApiBase::PARAM_DFLT => 'timestamp|user',
- ApiBase::PARAM_TYPE => self::getPropertyNames()
+ ApiBase::PARAM_TYPE => self::getPropertyNames(),
+ ApiBase::PARAM_HELP_MSG_PER_VALUE => self::getPropertyMessages(),
),
'limit' => array(
ApiBase::PARAM_TYPE => 'limit',
@@ -649,7 +652,11 @@ class ApiQueryImageInfo extends ApiQueryBase {
),
'urlwidth' => array(
ApiBase::PARAM_TYPE => 'integer',
- ApiBase::PARAM_DFLT => -1
+ ApiBase::PARAM_DFLT => -1,
+ ApiBase::PARAM_HELP_MSG => array(
+ 'apihelp-query+imageinfo-param-urlwidth',
+ ApiQueryImageInfo::TRANSFORM_LIMIT,
+ ),
),
'urlheight' => array(
ApiBase::PARAM_TYPE => 'integer',
@@ -675,7 +682,9 @@ class ApiQueryImageInfo extends ApiQueryBase {
ApiBase::PARAM_DFLT => '',
ApiBase::PARAM_TYPE => 'string',
),
- 'continue' => null,
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ),
'localonly' => false,
);
}
@@ -684,16 +693,49 @@ class ApiQueryImageInfo extends ApiQueryBase {
* Returns all possible parameters to iiprop
*
* @param array $filter List of properties to filter out
- *
* @return array
*/
public static function getPropertyNames( $filter = array() ) {
- return array_diff( array_keys( self::getProperties() ), $filter );
+ return array_keys( self::getPropertyMessages( $filter ) );
+ }
+
+ /**
+ * Returns messages for all possible parameters to iiprop
+ *
+ * @param array $filter List of properties to filter out
+ * @return array
+ */
+ public static function getPropertyMessages( $filter = array() ) {
+ return array_diff_key(
+ array(
+ 'timestamp' => 'apihelp-query+imageinfo-paramvalue-prop-timestamp',
+ 'user' => 'apihelp-query+imageinfo-paramvalue-prop-user',
+ 'userid' => 'apihelp-query+imageinfo-paramvalue-prop-userid',
+ 'comment' => 'apihelp-query+imageinfo-paramvalue-prop-comment',
+ 'parsedcomment' => 'apihelp-query+imageinfo-paramvalue-prop-parsedcomment',
+ 'canonicaltitle' => 'apihelp-query+imageinfo-paramvalue-prop-canonicaltitle',
+ 'url' => 'apihelp-query+imageinfo-paramvalue-prop-url',
+ 'size' => 'apihelp-query+imageinfo-paramvalue-prop-size',
+ 'dimensions' => 'apihelp-query+imageinfo-paramvalue-prop-dimensions',
+ 'sha1' => 'apihelp-query+imageinfo-paramvalue-prop-sha1',
+ 'mime' => 'apihelp-query+imageinfo-paramvalue-prop-mime',
+ 'thumbmime' => 'apihelp-query+imageinfo-paramvalue-prop-thumbmime',
+ 'mediatype' => 'apihelp-query+imageinfo-paramvalue-prop-mediatype',
+ 'metadata' => 'apihelp-query+imageinfo-paramvalue-prop-metadata',
+ 'commonmetadata' => 'apihelp-query+imageinfo-paramvalue-prop-commonmetadata',
+ 'extmetadata' => 'apihelp-query+imageinfo-paramvalue-prop-extmetadata',
+ 'archivename' => 'apihelp-query+imageinfo-paramvalue-prop-archivename',
+ 'bitdepth' => 'apihelp-query+imageinfo-paramvalue-prop-bitdepth',
+ 'uploadwarning' => 'apihelp-query+imageinfo-paramvalue-prop-uploadwarning',
+ ),
+ array_flip( $filter )
+ );
}
/**
* Returns array key value pairs of properties and their descriptions
*
+ * @deprecated since 1.25
* @param string $modulePrefix
* @return array
*/
@@ -730,6 +772,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
/**
* Returns the descriptions for the properties provided by getPropertyNames()
*
+ * @deprecated since 1.25
* @param array $filter List of properties to filter out
* @param string $modulePrefix
* @return array
@@ -741,55 +784,13 @@ class ApiQueryImageInfo extends ApiQueryBase {
);
}
- /**
- * Return the API documentation for the parameters.
- * @return array Parameter documentation.
- */
- public function getParamDescription() {
- $p = $this->getModulePrefix();
-
- return array(
- 'prop' => self::getPropertyDescriptions( array(), $p ),
- 'urlwidth' => array(
- "If {$p}prop=url is set, a URL to an image scaled to this width will be returned.",
- 'For performance reasons if this option is used, ' .
- 'no more than ' . self::TRANSFORM_LIMIT . ' scaled images will be returned.'
- ),
- 'urlheight' => "Similar to {$p}urlwidth.",
- 'urlparam' => array(
- "A handler specific parameter string. For example, pdf's ",
- "might use 'page15-100px'."
- ),
- 'limit' => 'How many image revisions to return per image',
- 'start' => 'Timestamp to start listing from',
- 'end' => 'Timestamp to stop listing at',
- 'metadataversion'
- => array( "Version of metadata to use. if 'latest' is specified, use latest version.",
- "Defaults to '1' for backwards compatibility" ),
- 'extmetadatalanguage' => array(
- 'What language to fetch extmetadata in. This affects both which',
- 'translation to fetch, if multiple are available, as well as how things',
- 'like numbers and various values are formatted.'
- ),
- 'extmetadatamultilang'
- =>'If translations for extmetadata property are available, fetch all of them.',
- 'extmetadatafilter'
- => "If specified and non-empty, only these keys will be returned for {$p}prop=extmetadata",
- 'continue' => 'If the query response includes a continue value, ' .
- 'use it here to get another page of results',
- 'localonly' => 'Look only for files in the local repository',
- );
- }
-
- public function getDescription() {
- return 'Returns image information and upload history.';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&titles=File:Albert%20Einstein%20Head.jpg&prop=imageinfo',
- 'api.php?action=query&titles=File:Test.jpg&prop=imageinfo&iilimit=50&' .
- 'iiend=20071231235959&iiprop=timestamp|user|url',
+ 'action=query&titles=File:Albert%20Einstein%20Head.jpg&prop=imageinfo'
+ => 'apihelp-query+imageinfo-example-simple',
+ 'action=query&titles=File:Test.jpg&prop=imageinfo&iilimit=50&' .
+ 'iiend=2007-12-31T23:59:59Z&iiprop=timestamp|user|url'
+ => 'apihelp-query+imageinfo-example-dated',
);
}
diff --git a/includes/api/ApiQueryImages.php b/includes/api/ApiQueryImages.php
index 9bc3abed..029d945d 100644
--- a/includes/api/ApiQueryImages.php
+++ b/includes/api/ApiQueryImages.php
@@ -146,7 +146,9 @@ class ApiQueryImages extends ApiQueryGeneratorBase {
ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
),
- 'continue' => null,
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ),
'images' => array(
ApiBase::PARAM_ISMULTI => true,
),
@@ -160,26 +162,12 @@ class ApiQueryImages extends ApiQueryGeneratorBase {
);
}
- public function getParamDescription() {
- return array(
- 'limit' => 'How many images to return',
- 'continue' => 'When more results are available, use this to continue',
- 'images' => 'Only list these images. Useful for checking whether a ' .
- 'certain page has a certain Image.',
- 'dir' => 'The direction in which to list',
- );
- }
-
- public function getDescription() {
- return 'Returns all images contained on the given page(s).';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&prop=images&titles=Main%20Page'
- => 'Get a list of images used in the [[Main Page]]',
- 'api.php?action=query&generator=images&titles=Main%20Page&prop=info'
- => 'Get information about all images used in the [[Main Page]]',
+ 'action=query&prop=images&titles=Main%20Page'
+ => 'apihelp-query+images-example-simple',
+ 'action=query&generator=images&titles=Main%20Page&prop=info'
+ => 'apihelp-query+images-example-generator',
);
}
diff --git a/includes/api/ApiQueryInfo.php b/includes/api/ApiQueryInfo.php
index d7037e3a..66178d4f 100644
--- a/includes/api/ApiQueryInfo.php
+++ b/includes/api/ApiQueryInfo.php
@@ -42,12 +42,14 @@ class ApiQueryInfo extends ApiQueryBase {
private $pageRestrictions, $pageIsRedir, $pageIsNew, $pageTouched,
$pageLatest, $pageLength;
- private $protections, $watched, $watchers, $notificationtimestamps,
+ private $protections, $restrictionTypes, $watched, $watchers, $notificationtimestamps,
$talkids, $subjectids, $displaytitles;
private $showZeroWatchers = false;
private $tokenFunctions;
+ private $countTestedActions = 0;
+
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'in' );
}
@@ -58,21 +60,21 @@ class ApiQueryInfo extends ApiQueryBase {
*/
public function requestExtraData( $pageSet ) {
$pageSet->requestField( 'page_restrictions' );
- // when resolving redirects, no page will have this field
- if ( !$pageSet->isResolvingRedirects() ) {
- $pageSet->requestField( 'page_is_redirect' );
- }
+ // If the pageset is resolving redirects we won't get page_is_redirect.
+ // But we can't know for sure until the pageset is executed (revids may
+ // turn it off), so request it unconditionally.
+ $pageSet->requestField( 'page_is_redirect' );
$pageSet->requestField( 'page_is_new' );
$config = $this->getConfig();
- if ( !$config->get( 'DisableCounters' ) ) {
- $pageSet->requestField( 'page_counter' );
- }
$pageSet->requestField( 'page_touched' );
$pageSet->requestField( 'page_latest' );
$pageSet->requestField( 'page_len' );
if ( $config->get( 'ContentHandlerUseDB' ) ) {
$pageSet->requestField( 'page_content_model' );
}
+ if ( $config->get( 'PageLanguageUseDB' ) ) {
+ $pageSet->requestField( 'page_lang' );
+ }
}
/**
@@ -88,8 +90,9 @@ class ApiQueryInfo extends ApiQueryBase {
return $this->tokenFunctions;
}
- // If we're in JSON callback mode, no tokens can be obtained
- if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) {
+ // If we're in a mode that breaks the same-origin policy, no tokens can
+ // be obtained
+ if ( $this->lacksSameOriginSecurity() ) {
return array();
}
@@ -104,7 +107,7 @@ class ApiQueryInfo extends ApiQueryBase {
'import' => array( 'ApiQueryInfo', 'getImportToken' ),
'watch' => array( 'ApiQueryInfo', 'getWatchToken' ),
);
- wfRunHooks( 'APIQueryInfoTokens', array( &$this->tokenFunctions ) );
+ Hooks::run( 'APIQueryInfoTokens', array( &$this->tokenFunctions ) );
return $this->tokenFunctions;
}
@@ -328,9 +331,6 @@ class ApiQueryInfo extends ApiQueryBase {
: array();
$this->pageIsNew = $pageSet->getCustomField( 'page_is_new' );
- if ( !$this->getConfig()->get( 'DisableCounters' ) ) {
- $this->pageCounter = $pageSet->getCustomField( 'page_counter' );
- }
$this->pageTouched = $pageSet->getCustomField( 'page_touched' );
$this->pageLatest = $pageSet->getCustomField( 'page_latest' );
$this->pageLength = $pageSet->getCustomField( 'page_len' );
@@ -360,7 +360,7 @@ class ApiQueryInfo extends ApiQueryBase {
/** @var $title Title */
foreach ( $this->everything as $pageid => $title ) {
$pageInfo = $this->extractPageInfo( $pageid, $title );
- $fit = $result->addValue( array(
+ $fit = $pageInfo !== null && $result->addValue( array(
'query',
'pages'
), $pageid, $pageInfo );
@@ -377,7 +377,7 @@ class ApiQueryInfo extends ApiQueryBase {
* Get a result array with information about a title
* @param int $pageid Page ID (negative for missing titles)
* @param Title $title
- * @return array
+ * @return array|null
*/
private function extractPageInfo( $pageid, $title ) {
$pageInfo = array();
@@ -392,16 +392,13 @@ class ApiQueryInfo extends ApiQueryBase {
if ( $titleExists ) {
$pageInfo['touched'] = wfTimestamp( TS_ISO_8601, $this->pageTouched[$pageid] );
$pageInfo['lastrevid'] = intval( $this->pageLatest[$pageid] );
- $pageInfo['counter'] = $this->getConfig()->get( 'DisableCounters' )
- ? ''
- : intval( $this->pageCounter[$pageid] );
$pageInfo['length'] = intval( $this->pageLength[$pageid] );
if ( isset( $this->pageIsRedir[$pageid] ) && $this->pageIsRedir[$pageid] ) {
- $pageInfo['redirect'] = '';
+ $pageInfo['redirect'] = true;
}
if ( $this->pageIsNew[$pageid] ) {
- $pageInfo['new'] = '';
+ $pageInfo['new'] = true;
}
}
@@ -424,11 +421,18 @@ class ApiQueryInfo extends ApiQueryBase {
$pageInfo['protection'] =
$this->protections[$ns][$dbkey];
}
- $this->getResult()->setIndexedTagName( $pageInfo['protection'], 'pr' );
+ ApiResult::setIndexedTagName( $pageInfo['protection'], 'pr' );
+
+ $pageInfo['restrictiontypes'] = array();
+ if ( isset( $this->restrictionTypes[$ns][$dbkey] ) ) {
+ $pageInfo['restrictiontypes'] =
+ $this->restrictionTypes[$ns][$dbkey];
+ }
+ ApiResult::setIndexedTagName( $pageInfo['restrictiontypes'], 'rt' );
}
- if ( $this->fld_watched && isset( $this->watched[$ns][$dbkey] ) ) {
- $pageInfo['watched'] = '';
+ if ( $this->fld_watched ) {
+ $pageInfo['watched'] = isset( $this->watched[$ns][$dbkey] );
}
if ( $this->fld_watchers ) {
@@ -460,8 +464,8 @@ class ApiQueryInfo extends ApiQueryBase {
$pageInfo['editurl'] = wfExpandUrl( $title->getFullURL( 'action=edit' ), PROTO_CURRENT );
$pageInfo['canonicalurl'] = wfExpandUrl( $title->getFullURL(), PROTO_CANONICAL );
}
- if ( $this->fld_readable && $title->userCan( 'read', $this->getUser() ) ) {
- $pageInfo['readable'] = '';
+ if ( $this->fld_readable ) {
+ $pageInfo['readable'] = $title->userCan( 'read', $this->getUser() );
}
if ( $this->fld_preload ) {
@@ -469,7 +473,7 @@ class ApiQueryInfo extends ApiQueryBase {
$pageInfo['preload'] = '';
} else {
$text = null;
- wfRunHooks( 'EditFormPreloadText', array( &$text, &$title ) );
+ Hooks::run( 'EditFormPreloadText', array( &$text, &$title ) );
$pageInfo['preload'] = $text;
}
@@ -483,6 +487,20 @@ class ApiQueryInfo extends ApiQueryBase {
}
}
+ if ( $this->params['testactions'] ) {
+ $limit = $this->getMain()->canApiHighLimits() ? self::LIMIT_SML1 : self::LIMIT_SML2;
+ if ( $this->countTestedActions >= $limit ) {
+ return null; // force a continuation
+ }
+
+ $user = $this->getUser();
+ $pageInfo['actions'] = array();
+ foreach ( $this->params['testactions'] as $action ) {
+ $this->countTestedActions++;
+ $pageInfo['actions'][$action] = $title->userCan( $action, $user );
+ }
+ }
+
return $pageInfo;
}
@@ -512,7 +530,7 @@ class ApiQueryInfo extends ApiQueryBase {
'expiry' => $wgContLang->formatExpiry( $row->pr_expiry, TS_ISO_8601 )
);
if ( $row->pr_cascade ) {
- $a['cascade'] = '';
+ $a['cascade'] = true;
}
$this->protections[$title->getNamespace()][$title->getDBkey()][] = $a;
}
@@ -574,7 +592,8 @@ class ApiQueryInfo extends ApiQueryBase {
}
}
- // Cascading protections
+ // Separate good and missing titles into files and other pages
+ // and populate $this->restrictionTypes
$images = $others = array();
foreach ( $this->everything as $title ) {
if ( $title->getNamespace() == NS_FILE ) {
@@ -582,6 +601,9 @@ class ApiQueryInfo extends ApiQueryBase {
} else {
$others[] = $title;
}
+ // Applicable protection types
+ $this->restrictionTypes[$title->getNamespace()][$title->getDBkey()] =
+ array_values( $title->getRestrictionTypes() );
}
if ( count( $others ) ) {
@@ -817,45 +839,31 @@ class ApiQueryInfo extends ApiQueryBase {
'displaytitle',
// If you add more properties here, please consider whether they
// need to be added to getCacheMode()
- ) ),
+ ),
+ ApiBase::PARAM_HELP_MSG_PER_VALUE => array(),
+ ),
+ 'testactions' => array(
+ ApiBase::PARAM_TYPE => 'string',
+ ApiBase::PARAM_ISMULTI => true,
+ ),
'token' => array(
ApiBase::PARAM_DEPRECATED => true,
ApiBase::PARAM_DFLT => null,
ApiBase::PARAM_ISMULTI => true,
ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() )
),
- 'continue' => null,
- );
- }
-
- public function getParamDescription() {
- return array(
- 'prop' => array(
- 'Which additional properties to get:',
- ' protection - List the protection level of each page',
- ' talkid - The page ID of the talk page for each non-talk page',
- ' watched - List the watched status of each page',
- ' watchers - The number of watchers, if allowed',
- ' notificationtimestamp - The watchlist notification timestamp of each page',
- ' subjectid - The page ID of the parent page for each talk page',
- ' url - Gives a full URL, an edit URL, and the canonical URL for each page',
- ' readable - Whether the user can read this page',
- ' preload - Gives the text returned by EditFormPreloadText',
- ' displaytitle - Gives the way the page title is actually displayed',
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
),
- 'token' => 'Request a token to perform a data-modifying action on a page',
- 'continue' => 'When more results are available, use this to continue',
);
}
- public function getDescription() {
- return 'Get basic page information such as namespace, title, last touched date, ...';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&prop=info&titles=Main%20Page',
- 'api.php?action=query&prop=info&inprop=protection&titles=Main%20Page'
+ 'action=query&prop=info&titles=Main%20Page'
+ => 'apihelp-query+info-example-simple',
+ 'action=query&prop=info&inprop=protection&titles=Main%20Page'
+ => 'apihelp-query+info-example-protection',
);
}
diff --git a/includes/api/ApiQueryLangBacklinks.php b/includes/api/ApiQueryLangBacklinks.php
index 34842c63..7be18b2f 100644
--- a/includes/api/ApiQueryLangBacklinks.php
+++ b/includes/api/ApiQueryLangBacklinks.php
@@ -131,7 +131,7 @@ class ApiQueryLangBacklinks extends ApiQueryGeneratorBase {
ApiQueryBase::addTitleInfo( $entry, $title );
if ( $row->page_is_redirect ) {
- $entry['redirect'] = '';
+ $entry['redirect'] = true;
}
if ( $lllang ) {
@@ -154,7 +154,7 @@ class ApiQueryLangBacklinks extends ApiQueryGeneratorBase {
}
if ( is_null( $resultPageSet ) ) {
- $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'll' );
+ $result->addIndexedTagName( array( 'query', $this->getModuleName() ), 'll' );
} else {
$resultPageSet->populateFromTitles( $pages );
}
@@ -168,7 +168,9 @@ class ApiQueryLangBacklinks extends ApiQueryGeneratorBase {
return array(
'lang' => null,
'title' => null,
- 'continue' => null,
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ),
'limit' => array(
ApiBase::PARAM_DFLT => 10,
ApiBase::PARAM_TYPE => 'limit',
@@ -194,34 +196,12 @@ class ApiQueryLangBacklinks extends ApiQueryGeneratorBase {
);
}
- public function getParamDescription() {
- return array(
- 'lang' => 'Language for the language link',
- 'title' => "Language link to search for. Must be used with {$this->getModulePrefix()}lang",
- 'continue' => 'When more results are available, use this to continue',
- 'prop' => array(
- 'Which properties to get',
- ' lllang - Adds the language code of the language link',
- ' lltitle - Adds the title of the language link',
- ),
- 'limit' => 'How many total pages to return',
- 'dir' => 'The direction in which to list',
- );
- }
-
- public function getDescription() {
- return array( 'Find all pages that link to the given language link.',
- 'Can be used to find all links with a language code, or',
- 'all links to a title (with a given language).',
- 'Using neither parameter is effectively "All Language Links".',
- 'Note that this may not consider language links added by extensions.',
- );
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&list=langbacklinks&lbltitle=Test&lbllang=fr',
- 'api.php?action=query&generator=langbacklinks&glbltitle=Test&glbllang=fr&prop=info'
+ 'action=query&list=langbacklinks&lbltitle=Test&lbllang=fr'
+ => 'apihelp-query+langbacklinks-example-simple',
+ 'action=query&generator=langbacklinks&glbltitle=Test&glbllang=fr&prop=info'
+ => 'apihelp-query+langbacklinks-example-generator',
);
}
diff --git a/includes/api/ApiQueryLangLinks.php b/includes/api/ApiQueryLangLinks.php
index da05f273..5919ee97 100644
--- a/includes/api/ApiQueryLangLinks.php
+++ b/includes/api/ApiQueryLangLinks.php
@@ -124,7 +124,7 @@ class ApiQueryLangLinks extends ApiQueryBase {
if ( isset( $prop['autonym'] ) ) {
$entry['autonym'] = Language::fetchLanguageName( $row->ll_lang );
}
- ApiResult::setContent( $entry, $row->ll_title );
+ ApiResult::setContentValue( $entry, 'title', $row->ll_title );
$fit = $this->addPageSubItem( $row->ll_from, $entry );
if ( !$fit ) {
$this->setContinueEnumParameter( 'continue', "{$row->ll_from}|{$row->ll_lang}" );
@@ -140,18 +140,6 @@ class ApiQueryLangLinks extends ApiQueryBase {
public function getAllowedParams() {
global $wgContLang;
return array(
- '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
- ),
- 'continue' => null,
- 'url' => array(
- ApiBase::PARAM_DFLT => false,
- ApiBase::PARAM_DEPRECATED => true,
- ),
'prop' => array(
ApiBase::PARAM_ISMULTI => true,
ApiBase::PARAM_TYPE => array(
@@ -170,36 +158,27 @@ class ApiQueryLangLinks extends ApiQueryBase {
)
),
'inlanguagecode' => $wgContLang->getCode(),
- );
- }
-
- public function getParamDescription() {
- return array(
- 'limit' => 'How many langlinks to return',
- 'continue' => 'When more results are available, use this to continue',
- 'url' => "Whether to get the full URL (Cannot be used with {$this->getModulePrefix()}prop)",
- 'prop' => array(
- 'Which additional properties to get for each interlanguage link',
- ' url - Adds the full URL',
- ' langname - Adds the localised language name (best effort, use CLDR extension)',
- " Use {$this->getModulePrefix()}inlanguagecode to control the language",
- ' autonym - Adds the native language name',
+ '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
+ ),
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ),
+ 'url' => array(
+ ApiBase::PARAM_DFLT => false,
+ ApiBase::PARAM_DEPRECATED => true,
),
- 'lang' => 'Language code',
- 'title' => "Link to search for. Must be used with {$this->getModulePrefix()}lang",
- 'dir' => 'The direction in which to list',
- 'inlanguagecode' => 'Language code for localised language names',
);
}
- public function getDescription() {
- return 'Returns all interlanguage links from the given page(s).';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&prop=langlinks&titles=Main%20Page&redirects='
- => 'Get interlanguage links from the [[Main Page]]',
+ 'action=query&prop=langlinks&titles=Main%20Page&redirects='
+ => 'apihelp-query+langlinks-example-simple',
);
}
diff --git a/includes/api/ApiQueryLinks.php b/includes/api/ApiQueryLinks.php
index 71329c4d..3bd37144 100644
--- a/includes/api/ApiQueryLinks.php
+++ b/includes/api/ApiQueryLinks.php
@@ -34,26 +34,20 @@ class ApiQueryLinks extends ApiQueryGeneratorBase {
const LINKS = 'links';
const TEMPLATES = 'templates';
- private $table, $prefix, $description, $helpUrl;
+ private $table, $prefix, $helpUrl;
public function __construct( ApiQuery $query, $moduleName ) {
switch ( $moduleName ) {
case self::LINKS:
$this->table = 'pagelinks';
$this->prefix = 'pl';
- $this->description = 'link';
$this->titlesParam = 'titles';
- $this->titlesParamDescription = 'Only list links to these titles. Useful ' .
- 'for checking whether a certain page links to a certain title.';
$this->helpUrl = 'https://www.mediawiki.org/wiki/API:Properties#links_.2F_pl';
break;
case self::TEMPLATES:
$this->table = 'templatelinks';
$this->prefix = 'tl';
- $this->description = 'template';
$this->titlesParam = 'templates';
- $this->titlesParamDescription = 'Only list these templates. Useful ' .
- 'for checking whether a certain page uses a certain template.';
$this->helpUrl = 'https://www.mediawiki.org/wiki/API:Properties#templates_.2F_tl';
break;
default:
@@ -197,7 +191,9 @@ class ApiQueryLinks extends ApiQueryGeneratorBase {
ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
),
- 'continue' => null,
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ),
$this->titlesParam => array(
ApiBase::PARAM_ISMULTI => true,
),
@@ -211,32 +207,17 @@ 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",
- 'continue' => 'When more results are available, use this to continue',
- $this->titlesParam => $this->titlesParamDescription,
- 'dir' => 'The direction in which to list',
- );
- }
-
- public function getDescription() {
- return "Returns all {$this->description}s from the given page(s).";
- }
-
- public function getExamples() {
- $desc = $this->description;
+ protected function getExamplesMessages() {
$name = $this->getModuleName();
+ $path = $this->getModulePath();
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]]",
- "api.php?action=query&prop={$name}&titles=Main%20Page&{$this->prefix}namespace=2|10"
- => "Get {$desc}s from the Main Page in the User and Template namespaces",
+ "action=query&prop={$name}&titles=Main%20Page"
+ => "apihelp-{$path}-example-simple",
+ "action=query&generator={$name}&titles=Main%20Page&prop=info"
+ => "apihelp-{$path}-example-generator",
+ "action=query&prop={$name}&titles=Main%20Page&{$this->prefix}namespace=2|10"
+ => "apihelp-{$path}-example-namespaces",
);
}
diff --git a/includes/api/ApiQueryLogEvents.php b/includes/api/ApiQueryLogEvents.php
index d9dbb5e6..7b2381f4 100644
--- a/includes/api/ApiQueryLogEvents.php
+++ b/includes/api/ApiQueryLogEvents.php
@@ -230,19 +230,17 @@ class ApiQueryLogEvents extends ApiQueryBase {
}
$vals = $this->extractRowInfo( $row );
- if ( !$vals ) {
- continue;
- }
$fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
if ( !$fit ) {
$this->setContinueEnumParameter( 'continue', "$row->log_timestamp|$row->log_id" );
break;
}
}
- $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'item' );
+ $result->addIndexedTagName( array( 'query', $this->getModuleName() ), 'item' );
}
/**
+ * @deprecated since 1.25 Use LogFormatter::formatParametersForApi instead
* @param ApiResult $result
* @param array $vals
* @param string $params
@@ -255,100 +253,23 @@ class ApiQueryLogEvents extends ApiQueryBase {
public static function addLogParams( $result, &$vals, $params, $type,
$action, $ts, $legacy = false
) {
- switch ( $type ) {
- case 'move':
- if ( $legacy ) {
- $targetKey = 0;
- $noredirKey = 1;
- } else {
- $targetKey = '4::target';
- $noredirKey = '5::noredir';
- }
+ wfDeprecated( __METHOD__, '1.25' );
- if ( isset( $params[$targetKey] ) ) {
- $title = Title::newFromText( $params[$targetKey] );
- if ( $title ) {
- $vals2 = array();
- ApiQueryBase::addTitleInfo( $vals2, $title, 'new_' );
- $vals[$type] = $vals2;
- }
- }
- if ( isset( $params[$noredirKey] ) && $params[$noredirKey] ) {
- $vals[$type]['suppressedredirect'] = '';
- }
- $params = null;
- break;
- case 'patrol':
- if ( $legacy ) {
- $cur = 0;
- $prev = 1;
- $auto = 2;
- } else {
- $cur = '4::curid';
- $prev = '5::previd';
- $auto = '6::auto';
- }
- $vals2 = array();
- $vals2['cur'] = $params[$cur];
- $vals2['prev'] = $params[$prev];
- $vals2['auto'] = $params[$auto];
- $vals[$type] = $vals2;
- $params = null;
- break;
- case 'rights':
- $vals2 = array();
- if ( $legacy ) {
- list( $vals2['old'], $vals2['new'] ) = $params;
- } else {
- $vals2['new'] = implode( ', ', $params['5::newgroups'] );
- $vals2['old'] = implode( ', ', $params['4::oldgroups'] );
- }
- $vals[$type] = $vals2;
- $params = null;
- break;
- case 'block':
- if ( $action == 'unblock' ) {
- break;
- }
- $vals2 = array();
- list( $vals2['duration'], $vals2['flags'] ) = $params;
-
- // Indefinite blocks have no expiry time
- if ( SpecialBlock::parseExpiryInput( $params[0] ) !== wfGetDB( DB_SLAVE )->getInfinity() ) {
- $vals2['expiry'] = wfTimestamp( TS_ISO_8601,
- strtotime( $params[0], wfTimestamp( TS_UNIX, $ts ) ) );
- }
- $vals[$type] = $vals2;
- $params = null;
- break;
- case 'upload':
- if ( isset( $params['img_timestamp'] ) ) {
- $params['img_timestamp'] = wfTimestamp( TS_ISO_8601, $params['img_timestamp'] );
- }
- break;
- }
- if ( !is_null( $params ) ) {
- $logParams = array();
- // Keys like "4::paramname" can't be used for output so we change them to "paramname"
- foreach ( $params as $key => $value ) {
- if ( strpos( $key, ':' ) === false ) {
- $logParams[$key] = $value;
- continue;
- }
- $logParam = explode( ':', $key, 3 );
- $logParams[$logParam[2]] = $value;
- }
- $result->setIndexedTagName( $logParams, 'param' );
- $result->setIndexedTagName_recursive( $logParams, 'param' );
- $vals = array_merge( $vals, $logParams );
- }
+ $entry = new ManualLogEntry( $type, $action );
+ $entry->setParameters( $params );
+ $entry->setTimestamp( $ts );
+ $entry->setLegacy( $legacy );
+ $formatter = LogFormatter::newFromEntry( $entry );
+ $vals['params'] = $formatter->formatParametersForApi();
return $vals;
}
private function extractRowInfo( $row ) {
$logEntry = DatabaseLogEntry::newFromRow( $row );
- $vals = array();
+ $vals = array(
+ ApiResult::META_TYPE => 'assoc',
+ );
$anyHidden = false;
$user = $this->getUser();
@@ -362,7 +283,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
if ( $this->fld_title || $this->fld_ids || $this->fld_details && $row->log_params !== '' ) {
if ( LogEventsList::isDeleted( $row, LogPage::DELETED_ACTION ) ) {
- $vals['actionhidden'] = '';
+ $vals['actionhidden'] = true;
$anyHidden = true;
}
if ( LogEventsList::userCan( $row, LogPage::DELETED_ACTION, $user ) ) {
@@ -373,16 +294,8 @@ class ApiQueryLogEvents extends ApiQueryBase {
$vals['pageid'] = intval( $row->page_id );
$vals['logpage'] = intval( $row->log_page );
}
- if ( $this->fld_details && $row->log_params !== '' ) {
- self::addLogParams(
- $this->getResult(),
- $vals,
- $logEntry->getParameters(),
- $logEntry->getType(),
- $logEntry->getSubtype(),
- $logEntry->getTimestamp(),
- $logEntry->isLegacy()
- );
+ if ( $this->fld_details ) {
+ $vals['params'] = LogFormatter::newFromEntry( $logEntry )->formatParametersForApi();
}
}
}
@@ -394,7 +307,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
if ( $this->fld_user || $this->fld_userid ) {
if ( LogEventsList::isDeleted( $row, LogPage::DELETED_USER ) ) {
- $vals['userhidden'] = '';
+ $vals['userhidden'] = true;
$anyHidden = true;
}
if ( LogEventsList::userCan( $row, LogPage::DELETED_USER, $user ) ) {
@@ -406,7 +319,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
}
if ( !$row->log_user ) {
- $vals['anon'] = '';
+ $vals['anon'] = true;
}
}
}
@@ -416,7 +329,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
if ( ( $this->fld_comment || $this->fld_parsedcomment ) && isset( $row->log_comment ) ) {
if ( LogEventsList::isDeleted( $row, LogPage::DELETED_COMMENT ) ) {
- $vals['commenthidden'] = '';
+ $vals['commenthidden'] = true;
$anyHidden = true;
}
if ( LogEventsList::userCan( $row, LogPage::DELETED_COMMENT, $user ) ) {
@@ -433,7 +346,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
if ( $this->fld_tags ) {
if ( $row->ts_tags ) {
$tags = explode( ',', $row->ts_tags );
- $this->getResult()->setIndexedTagName( $tags, 'tag' );
+ ApiResult::setIndexedTagName( $tags, 'tag' );
$vals['tags'] = $tags;
} else {
$vals['tags'] = array();
@@ -441,7 +354,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
}
if ( $anyHidden && LogEventsList::isDeleted( $row, LogPage::DELETED_RESTRICTED ) ) {
- $vals['suppressed'] = '';
+ $vals['suppressed'] = true;
}
return $vals;
@@ -473,7 +386,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
public function getAllowedParams( $flags = 0 ) {
$config = $this->getConfig();
- return array(
+ $ret = array(
'prop' => array(
ApiBase::PARAM_ISMULTI => true,
ApiBase::PARAM_DFLT => 'ids|title|type|user|timestamp|comment|details',
@@ -510,14 +423,15 @@ class ApiQueryLogEvents extends ApiQueryBase {
ApiBase::PARAM_TYPE => array(
'newer',
'older'
- )
+ ),
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
),
'user' => null,
'title' => null,
'namespace' => array(
ApiBase::PARAM_TYPE => 'namespace'
),
- 'prefix' => null,
+ 'prefix' => array(),
'tag' => null,
'limit' => array(
ApiBase::PARAM_DFLT => 10,
@@ -526,52 +440,22 @@ class ApiQueryLogEvents extends ApiQueryBase {
ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
),
- 'continue' => null,
- );
- }
-
- public function getParamDescription() {
- $p = $this->getModulePrefix();
-
- return array(
- 'prop' => array(
- 'Which properties to get',
- ' ids - Adds the ID of the log event',
- ' title - Adds the title of the page for the log event',
- ' type - Adds the type of log event',
- ' user - Adds the user responsible for the log event',
- ' userid - Adds the user ID who was responsible for the log event',
- ' timestamp - Adds the timestamp for the event',
- ' comment - Adds the comment of the event',
- ' parsedcomment - Adds the parsed comment of the event',
- ' details - Lists additional details about the event',
- ' tags - Lists tags for the event',
- ),
- 'type' => 'Filter log entries to only this type',
- 'action' => array(
- "Filter log actions to only this action. Overrides {$p}type",
- "Wildcard actions like 'action/*' allows to specify any string for the asterisk"
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
),
- 'start' => 'The timestamp to start enumerating from',
- 'end' => 'The timestamp to end enumerating',
- 'dir' => $this->getDirectionDescription( $p ),
- 'user' => 'Filter entries to those made by the given user',
- 'title' => 'Filter entries to those related to a page',
- 'namespace' => 'Filter entries to those in the given namespace',
- 'prefix' => 'Filter entries that start with this prefix. Disabled in Miser Mode',
- 'limit' => 'How many total event entries to return',
- 'tag' => 'Only list event entries tagged with this tag',
- 'continue' => 'When more results are available, use this to continue',
);
- }
- public function getDescription() {
- return 'Get events from logs.';
+ if ( $config->get( 'MiserMode' ) ) {
+ $ret['prefix'][ApiBase::PARAM_HELP_MSG] = 'api-help-param-disabled-in-miser-mode';
+ }
+
+ return $ret;
}
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&list=logevents'
+ 'action=query&list=logevents'
+ => 'apihelp-query+logevents-example-simple',
);
}
diff --git a/includes/api/ApiQueryORM.php b/includes/api/ApiQueryORM.php
index 469b2972..dc10c91c 100644
--- a/includes/api/ApiQueryORM.php
+++ b/includes/api/ApiQueryORM.php
@@ -205,7 +205,7 @@ abstract class ApiQueryORM extends ApiQueryBase {
* @param array $serializedResults
*/
protected function setIndexedTagNames( array &$serializedResults ) {
- $this->getResult()->setIndexedTagName( $serializedResults, $this->getRowName() );
+ ApiResult::setIndexedTagName( $serializedResults, $this->getRowName() );
}
/**
@@ -233,15 +233,19 @@ abstract class ApiQueryORM extends ApiQueryBase {
ApiBase::PARAM_TYPE => $this->getTable()->getFieldNames(),
ApiBase::PARAM_ISMULTI => true,
ApiBase::PARAM_REQUIRED => true,
+ ApiBase::PARAM_HELP_MSG => 'api-orm-param-props',
),
'limit' => array(
ApiBase::PARAM_DFLT => 20,
ApiBase::PARAM_TYPE => 'limit',
ApiBase::PARAM_MIN => 1,
ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
- ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
+ ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2,
+ ApiBase::PARAM_HELP_MSG => 'api-orm-param-limit',
+ ),
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
),
- 'continue' => null,
);
return array_merge( $this->getTable()->getAPIParams(), $params );
@@ -249,6 +253,7 @@ abstract class ApiQueryORM extends ApiQueryBase {
/**
* @see ApiBase::getParamDescription()
+ * @deprecated since 1.25
* @return array
*/
public function getParamDescription() {
diff --git a/includes/api/ApiQueryPagePropNames.php b/includes/api/ApiQueryPagePropNames.php
index 8cd9c6cf..11a29ff9 100644
--- a/includes/api/ApiQueryPagePropNames.php
+++ b/includes/api/ApiQueryPagePropNames.php
@@ -78,12 +78,14 @@ class ApiQueryPagePropNames extends ApiQueryBase {
}
}
- $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'p' );
+ $result->addIndexedTagName( array( 'query', $this->getModuleName() ), 'p' );
}
public function getAllowedParams() {
return array(
- 'continue' => null,
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ),
'limit' => array(
ApiBase::PARAM_TYPE => 'limit',
ApiBase::PARAM_DFLT => 10,
@@ -94,20 +96,10 @@ class ApiQueryPagePropNames extends ApiQueryBase {
);
}
- public function getParamDescription() {
- return array(
- 'continue' => 'When more results are available, use this to continue',
- 'limit' => 'The maximum number of pages to return',
- );
- }
-
- public function getDescription() {
- return 'List all page prop names in use on the wiki.';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&list=pagepropnames' => 'Get first 10 prop names',
+ 'action=query&list=pagepropnames'
+ => 'apihelp-query+pagepropnames-example-simple',
);
}
diff --git a/includes/api/ApiQueryPageProps.php b/includes/api/ApiQueryPageProps.php
index e370c39f..dd19bf23 100644
--- a/includes/api/ApiQueryPageProps.php
+++ b/includes/api/ApiQueryPageProps.php
@@ -110,6 +110,7 @@ class ApiQueryPageProps extends ApiQueryBase {
* @return bool True if it fits in the result
*/
private function addPageProps( $result, $page, $props ) {
+ ApiResult::setArrayType( $props, 'assoc' );
$fit = $result->addValue( array( 'query', 'pages', $page ), 'pageprops', $props );
if ( !$fit ) {
@@ -125,28 +126,19 @@ class ApiQueryPageProps extends ApiQueryBase {
public function getAllowedParams() {
return array(
- 'continue' => null,
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ),
'prop' => array(
ApiBase::PARAM_ISMULTI => true,
),
);
}
- public function getParamDescription() {
- return array(
- 'continue' => 'When more results are available, use this to continue',
- 'prop' => 'Only list these props. Useful for checking whether a ' .
- 'certain page uses a certain page prop',
- );
- }
-
- public function getDescription() {
- return 'Get various properties defined in the page content.';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&prop=pageprops&titles=Category:Foo',
+ 'action=query&prop=pageprops&titles=Category:Foo'
+ => 'apihelp-query+pageprops-example-simple',
);
}
diff --git a/includes/api/ApiQueryPagesWithProp.php b/includes/api/ApiQueryPagesWithProp.php
index b6c85253..7bcaf247 100644
--- a/includes/api/ApiQueryPagesWithProp.php
+++ b/includes/api/ApiQueryPagesWithProp.php
@@ -99,7 +99,9 @@ class ApiQueryPagesWithProp extends ApiQueryGeneratorBase {
}
if ( $resultPageSet === null ) {
- $vals = array();
+ $vals = array(
+ ApiResult::META_TYPE => 'assoc',
+ );
if ( $fld_ids ) {
$vals['pageid'] = (int)$row->page_id;
}
@@ -121,7 +123,7 @@ class ApiQueryPagesWithProp extends ApiQueryGeneratorBase {
}
if ( $resultPageSet === null ) {
- $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'page' );
+ $result->addIndexedTagName( array( 'query', $this->getModuleName() ), 'page' );
}
}
@@ -140,7 +142,9 @@ class ApiQueryPagesWithProp extends ApiQueryGeneratorBase {
'value',
)
),
- 'continue' => null,
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ),
'limit' => array(
ApiBase::PARAM_TYPE => 'limit',
ApiBase::PARAM_DFLT => 10,
@@ -158,31 +162,12 @@ class ApiQueryPagesWithProp extends ApiQueryGeneratorBase {
);
}
- public function getParamDescription() {
- return array(
- 'propname' => 'Page prop for which to enumerate pages',
- 'prop' => array(
- 'What pieces of information to include',
- ' ids - Adds the page ID',
- ' title - Adds the title and namespace ID of the page',
- ' value - Adds the value of the page prop',
- ),
- 'dir' => 'In which direction to sort',
- 'continue' => 'When more results are available, use this to continue',
- 'limit' => 'The maximum number of pages to return',
- );
- }
-
- public function getDescription() {
- return 'List all pages using a given page prop.';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&list=pageswithprop&pwppropname=displaytitle&pwpprop=ids|title|value'
- => 'Get first 10 pages using {{DISPLAYTITLE:}}',
- 'api.php?action=query&generator=pageswithprop&gpwppropname=notoc&prop=info'
- => 'Get page info about first 10 pages using __NOTOC__',
+ 'action=query&list=pageswithprop&pwppropname=displaytitle&pwpprop=ids|title|value'
+ => 'apihelp-query+pageswithprop-example-simple',
+ 'action=query&generator=pageswithprop&gpwppropname=notoc&prop=info'
+ => 'apihelp-query+pageswithprop-example-generator',
);
}
diff --git a/includes/api/ApiQueryPrefixSearch.php b/includes/api/ApiQueryPrefixSearch.php
index 4abd7f0e..8eb644fc 100644
--- a/includes/api/ApiQueryPrefixSearch.php
+++ b/includes/api/ApiQueryPrefixSearch.php
@@ -43,15 +43,25 @@ class ApiQueryPrefixSearch extends ApiQueryGeneratorBase {
$search = $params['search'];
$limit = $params['limit'];
$namespaces = $params['namespace'];
+ $offset = $params['offset'];
$searcher = new TitlePrefixSearch;
- $titles = $searcher->searchWithVariants( $search, $limit, $namespaces );
+ $titles = $searcher->searchWithVariants( $search, $limit + 1, $namespaces, $offset );
if ( $resultPageSet ) {
+ if ( count( $titles ) > $limit ) {
+ $this->setContinueEnumParameter( 'offset', $offset + $params['limit'] );
+ array_pop( $titles );
+ }
$resultPageSet->populateFromTitles( $titles );
+ foreach ( $titles as $index => $title ) {
+ $resultPageSet->setGeneratorData( $title, array( 'index' => $index + $offset + 1 ) );
+ }
} else {
$result = $this->getResult();
+ $count = 0;
foreach ( $titles as $title ) {
- if ( !$limit-- ) {
+ if ( ++$count > $limit ) {
+ $this->setContinueEnumParameter( 'offset', $offset + $params['limit'] );
break;
}
$vals = array(
@@ -59,16 +69,17 @@ class ApiQueryPrefixSearch extends ApiQueryGeneratorBase {
'title' => $title->getPrefixedText(),
);
if ( $title->isSpecialPage() ) {
- $vals['special'] = '';
+ $vals['special'] = true;
} else {
$vals['pageid'] = intval( $title->getArticleId() );
}
$fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
if ( !$fit ) {
+ $this->setContinueEnumParameter( 'offset', $offset + $count - 1 );
break;
}
}
- $result->setIndexedTagName_internal(
+ $result->addIndexedTagName(
array( 'query', $this->getModuleName() ), $this->getModulePrefix()
);
}
@@ -97,24 +108,17 @@ class ApiQueryPrefixSearch extends ApiQueryGeneratorBase {
ApiBase::PARAM_MAX => 100,
ApiBase::PARAM_MAX2 => 200,
),
+ 'offset' => array(
+ ApiBase::PARAM_DFLT => 0,
+ ApiBase::PARAM_TYPE => 'integer',
+ ),
);
}
- public function getParamDescription() {
- return array(
- 'search' => 'Search string',
- 'limit' => 'Maximum amount of results to return',
- 'namespace' => 'Namespaces to search',
- );
- }
-
- public function getDescription() {
- return 'Perform a prefix search for page titles';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&list=prefixsearch&pssearch=meaning',
+ 'action=query&list=prefixsearch&pssearch=meaning'
+ => 'apihelp-query+prefixsearch-example-simple',
);
}
diff --git a/includes/api/ApiQueryProtectedTitles.php b/includes/api/ApiQueryProtectedTitles.php
index 4c88be7a..fb65e5e2 100644
--- a/includes/api/ApiQueryProtectedTitles.php
+++ b/includes/api/ApiQueryProtectedTitles.php
@@ -156,7 +156,7 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
}
if ( is_null( $resultPageSet ) ) {
- $result->setIndexedTagName_internal(
+ $result->addIndexedTagName(
array( 'query', $this->getModuleName() ),
$this->getModulePrefix()
);
@@ -196,7 +196,8 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
ApiBase::PARAM_TYPE => array(
'newer',
'older'
- )
+ ),
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
),
'start' => array(
ApiBase::PARAM_TYPE => 'timestamp'
@@ -217,39 +218,18 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
'level'
)
),
- 'continue' => null,
- );
- }
-
- public function getParamDescription() {
- return array(
- 'namespace' => 'Only list titles in these namespaces',
- 'start' => 'Start listing at this protection timestamp',
- 'end' => 'Stop listing at this protection timestamp',
- 'dir' => $this->getDirectionDescription( $this->getModulePrefix() ),
- 'limit' => 'How many total pages to return',
- 'prop' => array(
- 'Which properties to get',
- ' timestamp - Adds the timestamp of when protection was added',
- ' user - Adds the user that added the protection',
- ' userid - Adds the user id that added the protection',
- ' comment - Adds the comment for the protection',
- ' parsedcomment - Adds the parsed comment for the protection',
- ' expiry - Adds the timestamp of when the protection will be lifted',
- ' level - Adds the protection level',
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
),
- 'level' => 'Only list titles with these protection levels',
- 'continue' => 'When more results are available, use this to continue',
);
}
- public function getDescription() {
- return 'List all titles protected from creation.';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&list=protectedtitles',
+ 'action=query&list=protectedtitles'
+ => 'apihelp-query+protectedtitles-example-simple',
+ 'action=query&generator=protectedtitles&gptnamespace=0&prop=linkshere'
+ => 'apihelp-query+protectedtitles-example-generator',
);
}
diff --git a/includes/api/ApiQueryQueryPage.php b/includes/api/ApiQueryQueryPage.php
index 5ddd9450..650ac8fe 100644
--- a/includes/api/ApiQueryQueryPage.php
+++ b/includes/api/ApiQueryQueryPage.php
@@ -68,9 +68,9 @@ class ApiQueryQueryPage extends ApiQueryGeneratorBase {
$r = array( 'name' => $params['page'] );
if ( $qp->isCached() ) {
if ( !$qp->isCacheable() ) {
- $r['disabled'] = '';
+ $r['disabled'] = true;
} else {
- $r['cached'] = '';
+ $r['cached'] = true;
$ts = $qp->getCachedTimestamp();
if ( $ts ) {
$r['cachedtimestamp'] = wfTimestamp( TS_ISO_8601, $ts );
@@ -119,7 +119,7 @@ class ApiQueryQueryPage extends ApiQueryGeneratorBase {
}
}
if ( is_null( $resultPageSet ) ) {
- $result->setIndexedTagName_internal(
+ $result->addIndexedTagName(
array( 'query', $this->getModuleName(), 'results' ),
'page'
);
@@ -144,7 +144,10 @@ class ApiQueryQueryPage extends ApiQueryGeneratorBase {
ApiBase::PARAM_TYPE => array_keys( $this->qpMap ),
ApiBase::PARAM_REQUIRED => true
),
- 'offset' => 0,
+ 'offset' => array(
+ ApiBase::PARAM_DFLT => 0,
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+ ),
'limit' => array(
ApiBase::PARAM_DFLT => 10,
ApiBase::PARAM_TYPE => 'limit',
@@ -155,21 +158,10 @@ class ApiQueryQueryPage extends ApiQueryGeneratorBase {
);
}
- public function getParamDescription() {
- return array(
- 'page' => 'The name of the special page. Note, this is case sensitive',
- 'offset' => 'When more results are available, use this to continue',
- 'limit' => 'Number of results to return',
- );
- }
-
- public function getDescription() {
- return 'Get a list provided by a QueryPage-based special page.';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&list=querypage&qppage=Ancientpages'
+ 'action=query&list=querypage&qppage=Ancientpages'
+ => 'apihelp-query+querypage-example-ancientpages',
);
}
diff --git a/includes/api/ApiQueryRandom.php b/includes/api/ApiQueryRandom.php
index 530557e6..a2c28443 100644
--- a/includes/api/ApiQueryRandom.php
+++ b/includes/api/ApiQueryRandom.php
@@ -131,7 +131,7 @@ class ApiQueryRandom extends ApiQueryGeneratorBase {
}
if ( is_null( $resultPageSet ) ) {
- $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'page' );
+ $result->addIndexedTagName( array( 'query', $this->getModuleName() ), 'page' );
}
}
@@ -165,30 +165,15 @@ class ApiQueryRandom extends ApiQueryGeneratorBase {
);
}
- public function getParamDescription() {
+ protected function getExamplesMessages() {
return array(
- 'namespace' => 'Return pages in these namespaces only',
- 'limit' => 'Limit how many random pages will be returned',
- 'redirect' => 'Load a random redirect instead of a random page'
+ 'action=query&list=random&rnnamespace=0&rnlimit=2'
+ => 'apihelp-query+random-example-simple',
+ 'action=query&generator=random&grnnamespace=0&grnlimit=2&prop=info'
+ => 'apihelp-query+random-example-generator',
);
}
- public function getDescription() {
- return array(
- 'Get a set of random pages.',
- 'NOTE: Pages are listed in a fixed sequence, only the starting point is random.',
- ' This means that if, for example, "Main Page" is the first random page on',
- ' your list, "List of fictional monkeys" will *always* be second, "List of',
- ' people on stamps of Vanuatu" third, etc.',
- 'NOTE: If the number of pages in the namespace is lower than rnlimit, you will',
- ' get fewer pages. You will not get the same page twice.'
- );
- }
-
- public function getExamples() {
- return 'api.php?action=query&list=random&rnnamespace=0&rnlimit=2';
- }
-
public function getHelpUrls() {
return 'https://www.mediawiki.org/wiki/API:Random';
}
diff --git a/includes/api/ApiQueryRecentChanges.php b/includes/api/ApiQueryRecentChanges.php
index 6f0c5d34..f6a64785 100644
--- a/includes/api/ApiQueryRecentChanges.php
+++ b/includes/api/ApiQueryRecentChanges.php
@@ -56,15 +56,16 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
return $this->tokenFunctions;
}
- // If we're in JSON callback mode, no tokens can be obtained
- if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) {
+ // If we're in a mode that breaks the same-origin policy, no tokens can
+ // be obtained
+ if ( $this->lacksSameOriginSecurity() ) {
return array();
}
$this->tokenFunctions = array(
'patrol' => array( 'ApiQueryRecentChanges', 'getPatrolToken' )
);
- wfRunHooks( 'APIQueryRecentChangesTokens', array( &$this->tokenFunctions ) );
+ Hooks::run( 'APIQueryRecentChangesTokens', array( &$this->tokenFunctions ) );
return $this->tokenFunctions;
}
@@ -178,7 +179,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
if ( !is_null( $params['type'] ) ) {
try {
$this->addWhereFld( 'rc_type', RecentChange::parseToRCType( $params['type'] ) );
- } catch ( MWException $e ) {
+ } catch ( Exception $e ) {
ApiBase::dieDebug( __METHOD__, $e->getMessage() );
}
}
@@ -383,9 +384,6 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
$vals = $this->extractRowInfo( $row );
/* Add that row's data to our final output. */
- if ( !$vals ) {
- continue;
- }
$fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
if ( !$fit ) {
$this->setContinueEnumParameter( 'continue', "$row->rc_timestamp|$row->rc_id" );
@@ -398,7 +396,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
if ( is_null( $resultPageSet ) ) {
/* Format the result */
- $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'rc' );
+ $result->addIndexedTagName( array( 'query', $this->getModuleName() ), 'rc' );
} else {
$resultPageSet->populateFromTitles( $titles );
}
@@ -427,7 +425,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
/* Create a new entry in the result for the title. */
if ( $this->fld_title || $this->fld_ids ) {
if ( $type === RC_LOG && ( $row->rc_deleted & LogPage::DELETED_ACTION ) ) {
- $vals['actionhidden'] = '';
+ $vals['actionhidden'] = true;
$anyHidden = true;
}
if ( $type !== RC_LOG ||
@@ -451,7 +449,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
/* Add user data and 'anon' flag, if user is anonymous. */
if ( $this->fld_user || $this->fld_userid ) {
if ( $row->rc_deleted & Revision::DELETED_USER ) {
- $vals['userhidden'] = '';
+ $vals['userhidden'] = true;
$anyHidden = true;
}
if ( Revision::userCanBitfield( $row->rc_deleted, Revision::DELETED_USER, $user ) ) {
@@ -464,22 +462,16 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
}
if ( !$row->rc_user ) {
- $vals['anon'] = '';
+ $vals['anon'] = true;
}
}
}
/* Add flags, such as new, minor, bot. */
if ( $this->fld_flags ) {
- if ( $row->rc_bot ) {
- $vals['bot'] = '';
- }
- if ( $row->rc_type == RC_NEW ) {
- $vals['new'] = '';
- }
- if ( $row->rc_minor ) {
- $vals['minor'] = '';
- }
+ $vals['bot'] = (bool)$row->rc_bot;
+ $vals['new'] = $row->rc_type == RC_NEW;
+ $vals['minor'] = (bool)$row->rc_minor;
}
/* Add sizes of each revision. (Only available on 1.10+) */
@@ -496,7 +488,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
/* Add edit summary / log summary. */
if ( $this->fld_comment || $this->fld_parsedcomment ) {
if ( $row->rc_deleted & Revision::DELETED_COMMENT ) {
- $vals['commenthidden'] = '';
+ $vals['commenthidden'] = true;
$anyHidden = true;
}
if ( Revision::userCanBitfield( $row->rc_deleted, Revision::DELETED_COMMENT, $user ) ) {
@@ -511,45 +503,32 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
}
if ( $this->fld_redirect ) {
- if ( $row->page_is_redirect ) {
- $vals['redirect'] = '';
- }
+ $vals['redirect'] = (bool)$row->page_is_redirect;
}
/* Add the patrolled flag */
- if ( $this->fld_patrolled && $row->rc_patrolled == 1 ) {
- $vals['patrolled'] = '';
- }
-
- if ( $this->fld_patrolled && ChangesList::isUnpatrolled( $row, $user ) ) {
- $vals['unpatrolled'] = '';
+ if ( $this->fld_patrolled ) {
+ $vals['patrolled'] = $row->rc_patrolled == 1;
+ $vals['unpatrolled'] = ChangesList::isUnpatrolled( $row, $user );
}
if ( $this->fld_loginfo && $row->rc_type == RC_LOG ) {
if ( $row->rc_deleted & LogPage::DELETED_ACTION ) {
- $vals['actionhidden'] = '';
+ $vals['actionhidden'] = true;
$anyHidden = true;
}
if ( LogEventsList::userCanBitfield( $row->rc_deleted, LogPage::DELETED_ACTION, $user ) ) {
$vals['logid'] = intval( $row->rc_logid );
$vals['logtype'] = $row->rc_log_type;
$vals['logaction'] = $row->rc_log_action;
- $logEntry = DatabaseLogEntry::newFromRow( (array)$row );
- ApiQueryLogEvents::addLogParams(
- $this->getResult(),
- $vals,
- $logEntry->getParameters(),
- $logEntry->getType(),
- $logEntry->getSubtype(),
- $logEntry->getTimestamp()
- );
+ $vals['logparams'] = LogFormatter::newFromRow( $row )->formatParametersForApi();
}
}
if ( $this->fld_tags ) {
if ( $row->ts_tags ) {
$tags = explode( ',', $row->ts_tags );
- $this->getResult()->setIndexedTagName( $tags, 'tag' );
+ ApiResult::setIndexedTagName( $tags, 'tag' );
$vals['tags'] = $tags;
} else {
$vals['tags'] = array();
@@ -558,7 +537,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
if ( $this->fld_sha1 && $row->rev_sha1 !== null ) {
if ( $row->rev_deleted & Revision::DELETED_TEXT ) {
- $vals['sha1hidden'] = '';
+ $vals['sha1hidden'] = true;
$anyHidden = true;
}
if ( Revision::userCanBitfield( $row->rev_deleted, Revision::DELETED_TEXT, $user ) ) {
@@ -584,7 +563,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
}
if ( $anyHidden && ( $row->rc_deleted & Revision::DELETED_RESTRICTED ) ) {
- $vals['suppressed'] = '';
+ $vals['suppressed'] = true;
}
return $vals;
@@ -625,7 +604,8 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
ApiBase::PARAM_TYPE => array(
'newer',
'older'
- )
+ ),
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
),
'namespace' => array(
ApiBase::PARAM_ISMULTI => true,
@@ -687,6 +667,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
),
'type' => array(
+ ApiBase::PARAM_DFLT => 'edit|new|log',
ApiBase::PARAM_ISMULTI => true,
ApiBase::PARAM_TYPE => array(
'edit',
@@ -696,57 +677,18 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
)
),
'toponly' => false,
- 'continue' => null,
- );
- }
-
- public function getParamDescription() {
- $p = $this->getModulePrefix();
-
- return array(
- 'start' => 'The timestamp to start enumerating from',
- 'end' => 'The timestamp to end enumerating',
- 'dir' => $this->getDirectionDescription( $p ),
- 'namespace' => 'Filter log entries to only this namespace(s)',
- 'user' => 'Only list changes by this user',
- 'excludeuser' => 'Don\'t list changes by this user',
- 'prop' => array(
- 'Include additional pieces of information',
- ' user - Adds the user responsible for the edit and tags if they are an IP',
- ' userid - Adds the user id responsible for the edit',
- ' comment - Adds the comment for the edit',
- ' parsedcomment - Adds the parsed comment for the edit',
- ' flags - Adds flags for the edit',
- ' timestamp - Adds timestamp of the edit',
- ' title - Adds the page title of the edit',
- ' ids - Adds the page ID, recent changes ID and the new and old revision ID',
- ' sizes - Adds the new and old page length in bytes',
- ' redirect - Tags edit if page is a redirect',
- ' patrolled - Tags patrollable edits as being patrolled or unpatrolled',
- ' loginfo - Adds log information (logid, logtype, etc) to log entries',
- ' tags - Lists tags for the entry',
- ' sha1 - Adds the content checksum for entries associated with a revision',
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
),
- 'token' => 'Which tokens to obtain for each change',
- 'show' => array(
- 'Show only items that meet this criteria.',
- "For example, to see only minor edits done by logged-in users, set {$p}show=minor|!anon"
- ),
- 'type' => 'Which types of changes to show',
- 'limit' => 'How many total changes to return',
- 'tag' => 'Only list changes tagged with this tag',
- 'toponly' => 'Only list changes which are the latest revision',
- 'continue' => 'When more results are available, use this to continue',
);
}
- public function getDescription() {
- return 'Enumerate recent changes.';
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=query&list=recentchanges'
+ 'action=query&list=recentchanges'
+ => 'apihelp-query+recentchanges-example-simple',
+ 'action=query&generator=recentchanges&grcshow=!patrolled&prop=info'
+ => 'apihelp-query+recentchanges-example-generator',
);
}
diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php
index da4ec195..552ca3b4 100644
--- a/includes/api/ApiQueryRevisions.php
+++ b/includes/api/ApiQueryRevisions.php
@@ -32,20 +32,14 @@
*
* @ingroup API
*/
-class ApiQueryRevisions extends ApiQueryBase {
+class ApiQueryRevisions extends ApiQueryRevisionsBase {
- private $diffto, $difftotext, $expandTemplates, $generateXML, $section,
- $token, $parseContent, $contentFormat;
+ private $token = null;
public function __construct( ApiQuery $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'rv' );
}
- private $fld_ids = false, $fld_flags = false, $fld_timestamp = false,
- $fld_size = false, $fld_sha1 = false, $fld_comment = false,
- $fld_parsedcomment = false, $fld_user = false, $fld_userid = false,
- $fld_content = false, $fld_tags = false, $fld_contentmodel = false;
-
private $tokenFunctions;
/** @deprecated since 1.24 */
@@ -59,15 +53,16 @@ class ApiQueryRevisions extends ApiQueryBase {
return $this->tokenFunctions;
}
- // If we're in JSON callback mode, no tokens can be obtained
- if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) {
+ // If we're in a mode that breaks the same-origin policy, no tokens can
+ // be obtained
+ if ( $this->lacksSameOriginSecurity() ) {
return array();
}
$this->tokenFunctions = array(
'rollback' => array( 'ApiQueryRevisions', 'getRollbackToken' )
);
- wfRunHooks( 'APIQueryRevisionsTokens', array( &$this->tokenFunctions ) );
+ Hooks::run( 'APIQueryRevisionsTokens', array( &$this->tokenFunctions ) );
return $this->tokenFunctions;
}
@@ -89,7 +84,7 @@ class ApiQueryRevisions extends ApiQueryBase {
array( $title->getPrefixedText(), $rev->getUserText() ) );
}
- public function execute() {
+ protected function run( ApiPageSet $resultPageSet = null ) {
$params = $this->extractRequestParams( false );
// If any of those parameters are used, work in 'enumeration' mode.
@@ -107,6 +102,11 @@ class ApiQueryRevisions extends ApiQueryBase {
// Optimization -- nothing to do
if ( $revCount === 0 && $pageCount === 0 ) {
+ // Nothing to do
+ return;
+ }
+ if ( $revCount > 0 && count( $pageSet->getLiveRevisionIDs() ) === 0 ) {
+ // We're in revisions mode but all given revisions are deleted
return;
}
@@ -127,75 +127,32 @@ class ApiQueryRevisions extends ApiQueryBase {
);
}
- if ( !is_null( $params['difftotext'] ) ) {
- $this->difftotext = $params['difftotext'];
- } elseif ( !is_null( $params['diffto'] ) ) {
- if ( $params['diffto'] == 'cur' ) {
- $params['diffto'] = 0;
- }
- if ( ( !ctype_digit( $params['diffto'] ) || $params['diffto'] < 0 )
- && $params['diffto'] != 'prev' && $params['diffto'] != 'next'
- ) {
- $this->dieUsage(
- 'rvdiffto must be set to a non-negative number, "prev", "next" or "cur"',
- 'diffto'
- );
- }
- // Check whether the revision exists and is readable,
- // DifferenceEngine returns a rather ambiguous empty
- // string if that's not the case
- if ( $params['diffto'] != 0 ) {
- $difftoRev = Revision::newFromID( $params['diffto'] );
- if ( !$difftoRev ) {
- $this->dieUsageMsg( array( 'nosuchrevid', $params['diffto'] ) );
- }
- if ( !$difftoRev->userCan( Revision::DELETED_TEXT, $this->getUser() ) ) {
- $this->setWarning( "Couldn't diff to r{$difftoRev->getID()}: content is hidden" );
- $params['diffto'] = null;
- }
- }
- $this->diffto = $params['diffto'];
+ // In non-enum mode, rvlimit can't be directly used. Use the maximum
+ // allowed value.
+ if ( !$enumRevMode ) {
+ $this->setParsedLimit = false;
+ $params['limit'] = 'max';
}
$db = $this->getDB();
- $this->addTables( 'page' );
- $this->addFields( Revision::selectFields() );
- $this->addWhere( 'page_id = rev_page' );
-
- $prop = array_flip( $params['prop'] );
-
- // Optional fields
- $this->fld_ids = isset( $prop['ids'] );
- // $this->addFieldsIf('rev_text_id', $this->fld_ids); // should this be exposed?
- $this->fld_flags = isset( $prop['flags'] );
- $this->fld_timestamp = isset( $prop['timestamp'] );
- $this->fld_comment = isset( $prop['comment'] );
- $this->fld_parsedcomment = isset( $prop['parsedcomment'] );
- $this->fld_size = isset( $prop['size'] );
- $this->fld_sha1 = isset( $prop['sha1'] );
- $this->fld_contentmodel = isset( $prop['contentmodel'] );
- $this->fld_userid = isset( $prop['userid'] );
- $this->fld_user = isset( $prop['user'] );
- $this->token = $params['token'];
-
- if ( !empty( $params['contentformat'] ) ) {
- $this->contentFormat = $params['contentformat'];
- }
-
- $userMax = ( $this->fld_content ? ApiBase::LIMIT_SML1 : ApiBase::LIMIT_BIG1 );
- $botMax = ( $this->fld_content ? ApiBase::LIMIT_SML2 : ApiBase::LIMIT_BIG2 );
- $limit = $params['limit'];
- if ( $limit == 'max' ) {
- $limit = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
- $this->getResult()->setParsedLimit( $this->getModuleName(), $limit );
- }
+ $this->addTables( array( 'revision', 'page' ) );
+ $this->addJoinConds(
+ array( 'page' => array( 'INNER JOIN', array( 'page_id = rev_page' ) ) )
+ );
- if ( !is_null( $this->token ) || $pageCount > 0 ) {
- $this->addFields( Revision::selectPageFields() );
+ if ( $resultPageSet === null ) {
+ $this->parseParameters( $params );
+ $this->token = $params['token'];
+ $this->addFields( Revision::selectFields() );
+ if ( $this->token !== null || $pageCount > 0 ) {
+ $this->addFields( Revision::selectPageFields() );
+ }
+ } else {
+ $this->limit = $this->getParameter( 'limit' ) ?: 10;
+ $this->addFields( array( 'rev_id', 'rev_page' ) );
}
- if ( isset( $prop['tags'] ) ) {
- $this->fld_tags = true;
+ if ( $this->fld_tags ) {
$this->addTables( 'tag_summary' );
$this->addJoinConds(
array( 'tag_summary' => array( 'LEFT JOIN', array( 'rev_id=ts_rev_id' ) ) )
@@ -211,7 +168,7 @@ class ApiQueryRevisions extends ApiQueryBase {
$this->addWhereFld( 'ct_tag', $params['tag'] );
}
- if ( isset( $prop['content'] ) || !is_null( $this->diffto ) || !is_null( $this->difftotext ) ) {
+ if ( $this->fetchContent ) {
// For each page we will request, the user must have read rights for that page
$user = $this->getUser();
/** @var $title Title */
@@ -224,28 +181,11 @@ class ApiQueryRevisions extends ApiQueryBase {
}
$this->addTables( 'text' );
- $this->addWhere( 'rev_text_id=old_id' );
+ $this->addJoinConds(
+ array( 'text' => array( 'INNER JOIN', array( 'rev_text_id=old_id' ) ) )
+ );
$this->addFields( 'old_id' );
$this->addFields( Revision::selectTextFields() );
-
- $this->fld_content = isset( $prop['content'] );
-
- $this->expandTemplates = $params['expandtemplates'];
- $this->generateXML = $params['generatexml'];
- $this->parseContent = $params['parse'];
- if ( $this->parseContent ) {
- // Must manually initialize unset limit
- if ( is_null( $limit ) ) {
- $limit = 1;
- }
- // We are only going to parse 1 revision per request
- $this->validateLimit( 'limit', $limit, 1, 1, 1 );
- }
- if ( isset( $params['section'] ) ) {
- $this->section = $params['section'];
- } else {
- $this->section = false;
- }
}
// add user name, if needed
@@ -255,9 +195,6 @@ class ApiQueryRevisions extends ApiQueryBase {
$this->addFields( Revision::selectUserFields() );
}
- // Bug 24166 - API error when using rvprop=tags
- $this->addTables( 'revision' );
-
if ( $enumRevMode ) {
// This is mostly to prevent parameter errors (and optimize SQL?)
if ( !is_null( $params['startid'] ) && !is_null( $params['start'] ) ) {
@@ -300,12 +237,6 @@ class ApiQueryRevisions extends ApiQueryBase {
$params['start'], $params['end'], false );
}
- // must manually initialize unset limit
- if ( is_null( $limit ) ) {
- $limit = 10;
- }
- $this->validateLimit( 'limit', $limit, 1, $userMax, $botMax );
-
// There is only one ID, use it
$ids = array_keys( $pageSet->getGoodTitles() );
$this->addWhereFld( 'rev_page', reset( $ids ) );
@@ -330,11 +261,7 @@ class ApiQueryRevisions extends ApiQueryBase {
}
}
} elseif ( $revCount > 0 ) {
- $max = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
- $revs = $pageSet->getRevisionIDs();
- if ( self::truncateArray( $revs, $max ) ) {
- $this->setWarning( "Too many values supplied for parameter 'revids': the limit is $max" );
- }
+ $revs = $pageSet->getLiveRevisionIDs();
// Get all revision IDs
$this->addWhereFld( 'rev_id', array_keys( $revs ) );
@@ -343,19 +270,11 @@ class ApiQueryRevisions extends ApiQueryBase {
$this->addWhere( 'rev_id >= ' . intval( $params['continue'] ) );
}
$this->addOption( 'ORDER BY', 'rev_id' );
-
- // assumption testing -- we should never get more then $revCount rows.
- $limit = $revCount;
} elseif ( $pageCount > 0 ) {
- $max = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
$titles = $pageSet->getGoodTitles();
- if ( self::truncateArray( $titles, $max ) ) {
- $this->setWarning( "Too many values supplied for parameter 'titles': the limit is $max" );
- }
// When working in multi-page non-enumeration mode,
// limit to the latest revision only
- $this->addWhere( 'page_id=rev_page' );
$this->addWhere( 'page_latest=rev_id' );
// Get all page IDs
@@ -378,31 +297,20 @@ class ApiQueryRevisions extends ApiQueryBase {
'rev_page',
'rev_id'
) );
-
- // assumption testing -- we should never get more then $pageCount rows.
- $limit = $pageCount;
} else {
ApiBase::dieDebug( __METHOD__, 'param validation?' );
}
- $this->addOption( 'LIMIT', $limit + 1 );
+ $this->addOption( 'LIMIT', $this->limit + 1 );
$count = 0;
+ $generated = array();
$res = $this->select( __METHOD__ );
foreach ( $res as $row ) {
- if ( ++$count > $limit ) {
+ if ( ++$count > $this->limit ) {
// We've reached the one extra which shows that there are
// additional pages to be had. Stop here...
- if ( !$enumRevMode ) {
- ApiBase::dieDebug( __METHOD__, 'Got more rows then expected' ); // bug report
- }
- $this->setContinueEnumParameter( 'continue', intval( $row->rev_id ) );
- break;
- }
-
- $fit = $this->addPageSubItem( $row->rev_page, $this->extractRowInfo( $row ), 'rev' );
- if ( !$fit ) {
if ( $enumRevMode ) {
$this->setContinueEnumParameter( 'continue', intval( $row->rev_id ) );
} elseif ( $revCount > 0 ) {
@@ -413,434 +321,124 @@ class ApiQueryRevisions extends ApiQueryBase {
}
break;
}
- }
- }
-
- private function extractRowInfo( $row ) {
- $revision = new Revision( $row );
- $title = $revision->getTitle();
- $user = $this->getUser();
- $vals = array();
- $anyHidden = false;
-
- if ( $this->fld_ids ) {
- $vals['revid'] = intval( $revision->getId() );
- // $vals['oldid'] = intval( $row->rev_text_id ); // todo: should this be exposed?
- if ( !is_null( $revision->getParentId() ) ) {
- $vals['parentid'] = intval( $revision->getParentId() );
- }
- }
-
- if ( $this->fld_flags && $revision->isMinor() ) {
- $vals['minor'] = '';
- }
-
- if ( $this->fld_user || $this->fld_userid ) {
- if ( $revision->isDeleted( Revision::DELETED_USER ) ) {
- $vals['userhidden'] = '';
- $anyHidden = true;
- }
- if ( $revision->userCan( Revision::DELETED_USER, $user ) ) {
- if ( $this->fld_user ) {
- $vals['user'] = $revision->getRawUserText();
- }
- $userid = $revision->getRawUser();
- if ( !$userid ) {
- $vals['anon'] = '';
- }
-
- if ( $this->fld_userid ) {
- $vals['userid'] = $userid;
- }
- }
- }
-
- if ( $this->fld_timestamp ) {
- $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $revision->getTimestamp() );
- }
-
- if ( $this->fld_size ) {
- if ( !is_null( $revision->getSize() ) ) {
- $vals['size'] = intval( $revision->getSize() );
- } else {
- $vals['size'] = 0;
- }
- }
-
- if ( $this->fld_sha1 ) {
- if ( $revision->isDeleted( Revision::DELETED_TEXT ) ) {
- $vals['sha1hidden'] = '';
- $anyHidden = true;
- }
- if ( $revision->userCan( Revision::DELETED_TEXT, $user ) ) {
- if ( $revision->getSha1() != '' ) {
- $vals['sha1'] = wfBaseConvert( $revision->getSha1(), 36, 16, 40 );
- } else {
- $vals['sha1'] = '';
- }
- }
- }
-
- if ( $this->fld_contentmodel ) {
- $vals['contentmodel'] = $revision->getContentModel();
- }
-
- if ( $this->fld_comment || $this->fld_parsedcomment ) {
- if ( $revision->isDeleted( Revision::DELETED_COMMENT ) ) {
- $vals['commenthidden'] = '';
- $anyHidden = true;
- }
- if ( $revision->userCan( Revision::DELETED_COMMENT, $user ) ) {
- $comment = $revision->getRawComment();
-
- if ( $this->fld_comment ) {
- $vals['comment'] = $comment;
- }
-
- if ( $this->fld_parsedcomment ) {
- $vals['parsedcomment'] = Linker::formatComment( $comment, $title );
- }
- }
- }
- if ( $this->fld_tags ) {
- if ( $row->ts_tags ) {
- $tags = explode( ',', $row->ts_tags );
- $this->getResult()->setIndexedTagName( $tags, 'tag' );
- $vals['tags'] = $tags;
+ if ( $resultPageSet !== null ) {
+ $generated[] = $row->rev_id;
} else {
- $vals['tags'] = array();
- }
- }
-
- if ( !is_null( $this->token ) ) {
- $tokenFunctions = $this->getTokenFunctions();
- foreach ( $this->token as $t ) {
- $val = call_user_func( $tokenFunctions[$t], $title->getArticleID(), $title, $revision );
- if ( $val === false ) {
- $this->setWarning( "Action '$t' is not allowed for the current user" );
- } else {
- $vals[$t . 'token'] = $val;
- }
- }
- }
-
- $content = null;
- global $wgParser;
- if ( $this->fld_content || !is_null( $this->diffto ) || !is_null( $this->difftotext ) ) {
- $content = $revision->getContent( Revision::FOR_THIS_USER, $this->getUser() );
- // Expand templates after getting section content because
- // template-added sections don't count and Parser::preprocess()
- // will have less input
- if ( $content && $this->section !== false ) {
- $content = $content->getSection( $this->section, false );
- if ( !$content ) {
- $this->dieUsage(
- "There is no section {$this->section} in r" . $revision->getId(),
- 'nosuchsection'
- );
- }
- }
- if ( $revision->isDeleted( Revision::DELETED_TEXT ) ) {
- $vals['texthidden'] = '';
- $anyHidden = true;
- } elseif ( !$content ) {
- $vals['textmissing'] = '';
- }
- }
- if ( $this->fld_content && $content ) {
- $text = null;
-
- if ( $this->generateXML ) {
- if ( $content->getModel() === CONTENT_MODEL_WIKITEXT ) {
- $t = $content->getNativeData(); # note: don't set $text
-
- $wgParser->startExternalParse(
- $title,
- ParserOptions::newFromContext( $this->getContext() ),
- OT_PREPROCESS
- );
- $dom = $wgParser->preprocessToDom( $t );
- if ( is_callable( array( $dom, 'saveXML' ) ) ) {
- $xml = $dom->saveXML();
- } else {
- $xml = $dom->__toString();
+ $revision = new Revision( $row );
+ $rev = $this->extractRevisionInfo( $revision, $row );
+
+ if ( $this->token !== null ) {
+ $title = $revision->getTitle();
+ $tokenFunctions = $this->getTokenFunctions();
+ foreach ( $this->token as $t ) {
+ $val = call_user_func( $tokenFunctions[$t], $title->getArticleID(), $title, $revision );
+ if ( $val === false ) {
+ $this->setWarning( "Action '$t' is not allowed for the current user" );
+ } else {
+ $rev[$t . 'token'] = $val;
+ }
}
- $vals['parsetree'] = $xml;
- } else {
- $this->setWarning( "Conversion to XML is supported for wikitext only, " .
- $title->getPrefixedDBkey() .
- " uses content model " . $content->getModel() );
- }
- }
-
- if ( $this->expandTemplates && !$this->parseContent ) {
- #XXX: implement template expansion for all content types in ContentHandler?
- if ( $content->getModel() === CONTENT_MODEL_WIKITEXT ) {
- $text = $content->getNativeData();
-
- $text = $wgParser->preprocess(
- $text,
- $title,
- ParserOptions::newFromContext( $this->getContext() )
- );
- } else {
- $this->setWarning( "Template expansion is supported for wikitext only, " .
- $title->getPrefixedDBkey() .
- " uses content model " . $content->getModel() );
-
- $text = false;
}
- }
- if ( $this->parseContent ) {
- $po = $content->getParserOutput(
- $title,
- $revision->getId(),
- ParserOptions::newFromContext( $this->getContext() )
- );
- $text = $po->getText();
- }
-
- if ( $text === null ) {
- $format = $this->contentFormat ? $this->contentFormat : $content->getDefaultFormat();
- $model = $content->getModel();
-
- if ( !$content->isSupportedFormat( $format ) ) {
- $name = $title->getPrefixedDBkey();
-
- $this->dieUsage( "The requested format {$this->contentFormat} is not supported " .
- "for content model $model used by $name", 'badformat' );
- }
-
- $text = $content->serialize( $format );
- // always include format and model.
- // Format is needed to deserialize, model is needed to interpret.
- $vals['contentformat'] = $format;
- $vals['contentmodel'] = $model;
- }
-
- if ( $text !== false ) {
- ApiResult::setContent( $vals, $text );
- }
- }
-
- if ( $content && ( !is_null( $this->diffto ) || !is_null( $this->difftotext ) ) ) {
- static $n = 0; // Number of uncached diffs we've had
-
- if ( $n < $this->getConfig()->get( 'APIMaxUncachedDiffs' ) ) {
- $vals['diff'] = array();
- $context = new DerivativeContext( $this->getContext() );
- $context->setTitle( $title );
- $handler = $revision->getContentHandler();
-
- if ( !is_null( $this->difftotext ) ) {
- $model = $title->getContentModel();
-
- if ( $this->contentFormat
- && !ContentHandler::getForModelID( $model )->isSupportedFormat( $this->contentFormat )
- ) {
-
- $name = $title->getPrefixedDBkey();
-
- $this->dieUsage( "The requested format {$this->contentFormat} is not supported for " .
- "content model $model used by $name", 'badformat' );
+ $fit = $this->addPageSubItem( $row->rev_page, $rev, 'rev' );
+ if ( !$fit ) {
+ if ( $enumRevMode ) {
+ $this->setContinueEnumParameter( 'continue', intval( $row->rev_id ) );
+ } elseif ( $revCount > 0 ) {
+ $this->setContinueEnumParameter( 'continue', intval( $row->rev_id ) );
+ } else {
+ $this->setContinueEnumParameter( 'continue', intval( $row->rev_page ) .
+ '|' . intval( $row->rev_id ) );
}
-
- $difftocontent = ContentHandler::makeContent(
- $this->difftotext,
- $title,
- $model,
- $this->contentFormat
- );
-
- $engine = $handler->createDifferenceEngine( $context );
- $engine->setContent( $content, $difftocontent );
- } else {
- $engine = $handler->createDifferenceEngine( $context, $revision->getID(), $this->diffto );
- $vals['diff']['from'] = $engine->getOldid();
- $vals['diff']['to'] = $engine->getNewid();
- }
- $difftext = $engine->getDiffBody();
- ApiResult::setContent( $vals['diff'], $difftext );
- if ( !$engine->wasCacheHit() ) {
- $n++;
+ break;
}
- } else {
- $vals['diff']['notcached'] = '';
}
}
- if ( $anyHidden && $revision->isDeleted( Revision::DELETED_RESTRICTED ) ) {
- $vals['suppressed'] = '';
+ if ( $resultPageSet !== null ) {
+ $resultPageSet->populateFromRevisionIDs( $generated );
}
-
- return $vals;
}
public function getCacheMode( $params ) {
if ( isset( $params['token'] ) ) {
return 'private';
}
- if ( $this->userCanSeeRevDel() ) {
- return 'private';
- }
- if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
- // formatComment() calls wfMessage() among other things
- return 'anon-public-user-private';
- }
-
- return 'public';
+ return parent::getCacheMode( $params );
}
public function getAllowedParams() {
- return array(
- 'prop' => array(
- ApiBase::PARAM_ISMULTI => true,
- ApiBase::PARAM_DFLT => 'ids|timestamp|flags|comment|user',
- ApiBase::PARAM_TYPE => array(
- 'ids',
- 'flags',
- 'timestamp',
- 'user',
- 'userid',
- 'size',
- 'sha1',
- 'contentmodel',
- 'comment',
- 'parsedcomment',
- 'content',
- 'tags'
- )
- ),
- 'limit' => array(
- ApiBase::PARAM_TYPE => 'limit',
- ApiBase::PARAM_MIN => 1,
- ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
- ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
- ),
+ $ret = parent::getAllowedParams() + array(
'startid' => array(
- ApiBase::PARAM_TYPE => 'integer'
+ ApiBase::PARAM_TYPE => 'integer',
+ ApiBase::PARAM_HELP_MSG_INFO => array( array( 'singlepageonly' ) ),
),
'endid' => array(
- ApiBase::PARAM_TYPE => 'integer'
+ ApiBase::PARAM_TYPE => 'integer',
+ ApiBase::PARAM_HELP_MSG_INFO => array( array( 'singlepageonly' ) ),
),
'start' => array(
- ApiBase::PARAM_TYPE => 'timestamp'
+ ApiBase::PARAM_TYPE => 'timestamp',
+ ApiBase::PARAM_HELP_MSG_INFO => array( array( 'singlepageonly' ) ),
),
'end' => array(
- ApiBase::PARAM_TYPE => 'timestamp'
+ ApiBase::PARAM_TYPE => 'timestamp',
+ ApiBase::PARAM_HELP_MSG_INFO => array( array( 'singlepageonly' ) ),
),
'dir' => array(
ApiBase::PARAM_DFLT => 'older',
ApiBase::PARAM_TYPE => array(
'newer',
'older'
- )
+ ),
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
+ ApiBase::PARAM_HELP_MSG_INFO => array( array( 'singlepageonly' ) ),
),
'user' => array(
- ApiBase::PARAM_TYPE => 'user'
+ ApiBase::PARAM_TYPE => 'user',
+ ApiBase::PARAM_HELP_MSG_INFO => array( array( 'singlepageonly' ) ),
),
'excludeuser' => array(
- ApiBase::PARAM_TYPE => 'user'
+ ApiBase::PARAM_TYPE => 'user',
+ ApiBase::PARAM_HELP_MSG_INFO => array( array( 'singlepageonly' ) ),
),
'tag' => null,
- 'expandtemplates' => false,
- 'generatexml' => false,
- 'parse' => false,
- 'section' => null,
'token' => array(
ApiBase::PARAM_DEPRECATED => true,
ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() ),
ApiBase::PARAM_ISMULTI => true
),
- 'continue' => null,
- 'diffto' => null,
- 'difftotext' => null,
- 'contentformat' => array(
- ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(),
- ApiBase::PARAM_DFLT => null
+ 'continue' => array(
+ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
),
);
- }
- public function getParamDescription() {
- $p = $this->getModulePrefix();
+ $ret['limit'][ApiBase::PARAM_HELP_MSG_INFO] = array( array( 'singlepageonly' ) );
- return array(
- 'prop' => array(
- 'Which properties to get for each revision:',
- ' ids - The ID of the revision',
- ' flags - Revision flags (minor)',
- ' timestamp - The timestamp of the revision',
- ' user - User that made the revision',
- ' userid - User id of revision creator',
- ' size - Length (bytes) of the revision',
- ' sha1 - SHA-1 (base 16) of the revision',
- ' contentmodel - Content model id',
- ' comment - Comment by the user for revision',
- ' parsedcomment - Parsed comment by the user for the revision',
- ' content - Text of the revision',
- ' tags - Tags for the revision',
- ),
- 'limit' => 'Limit how many revisions will be returned (enum)',
- 'startid' => 'From which revision id to start enumeration (enum)',
- 'endid' => 'Stop revision enumeration on this revid (enum)',
- 'start' => 'From which revision timestamp to start enumeration (enum)',
- 'end' => 'Enumerate up to this timestamp (enum)',
- 'dir' => $this->getDirectionDescription( $p, ' (enum)' ),
- 'user' => 'Only include revisions made by user (enum)',
- 'excludeuser' => 'Exclude revisions made by user (enum)',
- 'expandtemplates' => "Expand templates in revision content (requires {$p}prop=content)",
- 'generatexml' => "Generate XML parse tree for revision content (requires {$p}prop=content)",
- 'parse' => array( "Parse revision content (requires {$p}prop=content).",
- 'For performance reasons if this option is used, rvlimit is enforced to 1.' ),
- 'section' => 'Only retrieve the content of this section number',
- 'token' => 'Which tokens to obtain for each revision',
- 'continue' => 'When more results are available, use this to continue',
- 'diffto' => array( 'Revision ID to diff each revision to.',
- 'Use "prev", "next" and "cur" for the previous, next and current revision respectively' ),
- 'difftotext' => array(
- 'Text to diff each revision to. Only diffs a limited number of revisions.',
- "Overrides {$p}diffto. If {$p}section is set, only that section will be",
- 'diffed against this text',
- ),
- 'tag' => 'Only list revisions tagged with this tag',
- 'contentformat' => 'Serialization format used for difftotext and expected for output of content',
- );
- }
-
- public function getDescription() {
- return array(
- 'Get revision information.',
- 'May be used in several ways:',
- ' 1) Get data about a set of pages (last revision), by setting titles or pageids parameter.',
- ' 2) Get revisions for one given page, by using titles/pageids with start/end/limit params.',
- ' 3) Get data about a set of revisions by setting their IDs with revids parameter.',
- 'All parameters marked as (enum) may only be used with a single page (#2).'
- );
+ return $ret;
}
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'Get data with content for the last revision of titles "API" and "Main Page"',
- ' api.php?action=query&prop=revisions&titles=API|Main%20Page&' .
- 'rvprop=timestamp|user|comment|content',
- 'Get last 5 revisions of the "Main Page"',
- ' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
- 'rvprop=timestamp|user|comment',
- 'Get first 5 revisions of the "Main Page"',
- ' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
- 'rvprop=timestamp|user|comment&rvdir=newer',
- 'Get first 5 revisions of the "Main Page" made after 2006-05-01',
- ' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
- 'rvprop=timestamp|user|comment&rvdir=newer&rvstart=20060501000000',
- 'Get first 5 revisions of the "Main Page" that were not made made by anonymous user "127.0.0.1"',
- ' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
- 'rvprop=timestamp|user|comment&rvexcludeuser=127.0.0.1',
- 'Get first 5 revisions of the "Main Page" that were made by the user "MediaWiki default"',
- ' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
- 'rvprop=timestamp|user|comment&rvuser=MediaWiki%20default',
+ 'action=query&prop=revisions&titles=API|Main%20Page&' .
+ 'rvprop=timestamp|user|comment|content'
+ => 'apihelp-query+revisions-example-content',
+ 'action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
+ 'rvprop=timestamp|user|comment'
+ => 'apihelp-query+revisions-example-last5',
+ 'action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
+ 'rvprop=timestamp|user|comment&rvdir=newer'
+ => 'apihelp-query+revisions-example-first5',
+ 'action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
+ 'rvprop=timestamp|user|comment&rvdir=newer&rvstart=2006-05-01T00:00:00Z'
+ => 'apihelp-query+revisions-example-first5-after',
+ 'action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
+ 'rvprop=timestamp|user|comment&rvexcludeuser=127.0.0.1'
+ => 'apihelp-query+revisions-example-first5-not-localhost',
+ 'action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
+ 'rvprop=timestamp|user|comment&rvuser=MediaWiki%20default'
+ => 'apihelp-query+revisions-example-first5-user',
);
}
diff --git a/includes/api/ApiQueryRevisionsBase.php b/includes/api/ApiQueryRevisionsBase.php
new file mode 100644
index 00000000..64f6120a
--- /dev/null
+++ b/includes/api/ApiQueryRevisionsBase.php
@@ -0,0 +1,477 @@
+<?php