<?php
/**
- * API for MediaWiki 1.8+
+ *
*
* Created on Sep 4, 2006
*
'feedwatchlist' => 'ApiFeedWatchlist',
'help' => 'ApiHelp',
'paraminfo' => 'ApiParamInfo',
+ 'rsd' => 'ApiRsd',
+ 'compare' => 'ApiComparePages',
// Write modules
'purge' => 'ApiPurge',
'move' => 'ApiMove',
'edit' => 'ApiEditPage',
'upload' => 'ApiUpload',
+ 'filerevert' => 'ApiFileRevert',
'emailuser' => 'ApiEmailUser',
'watch' => 'ApiWatch',
'patrol' => 'ApiPatrol',
)
);
- private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames;
+ /**
+ * @var ApiFormatBase
+ */
+ private $mPrinter;
+
+ private $mModules, $mModuleNames, $mFormats, $mFormatNames;
private $mResult, $mAction, $mShowVersions, $mEnableWrite, $mRequest;
private $mInternalMode, $mSquidMaxage, $mModule;
/**
* Return true if the API was started by other PHP code using FauxRequest
+ * @return bool
*/
public function isInternalMode() {
return $this->mInternalMode;
/**
* Get the API module object. Only works after executeAction()
+ *
+ * @return ApiBase
*/
public function getModule() {
return $this->mModule;
/**
* Set how long the response should be cached.
+ *
+ * @param $maxage
*/
public function setCacheMaxAge( $maxage ) {
$this->setCacheControl( array(
}
/**
- * @deprecated Private caching is now the default, so there is usually no
+ * @deprecated since 1.17 Private caching is now the default, so there is usually no
* need to call this function. If there is a need, you can use
* $this->setCacheMode('private')
*/
* given URL must either always or never call this function; if it sometimes does and
* sometimes doesn't, stuff will break.
*
- * @deprecated Use setCacheMode( 'anon-public-user-private' )
+ * @deprecated since 1.17 Use setCacheMode( 'anon-public-user-private' )
*/
public function setVaryCookie() {
$this->setCacheMode( 'anon-public-user-private' );
/**
* Create an instance of an output formatter by its name
+ *
+ * @param $format string
+ *
+ * @return ApiFormatBase
*/
public function createPrinterByName( $format ) {
if ( !isset( $this->mFormats[$format] ) ) {
/**
* Replace the result data with the information about an exception.
* Returns the error code
+ * @param $e Exception
+ * @return string
*/
protected function substituteResultWithError( $e ) {
// Printer may not be initialized if the extractRequestParams() fails for the main module
}
if ( $e instanceof UsageException ) {
- //
// User entered incorrect parameters - print usage screen
- //
$errMessage = $e->getMessageArray();
// Only print the help message when this is for the developer, not runtime
} else {
global $wgShowSQLErrors, $wgShowExceptionDetails;
- //
// Something is seriously wrong
- //
if ( ( $e instanceof DBQueryError ) && !$wgShowSQLErrors ) {
$info = 'Database query error';
} else {
/**
* Set up for the execution.
+ * @return array
*/
protected function setupExecuteAction() {
// First add the id to the top element
$this->dieUsageMsg( array( 'missingparam', 'token' ) );
} else {
global $wgUser;
- if ( !$wgUser->matchEditToken( $moduleParams['token'], $salt ) ) {
+ if ( !$wgUser->matchEditToken( $moduleParams['token'], $salt, $this->getMain()->getRequest() ) ) {
$this->dieUsageMsg( array( 'sessionfailure' ) );
}
}
/**
* Print results using the current printer
+ *
+ * @param $isError bool
*/
protected function printResult( $isError ) {
$this->getResult()->cleanUpUTF8();
$printer->profileOut();
}
+ /**
+ * @return bool
+ */
public function isReadMode() {
return false;
}
/**
* See ApiBase for description.
+ *
+ * @return array
*/
public function getAllowedParams() {
return array(
/**
* See ApiBase for description.
+ *
+ * @return array
*/
public function getParamDescription() {
return array(
/**
* See ApiBase for description.
+ *
+ * @return array
*/
public function getDescription() {
return array(
'',
'',
- '******************************************************************************************',
- '** **',
- '** This is an auto-generated MediaWiki API documentation page **',
- '** **',
- '** Documentation and Examples: **',
- '** http://www.mediawiki.org/wiki/API **',
- '** **',
- '******************************************************************************************',
+ '**********************************************************************************************************',
+ '** **',
+ '** This is an auto-generated MediaWiki API documentation page **',
+ '** **',
+ '** Documentation and Examples: **',
+ '** http://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.',
);
}
+ /**
+ * @return array
+ */
public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'readonlytext' ),
/**
* Returns an array of strings with credits for the API
+ * @return array
*/
protected function getCredits() {
return array(
'API developers:',
- ' Roan Kattouw <Firstname>.<Lastname>@home.nl (lead developer Sep 2007-present)',
+ ' Roan Kattouw <Firstname>.<Lastname>@gmail.com (lead developer Sep 2007-present)',
' Victor Vasiliev - vasilvv at gee mail dot com',
' Bryan Tong Minh - bryan . tongminh @ gmail . com',
' Sam Reed - sam @ reedyboy . net',
'or file a bug report at http://bugzilla.wikimedia.org/'
);
}
+
/**
* Sets whether the pretty-printer should format *bold* and $italics$
+ *
+ * @param $help bool
*/
public function setHelp( $help = true ) {
$this->mPrinter->setHelp( $help );
/**
* Override the parent to generate help messages for all available modules.
+ *
+ * @return string
*/
public function makeHelpMsg() {
- global $wgMemc, $wgAPICacheHelp, $wgAPICacheHelpTimeout;
+ global $wgMemc, $wgAPICacheHelpTimeout;
$this->setHelp();
// Get help text from cache if present
$key = wfMemcKey( 'apihelp', $this->getModuleName(),
SpecialVersion::getVersion( 'nodb' ) .
$this->getMain()->getShowVersions() );
- if ( $wgAPICacheHelp ) {
+ if ( $wgAPICacheHelpTimeout > 0 ) {
$cached = $wgMemc->get( $key );
if ( $cached ) {
return $cached;
}
}
$retval = $this->reallyMakeHelpMsg();
- if ( $wgAPICacheHelp ) {
+ if ( $wgAPICacheHelpTimeout > 0 ) {
$wgMemc->set( $key, $retval, $wgAPICacheHelpTimeout );
}
return $retval;
}
+ /**
+ * @return mixed|string
+ */
public function reallyMakeHelpMsg() {
$this->setHelp();
// Use parent to make default message for the main module
$msg = parent::makeHelpMsg();
- $astriks = str_repeat( '*** ', 10 );
+ $astriks = str_repeat( '*** ', 14 );
$msg .= "\n\n$astriks Modules $astriks\n\n";
- foreach ( $this->mModules as $moduleName => $unused ) {
+ foreach ( array_keys( $this->mModules ) as $moduleName ) {
$module = new $this->mModules[$moduleName] ( $this, $moduleName );
$msg .= self::makeHelpMsgHeader( $module, 'action' );
$msg2 = $module->makeHelpMsg();
}
$msg .= "\n$astriks Formats $astriks\n\n";
- foreach ( $this->mFormats as $formatName => $unused ) {
+ foreach ( array_keys( $this->mFormats ) as $formatName ) {
$module = $this->createPrinterByName( $formatName );
$msg .= self::makeHelpMsgHeader( $module, 'format' );
$msg2 = $module->makeHelpMsg();
return $msg;
}
+ /**
+ * @param $module ApiBase
+ * @param $paramName String What type of request is this? e.g. action, query, list, prop, meta, format
+ * @return string
+ */
public static function makeHelpMsgHeader( $module, $paramName ) {
$modulePrefix = $module->getModulePrefix();
if ( strval( $modulePrefix ) !== '' ) {
return "* $paramName={$module->getModuleName()} $modulePrefix*";
}
- private $mIsBot = null;
- private $mIsSysop = null;
private $mCanApiHighLimits = null;
- /**
- * Returns true if the currently logged in user is a bot, false otherwise
- * OBSOLETE, use canApiHighLimits() instead
- */
- public function isBot() {
- if ( !isset( $this->mIsBot ) ) {
- global $wgUser;
- $this->mIsBot = $wgUser->isAllowed( 'bot' );
- }
- return $this->mIsBot;
- }
-
- /**
- * Similar to isBot(), this method returns true if the logged in user is
- * a sysop, and false if not.
- * OBSOLETE, use canApiHighLimits() instead
- */
- public function isSysop() {
- if ( !isset( $this->mIsSysop ) ) {
- global $wgUser;
- $this->mIsSysop = in_array( 'sysop', $wgUser->getGroups() );
- }
-
- return $this->mIsSysop;
- }
-
/**
* Check whether the current user is allowed to use high limits
* @return bool
/**
* Returns the version information of this file, plus it includes
* the versions for all files that are not callable proper API modules
+ *
+ * @return array
*/
public function getVersion() {
- $vers = array ();
+ $vers = array();
$vers[] = 'MediaWiki: ' . SpecialVersion::getVersion() . "\n http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/";
$vers[] = __CLASS__ . ': $Id$';
$vers[] = ApiBase::getBaseVersion();
* Add or overwrite an output format for this ApiMain. Intended for use by extending
* classes who wish to add to or modify current formatters.
*
- * @param $fmtName The identifier for this format.
- * @param $fmtClass The class implementing this format.
+ * @param $fmtName string The identifier for this format.
+ * @param $fmtClass ApiFormatBase The class implementing this format.
*/
protected function addFormat( $fmtName, $fmtClass ) {
$this->mFormats[$fmtName] = $fmtClass;
/**
* Get the array mapping module names to class names
+ * @return array
*/
function getModules() {
return $this->mModules;
}
+
+ /**
+ * Returns the list of supported formats in form ( 'format' => 'ClassName' )
+ *
+ * @since 1.18
+ * @return array
+ */
+ public function getFormats() {
+ return $this->mFormats;
+ }
}
/**