Used DIRECTORY_SEPARATOR instead of '/' in GitInfo.php
[lhc/web/wiklou.git] / includes / api / ApiMain.php
index 829ba6f..2684f51 100644 (file)
@@ -39,7 +39,6 @@
  * @ingroup API
  */
 class ApiMain extends ApiBase {
-
        /**
         * When no format parameter is given, this format will be used
         */
@@ -84,6 +83,7 @@ class ApiMain extends ApiBase {
                'userrights' => 'ApiUserrights',
                'options' => 'ApiOptions',
                'imagerotate' => 'ApiImageRotate',
+               'revisiondelete' => 'ApiRevisionDelete',
        );
 
        /**
@@ -292,16 +292,6 @@ class ApiMain extends ApiBase {
                $this->mCacheMode = $mode;
        }
 
-       /**
-        * @deprecated since 1.17 Private caching is now the default, so there is usually no
-        * need to call this function. If there is a need, you can use
-        * $this->setCacheMode('private')
-        */
-       public function setCachePrivate() {
-               wfDeprecated( __METHOD__, '1.17' );
-               $this->setCacheMode( 'private' );
-       }
-
        /**
         * Set directives (key/value pairs) for the Cache-Control header.
         * Boolean values will be formatted as such, by including or omitting
@@ -316,21 +306,6 @@ class ApiMain extends ApiBase {
                $this->mCacheControl = $directives + $this->mCacheControl;
        }
 
-       /**
-        * Make sure Vary: Cookie and friends are set. Use this when the output of a request
-        * may be cached for anons but may not be cached for logged-in users.
-        *
-        * WARNING: This function must be called CONSISTENTLY for a given URL. This means that a
-        * given URL must either always or never call this function; if it sometimes does and
-        * sometimes doesn't, stuff will break.
-        *
-        * @deprecated since 1.17 Use setCacheMode( 'anon-public-user-private' )
-        */
-       public function setVaryCookie() {
-               wfDeprecated( __METHOD__, '1.17' );
-               $this->setCacheMode( 'anon-public-user-private' );
-       }
-
        /**
         * Create an instance of an output formatter by its name
         *
@@ -815,6 +790,28 @@ class ApiMain extends ApiBase {
                }
        }
 
+       /**
+        * Check asserts of the user's rights
+        * @param $params array
+        */
+       protected function checkAsserts( $params ) {
+               if ( isset( $params['assert'] ) ) {
+                       $user = $this->getUser();
+                       switch ( $params['assert'] ) {
+                               case 'user':
+                                       if ( $user->isAnon() ) {
+                                               $this->dieUsage( 'Assertion that the user is logged in failed', 'assertuserfailed' );
+                                       }
+                                       break;
+                               case 'bot':
+                                       if ( !$user->isAllowed( 'bot' ) ) {
+                                               $this->dieUsage( 'Assertion that the user has the bot right failed', 'assertbotfailed' );
+                                       }
+                                       break;
+                       }
+               }
+       }
+
        /**
         * Check POST for external response and setup result printer
         * @param $module ApiBase An Api module
@@ -857,6 +854,8 @@ class ApiMain extends ApiBase {
                        $this->setupExternalResponse( $module, $params );
                }
 
+               $this->checkAsserts( $params );
+
                // Execute
                $module->profileIn();
                $module->execute();
@@ -900,7 +899,7 @@ class ApiMain extends ApiBase {
                        }
                }
                $s .= "\n";
-               wfDebugLog( 'api', $s, false );
+               wfDebugLog( 'api', $s, 'private' );
        }
 
        /**
@@ -1046,6 +1045,9 @@ class ApiMain extends ApiBase {
                                ApiBase::PARAM_TYPE => 'integer',
                                ApiBase::PARAM_DFLT => 0
                        ),
+                       'assert' => array(
+                               ApiBase::PARAM_TYPE => array( 'user', 'bot' )
+                       ),
                        'requestid' => null,
                        'servedby' => false,
                        'origin' => null,
@@ -1071,6 +1073,7 @@ class ApiMain extends ApiBase {
                        ),
                        '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',
+                       'assert' => 'Verify the user is logged in if set to "user", or has the bot userright if "bot"',
                        'requestid' => 'Request ID to distinguish requests. This will just be output back to you',
                        'servedby' => 'Include the hostname that served the request in the ' .
                                'results. Unconditionally shown on error',
@@ -1143,6 +1146,11 @@ class ApiMain extends ApiBase {
                        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' ),
+                       array( 'code' => 'assertuserfailed', 'info' => 'Assertion that the user is logged in failed' ),
+                       array(
+                               'code' => 'assertbotfailed',
+                               'info' => 'Assertion that the user has the bot right failed'
+                       ),
                ) );
        }