Replace wfRunHooks calls with direct Hooks::run calls
[lhc/web/wiklou.git] / includes / api / ApiBase.php
index a214f2e..9cb895d 100644 (file)
@@ -74,6 +74,17 @@ abstract class ApiBase extends ContextSource {
        // is an array of any of strings giving the message key, arrays giving key and
        // parameters, or Message objects.
        const PARAM_HELP_MSG_APPEND = 11;
+       /// @since 1.25
+       // Specify additional information tags for the parameter. Value is an array
+       // of arrays, with the first member being the 'tag' for the info and the
+       // remaining members being the values. In the help, this is formatted using
+       // apihelp-{$path}-paraminfo-{$tag}, which is passed $1 = count, $2 =
+       // comma-joined list of values, $3 = module prefix.
+       const PARAM_HELP_MSG_INFO = 12;
+       /// @since 1.25
+       // When PARAM_DFLT is an array, this may be an array mapping those values
+       // to page titles which will be linked in the help.
+       const PARAM_VALUE_LINKS = 13;
 
        const LIMIT_BIG1 = 500; // Fast query, std user limit
        const LIMIT_BIG2 = 5000; // Fast query, bot/sysop limit
@@ -273,7 +284,8 @@ abstract class ApiBase extends ContextSource {
        }
 
        /**
-        * Indicates whether this module is "internal" or unstable
+        * Indicates whether this module is "internal"
+        * Internal API modules are not (yet) intended for 3rd party use and may be unstable.
         * @since 1.25
         * @return bool
         */
@@ -1031,7 +1043,7 @@ abstract class ApiBase extends ContextSource {
         * @param array $params All supplied parameters for the module
         * @return bool
         */
-       public final function validateToken( $token, array $params ) {
+       final public function validateToken( $token, array $params ) {
                $tokenType = $this->needsToken();
                $salts = ApiQueryTokens::getTokenTypeSalts();
                if ( !isset( $salts[$tokenType] ) ) {
@@ -1627,6 +1639,10 @@ abstract class ApiBase extends ContextSource {
                        'code' => 'missingtitle',
                        'info' => "The article you tried to edit doesn't exist"
                ),
+               'cantchangecontentmodel' => array(
+                       'code' => 'cantchangecontentmodel',
+                       'info' => "You don't have permission to change the content model of a page"
+               ),
                'nosuchrcid' => array(
                        'code' => 'nosuchrcid',
                        'info' => "There is no change with rcid \"\$1\""
@@ -1923,6 +1939,15 @@ abstract class ApiBase extends ContextSource {
         * @{
         */
 
+       /**
+        * Return the description message.
+        *
+        * @return string|array|Message
+        */
+       protected function getDescriptionMessage() {
+               return "apihelp-{$this->getModulePath()}-description";
+       }
+
        /**
         * Get final module description, after hooks have had a chance to tweak it as
         * needed.
@@ -1932,7 +1957,7 @@ abstract class ApiBase extends ContextSource {
         */
        public function getFinalDescription() {
                $desc = $this->getDescription();
-               wfRunHooks( 'APIGetDescription', array( &$this, &$desc ) );
+               Hooks::run( 'APIGetDescription', array( &$this, &$desc ) );
                $desc = self::escapeWikiText( $desc );
                if ( is_array( $desc ) ) {
                        $desc = join( "\n", $desc );
@@ -1940,7 +1965,7 @@ abstract class ApiBase extends ContextSource {
                        $desc = (string)$desc;
                }
 
-               $msg = $this->msg( "apihelp-{$this->getModulePath()}-description", array(
+               $msg = ApiBase::makeMessage( $this->getDescriptionMessage(), $this->getContext(), array(
                        $this->getModulePrefix(),
                        $this->getModuleName(),
                        $this->getModulePath(),
@@ -1950,7 +1975,7 @@ abstract class ApiBase extends ContextSource {
                }
                $msgs = array( $msg );
 
-               wfRunHooks( 'APIGetDescriptionMessages', array( $this, &$msgs ) );
+               Hooks::run( 'APIGetDescriptionMessages', array( $this, &$msgs ) );
 
                return $msgs;
        }
@@ -1980,7 +2005,7 @@ abstract class ApiBase extends ContextSource {
                        ) + ( isset( $params['token'] ) ? $params['token'] : array() );
                }
 
-               wfRunHooks( 'APIGetAllowedParams', array( &$this, &$params, $flags ) );
+               Hooks::run( 'APIGetAllowedParams', array( &$this, &$params, $flags ) );
 
                return $params;
        }
@@ -1994,7 +2019,7 @@ abstract class ApiBase extends ContextSource {
         */
        public function getFinalParamDescription() {
                $desc = $this->getParamDescription();
-               wfRunHooks( 'APIGetParamDescription', array( &$this, &$desc ) );
+               Hooks::run( 'APIGetParamDescription', array( &$this, &$desc ) );
 
                if ( !$desc ) {
                        $desc = array();
@@ -2062,7 +2087,7 @@ abstract class ApiBase extends ContextSource {
                        }
                }
 
-               wfRunHooks( 'APIGetParamDescriptionMessages', array( $this, &$msgs ) );
+               Hooks::run( 'APIGetParamDescriptionMessages', array( $this, &$msgs ) );
 
                return $msgs;
        }
@@ -2257,7 +2282,7 @@ abstract class ApiBase extends ContextSource {
                        ' "' . wfUrlencode( str_replace( ' ', '_', $this->getUser()->getName() ) ) . '"' .
                        ' "' . $request->getIP() . '"' .
                        ' "' . addslashes( $request->getHeader( 'Referer' ) ) . '"' .
-                       ' "' . addslashes( $request->getHeader( 'User-agent' ) ) . '"';
+                       ' "' . addslashes( $this->getMain()->getUserAgent() ) . '"';
                wfDebugLog( 'api-feature-usage', $s, 'private' );
        }
 
@@ -2424,7 +2449,7 @@ abstract class ApiBase extends ContextSource {
         * @return array|bool False on no parameter descriptions
         */
        protected function getParamDescription() {
-               return false;
+               return array();
        }
 
        /**