Index: trunk/phase3/RELEASE-NOTES-1.19 |
— | — | @@ -122,6 +122,7 @@ |
123 | 123 | * sha1 xml tag added to XML dump file. |
124 | 124 | * (bug 33646) Badtitle error page now emits a 400 HTTP status. |
125 | 125 | * Special:MovePage now has a dropdown menu for namespaces. |
| 126 | +* (bug 34420) Special:Version now shows git HEAD sha1 when available |
126 | 127 | |
127 | 128 | === Bug fixes in 1.19 === |
128 | 129 | * $wgUploadNavigationUrl should be used for file redlinks if. |
Index: trunk/phase3/includes/specials/SpecialVersion.php |
— | — | @@ -180,37 +180,68 @@ |
181 | 181 | |
182 | 182 | /** |
183 | 183 | * Return a wikitext-formatted string of the MediaWiki version with a link to |
184 | | - * the SVN revision if available. |
| 184 | + * the SVN revision or the git SHA1 of head if available. |
| 185 | + * Git is prefered over Svn |
| 186 | + * The fallback is just $wgVersion |
185 | 187 | * |
186 | 188 | * @return mixed |
187 | 189 | */ |
188 | 190 | public static function getVersionLinked() { |
189 | | - global $wgVersion, $IP; |
| 191 | + global $wgVersion; |
190 | 192 | wfProfileIn( __METHOD__ ); |
191 | 193 | |
| 194 | + if( $gitVersion = self::getVersionLinkedGit() ) { |
| 195 | + $v = $gitVersion; |
| 196 | + } elseif( $svnVersion = self::getVersionLinkedSvn() ) { |
| 197 | + $v = $svnVersion; |
| 198 | + } else { |
| 199 | + $v = $wgVersion; // fallback |
| 200 | + } |
| 201 | + |
| 202 | + wfProfileOut( __METHOD__ ); |
| 203 | + return $v; |
| 204 | + } |
| 205 | + |
| 206 | + /** |
| 207 | + * @return string wgVersion + a link to subversion revision of svn BASE |
| 208 | + */ |
| 209 | + private static function getVersionLinkedSvn() { |
| 210 | + global $wgVersion, $IP; |
| 211 | + |
192 | 212 | $info = self::getSvnInfo( $IP ); |
| 213 | + if( !isset( $info['checkout-rev'] ) ) { |
| 214 | + return false; |
| 215 | + } |
193 | 216 | |
194 | | - if ( isset( $info['checkout-rev'] ) ) { |
195 | | - $linkText = wfMsg( |
196 | | - 'version-svn-revision', |
197 | | - isset( $info['directory-rev'] ) ? $info['directory-rev'] : '', |
198 | | - $info['checkout-rev'] |
199 | | - ); |
| 217 | + $linkText = wfMsg( |
| 218 | + 'version-svn-revision', |
| 219 | + isset( $info['directory-rev'] ) ? $info['directory-rev'] : '', |
| 220 | + $info['checkout-rev'] |
| 221 | + ); |
200 | 222 | |
201 | | - if ( isset( $info['viewvc-url'] ) ) { |
202 | | - $version = "$wgVersion [{$info['viewvc-url']} $linkText]"; |
203 | | - } else { |
204 | | - $version = "$wgVersion $linkText"; |
205 | | - } |
| 223 | + if ( isset( $info['viewvc-url'] ) ) { |
| 224 | + $version = "$wgVersion [{$info['viewvc-url']} $linkText]"; |
206 | 225 | } else { |
207 | | - $version = $wgVersion; |
| 226 | + $version = "$wgVersion $linkText"; |
208 | 227 | } |
209 | 228 | |
210 | | - wfProfileOut( __METHOD__ ); |
211 | 229 | return $version; |
212 | 230 | } |
213 | 231 | |
214 | 232 | /** |
| 233 | + * @return false|string wgVersion + HEAD sha1 stripped to the first 7 chars |
| 234 | + */ |
| 235 | + private static function getVersionLinkedGit() { |
| 236 | + global $wgVersion, $IP; |
| 237 | + if( ! $sha1 = self::getGitHeadSha1( $IP) ) { |
| 238 | + return false; |
| 239 | + } |
| 240 | + $short_sha1 = substr( $sha1, 0, 7 ); |
| 241 | + |
| 242 | + return "$wgVersion ($short_sha1)"; |
| 243 | + } |
| 244 | + |
| 245 | + /** |
215 | 246 | * Returns an array with the base extension types. |
216 | 247 | * Type is stored as array key, the message as array value. |
217 | 248 | * |
— | — | @@ -678,6 +709,33 @@ |
679 | 710 | } |
680 | 711 | } |
681 | 712 | |
| 713 | + /** |
| 714 | + * @param $dir String: directory of the git checkout |
| 715 | + * @return false|String sha1 of commit HEAD points to |
| 716 | + */ |
| 717 | + public static function getGitHeadSha1( $dir ) { |
| 718 | + $BASEDIR = "{$dir}/.git/"; |
| 719 | + $HEADfile = "{$BASEDIR}/HEAD"; |
| 720 | + |
| 721 | + if( !file_exists( $HEADfile ) ) { |
| 722 | + return false; |
| 723 | + } |
| 724 | + |
| 725 | + preg_match( "/ref: (.*)/", |
| 726 | + file_get_contents( $HEADfile), $m ); |
| 727 | + |
| 728 | + $REFfile = "{$BASEDIR}{$m[1]}"; |
| 729 | + if( !file_exists( $REFfile ) ) { |
| 730 | + print "$REFfile doesnot exit?"; |
| 731 | + return false; |
| 732 | + } |
| 733 | + |
| 734 | + $sha1 = chop(file_get_contents( $REFfile )); |
| 735 | + |
| 736 | + return $sha1; |
| 737 | + } |
| 738 | + |
| 739 | + |
682 | 740 | function showEasterEgg() { |
683 | 741 | $rx = $rp = $xe = ''; |
684 | 742 | $alpha = array("", "kbQW", "\$\n()"); |