if ($this->getMain()->getShowVersions()) {
$versions = $this->getVersion();
$pattern = '/(\$.*) ([0-9a-z_]+\.php) (.*\$)/i';
- $replacement = '\\0' . "\n " . 'http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/api/\\2';
+ $callback = array($this, 'makeHelpMsg_callback');
if (is_array($versions)) {
foreach ($versions as &$v)
- $v = preg_replace($pattern, $replacement, $v);
+ $v = preg_replace_callback($pattern, $callback, $v);
$versions = implode("\n ", $versions);
}
else
- $versions = preg_replace($pattern, $replacement, $versions);
+ $versions = preg_replace_callback($pattern, $callback, $versions);
$msg .= "Version:\n $versions\n";
}
*/
public function makeHelpMsgParameters() {
$params = $this->getFinalParams();
- if ($params !== false) {
+ if ( $params ) {
$paramsDescription = $this->getFinalParamDescription();
$msg = '';
} else
return false;
}
+
+ /**
+ * Callback for preg_replace_callback() call in makeHelpMsg().
+ * Replaces a source file name with a link to ViewVC
+ */
+ public function makeHelpMsg_callback($matches) {
+ global $wgAutoloadClasses, $wgAutoloadLocalClasses;
+ if(isset($wgAutoloadLocalClasses[get_class($this)]))
+ $file = $wgAutoloadLocalClasses[get_class($this)];
+ else if(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 http://svn.wikimedia.org/" .
+ "viewvc/mediawiki/trunk/" . dirname($path) .
+ "/{$matches[2]}";
+ return $matches[0];
+ }
/**
* Returns the description string for this module
if($allowMultiple)
{
$s = count($unknown) > 1 ? "s" : "";
- $vals = implode(", ", $unknown);
+ $vals = implode(", ", $unknown);
$this->setWarning("Unrecognized value$s for parameter '$valueName': $vals");
}
else
* @param $errorCode string Error code
* @param $httpRespCode int HTTP response code
*/
- public function dieUsage($description, $errorCode, $httpRespCode = 0) {
+ public function dieUsage($description, $errorCode, $httpRespCode = 0, $extradata = null) {
wfProfileClose();
- throw new UsageException($description, $this->encodeParamName($errorCode), $httpRespCode);
+ throw new UsageException($description, $this->encodeParamName($errorCode), $httpRespCode, $extradata);
}
/**
'toofewexpiries' => array('code' => 'toofewexpiries', 'info' => "\$1 expiry timestamps were provided where \$2 were needed"),
'cantimport' => array('code' => 'cantimport', 'info' => "You don't have permission to import pages"),
'cantimport-upload' => array('code' => 'cantimport-upload', 'info' => "You don't have permission to import uploaded pages"),
+ 'nouploadmodule' => array( 'code' => 'nomodule', 'info' => 'No upload module set' ),
'importnofile' => array('code' => 'nofile', 'info' => "You didn't upload a file"),
'importuploaderrorsize' => array('code' => 'filetoobig', 'info' => 'The file you uploaded is bigger than the maximum upload size'),
'importuploaderrorpartial' => array('code' => 'partialupload', 'info' => 'The file was only partially uploaded'),
'emptynewsection' => array('code' => 'emptynewsection', 'info' => 'Creating empty new sections is not possible.'),
'revwrongpage' => array('code' => 'revwrongpage', 'info' => "r\$1 is not a revision of ``\$2''"),
'undo-failure' => array('code' => 'undofailure', 'info' => 'Undo failed due to conflicting intermediate edits'),
+
+ //uploadMsgs
+ 'invalid-session-key' => array( 'code' => 'invalid-session-key', 'info'=>'Not a valid session key' ),
);
+ /**
+ * Helper function for readonly errors
+ */
+ public function dieReadOnly() {
+ $parsed = $this->parseMsg( array( 'readonlytext' ) );
+ $this->dieUsage($parsed['info'], $parsed['code'], /* http error */ 0,
+ array( 'readonlyreason' => wfReadOnlyReason() ) );
+ }
+
/**
* Output the error message related to a certain array
* @param $error array Element of a getUserPermissionsErrors()-style array