<?php
-/*
+/**
* Created on Sep 19, 2006
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiFormatBase.php' );
+ require_once( 'ApiFormatBase.php' );
}
/**
private $mXslt = null;
public function __construct( $main, $format ) {
- parent :: __construct( $main, $format );
+ parent::__construct( $main, $format );
}
public function getMimeType() {
$this->mXslt = $params['xslt'];
$this->printText( '<?xml version="1.0"?>' );
- if ( !is_null( $this->mXslt ) )
+ if ( !is_null( $this->mXslt ) ) {
$this->addXslt();
- $this->printText( self::recXmlPrint( $this->mRootElemName,
+ }
+ $this->printText(
+ self::recXmlPrint( $this->mRootElemName,
$this->getResultData(),
$this->getIsHtml() ? - 2 : null,
- $this->mDoubleQuote ) );
+ $this->mDoubleQuote
+ )
+ );
}
/**
- * This method takes an array and converts it to XML.
- * There are several noteworthy cases:
- *
- * If array contains a key '_element', then the code assumes that ALL other keys are not important and replaces them with the value['_element'].
- * Example: name='root', value = array( '_element'=>'page', 'x', 'y', 'z') creates <root> <page>x</page> <page>y</page> <page>z</page> </root>
- *
- * If any of the array's element key is '*', then the code treats all other key->value pairs as attributes, and the value['*'] as the element's content.
- * Example: name='root', value = array( '*'=>'text', 'lang'=>'en', 'id'=>10) creates <root lang='en' id='10'>text</root>
- *
- * If neither key is found, all keys become element names, and values become element content.
- * The method is recursive, so the same rules apply to any sub-arrays.
- */
+ * This method takes an array and converts it to XML.
+ * There are several noteworthy cases:
+ *
+ * If array contains a key '_element', then the code assumes that ALL other keys are not important and replaces them with the value['_element'].
+ * Example: name='root', value = array( '_element'=>'page', 'x', 'y', 'z') creates <root> <page>x</page> <page>y</page> <page>z</page> </root>
+ *
+ * If any of the array's element key is '*', then the code treats all other key->value pairs as attributes, and the value['*'] as the element's content.
+ * Example: name='root', value = array( '*'=>'text', 'lang'=>'en', 'id'=>10) creates <root lang='en' id='10'>text</root>
+ *
+ * If neither key is found, all keys become element names, and values become element content.
+ * The method is recursive, so the same rules apply to any sub-arrays.
+ */
public static function recXmlPrint( $elemName, $elemValue, $indent, $doublequote = false ) {
$retval = '';
if ( !is_null( $indent ) ) {
$indent += 2;
- $indstr = "\n" . str_repeat( " ", $indent );
+ $indstr = "\n" . str_repeat( ' ', $indent );
} else {
$indstr = '';
}
$elemName = str_replace( ' ', '_', $elemName );
switch ( gettype( $elemValue ) ) {
- case 'array' :
- if ( isset ( $elemValue['*'] ) ) {
+ case 'array':
+ if ( isset( $elemValue['*'] ) ) {
$subElemContent = $elemValue['*'];
- if ( $doublequote )
+ if ( $doublequote ) {
$subElemContent = Sanitizer::encodeAttribute( $subElemContent );
- unset ( $elemValue['*'] );
-
+ }
+ unset( $elemValue['*'] );
+
// Add xml:space="preserve" to the
// element so XML parsers will leave
// whitespace in the content alone
$subElemContent = null;
}
- if ( isset ( $elemValue['_element'] ) ) {
+ if ( isset( $elemValue['_element'] ) ) {
$subElemIndName = $elemValue['_element'];
- unset ( $elemValue['_element'] );
+ unset( $elemValue['_element'] );
} else {
$subElemIndName = null;
}
- $indElements = array ();
- $subElements = array ();
+ $indElements = array();
+ $subElements = array();
foreach ( $elemValue as $subElemId => & $subElemValue ) {
- if ( is_string( $subElemValue ) && $doublequote )
+ if ( is_string( $subElemValue ) && $doublequote ) {
$subElemValue = Sanitizer::encodeAttribute( $subElemValue );
-
+ }
+
if ( gettype( $subElemId ) === 'integer' ) {
$indElements[] = $subElemValue;
- unset ( $elemValue[$subElemId] );
+ unset( $elemValue[$subElemId] );
} elseif ( is_array( $subElemValue ) ) {
$subElements[$subElemId] = $subElemValue;
unset ( $elemValue[$subElemId] );
}
}
- if ( is_null( $subElemIndName ) && count( $indElements ) )
- ApiBase :: dieDebug( __METHOD__, "($elemName, ...) has integer keys without _element value. Use ApiResult::setIndexedTagName()." );
+ if ( is_null( $subElemIndName ) && count( $indElements ) ) {
+ ApiBase::dieDebug( __METHOD__, "($elemName, ...) has integer keys without _element value. Use ApiResult::setIndexedTagName()." );
+ }
- if ( count( $subElements ) && count( $indElements ) && !is_null( $subElemContent ) )
- ApiBase :: dieDebug( __METHOD__, "($elemName, ...) has content and subelements" );
+ if ( count( $subElements ) && count( $indElements ) && !is_null( $subElemContent ) ) {
+ ApiBase::dieDebug( __METHOD__, "($elemName, ...) has content and subelements" );
+ }
if ( !is_null( $subElemContent ) ) {
$retval .= $indstr . Xml::element( $elemName, $elemValue, $subElemContent );
} elseif ( !count( $indElements ) && !count( $subElements ) ) {
- $retval .= $indstr . Xml::element( $elemName, $elemValue );
+ $retval .= $indstr . Xml::element( $elemName, $elemValue );
} else {
$retval .= $indstr . Xml::element( $elemName, $elemValue, null );
- foreach ( $subElements as $subElemId => & $subElemValue )
+ foreach ( $subElements as $subElemId => & $subElemValue ) {
$retval .= self::recXmlPrint( $subElemId, $subElemValue, $indent );
+ }
- foreach ( $indElements as $subElemId => & $subElemValue )
+ foreach ( $indElements as $subElemId => & $subElemValue ) {
$retval .= self::recXmlPrint( $subElemIndName, $subElemValue, $indent );
+ }
$retval .= $indstr . Xml::closeElement( $elemName );
}
break;
- case 'object' :
+ case 'object':
// ignore
break;
- default :
+ default:
$retval .= $indstr . Xml::element( $elemName, null, $elemValue );
break;
}
return $retval;
}
+
function addXslt() {
$nt = Title::newFromText( $this->mXslt );
if ( is_null( $nt ) || !$nt->exists() ) {
}
$this->printText( '<?xml-stylesheet href="' . $nt->escapeLocalURL( 'action=raw' ) . '" type="text/xsl" ?>' );
}
-
+
public function getAllowedParams() {
- return array (
+ return array(
'xmldoublequote' => false,
'xslt' => null,
);
}
public function getParamDescription() {
- return array (
+ return array(
'xmldoublequote' => 'If specified, double quotes all attributes and content.',
'xslt' => 'If specified, adds <xslt> as stylesheet',
);
}
public function getDescription() {
- return 'Output data in XML format' . parent :: getDescription();
+ return 'Output data in XML format' . parent::getDescription();
}
public function getVersion() {
<?php
-/*
+/**
* Created on Sep 19, 2006
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiFormatBase.php' );
+ require_once( 'ApiFormatBase.php' );
}
/**
class ApiFormatYaml extends ApiFormatBase {
public function __construct( $main, $format ) {
- parent :: __construct( $main, $format );
+ parent::__construct( $main, $format );
}
public function getMimeType() {
}
public function execute() {
- $this->printText( Spyc :: YAMLDump( $this->getResultData() ) );
+ $this->printText( Spyc::YAMLDump( $this->getResultData() ) );
}
public function getDescription() {
- return 'Output data in YAML format' . parent :: getDescription();
+ return 'Output data in YAML format' . parent::getDescription();
}
public function getVersion() {
<?php
-/*
+/**
* Created on Sep 6, 2006
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
}
public function getDescription() {
- return array (
+ return array(
'Display this help screen.'
);
}
<?php
-/*
+/**
* Created on Feb 4, 2009
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2009 Roan Kattouw <Firstname>.<Lastname>@home.nl
+ * Copyright © 2009 Roan Kattouw <Firstname>.<Lastname>@home.nl
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiBase.php' );
+ require_once( 'ApiBase.php' );
}
/**
class ApiImport extends ApiBase {
public function __construct( $main, $action ) {
- parent :: __construct( $main, $action );
+ parent::__construct( $main, $action );
}
public function execute() {
global $wgUser;
- if ( !$wgUser->isAllowed( 'import' ) )
+ if ( !$wgUser->isAllowed( 'import' ) ) {
$this->dieUsageMsg( array( 'cantimport' ) );
+ }
$params = $this->extractRequestParams();
$source = null;
$isUpload = false;
- if ( isset( $params['interwikisource'] ) )
- {
- if ( !isset( $params['interwikipage'] ) )
+ if ( isset( $params['interwikisource'] ) ) {
+ if ( !isset( $params['interwikipage'] ) ) {
$this->dieUsageMsg( array( 'missingparam', 'interwikipage' ) );
+ }
$source = ImportStreamSource::newFromInterwiki(
- $params['interwikisource'],
- $params['interwikipage'],
- $params['fullhistory'],
- $params['templates'] );
- }
- else
- {
+ $params['interwikisource'],
+ $params['interwikipage'],
+ $params['fullhistory'],
+ $params['templates']
+ );
+ } else {
$isUpload = true;
- if ( !$wgUser->isAllowed( 'importupload' ) )
+ if ( !$wgUser->isAllowed( 'importupload' ) ) {
$this->dieUsageMsg( array( 'cantimport-upload' ) );
+ }
$source = ImportStreamSource::newFromUpload( 'xml' );
}
- if ( $source instanceof WikiErrorMsg )
+ if ( $source instanceof WikiErrorMsg ) {
$this->dieUsageMsg( array_merge(
array( $source->getMessageKey() ),
$source->getMessageArgs() ) );
- else if ( WikiError::isError( $source ) )
+ } elseif ( WikiError::isError( $source ) ) {
// This shouldn't happen
$this->dieUsageMsg( array( 'import-unknownerror', $source->getMessage() ) );
+ }
$importer = new WikiImporter( $source );
- if ( isset( $params['namespace'] ) )
+ if ( isset( $params['namespace'] ) ) {
$importer->setTargetNamespace( $params['namespace'] );
- $reporter = new ApiImportReporter( $importer, $isUpload,
- $params['interwikisource'],
- $params['summary'] );
+ }
+ $reporter = new ApiImportReporter(
+ $importer,
+ $isUpload,
+ $params['interwikisource'],
+ $params['summary']
+ );
$result = $importer->doImport();
- if ( $result instanceof WikiXmlError )
+ if ( $result instanceof WikiXmlError ) {
$this->dieUsageMsg( array( 'import-xml-error',
$result->mLine,
$result->mColumn,
$result->mByte . $result->mContext,
xml_error_string( $result->mXmlError ) ) );
- else if ( WikiError::isError( $result ) )
+ } elseif ( WikiError::isError( $result ) ) {
$this->dieUsageMsg( array( 'import-unknownerror', $result->getMessage() ) ); // This shouldn't happen
+ }
$resultData = $reporter->getData();
$this->getResult()->setIndexedTagName( $resultData, 'page' );
public function getAllowedParams() {
global $wgImportSources;
- return array (
+ return array(
'token' => null,
'summary' => null,
'xml' => null,
'interwikisource' => array(
- ApiBase :: PARAM_TYPE => $wgImportSources
+ ApiBase::PARAM_TYPE => $wgImportSources
),
'interwikipage' => null,
'fullhistory' => false,
'templates' => false,
'namespace' => array(
- ApiBase :: PARAM_TYPE => 'namespace'
+ ApiBase::PARAM_TYPE => 'namespace'
)
);
}
public function getParamDescription() {
- return array (
+ return array(
'token' => 'Import token obtained through prop=info',
'summary' => 'Import summary',
'xml' => 'Uploaded XML file',
}
public function getDescription() {
- return array (
+ return array(
'Import a page from another wiki, or an XML file'
);
}
-
+
public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'cantimport' ),
array( 'import-unknownerror', 'result' ),
) );
}
-
+
public function getTokenSalt() {
return '';
}
class ApiImportReporter extends ImportReporter {
private $mResultArr = array();
- function reportPage( $title, $origTitle, $revisionCount, $successCount )
- {
+ function reportPage( $title, $origTitle, $revisionCount, $successCount ) {
// Add a result entry
$r = array();
ApiQueryBase::addTitleInfo( $r, $title );
parent::reportPage( $title, $origTitle, $revisionCount, $successCount );
}
- function getData()
- {
+ function getData() {
return $this->mResultArr;
}
}
\ No newline at end of file
<?php
-/*
+/**
* Created on Jan 4, 2008
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2008 Yuri Astrakhan <Firstname><Lastname>@gmail.com,
+ * Copyright © 2008 Yuri Astrakhan <Firstname><Lastname>@gmail.com,
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiBase.php' );
+ require_once( 'ApiBase.php' );
}
/**
class ApiLogout extends ApiBase {
public function __construct( $main, $action ) {
- parent :: __construct( $main, $action );
+ parent::__construct( $main, $action );
}
public function execute() {
global $wgUser;
$oldName = $wgUser->getName();
$wgUser->logout();
-
+
// Give extensions to do something after user logout
$injected_html = '';
wfRunHooks( 'UserLogoutComplete', array( &$wgUser, &$injected_html, $oldName ) );
}
public function getAllowedParams() {
- return array ();
+ return array();
}
public function getParamDescription() {
- return array ();
+ return array();
}
public function getDescription() {
- return array (
+ return array(
'This module is used to logout and clear session data'
);
}
<?php
-/*
+/**
* Created on Sep 4, 2006
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiBase.php' );
+ require_once( 'ApiBase.php' );
}
/**
/**
* List of available modules: action name => module class
*/
- private static $Modules = array (
+ private static $Modules = array(
'login' => 'ApiLogin',
'logout' => 'ApiLogout',
'query' => 'ApiQuery',
/**
* List of available formats: format name => format class
*/
- private static $Formats = array (
+ private static $Formats = array(
'json' => 'ApiFormatJson',
'jsonfm' => 'ApiFormatJson',
'php' => 'ApiFormatPhp',
* 'params' => array ( $someVarToSubst ) ),
* );
*/
- private static $mRights = array( '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.',
- 'params' => array ( ApiMain::LIMIT_SML2, ApiMain::LIMIT_BIG2 )
- )
+ private static $mRights = array(
+ '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.',
+ 'params' => array( ApiMain::LIMIT_SML2, ApiMain::LIMIT_BIG2 )
+ )
);
-
private $mPrinter, $mModules, $mModuleNames, $mFormats, $mFormatNames;
private $mResult, $mAction, $mShowVersions, $mEnableWrite, $mRequest;
private $mInternalMode, $mSquidMaxage, $mModule;
private $mCacheControl = array( 'must-revalidate' => true );
/**
- * Constructs an instance of ApiMain that utilizes the module and format specified by $request.
- *
- * @param $request object - 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
- */
+ * Constructs an instance of ApiMain that utilizes the module and format specified by $request.
+ *
+ * @param $request object - 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
+ */
public function __construct( $request, $enableWrite = false ) {
-
$this->mInternalMode = ( $request instanceof FauxRequest );
// Special handling for the main module: $parent === $this
- parent :: __construct( $this, $this->mInternalMode ? 'main_int' : 'main' );
+ parent::__construct( $this, $this->mInternalMode ? 'main_int' : 'main' );
if ( !$this->mInternalMode ) {
-
// Impose module restrictions.
// If the current user cannot read,
// Remove all modules other than login
}
global $wgAPIModules; // extension modules
- $this->mModules = $wgAPIModules + self :: $Modules;
+ $this->mModules = $wgAPIModules + self::$Modules;
$this->mModuleNames = array_keys( $this->mModules );
- $this->mFormats = self :: $Formats;
+ $this->mFormats = self::$Formats;
$this->mFormatNames = array_keys( $this->mFormats );
$this->mResult = new ApiResult( $this );
$this->mShowVersions = false;
$this->mEnableWrite = $enableWrite;
- $this->mRequest = & $request;
+ $this->mRequest = &$request;
- $this->mSquidMaxage = - 1; // flag for executeActionWithErrorHandling()
+ $this->mSquidMaxage = -1; // flag for executeActionWithErrorHandling()
$this->mCommit = false;
}
* @deprecated Use isWriteMode() instead
*/
public function requestWriteMode() {
- if ( !$this->mEnableWrite )
+ if ( !$this->mEnableWrite ) {
$this->dieUsageMsg( array( 'writedisabled' ) );
- if ( wfReadOnly() )
+ }
+ if ( wfReadOnly() ) {
$this->dieUsageMsg( array( 'readonlytext' ) );
+ }
}
/**
* Create an instance of an output formatter by its name
*/
public function createPrinterByName( $format ) {
- if ( !isset( $this->mFormats[$format] ) )
+ if ( !isset( $this->mFormats[$format] ) ) {
$this->dieUsage( "Unrecognized format: {$format}", 'unknown_format' );
+ }
return new $this->mFormats[$format] ( $this, $format );
}
*/
public function execute() {
$this->profileIn();
- if ( $this->mInternalMode )
+ if ( $this->mInternalMode ) {
$this->executeAction();
- else
+ } else {
$this->executeActionWithErrorHandling();
+ }
$this->profileOut();
}
* have been accumulated, and replace it with an error message and a help screen.
*/
protected function executeActionWithErrorHandling() {
-
// In case an error occurs during data output,
// clear the output buffer and print just the error information
ob_start();
$this->setCacheMaxAge( 0 );
$headerStr = 'MediaWiki-API-Error: ' . $errCode;
- if ( $e->getCode() === 0 )
+ if ( $e->getCode() === 0 ) {
header( $headerStr );
- else
+ } else {
header( $headerStr, true, $e->getCode() );
+ }
// Reset and print just the error message
ob_clean();
$separator = ', ';
}
}
-
+
header( "Cache-Control: $ccHeader" );
- if ( $this->mPrinter->getIsHtml() )
+ if ( $this->mPrinter->getIsHtml() ) {
echo wfReportTime();
+ }
ob_end_flush();
}
* Returns the error code
*/
protected function substituteResultWithError( $e ) {
-
// Printer may not be initialized if the extractRequestParams() fails for the main module
if ( !isset ( $this->mPrinter ) ) {
// The printer has not been created yet. Try to manually get formatter value.
$value = $this->getRequest()->getVal( 'format', self::API_DEFAULT_FORMAT );
- if ( !in_array( $value, $this->mFormatNames ) )
+ if ( !in_array( $value, $this->mFormatNames ) ) {
$value = self::API_DEFAULT_FORMAT;
+ }
$this->mPrinter = $this->createPrinterByName( $value );
- if ( $this->mPrinter->getNeedsRawData() )
+ if ( $this->mPrinter->getNeedsRawData() ) {
$this->getResult()->setRawMode();
+ }
}
if ( $e instanceof UsageException ) {
$errMessage = $e->getMessageArray();
// Only print the help message when this is for the developer, not runtime
- if ( $this->mPrinter->getWantsHelp() || $this->mAction == 'help' )
- ApiResult :: setContent( $errMessage, $this->makeHelpMsg() );
+ if ( $this->mPrinter->getWantsHelp() || $this->mAction == 'help' ) {
+ ApiResult::setContent( $errMessage, $this->makeHelpMsg() );
+ }
} else {
global $wgShowSQLErrors, $wgShowExceptionDetails;
// Something is seriously wrong
//
if ( ( $e instanceof DBQueryError ) && !$wgShowSQLErrors ) {
- $info = "Database query error";
+ $info = 'Database query error';
} else {
$info = "Exception Caught: {$e->getMessage()}";
}
- $errMessage = array (
+ $errMessage = array(
'code' => 'internal_api_error_' . get_class( $e ),
'info' => $info,
);
- ApiResult :: setContent( $errMessage, $wgShowExceptionDetails ? "\n\n{$e->getTraceAsString()}\n\n" : "" );
+ ApiResult::setContent( $errMessage, $wgShowExceptionDetails ? "\n\n{$e->getTraceAsString()}\n\n" : '' );
}
$this->getResult()->reset();
$this->getResult()->disableSizeCheck();
// Re-add the id
$requestid = $this->getParameter( 'requestid' );
- if ( !is_null( $requestid ) )
+ if ( !is_null( $requestid ) ) {
$this->getResult()->addValue( null, 'requestid', $requestid );
+ }
$this->getResult()->addValue( null, 'error', $errMessage );
return $errMessage['code'];
protected function executeAction() {
// First add the id to the top element
$requestid = $this->getParameter( 'requestid' );
- if ( !is_null( $requestid ) )
+ if ( !is_null( $requestid ) ) {
$this->getResult()->addValue( null, 'requestid', $requestid );
+ }
$params = $this->extractRequestParams();
$this->mAction = $params['action'];
if ( !is_string( $this->mAction ) ) {
- $this->dieUsage( "The API requires a valid action parameter", 'unknown_action' );
+ $this->dieUsage( 'The API requires a valid action parameter', 'unknown_action' );
}
-
+
// Instantiate the module requested by the user
$module = new $this->mModules[$this->mAction] ( $this, $this->mAction );
$this->mModule = $module;
$moduleParams = $module->extractRequestParams();
-
+
// Die if token required, but not provided (unless there is a gettoken parameter)
$salt = $module->getTokenSalt();
- if ( $salt !== false && !isset( $moduleParams['gettoken'] ) )
- {
+ if ( $salt !== false && !isset( $moduleParams['gettoken'] ) ) {
if ( !isset( $moduleParams['token'] ) ) {
$this->dieUsageMsg( array( 'missingparam', 'token' ) );
} else {
global $wgUser, $wgGroupPermissions;
if ( $module->isReadMode() && !$wgGroupPermissions['*']['read'] && !$wgUser->isAllowed( 'read' ) )
+ {
$this->dieUsageMsg( array( 'readrequired' ) );
+ }
if ( $module->isWriteMode() ) {
- if ( !$this->mEnableWrite )
+ if ( !$this->mEnableWrite ) {
$this->dieUsageMsg( array( 'writedisabled' ) );
- if ( !$wgUser->isAllowed( 'writeapi' ) )
+ }
+ if ( !$wgUser->isAllowed( 'writeapi' ) ) {
$this->dieUsageMsg( array( 'writerequired' ) );
- if ( wfReadOnly() )
+ }
+ if ( wfReadOnly() ) {
$this->dieReadOnly();
+ }
}
if ( !$this->mInternalMode ) {
// Ignore mustBePosted() for internal calls
- if ( $module->mustBePosted() && !$this->mRequest->wasPosted() )
- $this->dieUsageMsg( array ( 'mustbeposted', $this->mAction ) );
+ if ( $module->mustBePosted() && !$this->mRequest->wasPosted() ) {
+ $this->dieUsageMsg( array( 'mustbeposted', $this->mAction ) );
+ }
// See if custom printer is used
$this->mPrinter = $module->getCustomPrinter();
$this->mPrinter = $this->createPrinterByName( $params['format'] );
}
- if ( $this->mPrinter->getNeedsRawData() )
+ if ( $this->mPrinter->getNeedsRawData() ) {
$this->getResult()->setRawMode();
+ }
}
// Execute
$printer = $this->mPrinter;
$printer->profileIn();
- /* If the help message is requested in the default (xmlfm) format,
+ /**
+ * If the help message is requested in the default (xmlfm) format,
* tell the printer not to escape ampersands so that our links do
- * not break. */
- $printer->setUnescapeAmps ( ( $this->mAction == 'help' || $isError )
+ * not break.
+ */
+ $printer->setUnescapeAmps( ( $this->mAction == 'help' || $isError )
&& $printer->getFormat() == 'XML' && $printer->getIsHtml() );
$printer->initPrinter( $isError );
* See ApiBase for description.
*/
public function getAllowedParams() {
- return array (
- 'format' => array (
- ApiBase :: PARAM_DFLT => ApiMain :: API_DEFAULT_FORMAT,
- ApiBase :: PARAM_TYPE => $this->mFormatNames
+ return array(
+ 'format' => array(
+ ApiBase::PARAM_DFLT => ApiMain::API_DEFAULT_FORMAT,
+ ApiBase::PARAM_TYPE => $this->mFormatNames
),
- 'action' => array (
- ApiBase :: PARAM_DFLT => 'help',
- ApiBase :: PARAM_TYPE => $this->mModuleNames
+ 'action' => array(
+ ApiBase::PARAM_DFLT => 'help',
+ ApiBase::PARAM_TYPE => $this->mModuleNames
),
'version' => false,
- 'maxlag' => array (
- ApiBase :: PARAM_TYPE => 'integer'
+ 'maxlag' => array(
+ ApiBase::PARAM_TYPE => 'integer'
),
- 'smaxage' => array (
- ApiBase :: PARAM_TYPE => 'integer',
- ApiBase :: PARAM_DFLT => 0
+ 'smaxage' => array(
+ ApiBase::PARAM_TYPE => 'integer',
+ ApiBase::PARAM_DFLT => 0
),
- 'maxage' => array (
- ApiBase :: PARAM_TYPE => 'integer',
- ApiBase :: PARAM_DFLT => 0
+ 'maxage' => array(
+ ApiBase::PARAM_TYPE => 'integer',
+ ApiBase::PARAM_DFLT => 0
),
'requestid' => null,
);
* See ApiBase for description.
*/
public function getParamDescription() {
- return array (
+ return array(
'format' => 'The format of the output',
'action' => 'What action you would like to perform',
'version' => 'When showing help, include version for each module',
* See ApiBase for description.
*/
public function getDescription() {
- return array (
+ return array(
'',
'',
'******************************************************************',
);
}
- public function getPossibleErrors() {
+ public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'readonlytext' ),
array( 'code' => 'unknown_format', 'info' => 'Unrecognized format: format' ),
array( 'code' => 'unknown_action', 'info' => 'The API requires a valid action parameter' ),
array( 'code' => 'maxlag', 'info' => 'Waiting for host: x seconds lagged' ),
array( 'code' => 'maxlag', 'info' => 'Waiting for a database server: x seconds lagged' ),
- ) );
+ ) );
}
/**
$this->getMain()->getShowVersions() );
if ( $wgAPICacheHelp ) {
$cached = $wgMemc->get( $key );
- if ( $cached )
+ if ( $cached ) {
return $cached;
+ }
}
$retval = $this->reallyMakeHelpMsg();
- if ( $wgAPICacheHelp )
+ if ( $wgAPICacheHelp ) {
$wgMemc->set( $key, $retval, $wgAPICacheHelpTimeout );
+ }
return $retval;
}
public function reallyMakeHelpMsg() {
-
$this->mPrinter->setHelp();
// Use parent to make default message for the main module
- $msg = parent :: makeHelpMsg();
+ $msg = parent::makeHelpMsg();
$astriks = str_repeat( '*** ', 10 );
$msg .= "\n\n$astriks Modules $astriks\n\n";
$module = new $this->mModules[$moduleName] ( $this, $moduleName );
$msg .= self::makeHelpMsgHeader( $module, 'action' );
$msg2 = $module->makeHelpMsg();
- if ( $msg2 !== false )
+ if ( $msg2 !== false ) {
$msg .= $msg2;
+ }
$msg .= "\n";
}
$msg .= "\n$astriks Permissions $astriks\n\n";
- foreach ( self :: $mRights as $right => $rightMsg ) {
+ foreach ( self::$mRights as $right => $rightMsg ) {
$groups = User::getGroupsWithPermission( $right );
$msg .= "* " . $right . " *\n " . wfMsgReplaceArgs( $rightMsg[ 'msg' ], $rightMsg[ 'params' ] ) .
- "\nGranted to:\n " . str_replace( "*", "all", implode( ", ", $groups ) ) . "\n";
+ "\nGranted to:\n " . str_replace( '*', 'all', implode( ', ', $groups ) ) . "\n";
}
$module = $this->createPrinterByName( $formatName );
$msg .= self::makeHelpMsgHeader( $module, 'format' );
$msg2 = $module->makeHelpMsg();
- if ( $msg2 !== false )
+ if ( $msg2 !== false ) {
$msg .= $msg2;
+ }
$msg .= "\n";
}
public static function makeHelpMsgHeader( $module, $paramName ) {
$modulePrefix = $module->getModulePrefix();
- if ( strval( $modulePrefix ) !== '' )
+ if ( strval( $modulePrefix ) !== '' ) {
$modulePrefix = "($modulePrefix) ";
+ }
return "* $paramName={$module->getModuleName()} $modulePrefix*";
}
* OBSOLETE, use canApiHighLimits() instead
*/
public function isBot() {
- if ( !isset ( $this->mIsBot ) ) {
+ if ( !isset( $this->mIsBot ) ) {
global $wgUser;
$this->mIsBot = $wgUser->isAllowed( 'bot' );
}
* OBSOLETE, use canApiHighLimits() instead
*/
public function isSysop() {
- if ( !isset ( $this->mIsSysop ) ) {
+ if ( !isset( $this->mIsSysop ) ) {
global $wgUser;
$this->mIsSysop = in_array( 'sysop', $wgUser->getGroups() );
}
$vers = array ();
$vers[] = 'MediaWiki: ' . SpecialVersion::getVersion() . "\n http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/";
$vers[] = __CLASS__ . ': $Id$';
- $vers[] = ApiBase :: getBaseVersion();
- $vers[] = ApiFormatBase :: getBaseVersion();
- $vers[] = ApiQueryBase :: getBaseVersion();
+ $vers[] = ApiBase::getBaseVersion();
+ $vers[] = ApiFormatBase::getBaseVersion();
+ $vers[] = ApiQueryBase::getBaseVersion();
return $vers;
}
* classes who wish to add their own modules to their lexicon or override the
* behavior of inherent ones.
*
- * @access protected
* @param $mdlName String The identifier for this module.
* @param $mdlClass String The class where this module is implemented.
*/
* Add or overwrite an output format for this ApiMain. Intended for use by extending
* classes who wish to add to or modify current formatters.
*
- * @access protected
* @param $fmtName The identifier for this format.
* @param $fmtClass The class implementing this format.
*/
private $mExtraData;
public function __construct( $message, $codestr, $code = 0, $extradata = null ) {
- parent :: __construct( $message, $code );
+ parent::__construct( $message, $code );
$this->mCodestr = $codestr;
$this->mExtraData = $extradata;
}
+
public function getCodeString() {
return $this->mCodestr;
}
+
public function getMessageArray() {
- $result = array (
- 'code' => $this->mCodestr,
- 'info' => $this->getMessage()
+ $result = array(
+ 'code' => $this->mCodestr,
+ 'info' => $this->getMessage()
);
- if ( is_array( $this->mExtraData ) )
+ if ( is_array( $this->mExtraData ) ) {
$result = array_merge( $result, $this->mExtraData );
+ }
return $result;
}
+
public function __toString() {
return "{$this->getCodeString()}: {$this->getMessage()}";
}
<?php
-/*
+/**
* Created on Oct 13, 2006
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( "ApiBase.php" );
+ require_once( "ApiBase.php" );
}
/**
class ApiOpenSearch extends ApiBase {
public function __construct( $main, $action ) {
- parent :: __construct( $main, $action );
+ parent::__construct( $main, $action );
}
public function getCustomPrinter() {
$suggest = $params['suggest'];
// MWSuggest or similar hit
- if ( $suggest && !$wgEnableOpenSearchSuggest )
+ if ( $suggest && !$wgEnableOpenSearchSuggest ) {
$srchres = array();
- else {
+ } else {
// Open search results may be stored for a very long
// time
$this->getMain()->setCacheMaxAge( $wgSearchSuggestCacheExpiry );
}
public function getAllowedParams() {
- return array (
+ return array(
'search' => null,
'limit' => array(
- ApiBase :: PARAM_DFLT => 10,
- ApiBase :: PARAM_TYPE => 'limit',
- ApiBase :: PARAM_MIN => 1,
- ApiBase :: PARAM_MAX => 100,
- ApiBase :: PARAM_MAX2 => 100
+ ApiBase::PARAM_DFLT => 10,
+ ApiBase::PARAM_TYPE => 'limit',
+ ApiBase::PARAM_MIN => 1,
+ ApiBase::PARAM_MAX => 100,
+ ApiBase::PARAM_MAX2 => 100
),
'namespace' => array(
- ApiBase :: PARAM_DFLT => NS_MAIN,
- ApiBase :: PARAM_TYPE => 'namespace',
- ApiBase :: PARAM_ISMULTI => true
+ ApiBase::PARAM_DFLT => NS_MAIN,
+ ApiBase::PARAM_TYPE => 'namespace',
+ ApiBase::PARAM_ISMULTI => true
),
'suggest' => false,
);
}
public function getParamDescription() {
- return array (
+ return array(
'search' => 'Search string',
'limit' => 'Maximum amount of results to return',
'namespace' => 'Namespaces to search',
}
protected function getExamples() {
- return array (
+ return array(
'api.php?action=opensearch&search=Te'
);
}
<?php
-/*
+/**
* Created on Sep 24, 2006
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( 'ApiQueryBase.php' );
+ require_once( 'ApiQueryBase.php' );
}
/**
* @param $resolveRedirects bool Whether redirects should be resolved
*/
public function __construct( $query, $resolveRedirects = false ) {
- parent :: __construct( $query, 'query' );
+ parent::__construct( $query, 'query' );
- $this->mAllPages = array ();
+ $this->mAllPages = array();
$this->mTitles = array();
- $this->mGoodTitles = array ();
- $this->mMissingTitles = array ();
- $this->mInvalidTitles = array ();
- $this->mMissingPageIDs = array ();
- $this->mRedirectTitles = array ();
- $this->mNormalizedTitles = array ();
- $this->mInterwikiTitles = array ();
+ $this->mGoodTitles = array();
+ $this->mMissingTitles = array();
+ $this->mInvalidTitles = array();
+ $this->mMissingPageIDs = array();
+ $this->mRedirectTitles = array();
+ $this->mNormalizedTitles = array();
+ $this->mInterwikiTitles = array();
$this->mGoodRevIDs = array();
$this->mMissingRevIDs = array();
- $this->mRequestedPageFields = array ();
+ $this->mRequestedPageFields = array();
$this->mResolveRedirects = $resolveRedirects;
- if ( $resolveRedirects )
+ if ( $resolveRedirects ) {
$this->mPendingRedirectIDs = array();
+ }
- $this->mFakePageId = - 1;
+ $this->mFakePageId = -1;
}
/**
public function getPageTableFields() {
// Ensure we get minimum required fields
// DON'T change this order
- $pageFlds = array (
+ $pageFlds = array(
'page_namespace' => null,
'page_title' => null,
'page_id' => null,
);
- if ( $this->mResolveRedirects )
+ if ( $this->mResolveRedirects ) {
$pageFlds['page_is_redirect'] = null;
+ }
// only store non-default fields
$this->mRequestedPageFields = array_diff_key( $this->mRequestedPageFields, $pageFlds );
// Only one of the titles/pageids/revids is allowed at the same time
$dataSource = null;
- if ( isset ( $params['titles'] ) )
+ if ( isset( $params['titles'] ) ) {
$dataSource = 'titles';
- if ( isset ( $params['pageids'] ) ) {
- if ( isset ( $dataSource ) )
+ }
+ if ( isset( $params['pageids'] ) ) {
+ if ( isset( $dataSource ) ) {
$this->dieUsage( "Cannot use 'pageids' at the same time as '$dataSource'", 'multisource' );
+ }
$dataSource = 'pageids';
}
- if ( isset ( $params['revids'] ) ) {
- if ( isset ( $dataSource ) )
+ if ( isset( $params['revids'] ) ) {
+ if ( isset( $dataSource ) ) {
$this->dieUsage( "Cannot use 'revids' at the same time as '$dataSource'", 'multisource' );
+ }
$dataSource = 'revids';
}
switch ( $dataSource ) {
- case 'titles' :
+ case 'titles':
$this->initFromTitles( $params['titles'] );
break;
- case 'pageids' :
+ case 'pageids':
$this->initFromPageIds( $params['pageids'] );
break;
- case 'revids' :
- if ( $this->mResolveRedirects )
+ case 'revids':
+ if ( $this->mResolveRedirects ) {
$this->setWarning( 'Redirect resolution cannot be used together with the revids= parameter. ' .
'Any redirects the revids= point to have not been resolved.' );
+ }
$this->mResolveRedirects = false;
$this->initFromRevIDs( $params['revids'] );
break;
- default :
+ default:
// Do nothing - some queries do not need any of the data sources.
break;
}
* @param $row Result row
*/
public function processDbRow( $row ) {
-
// Store Title object in various data structures
- $title = Title :: makeTitle( $row->page_namespace, $row->page_title );
+ $title = Title::makeTitle( $row->page_namespace, $row->page_title );
$pageId = intval( $row->page_id );
$this->mAllPages[$row->page_namespace][$row->page_title] = $pageId;
$this->mGoodTitles[$pageId] = $title;
}
- foreach ( $this->mRequestedPageFields as $fieldName => & $fieldValues )
+ foreach ( $this->mRequestedPageFields as $fieldName => &$fieldValues ) {
$fieldValues[$pageId] = $row-> $fieldName;
+ }
}
/**
* @param $titles array of Title objects or strings
*/
private function initFromTitles( $titles ) {
-
// Get validated and normalized title objects
$linkBatch = $this->processTitlesArray( $titles );
- if ( $linkBatch->isEmpty() )
+ if ( $linkBatch->isEmpty() ) {
return;
+ }
$db = $this->getDB();
$set = $linkBatch->constructSet( 'page', $db );
$this->profileDBOut();
// Hack: get the ns:titles stored in array(ns => array(titles)) format
- $this->initFromQueryResult( $db, $res, $linkBatch->data, true ); // process Titles
+ $this->initFromQueryResult( $db, $res, $linkBatch->data, true ); // process Titles
// Resolve any found redirects
$this->resolvePendingRedirects();
* @param $pageids array of page IDs
*/
private function initFromPageIds( $pageids ) {
- if ( !count( $pageids ) )
+ if ( !count( $pageids ) ) {
return;
+ }
$pageids = array_map( 'intval', $pageids ); // paranoia
- $set = array (
+ $set = array(
'page_id' => $pageids
);
$db = $this->getDB();
* If false, treat it as an array of [pageIDs]
*/
private function initFromQueryResult( $db, $res, &$remaining = null, $processTitles = null ) {
- if ( !is_null( $remaining ) && is_null( $processTitles ) )
- ApiBase :: dieDebug( __METHOD__, 'Missing $processTitles parameter when $remaining is provided' );
+ if ( !is_null( $remaining ) && is_null( $processTitles ) ) {
+ ApiBase::dieDebug( __METHOD__, 'Missing $processTitles parameter when $remaining is provided' );
+ }
while ( $row = $db->fetchObject( $res ) ) {
-
$pageId = intval( $row->page_id );
// Remove found page from the list of remaining items
if ( isset( $remaining ) ) {
- if ( $processTitles )
- unset ( $remaining[$row->page_namespace][$row->page_title] );
- else
- unset ( $remaining[$pageId] );
+ if ( $processTitles ) {
+ unset( $remaining[$row->page_namespace][$row->page_title] );
+ } else {
+ unset( $remaining[$pageId] );
+ }
}
// Store any extra fields requested by modules
// The remaining titles in $remaining are non-existent pages
foreach ( $remaining as $ns => $dbkeys ) {
foreach ( $dbkeys as $dbkey => $unused ) {
- $title = Title :: makeTitle( $ns, $dbkey );
+ $title = Title::makeTitle( $ns, $dbkey );
$this->mAllPages[$ns][$dbkey] = $this->mFakePageId;
$this->mMissingTitles[$this->mFakePageId] = $title;
$this->mFakePageId--;
$this->mTitles[] = $title;
}
}
- }
- else
- {
+ } else {
// The remaining pageids do not exist
- if ( !$this->mMissingPageIDs )
+ if ( !$this->mMissingPageIDs ) {
$this->mMissingPageIDs = array_keys( $remaining );
- else
+ } else {
$this->mMissingPageIDs = array_merge( $this->mMissingPageIDs, array_keys( $remaining ) );
+ }
}
}
}
* @param $revids array of revision IDs
*/
private function initFromRevIDs( $revids ) {
-
- if ( !count( $revids ) )
+ if ( !count( $revids ) ) {
return;
+ }
$revids = array_map( 'intval', $revids ); // paranoia
$db = $this->getDB();
* have been resolved.
*/
private function resolvePendingRedirects() {
-
if ( $this->mResolveRedirects ) {
$db = $this->getDB();
$pageFlds = $this->getPageTableFields();
// Repeat until all redirects have been resolved
// The infinite loop is prevented by keeping all known pages in $this->mAllPages
while ( $this->mPendingRedirectIDs ) {
-
// Resolve redirects by querying the pagelinks table, and repeat the process
// Create a new linkBatch object for the next pass
$linkBatch = $this->getRedirectTargets();
- if ( $linkBatch->isEmpty() )
+ if ( $linkBatch->isEmpty() ) {
break;
+ }
$set = $linkBatch->constructSet( 'page', $db );
- if ( $set === false )
+ if ( $set === false ) {
break;
+ }
// Get pageIDs data from the `page` table
$this->profileDBIn();
$db = $this->getDB();
$this->profileDBIn();
- $res = $db->select( 'redirect', array(
+ $res = $db->select(
+ 'redirect',
+ array(
'rd_from',
'rd_namespace',
'rd_title'
);
$this->profileDBOut();
- while ( $row = $db->fetchObject( $res ) )
- {
+ while ( $row = $db->fetchObject( $res ) ) {
$rdfrom = intval( $row->rd_from );
$from = $this->mPendingRedirectIDs[$rdfrom]->getPrefixedText();
$to = Title::makeTitle( $row->rd_namespace, $row->rd_title )->getPrefixedText();
unset( $this->mPendingRedirectIDs[$rdfrom] );
- if ( !isset( $this->mAllPages[$row->rd_namespace][$row->rd_title] ) )
+ if ( !isset( $this->mAllPages[$row->rd_namespace][$row->rd_title] ) ) {
$lb->add( $row->rd_namespace, $row->rd_title );
+ }
$this->mRedirectTitles[$from] = $to;
}
$db->freeResult( $res );
- if ( $this->mPendingRedirectIDs )
- {
+ if ( $this->mPendingRedirectIDs ) {
// We found pages that aren't in the redirect table
// Add them
- foreach ( $this->mPendingRedirectIDs as $id => $title )
- {
+ foreach ( $this->mPendingRedirectIDs as $id => $title ) {
$article = new Article( $title );
$rt = $article->insertRedirect();
- if ( !$rt )
+ if ( !$rt ) {
// What the hell. Let's just ignore this
continue;
+ }
$lb->addObj( $rt );
$this->mRedirectTitles[$title->getPrefixedText()] = $rt->getPrefixedText();
unset( $this->mPendingRedirectIDs[$id] );
* @return LinkBatch
*/
private function processTitlesArray( $titles ) {
-
$linkBatch = new LinkBatch();
foreach ( $titles as $title ) {
-
- $titleObj = is_string( $title ) ? Title :: newFromText( $title ) : $title;
- if ( !$titleObj )
- {
+ $titleObj = is_string( $title ) ? Title::newFromText( $title ) : $title;
+ if ( !$titleObj ) {
// Handle invalid titles gracefully
$this->mAllpages[0][$title] = $this->mFakePageId;
$this->mInvalidTitles[$this->mFakePageId] = $title;
// This title is an interwiki link.
$this->mInterwikiTitles[$titleObj->getPrefixedText()] = $iw;
} else {
-
// Validation
- if ( $titleObj->getNamespace() < 0 )
- $this->setWarning( "No support for special pages has been implemented" );
- else
+ if ( $titleObj->getNamespace() < 0 ) {
+ $this->setWarning( 'No support for special pages has been implemented' );
+ } else {
$linkBatch->addObj( $titleObj );
+ }
}
// Make sure we remember the original title that was
}
protected function getAllowedParams() {
- return array (
- 'titles' => array (
- ApiBase :: PARAM_ISMULTI => true
+ return array(
+ 'titles' => array(
+ ApiBase::PARAM_ISMULTI => true
),
- 'pageids' => array (
- ApiBase :: PARAM_TYPE => 'integer',
- ApiBase :: PARAM_ISMULTI => true
+ 'pageids' => array(
+ ApiBase::PARAM_TYPE => 'integer',
+ ApiBase::PARAM_ISMULTI => true
),
- 'revids' => array (
- ApiBase :: PARAM_TYPE => 'integer',
- ApiBase :: PARAM_ISMULTI => true
+ 'revids' => array(
+ ApiBase::PARAM_TYPE => 'integer',
+ ApiBase::PARAM_ISMULTI => true
)
);
}
protected function getParamDescription() {
- return array (
+ return array(
'titles' => 'A list of titles to work on',
'pageids' => 'A list of page IDs to work on',
'revids' => 'A list of revision IDs to work on'
<?php
-/*
+/**
* Created on Dec 01, 2007
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2008 Roan Kattouw <Firstname>.<Lastname>@home.nl
+ * Copyright © 2008 Roan Kattouw <Firstname>.<Lastname>@home.nl
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( "ApiBase.php" );
+ require_once( "ApiBase.php" );
}
/**
class ApiParamInfo extends ApiBase {
public function __construct( $main, $action ) {
- parent :: __construct( $main, $action );
+ parent::__construct( $main, $action );
}
public function execute() {
$result = $this->getResult();
$queryObj = new ApiQuery( $this->getMain(), 'query' );
$r = array();
- if ( is_array( $params['modules'] ) )
- {
+ if ( is_array( $params['modules'] ) ) {
$modArr = $this->getMain()->getModules();
$r['modules'] = array();
- foreach ( $params['modules'] as $m )
- {
- if ( !isset( $modArr[$m] ) )
- {
+ foreach ( $params['modules'] as $m ) {
+ if ( !isset( $modArr[$m] ) ) {
$r['modules'][] = array( 'name' => $m, 'missing' => '' );
continue;
}
}
$result->setIndexedTagName( $r['modules'], 'module' );
}
- if ( is_array( $params['querymodules'] ) )
- {
+ if ( is_array( $params['querymodules'] ) ) {
$qmodArr = $queryObj->getModules();
$r['querymodules'] = array();
- foreach ( $params['querymodules'] as $qm )
- {
- if ( !isset( $qmodArr[$qm] ) )
- {
+ foreach ( $params['querymodules'] as $qm ) {
+ if ( !isset( $qmodArr[$qm] ) ) {
$r['querymodules'][] = array( 'name' => $qm, 'missing' => '' );
continue;
}
}
$result->setIndexedTagName( $r['querymodules'], 'module' );
}
- if ( $params['mainmodule'] )
+ if ( $params['mainmodule'] ) {
$r['mainmodule'] = $this->getClassInfo( $this->getMain() );
- if ( $params['pagesetmodule'] )
- {
+ }
+ if ( $params['pagesetmodule'] ) {
$pageSet = new ApiPageSet( $queryObj );
$r['pagesetmodule'] = $this->getClassInfo( $pageSet );
}
$result->addValue( null, $this->getModuleName(), $r );
}
- function getClassInfo( $obj )
- {
+ function getClassInfo( $obj ) {
$result = $this->getResult();
$retval['classname'] = get_class( $obj );
$retval['description'] = implode( "\n", (array)$obj->getDescription() );
$retval['version'] = implode( "\n", (array)$obj->getVersion() );
$retval['prefix'] = $obj->getModulePrefix();
- if ( $obj->isReadMode() )
+ if ( $obj->isReadMode() ) {
$retval['readrights'] = '';
- if ( $obj->isWriteMode() )
+ }
+ if ( $obj->isWriteMode() ) {
$retval['writerights'] = '';
- if ( $obj->mustBePosted() )
+ }
+ if ( $obj->mustBePosted() ) {
$retval['mustbeposted'] = '';
- if ( $obj instanceof ApiQueryGeneratorBase )
+ }
+ if ( $obj instanceof ApiQueryGeneratorBase ) {
$retval['generator'] = '';
+ }
$allowedParams = $obj->getFinalParams();
- if ( !is_array( $allowedParams ) )
+ if ( !is_array( $allowedParams ) ) {
return $retval;
-
+ }
+
$retval['parameters'] = array();
$paramDesc = $obj->getFinalParamDescription();
- foreach ( $allowedParams as $n => $p )
- {
+ foreach ( $allowedParams as $n => $p ) {
$a = array( 'name' => $n );
- if ( isset( $paramDesc[$n] ) )
+ if ( isset( $paramDesc[$n] ) ) {
$a['description'] = implode( "\n", (array)$paramDesc[$n] );
- if ( isset( $p[ApiBase::PARAM_DEPRECATED] ) && $p[ApiBase::PARAM_DEPRECATED] )
+ }
+ if ( isset( $p[ApiBase::PARAM_DEPRECATED] ) && $p[ApiBase::PARAM_DEPRECATED] ) {
$a['deprecated'] = '';
- if ( !is_array( $p ) )
- {
- if ( is_bool( $p ) )
- {
+ }
+ if ( !is_array( $p ) ) {
+ if ( is_bool( $p ) ) {
$a['type'] = 'bool';
$a['default'] = ( $p ? 'true' : 'false' );
- }
- else if ( is_string( $p ) || is_null( $p ) )
- {
+ } elseif ( is_string( $p ) || is_null( $p ) ) {
$a['type'] = 'string';
$a['default'] = strval( $p );
- }
- else if ( is_int( $p ) )
- {
+ } elseif ( is_int( $p ) ) {
$a['type'] = 'integer';
$a['default'] = intval( $p );
}
continue;
}
- if ( isset( $p[ApiBase::PARAM_DFLT] ) )
+ if ( isset( $p[ApiBase::PARAM_DFLT] ) ) {
$a['default'] = $p[ApiBase::PARAM_DFLT];
- if ( isset( $p[ApiBase::PARAM_ISMULTI] ) )
- if ( $p[ApiBase::PARAM_ISMULTI] )
- {
+ }
+ if ( isset( $p[ApiBase::PARAM_ISMULTI] ) ) {
+ if ( $p[ApiBase::PARAM_ISMULTI] ) {
$a['multi'] = '';
$a['limit'] = $this->getMain()->canApiHighLimits() ?
ApiBase::LIMIT_SML2 :
ApiBase::LIMIT_SML1;
}
+ }
- if ( isset( $p[ApiBase::PARAM_ALLOW_DUPLICATES] ) )
- if ( $p[ApiBase::PARAM_ALLOW_DUPLICATES] )
+ if ( isset( $p[ApiBase::PARAM_ALLOW_DUPLICATES] ) ) {
+ if ( $p[ApiBase::PARAM_ALLOW_DUPLICATES] ) {
$a['allowsduplicates'] = '';
+ }
+ }
- if ( isset( $p[ApiBase::PARAM_TYPE] ) )
- {
+ if ( isset( $p[ApiBase::PARAM_TYPE] ) ) {
$a['type'] = $p[ApiBase::PARAM_TYPE];
- if ( is_array( $a['type'] ) )
+ if ( is_array( $a['type'] ) ) {
$result->setIndexedTagName( $a['type'], 't' );
+ }
}
- if ( isset( $p[ApiBase::PARAM_MAX] ) )
+ if ( isset( $p[ApiBase::PARAM_MAX] ) ) {
$a['max'] = $p[ApiBase::PARAM_MAX];
- if ( isset( $p[ApiBase::PARAM_MAX2] ) )
+ }
+ if ( isset( $p[ApiBase::PARAM_MAX2] ) ) {
$a['highmax'] = $p[ApiBase::PARAM_MAX2];
- if ( isset( $p[ApiBase::PARAM_MIN] ) )
+ }
+ if ( isset( $p[ApiBase::PARAM_MIN] ) ) {
$a['min'] = $p[ApiBase::PARAM_MIN];
+ }
$retval['parameters'][] = $a;
}
$result->setIndexedTagName( $retval['parameters'], 'param' );
-
+
// Errors
$retval['errors'] = $this->parseErrors( $obj->getPossibleErrors() );
-
+
$result->setIndexedTagName( $retval['errors'], 'error' );
-
+
return $retval;
}
}
public function getAllowedParams() {
- return array (
+ return array(
'modules' => array(
- ApiBase :: PARAM_ISMULTI => true
+ ApiBase::PARAM_ISMULTI => true
),
'querymodules' => array(
- ApiBase :: PARAM_ISMULTI => true
+ ApiBase::PARAM_ISMULTI => true
),
'mainmodule' => false,
'pagesetmodule' => false,
}
public function getParamDescription() {
- return array (
+ return array(
'modules' => 'List of module names (value of the action= parameter)',
'querymodules' => 'List of query module names (value of prop=, meta= or list= parameter)',
'mainmodule' => 'Get information about the main (top-level) module as well',
}
protected function getExamples() {
- return array (
+ return array(
'api.php?action=paraminfo&modules=parse&querymodules=allpages|siteinfo'
);
}
<?php
-/*
+/**
* Created on Dec 01, 2007
*
* API for MediaWiki 1.8+
*
- * Copyright (C) 2007 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2007 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( "ApiBase.php" );
+ require_once( "ApiBase.php" );
}
/**
class ApiParse extends ApiBase {
public function __construct( $main, $action ) {
- parent :: __construct( $main, $action );
+ parent::__construct( $main, $action );
}
public function execute() {
$title = $params['title'];
$page = $params['page'];
$oldid = $params['oldid'];
- if ( !is_null( $page ) && ( !is_null( $text ) || $title != "API" ) )
- $this->dieUsage( "The page parameter cannot be used together with the text and title parameters", 'params' );
+ if ( !is_null( $page ) && ( !is_null( $text ) || $title != 'API' ) ) {
+ $this->dieUsage( 'The page parameter cannot be used together with the text and title parameters', 'params' );
+ }
$prop = array_flip( $params['prop'] );
$revid = false;
$popts->setTidy( true );
$popts->enableLimitReport();
$redirValues = null;
- if ( !is_null( $oldid ) || !is_null( $page ) )
- {
- if ( !is_null( $oldid ) )
- {
+ if ( !is_null( $oldid ) || !is_null( $page ) ) {
+ if ( !is_null( $oldid ) ) {
// Don't use the parser cache
$rev = Revision::newFromID( $oldid );
- if ( !$rev )
+ if ( !$rev ) {
$this->dieUsage( "There is no revision ID $oldid", 'missingrev' );
- if ( !$rev->userCan( Revision::DELETED_TEXT ) )
+ }
+ if ( !$rev->userCan( Revision::DELETED_TEXT ) ) {
$this->dieUsage( "You don't have permission to view deleted revisions", 'permissiondenied' );
+ }
$text = $rev->getText( Revision::FOR_THIS_USER );
$titleObj = $rev->getTitle();
$wgTitle = $titleObj;
$p_result = $wgParser->parse( $text, $titleObj, $popts );
- }
- else
- {
- if ( $params['redirects'] )
- {
+ } else {
+ if ( $params['redirects'] ) {
$req = new FauxRequest( array(
'action' => 'query',
'redirects' => '',
$data = $main->getResultData();
$redirValues = @$data['query']['redirects'];
$to = $page;
- foreach ( (array)$redirValues as $r )
+ foreach ( (array)$redirValues as $r ) {
$to = $r['to'];
- }
- else
+ }
+ } else {
$to = $page;
+ }
$titleObj = Title::newFromText( $to );
- if ( !$titleObj )
+ if ( !$titleObj ) {
$this->dieUsage( "The page you specified doesn't exist", 'missingtitle' );
+ }
$articleObj = new Article( $titleObj );
- if ( isset( $prop['revid'] ) )
+ if ( isset( $prop['revid'] ) ) {
$oldid = $articleObj->getRevIdFetched();
+ }
// Try the parser cache first
$p_result = false;
$pcache = ParserCache::singleton();
- if ( $wgEnableParserCache )
+ if ( $wgEnableParserCache ) {
$p_result = $pcache->get( $articleObj, $wgUser );
- if ( !$p_result )
- {
+ }
+ if ( !$p_result ) {
$p_result = $wgParser->parse( $articleObj->getContent(), $titleObj, $popts );
-
- if ( $wgEnableParserCache )
+
+ if ( $wgEnableParserCache ) {
$pcache->save( $p_result, $articleObj, $popts );
+ }
}
}
- }
- else
- {
+ } else {
$titleObj = Title::newFromText( $title );
- if ( !$titleObj )
- $titleObj = Title::newFromText( "API" );
+ if ( !$titleObj ) {
+ $titleObj = Title::newFromText( 'API' );
+ }
$wgTitle = $titleObj;
- if ( $params['pst'] || $params['onlypst'] )
+ if ( $params['pst'] || $params['onlypst'] ) {
$text = $wgParser->preSaveTransform( $text, $titleObj, $wgUser, $popts );
- if ( $params['onlypst'] )
- {
+ }
+ if ( $params['onlypst'] ) {
// Build a result and bail out
$result_array['text'] = array();
$this->getResult()->setContent( $result_array['text'], $text );
// Return result
$result = $this->getResult();
$result_array = array();
- if ( $params['redirects'] && !is_null( $redirValues ) )
+ if ( $params['redirects'] && !is_null( $redirValues ) ) {
$result_array['redirects'] = $redirValues;
-
+ }
+
if ( isset( $prop['text'] ) ) {
$result_array['text'] = array();
$result->setContent( $result_array['text'], $p_result->getText() );
}
-
+
if ( !is_null( $params['summary'] ) ) {
$result_array['parsedsummary'] = array();
$result->setContent( $result_array['parsedsummary'], $wgUser->getSkin()->formatComment( $params['summary'], $titleObj ) );
}
-
- if ( isset( $prop['langlinks'] ) )
+
+ if ( isset( $prop['langlinks'] ) ) {
$result_array['langlinks'] = $this->formatLangLinks( $p_result->getLanguageLinks() );
- if ( isset( $prop['categories'] ) )
+ }
+ if ( isset( $prop['categories'] ) ) {
$result_array['categories'] = $this->formatCategoryLinks( $p_result->getCategories() );
- if ( isset( $prop['links'] ) )
+ }
+ if ( isset( $prop['links'] ) ) {
$result_array['links'] = $this->formatLinks( $p_result->getLinks() );
- if ( isset( $prop['templates'] ) )
+ }
+ if ( isset( $prop['templates'] ) ) {
$result_array['templates'] = $this->formatLinks( $p_result->getTemplates() );
- if ( isset( $prop['images'] ) )
+ }
+ if ( isset( $prop['images'] ) ) {
$result_array['images'] = array_keys( $p_result->getImages() );
- if ( isset( $prop['externallinks'] ) )
+ }
+ if ( isset( $prop['externallinks'] ) ) {
$result_array['externallinks'] = array_keys( $p_result->getExternalLinks() );
- if ( isset( $prop['sections'] ) )
+ }
+ if ( isset( $prop['sections'] ) ) {
$result_array['sections'] = $p_result->getSections();
- if ( isset( $prop['displaytitle'] ) )
+ }
+ if ( isset( $prop['displaytitle'] ) ) {
$result_array['displaytitle'] = $p_result->getDisplayTitle() ?
$p_result->getDisplayTitle() :
$titleObj->getPrefixedText();
-
- if ( isset( $prop['headitems'] ) )
+ }
+
+ if ( isset( $prop['headitems'] ) ) {
$result_array['headitems'] = $this->formatHeadItems( $p_result->getHeadItems() );
-
+ }
+
if ( isset( $prop['headhtml'] ) ) {
$out = new OutputPage;
$out->addParserOutputNoText( $p_result );
$result_array['headhtml'] = array();
$result->setContent( $result_array['headhtml'], $out->headElement( $wgUser->getSkin() ) );
}
-
- if ( !is_null( $oldid ) )
+
+ if ( !is_null( $oldid ) ) {
$result_array['revid'] = intval( $oldid );
+ }
$result_mapping = array(
'redirects' => 'r',
$entry = array();
$entry['ns'] = $ns;
$this->getResult()->setContent( $entry, Title::makeTitle( $ns, $title )->getFullText() );
- if ( $id != 0 )
+ if ( $id != 0 ) {
$entry['exists'] = '';
+ }
$result[] = $entry;
}
}
private function setIndexedTagNames( &$array, $mapping ) {
foreach ( $mapping as $key => $name ) {
- if ( isset( $array[$key] ) )
+ if ( isset( $array[$key] ) ) {
$this->getResult()->setIndexedTagName( $array[$key], $name );
+ }
}
}
public function getAllowedParams() {
- return array (
+ return array(
'title' => array(
- ApiBase :: PARAM_DFLT => 'API',
+ ApiBase::PARAM_DFLT => 'API',
),
'text' => null,
'summary' => null,
'redirects' => false,
'oldid' => null,
'prop' => array(
- ApiBase :: PARAM_DFLT => 'text|langlinks|categories|links|templates|images|externallinks|sections|revid|displaytitle',
- ApiBase :: PARAM_ISMULTI => true,
- ApiBase :: PARAM_TYPE => array(
+ ApiBase::PARAM_DFLT => 'text|langlinks|categories|links|templates|images|externallinks|sections|revid|displaytitle',
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_TYPE => array(
'text',
'langlinks',
'categories',
}
public function getParamDescription() {
- return array (
+ return array(
'text' => 'Wikitext to parse',
'summary' => 'Summary to parse',
'redirects' => 'If the page parameter is set to a redirect, resolve it',
public function getDescription() {
return 'This module parses wikitext and returns parser output';
}
-
+
public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'code' => 'params', 'info' => 'The page parameter cannot be used together with the text and title parameters' ),
}
protected function getExamples() {
- return array (
+ return array(
'api.php?action=parse&text={{Project:Sandbox}}'
);
}
<?php
-/*
+/**
* Created on Sep 2, 2008
*
* API for MediaWiki 1.14+
*
- * Copyright (C) 2008 Soxred93 soxred93@gmail.com,
+ * Copyright © 2008 Soxred93 soxred93@gmail.com,
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
class ApiPatrol extends ApiBase {
public function __construct( $main, $action ) {
- parent :: __construct( $main, $action );
+ parent::__construct( $main, $action );
}
/**
*/
public function execute() {
$params = $this->extractRequestParams();
-
- if ( !isset( $params['rcid'] ) )
+
+ if ( !isset( $params['rcid'] ) ) {
$this->dieUsageMsg( array( 'missingparam', 'rcid' ) );
+ }
$rc = RecentChange::newFromID( $params['rcid'] );
- if ( !$rc instanceof RecentChange )
+ if ( !$rc instanceof RecentChange ) {
$this->dieUsageMsg( array( 'nosuchrcid', $params['rcid'] ) );
+ }
$retval = RecentChange::markPatrolled( $params['rcid'] );
-
- if ( $retval )
+
+ if ( $retval ) {
$this->dieUsageMsg( reset( $retval ) );
-
+ }
+
$result = array( 'rcid' => intval( $rc->getAttribute( 'rc_id' ) ) );
ApiQueryBase::addTitleInfo( $result, $rc->getTitle() );
$this->getResult()->addValue( null, $this->getModuleName(), $result );
}
public function getAllowedParams() {
- return array (
+ return array(
'token' => null,
'rcid' => array(
- ApiBase :: PARAM_TYPE => 'integer'
+ ApiBase::PARAM_TYPE => 'integer'
),
);
}
public function getParamDescription() {
- return array (
+ return array(
'token' => 'Patrol token obtained from list=recentchanges',
'rcid' => 'Recentchanges ID to patrol',
);
}
public function getDescription() {
- return array (
+ return array(
'Patrol a page or revision. '
);
}
-
- public function getPossibleErrors() {
+
+ public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'missingparam', 'rcid' ),
array( 'nosuchrcid', 'rcid' ),
- ) );
+ ) );
}
-
+
public function getTokenSalt() {
return '';
}
<?php
-/*
+/**
* Created on Sep 1, 2007
* API for MediaWiki 1.8+
*
- * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
+ * Copyright © 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
if ( !defined( 'MEDIAWIKI' ) ) {
// Eclipse helper - will be ignored in production
- require_once ( "ApiBase.php" );
+ require_once( "ApiBase.php" );
}
/**
class ApiProtect extends ApiBase {
public function __construct( $main, $action ) {
- parent :: __construct( $main, $action );
+ parent::__construct( $main, $action );
}
public function execute() {
$params = $this->extractRequestParams();
$titleObj = null;
- if ( !isset( $params['title'] ) )
+ if ( !isset( $params['title'] ) ) {
$this->dieUsageMsg( array( 'missingparam', 'title' ) );
- if ( empty( $params['protections'] ) )
+ }
+ if ( empty( $params['protections'] ) ) {
$this->dieUsageMsg( array( 'missingparam', 'protections' ) );
+ }
$titleObj = Title::newFromText( $params['title'] );
- if ( !$titleObj )
+ if ( !$titleObj ) {
$this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
+ }
$errors = $titleObj->getUserPermissionsErrors( 'protect', $wgUser );
- if ( $errors )
+ if ( $errors ) {
// We don't care about multiple errors, just report one of them
$this->dieUsageMsg( reset( $errors ) );
+ }
$expiry = (array)$params['expiry'];
- if ( count( $expiry ) != count( $params['protections'] ) )
- {
- if ( count( $expiry ) == 1 )
+ if ( count( $expiry ) != count( $params['protections'] ) ) {
+ if ( count( $expiry ) == 1 ) {
$expiry = array_fill( 0, count( $params['protections'] ), $expiry[0] );
- else
+ } else {
$this->dieUsageMsg( array( 'toofewexpiries', count( $expiry ), count( $params['protections'] ) ) );
+ }
}
-
+
$restrictionTypes = $titleObj->getRestrictionTypes();
-
+
$protections = array();
$expiryarray = array();
$resultProtections = array();
- foreach ( $params['protections'] as $i => $prot )
- {
+ foreach ( $params['protections'] as $i => $prot ) {
$p = explode( '=', $prot );
$protections[$p[0]] = ( $p[1] == 'all' ? '' : $p[1] );
- if ( $titleObj->exists() && $p[0] == 'create' )
+ if ( $titleObj->exists() && $p[0] == 'create' ) {
$this->dieUsageMsg( array( 'create-titleexists' ) );
- if ( !$titleObj->exists() && $p[0] != 'create' )
+ }
+ if ( !$titleObj->exists() && $p[0] != 'create' ) {
$this->dieUsageMsg( array( 'missingtitle-createonly' ) );
+ }
- if ( !in_array( $p[0], $restrictionTypes ) && $p[0] != 'create' )
+ if ( !in_array( $p[0], $restrictionTypes ) && $p[0] != 'create' ) {
$this->dieUsageMsg( array( 'protect-invalidaction', $p[0] ) );
- if ( !in_array( $p[1], $wgRestrictionLevels ) && $p[1] != 'all' )
+ }
+ if ( !in_array( $p[1], $wgRestrictionLevels ) && $p[1] != 'all' ) {
$this->dieUsageMsg( array( 'protect-invalidlevel', $p[1] ) );
+ }
- if ( in_array( $expiry[$i], array( 'infinite', 'indefinite', 'never' ) ) )
+ if ( in_array( $expiry[$i], array( 'infinite', 'indefinite', 'never' ) ) ) {
$expiryarray[$p[0]] = Block::infinity();
- else
- {
+ } else {
$exp = strtotime( $expiry[$i] );
- if ( $exp < 0 || $exp == false )
+ if ( $exp < 0 || $exp == false ) {
$this->dieUsageMsg( array( 'invalidexpiry', $expiry[$i] ) );
+ }
$exp = wfTimestamp( TS_MW, $exp );
- if ( $exp < wfTimestampNow() )
+ if ( $exp < wfTimestampNow() ) {
$this->dieUsageMsg( array( 'pastexpiry', $expiry[$i] ) );
+ }
$expiryarray[$p[0]] = $exp;
}
$resultProtections[] = array( $p[0] => $protections[$p[0]],
$cascade = $params['cascade'];
$articleObj = new Article( $titleObj );
- if ( $params['watch'] )
+ if ( $params['watch'] ) {
$articleObj->doWatch();
- if ( $titleObj->exists() )
+ }
+ if ( $titleObj->exists() ) {
$ok = $articleObj->updateRestrictions( $protections, $params['reason'], $cascade, $expiryarray );
- else
+ } else {
$ok = $titleObj->updateTitleProtection( $protections['create'], $params['reason'], $expiryarray['create'] );
- if ( !$ok )
+ }
+ if ( !$ok ) {
// This is very weird. Maybe the article was deleted or the user was blocked/desysopped in the meantime?
// Just throw an unknown error in this case, as it's very likely to be a race condition
$this->dieUsageMsg( array() );
- $res = array( 'title' => $titleObj->getPrefixedText(), 'reason' => $params['reason'] );
- if ( $cascade )
+ }
+ $res = array(
+ 'title' => $titleObj->getPrefixedText(),
+ 'reason' => $params['reason']
+ );
+ if ( $cascade ) {
$res['cascade'] = '';
+ }
$res['protections'] = $resultProtections;
$this->getResult()->setIndexedTagName( $res['protections'], 'protection' );
$this->getResult()->addValue( null, $this->getModuleName(), $res );
}
public function getAllowedParams() {
- return array (
+ return array(
'title' => null,
'token' => null,
'protections' => array(
- ApiBase :: PARAM_ISMULTI => true
+ ApiBase::PARAM_ISMULTI => true
),
'expiry' => array(
- ApiBase :: PARAM_ISMULTI => true,
- ApiBase :: PARAM_ALLOW_DUPLICATES => true,
- ApiBase :: PARAM_DFLT => 'infinite',
+ ApiBase::PARAM_ISMULTI => true,
+ ApiBase::PARAM_ALLOW_DUPLICATES => true,
+ ApiBase::PARAM_DFLT => 'infinite',
),
'reason' => '',
'cascade' => false,
}
public function getParamDescription() {
- return array (
+ return array(
'title' => 'Title of the page you want to (un)protect.',
'token' => 'A protect token previously retrieved through prop=info',
'protections' => 'Pipe-separated list of protection levels, formatted action=group (e.g. edit=sysop)',
'Change the protection level of a page.'
);
}
-
+
public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(), array(
array( 'missingparam', 'title' ),
array( 'pastexpiry', 'expiry' ),
) );
}
-
+
public function getTokenSalt() {
return null;
}
protected function getExamples() {
- return array (
+ return array(
'api.php?action=protect&title=Main%20Page&token=123ABC&protections=edit=sysop|move=sysop&cascade&expiry=20070901163000|never',
'api.php?action=protect&title=Main%20Page&token=123ABC&protections=edit=all|move=all&reason=Lifting%20restrictions'
);