Fixed spacing in db/debug/diff/externalstore/objectcache folder
[mediawiki.git] / includes / specials / SpecialVersion.php
blobb01058ac7ceab38f2f9d2ebe66b7ccfe9f9b8ed3
1 <?php
2 /**
3 * Implements Special:Version
5 * Copyright © 2005 Ævar Arnfjörð Bjarmason
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
22 * @file
23 * @ingroup SpecialPage
26 /**
27 * Give information about the version of MediaWiki, PHP, the DB and extensions
29 * @ingroup SpecialPage
31 class SpecialVersion extends SpecialPage {
33 protected $firstExtOpened = false;
35 protected static $extensionTypes = false;
37 protected static $viewvcUrls = array(
38 'svn+ssh://svn.wikimedia.org/svnroot/mediawiki' => 'http://svn.wikimedia.org/viewvc/mediawiki',
39 'http://svn.wikimedia.org/svnroot/mediawiki' => 'http://svn.wikimedia.org/viewvc/mediawiki',
40 'https://svn.wikimedia.org/svnroot/mediawiki' => 'https://svn.wikimedia.org/viewvc/mediawiki',
43 public function __construct() {
44 parent::__construct( 'Version' );
47 /**
48 * main()
50 public function execute( $par ) {
51 global $wgSpecialVersionShowHooks, $IP;
53 $this->setHeaders();
54 $this->outputHeader();
55 $out = $this->getOutput();
56 $out->allowClickjacking();
58 if ( $par !== 'Credits' ) {
59 $text =
60 $this->getMediaWikiCredits() .
61 $this->softwareInformation() .
62 $this->getEntryPointInfo() .
63 $this->getExtensionCredits();
64 if ( $wgSpecialVersionShowHooks ) {
65 $text .= $this->getWgHooks();
68 $out->addWikiText( $text );
69 $out->addHTML( $this->IPInfo() );
71 if ( $this->getRequest()->getVal( 'easteregg' ) ) {
72 // TODO: put something interesting here
74 } else {
75 // Credits sub page
77 // Header
78 $out->addHTML( wfMessage( 'version-credits-summary' )->parseAsBlock() );
80 $wikiText = file_get_contents( $IP . '/CREDITS' );
82 // Take everything from the first section onwards, to remove the (not localized) header
83 $wikiText = substr( $wikiText, strpos( $wikiText, '==' ) );
85 $out->addWikiText( $wikiText );
89 /**
90 * Returns wiki text showing the license information.
92 * @return string
94 private static function getMediaWikiCredits() {
95 $ret = Xml::element( 'h2', array( 'id' => 'mw-version-license' ), wfMessage( 'version-license' )->text() );
97 // This text is always left-to-right.
98 $ret .= '<div class="plainlinks">';
99 $ret .= "__NOTOC__
100 " . self::getCopyrightAndAuthorList() . "\n
101 " . wfMessage( 'version-license-info' )->text();
102 $ret .= '</div>';
104 return str_replace( "\t\t", '', $ret ) . "\n";
108 * Get the "MediaWiki is copyright 2001-20xx by lots of cool guys" text
110 * @return String
112 public static function getCopyrightAndAuthorList() {
113 global $wgLang;
115 if ( defined( 'MEDIAWIKI_INSTALL' ) ) {
116 $othersLink = '[http://www.mediawiki.org/wiki/Special:Version/Credits ' . wfMessage( 'version-poweredby-others' )->text() . ']';
117 } else {
118 $othersLink = '[[Special:Version/Credits|' . wfMessage( 'version-poweredby-others' )->text() . ']]';
121 $authorList = array(
122 'Magnus Manske', 'Brion Vibber', 'Lee Daniel Crocker',
123 'Tim Starling', 'Erik Möller', 'Gabriel Wicke', 'Ævar Arnfjörð Bjarmason',
124 'Niklas Laxström', 'Domas Mituzas', 'Rob Church', 'Yuri Astrakhan',
125 'Aryeh Gregor', 'Aaron Schulz', 'Andrew Garrett', 'Raimond Spekking',
126 'Alexandre Emsenhuber', 'Siebrand Mazeland', 'Chad Horohoe',
127 'Roan Kattouw', 'Trevor Parscal', 'Bryan Tong Minh', 'Sam Reed',
128 'Victor Vasiliev', 'Rotem Liss', 'Platonides', 'Antoine Musso',
129 'Timo Tijhof', 'Daniel Kinzler', 'Jeroen De Dauw', $othersLink
132 return wfMessage( 'version-poweredby-credits', date( 'Y' ),
133 $wgLang->listToText( $authorList ) )->text();
137 * Returns wiki text showing the third party software versions (apache, php, mysql).
139 * @return string
141 static function softwareInformation() {
142 $dbr = wfGetDB( DB_SLAVE );
144 // Put the software in an array of form 'name' => 'version'. All messages should
145 // be loaded here, so feel free to use wfMessage in the 'name'. Raw HTML or
146 // wikimarkup can be used.
147 $software = array();
148 $software['[https://www.mediawiki.org/ MediaWiki]'] = self::getVersionLinked();
149 $software['[http://www.php.net/ PHP]'] = phpversion() . " (" . PHP_SAPI . ")";
150 $software[$dbr->getSoftwareLink()] = $dbr->getServerInfo();
152 // Allow a hook to add/remove items.
153 wfRunHooks( 'SoftwareInfo', array( &$software ) );
155 $out = Xml::element( 'h2', array( 'id' => 'mw-version-software' ), wfMessage( 'version-software' )->text() ) .
156 Xml::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-software' ) ) .
157 "<tr>
158 <th>" . wfMessage( 'version-software-product' )->text() . "</th>
159 <th>" . wfMessage( 'version-software-version' )->text() . "</th>
160 </tr>\n";
162 foreach ( $software as $name => $version ) {
163 $out .= "<tr>
164 <td>" . $name . "</td>
165 <td dir=\"ltr\">" . $version . "</td>
166 </tr>\n";
169 return $out . Xml::closeElement( 'table' );
173 * Return a string of the MediaWiki version with SVN revision if available.
175 * @param $flags String
176 * @return mixed
178 public static function getVersion( $flags = '' ) {
179 global $wgVersion, $IP;
180 wfProfileIn( __METHOD__ );
182 $gitInfo = self::getGitHeadSha1( $IP );
183 $svnInfo = self::getSvnInfo( $IP );
184 if ( !$svnInfo && !$gitInfo ) {
185 $version = $wgVersion;
186 } elseif ( $gitInfo && $flags === 'nodb' ) {
187 $shortSha1 = substr( $gitInfo, 0, 7 );
188 $version = "$wgVersion ($shortSha1)";
189 } elseif ( $gitInfo ) {
190 $shortSha1 = substr( $gitInfo, 0, 7 );
191 $shortSha1 = wfMessage( 'parentheses' )->params( $shortSha1 )->escaped();
192 $version = "$wgVersion $shortSha1";
193 } elseif ( $flags === 'nodb' ) {
194 $version = "$wgVersion (r{$svnInfo['checkout-rev']})";
195 } else {
196 $version = $wgVersion . ' ' .
197 wfMessage(
198 'version-svn-revision',
199 isset( $info['directory-rev'] ) ? $info['directory-rev'] : '',
200 $info['checkout-rev']
201 )->text();
204 wfProfileOut( __METHOD__ );
205 return $version;
209 * Return a wikitext-formatted string of the MediaWiki version with a link to
210 * the SVN revision or the git SHA1 of head if available.
211 * Git is prefered over Svn
212 * The fallback is just $wgVersion
214 * @return mixed
216 public static function getVersionLinked() {
217 global $wgVersion;
218 wfProfileIn( __METHOD__ );
220 $gitVersion = self::getVersionLinkedGit();
221 if ( $gitVersion ) {
222 $v = $gitVersion;
223 } else {
224 $svnVersion = self::getVersionLinkedSvn();
225 if ( $svnVersion ) {
226 $v = $svnVersion;
227 } else {
228 $v = $wgVersion; // fallback
232 wfProfileOut( __METHOD__ );
233 return $v;
237 * @return string wgVersion + a link to subversion revision of svn BASE
239 private static function getVersionLinkedSvn() {
240 global $IP;
242 $info = self::getSvnInfo( $IP );
243 if ( !isset( $info['checkout-rev'] ) ) {
244 return false;
247 $linkText = wfMessage(
248 'version-svn-revision',
249 isset( $info['directory-rev'] ) ? $info['directory-rev'] : '',
250 $info['checkout-rev']
251 )->text();
253 if ( isset( $info['viewvc-url'] ) ) {
254 $version = "[{$info['viewvc-url']} $linkText]";
255 } else {
256 $version = $linkText;
259 return self::getwgVersionLinked() . " $version";
263 * @return string
265 private static function getwgVersionLinked() {
266 global $wgVersion;
267 $versionUrl = "";
268 if ( wfRunHooks( 'SpecialVersionVersionUrl', array( $wgVersion, &$versionUrl ) ) ) {
269 $versionParts = array();
270 preg_match( "/^(\d+\.\d+)/", $wgVersion, $versionParts );
271 $versionUrl = "https://www.mediawiki.org/wiki/MediaWiki_{$versionParts[1]}";
273 return "[$versionUrl $wgVersion]";
277 * @since 1.22 Returns the HEAD date in addition to the sha1 and link
278 * @return bool|string wgVersion + HEAD sha1 stripped to the first 7 chars with link and date, or false on failure
280 private static function getVersionLinkedGit() {
281 global $IP, $wgLang;
283 $gitInfo = new GitInfo( $IP );
284 $headSHA1 = $gitInfo->getHeadSHA1();
285 if ( !$headSHA1 ) {
286 return false;
289 $shortSHA1 = '(' . substr( $headSHA1, 0, 7 ) . ')';
291 $gitHeadUrl = $gitInfo->getHeadViewUrl();
292 if ( $gitHeadUrl !== false ) {
293 $shortSHA1 = "[$gitHeadUrl $shortSHA1]";
296 $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
297 if ( $gitHeadCommitDate ) {
298 $shortSHA1 .= "<br/>" . $wgLang->timeanddate( $gitHeadCommitDate, true );
301 return self::getwgVersionLinked() . " $shortSHA1";
305 * Returns an array with the base extension types.
306 * Type is stored as array key, the message as array value.
308 * TODO: ideally this would return all extension types, including
309 * those added by SpecialVersionExtensionTypes. This is not possible
310 * since this hook is passing along $this though.
312 * @since 1.17
314 * @return array
316 public static function getExtensionTypes() {
317 if ( self::$extensionTypes === false ) {
318 self::$extensionTypes = array(
319 'specialpage' => wfMessage( 'version-specialpages' )->text(),
320 'parserhook' => wfMessage( 'version-parserhooks' )->text(),
321 'variable' => wfMessage( 'version-variables' )->text(),
322 'media' => wfMessage( 'version-mediahandlers' )->text(),
323 'antispam' => wfMessage( 'version-antispam' )->text(),
324 'skin' => wfMessage( 'version-skins' )->text(),
325 'api' => wfMessage( 'version-api' )->text(),
326 'other' => wfMessage( 'version-other' )->text(),
329 wfRunHooks( 'ExtensionTypes', array( &self::$extensionTypes ) );
332 return self::$extensionTypes;
336 * Returns the internationalized name for an extension type.
338 * @since 1.17
340 * @param $type String
342 * @return string
344 public static function getExtensionTypeName( $type ) {
345 $types = self::getExtensionTypes();
346 return isset( $types[$type] ) ? $types[$type] : $types['other'];
350 * Generate wikitext showing extensions name, URL, author and description.
352 * @return String: Wikitext
354 function getExtensionCredits() {
355 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser;
357 if ( !count( $wgExtensionCredits ) && !count( $wgExtensionFunctions ) ) {
358 return '';
361 $extensionTypes = self::getExtensionTypes();
364 * @deprecated as of 1.17, use hook ExtensionTypes instead.
366 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
368 $out = Xml::element( 'h2', array( 'id' => 'mw-version-ext' ), $this->msg( 'version-extensions' )->text() ) .
369 Xml::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-ext' ) );
371 // Make sure the 'other' type is set to an array.
372 if ( !array_key_exists( 'other', $wgExtensionCredits ) ) {
373 $wgExtensionCredits['other'] = array();
376 // Find all extensions that do not have a valid type and give them the type 'other'.
377 foreach ( $wgExtensionCredits as $type => $extensions ) {
378 if ( !array_key_exists( $type, $extensionTypes ) ) {
379 $wgExtensionCredits['other'] = array_merge( $wgExtensionCredits['other'], $extensions );
383 // Loop through the extension categories to display their extensions in the list.
384 foreach ( $extensionTypes as $type => $message ) {
385 if ( $type != 'other' ) {
386 $out .= $this->getExtensionCategory( $type, $message );
390 // We want the 'other' type to be last in the list.
391 $out .= $this->getExtensionCategory( 'other', $extensionTypes['other'] );
393 if ( count( $wgExtensionFunctions ) ) {
394 $out .= $this->openExtType( $this->msg( 'version-extension-functions' )->text(), 'extension-functions' );
395 $out .= '<tr><td colspan="4">' . $this->listToText( $wgExtensionFunctions ) . "</td></tr>\n";
398 $tags = $wgParser->getTags();
399 $cnt = count( $tags );
401 if ( $cnt ) {
402 for ( $i = 0; $i < $cnt; ++$i ) {
403 $tags[$i] = "&lt;{$tags[$i]}&gt;";
405 $out .= $this->openExtType( $this->msg( 'version-parser-extensiontags' )->text(), 'parser-tags' );
406 $out .= '<tr><td colspan="4">' . $this->listToText( $tags ) . "</td></tr>\n";
409 $fhooks = $wgParser->getFunctionHooks();
410 if ( count( $fhooks ) ) {
411 $out .= $this->openExtType( $this->msg( 'version-parser-function-hooks' )->text(), 'parser-function-hooks' );
412 $out .= '<tr><td colspan="4">' . $this->listToText( $fhooks ) . "</td></tr>\n";
415 $out .= Xml::closeElement( 'table' );
417 return $out;
421 * Creates and returns the HTML for a single extension category.
423 * @since 1.17
425 * @param $type String
426 * @param $message String
428 * @return string
430 protected function getExtensionCategory( $type, $message ) {
431 global $wgExtensionCredits;
433 $out = '';
435 if ( array_key_exists( $type, $wgExtensionCredits ) && count( $wgExtensionCredits[$type] ) > 0 ) {
436 $out .= $this->openExtType( $message, 'credits-' . $type );
438 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
440 foreach ( $wgExtensionCredits[$type] as $extension ) {
441 $out .= $this->getCreditsForExtension( $extension );
445 return $out;
449 * Callback to sort extensions by type.
450 * @param $a array
451 * @param $b array
452 * @return int
454 function compare( $a, $b ) {
455 if ( $a['name'] === $b['name'] ) {
456 return 0;
457 } else {
458 return $this->getLanguage()->lc( $a['name'] ) > $this->getLanguage()->lc( $b['name'] )
460 : -1;
465 * Creates and formats the credits for a single extension and returns this.
467 * @param $extension Array
469 * @return string
471 function getCreditsForExtension( array $extension ) {
472 global $wgLang;
474 $name = isset( $extension['name'] ) ? $extension['name'] : '[no name]';
476 $vcsText = false;
478 if ( isset( $extension['path'] ) ) {
479 $gitInfo = new GitInfo( dirname( $extension['path'] ) );
480 $gitHeadSHA1 = $gitInfo->getHeadSHA1();
481 if ( $gitHeadSHA1 !== false ) {
482 $vcsText = '(' . substr( $gitHeadSHA1, 0, 7 ) . ')';
483 $gitViewerUrl = $gitInfo->getHeadViewUrl();
484 if ( $gitViewerUrl !== false ) {
485 $vcsText = "[$gitViewerUrl $vcsText]";
487 $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
488 if ( $gitHeadCommitDate ) {
489 $vcsText .= "<br/>" . $wgLang->timeanddate( $gitHeadCommitDate, true );
491 } else {
492 $svnInfo = self::getSvnInfo( dirname( $extension['path'] ) );
493 # Make subversion text/link.
494 if ( $svnInfo !== false ) {
495 $directoryRev = isset( $svnInfo['directory-rev'] ) ? $svnInfo['directory-rev'] : null;
496 $vcsText = $this->msg( 'version-svn-revision', $directoryRev, $svnInfo['checkout-rev'] )->text();
497 $vcsText = isset( $svnInfo['viewvc-url'] ) ? '[' . $svnInfo['viewvc-url'] . " $vcsText]" : $vcsText;
502 # Make main link (or just the name if there is no URL).
503 if ( isset( $extension['url'] ) ) {
504 $mainLink = "[{$extension['url']} $name]";
505 } else {
506 $mainLink = $name;
509 if ( isset( $extension['version'] ) ) {
510 $versionText = '<span class="mw-version-ext-version">' .
511 $this->msg( 'version-version', $extension['version'] )->text() .
512 '</span>';
513 } else {
514 $versionText = '';
517 # Make description text.
518 $description = isset ( $extension['description'] ) ? $extension['description'] : '';
520 if ( isset ( $extension['descriptionmsg'] ) ) {
521 # Look for a localized description.
522 $descriptionMsg = $extension['descriptionmsg'];
524 if ( is_array( $descriptionMsg ) ) {
525 $descriptionMsgKey = $descriptionMsg[0]; // Get the message key
526 array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
527 array_map( "htmlspecialchars", $descriptionMsg ); // For sanity
528 $description = $this->msg( $descriptionMsgKey, $descriptionMsg )->text();
529 } else {
530 $description = $this->msg( $descriptionMsg )->text();
534 if ( $vcsText !== false ) {
535 $extNameVer = "<tr>
536 <td><em>$mainLink $versionText</em></td>
537 <td><em>$vcsText</em></td>";
538 } else {
539 $extNameVer = "<tr>
540 <td colspan=\"2\"><em>$mainLink $versionText</em></td>";
543 $author = isset ( $extension['author'] ) ? $extension['author'] : array();
544 $extDescAuthor = "<td>$description</td>
545 <td>" . $this->listAuthors( $author, false ) . "</td>
546 </tr>\n";
548 return $extNameVer . $extDescAuthor;
552 * Generate wikitext showing hooks in $wgHooks.
554 * @return String: wikitext
556 private function getWgHooks() {
557 global $wgHooks;
559 if ( count( $wgHooks ) ) {
560 $myWgHooks = $wgHooks;
561 ksort( $myWgHooks );
563 $ret = Xml::element( 'h2', array( 'id' => 'mw-version-hooks' ), $this->msg( 'version-hooks' )->text() ) .
564 Xml::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-hooks' ) ) .
565 "<tr>
566 <th>" . $this->msg( 'version-hook-name' )->text() . "</th>
567 <th>" . $this->msg( 'version-hook-subscribedby' )->text() . "</th>
568 </tr>\n";
570 foreach ( $myWgHooks as $hook => $hooks ) {
571 $ret .= "<tr>
572 <td>$hook</td>
573 <td>" . $this->listToText( $hooks ) . "</td>
574 </tr>\n";
577 $ret .= Xml::closeElement( 'table' );
578 return $ret;
579 } else {
580 return '';
584 private function openExtType( $text, $name = null ) {
585 $opt = array( 'colspan' => 4 );
586 $out = '';
588 if ( $this->firstExtOpened ) {
589 // Insert a spacing line
590 $out .= '<tr class="sv-space">' . Html::element( 'td', $opt ) . "</tr>\n";
592 $this->firstExtOpened = true;
594 if ( $name ) {
595 $opt['id'] = "sv-$name";
598 $out .= "<tr>" . Xml::element( 'th', $opt, $text ) . "</tr>\n";
600 return $out;
604 * Get information about client's IP address.
606 * @return String: HTML fragment
608 private function IPInfo() {
609 $ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) );
610 return "<!-- visited from $ip -->\n<span style='display:none'>visited from $ip</span>";
614 * Return a formatted unsorted list of authors
616 * @param $authors mixed: string or array of strings
617 * @return String: HTML fragment
619 function listAuthors( $authors ) {
620 $list = array();
621 foreach ( (array)$authors as $item ) {
622 if ( $item == '...' ) {
623 $list[] = $this->msg( 'version-poweredby-others' )->text();
624 } elseif ( substr( $item, -5 ) == ' ...]' ) {
625 $list[] = substr( $item, 0, -4 ) . $this->msg( 'version-poweredby-others' )->text() . "]";
626 } else {
627 $list[] = $item;
630 return $this->listToText( $list, false );
634 * Convert an array of items into a list for display.
636 * @param array $list of elements to display
637 * @param $sort Boolean: whether to sort the items in $list
639 * @return String
641 function listToText( $list, $sort = true ) {
642 $cnt = count( $list );
644 if ( $cnt == 1 ) {
645 // Enforce always returning a string
646 return (string)self::arrayToString( $list[0] );
647 } elseif ( $cnt == 0 ) {
648 return '';
649 } else {
650 if ( $sort ) {
651 sort( $list );
653 return $this->getLanguage()->listToText( array_map( array( __CLASS__, 'arrayToString' ), $list ) );
658 * Convert an array or object to a string for display.
660 * @param $list Mixed: will convert an array to string if given and return
661 * the paramater unaltered otherwise
663 * @return Mixed
665 public static function arrayToString( $list ) {
666 if ( is_array( $list ) && count( $list ) == 1 ) {
667 $list = $list[0];
669 if ( is_object( $list ) ) {
670 $class = wfMessage( 'parentheses' )->params( get_class( $list ) )->escaped();
671 return $class;
672 } elseif ( !is_array( $list ) ) {
673 return $list;
674 } else {
675 if ( is_object( $list[0] ) ) {
676 $class = get_class( $list[0] );
677 } else {
678 $class = $list[0];
680 return wfMessage( 'parentheses' )->params( "$class, {$list[1]}" )->escaped();
685 * Get an associative array of information about a given path, from its .svn
686 * subdirectory. Returns false on error, such as if the directory was not
687 * checked out with subversion.
689 * Returned keys are:
690 * Required:
691 * checkout-rev The revision which was checked out
692 * Optional:
693 * directory-rev The revision when the directory was last modified
694 * url The subversion URL of the directory
695 * repo-url The base URL of the repository
696 * viewvc-url A ViewVC URL pointing to the checked-out revision
697 * @param $dir string
698 * @return array|bool
700 public static function getSvnInfo( $dir ) {
701 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
702 $entries = $dir . '/.svn/entries';
704 if ( !file_exists( $entries ) ) {
705 return false;
708 $lines = file( $entries );
709 if ( !count( $lines ) ) {
710 return false;
713 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
714 if ( preg_match( '/^<\?xml/', $lines[0] ) ) {
715 // subversion is release <= 1.3
716 if ( !function_exists( 'simplexml_load_file' ) ) {
717 // We could fall back to expat... YUCK
718 return false;
721 // SimpleXml whines about the xmlns...
722 wfSuppressWarnings();
723 $xml = simplexml_load_file( $entries );
724 wfRestoreWarnings();
726 if ( $xml ) {
727 foreach ( $xml->entry as $entry ) {
728 if ( $xml->entry[0]['name'] == '' ) {
729 // The directory entry should always have a revision marker.
730 if ( $entry['revision'] ) {
731 return array( 'checkout-rev' => intval( $entry['revision'] ) );
737 return false;
740 // Subversion is release 1.4 or above.
741 if ( count( $lines ) < 11 ) {
742 return false;
745 $info = array(
746 'checkout-rev' => intval( trim( $lines[3] ) ),
747 'url' => trim( $lines[4] ),
748 'repo-url' => trim( $lines[5] ),
749 'directory-rev' => intval( trim( $lines[10] ) )
752 if ( isset( self::$viewvcUrls[$info['repo-url']] ) ) {
753 $viewvc = str_replace(
754 $info['repo-url'],
755 self::$viewvcUrls[$info['repo-url']],
756 $info['url']
759 $viewvc .= '/?pathrev=';
760 $viewvc .= urlencode( $info['checkout-rev'] );
761 $info['viewvc-url'] = $viewvc;
764 return $info;
768 * Retrieve the revision number of a Subversion working directory.
770 * @param string $dir directory of the svn checkout
772 * @return Integer: revision number as int
774 public static function getSvnRevision( $dir ) {
775 $info = self::getSvnInfo( $dir );
777 if ( $info === false ) {
778 return false;
779 } elseif ( isset( $info['checkout-rev'] ) ) {
780 return $info['checkout-rev'];
781 } else {
782 return false;
787 * @param string $dir directory of the git checkout
788 * @return bool|String sha1 of commit HEAD points to
790 public static function getGitHeadSha1( $dir ) {
791 $repo = new GitInfo( $dir );
792 return $repo->getHeadSHA1();
796 * Get the list of entry points and their URLs
797 * @return string Wikitext
799 public function getEntryPointInfo() {
800 global $wgArticlePath, $wgScriptPath;
801 $scriptPath = $wgScriptPath ? $wgScriptPath : "/";
802 $entryPoints = array(
803 'version-entrypoints-articlepath' => $wgArticlePath,
804 'version-entrypoints-scriptpath' => $scriptPath,
805 'version-entrypoints-index-php' => wfScript( 'index' ),
806 'version-entrypoints-api-php' => wfScript( 'api' ),
807 'version-entrypoints-load-php' => wfScript( 'load' ),
810 $language = $this->getLanguage();
811 $thAttribures = array(
812 'dir' => $language->getDir(),
813 'lang' => $language->getCode()
815 $out = Html::element( 'h2', array( 'id' => 'mw-version-entrypoints' ), $this->msg( 'version-entrypoints' )->text() ) .
816 Html::openElement( 'table',
817 array(
818 'class' => 'wikitable plainlinks',
819 'id' => 'mw-version-entrypoints-table',
820 'dir' => 'ltr',
821 'lang' => 'en'
824 Html::openElement( 'tr' ) .
825 Html::element( 'th', $thAttribures, $this->msg( 'version-entrypoints-header-entrypoint' )->text() ) .
826 Html::element( 'th', $thAttribures, $this->msg( 'version-entrypoints-header-url' )->text() ) .
827 Html::closeElement( 'tr' );
829 foreach ( $entryPoints as $message => $value ) {
830 $url = wfExpandUrl( $value, PROTO_RELATIVE );
831 $out .= Html::openElement( 'tr' ) .
832 // ->text() looks like it should be ->parse(), but this function
833 // returns wikitext, not HTML, boo
834 Html::rawElement( 'td', array(), $this->msg( $message )->text() ) .
835 Html::rawElement( 'td', array(), Html::rawElement( 'code', array(), "[$url $value]" ) ) .
836 Html::closeElement( 'tr' );
839 $out .= Html::closeElement( 'table' );
840 return $out;
843 protected function getGroupName() {
844 return 'wiki';