Merge "Add logic for "tags" in ApiBase"
[lhc/web/wiklou.git] / includes / api / ApiBase.php
index 56a8a7a..a6da823 100644 (file)
@@ -74,12 +74,14 @@ abstract class ApiBase extends ContextSource {
         * - string: Any non-empty string, not expected to be very long or contain newlines.
         *   <input type="text"> would be an appropriate HTML form field.
         * - submodule: The name of a submodule of this module, see PARAM_SUBMODULE_MAP.
+        * - tags: A string naming an existing, explicitly-defined tag. Should usually be
+        *   used with PARAM_ISMULTI.
         * - text: Any non-empty string, expected to be very long or contain newlines.
         *   <textarea> would be an appropriate HTML form field.
         * - timestamp: A timestamp in any format recognized by MWTimestamp, or the
         *   string 'now' representing the current timestamp. Will be returned in
         *   TS_MW format.
-        * - user: A MediaWiki username. Will be returned normalized but not canonicalized.
+        * - user: A MediaWiki username or IP. Will be returned normalized but not canonicalized.
         * - upload: An uploaded file. Will be returned as a WebRequestUpload object.
         *   Cannot be used with PARAM_ISMULTI.
         */
@@ -637,6 +639,17 @@ abstract class ApiBase extends ContextSource {
         * @{
         */
 
+       /**
+        * Indicate if the module supports dynamically-determined parameters that
+        * cannot be included in self::getAllowedParams().
+        * @return string|array|Message|null Return null if the module does not
+        *  support additional dynamic parameters, otherwise return a message
+        *  describing them.
+        */
+       public function dynamicParameterDocumentation() {
+               return null;
+       }
+
        /**
         * This method mangles parameter name based on the prefix supplied to the constructor.
         * Override this method to change parameter name during runtime
@@ -1052,6 +1065,16 @@ abstract class ApiBase extends ContextSource {
                                                break;
                                        case 'upload': // nothing to do
                                                break;
+                                       case 'tags':
+                                               // If change tagging was requested, check that the tags are valid.
+                                               if ( !is_array( $value ) && !$multi ) {
+                                                       $value = array( $value );
+                                               }
+                                               $tagsStatus = ChangeTags::canAddTagsAccompanyingChange( $value );
+                                               if ( !$tagsStatus->isGood() ) {
+                                                       $this->dieStatus( $tagsStatus );
+                                               }
+                                               break;
                                        default:
                                                ApiBase::dieDebug( __METHOD__, "Param $encParamName's type is unknown - $type" );
                                }
@@ -1249,11 +1272,10 @@ abstract class ApiBase extends ContextSource {
                        );
                }
 
-               if ( $this->getUser()->matchEditToken(
-                       $token,
-                       $salts[$tokenType],
-                       $this->getRequest()
-               ) ) {
+               $tokenObj = ApiQueryTokens::getToken(
+                       $this->getUser(), $this->getRequest()->getSession(), $salts[$tokenType]
+               );
+               if ( $tokenObj->match( $token ) ) {
                        return true;
                }
 
@@ -2512,19 +2534,6 @@ abstract class ApiBase extends ContextSource {
        /// @deprecated since 1.24
        const PROP_NULLABLE = 1;
 
-       /**
-        * Formerly returned a string that identifies the version of the extending
-        * class. Typically included the class name, the svn revision, timestamp,
-        * and last author. Usually done with SVN's Id keyword
-        *
-        * @deprecated since 1.21, version string is no longer supported
-        * @return string
-        */
-       public function getVersion() {
-               wfDeprecated( __METHOD__, '1.21' );
-               return '';
-       }
-
        /**
         * Formerly used to fetch a list of possible properites in the result,
         * somehow organized with respect to the prop parameter that causes them to