Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / specials / SpecialVersion.php
blob5ba785f57d5f548f9868720a5d14debcd1ac8d82
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 = '[//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 $translatorsLink = '[//translatewiki.net/wiki/Translating:MediaWiki/Credits ' . wfMessage( 'version-poweredby-translators' )->text() . ']';
123 $authorList = array(
124 'Magnus Manske', 'Brion Vibber', 'Lee Daniel Crocker',
125 'Tim Starling', 'Erik Möller', 'Gabriel Wicke', 'Ævar Arnfjörð Bjarmason',
126 'Niklas Laxström', 'Domas Mituzas', 'Rob Church', 'Yuri Astrakhan',
127 'Aryeh Gregor', 'Aaron Schulz', 'Andrew Garrett', 'Raimond Spekking',
128 'Alexandre Emsenhuber', 'Siebrand Mazeland', 'Chad Horohoe',
129 'Roan Kattouw', 'Trevor Parscal', 'Bryan Tong Minh', 'Sam Reed',
130 'Victor Vasiliev', 'Rotem Liss', 'Platonides', 'Antoine Musso',
131 'Timo Tijhof', 'Daniel Kinzler', 'Jeroen De Dauw', $othersLink,
132 $translatorsLink
135 return wfMessage( 'version-poweredby-credits', MWTimestamp::getLocalInstance()->format( 'Y' ),
136 $wgLang->listToText( $authorList ) )->text();
140 * Returns wiki text showing the third party software versions (apache, php, mysql).
142 * @return string
144 static function softwareInformation() {
145 $dbr = wfGetDB( DB_SLAVE );
147 // Put the software in an array of form 'name' => 'version'. All messages should
148 // be loaded here, so feel free to use wfMessage in the 'name'. Raw HTML or
149 // wikimarkup can be used.
150 $software = array();
151 $software['[https://www.mediawiki.org/ MediaWiki]'] = self::getVersionLinked();
152 $software['[http://www.php.net/ PHP]'] = phpversion() . " (" . PHP_SAPI . ")";
153 $software[$dbr->getSoftwareLink()] = $dbr->getServerInfo();
155 // Allow a hook to add/remove items.
156 wfRunHooks( 'SoftwareInfo', array( &$software ) );
158 $out = Xml::element( 'h2', array( 'id' => 'mw-version-software' ), wfMessage( 'version-software' )->text() ) .
159 Xml::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-software' ) ) .
160 "<tr>
161 <th>" . wfMessage( 'version-software-product' )->text() . "</th>
162 <th>" . wfMessage( 'version-software-version' )->text() . "</th>
163 </tr>\n";
165 foreach ( $software as $name => $version ) {
166 $out .= "<tr>
167 <td>" . $name . "</td>
168 <td dir=\"ltr\">" . $version . "</td>
169 </tr>\n";
172 return $out . Xml::closeElement( 'table' );
176 * Return a string of the MediaWiki version with SVN revision if available.
178 * @param $flags String
179 * @return mixed
181 public static function getVersion( $flags = '' ) {
182 global $wgVersion, $IP;
183 wfProfileIn( __METHOD__ );
185 $gitInfo = self::getGitHeadSha1( $IP );
186 $svnInfo = self::getSvnInfo( $IP );
187 if ( !$svnInfo && !$gitInfo ) {
188 $version = $wgVersion;
189 } elseif ( $gitInfo && $flags === 'nodb' ) {
190 $shortSha1 = substr( $gitInfo, 0, 7 );
191 $version = "$wgVersion ($shortSha1)";
192 } elseif ( $gitInfo ) {
193 $shortSha1 = substr( $gitInfo, 0, 7 );
194 $shortSha1 = wfMessage( 'parentheses' )->params( $shortSha1 )->escaped();
195 $version = "$wgVersion $shortSha1";
196 } elseif ( $flags === 'nodb' ) {
197 $version = "$wgVersion (r{$svnInfo['checkout-rev']})";
198 } else {
199 $version = $wgVersion . ' ' .
200 wfMessage(
201 'version-svn-revision',
202 isset( $info['directory-rev'] ) ? $info['directory-rev'] : '',
203 $info['checkout-rev']
204 )->text();
207 wfProfileOut( __METHOD__ );
208 return $version;
212 * Return a wikitext-formatted string of the MediaWiki version with a link to
213 * the SVN revision or the git SHA1 of head if available.
214 * Git is prefered over Svn
215 * The fallback is just $wgVersion
217 * @return mixed
219 public static function getVersionLinked() {
220 global $wgVersion;
221 wfProfileIn( __METHOD__ );
223 $gitVersion = self::getVersionLinkedGit();
224 if ( $gitVersion ) {
225 $v = $gitVersion;
226 } else {
227 $svnVersion = self::getVersionLinkedSvn();
228 if ( $svnVersion ) {
229 $v = $svnVersion;
230 } else {
231 $v = $wgVersion; // fallback
235 wfProfileOut( __METHOD__ );
236 return $v;
240 * @return string wgVersion + a link to subversion revision of svn BASE
242 private static function getVersionLinkedSvn() {
243 global $IP;
245 $info = self::getSvnInfo( $IP );
246 if ( !isset( $info['checkout-rev'] ) ) {
247 return false;
250 $linkText = wfMessage(
251 'version-svn-revision',
252 isset( $info['directory-rev'] ) ? $info['directory-rev'] : '',
253 $info['checkout-rev']
254 )->text();
256 if ( isset( $info['viewvc-url'] ) ) {
257 $version = "[{$info['viewvc-url']} $linkText]";
258 } else {
259 $version = $linkText;
262 return self::getwgVersionLinked() . " $version";
266 * @return string
268 private static function getwgVersionLinked() {
269 global $wgVersion;
270 $versionUrl = "";
271 if ( wfRunHooks( 'SpecialVersionVersionUrl', array( $wgVersion, &$versionUrl ) ) ) {
272 $versionParts = array();
273 preg_match( "/^(\d+\.\d+)/", $wgVersion, $versionParts );
274 $versionUrl = "https://www.mediawiki.org/wiki/MediaWiki_{$versionParts[1]}";
276 return "[$versionUrl $wgVersion]";
280 * @since 1.22 Returns the HEAD date in addition to the sha1 and link
281 * @return bool|string wgVersion + HEAD sha1 stripped to the first 7 chars with link and date, or false on failure
283 private static function getVersionLinkedGit() {
284 global $IP, $wgLang;
286 $gitInfo = new GitInfo( $IP );
287 $headSHA1 = $gitInfo->getHeadSHA1();
288 if ( !$headSHA1 ) {
289 return false;
292 $shortSHA1 = '(' . substr( $headSHA1, 0, 7 ) . ')';
294 $gitHeadUrl = $gitInfo->getHeadViewUrl();
295 if ( $gitHeadUrl !== false ) {
296 $shortSHA1 = "[$gitHeadUrl $shortSHA1]";
299 $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
300 if ( $gitHeadCommitDate ) {
301 $shortSHA1 .= "<br/>" . $wgLang->timeanddate( $gitHeadCommitDate, true );
304 return self::getwgVersionLinked() . " $shortSHA1";
308 * Returns an array with the base extension types.
309 * Type is stored as array key, the message as array value.
311 * TODO: ideally this would return all extension types, including
312 * those added by SpecialVersionExtensionTypes. This is not possible
313 * since this hook is passing along $this though.
315 * @since 1.17
317 * @return array
319 public static function getExtensionTypes() {
320 if ( self::$extensionTypes === false ) {
321 self::$extensionTypes = array(
322 'specialpage' => wfMessage( 'version-specialpages' )->text(),
323 'parserhook' => wfMessage( 'version-parserhooks' )->text(),
324 'variable' => wfMessage( 'version-variables' )->text(),
325 'media' => wfMessage( 'version-mediahandlers' )->text(),
326 'antispam' => wfMessage( 'version-antispam' )->text(),
327 'skin' => wfMessage( 'version-skins' )->text(),
328 'api' => wfMessage( 'version-api' )->text(),
329 'other' => wfMessage( 'version-other' )->text(),
332 wfRunHooks( 'ExtensionTypes', array( &self::$extensionTypes ) );
335 return self::$extensionTypes;
339 * Returns the internationalized name for an extension type.
341 * @since 1.17
343 * @param $type String
345 * @return string
347 public static function getExtensionTypeName( $type ) {
348 $types = self::getExtensionTypes();
349 return isset( $types[$type] ) ? $types[$type] : $types['other'];
353 * Generate wikitext showing extensions name, URL, author and description.
355 * @return String: Wikitext
357 function getExtensionCredits() {
358 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser;
360 if ( !count( $wgExtensionCredits ) && !count( $wgExtensionFunctions ) ) {
361 return '';
364 $extensionTypes = self::getExtensionTypes();
367 * @deprecated as of 1.17, use hook ExtensionTypes instead.
369 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
371 $out = Xml::element( 'h2', array( 'id' => 'mw-version-ext' ), $this->msg( 'version-extensions' )->text() ) .
372 Xml::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-ext' ) );
374 // Make sure the 'other' type is set to an array.
375 if ( !array_key_exists( 'other', $wgExtensionCredits ) ) {
376 $wgExtensionCredits['other'] = array();
379 // Find all extensions that do not have a valid type and give them the type 'other'.
380 foreach ( $wgExtensionCredits as $type => $extensions ) {
381 if ( !array_key_exists( $type, $extensionTypes ) ) {
382 $wgExtensionCredits['other'] = array_merge( $wgExtensionCredits['other'], $extensions );
386 // Loop through the extension categories to display their extensions in the list.
387 foreach ( $extensionTypes as $type => $message ) {
388 if ( $type != 'other' ) {
389 $out .= $this->getExtensionCategory( $type, $message );
393 // We want the 'other' type to be last in the list.
394 $out .= $this->getExtensionCategory( 'other', $extensionTypes['other'] );
396 $tags = $wgParser->getTags();
397 $cnt = count( $tags );
399 if ( $cnt ) {
400 for ( $i = 0; $i < $cnt; ++$i ) {
401 $tags[$i] = "&lt;{$tags[$i]}&gt;";
403 $out .= $this->openExtType( $this->msg( 'version-parser-extensiontags' )->text(), 'parser-tags' );
404 $out .= '<tr><td colspan="4">' . $this->listToText( $tags ) . "</td></tr>\n";
407 $fhooks = $wgParser->getFunctionHooks();
408 if ( count( $fhooks ) ) {
409 $out .= $this->openExtType( $this->msg( 'version-parser-function-hooks' )->text(), 'parser-function-hooks' );
410 $out .= '<tr><td colspan="4">' . $this->listToText( $fhooks ) . "</td></tr>\n";
413 $out .= Xml::closeElement( 'table' );
415 return $out;
419 * Creates and returns the HTML for a single extension category.
421 * @since 1.17
423 * @param $type String
424 * @param $message String
426 * @return string
428 protected function getExtensionCategory( $type, $message ) {
429 global $wgExtensionCredits;
431 $out = '';
433 if ( array_key_exists( $type, $wgExtensionCredits ) && count( $wgExtensionCredits[$type] ) > 0 ) {
434 $out .= $this->openExtType( $message, 'credits-' . $type );
436 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
438 foreach ( $wgExtensionCredits[$type] as $extension ) {
439 $out .= $this->getCreditsForExtension( $extension );
443 return $out;
447 * Callback to sort extensions by type.
448 * @param $a array
449 * @param $b array
450 * @return int
452 function compare( $a, $b ) {
453 if ( $a['name'] === $b['name'] ) {
454 return 0;
455 } else {
456 return $this->getLanguage()->lc( $a['name'] ) > $this->getLanguage()->lc( $b['name'] )
458 : -1;
463 * Creates and formats the credits for a single extension and returns this.
465 * @param $extension Array
467 * @return string
469 function getCreditsForExtension( array $extension ) {
470 global $wgLang;
472 $name = isset( $extension['name'] ) ? $extension['name'] : '[no name]';
474 $vcsText = false;
476 if ( isset( $extension['path'] ) ) {
477 $gitInfo = new GitInfo( dirname( $extension['path'] ) );
478 $gitHeadSHA1 = $gitInfo->getHeadSHA1();
479 if ( $gitHeadSHA1 !== false ) {
480 $vcsText = '(' . substr( $gitHeadSHA1, 0, 7 ) . ')';
481 $gitViewerUrl = $gitInfo->getHeadViewUrl();
482 if ( $gitViewerUrl !== false ) {
483 $vcsText = "[$gitViewerUrl $vcsText]";
485 $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
486 if ( $gitHeadCommitDate ) {
487 $vcsText .= "<br/>" . $wgLang->timeanddate( $gitHeadCommitDate, true );
489 } else {
490 $svnInfo = self::getSvnInfo( dirname( $extension['path'] ) );
491 # Make subversion text/link.
492 if ( $svnInfo !== false ) {
493 $directoryRev = isset( $svnInfo['directory-rev'] ) ? $svnInfo['directory-rev'] : null;
494 $vcsText = $this->msg( 'version-svn-revision', $directoryRev, $svnInfo['checkout-rev'] )->text();
495 $vcsText = isset( $svnInfo['viewvc-url'] ) ? '[' . $svnInfo['viewvc-url'] . " $vcsText]" : $vcsText;
500 # Make main link (or just the name if there is no URL).
501 if ( isset( $extension['url'] ) ) {
502 $mainLink = "[{$extension['url']} $name]";
503 } else {
504 $mainLink = $name;
507 if ( isset( $extension['version'] ) ) {
508 $versionText = '<span class="mw-version-ext-version">' .
509 $this->msg( 'version-version', $extension['version'] )->text() .
510 '</span>';
511 } else {
512 $versionText = '';
515 # Make description text.
516 $description = isset( $extension['description'] ) ? $extension['description'] : '';
518 if ( isset( $extension['descriptionmsg'] ) ) {
519 # Look for a localized description.
520 $descriptionMsg = $extension['descriptionmsg'];
522 if ( is_array( $descriptionMsg ) ) {
523 $descriptionMsgKey = $descriptionMsg[0]; // Get the message key
524 array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
525 array_map( "htmlspecialchars", $descriptionMsg ); // For sanity
526 $description = $this->msg( $descriptionMsgKey, $descriptionMsg )->text();
527 } else {
528 $description = $this->msg( $descriptionMsg )->text();
532 if ( $vcsText !== false ) {
533 $extNameVer = "<tr>
534 <td><em>$mainLink $versionText</em></td>
535 <td><em>$vcsText</em></td>";
536 } else {
537 $extNameVer = "<tr>
538 <td colspan=\"2\"><em>$mainLink $versionText</em></td>";
541 $author = isset( $extension['author'] ) ? $extension['author'] : array();
542 $extDescAuthor = "<td>$description</td>
543 <td>" . $this->listAuthors( $author, false ) . "</td>
544 </tr>\n";
546 return $extNameVer . $extDescAuthor;
550 * Generate wikitext showing hooks in $wgHooks.
552 * @return String: wikitext
554 private function getWgHooks() {
555 global $wgHooks;
557 if ( count( $wgHooks ) ) {
558 $myWgHooks = $wgHooks;
559 ksort( $myWgHooks );
561 $ret = Xml::element( 'h2', array( 'id' => 'mw-version-hooks' ), $this->msg( 'version-hooks' )->text() ) .
562 Xml::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-hooks' ) ) .
563 "<tr>
564 <th>" . $this->msg( 'version-hook-name' )->text() . "</th>
565 <th>" . $this->msg( 'version-hook-subscribedby' )->text() . "</th>
566 </tr>\n";
568 foreach ( $myWgHooks as $hook => $hooks ) {
569 $ret .= "<tr>
570 <td>$hook</td>
571 <td>" . $this->listToText( $hooks ) . "</td>
572 </tr>\n";
575 $ret .= Xml::closeElement( 'table' );
576 return $ret;
577 } else {
578 return '';
582 private function openExtType( $text, $name = null ) {
583 $opt = array( 'colspan' => 4 );
584 $out = '';
586 if ( $this->firstExtOpened ) {
587 // Insert a spacing line
588 $out .= '<tr class="sv-space">' . Html::element( 'td', $opt ) . "</tr>\n";
590 $this->firstExtOpened = true;
592 if ( $name ) {
593 $opt['id'] = "sv-$name";
596 $out .= "<tr>" . Xml::element( 'th', $opt, $text ) . "</tr>\n";
598 return $out;
602 * Get information about client's IP address.
604 * @return String: HTML fragment
606 private function IPInfo() {
607 $ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) );
608 return "<!-- visited from $ip -->\n<span style='display:none'>visited from $ip</span>";
612 * Return a formatted unsorted list of authors
614 * @param $authors mixed: string or array of strings
615 * @return String: HTML fragment
617 function listAuthors( $authors ) {
618 $list = array();
619 foreach ( (array)$authors as $item ) {
620 if ( $item == '...' ) {
621 $list[] = $this->msg( 'version-poweredby-others' )->text();
622 } elseif ( substr( $item, -5 ) == ' ...]' ) {
623 $list[] = substr( $item, 0, -4 ) . $this->msg( 'version-poweredby-others' )->text() . "]";
624 } else {
625 $list[] = $item;
628 return $this->listToText( $list, false );
632 * Convert an array of items into a list for display.
634 * @param array $list of elements to display
635 * @param $sort Boolean: whether to sort the items in $list
637 * @return String
639 function listToText( $list, $sort = true ) {
640 $cnt = count( $list );
642 if ( $cnt == 1 ) {
643 // Enforce always returning a string
644 return (string)self::arrayToString( $list[0] );
645 } elseif ( $cnt == 0 ) {
646 return '';
647 } else {
648 if ( $sort ) {
649 sort( $list );
651 return $this->getLanguage()->listToText( array_map( array( __CLASS__, 'arrayToString' ), $list ) );
656 * Convert an array or object to a string for display.
658 * @param $list Mixed: will convert an array to string if given and return
659 * the paramater unaltered otherwise
661 * @return Mixed
663 public static function arrayToString( $list ) {
664 if ( is_array( $list ) && count( $list ) == 1 ) {
665 $list = $list[0];
667 if ( is_object( $list ) ) {
668 $class = wfMessage( 'parentheses' )->params( get_class( $list ) )->escaped();
669 return $class;
670 } elseif ( !is_array( $list ) ) {
671 return $list;
672 } else {
673 if ( is_object( $list[0] ) ) {
674 $class = get_class( $list[0] );
675 } else {
676 $class = $list[0];
678 return wfMessage( 'parentheses' )->params( "$class, {$list[1]}" )->escaped();
683 * Get an associative array of information about a given path, from its .svn
684 * subdirectory. Returns false on error, such as if the directory was not
685 * checked out with subversion.
687 * Returned keys are:
688 * Required:
689 * checkout-rev The revision which was checked out
690 * Optional:
691 * directory-rev The revision when the directory was last modified
692 * url The subversion URL of the directory
693 * repo-url The base URL of the repository
694 * viewvc-url A ViewVC URL pointing to the checked-out revision
695 * @param $dir string
696 * @return array|bool
698 public static function getSvnInfo( $dir ) {
699 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
700 $entries = $dir . '/.svn/entries';
702 if ( !file_exists( $entries ) ) {
703 return false;
706 $lines = file( $entries );
707 if ( !count( $lines ) ) {
708 return false;
711 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
712 if ( preg_match( '/^<\?xml/', $lines[0] ) ) {
713 // subversion is release <= 1.3
714 if ( !function_exists( 'simplexml_load_file' ) ) {
715 // We could fall back to expat... YUCK
716 return false;
719 // SimpleXml whines about the xmlns...
720 wfSuppressWarnings();
721 $xml = simplexml_load_file( $entries );
722 wfRestoreWarnings();
724 if ( $xml ) {
725 foreach ( $xml->entry as $entry ) {
726 if ( $xml->entry[0]['name'] == '' ) {
727 // The directory entry should always have a revision marker.
728 if ( $entry['revision'] ) {
729 return array( 'checkout-rev' => intval( $entry['revision'] ) );
735 return false;
738 // Subversion is release 1.4 or above.
739 if ( count( $lines ) < 11 ) {
740 return false;
743 $info = array(
744 'checkout-rev' => intval( trim( $lines[3] ) ),
745 'url' => trim( $lines[4] ),
746 'repo-url' => trim( $lines[5] ),
747 'directory-rev' => intval( trim( $lines[10] ) )
750 if ( isset( self::$viewvcUrls[$info['repo-url']] ) ) {
751 $viewvc = str_replace(
752 $info['repo-url'],
753 self::$viewvcUrls[$info['repo-url']],
754 $info['url']
757 $viewvc .= '/?pathrev=';
758 $viewvc .= urlencode( $info['checkout-rev'] );
759 $info['viewvc-url'] = $viewvc;
762 return $info;
766 * Retrieve the revision number of a Subversion working directory.
768 * @param string $dir directory of the svn checkout
770 * @return Integer: revision number as int
772 public static function getSvnRevision( $dir ) {
773 $info = self::getSvnInfo( $dir );
775 if ( $info === false ) {
776 return false;
777 } elseif ( isset( $info['checkout-rev'] ) ) {
778 return $info['checkout-rev'];
779 } else {
780 return false;
785 * @param string $dir directory of the git checkout
786 * @return bool|String sha1 of commit HEAD points to
788 public static function getGitHeadSha1( $dir ) {
789 $repo = new GitInfo( $dir );
790 return $repo->getHeadSHA1();
794 * Get the list of entry points and their URLs
795 * @return string Wikitext
797 public function getEntryPointInfo() {
798 global $wgArticlePath, $wgScriptPath;
799 $scriptPath = $wgScriptPath ? $wgScriptPath : "/";
800 $entryPoints = array(
801 'version-entrypoints-articlepath' => $wgArticlePath,
802 'version-entrypoints-scriptpath' => $scriptPath,
803 'version-entrypoints-index-php' => wfScript( 'index' ),
804 'version-entrypoints-api-php' => wfScript( 'api' ),
805 'version-entrypoints-load-php' => wfScript( 'load' ),
808 $language = $this->getLanguage();
809 $thAttribures = array(
810 'dir' => $language->getDir(),
811 'lang' => $language->getCode()
813 $out = Html::element( 'h2', array( 'id' => 'mw-version-entrypoints' ), $this->msg( 'version-entrypoints' )->text() ) .
814 Html::openElement( 'table',
815 array(
816 'class' => 'wikitable plainlinks',
817 'id' => 'mw-version-entrypoints-table',
818 'dir' => 'ltr',
819 'lang' => 'en'
822 Html::openElement( 'tr' ) .
823 Html::element( 'th', $thAttribures, $this->msg( 'version-entrypoints-header-entrypoint' )->text() ) .
824 Html::element( 'th', $thAttribures, $this->msg( 'version-entrypoints-header-url' )->text() ) .
825 Html::closeElement( 'tr' );
827 foreach ( $entryPoints as $message => $value ) {
828 $url = wfExpandUrl( $value, PROTO_RELATIVE );
829 $out .= Html::openElement( 'tr' ) .
830 // ->text() looks like it should be ->parse(), but this function
831 // returns wikitext, not HTML, boo
832 Html::rawElement( 'td', array(), $this->msg( $message )->text() ) .
833 Html::rawElement( 'td', array(), Html::rawElement( 'code', array(), "[$url $value]" ) ) .
834 Html::closeElement( 'tr' );
837 $out .= Html::closeElement( 'table' );
838 return $out;
841 protected function getGroupName() {
842 return 'wiki';