MediaWiki  1.23.14
ApiMain Class Reference

This is the main API class, used for both external and internal processing. More...

Inheritance diagram for ApiMain:
Collaboration diagram for ApiMain:

Public Member Functions

 __construct ( $context=null, $enableWrite=false)
 Constructs an instance of ApiMain that utilizes the module and format specified by $request. More...
 
 canApiHighLimits ()
 Check whether the current user is allowed to use high limits. More...
 
 createPrinterByName ( $format)
 Create an instance of an output formatter by its name. More...
 
 execute ()
 Execute api request. More...
 
 getAllowedParams ()
 See ApiBase for description. More...
 
 getCheck ( $name)
 Get a boolean request value, and register the fact that the parameter was used, for logging. More...
 
 getDescription ()
 See ApiBase for description. More...
 
 getFormats ()
 Returns the list of supported formats in form ( 'format' => 'ClassName' ) More...
 
 getModule ()
 Get the API module object. More...
 
 getModuleManager ()
 Overrides to return this instance's module manager. More...
 
 getModules ()
 Get the array mapping module names to class names. More...
 
 getParamDescription ()
 See ApiBase for description. More...
 
 getPossibleErrors ()
 
 getPrinter ()
 Get the result formatter object. More...
 
 getResult ()
 Get the ApiResult object associated with current request. More...
 
 getShowVersions ()
 Check whether the user wants us to show version information in the API help. More...
 
 getUpload ( $name)
 Get a request upload, and register the fact that it was used, for logging. More...
 
 getVal ( $name, $default=null)
 Get a request value, and register the fact that it was used, for logging. More...
 
 isInternalMode ()
 Return true if the API was started by other PHP code using FauxRequest. More...
 
 isReadMode ()
 
 lacksSameOriginSecurity ()
 Get the security flag for the current request. More...
 
 makeHelpMsg ()
 Override the parent to generate help messages for all available modules. More...
 
 reallyMakeHelpMsg ()
 
 setCacheControl ( $directives)
 Set directives (key/value pairs) for the Cache-Control header. More...
 
 setCacheMaxAge ( $maxage)
 Set how long the response should be cached. More...
 
 setCacheMode ( $mode)
 Set the type of caching headers which will be sent. More...
 
 setHelp ( $help=true)
 Sets whether the pretty-printer should format bold and $italics$. More...
 
- Public Member Functions inherited from ApiBase
 __construct ( $mainModule, $moduleName, $modulePrefix='')
 Constructor. More...
 
 createContext ()
 Create a new RequestContext object to use e.g. More...
 
 dieReadOnly ()
 Helper function for readonly errors. More...
 
 dieStatus ( $status)
 Throw a UsageException based on the errors in the Status object. More...
 
 dieUsage ( $description, $errorCode, $httpRespCode=0, $extradata=null)
 Throw a UsageException, which will (if uncaught) call the main module's error handler and die with an error message. More...
 
 dieUsageMsg ( $error)
 Output the error message related to a certain array. More...
 
 dieUsageMsgOrDebug ( $error)
 Will only set a warning instead of failing if the global $wgDebugAPI is set to true. More...
 
 encodeParamName ( $paramName)
 This method mangles parameter name based on the prefix supplied to the constructor. More...
 
 extractRequestParams ( $parseLimit=true)
 Using getAllowedParams(), this function makes an array of the values provided by the user, with key being the name of the variable, and value - validated value from user or default. More...
 
 getCustomPrinter ()
 If the module may only be used with a certain format module, it should override this method to return an instance of that formatter. More...
 
 getErrorFromStatus ( $status)
 Get error (as code, string) from a Status object. More...
 
 getFinalDescription ()
 Get final module description, after hooks have had a chance to tweak it as needed. More...
 
 getFinalParamDescription ()
 Get final parameter descriptions, after hooks have had a chance to tweak it as needed. More...
 
 getFinalParams ( $flags=0)
 Get final list of parameters, after hooks have had a chance to tweak it as needed. More...
 
 getFinalPossibleErrors ()
 Get final list of possible errors, after hooks have had a chance to tweak it as needed. More...
 
 getFinalResultProperties ()
 Get final possible result properties, after hooks have had a chance to tweak it as needed. More...
 
 getHelpUrls ()
 
 getMain ()
 Get the main module. More...
 
 getModuleName ()
 Get the name of the module being executed by this instance. More...
 
 getModulePrefix ()
 Get parameter prefix (usually two letters or an empty string). More...
 
 getModuleProfileName ( $db=false)
 Get the name of the module as shown in the profiler log. More...
 
 getProfileDBTime ()
 Total time the module used the database. More...
 
 getProfileTime ()
 Total time the module was executed. More...
 
 getRequireAtLeastOneParameterErrorMessages ( $params)
 Generates the possible errors requireAtLeastOneParameter() can die with. More...
 
 getRequireMaxOneParameterErrorMessages ( $params)
 Generates the possible error requireMaxOneParameter() can die with. More...
 
 getRequireOnlyOneParameterErrorMessages ( $params)
 Generates the possible errors requireOnlyOneParameter() can die with. More...
 
 getResultData ()
 Get the result data array (read-only) More...
 
 getTitleOrPageId ( $params, $load=false)
 
 getTitleOrPageIdErrorMessage ()
 
 getTokenSalt ()
 Returns the token salt if there is one, '' if the module doesn't require a salt, else false if the module doesn't need a token You have also to override needsToken() Value is passed to User::getEditToken. More...
 
 getVersion ()
 Returns a string that identifies the version of the extending class. More...
 
 getWatchlistUser ( $params)
 Gets the user for whom to get the watchlist. More...
 
 isMain ()
 Returns true if this module is the main module ($this === $this->mMainModule), false otherwise. More...
 
 isWriteMode ()
 Indicates whether this module requires write mode. More...
 
 makeHelpMsgParameters ()
 Generates the parameter descriptions for this module, to be displayed in the module's help. More...
 
 mustBePosted ()
 Indicates whether this module must be called with a POST request. More...
 
 needsToken ()
 Returns whether this module requires a token to execute It is used to show possible errors in action=paraminfo see bug 25248. More...
 
 parseErrors ( $errors)
 Parses a list of errors into a standardised format. More...
 
 parseMsg ( $error)
 Return the error message related to a certain array. More...
 
 profileDBIn ()
 Start module profiling. More...
 
 profileDBOut ()
 End database profiling. More...
 
 profileIn ()
 Start module profiling. More...
 
 profileOut ()
 End module profiling. More...
 
 requireAtLeastOneParameter ( $params)
 Die if none of a certain set of parameters is set and not false. More...
 
 requireMaxOneParameter ( $params)
 Die if more than one of a certain set of parameters is set and not false. More...
 
 requireOnlyOneParameter ( $params)
 Die if none or more than one of a certain set of parameters is set and not false. More...
 
 safeProfileOut ()
 When modules crash, sometimes it is needed to do a profileOut() regardless of the profiling state the module was in. More...
 
 setWarning ( $warning)
 Set warning section for this module. More...
 
 shouldCheckMaxlag ()
 Indicates if this module needs maxlag to be checked. More...
 
 validateLimit ( $paramName, &$value, $min, $max, $botMax=null, $enforceLimits=false)
 Validate the value against the minimum and user/bot maximum limits. More...
 
 validateTimestamp ( $value, $encParamName)
 Validate and normalize of parameters of type 'timestamp'. More...
 
- Public Member Functions inherited from ContextSource
 canUseWikiPage ()
 Check whether a WikiPage object can be get with getWikiPage(). More...
 
 exportSession ()
 Export the resolved user IP, HTTP headers, user ID, and session ID. More...
 
 getConfig ()
 Get the Config object. More...
 
 getContext ()
 Get the RequestContext object. More...
 
 getLang ()
 Get the Language object. More...
 
 getLanguage ()
 Get the Language object. More...
 
 getOutput ()
 Get the OutputPage object. More...
 
 getRequest ()
 Get the WebRequest object. More...
 
 getSkin ()
 Get the Skin object. More...
 
 getTitle ()
 Get the Title object. More...
 
 getUser ()
 Get the User object. More...
 
 getWikiPage ()
 Get the WikiPage object. More...
 
 msg ()
 Get a Message object with context set Parameters are the same as wfMessage() More...
 
 setContext (IContextSource $context)
 Set the IContextSource object. More...
 

Static Public Member Functions

static handleApiBeforeMainException (Exception $e)
 Handle an exception from the ApiBeforeMain hook. More...
 
static makeHelpMsgHeader ( $module, $paramName)
 
- Static Public Member Functions inherited from ApiBase
static debugPrint ( $value, $name='unknown', $backtrace=false)
 Debugging function that prints a value and an optional backtrace. More...
 
static truncateArray (&$arr, $limit)
 Truncate an array to a certain length. More...
 

Public Attributes

 $mModule
 
 $mResult
 
 $mSquidMaxage
 
const API_DEFAULT_FORMAT = 'xmlfm'
 When no format parameter is given, this format will be used. More...
 
- Public Attributes inherited from ApiBase
 $mDBTime = 0
 
 $mModuleName
 
 $mModulePrefix
 
 $mModuleTime = 0
 
const GET_VALUES_FOR_HELP = 1
 getAllowedParams() flag: When set, the result could take longer to generate, but should be more thorough. More...
 
const LIMIT_BIG1 = 500
 
const LIMIT_BIG2 = 5000
 
const LIMIT_SML1 = 50
 
const LIMIT_SML2 = 500
 
const PARAM_ALLOW_DUPLICATES = 6
 
const PARAM_DEPRECATED = 7
 
const PARAM_DFLT = 0
 
const PARAM_ISMULTI = 1
 
const PARAM_MAX = 3
 
const PARAM_MAX2 = 4
 
const PARAM_MIN = 5
 
const PARAM_RANGE_ENFORCE = 9
 
const PARAM_REQUIRED = 8
 
const PARAM_TYPE = 2
 
const PROP_LIST = 'LIST'
 
const PROP_NULLABLE = 1
 
const PROP_ROOT = 'ROOT'
 
const PROP_TYPE = 0
 

Protected Member Functions

 addFormat ( $name, $class)
 Add or overwrite an output format for this ApiMain. More...
 
 addModule ( $name, $class)
 Add or overwrite a module in this ApiMain instance. More...
 
 checkAsserts ( $params)
 Check asserts of the user's rights. More...
 
 checkExecutePermissions ( $module)
 Check for sufficient permissions to execute. More...
 
 checkMaxLag ( $module, $params)
 Check the max lag if necessary. More...
 
 encodeRequestLogValue ( $s)
 Encode a value in a format suitable for a space-separated log line. More...
 
 executeAction ()
 Execute the actual module, without any error handling. More...
 
 executeActionWithErrorHandling ()
 Execute an action, and in case of an error, erase whatever partial results have been accumulated, and replace it with an error message and a help screen. More...
 
 getCredits ()
 Returns an array of strings with credits for the API. More...
 
 getParamsUsed ()
 Get the request parameters used in the course of the preceding execute() request. More...
 
 handleCORS ()
 Check the &origin= query parameter against the Origin: HTTP header and respond appropriately. More...
 
 handleException (Exception $e)
 Handle an exception as an API response. More...
 
 logRequest ( $time)
 Log the preceding request. More...
 
 printResult ( $isError)
 Print results using the current printer. More...
 
 reportUnusedParams ()
 Report unused parameters, so the client gets a hint in case it gave us parameters we don't know, for example in case of spelling mistakes or a missing 'g' prefix for generators. More...
 
 sendCacheHeaders ()
 
 setupExecuteAction ()
 Set up for the execution. More...
 
 setupExternalResponse ( $module, $params)
 Check POST for external response and setup result printer. More...
 
 setupModule ()
 Set up the module for response. More...
 
 substituteResultWithError ( $e)
 Replace the result data with the information about an exception. More...
 
- Protected Member Functions inherited from ApiBase
 dieContinueUsageIf ( $condition)
 Die with the $prefix. More...
 
 getDB ()
 Gets a default slave database connection object. More...
 
 getExamples ()
 Returns usage examples for this module. More...
 
 getParameter ( $paramName, $parseLimit=true)
 Get a value for the given parameter. More...
 
 getParameterFromSettings ( $paramName, $paramSettings, $parseLimit)
 Using the settings determine the value for the given parameter. More...
 
 getResultProperties ()
 Returns possible properties in the result, grouped by the value of the prop parameter that shows them. More...
 
 getWatchlistValue ( $watchlist, $titleObj, $userOption=null)
 Return true if we're to watch the page, false if not, null if no change. More...
 
 makeHelpArrayToString ( $prefix, $title, $input)
 
 parseMultiValue ( $valueName, $value, $allowMultiple, $allowedValues)
 Return an array of values that were given in a 'a|b|c' notation, after it optionally validates them against the list allowed values. More...
 
 setWatch ( $watch, $titleObj, $userOption=null)
 Set a watch (or unwatch) based the based on a watchlist parameter. More...
 

Static Protected Member Functions

static matchOrigin ( $value, $rules, $exceptions)
 Attempt to match an Origin header against a set of rules and a set of exceptions. More...
 
static wildcardToRegex ( $wildcard)
 Helper function to convert wildcard string into a regex '*' => '. More...
 
- Static Protected Member Functions inherited from ApiBase
static addTokenProperties (&$props, $tokenFunctions)
 Add token properties to the array used by getResultProperties, based on a token functions mapping. More...
 
static dieDebug ( $method, $message)
 Internal code errors should be reported with this method. More...
 

Private Attributes

bool null $lacksSameOriginSecurity = null
 Cached return value from self::lacksSameOriginSecurity() *. More...
 
 $mAction
 
 $mCacheControl = array()
 
 $mCacheMode = 'private'
 
 $mCanApiHighLimits = null
 
 $mEnableWrite
 
 $mInternalMode
 
 $mModuleMgr
 
 $mParamsUsed = array()
 
ApiFormatBase $mPrinter
 

Static Private Attributes

static $Formats
 List of available formats: format name => format class. More...
 
static $Modules
 List of available modules: action name => module class. More...
 
static $mRights
 List of user roles that are specifically relevant to the API. More...
 

Additional Inherited Members

- Static Public Attributes inherited from ApiBase
static $messageMap
 Array that maps message keys to error messages. More...
 

Detailed Description

This is the main API class, used for both external and internal processing.

When executed, it will create the requested formatter object, instantiate and execute an object associated with the needed action, and use formatter to print results. In case of an exception, an error message will be printed using the same formatter.

To use API from another application, run it using FauxRequest object, in which case any internal exceptions will not be handled but passed up to the caller. After successful execution, use getResult() for the resulting data.

Definition at line 41 of file ApiMain.php.

Constructor & Destructor Documentation

◆ __construct()

ApiMain::__construct (   $context = null,
  $enableWrite = false 
)

Constructs an instance of ApiMain that utilizes the module and format specified by $request.

Parameters
$contextIContextSource|WebRequest - if this is an instance of FauxRequest, errors are thrown and no printing occurs
bool$enableWriteshould be set to true if the api may modify data

Definition at line 155 of file ApiMain.php.

References ContextSource\$context, $request, $wgUser, ContextSource\getContext(), RequestContext\getMain(), ContextSource\getRequest(), getVal(), global, ContextSource\setContext(), User, and wfDebug().

Member Function Documentation

◆ addFormat()

ApiMain::addFormat (   $name,
  $class 
)
protected

Add or overwrite an output format for this ApiMain.

Intended for use by extending classes who wish to add to or modify current formatters.

Deprecated:
since 1.21, Use getModuleManager()->addModule() instead.
Parameters
string$nameThe identifier for this format.
$classApiFormatBase The class implementing this format.

Definition at line 1408 of file ApiMain.php.

References $name, and getModuleManager().

◆ addModule()

ApiMain::addModule (   $name,
  $class 
)
protected

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.

Deprecated:
since 1.21, Use getModuleManager()->addModule() instead.
Parameters
string$nameThe identifier for this module.
$classApiBase The class where this module is implemented.

Definition at line 1396 of file ApiMain.php.

References $name, and getModuleManager().

◆ canApiHighLimits()

ApiMain::canApiHighLimits ( )

Check whether the current user is allowed to use high limits.

Returns
bool

Definition at line 1360 of file ApiMain.php.

References $mCanApiHighLimits, and ContextSource\getUser().

◆ checkAsserts()

ApiMain::checkAsserts (   $params)
protected

Check asserts of the user's rights.

Parameters
$paramsarray

Definition at line 881 of file ApiMain.php.

References $params, $user, ApiBase\dieUsage(), and ContextSource\getUser().

Referenced by executeAction().

◆ checkExecutePermissions()

ApiMain::checkExecutePermissions (   $module)
protected

Check for sufficient permissions to execute.

Parameters
$moduleApiBase An Api module

Definition at line 851 of file ApiMain.php.

References $user, array(), ApiBase\dieReadOnly(), ApiBase\dieUsageMsg(), ContextSource\getUser(), User\isEveryoneAllowed(), wfReadOnly(), and wfRunHooks().

Referenced by executeAction().

◆ checkMaxLag()

ApiMain::checkMaxLag (   $module,
  $params 
)
protected

Check the max lag if necessary.

Parameters
$moduleApiBase object: Api module being used
array$paramsan array containing the request parameters.
Returns
boolean True on success, false should exit immediately

Definition at line 824 of file ApiMain.php.

References $params, $response, ApiBase\dieUsage(), ContextSource\getRequest(), global, list, and wfGetLB().

Referenced by executeAction().

◆ createPrinterByName()

ApiMain::createPrinterByName (   $format)

Create an instance of an output formatter by its name.

Parameters
$formatstring
Returns
ApiFormatBase

Definition at line 347 of file ApiMain.php.

References ApiBase\dieUsage().

Referenced by setupExternalResponse(), and substituteResultWithError().

◆ encodeRequestLogValue()

ApiMain::encodeRequestLogValue (   $s)
protected

Encode a value in a format suitable for a space-separated log line.

Definition at line 992 of file ApiMain.php.

References $s.

Referenced by logRequest().

◆ execute()

ApiMain::execute ( )

Execute api request.

Any errors will be handled if the API was called by the remote client.

Reimplemented from ApiBase.

Definition at line 359 of file ApiMain.php.

References executeAction(), executeActionWithErrorHandling(), ApiBase\profileIn(), and ApiBase\profileOut().

◆ executeAction()

◆ executeActionWithErrorHandling()

ApiMain::executeActionWithErrorHandling ( )
protected

Execute an action, and in case of an error, erase whatever partial results have been accumulated, and replace it with an error message and a help screen.

Definition at line 374 of file ApiMain.php.

References $e, $t, executeAction(), ContextSource\getRequest(), handleCORS(), handleException(), logRequest(), sendCacheHeaders(), and wfReportTime().

Referenced by execute().

◆ getAllowedParams()

ApiMain::getAllowedParams ( )

See ApiBase for description.

Returns
array

Reimplemented from ApiBase.

Definition at line 1111 of file ApiMain.php.

References API_DEFAULT_FORMAT, array(), ApiBase\PARAM_DFLT, and ApiBase\PARAM_TYPE.

◆ getCheck()

ApiMain::getCheck (   $name)

Get a boolean request value, and register the fact that the parameter was used, for logging.

Definition at line 1025 of file ApiMain.php.

References $name, and ContextSource\getRequest().

◆ getCredits()

ApiMain::getCredits ( )
protected

Returns an array of strings with credits for the API.

Returns
array

Definition at line 1245 of file ApiMain.php.

References array().

Referenced by reallyMakeHelpMsg().

◆ getDescription()

ApiMain::getDescription ( )

See ApiBase for description.

Returns
array

Reimplemented from ApiBase.

Definition at line 1182 of file ApiMain.php.

References array().

◆ getFormats()

ApiMain::getFormats ( )

Returns the list of supported formats in form ( 'format' => 'ClassName' )

Since
1.18
Deprecated:
since 1.21, Use getModuleManager()'s methods instead.
Returns
array

Definition at line 1428 of file ApiMain.php.

References getModuleManager().

◆ getModule()

ApiMain::getModule ( )

Get the API module object.

Only works after executeAction()

Returns
ApiBase

Definition at line 255 of file ApiMain.php.

References $mModule.

◆ getModuleManager()

ApiMain::getModuleManager ( )

Overrides to return this instance's module manager.

Returns
ApiModuleManager

Reimplemented from ApiBase.

Definition at line 1383 of file ApiMain.php.

References $mModuleMgr.

Referenced by addFormat(), addModule(), getFormats(), and getModules().

◆ getModules()

ApiMain::getModules ( )

Get the array mapping module names to class names.

Deprecated:
since 1.21, Use getModuleManager()'s methods instead.
Returns
array

Definition at line 1417 of file ApiMain.php.

References getModuleManager().

◆ getParamDescription()

ApiMain::getParamDescription ( )

See ApiBase for description.

Returns
array

Reimplemented from ApiBase.

Definition at line 1146 of file ApiMain.php.

References array().

◆ getParamsUsed()

ApiMain::getParamsUsed ( )
protected

Get the request parameters used in the course of the preceding execute() request.

Definition at line 1008 of file ApiMain.php.

Referenced by logRequest(), and reportUnusedParams().

◆ getPossibleErrors()

ApiMain::getPossibleErrors ( )
Returns
array

Reimplemented from ApiBase.

Definition at line 1226 of file ApiMain.php.

References array().

◆ getPrinter()

ApiMain::getPrinter ( )

Get the result formatter object.

Only works after setupExecuteAction()

Returns
ApiFormatBase

Definition at line 264 of file ApiMain.php.

References $mPrinter.

◆ getResult()

ApiMain::getResult ( )

Get the ApiResult object associated with current request.

Returns
ApiResult

Reimplemented from ApiBase.

Definition at line 217 of file ApiMain.php.

References $mResult.

Referenced by executeAction(), printResult(), setupExecuteAction(), setupExternalResponse(), and substituteResultWithError().

◆ getShowVersions()

ApiMain::getShowVersions ( )

Check whether the user wants us to show version information in the API help.

Returns
bool
Deprecated:
since 1.21, always returns false

Definition at line 1373 of file ApiMain.php.

References wfDeprecated().

◆ getUpload()

ApiMain::getUpload (   $name)

Get a request upload, and register the fact that it was used, for logging.

Since
1.21
Parameters
string$nameParameter name
Returns
WebRequestUpload

Definition at line 1038 of file ApiMain.php.

References $name, and ContextSource\getRequest().

◆ getVal()

ApiMain::getVal (   $name,
  $default = null 
)

Get a request value, and register the fact that it was used, for logging.

Definition at line 1015 of file ApiMain.php.

References $name, and ContextSource\getRequest().

Referenced by __construct().

◆ handleApiBeforeMainException()

static ApiMain::handleApiBeforeMainException ( Exception  $e)
static

Handle an exception from the ApiBeforeMain hook.

This tries to print the exception as an API response, to be more friendly to clients. If it fails, it will rethrow the exception.

Since
1.23
Parameters
Exception$e

Definition at line 467 of file ApiMain.php.

References $e, false, and RequestContext\getMain().

◆ handleCORS()

ApiMain::handleCORS ( )
protected

Check the &origin= query parameter against the Origin: HTTP header and respond appropriately.

If no origin parameter is present, nothing happens. If an origin parameter is present but doesn't match the Origin header, a 403 status code is set and false is returned. 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.

Returns
bool False if the caller should abort (403 case), true otherwise (all other cases)

Definition at line 497 of file ApiMain.php.

References $request, $response, array(), HttpStatus\getMessage(), ContextSource\getOutput(), ApiBase\getParameter(), ContextSource\getRequest(), global, and matchOrigin().

Referenced by executeActionWithErrorHandling().

◆ handleException()

ApiMain::handleException ( Exception  $e)
protected

◆ isInternalMode()

ApiMain::isInternalMode ( )

Return true if the API was started by other PHP code using FauxRequest.

Returns
bool

Definition at line 208 of file ApiMain.php.

References $mInternalMode.

◆ isReadMode()

ApiMain::isReadMode ( )
Returns
bool

Reimplemented from ApiBase.

Definition at line 1102 of file ApiMain.php.

◆ lacksSameOriginSecurity()

ApiMain::lacksSameOriginSecurity ( )

Get the security flag for the current request.

Returns
bool

Reimplemented from ApiBase.

Definition at line 225 of file ApiMain.php.

References $lacksSameOriginSecurity, $request, array(), false, ContextSource\getRequest(), and Hooks\run().

◆ logRequest()

ApiMain::logRequest (   $time)
protected

Log the preceding request.

Parameters
int$timeTime in seconds

Definition at line 964 of file ApiMain.php.

References $name, $request, $s, $time, $value, as, encodeRequestLogValue(), getParamsUsed(), ContextSource\getRequest(), ContextSource\getUser(), wfDebugLog(), and wfUrlencode().

Referenced by executeActionWithErrorHandling().

◆ makeHelpMsg()

ApiMain::makeHelpMsg ( )

Override the parent to generate help messages for all available modules.

Returns
string

Reimplemented from ApiBase.

Definition at line 1273 of file ApiMain.php.

References $retval, $wgMemc, ApiBase\getModuleName(), SpecialVersion\getVersion(), global, reallyMakeHelpMsg(), setHelp(), and wfMemcKey().

Referenced by substituteResultWithError().

◆ makeHelpMsgHeader()

static ApiMain::makeHelpMsgHeader (   $module,
  $paramName 
)
static
Parameters
$moduleApiBase
string$paramNameWhat type of request is this? e.g. action, query, list, prop, meta, format
Returns
string

Definition at line 1345 of file ApiMain.php.

Referenced by ApiHelp\buildModuleHelp(), ApiQuery\makeHelpMsgHelper(), and reallyMakeHelpMsg().

◆ matchOrigin()

static ApiMain::matchOrigin (   $value,
  $rules,
  $exceptions 
)
staticprotected

Attempt to match an Origin header against a set of rules and a set of exceptions.

Parameters
string$valueOrigin header
array$rulesSet of wildcard rules
array$exceptionsSet of wildcard rules
Returns
bool True if $value matches a rule in $rules and doesn't match any rules in $exceptions, false otherwise

Definition at line 550 of file ApiMain.php.

References $exceptions, $value, and as.

Referenced by handleCORS().

◆ printResult()

ApiMain::printResult (   $isError)
protected

Print results using the current printer.

Parameters
$isErrorbool

Definition at line 1074 of file ApiMain.php.

References $mPrinter, getResult(), global, ApiBase\profileIn(), and ApiBase\setWarning().

Referenced by executeAction(), and handleException().

◆ reallyMakeHelpMsg()

ApiMain::reallyMakeHelpMsg ( )
Returns
mixed|string

Definition at line 1296 of file ApiMain.php.

References $name, $right, as, getCredits(), User\getGroupsWithPermission(), makeHelpMsgHeader(), setHelp(), and wfMsgReplaceArgs().

Referenced by makeHelpMsg().

◆ reportUnusedParams()

ApiMain::reportUnusedParams ( )
protected

Report unused parameters, so the client gets a hint in case it gave us parameters we don't know, for example in case of spelling mistakes or a missing 'g' prefix for generators.

Definition at line 1048 of file ApiMain.php.

References $s, array(), getParamsUsed(), ContextSource\getRequest(), and ApiBase\setWarning().

Referenced by executeAction().

◆ sendCacheHeaders()

ApiMain::sendCacheHeaders ( )
protected

◆ setCacheControl()

ApiMain::setCacheControl (   $directives)

Set directives (key/value pairs) for the Cache-Control header.

Boolean values will be formatted as such, by including or omitting without an equals sign.

Cache control values set here will only be used if the cache mode is not private, see setCacheMode().

Parameters
$directivesarray

Definition at line 336 of file ApiMain.php.

References $mCacheControl.

Referenced by setCacheMaxAge().

◆ setCacheMaxAge()

ApiMain::setCacheMaxAge (   $maxage)

Set how long the response should be cached.

Parameters
$maxage

Definition at line 273 of file ApiMain.php.

References array(), and setCacheControl().

◆ setCacheMode()

ApiMain::setCacheMode (   $mode)

Set the type of caching headers which will be sent.

Parameters
string$modeOne of:
  • 'public': Cache this object in public caches, if the maxage or smaxage parameter is set, or if setCacheMaxAge() was called. If a maximum age is not provided by any of these means, the object will be private.
  • 'private': Cache this object only in private client-side caches.
  • 'anon-public-user-private': Make this object cacheable for logged-out users, but private for logged-in users. IMPORTANT: If this is set, it must be set consistently for a given URL, it cannot be set differently depending on things like the contents of the database, or whether the user is logged in.

If the wiki does not allow anonymous users to read it, the mode set here will be ignored, and private caching headers will always be sent. In other words, the "public" mode is equivalent to saying that the data sent is as public as a page view.

For user-dependent data, the private mode should generally be used. The anon-public-user-private mode should only be used where there is a particularly good performance reason for caching the anonymous response, but where the response to logged-in users may differ, or may contain private data.

If this function is never called, then the default will be the private mode.

Definition at line 305 of file ApiMain.php.

References array(), User\isEveryoneAllowed(), and wfDebug().

Referenced by handleException().

◆ setHelp()

ApiMain::setHelp (   $help = true)

Sets whether the pretty-printer should format bold and $italics$.

Parameters
$helpbool

Definition at line 1264 of file ApiMain.php.

References $help.

Referenced by makeHelpMsg(), and reallyMakeHelpMsg().

◆ setupExecuteAction()

ApiMain::setupExecuteAction ( )
protected

Set up for the execution.

Returns
array

Definition at line 759 of file ApiMain.php.

References $params, ApiBase\dieUsage(), ApiBase\extractRequestParams(), ApiBase\getParameter(), getResult(), and global.

Referenced by executeAction().

◆ setupExternalResponse()

ApiMain::setupExternalResponse (   $module,
  $params 
)
protected

Check POST for external response and setup result printer.

Parameters
$moduleApiBase An Api module
array$paramsan array with the request parameters

Definition at line 904 of file ApiMain.php.

References $params, array(), createPrinterByName(), ApiBase\dieUsageMsgOrDebug(), ContextSource\getRequest(), and getResult().

Referenced by executeAction().

◆ setupModule()

ApiMain::setupModule ( )
protected

Set up the module for response.

Returns
ApiBase The module that will handle this action

Definition at line 791 of file ApiMain.php.

References array(), ApiBase\dieUsage(), ApiBase\dieUsageMsg(), ContextSource\getContext(), ContextSource\getRequest(), and ContextSource\getUser().

Referenced by executeAction().

◆ substituteResultWithError()

ApiMain::substituteResultWithError (   $e)
protected

Replace the result data with the information about an exception.

Returns the error code

Parameters
$eException
Returns
string

Definition at line 678 of file ApiMain.php.

References $e, $value, API_DEFAULT_FORMAT, array(), createPrinterByName(), ApiBase\getParameter(), ContextSource\getRequest(), getResult(), global, makeHelpMsg(), and ApiResult\setContent().

Referenced by handleException().

◆ wildcardToRegex()

static ApiMain::wildcardToRegex (   $wildcard)
staticprotected

Helper function to convert wildcard string into a regex '*' => '.

*?' '?' => '.'

Parameters
string$wildcardString with wildcards
Returns
string Regular expression

Definition at line 575 of file ApiMain.php.

References array().

Member Data Documentation

◆ $Formats

ApiMain::$Formats
staticprivate
Initial value:
'json' => 'ApiFormatJson',
'jsonfm' => 'ApiFormatJson',
'php' => 'ApiFormatPhp',
'phpfm' => 'ApiFormatPhp',
'wddx' => 'ApiFormatWddx',
'wddxfm' => 'ApiFormatWddx',
'xml' => 'ApiFormatXml',
'xmlfm' => 'ApiFormatXml',
'yaml' => 'ApiFormatYaml',
'yamlfm' => 'ApiFormatYaml',
'rawfm' => 'ApiFormatJson',
'txt' => 'ApiFormatTxt',
'txtfm' => 'ApiFormatTxt',
'dbg' => 'ApiFormatDbg',
'dbgfm' => 'ApiFormatDbg',
'dump' => 'ApiFormatDump',
'dumpfm' => 'ApiFormatDump',
'none' => 'ApiFormatNone',
)

List of available formats: format name => format class.

Definition at line 93 of file ApiMain.php.

◆ $lacksSameOriginSecurity

bool null ApiMain::$lacksSameOriginSecurity = null
private

Cached return value from self::lacksSameOriginSecurity() *.

Definition at line 146 of file ApiMain.php.

Referenced by lacksSameOriginSecurity().

◆ $mAction

ApiMain::$mAction
private

Definition at line 138 of file ApiMain.php.

◆ $mCacheControl

ApiMain::$mCacheControl = array()
private

Definition at line 143 of file ApiMain.php.

Referenced by setCacheControl().

◆ $mCacheMode

ApiMain::$mCacheMode = 'private'
private

Definition at line 142 of file ApiMain.php.

◆ $mCanApiHighLimits

ApiMain::$mCanApiHighLimits = null
private

Definition at line 1354 of file ApiMain.php.

Referenced by canApiHighLimits().

◆ $mEnableWrite

ApiMain::$mEnableWrite
private

Definition at line 139 of file ApiMain.php.

◆ $mInternalMode

ApiMain::$mInternalMode
private

Definition at line 140 of file ApiMain.php.

Referenced by isInternalMode().

◆ $mModule

ApiMain::$mModule

Definition at line 140 of file ApiMain.php.

Referenced by getModule().

◆ $mModuleMgr

ApiMain::$mModuleMgr
private

Definition at line 137 of file ApiMain.php.

Referenced by getModuleManager().

◆ $Modules

ApiMain::$Modules
staticprivate

List of available modules: action name => module class.

Definition at line 50 of file ApiMain.php.

◆ $mParamsUsed

ApiMain::$mParamsUsed = array()
private

Definition at line 144 of file ApiMain.php.

◆ $mPrinter

ApiFormatBase ApiMain::$mPrinter
private

Definition at line 135 of file ApiMain.php.

Referenced by getPrinter(), and printResult().

◆ $mResult

ApiMain::$mResult

Definition at line 137 of file ApiMain.php.

Referenced by getResult().

◆ $mRights

ApiMain::$mRights
staticprivate
Initial value:
'writeapi' => array(
'msg' => 'Use of the write API',
'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.',
)
)

List of user roles that are specifically relevant to the API.

array( 'right' => array ( 'msg' => 'Some message with a $1', 'params' => array ( $someVarToSubst ) ), );

Definition at line 121 of file ApiMain.php.

◆ $mSquidMaxage

ApiMain::$mSquidMaxage

Definition at line 140 of file ApiMain.php.

◆ API_DEFAULT_FORMAT

const ApiMain::API_DEFAULT_FORMAT = 'xmlfm'

When no format parameter is given, this format will be used.

Definition at line 45 of file ApiMain.php.

Referenced by getAllowedParams(), and substituteResultWithError().


The documentation for this class was generated from the following file:
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
ApiBase\LIMIT_SML2
const LIMIT_SML2
Definition: ApiBase.php:81
ApiBase\LIMIT_BIG2
const LIMIT_BIG2
Definition: ApiBase.php:79