r50366 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50365‎ | r50366 | r50367 >
Date:12:52, 9 May 2009
Author:catrope
Status:ok (Comments)
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiMain.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiMain.php
@@ -653,7 +653,6 @@
654654 $vers[] = ApiBase :: getBaseVersion();
655655 $vers[] = ApiFormatBase :: getBaseVersion();
656656 $vers[] = ApiQueryBase :: getBaseVersion();
657 - $vers[] = ApiFormatFeedWrapper :: getVersion(); // not accessible with format=xxx
658657 return $vers;
659658 }
660659
Index: trunk/phase3/includes/api/ApiBase.php
@@ -248,15 +248,15 @@
249249 if ($this->getMain()->getShowVersions()) {
250250 $versions = $this->getVersion();
251251 $pattern = '/(\$.*) ([0-9a-z_]+\.php) (.*\$)/i';
252 - $replacement = '\\0' . "\n " . 'http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/api/\\2';
 252+ $callback = array($this, 'makeHelpMsg_callback');
253253
254254 if (is_array($versions)) {
255255 foreach ($versions as &$v)
256 - $v = preg_replace($pattern, $replacement, $v);
 256+ $v = preg_replace_callback($pattern, $callback, $v);
257257 $versions = implode("\n ", $versions);
258258 }
259259 else
260 - $versions = preg_replace($pattern, $replacement, $versions);
 260+ $versions = preg_replace_callback($pattern, $callback, $versions);
261261
262262 $msg .= "Version:\n $versions\n";
263263 }
@@ -336,6 +336,36 @@
337337 } else
338338 return false;
339339 }
 340+
 341+ /**
 342+ * Callback for preg_replace_callback() call in makeHelpMsg().
 343+ * Replaces a source file name with a link to ViewVC
 344+ */
 345+ public function makeHelpMsg_callback($matches) {
 346+ global $wgAutoloadClasses, $wgAutoloadLocalClasses;
 347+ if(isset($wgAutoloadLocalClasses[get_class($this)]))
 348+ $file = $wgAutoloadLocalClasses[get_class($this)];
 349+ else if(isset($wgAutoloadClasses[get_class($this)]))
 350+ $file = $wgAutoloadClasses[get_class($this)];
 351+
 352+ // Do some guesswork here
 353+ $path = strstr($file, 'includes/api/');
 354+ if($path === false)
 355+ $path = strstr($file, 'extensions/');
 356+ else
 357+ $path = 'phase3/' . $path;
 358+
 359+ // Get the filename from $matches[2] instead of $file
 360+ // If they're not the same file, they're assumed to be in the
 361+ // same directory
 362+ // This is necessary to make stuff like ApiMain::getVersion()
 363+ // returning the version string for ApiBase work
 364+ if($path)
 365+ return "{$matches[0]}\n http://svn.wikimedia.org/" .
 366+ "viewvc/mediawiki/trunk/" . dirname($path) .
 367+ "/{$matches[2]}";
 368+ return $matches[0];
 369+ }
340370
341371 /**
342372 * Returns the description string for this module
Index: trunk/phase3/RELEASE-NOTES
@@ -137,6 +137,7 @@
138138 * (bug 18710) Fixed internal error with empty parameter in action=paraminfo
139139 * (bug 18709) Missing descriptions for some parameters in action=paraminfo
140140 output
 141+* (bug 18731) Show correct SVN links for extension modules in api.php?version
141142
142143 === Languages updated in 1.16 ===
143144

Comments

#Comment by Catrope (talk | contribs)   13:03, 9 May 2009

This also fixes the E_STRICT reported in bug 18730 comment #1

#Comment by Brion VIBBER (talk | contribs)   17:43, 11 May 2009

Assumption is not valid; some directories contain extension entry point files with different names. Use the path that's provided in the version information, rather than throwing it away and attempting to guess it again.

#Comment by Catrope (talk | contribs)   18:53, 11 May 2009

First of all this does not make any assumptions about the name of the entry point file, just about the name of the directory it's located in. Also, just how would I get the path in the version information?

#Comment by 😂 (talk | contribs)   01:03, 18 May 2009

$wgExtensionCredits['type']['name']['path']?

#Comment by Catrope (talk | contribs)   07:06, 18 May 2009

That would involve guessing the name of the extension based on the path, which isn't really any better, and it would require iterating over all types, as the extension type can't reasonably be guessed. This doesn't sound like a convincingly better option to me.

#Comment by Tim Starling (talk | contribs)   10:09, 4 June 2009

Will do for now.

Status & tagging log