API: Add support for selected HTTP precondition headers
[lhc/web/wiklou.git] / includes / api / ApiBase.php
index 4b76e65..d53797b 100644 (file)
@@ -345,6 +345,22 @@ abstract class ApiBase extends ContextSource {
                return null;
        }
 
+       /**
+        * Returns data for HTTP conditional request mechanisms.
+        *
+        * @since 1.26
+        * @param string $condition Condition being queried:
+        *  - last-modified: Return a timestamp representing the maximum of the
+        *    last-modified dates for all resources involved in the request. See
+        *    RFC 7232 § 2.2 for semantics.
+        *  - etag: Return an entity-tag representing the state of all resources involved
+        *    in the request. Quotes must be included. See RFC 7232 § 2.3 for semantics.
+        * @return string|boolean|null As described above, or null if no value is available.
+        */
+       public function getConditionalRequestData( $condition ) {
+               return null;
+       }
+
        /**@}*/
 
        /************************************************************************//**
@@ -1229,7 +1245,7 @@ abstract class ApiBase extends ContextSource {
                                $this->dieUsage( 'Specified user does not exist', 'bad_wlowner' );
                        }
                        $token = $user->getOption( 'watchlisttoken' );
-                       if ( $token == '' || $token != $params['token'] ) {
+                       if ( $token == '' || !hash_equals( $token, $params['token'] ) ) {
                                $this->dieUsage(
                                        'Incorrect watchlist token provided -- please set a correct token in Special:Preferences',
                                        'bad_wltoken'
@@ -2481,7 +2497,7 @@ abstract class ApiBase extends ContextSource {
         * Returns the description string for this module
         *
         * Ignored if an i18n message exists for
-        * "apihelp-{$this->getModulePathString()}-description".
+        * "apihelp-{$this->getModulePath()}-description".
         *
         * @deprecated since 1.25
         * @return Message|string|array
@@ -2495,7 +2511,7 @@ abstract class ApiBase extends ContextSource {
         *
         * For each parameter, ignored if an i18n message exists for the parameter.
         * By default that message is
-        * "apihelp-{$this->getModulePathString()}-param-{$param}", but it may be
+        * "apihelp-{$this->getModulePath()}-param-{$param}", but it may be
         * overridden using ApiBase::PARAM_HELP_MSG in the data returned by
         * self::getFinalParams().
         *
@@ -2870,6 +2886,16 @@ abstract class ApiBase extends ContextSource {
                return $this->getResult()->getData();
        }
 
+       /**
+        * Call wfTransactionalTimeLimit() if this request was POSTed
+        * @since 1.26
+        */
+       protected function useTransactionalTimeLimit() {
+               if ( $this->getRequest()->wasPosted() ) {
+                       wfTransactionalTimeLimit();
+               }
+       }
+
        /**@}*/
 }