<?php
/**
- * Created on Sep 4, 2006
- *
* Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
*
* This program is free software; you can redistribute it and/or modify
* List of available modules: action name => module class
*/
private static $Modules = [
- 'login' => 'ApiLogin',
- 'clientlogin' => 'ApiClientLogin',
- 'logout' => 'ApiLogout',
- 'createaccount' => 'ApiAMCreateAccount',
- 'linkaccount' => 'ApiLinkAccount',
- 'unlinkaccount' => 'ApiRemoveAuthenticationData',
- 'changeauthenticationdata' => 'ApiChangeAuthenticationData',
- 'removeauthenticationdata' => 'ApiRemoveAuthenticationData',
- 'resetpassword' => 'ApiResetPassword',
- 'query' => 'ApiQuery',
- 'expandtemplates' => 'ApiExpandTemplates',
- 'parse' => 'ApiParse',
- 'stashedit' => 'ApiStashEdit',
- 'opensearch' => 'ApiOpenSearch',
- 'feedcontributions' => 'ApiFeedContributions',
- 'feedrecentchanges' => 'ApiFeedRecentChanges',
- 'feedwatchlist' => 'ApiFeedWatchlist',
- 'help' => 'ApiHelp',
- 'paraminfo' => 'ApiParamInfo',
- 'rsd' => 'ApiRsd',
- 'compare' => 'ApiComparePages',
- 'tokens' => 'ApiTokens',
- 'checktoken' => 'ApiCheckToken',
- 'cspreport' => 'ApiCSPReport',
- 'validatepassword' => 'ApiValidatePassword',
+ 'login' => ApiLogin::class,
+ 'clientlogin' => ApiClientLogin::class,
+ 'logout' => ApiLogout::class,
+ 'createaccount' => ApiAMCreateAccount::class,
+ 'linkaccount' => ApiLinkAccount::class,
+ 'unlinkaccount' => ApiRemoveAuthenticationData::class,
+ 'changeauthenticationdata' => ApiChangeAuthenticationData::class,
+ 'removeauthenticationdata' => ApiRemoveAuthenticationData::class,
+ 'resetpassword' => ApiResetPassword::class,
+ 'query' => ApiQuery::class,
+ 'expandtemplates' => ApiExpandTemplates::class,
+ 'parse' => ApiParse::class,
+ 'stashedit' => ApiStashEdit::class,
+ 'opensearch' => ApiOpenSearch::class,
+ 'feedcontributions' => ApiFeedContributions::class,
+ 'feedrecentchanges' => ApiFeedRecentChanges::class,
+ 'feedwatchlist' => ApiFeedWatchlist::class,
+ 'help' => ApiHelp::class,
+ 'paraminfo' => ApiParamInfo::class,
+ 'rsd' => ApiRsd::class,
+ 'compare' => ApiComparePages::class,
+ 'tokens' => ApiTokens::class,
+ 'checktoken' => ApiCheckToken::class,
+ 'cspreport' => ApiCSPReport::class,
+ 'validatepassword' => ApiValidatePassword::class,
// Write modules
- 'purge' => 'ApiPurge',
- 'setnotificationtimestamp' => 'ApiSetNotificationTimestamp',
- 'rollback' => 'ApiRollback',
- 'delete' => 'ApiDelete',
- 'undelete' => 'ApiUndelete',
- 'protect' => 'ApiProtect',
- 'block' => 'ApiBlock',
- 'unblock' => 'ApiUnblock',
- 'move' => 'ApiMove',
- 'edit' => 'ApiEditPage',
- 'upload' => 'ApiUpload',
- 'filerevert' => 'ApiFileRevert',
- 'emailuser' => 'ApiEmailUser',
- 'watch' => 'ApiWatch',
- 'patrol' => 'ApiPatrol',
- 'import' => 'ApiImport',
- 'clearhasmsg' => 'ApiClearHasMsg',
- 'userrights' => 'ApiUserrights',
- 'options' => 'ApiOptions',
- 'imagerotate' => 'ApiImageRotate',
- 'revisiondelete' => 'ApiRevisionDelete',
- 'managetags' => 'ApiManageTags',
- 'tag' => 'ApiTag',
- 'mergehistory' => 'ApiMergeHistory',
- 'setpagelanguage' => 'ApiSetPageLanguage',
+ 'purge' => ApiPurge::class,
+ 'setnotificationtimestamp' => ApiSetNotificationTimestamp::class,
+ 'rollback' => ApiRollback::class,
+ 'delete' => ApiDelete::class,
+ 'undelete' => ApiUndelete::class,
+ 'protect' => ApiProtect::class,
+ 'block' => ApiBlock::class,
+ 'unblock' => ApiUnblock::class,
+ 'move' => ApiMove::class,
+ 'edit' => ApiEditPage::class,
+ 'upload' => ApiUpload::class,
+ 'filerevert' => ApiFileRevert::class,
+ 'emailuser' => ApiEmailUser::class,
+ 'watch' => ApiWatch::class,
+ 'patrol' => ApiPatrol::class,
+ 'import' => ApiImport::class,
+ 'clearhasmsg' => ApiClearHasMsg::class,
+ 'userrights' => ApiUserrights::class,
+ 'options' => ApiOptions::class,
+ 'imagerotate' => ApiImageRotate::class,
+ 'revisiondelete' => ApiRevisionDelete::class,
+ 'managetags' => ApiManageTags::class,
+ 'tag' => ApiTag::class,
+ 'mergehistory' => ApiMergeHistory::class,
+ 'setpagelanguage' => ApiSetPageLanguage::class,
];
/**
* List of available formats: format name => format class
*/
private static $Formats = [
- 'json' => 'ApiFormatJson',
- 'jsonfm' => 'ApiFormatJson',
- 'php' => 'ApiFormatPhp',
- 'phpfm' => 'ApiFormatPhp',
- 'xml' => 'ApiFormatXml',
- 'xmlfm' => 'ApiFormatXml',
- 'rawfm' => 'ApiFormatJson',
- 'none' => 'ApiFormatNone',
+ 'json' => ApiFormatJson::class,
+ 'jsonfm' => ApiFormatJson::class,
+ 'php' => ApiFormatPhp::class,
+ 'phpfm' => ApiFormatPhp::class,
+ 'xml' => ApiFormatXml::class,
+ 'xmlfm' => ApiFormatXml::class,
+ 'rawfm' => ApiFormatJson::class,
+ 'none' => ApiFormatNone::class,
];
/**
* Set the continuation manager
* @param ApiContinuationManager|null $manager
*/
- 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()
- );
- }
+ public function setContinuationManager( ApiContinuationManager $manager = null ) {
+ if ( $manager !== null && $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;
}
$this->setCacheMode( 'private' );
$response = $this->getRequest()->response();
- $headerStr = 'MediaWiki-API-Error: ' . join( ', ', $errCodes );
+ $headerStr = 'MediaWiki-API-Error: ' . implode( ', ', $errCodes );
$response->header( $headerStr );
// Reset and print just the error message
// None of the rest have any messages for non-error types
} elseif ( $e instanceof UsageException ) {
// User entered incorrect parameters - generate error response
- $data = MediaWiki\quietCall( [ $e, 'getMessageArray' ] );
+ $data = Wikimedia\quietCall( [ $e, 'getMessageArray' ] );
$code = $data['code'];
$info = $data['info'];
unset( $data['code'], $data['info'] );
// Instantiate the module requested by the user
$module = $this->mModuleMgr->getModule( $this->mAction, 'action' );
if ( $module === null ) {
+ // Probably can't happen
+ // @codeCoverageIgnoreStart
$this->dieWithError(
[ 'apierror-unknownaction', wfEscapeWikiText( $this->mAction ) ], 'unknown_action'
);
+ // @codeCoverageIgnoreEnd
}
$moduleParams = $module->extractRequestParams();
}
if ( !isset( $moduleParams['token'] ) ) {
+ // Probably can't happen
+ // @codeCoverageIgnoreStart
$module->dieWithError( [ 'apierror-missingparam', 'token' ] );
+ // @codeCoverageIgnoreEnd
}
$module->requirePostedParameters( [ 'token' ] );
$this->getRequest()->response()->statusHeader( 304 );
// Avoid outputting the compressed representation of a zero-length body
- MediaWiki\suppressWarnings();
+ Wikimedia\suppressWarnings();
ini_set( 'zlib.output_compression', 0 );
- MediaWiki\restoreWarnings();
+ Wikimedia\restoreWarnings();
wfClearOutputBuffers();
return false;
}
// Allow extensions to stop execution for arbitrary reasons.
- $message = false;
+ $message = 'hookaborted';
if ( !Hooks::run( 'ApiCheckCanExecute', [ $module, $user, &$message ] ) ) {
$this->dieWithError( $message );
}
/**
* Get a request value, and register the fact that it was used, for logging.
* @param string $name
- * @param mixed $default
- * @return mixed
+ * @param string|null $default
+ * @return string|null
*/
public function getVal( $name, $default = null ) {
$this->mParamsUsed[$name] = true;