From 91271d809e236d36ac8061021422e692b1cd6d10 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Sat, 9 May 2009 12:52:38 +0000 Subject: [PATCH] API: (bug 18731) Show correct SVN links for extension modules in api.php?version . Guesswork to get the path assumes extensions are in a directory called extensions/extensionname , which should be a valid assumption on sane installs. --- RELEASE-NOTES | 1 + includes/api/ApiBase.php | 36 +++++++++++++++++++++++++++++++++--- includes/api/ApiMain.php | 1 - 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index fd6d06ca4c..875fc9e55c 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -137,6 +137,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 18710) Fixed internal error with empty parameter in action=paraminfo * (bug 18709) Missing descriptions for some parameters in action=paraminfo output +* (bug 18731) Show correct SVN links for extension modules in api.php?version === Languages updated in 1.16 === diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 990b8e66c6..32b800f28a 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -248,15 +248,15 @@ abstract class ApiBase { 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"; } @@ -336,6 +336,36 @@ abstract class ApiBase { } 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 diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 98c06b1563..92f92aa303 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -653,7 +653,6 @@ class ApiMain extends ApiBase { $vers[] = ApiBase :: getBaseVersion(); $vers[] = ApiFormatBase :: getBaseVersion(); $vers[] = ApiQueryBase :: getBaseVersion(); - $vers[] = ApiFormatFeedWrapper :: getVersion(); // not accessible with format=xxx return $vers; } -- 2.20.1