Merge "Remove extra unneeded whitespace"
[lhc/web/wiklou.git] / includes / api / ApiMain.php
index 880d884..7414a97 100644 (file)
  * @defgroup API API
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) {
-       // Eclipse helper - will be ignored in production
-       require_once( 'ApiBase.php' );
-}
-
 /**
  * This is the main API class, used for both external and internal processing.
  * When executed, it will create the requested formatter object,
@@ -66,6 +61,7 @@ class ApiMain extends ApiBase {
                'paraminfo' => 'ApiParamInfo',
                'rsd' => 'ApiRsd',
                'compare' => 'ApiComparePages',
+               'tokens' => 'ApiTokens',
 
                // Write modules
                'purge' => 'ApiPurge',
@@ -84,6 +80,7 @@ class ApiMain extends ApiBase {
                'patrol' => 'ApiPatrol',
                'import' => 'ApiImport',
                'userrights' => 'ApiUserrights',
+               'options' => 'ApiOptions',
        );
 
        /**
@@ -132,7 +129,7 @@ class ApiMain extends ApiBase {
        private $mPrinter;
 
        private $mModules, $mModuleNames, $mFormats, $mFormatNames;
-       private $mResult, $mAction, $mShowVersions, $mEnableWrite/*, $mRequest*/;
+       private $mResult, $mAction, $mShowVersions, $mEnableWrite;
        private $mInternalMode, $mSquidMaxage, $mModule;
 
        private $mCacheMode = 'private';
@@ -291,6 +288,7 @@ class ApiMain extends ApiBase {
         * $this->setCacheMode('private')
         */
        public function setCachePrivate() {
+               wfDeprecated( __METHOD__, '1.17' );
                $this->setCacheMode( 'private' );
        }
 
@@ -319,6 +317,7 @@ class ApiMain extends ApiBase {
         * @deprecated since 1.17 Use setCacheMode( 'anon-public-user-private' )
         */
        public function setVaryCookie() {
+               wfDeprecated( __METHOD__, '1.17' );
                $this->setCacheMode( 'anon-public-user-private' );
        }
 
@@ -363,7 +362,7 @@ class ApiMain extends ApiBase {
                        $this->executeAction();
                } catch ( Exception $e ) {
                        // Log it
-                       if ( $e instanceof MWException ) {
+                       if ( !( $e instanceof UsageException ) ) {
                                wfDebugLog( 'exception', $e->getLogMessage() );
                        }
 
@@ -404,7 +403,7 @@ class ApiMain extends ApiBase {
        }
 
        protected function sendCacheHeaders() {
-               global $wgUseXVO, $wgOut, $wgVaryOnXFP;
+               global $wgUseXVO, $wgVaryOnXFP;
                $response = $this->getRequest()->response();
 
                if ( $this->mCacheMode == 'private' ) {
@@ -416,11 +415,12 @@ class ApiMain extends ApiBase {
                        $xfp = $wgVaryOnXFP ? ', X-Forwarded-Proto' : '';
                        $response->header( 'Vary: Accept-Encoding, Cookie' . $xfp );
                        if ( $wgUseXVO ) {
+                               $out = $this->getOutput();
                                if ( $wgVaryOnXFP ) {
-                                       $wgOut->addVaryHeader( 'X-Forwarded-Proto' );
+                                       $out->addVaryHeader( 'X-Forwarded-Proto' );
                                }
-                               $response->header( $wgOut->getXVO() );
-                               if ( $wgOut->haveCacheVaryCookies() ) {
+                               $response->header( $out->getXVO() );
+                               if ( $out->haveCacheVaryCookies() ) {
                                        // Logged in, mark this request private
                                        $response->header( 'Cache-Control: private' );
                                        return;
@@ -596,12 +596,18 @@ class ApiMain extends ApiBase {
                $moduleParams = $module->extractRequestParams();
 
                // Die if token required, but not provided (unless there is a gettoken parameter)
+               if ( isset( $moduleParams['gettoken'] ) ) {
+                       $gettoken = $moduleParams['gettoken'];
+               } else {
+                       $gettoken = false;
+               }
+
                $salt = $module->getTokenSalt();
-               if ( $salt !== false && !isset( $moduleParams['gettoken'] ) ) {
+               if ( $salt !== false && !$gettoken ) {
                        if ( !isset( $moduleParams['token'] ) ) {
                                $this->dieUsageMsg( array( 'missingparam', 'token' ) );
                        } else {
-                               if ( !$this->getUser()->matchEditToken( $moduleParams['token'], $salt, $this->getRequest() ) ) {
+                               if ( !$this->getUser()->matchEditToken( $moduleParams['token'], $salt ) ) {
                                        $this->dieUsageMsg( 'sessionfailure' );
                                }
                        }
@@ -709,6 +715,9 @@ class ApiMain extends ApiBase {
                $module->profileOut();
 
                if ( !$this->mInternalMode ) {
+                       //append Debug information
+                       MWDebug::appendDebugInfoToApiResult( $this->getContext(), $this->getResult() );
+
                        // Print result data
                        $this->printResult( false );
                }
@@ -794,7 +803,7 @@ class ApiMain extends ApiBase {
                                'wait until the replication lag is less than the specified value.',
                                'In case of a replag error, a HTTP 503 error is returned, with the message like',
                                '"Waiting for $host: $lag seconds lagged\n".',
-                               'See http://www.mediawiki.org/wiki/Manual:Maxlag_parameter for more information',
+                               'See https://www.mediawiki.org/wiki/Manual:Maxlag_parameter for more information',
                        ),
                        'smaxage' => 'Set the s-maxage header to this many seconds. Errors are never cached',
                        'maxage' => 'Set the max-age header to this many seconds. Errors are never cached',
@@ -816,8 +825,8 @@ class ApiMain extends ApiBase {
                        '**                                                                                                      **',
                        '**                      This is an auto-generated MediaWiki API documentation page                      **',
                        '**                                                                                                      **',
-                       '**                                    Documentation and Examples:                                       **',
-                       '**                                 http://www.mediawiki.org/wiki/API                                    **',
+                       '**                                     Documentation and Examples:                                      **',
+                       '**                                  https://www.mediawiki.org/wiki/API                                  **',
                        '**                                                                                                      **',
                        '**********************************************************************************************************',
                        '',
@@ -832,13 +841,13 @@ class ApiMain extends ApiBase {
                        '                       In the case of an invalid action being passed, these will have a value',
                        '                       of "unknown_action"',
                        '',
-                       '                       For more information see http://www.mediawiki.org/wiki/API:Errors_and_warnings',
+                       '                       For more information see https://www.mediawiki.org/wiki/API:Errors_and_warnings',
                        '',
-                       'Documentation:         http://www.mediawiki.org/wiki/API:Main_page',
-                       'FAQ                    http://www.mediawiki.org/wiki/API:FAQ',
-                       'Mailing list:          http://lists.wikimedia.org/mailman/listinfo/mediawiki-api',
-                       'Api Announcements:     http://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce',
-                       'Bugs & Requests:       http://bugzilla.wikimedia.org/buglist.cgi?component=API&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&order=bugs.delta_ts',
+                       'Documentation:         https://www.mediawiki.org/wiki/API:Main_page',
+                       'FAQ                    https://www.mediawiki.org/wiki/API:FAQ',
+                       'Mailing list:          https://lists.wikimedia.org/mailman/listinfo/mediawiki-api',
+                       'Api Announcements:     https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce',
+                       'Bugs & Requests:       https://bugzilla.wikimedia.org/buglist.cgi?component=API&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&order=bugs.delta_ts',
                        '',
                        '',
                        '',
@@ -874,7 +883,7 @@ class ApiMain extends ApiBase {
                        '    Yuri Astrakhan <Firstname><Lastname>@gmail.com (creator, lead developer Sep 2006-Sep 2007)',
                        '',
                        'Please send your comments, suggestions and questions to mediawiki-api@lists.wikimedia.org',
-                       'or file a bug report at http://bugzilla.wikimedia.org/'
+                       'or file a bug report at https://bugzilla.wikimedia.org/'
                );
        }
 
@@ -1001,7 +1010,7 @@ class ApiMain extends ApiBase {
         */
        public function getVersion() {
                $vers = array();
-               $vers[] = 'MediaWiki: ' . SpecialVersion::getVersion() . "\n    http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/";
+               $vers[] = 'MediaWiki: ' . SpecialVersion::getVersion() . "\n    https://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/";
                $vers[] = __CLASS__ . ': $Id$';
                $vers[] = ApiBase::getBaseVersion();
                $vers[] = ApiFormatBase::getBaseVersion();
@@ -1057,7 +1066,7 @@ class ApiMain extends ApiBase {
  *
  * @ingroup API
  */
-class UsageException extends Exception {
+class UsageException extends MWException {
 
        private $mCodestr;
        private $mExtraData;