'import' => 'ApiImport',
'userrights' => 'ApiUserrights',
'options' => 'ApiOptions',
+ 'imagerotate' =>'ApiImageRotate',
);
/**
* Constructs an instance of ApiMain that utilizes the module and format specified by $request.
*
* @param $context IContextSource|WebRequest - if this is an instance of FauxRequest, errors are thrown and no printing occurs
- * @param $enableWrite bool should be set to true if the api may modify data
+ * @param bool $enableWrite should be set to true if the api may modify data
*/
public function __construct( $context = null, $enableWrite = false ) {
if ( $context === null ) {
/**
* Set the type of caching headers which will be sent.
*
- * @param $mode String One of:
+ * @param string $mode One 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.
return;
}
- if ( !in_array( 'read', User::getGroupPermissions( array( '*' ) ), true ) ) {
+ if ( !User::groupHasPermission( '*', 'read' ) ) {
// Private wiki, only private headers
if ( $mode !== 'private' ) {
wfDebug( __METHOD__ . ": ignoring request for $mode cache mode, private wiki\n" );
return;
}
+ // Exit here if the request method was OPTIONS
+ // (assume there will be a followup GET or POST)
+ if ( $this->getRequest()->getMethod() === 'OPTIONS' ) {
+ return;
+ }
+
// In case an error occurs during data output,
// clear the output buffer and print just the error information
ob_start();
/**
* Attempt to match an Origin header against a set of rules and a set of exceptions
- * @param $value string Origin header
- * @param $rules array Set of wildcard rules
- * @param $exceptions array Set of wildcard rules
+ * @param string $value Origin header
+ * @param array $rules Set of wildcard rules
+ * @param array $exceptions Set of wildcard rules
* @return bool True if $value matches a rule in $rules and doesn't match any rules in $exceptions, false otherwise
*/
protected static function matchOrigin( $value, $rules, $exceptions ) {
* '*' => '.*?'
* '?' => '.'
*
- * @param $wildcard string String with wildcards
+ * @param string $wildcard String with wildcards
* @return string Regular expression
*/
protected static function wildcardToRegex( $wildcard ) {
/**
* Check the max lag if necessary
* @param $module ApiBase object: Api module being used
- * @param $params Array an array containing the request parameters.
+ * @param array $params an array containing the request parameters.
* @return boolean True on success, false should exit immediately
*/
protected function checkMaxLag( $module, $params ) {
*/
protected function checkExecutePermissions( $module ) {
$user = $this->getUser();
- if ( $module->isReadMode() && !in_array( 'read', User::getGroupPermissions( array( '*' ) ), true ) &&
+ if ( $module->isReadMode() && !User::groupHasPermission( '*', 'read' ) &&
!$user->isAllowed( 'read' ) )
{
$this->dieUsageMsg( 'readrequired' );
/**
* Check POST for external response and setup result printer
* @param $module ApiBase An Api module
- * @param $params Array an array with the request parameters
+ * @param array $params an array with the request parameters
*/
protected function setupExternalResponse( $module, $params ) {
if ( !$this->getRequest()->wasPosted() && $module->mustBePosted() ) {
wfRunHooks( 'APIAfterExecute', array( &$module ) );
$module->profileOut();
- if ( !$this->mInternalMode ) {
- // Report unused params
- $this->reportUnusedParams();
+ $this->reportUnusedParams();
+ if ( !$this->mInternalMode ) {
//append Debug information
MWDebug::appendDebugInfoToApiResult( $this->getContext(), $this->getResult() );
return $this->getRequest()->getCheck( $name );
}
+ /**
+ * Get a request upload, and register the fact that it was used, for logging.
+ *
+ * @since 1.21
+ * @param string $name Parameter name
+ * @return WebRequestUpload
+ */
+ public function getUpload( $name ) {
+ $this->mParamsUsed[$name] = true;
+ return $this->getRequest()->getUpload( $name );
+ }
+
/**
* 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.
$paramsUsed = $this->getParamsUsed();
$allParams = $this->getRequest()->getValueNames();
- $unusedParams = array_diff( $allParams, $paramsUsed );
+ if ( !$this->mInternalMode ) {
+ // Printer has not yet executed; don't warn that its parameters are unused
+ $printerParams = array_map(
+ array( $this->mPrinter, 'encodeParamName' ),
+ array_keys( $this->mPrinter->getFinalParams() ?: array() )
+ );
+ $unusedParams = array_diff( $allParams, $paramsUsed, $printerParams );
+ } else {
+ $unusedParams = array_diff( $allParams, $paramsUsed );
+ }
+
if( count( $unusedParams ) ) {
$s = count( $unusedParams ) > 1 ? 's' : '';
$this->setWarning( "Unrecognized parameter$s: '" . implode( $unusedParams, "', '" ) . "'" );
protected function getCredits() {
return array(
'API developers:',
- ' Roan Kattouw "<Firstname>.<Lastname>@gmail.com" (lead developer Sep 2007-present)',
+ ' Roan Kattouw "<Firstname>.<Lastname>@gmail.com" (lead developer Sep 2007-2009)',
' Victor Vasiliev - vasilvv at gee mail dot com',
' Bryan Tong Minh - bryan . tongminh @ gmail . com',
' Sam Reed - sam @ reedyboy . net',
- ' Yuri Astrakhan "<Firstname><Lastname>@gmail.com" (creator, lead developer Sep 2006-Sep 2007, 2012)',
+ ' Yuri Astrakhan "<Firstname><Lastname>@gmail.com" (creator, lead developer Sep 2006-Sep 2007, 2012-present)',
'',
'Please send your comments, suggestions and questions to mediawiki-api@lists.wikimedia.org',
'or file a bug report at https://bugzilla.wikimedia.org/'
/**
* @param $module ApiBase
- * @param $paramName String What type of request is this? e.g. action, query, list, prop, meta, format
+ * @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 ) {
* behavior of inherent ones.
*
* @deprecated since 1.21, Use getModuleManager()->addModule() instead.
- * @param $name string The identifier for this module.
+ * @param string $name The identifier for this module.
* @param $class ApiBase The class where this module is implemented.
*/
protected function addModule( $name, $class ) {
* classes who wish to add to or modify current formatters.
*
* @deprecated since 1.21, Use getModuleManager()->addModule() instead.
- * @param $name string The identifier for this format.
+ * @param string $name The identifier for this format.
* @param $class ApiFormatBase The class implementing this format.
*/
protected function addFormat( $name, $class ) {
- $this->getModuleManager->addModule( $name, 'format', $class );
+ $this->getModuleManager()->addModule( $name, 'format', $class );
}
/**