r49995 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r49994 | r49995 (on ViewVC) | r49996 >
Date:05:24, 28 April 2009
Author:shinjiman
Status:resolved (Comments)
Tags:
Comment:* (bug 18593) Unify svn-revision references in Special:Version, in addition with Brion's recommendations. :)
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialVersion.php
===================================================================
--- trunk/phase3/includes/specials/SpecialVersion.php	(revision 49994)
+++ trunk/phase3/includes/specials/SpecialVersion.php	(revision 49995)
@@ -114,7 +114,7 @@
 	public static function getVersion() {
 		global $wgVersion, $IP;
 		wfProfileIn( __METHOD__ );
-		$svn = self::getSvnRevision( $IP, false );
+		$svn = self::getSvnRevision( $IP, false , false);
 		$version = $svn ? $wgVersion . wfMsg( 'version-svn-revision', $svn ) : $wgVersion;
 		wfProfileOut( __METHOD__ );
 		return $version;
@@ -129,8 +129,11 @@
 	public static function getVersionLinked() {
 		global $wgVersion, $IP;
 		wfProfileIn( __METHOD__ );
-		$svn = self::getSvnRevision( $IP, false );
-		$viewvc = 'http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/?pathrev=';
+		$svn = self::getSvnRevision( $IP, false, false );
+		$svnDir = self::getSvnRevision( $IP, false, true );
+		$viewvcStart = 'http://svn.wikimedia.org/viewvc/mediawiki/';
+		$viewvcEnd = '/?pathrev=';
+		$viewvc = $viewvcStart . $svnDir .  $viewvcEnd;
 		$version = $svn ? $wgVersion . " [{$viewvc}{$svn} " . wfMsg( 'version-svn-revision', $svn ) . ']' : $wgVersion;
 		wfProfileOut( __METHOD__ );
 		return $version;
@@ -164,8 +167,13 @@
 				foreach ( $wgExtensionCredits[$type] as $extension ) {
 					$version = null;
 					$subVersion = null;
-					if (isset($extension['path']))
-						$subVersion = self::getSvnRevision(dirname($extension['path']), true);
+					$viewvc = null;
+					if ( isset( $extension['path'] ) ) {
+						$subVersion = self::getSvnRevision(dirname($extension['path']), true, false);
+						$subVersionDir = self::getSvnRevision(dirname($extension['path']), true, true);
+						if ($subVersionDir)
+							$viewvc = $subVersionDir . $subVersion;
+					}
 					if ( isset( $extension['version'] ) ) {
 						$version = $extension['version'];
 					}
@@ -174,6 +182,7 @@
 						isset ( $extension['name'] )           ? $extension['name']        : '',
 						$version,
 						$subVersion,
+						$viewvc,
 						isset ( $extension['author'] )         ? $extension['author']      : '',
 						isset ( $extension['url'] )            ? $extension['url']         : null,
 						isset ( $extension['description'] )    ? $extension['description'] : '',
@@ -220,10 +229,11 @@
 		}
 	}
 
-	function formatCredits( $name, $version = null, $subVersion = null, $author = null, $url = null, $description = null, $descriptionMsg = null ) {
+	function formatCredits( $name, $version = null, $subVersion = null, $subVersionURL = null, $author = null, $url = null, $description = null, $descriptionMsg = null ) {
 		$extension = isset( $url ) ? "[$url $name]" : $name;
 		$version = isset( $version ) ? wfMsg( 'version-version', $version ) : '';
 		$subVersion = isset( $subVersion ) ? wfMsg( 'version-svn-revision', $subVersion ) : '';
+		$subVersion = isset( $subVersionURL ) ? "[$subVersionURL $subVersion]" : $subVersion;
 
 		# Look for a localized description
 		if( isset( $descriptionMsg ) ) {
@@ -341,7 +351,7 @@
 	 * @param string $dir
 	 * @return mixed revision number as int, or false if not a SVN checkout
 	 */
-	public static function getSvnRevision( $dir , $extension = false) {
+	public static function getSvnRevision( $dir , $extension = false, $relPath = false) {
 		// http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
 		$entries = $dir . '/.svn/entries';
 
@@ -377,6 +387,31 @@
 			return false;
 		} else {
 			// subversion is release 1.4 or above
+			if ($relPath) {
+				$endPath = strstr( $content[4], 'tags' );
+				if (!$endPath) {
+					$endPath = strstr( $content[4], 'branches' );
+					if (!$endPath) {
+						$endPath = strstr( $content[4], 'trunk' );
+						if (!$endPath)
+							return false;
+					}
+				}
+				$endPath = trim ( $endPath );
+				if ($extension) {
+					$wmSvnPath = 'svn.wikimedia.org/svnroot/mediawiki';
+					$isWMSvn = strstr($content[5],$wmSvnPath);
+					if (!strcmp($isWMSvn,null)) {
+						return false;
+					} else {
+						$viewvcStart = 'http://svn.wikimedia.org/viewvc/mediawiki/';
+						$viewvcEnd = '/?pathrev=';
+						$viewvc = $viewvcStart . $endPath . $viewvcEnd;
+						return $viewvc;
+					}
+				}
+				return $endPath;
+			}
 			if ($extension)
 				// get the last file revsion number
 				return intval( $content[10]) ;

Follow-up revisions

RevisionCommit summaryAuthorDate
r55130Fixes for Shinjiman's Special:Version updates r49995-r50121:tstarling08:31, 16 August 2009

Comments

#Comment by Brion VIBBER (Talk | contribs)   17:54, 28 April 2009

This seems to be just discarding revision info for an extension checked out of a branch. Something ain't right...

#Comment by Brion VIBBER (Talk | contribs)   18:01, 28 April 2009

Ehhh, seems to work but it's got a lot of funky hardcoding, and looks like it would get confused by something from a third-party SVN. Instead of manually looking for 'tags', 'branches', and 'trunk', just chopping off the known svn.wikimedia.org/svnroot path prefix should do fine.

Branch checkout info didn't work because existing branches don't have the path specified in their about info, which kinda sucks but eh.

#Comment by Tim Starling (Talk | contribs)   08:32, 16 August 2009

Should be fixed as of r55130.

Status & tagging log

Views
Toolbox