API: (bug 18731) Show correct SVN links for extension modules in api.php?version...
authorRoan Kattouw <catrope@users.mediawiki.org>
Sat, 9 May 2009 12:52:38 +0000 (12:52 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Sat, 9 May 2009 12:52:38 +0000 (12:52 +0000)
RELEASE-NOTES
includes/api/ApiBase.php
includes/api/ApiMain.php

index fd6d06c..875fc9e 100644 (file)
@@ -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 ===
 
index 990b8e6..32b800f 100644 (file)
@@ -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
index 98c06b1..92f92aa 100644 (file)
@@ -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;
        }