raise timeout for CdbTest::testCdb()
[lhc/web/wiklou.git] / includes / api / ApiBase.php
index 875a381..5621b7c 100644 (file)
@@ -105,15 +105,19 @@ abstract class ApiBase extends ContextSource {
         * The result data should be stored in the ApiResult object available
         * through getResult().
         */
-       public abstract function execute();
+       abstract public function execute();
 
        /**
         * Returns a string that identifies the version of the extending class.
         * Typically includes the class name, the svn revision, timestamp, and
         * last author. Usually done with SVN's Id keyword
         * @return string
+        * @deprecated since 1.21, version string is no longer supported
         */
-       public abstract function getVersion();
+       public function getVersion() {
+               wfDeprecated( __METHOD__, '1.21' );
+               return '';
+       }
 
        /**
         * Get the name of the module being executed by this instance
@@ -299,23 +303,6 @@ abstract class ApiBase extends ContextSource {
                        }
 
                        $msg .= $this->makeHelpArrayToString( $lnPrfx, "Help page", $this->getHelpUrls() );
-
-                       if ( $this->getMain()->getShowVersions() ) {
-                               $versions = $this->getVersion();
-                               $pattern = '/(\$.*) ([0-9a-z_]+\.php) (.*\$)/i';
-                               $callback = array( $this, 'makeHelpMsg_callback' );
-
-                               if ( is_array( $versions ) ) {
-                                       foreach ( $versions as &$v ) {
-                                               $v = preg_replace_callback( $pattern, $callback, $v );
-                                       }
-                                       $versions = implode( "\n  ", $versions );
-                               } else {
-                                       $versions = preg_replace_callback( $pattern, $callback, $versions );
-                               }
-
-                               $msg .= "Version:\n  $versions\n";
-                       }
                }
 
                return $msg;
@@ -340,13 +327,15 @@ abstract class ApiBase extends ContextSource {
                        return '';
                }
                if ( !is_array( $input ) ) {
-                       $input = array(
-                               $input
-                       );
+                       $input = array( $input );
                }
 
                if ( count( $input ) > 0 ) {
-                       $msg = $title . ( count( $input ) > 1 ? 's' : '' ) . ":\n  ";
+                       if ( $title ) {
+                               $msg = $title . ( count( $input ) > 1 ? 's' : '' ) . ":\n  ";
+                       } else {
+                               $msg = '  ';
+                       }
                        $msg .= implode( $prefix, $input ) . "\n";
                        return $msg;
                }
@@ -486,44 +475,6 @@ 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 ) {
-               global $wgAutoloadClasses, $wgAutoloadLocalClasses;
-
-               $file = '';
-               if ( isset( $wgAutoloadLocalClasses[get_class( $this )] ) ) {
-                       $file = $wgAutoloadLocalClasses[get_class( $this )];
-               } elseif ( isset( $wgAutoloadClasses[get_class( $this )] ) ) {
-                       $file = $wgAutoloadClasses[get_class( $this )];
-               }
-
-               // Do some guesswork here
-               $path = strstr( $file, 'includes/api/' );
-               if ( $path === false ) {
-                       $path = strstr( $file, 'extensions/' );
-               } else {
-                       $path = 'phase3/' . $path;
-               }
-
-               // Get the filename from $matches[2] instead of $file
-               // If they're not the same file, they're assumed to be in the
-               // same directory
-               // This is necessary to make stuff like ApiMain::getVersion()
-               // returning the version string for ApiBase work
-               if ( $path ) {
-                       return "{$matches[0]}\n   https://svn.wikimedia.org/" .
-                                       "viewvc/mediawiki/trunk/" . dirname( $path ) .
-                                       "/{$matches[2]}";
-               }
-               return $matches[0];
-       }
-
        /**
         * Returns the description string for this module
         * @return mixed string or array of strings
@@ -703,7 +654,7 @@ abstract class ApiBase extends ContextSource {
                        array( $this, "parameterNotEmpty" ) ) ), $required );
 
                if ( count( $intersection ) > 1 ) {
-                       $this->dieUsage( "The parameters {$p}" . implode( ", {$p}",  $intersection ) . ' can not be used together', "{$p}invalidparammix" );
+                       $this->dieUsage( "The parameters {$p}" . implode( ", {$p}", $intersection ) . ' can not be used together', "{$p}invalidparammix" );
                } elseif ( count( $intersection ) == 0 ) {
                        $this->dieUsage( "One of the parameters {$p}" . implode( ", {$p}", $required ) . ' is required', "{$p}missingparam" );
                }
@@ -775,6 +726,9 @@ abstract class ApiBase extends ContextSource {
                        if ( !$titleObj ) {
                                $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
                        }
+                       if ( !$titleObj->canExist() ) {
+                               $this->dieUsage( "Namespace doesn't allow actual pages", 'pagecannotexist' );
+                       }
                        $pageObj = WikiPage::factory( $titleObj );
                        if ( $load !== false ) {
                                $pageObj->loadPageData( $load );
@@ -929,9 +883,9 @@ abstract class ApiBase extends ContextSource {
                                ApiBase::dieDebug( __METHOD__, "Boolean param $encParamName's default is set to '$default'. Boolean parameters must default to false." );
                        }
 
-                       $value = $this->getRequest()->getCheck( $encParamName );
+                       $value = $this->getMain()->getCheck( $encParamName );
                } else {
-                       $value = $this->getRequest()->getVal( $encParamName, $default );
+                       $value = $this->getMain()->getVal( $encParamName, $default );
 
                        if ( isset( $value ) && $type == 'namespace' ) {
                                $type = MWNamespace::getValidNamespaces();
@@ -1149,11 +1103,11 @@ abstract class ApiBase extends ContextSource {
         * @return string
         */
        function validateTimestamp( $value, $paramName ) {
-               $value = wfTimestamp( TS_UNIX, $value );
-               if ( $value === 0 ) {
+               $unixTimestamp = wfTimestamp( TS_UNIX, $value );
+               if ( $unixTimestamp === false ) {
                        $this->dieUsage( "Invalid value '$value' for timestamp parameter $paramName", "badtimestamp_{$paramName}" );
                }
-               return wfTimestamp( TS_MW, $value );
+               return wfTimestamp( TS_MW, $unixTimestamp );
        }
 
        /**
@@ -1384,6 +1338,26 @@ abstract class ApiBase extends ContextSource {
                $this->dieUsage( $parsed['info'], $parsed['code'] );
        }
 
+       /**
+        * Will only set a warning instead of failing if the global $wgDebugAPI
+        * is set to true. Otherwise behaves exactly as dieUsageMsg().
+        * @param $error (array|string) Element of a getUserPermissionsErrors()-style array
+        * @since 1.21
+        */
+       public function dieUsageMsgOrDebug( $error ) {
+               global $wgDebugAPI;
+               if( $wgDebugAPI !== true ) {
+                       $this->dieUsageMsg( $error );
+               } else {
+                       if( is_string( $error ) ) {
+                               $error = array( $error );
+                       }
+                       $parsed = $this->parseMsg( $error );
+                       $this->setWarning( '$wgDebugAPI: ' . $parsed['code']
+                               . ' - ' . $parsed['info'] );
+               }
+       }
+
        /**
         * Return the error message related to a certain array
         * @param $error array Element of a getUserPermissionsErrors()-style array
@@ -1395,7 +1369,7 @@ abstract class ApiBase extends ContextSource {
 
                // Check whether the error array was nested
                // array( array( <code>, <params> ), array( <another_code>, <params> ) )
-               if( is_array( $key ) ){
+               if( is_array( $key ) ) {
                        $error = $key;
                        $key = array_shift( $error );
                }
@@ -1686,12 +1660,4 @@ abstract class ApiBase extends ContextSource {
                }
                print "\n</pre>\n";
        }
-
-       /**
-        * Returns a string that identifies the version of this class.
-        * @return string
-        */
-       public static function getBaseVersion() {
-               return __CLASS__ . ': $Id$';
-       }
 }