FU r106752: use "media-" instead of "images-" in container names. Long live books...
[lhc/web/wiklou.git] / includes / api / ApiBase.php
index 15f0078..e1ba493 100644 (file)
@@ -74,7 +74,7 @@ abstract class ApiBase extends ContextSource {
                $this->mModulePrefix = $modulePrefix;
 
                if ( !$this->isMain() ) {
-                       $this->setContext( $this->mMainModule );
+                       $this->setContext( $mainModule->getContext() );
                }
        }
 
@@ -183,11 +183,12 @@ abstract class ApiBase extends ContextSource {
         * The object will have the WebRequest and the User object set to the ones
         * used in this instance.
         *
-        * @deprecated 1.19 use getContext to get the current context
-        * @return RequestContext
+        * @deprecated since 1.19 use getContext to get the current context
+        * @return DerivativeContext
         */
        public function createContext() {
-               return $this->getContext();
+               wfDeprecated( __METHOD__, '1.19' );
+               return new DerivativeContext( $this->getContext() );
        }
 
        /**
@@ -235,7 +236,7 @@ abstract class ApiBase extends ContextSource {
        public function makeHelpMsg() {
                static $lnPrfx = "\n  ";
 
-               $msg = $this->getDescription();
+               $msg = $this->getFinalDescription();
 
                if ( $msg !== false ) {
 
@@ -436,6 +437,7 @@ abstract class ApiBase extends ContextSource {
         * Callback for preg_replace_callback() call in makeHelpMsg().
         * Replaces a source file name with a link to ViewVC
         *
+        * @param $matches array
         * @return string
         */
        public function makeHelpMsg_callback( $matches ) {
@@ -462,7 +464,7 @@ abstract class ApiBase extends ContextSource {
                // This is necessary to make stuff like ApiMain::getVersion()
                // returning the version string for ApiBase work
                if ( $path ) {
-                       return "{$matches[0]}\n   http://svn.wikimedia.org/" .
+                       return "{$matches[0]}\n   https://svn.wikimedia.org/" .
                                "viewvc/mediawiki/trunk/" . dirname( $path ) .
                                "/{$matches[2]}";
                }
@@ -509,6 +511,7 @@ abstract class ApiBase extends ContextSource {
        /**
         * Get final list of parameters, after hooks have had a chance to
         * tweak it as needed.
+        *
         * @return array or false
         */
        public function getFinalParams() {
@@ -518,8 +521,9 @@ abstract class ApiBase extends ContextSource {
        }
 
        /**
-        * Get final description, after hooks have had a chance to tweak it as
+        * Get final parameter descriptions, after hooks have had a chance to tweak it as
         * needed.
+        *
         * @return array
         */
        public function getFinalParamDescription() {
@@ -528,6 +532,18 @@ abstract class ApiBase extends ContextSource {
                return $desc;
        }
 
+       /**
+        * Get final module description, after hooks have had a chance to tweak it as
+        * needed.
+        *
+        * @return array
+        */
+       public function getFinalDescription() {
+               $desc = $this->getDescription();
+               wfRunHooks( 'APIGetDescription', array( &$this, &$desc ) );
+               return $desc;
+       }
+
        /**
         * This method mangles parameter name based on the prefix supplied to the constructor.
         * Override this method to change parameter name during runtime
@@ -658,6 +674,7 @@ abstract class ApiBase extends ContextSource {
         * @return array
         */
        public static function getValidNamespaces() {
+               wfDeprecated( __METHOD__, '1.17' );
                return MWNamespace::getValidNamespaces();
        }
 
@@ -1147,6 +1164,8 @@ abstract class ApiBase extends ContextSource {
                'mustbeposted' => array( 'code' => 'mustbeposted', 'info' => "The \$1 module requires a POST request" ),
                'show' => array( 'code' => 'show', 'info' => 'Incorrect parameter - mutually exclusive values may not be supplied' ),
                'specialpage-cantexecute' => array( 'code' => 'specialpage-cantexecute', 'info' => "You don't have permission to view the results of this special page" ),
+               'invalidoldimage' => array( 'code' => 'invalidoldimage', 'info' => 'The oldimage parameter has invalid format' ),
+               'nodeleteablefile' => array( 'code' => 'nodeleteablefile', 'info' => 'No such old version of the file' ),
 
                // ApiEditPage messages
                'noimageredirect-anon' => array( 'code' => 'noimageredirect-anon', 'info' => "Anonymous users can't create image redirects" ),
@@ -1178,6 +1197,7 @@ abstract class ApiBase extends ContextSource {
                'copyuploaddisabled' => array( 'code' => 'copyuploaddisabled', 'info' => 'Uploads by URL is not enabled.  Make sure $wgAllowCopyUploads is set to true in LocalSettings.php.' ),
 
                'filename-tooshort' => array( 'code' => 'filename-tooshort', 'info' => 'The filename is too short' ),
+               'filename-toolong' => array( 'code' => 'filename-toolong', 'info' => 'The filename is too long' ),
                'illegal-filename' => array( 'code' => 'illegal-filename', 'info' => 'The filename is not allowed' ),
                'filetype-missing' => array( 'code' => 'filetype-missing', 'info' => 'The file is missing an extension' ),
        );
@@ -1297,7 +1317,7 @@ abstract class ApiBase extends ContextSource {
        public function getWatchlistUser( $params ) {
                if ( !is_null( $params['owner'] ) && !is_null( $params['token'] ) ) {
                        $user = User::newFromName( $params['owner'], false );
-                       if ( !$user->getId() ) {
+                       if ( !($user && $user->getId()) ) {
                                $this->dieUsage( 'Specified user does not exist', 'bad_wlowner' );
                        }
                        $token = $user->getOption( 'watchlisttoken' );
@@ -1480,6 +1500,13 @@ abstract class ApiBase extends ContextSource {
                return $this->mDBTime;
        }
 
+       /**
+        * @return DatabaseBase
+        */
+       protected function getDB() {
+               return wfGetDB( DB_SLAVE, 'api' );
+       }
+
        /**
         * Debugging function that prints a value and an optional backtrace
         * @param $value mixed Value to print