* 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
}
$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;
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;
}
}
}
- /**
- * 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
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" );
}
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 );
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();
* @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 );
}
/**
$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
// 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 );
}
}
print "\n</pre>\n";
}
-
- /**
- * Returns a string that identifies the version of this class.
- * @return string
- */
- public static function getBaseVersion() {
- return __CLASS__ . ': $Id$';
- }
}