interact with ApiParse and ApiExpandTemplates.
* (T139565) SECURITY: API: Generate head items in the context of the given title
* (T115333) SECURITY: Check read permission when loading page content in ApiParse
+* ApiBase::makeHelpArrayToString() was removed (deprecated since 1.25)
+* ApiBase::makeHelpMsgParameters() was removed (deprecated since 1.25)
+* ApiBase::makeHelpMsg() was removed (deprecated since 1.25)
+* ApiFormatBase::formatHTML() was removed (deprecated since 1.25)
+* ApiFormatBase::getNeedsRawData() was removed (deprecated since 1.25)
+* ApiFormatBase::getWantsHelp() was removed (deprecated since 1.25)
+* ApiFormatBase::setBufferResult() was removed (deprecated since 1.25)
+* ApiFormatBase::setHelp() was removed (deprecated since 1.25)
+* ApiFormatBase::setUnescapeAmps() was removed (deprecated since 1.25)
+* ApiMain::makeHelpMsgHeader() was removed (deprecated since 1.25)
+* ApiMain::reallyMakeHelpMsg() was removed (deprecated since 1.25)
+* ApiMain::setHelp() was removed (deprecated since 1.25)
+* ApiResult::beginContinuation() was removed (deprecated since 1.25)
+* ApiResult::cleanUpUTF8() was removed (deprecated since 1.25)
+* ApiResult::convertStatusToArray() was removed (deprecated since 1.25)
+* ApiResult::disableSizeCheck() was removed (deprecated since 1.24)
+* ApiResult::enableSizeCheck() was removed (deprecated since 1.24)
+* ApiResult::endContinuation() was removed (deprecated since 1.25)
+* ApiResult::getData() was removed (deprecated since 1.25)
+* ApiResult::getIsRawMode() was removed (deprecated since 1.25)
+* ApiResult::setContent() was removed (deprecated since 1.25)
+* ApiResult::setContinueParam() was removed (deprecated since 1.25)
+* ApiResult::setElement() was removed (deprecated since 1.25)
+* ApiResult::setGeneratorContinueParam() was removed (deprecated since 1.25)
+* ApiResult::setIndexedTagName_internal() was removed (deprecated since 1.25)
+* ApiResult::setIndexedTagName_recursive() was removed (deprecated since 1.25)
+* ApiResult::setMainForContinuation() was removed (deprecated since 1.25)
+* ApiResult::setParsedLimit() was removed (deprecated since 1.25)
+* ApiResult::setRawMode() was removed (deprecated since 1.25)
+* ApiResult::size() was removed (deprecated since 1.25)
=== Languages updated in 1.28 ===
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();
-
- if ( $msg !== false ) {
-
- if ( !is_array( $msg ) ) {
- $msg = [
- $msg
- ];
- }
- $msg = $lnPrfx . implode( $lnPrfx, $msg ) . "\n";
-
- $msg .= $this->makeHelpArrayToString( $lnPrfx, false, $this->getHelpUrls() );
-
- if ( $this->isReadMode() ) {
- $msg .= "\nThis module requires read rights";
- }
- if ( $this->isWriteMode() ) {
- $msg .= "\nThis module requires write rights";
- }
- if ( $this->mustBePosted() ) {
- $msg .= "\nThis module only accepts POST requests";
- }
- if ( $this->isReadMode() || $this->isWriteMode() ||
- $this->mustBePosted()
- ) {
- $msg .= "\n";
- }
-
- // Parameters
- $paramsMsg = $this->makeHelpMsgParameters();
- if ( $paramsMsg !== false ) {
- $msg .= "Parameters:\n$paramsMsg";
- }
-
- $examples = $this->getExamples();
- if ( $examples ) {
- if ( !is_array( $examples ) ) {
- $examples = [
- $examples
- ];
- }
- $msg .= 'Example' . ( count( $examples ) > 1 ? 's' : '' ) . ":\n";
- foreach ( $examples as $k => $v ) {
- if ( is_numeric( $k ) ) {
- $msg .= " $v\n";
- } else {
- if ( is_array( $v ) ) {
- $msgExample = implode( "\n", array_map( [ $this, 'indentExampleText' ], $v ) );
- } else {
- $msgExample = " $v";
- }
- $msgExample .= ':';
- $msg .= wordwrap( $msgExample, 100, "\n" ) . "\n $k\n";
- }
- }
- }
- }
-
- return $msg;
- }
-
- /**
- * @deprecated since 1.25
- * @param string $item
- * @return string
- */
- private function indentExampleText( $item ) {
- return ' ' . $item;
- }
-
- /**
- * @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 '';
- }
- if ( !is_array( $input ) ) {
- $input = [ $input ];
- }
-
- if ( count( $input ) > 0 ) {
- if ( $title ) {
- $msg = $title . ( count( $input ) > 1 ? 's' : '' ) . ":\n ";
- } else {
- $msg = ' ';
- }
- $msg .= implode( $prefix, $input ) . "\n";
-
- return $msg;
- }
-
- return '';
- }
-
- /**
- * 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 ) {
- $paramsDescription = $this->getFinalParamDescription();
- $msg = '';
- $paramPrefix = "\n" . str_repeat( ' ', 24 );
- $descWordwrap = "\n" . str_repeat( ' ', 28 );
- foreach ( $params as $paramName => $paramSettings ) {
- $desc = isset( $paramsDescription[$paramName] ) ? $paramsDescription[$paramName] : '';
- if ( is_array( $desc ) ) {
- $desc = implode( $paramPrefix, $desc );
- }
-
- // handle shorthand
- if ( !is_array( $paramSettings ) ) {
- $paramSettings = [
- self::PARAM_DFLT => $paramSettings,
- ];
- }
-
- // handle missing type
- if ( !isset( $paramSettings[ApiBase::PARAM_TYPE] ) ) {
- $dflt = isset( $paramSettings[ApiBase::PARAM_DFLT] )
- ? $paramSettings[ApiBase::PARAM_DFLT]
- : null;
- if ( is_bool( $dflt ) ) {
- $paramSettings[ApiBase::PARAM_TYPE] = 'boolean';
- } elseif ( is_string( $dflt ) || is_null( $dflt ) ) {
- $paramSettings[ApiBase::PARAM_TYPE] = 'string';
- } elseif ( is_int( $dflt ) ) {
- $paramSettings[ApiBase::PARAM_TYPE] = 'integer';
- }
- }
-
- if ( isset( $paramSettings[self::PARAM_DEPRECATED] )
- && $paramSettings[self::PARAM_DEPRECATED]
- ) {
- $desc = "DEPRECATED! $desc";
- }
-
- if ( isset( $paramSettings[self::PARAM_REQUIRED] )
- && $paramSettings[self::PARAM_REQUIRED]
- ) {
- $desc .= $paramPrefix . 'This parameter is required';
- }
-
- $type = isset( $paramSettings[self::PARAM_TYPE] )
- ? $paramSettings[self::PARAM_TYPE]
- : null;
- if ( isset( $type ) ) {
- $hintPipeSeparated = true;
- $multi = isset( $paramSettings[self::PARAM_ISMULTI] )
- ? $paramSettings[self::PARAM_ISMULTI]
- : false;
- if ( $multi ) {
- $prompt = 'Values (separate with \'|\'): ';
- } else {
- $prompt = 'One value: ';
- }
-
- if ( $type === 'submodule' ) {
- if ( isset( $paramSettings[self::PARAM_SUBMODULE_MAP] ) ) {
- $type = array_keys( $paramSettings[self::PARAM_SUBMODULE_MAP] );
- } else {
- $type = $this->getModuleManager()->getNames( $paramName );
- }
- sort( $type );
- }
- if ( is_array( $type ) ) {
- $choices = [];
- $nothingPrompt = '';
- foreach ( $type as $t ) {
- if ( $t === '' ) {
- $nothingPrompt = 'Can be empty, or ';
- } else {
- $choices[] = $t;
- }
- }
- $desc .= $paramPrefix . $nothingPrompt . $prompt;
- $choicesstring = implode( ', ', $choices );
- $desc .= wordwrap( $choicesstring, 100, $descWordwrap );
- $hintPipeSeparated = false;
- } else {
- switch ( $type ) {
- case 'namespace':
- // Special handling because namespaces are
- // type-limited, yet they are not given
- $desc .= $paramPrefix . $prompt;
- $desc .= wordwrap( implode( ', ', MWNamespace::getValidNamespaces() ),
- 100, $descWordwrap );
- $hintPipeSeparated = false;
- break;
- case 'limit':
- $desc .= $paramPrefix . "No more than {$paramSettings[self::PARAM_MAX]}";
- if ( isset( $paramSettings[self::PARAM_MAX2] ) ) {
- $desc .= " ({$paramSettings[self::PARAM_MAX2]} for bots)";
- }
- $desc .= ' allowed';
- break;
- case 'integer':
- $s = $multi ? 's' : '';
- $hasMin = isset( $paramSettings[self::PARAM_MIN] );
- $hasMax = isset( $paramSettings[self::PARAM_MAX] );
- if ( $hasMin || $hasMax ) {
- if ( !$hasMax ) {
- $intRangeStr = "The value$s must be no less than " .
- "{$paramSettings[self::PARAM_MIN]}";
- } elseif ( !$hasMin ) {
- $intRangeStr = "The value$s must be no more than " .
- "{$paramSettings[self::PARAM_MAX]}";
- } else {
- $intRangeStr = "The value$s must be between " .
- "{$paramSettings[self::PARAM_MIN]} and {$paramSettings[self::PARAM_MAX]}";
- }
-
- $desc .= $paramPrefix . $intRangeStr;
- }
- break;
- case 'upload':
- $desc .= $paramPrefix . 'Must be posted as a file upload using multipart/form-data';
- break;
- }
- }
-
- if ( $multi ) {
- if ( $hintPipeSeparated ) {
- $desc .= $paramPrefix . "Separate values with '|'";
- }
-
- $isArray = is_array( $type );
- if ( !$isArray
- || $isArray && count( $type ) > self::LIMIT_SML1
- ) {
- $desc .= $paramPrefix . 'Maximum number of values ' .
- self::LIMIT_SML1 . ' (' . self::LIMIT_SML2 . ' for bots)';
- }
- }
- }
-
- $default = isset( $paramSettings[self::PARAM_DFLT] ) ? $paramSettings[self::PARAM_DFLT] : null;
- if ( !is_null( $default ) && $default !== false ) {
- $desc .= $paramPrefix . "Default: $default";
- }
-
- $msg .= sprintf( " %-19s - %s\n", $this->encodeParamName( $paramName ), $desc );
- }
-
- return $msg;
- }
-
- return false;
- }
-
/**
* @deprecated since 1.25, always returns empty string
* @param IDatabase|bool $db
return 'https://www.mediawiki.org/wiki/API:Data_formats';
}
- /************************************************************************//**
- * @name Deprecated
- * @{
- */
-
- /**
- * Specify whether or not sequences like " should be unescaped
- * to " . 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 );
-
- if ( $this->mFormat === 'XML' ) {
- // encode all comments or tags as safe blue strings
- $text = str_replace( '<', '<span style="color:blue;"><', $text );
- $text = str_replace( '>', '></span>', $text );
- }
-
- // identify requests to api.php
- $text = preg_replace( '#^(\s*)(api\.php\?[^ <\n\t]+)$#m', '\1<a href="\2">\2</a>', $text );
- if ( $this->mHelp ) {
- // make lines inside * bold
- $text = preg_replace( '#^(\s*)(\*[^<>\n]+\*)(\s*)$#m', '$1<b>$2</b>$3', $text );
- }
-
- // Armor links (bug 61362)
- $masked = [];
- $text = preg_replace_callback( '#<a .*?</a>#', function ( $matches ) use ( &$masked ) {
- $sha = sha1( $matches[0] );
- $masked[$sha] = $matches[0];
- return "<$sha>";
- }, $text );
-
- // identify URLs
- $protos = wfUrlProtocolsWithoutProtRel();
- // This regex hacks around bug 13218 (" included in the URL)
- $text = preg_replace(
- "#(((?i)$protos).*?)(")?([ \\'\"<>\n]|<|>|")#",
- '<a href="\\1">\\1</a>\\3\\4',
- $text
- );
-
- // Unarmor links
- $text = preg_replace_callback( '#<([0-9a-f]{40})>#', function ( $matches ) use ( &$masked ) {
- $sha = $matches[1];
- return isset( $masked[$sha] ) ? $masked[$sha] : $matches[0];
- }, $text );
-
- /**
- * Temporary fix for bad links in help messages. As a special case,
- * XML-escaped metachars are de-escaped one level in the help message
- * for legibility. Should be removed once we have completed a fully-HTML
- * version of the help message.
- */
- if ( $this->mUnescapeAmps ) {
- $text = preg_replace( '/&(amp|quot|lt|gt);/', '&\1;', $text );
- }
-
- return $text;
- }
-
- /**
- * @see ApiBase::getDescription
- * @deprecated since 1.25
- */
- public function getDescription() {
- return $this->getIsHtml() ? ' (pretty-print in HTML)' : '';
- }
-
- /**
- * Set the flag to buffer the result instead of printing it.
- * @deprecated since 1.25, output is always buffered
- * @param bool $value
- */
- 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 Always true
- */
- public function getNeedsRawData() {
- wfDeprecated( __METHOD__, '1.25' );
- return true;
- }
-
- /**@}*/
}
/**
return 'application/json';
}
- /**
- * @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();
$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->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' );
-
- $this->setHelp();
- $cacheHelpTimeout = $this->getConfig()->get( 'APICacheHelpTimeout' );
-
- return ObjectCache::getMainWANInstance()->getWithSetCallback(
- wfMemcKey(
- 'apihelp',
- $this->getModuleName(),
- str_replace( ' ', '_', SpecialVersion::getVersion( 'nodb' ) )
- ),
- $cacheHelpTimeout > 0 ? $cacheHelpTimeout : WANObjectCache::TTL_UNCACHEABLE,
- [ $this, 'reallyMakeHelpMsg' ]
- );
- }
-
- /**
- * @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
- $msg = parent::makeHelpMsg();
-
- $asterisks = str_repeat( '*** ', 14 );
- $msg .= "\n\n$asterisks Modules $asterisks\n\n";
-
- foreach ( $this->mModuleMgr->getNames( 'action' ) as $name ) {
- $module = $this->mModuleMgr->getModule( $name );
- $msg .= self::makeHelpMsgHeader( $module, 'action' );
-
- $msg2 = $module->makeHelpMsg();
- if ( $msg2 !== false ) {
- $msg .= $msg2;
- }
- $msg .= "\n";
- }
-
- $msg .= "\n$asterisks Permissions $asterisks\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 $rightsMsg" .
- "\nGranted to:\n " . str_replace( '*', 'all', implode( ', ', $groups ) ) . "\n\n";
- }
-
- $msg .= "\n$asterisks Formats $asterisks\n\n";
- foreach ( $this->mModuleMgr->getNames( 'format' ) as $name ) {
- $module = $this->mModuleMgr->getModule( $name );
- $msg .= self::makeHelpMsgHeader( $module, 'format' );
- $msg2 = $module->makeHelpMsg();
- if ( $msg2 !== false ) {
- $msg .= $msg2;
- }
- $msg .= "\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) ";
- }
-
- return "* $paramName={$module->getModuleName()} $modulePrefix*";
- }
-
- /**@}*/
-
}
/**
return $result;
}
- /**
- * 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();
-
- $querySeparator = str_repeat( '--- ', 12 );
- $moduleSeparator = str_repeat( '*** ', 14 );
- $msg .= "\n$querySeparator Query: Prop $querySeparator\n\n";
- $msg .= $this->makeHelpMsgHelper( 'prop' );
- $msg .= "\n$querySeparator Query: List $querySeparator\n\n";
- $msg .= $this->makeHelpMsgHelper( 'list' );
- $msg .= "\n$querySeparator Query: Meta $querySeparator\n\n";
- $msg .= $this->makeHelpMsgHelper( 'meta' );
- $msg .= "\n\n$moduleSeparator Modules: continuation $moduleSeparator\n\n";
-
- return $msg;
- }
-
- /**
- * 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
- */
- private function makeHelpMsgHelper( $group ) {
- $moduleDescriptions = [];
-
- $moduleNames = $this->mModuleMgr->getNames( $group );
- sort( $moduleNames );
- foreach ( $moduleNames as $name ) {
- /**
- * @var $module ApiQueryBase
- */
- $module = $this->mModuleMgr->getModule( $name );
-
- $msg = ApiMain::makeHelpMsgHeader( $module, $group );
- $msg2 = $module->makeHelpMsg();
- if ( $msg2 !== false ) {
- $msg .= $msg2;
- }
- if ( $module instanceof ApiQueryGeneratorBase ) {
- $msg .= "Generator:\n This module may be used as a generator\n";
- }
- $moduleDescriptions[] = $msg;
- }
-
- return implode( "\n", $moduleDescriptions );
- }
-
public function isReadMode() {
// We need to make an exception for certain meta modules that should be
// accessible even without the 'read' right. Restrict the exception as
$arr = &$this->path( $path, ( $flags & ApiResult::ADD_ON_TOP ) ? 'prepend' : 'append' );
if ( $this->checkingSize && !( $flags & ApiResult::NO_SIZE_CHECK ) ) {
- // self::valueSize needs the validated value. Then flag
+ // self::size needs the validated value. Then flag
// to not re-validate later.
$value = self::validateValue( $value );
$flags |= ApiResult::NO_VALIDATE;
- $newsize = $this->size + self::valueSize( $value );
+ $newsize = $this->size + self::size( $value );
if ( $this->maxSize !== false && $newsize > $this->maxSize ) {
/// @todo Add i18n message when replacing calls to ->setWarning()
$msg = new ApiRawMessage( 'This result was truncated because it would otherwise ' .
}
$ret = self::unsetValue( $this->path( $path, 'dummy' ), $name );
if ( $this->checkingSize && !( $flags & ApiResult::NO_SIZE_CHECK ) ) {
- $newsize = $this->size - self::valueSize( $ret );
+ $newsize = $this->size - self::size( $ret );
$this->size = max( $newsize, 0 );
}
return $ret;
/**
* Get the 'real' size of a result item. This means the strlen() of the item,
* or the sum of the strlen()s of the elements if the item is an array.
- * @note Once the deprecated public self::size is removed, we can rename
- * this back to a less awkward name.
* @param mixed $value Validated value (see self::validateValue())
* @return int
*/
- private static function valueSize( $value ) {
+ private static function size( $value ) {
$s = 0;
if ( is_array( $value ) ) {
foreach ( $value as $k => $v ) {
if ( !self::isMetadataKey( $k ) ) {
- $s += self::valueSize( $v );
+ $s += self::size( $v );
}
}
} elseif ( is_scalar( $value ) ) {
/**@}*/
- /************************************************************************//**
- * @name Deprecated
- * @{
- */
-
- /**
- * Formerly used to enable/disable "raw mode".
- * @deprecated since 1.25, you shouldn't have been using it in the first place
- * @since 1.23 $flag parameter added
- * @param bool $flag Set the raw mode flag to this state
- */
- public function setRawMode( $flag = true ) {
- wfDeprecated( __METHOD__, '1.25' );
- }
-
- /**
- * Returns true, the equivalent of "raw mode" is always enabled now
- * @deprecated since 1.25, you shouldn't have been using it in the first place
- * @return bool
- */
- public function getIsRawMode() {
- wfDeprecated( __METHOD__, '1.25' );
- return true;
- }
-
- /**
- * Get the result's internal data array (read-only)
- * @deprecated since 1.25, use $this->getResultData() instead
- * @return array
- */
- public function getData() {
- wfDeprecated( __METHOD__, '1.25' );
- return $this->getResultData( null, [
- 'BC' => [],
- 'Types' => [],
- 'Strip' => 'all',
- ] );
- }
-
- /**
- * Disable size checking in addValue(). Don't use this unless you
- * REALLY know what you're doing. Values added while size checking
- * was disabled will not be counted (ever)
- * @deprecated since 1.24, use ApiResult::NO_SIZE_CHECK
- */
- public function disableSizeCheck() {
- wfDeprecated( __METHOD__, '1.24' );
- $this->checkingSize = false;
- }
-
- /**
- * Re-enable size checking in addValue()
- * @deprecated since 1.24, use ApiResult::NO_SIZE_CHECK
- */
- public function enableSizeCheck() {
- wfDeprecated( __METHOD__, '1.24' );
- $this->checkingSize = true;
- }
-
- /**
- * Alias for self::setValue()
- *
- * @since 1.21 int $flags replaced boolean $override
- * @deprecated since 1.25, use self::setValue() instead
- * @param array $arr To add $value to
- * @param string $name Index of $arr to add $value at
- * @param mixed $value
- * @param int $flags Zero or more OR-ed flags like OVERRIDE | ADD_ON_TOP.
- * This parameter used to be boolean, and the value of OVERRIDE=1 was
- * specifically chosen so that it would be backwards compatible with the
- * new method signature.
- */
- public static function setElement( &$arr, $name, $value, $flags = 0 ) {
- wfDeprecated( __METHOD__, '1.25' );
- self::setValue( $arr, $name, $value, $flags );
- }
-
- /**
- * Adds a content element to an array.
- * Use this function instead of hardcoding the '*' element.
- * @deprecated since 1.25, use self::setContentValue() instead
- * @param array $arr To add the content element to
- * @param mixed $value
- * @param string $subElemName When present, content element is created
- * as a sub item of $arr. Use this parameter to create elements in
- * format "<elem>text</elem>" without attributes.
- */
- public static function setContent( &$arr, $value, $subElemName = null ) {
- wfDeprecated( __METHOD__, '1.25' );
- if ( is_array( $value ) ) {
- throw new InvalidArgumentException( __METHOD__ . ': Bad parameter' );
- }
- if ( is_null( $subElemName ) ) {
- self::setContentValue( $arr, 'content', $value );
- } else {
- if ( !isset( $arr[$subElemName] ) ) {
- $arr[$subElemName] = [];
- }
- self::setContentValue( $arr[$subElemName], 'content', $value );
- }
- }
-
- /**
- * Set indexed tag name on all subarrays of $arr
- *
- * Does not set the tag name for $arr itself.
- *
- * @deprecated since 1.25, use self::setIndexedTagNameRecursive() instead
- * @param array $arr
- * @param string $tag Tag name
- */
- public function setIndexedTagName_recursive( &$arr, $tag ) {
- wfDeprecated( __METHOD__, '1.25' );
- if ( !is_array( $arr ) ) {
- return;
- }
- if ( !is_string( $tag ) ) {
- throw new InvalidArgumentException( 'Bad tag name' );
- }
- foreach ( $arr as $k => &$v ) {
- if ( !self::isMetadataKey( $k ) && is_array( $v ) ) {
- $v[self::META_INDEXED_TAG_NAME] = $tag;
- $this->setIndexedTagName_recursive( $v, $tag );
- }
- }
- }
-
- /**
- * Alias for self::addIndexedTagName()
- * @deprecated since 1.25, use $this->addIndexedTagName() instead
- * @param array $path Path to the array, like addValue()'s $path
- * @param string $tag
- */
- public function setIndexedTagName_internal( $path, $tag ) {
- wfDeprecated( __METHOD__, '1.25' );
- $this->addIndexedTagName( $path, $tag );
- }
-
- /**
- * Alias for self::addParsedLimit()
- * @deprecated since 1.25, use $this->addParsedLimit() instead
- * @param string $moduleName
- * @param int $limit
- */
- public function setParsedLimit( $moduleName, $limit ) {
- wfDeprecated( __METHOD__, '1.25' );
- $this->addParsedLimit( $moduleName, $limit );
- }
-
- /**
- * Set the ApiMain for use by $this->beginContinuation()
- * @since 1.25
- * @deprecated for backwards compatibility only, do not use
- * @param ApiMain $main
- */
- public function setMainForContinuation( ApiMain $main ) {
- $this->mainForContinuation = $main;
- }
-
- /**
- * Parse a 'continue' parameter and return status information.
- *
- * This must be balanced by a call to endContinuation().
- *
- * @since 1.24
- * @deprecated since 1.25, use ApiContinuationManager instead
- * @param string|null $continue
- * @param ApiBase[] $allModules
- * @param array $generatedModules
- * @return array
- */
- public function beginContinuation(
- $continue, array $allModules = [], array $generatedModules = []
- ) {
- wfDeprecated( __METHOD__, '1.25' );
- if ( $this->mainForContinuation->getContinuationManager() ) {
- throw new UnexpectedValueException(
- __METHOD__ . ': Continuation already in progress from ' .
- $this->mainForContinuation->getContinuationManager()->getSource()
- );
- }
-
- // Ugh. If $continue doesn't match that in the request, temporarily
- // replace the request when creating the ApiContinuationManager.
- if ( $continue === null ) {
- $continue = '';
- }
- if ( $this->mainForContinuation->getVal( 'continue', '' ) !== $continue ) {
- $oldCtx = $this->mainForContinuation->getContext();
- $newCtx = new DerivativeContext( $oldCtx );
- $newCtx->setRequest( new DerivativeRequest(
- $oldCtx->getRequest(),
- [ 'continue' => $continue ] + $oldCtx->getRequest()->getValues(),
- $oldCtx->getRequest()->wasPosted()
- ) );
- $this->mainForContinuation->setContext( $newCtx );
- $reset = new ScopedCallback(
- [ $this->mainForContinuation, 'setContext' ],
- [ $oldCtx ]
- );
- }
- $manager = new ApiContinuationManager(
- $this->mainForContinuation, $allModules, $generatedModules
- );
- $reset = null;
-
- $this->mainForContinuation->setContinuationManager( $manager );
-
- return [
- $manager->isGeneratorDone(),
- $manager->getRunModules(),
- ];
- }
-
- /**
- * @since 1.24
- * @deprecated since 1.25, use ApiContinuationManager instead
- * @param ApiBase $module
- * @param string $paramName
- * @param string|array $paramValue
- */
- public function setContinueParam( ApiBase $module, $paramName, $paramValue ) {
- wfDeprecated( __METHOD__, '1.25' );
- if ( $this->mainForContinuation->getContinuationManager() ) {
- $this->mainForContinuation->getContinuationManager()->addContinueParam(
- $module, $paramName, $paramValue
- );
- }
- }
-
- /**
- * @since 1.24
- * @deprecated since 1.25, use ApiContinuationManager instead
- * @param ApiBase $module
- * @param string $paramName
- * @param string|array $paramValue
- */
- public function setGeneratorContinueParam( ApiBase $module, $paramName, $paramValue ) {
- wfDeprecated( __METHOD__, '1.25' );
- if ( $this->mainForContinuation->getContinuationManager() ) {
- $this->mainForContinuation->getContinuationManager()->addGeneratorContinueParam(
- $module, $paramName, $paramValue
- );
- }
- }
-
- /**
- * Close continuation, writing the data into the result
- * @since 1.24
- * @deprecated since 1.25, use ApiContinuationManager instead
- * @param string $style 'standard' for the new style since 1.21, 'raw' for
- * the style used in 1.20 and earlier.
- */
- public function endContinuation( $style = 'standard' ) {
- wfDeprecated( __METHOD__, '1.25' );
- if ( !$this->mainForContinuation->getContinuationManager() ) {
- return;
- }
-
- if ( $style === 'raw' ) {
- $data = $this->mainForContinuation->getContinuationManager()->getRawContinuation();
- if ( $data ) {
- $this->addValue( null, 'query-continue', $data, self::ADD_ON_TOP | self::NO_SIZE_CHECK );
- }
- } else {
- $this->mainForContinuation->getContinuationManager()->setContinuationIntoResult( $this );
- }
- }
-
- /**
- * No-op, this is now checked on insert.
- * @deprecated since 1.25
- */
- public function cleanUpUTF8() {
- wfDeprecated( __METHOD__, '1.25' );
- }
-
- /**
- * Get the 'real' size of a result item. This means the strlen() of the item,
- * or the sum of the strlen()s of the elements if the item is an array.
- * @deprecated since 1.25, no external users known and there doesn't seem
- * to be any case for such use over just checking the return value from the
- * add/set methods.
- * @param mixed $value
- * @return int
- */
- public static function size( $value ) {
- wfDeprecated( __METHOD__, '1.25' );
- return self::valueSize( self::validateValue( $value ) );
- }
-
- /**
- * Converts a Status object to an array suitable for addValue
- * @deprecated since 1.25, use ApiErrorFormatter::arrayFromStatus()
- * @param Status $status
- * @param string $errorType
- * @return array
- */
- public function convertStatusToArray( $status, $errorType = 'error' ) {
- wfDeprecated( __METHOD__, '1.25' );
- return $this->errorFormatter->arrayFromStatus( $status, $errorType );
- }
-
- /**@}*/
}
/**
], ApiResult::addMetadataToResultVars( $arr ) );
}
- /**
- * @covers ApiResult
- */
- public function testDeprecatedFunctions() {
- // Ignore ApiResult deprecation warnings during this test
- set_error_handler( function ( $errno, $errstr ) use ( &$warnings ) {
- if ( preg_match( '/Use of ApiResult::\S+ was deprecated in MediaWiki \d+.\d+\./', $errstr ) ) {
- return true;
- }
- if ( preg_match( '/Use of ApiMain to ApiResult::__construct ' .
- 'was deprecated in MediaWiki \d+.\d+\./', $errstr ) ) {
- return true;
- }
- return false;
- } );
- $reset = new ScopedCallback( 'restore_error_handler' );
-
- $context = new DerivativeContext( RequestContext::getMain() );
- $context->setConfig( new HashConfig( [
- 'APIModules' => [],
- 'APIFormatModules' => [],
- 'APIMaxResultSize' => 42,
- ] ) );
- $main = new ApiMain( $context );
- $result = TestingAccessWrapper::newFromObject( new ApiResult( $main ) );
- $this->assertSame( 42, $result->maxSize );
- $this->assertSame( $main->getErrorFormatter(), $result->errorFormatter );
- $this->assertSame( $main, $result->mainForContinuation );
-
- $result = new ApiResult( 8388608 );
-
- $result->addContentValue( null, 'test', 'content' );
- $result->addContentValue( [ 'foo', 'bar' ], 'test', 'content' );
- $result->addIndexedTagName( null, 'itn' );
- $result->addSubelementsList( null, [ 'sub' ] );
- $this->assertSame( [
- 'foo' => [
- 'bar' => [
- '*' => 'content',
- ],
- ],
- '*' => 'content',
- ], $result->getData() );
-
- $arr = [];
- ApiResult::setContent( $arr, 'value' );
- ApiResult::setContent( $arr, 'value2', 'foobar' );
- $this->assertSame( [
- ApiResult::META_CONTENT => 'content',
- 'content' => 'value',
- 'foobar' => [
- ApiResult::META_CONTENT => 'content',
- 'content' => 'value2',
- ],
- ], $arr );
-
- $result = new ApiResult( 3 );
- $formatter = new ApiErrorFormatter_BackCompat( $result );
- $result->setErrorFormatter( $formatter );
- $result->disableSizeCheck();
- $this->assertTrue( $result->addValue( null, 'foo', '1234567890' ) );
- $result->enableSizeCheck();
- $this->assertSame( 0, $result->getSize() );
- $this->assertFalse( $result->addValue( null, 'foo', '1234567890' ) );
-
- $arr = [ 'foo' => [ 'bar' => 1 ] ];
- $result->setIndexedTagName_recursive( $arr, 'itn' );
- $this->assertSame( [
- 'foo' => [
- 'bar' => 1,
- ApiResult::META_INDEXED_TAG_NAME => 'itn'
- ],
- ], $arr );
-
- $status = Status::newGood();
- $status->fatal( 'parentheses', '1' );
- $status->fatal( 'parentheses', '2' );
- $status->warning( 'parentheses', '3' );
- $status->warning( 'parentheses', '4' );
- $this->assertSame( [
- [
- 'type' => 'error',
- 'message' => 'parentheses',
- 'params' => [
- 0 => '1',
- ApiResult::META_INDEXED_TAG_NAME => 'param',
- ],
- ],
- [
- 'type' => 'error',
- 'message' => 'parentheses',
- 'params' => [
- 0 => '2',
- ApiResult::META_INDEXED_TAG_NAME => 'param',
- ],
- ],
- ApiResult::META_INDEXED_TAG_NAME => 'error',
- ], $result->convertStatusToArray( $status, 'error' ) );
- $this->assertSame( [
- [
- 'type' => 'warning',
- 'message' => 'parentheses',
- 'params' => [
- 0 => '3',
- ApiResult::META_INDEXED_TAG_NAME => 'param',
- ],
- ],
- [
- 'type' => 'warning',
- 'message' => 'parentheses',
- 'params' => [
- 0 => '4',
- ApiResult::META_INDEXED_TAG_NAME => 'param',
- ],
- ],
- ApiResult::META_INDEXED_TAG_NAME => 'warning',
- ], $result->convertStatusToArray( $status, 'warning' ) );
- }
-
- /**
- * @covers ApiResult
- */
- public function testDeprecatedContinuation() {
- // Ignore ApiResult deprecation warnings during this test
- set_error_handler( function ( $errno, $errstr ) use ( &$warnings ) {
- if ( preg_match( '/Use of ApiResult::\S+ was deprecated in MediaWiki \d+.\d+\./', $errstr ) ) {
- return true;
- }
- return false;
- } );
-
- $reset = new ScopedCallback( 'restore_error_handler' );
- $allModules = [
- new MockApiQueryBase( 'mock1' ),
- new MockApiQueryBase( 'mock2' ),
- new MockApiQueryBase( 'mocklist' ),
- ];
- $generator = new MockApiQueryBase( 'generator' );
-
- $main = new ApiMain( RequestContext::getMain() );
- $result = new ApiResult( 8388608 );
- $result->setMainForContinuation( $main );
- $ret = $result->beginContinuation( null, $allModules, [ 'mock1', 'mock2' ] );
- $this->assertSame( [ false, $allModules ], $ret );
- $result->setContinueParam( $allModules[0], 'm1continue', [ 1, 2 ] );
- $result->setContinueParam( $allModules[2], 'mlcontinue', 2 );
- $result->setGeneratorContinueParam( $generator, 'gcontinue', 3 );
- $result->endContinuation( 'raw' );
- $result->endContinuation( 'standard' );
- $this->assertSame( [
- 'mlcontinue' => 2,
- 'm1continue' => '1|2',
- 'continue' => '||mock2',
- ], $result->getResultData( 'continue' ) );
- $this->assertSame( null, $result->getResultData( 'batchcomplete' ) );
- $this->assertSame( [
- 'mock1' => [ 'm1continue' => '1|2' ],
- 'mocklist' => [ 'mlcontinue' => 2 ],
- 'generator' => [ 'gcontinue' => 3 ],
- ], $result->getResultData( 'query-continue' ) );
- $main->setContinuationManager( null );
-
- $result = new ApiResult( 8388608 );
- $result->setMainForContinuation( $main );
- $ret = $result->beginContinuation( null, $allModules, [ 'mock1', 'mock2' ] );
- $this->assertSame( [ false, $allModules ], $ret );
- $result->setContinueParam( $allModules[0], 'm1continue', [ 1, 2 ] );
- $result->setGeneratorContinueParam( $generator, 'gcontinue', [ 3, 4 ] );
- $result->endContinuation( 'raw' );
- $result->endContinuation( 'standard' );
- $this->assertSame( [
- 'm1continue' => '1|2',
- 'continue' => '||mock2|mocklist',
- ], $result->getResultData( 'continue' ) );
- $this->assertSame( null, $result->getResultData( 'batchcomplete' ) );
- $this->assertSame( [
- 'mock1' => [ 'm1continue' => '1|2' ],
- 'generator' => [ 'gcontinue' => '3|4' ],
- ], $result->getResultData( 'query-continue' ) );
- $main->setContinuationManager( null );
-
- $result = new ApiResult( 8388608 );
- $result->setMainForContinuation( $main );
- $ret = $result->beginContinuation( null, $allModules, [ 'mock1', 'mock2' ] );
- $this->assertSame( [ false, $allModules ], $ret );
- $result->setContinueParam( $allModules[2], 'mlcontinue', 2 );
- $result->setGeneratorContinueParam( $generator, 'gcontinue', 3 );
- $result->endContinuation( 'raw' );
- $result->endContinuation( 'standard' );
- $this->assertSame( [
- 'mlcontinue' => 2,
- 'gcontinue' => 3,
- 'continue' => 'gcontinue||',
- ], $result->getResultData( 'continue' ) );
- $this->assertSame( true, $result->getResultData( 'batchcomplete' ) );
- $this->assertSame( [
- 'mocklist' => [ 'mlcontinue' => 2 ],
- 'generator' => [ 'gcontinue' => 3 ],
- ], $result->getResultData( 'query-continue' ) );
- $main->setContinuationManager( null );
-
- $result = new ApiResult( 8388608 );
- $result->setMainForContinuation( $main );
- $ret = $result->beginContinuation( null, $allModules, [ 'mock1', 'mock2' ] );
- $this->assertSame( [ false, $allModules ], $ret );
- $result->setGeneratorContinueParam( $generator, 'gcontinue', 3 );
- $result->endContinuation( 'raw' );
- $result->endContinuation( 'standard' );
- $this->assertSame( [
- 'gcontinue' => 3,
- 'continue' => 'gcontinue||mocklist',
- ], $result->getResultData( 'continue' ) );
- $this->assertSame( true, $result->getResultData( 'batchcomplete' ) );
- $this->assertSame( [
- 'generator' => [ 'gcontinue' => 3 ],
- ], $result->getResultData( 'query-continue' ) );
- $main->setContinuationManager( null );
-
- $result = new ApiResult( 8388608 );
- $result->setMainForContinuation( $main );
- $ret = $result->beginContinuation( null, $allModules, [ 'mock1', 'mock2' ] );
- $this->assertSame( [ false, $allModules ], $ret );
- $result->setContinueParam( $allModules[0], 'm1continue', [ 1, 2 ] );
- $result->setContinueParam( $allModules[2], 'mlcontinue', 2 );
- $result->endContinuation( 'raw' );
- $result->endContinuation( 'standard' );
- $this->assertSame( [
- 'mlcontinue' => 2,
- 'm1continue' => '1|2',
- 'continue' => '||mock2',
- ], $result->getResultData( 'continue' ) );
- $this->assertSame( null, $result->getResultData( 'batchcomplete' ) );
- $this->assertSame( [
- 'mock1' => [ 'm1continue' => '1|2' ],
- 'mocklist' => [ 'mlcontinue' => 2 ],
- ], $result->getResultData( 'query-continue' ) );
- $main->setContinuationManager( null );
-
- $result = new ApiResult( 8388608 );
- $result->setMainForContinuation( $main );
- $ret = $result->beginContinuation( null, $allModules, [ 'mock1', 'mock2' ] );
- $this->assertSame( [ false, $allModules ], $ret );
- $result->setContinueParam( $allModules[0], 'm1continue', [ 1, 2 ] );
- $result->endContinuation( 'raw' );
- $result->endContinuation( 'standard' );
- $this->assertSame( [
- 'm1continue' => '1|2',
- 'continue' => '||mock2|mocklist',
- ], $result->getResultData( 'continue' ) );
- $this->assertSame( null, $result->getResultData( 'batchcomplete' ) );
- $this->assertSame( [
- 'mock1' => [ 'm1continue' => '1|2' ],
- ], $result->getResultData( 'query-continue' ) );
- $main->setContinuationManager( null );
-
- $result = new ApiResult( 8388608 );
- $result->setMainForContinuation( $main );
- $ret = $result->beginContinuation( null, $allModules, [ 'mock1', 'mock2' ] );
- $this->assertSame( [ false, $allModules ], $ret );
- $result->setContinueParam( $allModules[2], 'mlcontinue', 2 );
- $result->endContinuation( 'raw' );
- $result->endContinuation( 'standard' );
- $this->assertSame( [
- 'mlcontinue' => 2,
- 'continue' => '-||mock1|mock2',
- ], $result->getResultData( 'continue' ) );
- $this->assertSame( true, $result->getResultData( 'batchcomplete' ) );
- $this->assertSame( [
- 'mocklist' => [ 'mlcontinue' => 2 ],
- ], $result->getResultData( 'query-continue' ) );
- $main->setContinuationManager( null );
-
- $result = new ApiResult( 8388608 );
- $result->setMainForContinuation( $main );
- $ret = $result->beginContinuation( null, $allModules, [ 'mock1', 'mock2' ] );
- $this->assertSame( [ false, $allModules ], $ret );
- $result->endContinuation( 'raw' );
- $result->endContinuation( 'standard' );
- $this->assertSame( null, $result->getResultData( 'continue' ) );
- $this->assertSame( true, $result->getResultData( 'batchcomplete' ) );
- $this->assertSame( null, $result->getResultData( 'query-continue' ) );
- $main->setContinuationManager( null );
-
- $result = new ApiResult( 8388608 );
- $result->setMainForContinuation( $main );
- $ret = $result->beginContinuation( '||mock2', $allModules, [ 'mock1', 'mock2' ] );
- $this->assertSame(
- [ false, array_values( array_diff_key( $allModules, [ 1 => 1 ] ) ) ],
- $ret
- );
- $main->setContinuationManager( null );
-
- $result = new ApiResult( 8388608 );
- $result->setMainForContinuation( $main );
- $ret = $result->beginContinuation( '-||', $allModules, [ 'mock1', 'mock2' ] );
- $this->assertSame(
- [ true, array_values( array_diff_key( $allModules, [ 0 => 0, 1 => 1 ] ) ) ],
- $ret
- );
- $main->setContinuationManager( null );
-
- $result = new ApiResult( 8388608 );
- $result->setMainForContinuation( $main );
- try {
- $result->beginContinuation( 'foo', $allModules, [ 'mock1', 'mock2' ] );
- $this->fail( 'Expected exception not thrown' );
- } catch ( UsageException $ex ) {
- $this->assertSame(
- 'Invalid continue param. You should pass the original value returned by the previous query',
- $ex->getMessage(),
- 'Expected exception'
- );
- }
- $main->setContinuationManager( null );
-
- $result = new ApiResult( 8388608 );
- $result->setMainForContinuation( $main );
- $result->beginContinuation( '||mock2', array_slice( $allModules, 0, 2 ),
- [ 'mock1', 'mock2' ] );
- try {
- $result->setContinueParam( $allModules[1], 'm2continue', 1 );
- $this->fail( 'Expected exception not thrown' );
- } catch ( UnexpectedValueException $ex ) {
- $this->assertSame(
- 'Module \'mock2\' was not supposed to have been executed, but it was executed anyway',
- $ex->getMessage(),
- 'Expected exception'
- );
- }
- try {
- $result->setContinueParam( $allModules[2], 'mlcontinue', 1 );
- $this->fail( 'Expected exception not thrown' );
- } catch ( UnexpectedValueException $ex ) {
- $this->assertSame(
- 'Module \'mocklist\' called ApiContinuationManager::addContinueParam ' .
- 'but was not passed to ApiContinuationManager::__construct',
- $ex->getMessage(),
- 'Expected exception'
- );
- }
- $main->setContinuationManager( null );
-
- }
-
public function testObjectSerialization() {
$arr = [];
ApiResult::setValue( $arr, 'foo', (object)[ 'a' => 1, 'b' => 2 ] );