* Include subversion revision number in Special:Version if available
authorBrion Vibber <brion@users.mediawiki.org>
Fri, 7 Apr 2006 00:00:50 +0000 (00:00 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Fri, 7 Apr 2006 00:00:50 +0000 (00:00 +0000)
Currently requires SimpleXML extension (available by default on PHP5)

RELEASE-NOTES
includes/SpecialVersion.php

index 9f06a38..a451495 100644 (file)
@@ -31,6 +31,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 5476) Invalid xhtml in German localization
 * (bug 5479) Id translation for preferences tabs caption
 * Added skinname and style path parameters to CBT version of MonoBook
+* Include subversion revision number in Special:Version if available
 
 
 == Compatibility ==
index 66c4e3e..1369a54 100644 (file)
@@ -45,8 +45,7 @@ class SpecialVersion {
         * @static
         */
        function MediaWikiCredits() {
-               global $wgVersion;
-
+               $version = $this->getVersion();
                $dbr =& wfGetDB( DB_SLAVE );
 
                $ret =
@@ -71,12 +70,18 @@ class SpecialVersion {
                Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
                or [http://www.gnu.org/copyleft/gpl.html read it online]
 
-               * [http://www.mediawiki.org/ MediaWiki]: $wgVersion
+               * [http://www.mediawiki.org/ MediaWiki]: $version
                * [http://www.php.net/ PHP]: " . phpversion() . " (" . php_sapi_name() . ")
                * " . $dbr->getSoftwareLink() . ": " . $dbr->getServerVersion();
 
                return str_replace( "\t\t", '', $ret );
        }
+       
+       function getVersion() {
+               global $wgVersion, $IP;
+               $svn = $this->getSvnRevision( $IP );
+               return $svn ? "$wgVersion (r$svn)" : $wgVersion;
+       }
 
        function extensionCredits() {
                global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunction;
@@ -225,6 +230,39 @@ class SpecialVersion {
                }
        }
 
+       /**
+        * Retrieve the revision number of a Subversion working directory.
+        *
+        * @param string $dir
+        * @return mixed revision number as int, or false if not a SVN checkout
+        */
+       function getSvnRevision( $dir ) {
+               if( !function_exists( 'simplexml_load_file' ) ) {
+                       // We could fall back to expat... YUCK
+                       return false;
+               }
+               
+               // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
+               $entries = $dir . '/.svn/entries';
+               
+               // SimpleXml whines about the xmlns...
+               wfSuppressWarnings();
+               $xml = simplexml_load_file( $entries );
+               wfRestoreWarnings();
+               
+               if( $xml ) {
+                       foreach( $xml->entry as $entry ) {
+                               if( $xml->entry[0]['name'] == '' ) {
+                                       // The directory entry should always have a revision marker.
+                                       if( $entry['revision'] ) {
+                                               return intval( $entry['revision'] );
+                                       }
+                               }
+                       }
+               }
+               return false;
+       }
+
        /**#@-*/
 }