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
23 * @ingroup SpecialPage
27 * Give information about the version of MediaWiki, PHP, the DB and extensions
29 * @ingroup SpecialPage
31 class SpecialVersion
extends SpecialPage
{
32 protected $firstExtOpened = false;
35 * Stores the current rev id/SHA hash of MediaWiki core
37 protected $coreId = '';
39 protected static $extensionTypes = false;
41 protected static $viewvcUrls = array(
42 'svn+ssh://svn.wikimedia.org/svnroot/mediawiki' => 'http://svn.wikimedia.org/viewvc/mediawiki',
43 'http://svn.wikimedia.org/svnroot/mediawiki' => 'http://svn.wikimedia.org/viewvc/mediawiki',
44 'https://svn.wikimedia.org/svnroot/mediawiki' => 'https://svn.wikimedia.org/viewvc/mediawiki',
47 public function __construct() {
48 parent
::__construct( 'Version' );
54 public function execute( $par ) {
55 global $IP, $wgExtensionCredits;
58 $this->outputHeader();
59 $out = $this->getOutput();
60 $out->allowClickjacking();
62 // Explode the sub page information into useful bits
63 $parts = explode( '/', (string)$par );
65 if ( isset( $parts[1] ) ) {
66 $extName = str_replace( '_', ' ', $parts[1] );
68 foreach ( $wgExtensionCredits as $group => $extensions ) {
69 foreach ( $extensions as $ext ) {
70 if ( isset( $ext['name'] ) && ( $ext['name'] === $extName ) ) {
77 $out->setStatusCode( 404 );
80 $extName = 'MediaWiki';
83 // Now figure out what to do
84 switch ( strtolower( $parts[0] ) ) {
86 $wikiText = '{{int:version-credits-not-found}}';
87 if ( $extName === 'MediaWiki' ) {
88 $wikiText = file_get_contents( $IP . '/CREDITS' );
89 } elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) {
90 $file = $this->getExtAuthorsFileName( dirname( $extNode['path'] ) );
92 $wikiText = file_get_contents( $file );
93 if ( substr( $file, -4 ) === '.txt' ) {
94 $wikiText = Html
::element( 'pre', array(), $wikiText );
99 $out->setPageTitle( $this->msg( 'version-credits-title', $extName ) );
100 $out->addWikiText( $wikiText );
104 $wikiText = '{{int:version-license-not-found}}';
105 if ( $extName === 'MediaWiki' ) {
106 $wikiText = file_get_contents( $IP . '/COPYING' );
107 } elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) {
108 $file = $this->getExtLicenseFileName( dirname( $extNode['path'] ) );
110 $wikiText = file_get_contents( $file );
111 if ( !isset( $extNode['license-name'] ) ) {
112 // If the developer did not explicitly set license-name they probably
113 // are unaware that we're now sucking this file in and thus it's probably
114 // not wikitext friendly.
115 $wikiText = "<pre>$wikiText</pre>";
120 $out->setPageTitle( $this->msg( 'version-license-title', $extName ) );
121 $out->addWikiText( $wikiText );
125 $out->addModules( 'mediawiki.special.version' );
127 $this->getMediaWikiCredits() .
128 $this->softwareInformation() .
129 $this->getEntryPointInfo()
132 $this->getSkinCredits() .
133 $this->getExtensionCredits() .
134 $this->getParserTags() .
135 $this->getParserFunctionHooks()
137 $out->addWikiText( $this->getWgHooks() );
138 $out->addHTML( $this->IPInfo() );
145 * Returns wiki text showing the license information.
149 private static function getMediaWikiCredits() {
152 array( 'id' => 'mw-version-license' ),
153 wfMessage( 'version-license' )->text()
156 // This text is always left-to-right.
157 $ret .= '<div class="plainlinks">';
159 " . self
::getCopyrightAndAuthorList() . "\n
160 " . wfMessage( 'version-license-info' )->text();
163 return str_replace( "\t\t", '', $ret ) . "\n";
167 * Get the "MediaWiki is copyright 2001-20xx by lots of cool guys" text
171 public static function getCopyrightAndAuthorList() {
174 if ( defined( 'MEDIAWIKI_INSTALL' ) ) {
175 $othersLink = '[//www.mediawiki.org/wiki/Special:Version/Credits ' .
176 wfMessage( 'version-poweredby-others' )->text() . ']';
178 $othersLink = '[[Special:Version/Credits|' .
179 wfMessage( 'version-poweredby-others' )->text() . ']]';
182 $translatorsLink = '[//translatewiki.net/wiki/Translating:MediaWiki/Credits ' .
183 wfMessage( 'version-poweredby-translators' )->text() . ']';
186 'Magnus Manske', 'Brion Vibber', 'Lee Daniel Crocker',
187 'Tim Starling', 'Erik Möller', 'Gabriel Wicke', 'Ævar Arnfjörð Bjarmason',
188 'Niklas Laxström', 'Domas Mituzas', 'Rob Church', 'Yuri Astrakhan',
189 'Aryeh Gregor', 'Aaron Schulz', 'Andrew Garrett', 'Raimond Spekking',
190 'Alexandre Emsenhuber', 'Siebrand Mazeland', 'Chad Horohoe',
191 'Roan Kattouw', 'Trevor Parscal', 'Bryan Tong Minh', 'Sam Reed',
192 'Victor Vasiliev', 'Rotem Liss', 'Platonides', 'Antoine Musso',
193 'Timo Tijhof', 'Daniel Kinzler', 'Jeroen De Dauw', $othersLink,
197 return wfMessage( 'version-poweredby-credits', MWTimestamp
::getLocalInstance()->format( 'Y' ),
198 $wgLang->listToText( $authorList ) )->text();
202 * Returns wiki text showing the third party software versions (apache, php, mysql).
206 static function softwareInformation() {
207 $dbr = wfGetDB( DB_SLAVE
);
209 // Put the software in an array of form 'name' => 'version'. All messages should
210 // be loaded here, so feel free to use wfMessage in the 'name'. Raw HTML or
211 // wikimarkup can be used.
213 $software['[https://www.mediawiki.org/ MediaWiki]'] = self
::getVersionLinked();
214 $software['[http://www.php.net/ PHP]'] = phpversion() . " (" . PHP_SAPI
. ")";
215 $software[$dbr->getSoftwareLink()] = $dbr->getServerInfo();
217 // Allow a hook to add/remove items.
218 wfRunHooks( 'SoftwareInfo', array( &$software ) );
222 array( 'id' => 'mw-version-software' ),
223 wfMessage( 'version-software' )->text()
225 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-software' ) ) .
227 <th>" . wfMessage( 'version-software-product' )->text() . "</th>
228 <th>" . wfMessage( 'version-software-version' )->text() . "</th>
231 foreach ( $software as $name => $version ) {
233 <td>" . $name . "</td>
234 <td dir=\"ltr\">" . $version . "</td>
238 return $out . Xml
::closeElement( 'table' );
242 * Return a string of the MediaWiki version with SVN revision if available.
244 * @param string $flags
247 public static function getVersion( $flags = '' ) {
248 global $wgVersion, $IP;
249 wfProfileIn( __METHOD__
);
251 $gitInfo = self
::getGitHeadSha1( $IP );
252 $svnInfo = self
::getSvnInfo( $IP );
253 if ( !$svnInfo && !$gitInfo ) {
254 $version = $wgVersion;
255 } elseif ( $gitInfo && $flags === 'nodb' ) {
256 $shortSha1 = substr( $gitInfo, 0, 7 );
257 $version = "$wgVersion ($shortSha1)";
258 } elseif ( $gitInfo ) {
259 $shortSha1 = substr( $gitInfo, 0, 7 );
260 $shortSha1 = wfMessage( 'parentheses' )->params( $shortSha1 )->escaped();
261 $version = "$wgVersion $shortSha1";
262 } elseif ( $flags === 'nodb' ) {
263 $version = "$wgVersion (r{$svnInfo['checkout-rev']})";
265 $version = $wgVersion . ' ' .
267 'version-svn-revision',
268 isset( $info['directory-rev'] ) ?
$info['directory-rev'] : '',
269 $info['checkout-rev']
273 wfProfileOut( __METHOD__
);
279 * Return a wikitext-formatted string of the MediaWiki version with a link to
280 * the SVN revision or the git SHA1 of head if available.
281 * Git is prefered over Svn
282 * The fallback is just $wgVersion
286 public static function getVersionLinked() {
288 wfProfileIn( __METHOD__
);
290 $gitVersion = self
::getVersionLinkedGit();
294 $svnVersion = self
::getVersionLinkedSvn();
298 $v = $wgVersion; // fallback
302 wfProfileOut( __METHOD__
);
308 * @return string wgVersion + a link to subversion revision of svn BASE
310 private static function getVersionLinkedSvn() {
313 $info = self
::getSvnInfo( $IP );
314 if ( !isset( $info['checkout-rev'] ) ) {
318 $linkText = wfMessage(
319 'version-svn-revision',
320 isset( $info['directory-rev'] ) ?
$info['directory-rev'] : '',
321 $info['checkout-rev']
324 if ( isset( $info['viewvc-url'] ) ) {
325 $version = "[{$info['viewvc-url']} $linkText]";
327 $version = $linkText;
330 return self
::getwgVersionLinked() . " $version";
336 private static function getwgVersionLinked() {
339 if ( wfRunHooks( 'SpecialVersionVersionUrl', array( $wgVersion, &$versionUrl ) ) ) {
340 $versionParts = array();
341 preg_match( "/^(\d+\.\d+)/", $wgVersion, $versionParts );
342 $versionUrl = "https://www.mediawiki.org/wiki/MediaWiki_{$versionParts[1]}";
345 return "[$versionUrl $wgVersion]";
349 * @since 1.22 Returns the HEAD date in addition to the sha1 and link
350 * @return bool|string wgVersion + HEAD sha1 stripped to the first 7 chars
351 * with link and date, or false on failure
353 private static function getVersionLinkedGit() {
356 $gitInfo = new GitInfo( $IP );
357 $headSHA1 = $gitInfo->getHeadSHA1();
362 $shortSHA1 = '(' . substr( $headSHA1, 0, 7 ) . ')';
364 $gitHeadUrl = $gitInfo->getHeadViewUrl();
365 if ( $gitHeadUrl !== false ) {
366 $shortSHA1 = "[$gitHeadUrl $shortSHA1]";
369 $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
370 if ( $gitHeadCommitDate ) {
371 $shortSHA1 .= Html
::element( 'br' ) . $wgLang->timeanddate( $gitHeadCommitDate, true );
374 return self
::getwgVersionLinked() . " $shortSHA1";
378 * Returns an array with the base extension types.
379 * Type is stored as array key, the message as array value.
381 * TODO: ideally this would return all extension types.
387 public static function getExtensionTypes() {
388 if ( self
::$extensionTypes === false ) {
389 self
::$extensionTypes = array(
390 'specialpage' => wfMessage( 'version-specialpages' )->text(),
391 'parserhook' => wfMessage( 'version-parserhooks' )->text(),
392 'variable' => wfMessage( 'version-variables' )->text(),
393 'media' => wfMessage( 'version-mediahandlers' )->text(),
394 'antispam' => wfMessage( 'version-antispam' )->text(),
395 'skin' => wfMessage( 'version-skins' )->text(),
396 'api' => wfMessage( 'version-api' )->text(),
397 'other' => wfMessage( 'version-other' )->text(),
400 wfRunHooks( 'ExtensionTypes', array( &self
::$extensionTypes ) );
403 return self
::$extensionTypes;
407 * Returns the internationalized name for an extension type.
411 * @param string $type
415 public static function getExtensionTypeName( $type ) {
416 $types = self
::getExtensionTypes();
418 return isset( $types[$type] ) ?
$types[$type] : $types['other'];
422 * Generate wikitext showing extensions name, URL, author and description.
424 * @return string Wikitext
426 function getExtensionCredits() {
427 global $wgExtensionCredits;
429 if ( !count( $wgExtensionCredits ) ) {
433 $extensionTypes = self
::getExtensionTypes();
437 array( 'id' => 'mw-version-ext' ),
438 $this->msg( 'version-extensions' )->text()
440 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-ext' ) );
442 // Make sure the 'other' type is set to an array.
443 if ( !array_key_exists( 'other', $wgExtensionCredits ) ) {
444 $wgExtensionCredits['other'] = array();
447 // Find all extensions that do not have a valid type and give them the type 'other'.
448 foreach ( $wgExtensionCredits as $type => $extensions ) {
449 if ( !array_key_exists( $type, $extensionTypes ) ) {
450 $wgExtensionCredits['other'] = array_merge( $wgExtensionCredits['other'], $extensions );
454 $this->firstExtOpened
= false;
455 // Loop through the extension categories to display their extensions in the list.
456 foreach ( $extensionTypes as $type => $message ) {
457 // Skins have a separate section
458 if ( $type !== 'other' && $type !== 'skin' ) {
459 $out .= $this->getExtensionCategory( $type, $message );
463 // We want the 'other' type to be last in the list.
464 $out .= $this->getExtensionCategory( 'other', $extensionTypes['other'] );
466 $out .= Xml
::closeElement( 'table' );
472 * Generate wikitext showing skins name, URL, author and description.
474 * @return string Wikitext
476 function getSkinCredits() {
479 array( 'id' => 'mw-version-skin' ),
480 $this->msg( 'version-skins' )->text()
482 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-skin' ) );
484 $this->firstExtOpened
= false;
485 $out .= $this->getExtensionCategory( 'skin', null );
487 $out .= Xml
::closeElement( 'table' );
493 * Obtains a list of installed parser tags and the associated H2 header
495 * @return string HTML output
497 protected function getParserTags() {
500 $tags = $wgParser->getTags();
502 if ( count( $tags ) ) {
503 $out = Html
::rawElement(
505 array( 'class' => 'mw-headline' ),
506 Linker
::makeExternalLink(
507 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Tag_extensions',
508 $this->msg( 'version-parser-extensiontags' )->parse(),
509 false /* msg()->parse() already escapes */
513 array_walk( $tags, function ( &$value ) {
514 $value = '<' . htmlentities( $value ) . '>';
516 $out .= $this->listToText( $tags );
525 * Obtains a list of installed parser function hooks and the associated H2 header
527 * @return string HTML output
529 protected function getParserFunctionHooks() {
532 $fhooks = $wgParser->getFunctionHooks();
533 if ( count( $fhooks ) ) {
534 $out = Html
::rawElement( 'h2', array( 'class' => 'mw-headline' ), Linker
::makeExternalLink(
535 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Parser_functions',
536 $this->msg( 'version-parser-function-hooks' )->parse(),
537 false /* msg()->parse() already escapes */
540 $out .= $this->listToText( $fhooks );
549 * Creates and returns the HTML for a single extension category.
553 * @param string $type
554 * @param string $message
558 protected function getExtensionCategory( $type, $message ) {
559 global $wgExtensionCredits;
563 if ( array_key_exists( $type, $wgExtensionCredits ) && count( $wgExtensionCredits[$type] ) > 0 ) {
564 $out .= $this->openExtType( $message, 'credits-' . $type );
566 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
568 foreach ( $wgExtensionCredits[$type] as $extension ) {
569 $out .= $this->getCreditsForExtension( $extension );
577 * Callback to sort extensions by type.
582 function compare( $a, $b ) {
583 if ( $a['name'] === $b['name'] ) {
586 return $this->getLanguage()->lc( $a['name'] ) > $this->getLanguage()->lc( $b['name'] )
593 * Creates and formats a version line for a single extension.
595 * Information for five columns will be created. Parameters required in the
596 * $extension array for part rendering are indicated in ()
597 * - The name of (name), and URL link to (url), the extension
598 * - Official version number (version) and if available version control system
599 * revision (path), link, and date
600 * - If available the short name of the license (license-name) and a linke
601 * to ((LICENSE)|(COPYING))(\.txt)? if it exists.
602 * - Description of extension (descriptionmsg or description)
603 * - List of authors (author) and link to a ((AUTHORS)|(CREDITS))(\.txt)? file if it exists
605 * @param array $extension
607 * @return string Raw HTML
609 function getCreditsForExtension( array $extension ) {
610 $out = $this->getOutput();
612 // We must obtain the information for all the bits and pieces!
613 // ... such as extension names and links
614 if ( isset( $extension['namemsg'] ) ) {
615 // Localized name of extension
616 $extensionName = $this->msg( $extension['namemsg'] )->text();
617 } elseif ( isset( $extension['name'] ) ) {
618 // Non localized version
619 $extensionName = $extension['name'];
621 $extensionName = $this->msg( 'version-no-ext-name' )->text();
624 if ( isset( $extension['url'] ) ) {
625 $extensionNameLink = Linker
::makeExternalLink(
630 array( 'class' => 'mw-version-ext-name' )
633 $extensionNameLink = $extensionName;
636 // ... and the version information
637 // If the extension path is set we will check that directory for GIT and SVN
638 // metadata in an attempt to extract date and vcs commit metadata.
639 $canonicalVersion = '–';
640 $extensionPath = null;
645 if ( isset( $extension['version'] ) ) {
646 $canonicalVersion = $out->parseInline( $extension['version'] );
649 if ( isset( $extension['path'] ) ) {
651 if ( $this->coreId
== '' ) {
652 wfDebug( 'Looking up core head id' );
653 $coreHeadSHA1 = self
::getGitHeadSha1( $IP );
654 if ( $coreHeadSHA1 ) {
655 $this->coreId
= $coreHeadSHA1;
657 $svnInfo = self
::getSvnInfo( $IP );
658 if ( $svnInfo !== false ) {
659 $this->coreId
= $svnInfo['checkout-rev'];
663 $cache = wfGetCache( CACHE_ANYTHING
);
664 $memcKey = wfMemcKey( 'specialversion-ext-version-text', $extension['path'], $this->coreId
);
665 list( $vcsVersion, $vcsLink, $vcsDate ) = $cache->get( $memcKey );
667 if ( !$vcsVersion ) {
668 wfDebug( "Getting VCS info for extension $extensionName" );
669 $extensionPath = dirname( $extension['path'] );
670 $gitInfo = new GitInfo( $extensionPath );
671 $vcsVersion = $gitInfo->getHeadSHA1();
672 if ( $vcsVersion !== false ) {
673 $vcsVersion = substr( $vcsVersion, 0, 7 );
674 $vcsLink = $gitInfo->getHeadViewUrl();
675 $vcsDate = $gitInfo->getHeadCommitDate();
677 $svnInfo = self
::getSvnInfo( $extensionPath );
678 if ( $svnInfo !== false ) {
679 $vcsVersion = $this->msg( 'version-svn-revision', $svnInfo['checkout-rev'] )->text();
680 $vcsLink = isset( $svnInfo['viewvc-url'] ) ?
$svnInfo['viewvc-url'] : '';
683 $cache->set( $memcKey, array( $vcsVersion, $vcsLink, $vcsDate ), 60 * 60 * 24 );
685 wfDebug( "Pulled VCS info for extension $extensionName from cache" );
689 $versionString = Html
::rawElement(
691 array( 'class' => 'mw-version-ext-version' ),
697 $vcsVerString = Linker
::makeExternalLink(
699 $this->msg( 'version-version', $vcsVersion ),
702 array( 'class' => 'mw-version-ext-vcs-version' )
705 $vcsVerString = Html
::element( 'span',
706 array( 'class' => 'mw-version-ext-vcs-version' ),
710 $versionString .= " {$vcsVerString}";
713 $vcsTimeString = Html
::element( 'span',
714 array( 'class' => 'mw-version-ext-vcs-timestamp' ),
715 $this->getLanguage()->timeanddate( $vcsDate )
717 $versionString .= " {$vcsTimeString}";
719 $versionString = Html
::rawElement( 'span',
720 array( 'class' => 'mw-version-ext-meta-version' ),
725 // ... and license information; if a license file exists we
728 if ( isset( $extension['license-name'] ) ) {
729 $licenseLink = Linker
::link(
730 $this->getPageTitle( 'License/' . $extensionName ),
731 $out->parseInline( $extension['license-name'] ),
732 array( 'class' => 'mw-version-ext-license' )
734 } elseif ( $this->getExtLicenseFileName( $extensionPath ) ) {
735 $licenseLink = Linker
::link(
736 $this->getPageTitle( 'License/' . $extensionName ),
737 $this->msg( 'version-ext-license' ),
738 array( 'class' => 'mw-version-ext-license' )
742 // ... and generate the description; which can be a parameterized l10n message
743 // in the form array( <msgname>, <parameter>, <parameter>... ) or just a straight
745 if ( isset( $extension['descriptionmsg'] ) ) {
746 // Localized description of extension
747 $descriptionMsg = $extension['descriptionmsg'];
749 if ( is_array( $descriptionMsg ) ) {
750 $descriptionMsgKey = $descriptionMsg[0]; // Get the message key
751 array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
752 array_map( "htmlspecialchars", $descriptionMsg ); // For sanity
753 $description = $this->msg( $descriptionMsgKey, $descriptionMsg )->text();
755 $description = $this->msg( $descriptionMsg )->text();
757 } elseif ( isset( $extension['description'] ) ) {
758 // Non localized version
759 $description = $extension['description'];
763 $description = $out->parseInline( $description );
765 // ... now get the authors for this extension
766 $authors = isset( $extension['author'] ) ?
$extension['author'] : array();
767 $authors = $this->listAuthors( $authors, $extensionName, $extensionPath );
769 // Finally! Create the table
770 $html = Html
::openElement( 'tr', array(
771 'class' => 'mw-version-ext',
772 'id' => "mw-version-ext-{$extensionName}"
776 $html .= Html
::rawElement( 'td', array(), $extensionNameLink );
777 $html .= Html
::rawElement( 'td', array(), $versionString );
778 $html .= Html
::rawElement( 'td', array(), $licenseLink );
779 $html .= Html
::rawElement( 'td', array( 'class' => 'mw-version-ext-description' ), $description );
780 $html .= Html
::rawElement( 'td', array( 'class' => 'mw-version-ext-authors' ), $authors );
782 $html .= Html
::closeElement( 'td' );
788 * Generate wikitext showing hooks in $wgHooks.
790 * @return string Wikitext
792 private function getWgHooks() {
793 global $wgSpecialVersionShowHooks, $wgHooks;
795 if ( $wgSpecialVersionShowHooks && count( $wgHooks ) ) {
796 $myWgHooks = $wgHooks;
800 $ret[] = '== {{int:version-hooks}} ==';
801 $ret[] = Html
::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-hooks' ) );
802 $ret[] = Html
::openElement( 'tr' );
803 $ret[] = Html
::element( 'th', array(), $this->msg( 'version-hook-name' )->text() );
804 $ret[] = Html
::element( 'th', array(), $this->msg( 'version-hook-subscribedby' )->text() );
805 $ret[] = Html
::closeElement( 'tr' );
807 foreach ( $myWgHooks as $hook => $hooks ) {
808 $ret[] = Html
::openElement( 'tr' );
809 $ret[] = Html
::element( 'td', array(), $hook );
810 $ret[] = Html
::element( 'td', array(), $this->listToText( $hooks ) );
811 $ret[] = Html
::closeElement( 'tr' );
814 $ret[] = Html
::closeElement( 'table' );
816 return implode( "\n", $ret );
822 private function openExtType( $text = null, $name = null ) {
825 $opt = array( 'colspan' => 5 );
826 if ( $this->firstExtOpened
) {
827 // Insert a spacing line
828 $out .= Html
::rawElement( 'tr', array( 'class' => 'sv-space' ),
829 Html
::element( 'td', $opt )
832 $this->firstExtOpened
= true;
835 $opt['id'] = "sv-$name";
838 if ( $text !== null ) {
839 $out .= Html
::rawElement( 'tr', array(),
840 Html
::element( 'th', $opt, $text )
844 $firstHeadingMsg = ( $name === 'credits-skin' )
845 ?
'version-skin-colheader-name'
846 : 'version-ext-colheader-name';
847 $out .= Html
::openElement( 'tr' );
848 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
849 $this->msg( $firstHeadingMsg )->text() );
850 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
851 $this->msg( 'version-ext-colheader-version' )->text() );
852 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
853 $this->msg( 'version-ext-colheader-license' )->text() );
854 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
855 $this->msg( 'version-ext-colheader-description' )->text() );
856 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
857 $this->msg( 'version-ext-colheader-credits' )->text() );
858 $out .= Html
::closeElement( 'tr' );
864 * Get information about client's IP address.
866 * @return string HTML fragment
868 private function IPInfo() {
869 $ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) );
871 return "<!-- visited from $ip -->\n<span style='display:none'>visited from $ip</span>";
875 * Return a formatted unsorted list of authors
878 * If an item in the $authors array is '...' it is assumed to indicate an
879 * 'and others' string which will then be linked to an ((AUTHORS)|(CREDITS))(\.txt)?
880 * file if it exists in $dir.
882 * Similarly an entry ending with ' ...]' is assumed to be a link to an
885 * If no '...' string variant is found, but an authors file is found an
886 * 'and others' will be added to the end of the credits.
888 * @param string|array $authors
889 * @param string $extName Name of the extension for link creation
890 * @param string $extDir Path to the extension root directory
892 * @return string HTML fragment
894 function listAuthors( $authors, $extName, $extDir ) {
898 foreach ( (array)$authors as $item ) {
899 if ( $item == '...' ) {
902 if ( $this->getExtAuthorsFileName( $extDir ) ) {
903 $text = Linker
::link(
904 $this->getPageTitle( "Credits/$extName" ),
905 $this->msg( 'version-poweredby-others' )->text()
908 $text = $this->msg( 'version-poweredby-others' )->text();
911 } elseif ( substr( $item, -5 ) == ' ...]' ) {
913 $list[] = $this->getOutput()->parseInline(
914 substr( $item, 0, -4 ) . $this->msg( 'version-poweredby-others' )->text() . "]"
917 $list[] = $this->getOutput()->parseInline( $item );
921 if ( !$hasOthers && $this->getExtAuthorsFileName( $extDir ) ) {
922 $list[] = $text = Linker
::link(
923 $this->getPageTitle( "Credits/$extName" ),
924 $this->msg( 'version-poweredby-others' )->text()
928 return $this->listToText( $list, false );
932 * Obtains the full path of an extensions authors or credits file if
935 * @param string $extDir Path to the extensions root directory
939 * @return bool|string False if no such file exists, otherwise returns
942 public static function getExtAuthorsFileName( $extDir ) {
947 foreach ( scandir( $extDir ) as $file ) {
948 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
949 if ( preg_match( '/^((AUTHORS)|(CREDITS))(\.txt)?$/', $file ) &&
950 is_readable( $fullPath ) &&
961 * Obtains the full path of an extensions copying or license file if
964 * @param string $extDir Path to the extensions root directory
968 * @return bool|string False if no such file exists, otherwise returns
971 public static function getExtLicenseFileName( $extDir ) {
976 foreach ( scandir( $extDir ) as $file ) {
977 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
978 if ( preg_match( '/^((COPYING)|(LICENSE))(\.txt)?$/', $file ) &&
979 is_readable( $fullPath ) &&
990 * Convert an array of items into a list for display.
992 * @param array $list List of elements to display
993 * @param bool $sort Whether to sort the items in $list
997 function listToText( $list, $sort = true ) {
998 if ( !count( $list ) ) {
1005 return $this->getLanguage()
1006 ->listToText( array_map( array( __CLASS__
, 'arrayToString' ), $list ) );
1010 * Convert an array or object to a string for display.
1012 * @param mixed $list Will convert an array to string if given and return
1013 * the paramater unaltered otherwise
1017 public static function arrayToString( $list ) {
1018 if ( is_array( $list ) && count( $list ) == 1 ) {
1021 if ( is_object( $list ) ) {
1022 $class = wfMessage( 'parentheses' )->params( get_class( $list ) )->escaped();
1025 } elseif ( !is_array( $list ) ) {
1028 if ( is_object( $list[0] ) ) {
1029 $class = get_class( $list[0] );
1034 return wfMessage( 'parentheses' )->params( "$class, {$list[1]}" )->escaped();
1039 * Get an associative array of information about a given path, from its .svn
1040 * subdirectory. Returns false on error, such as if the directory was not
1041 * checked out with subversion.
1043 * Returned keys are:
1045 * checkout-rev The revision which was checked out
1047 * directory-rev The revision when the directory was last modified
1048 * url The subversion URL of the directory
1049 * repo-url The base URL of the repository
1050 * viewvc-url A ViewVC URL pointing to the checked-out revision
1051 * @param string $dir
1052 * @return array|bool
1054 public static function getSvnInfo( $dir ) {
1055 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
1056 $entries = $dir . '/.svn/entries';
1058 if ( !file_exists( $entries ) ) {
1062 $lines = file( $entries );
1063 if ( !count( $lines ) ) {
1067 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
1068 if ( preg_match( '/^<\?xml/', $lines[0] ) ) {
1069 // subversion is release <= 1.3
1070 if ( !function_exists( 'simplexml_load_file' ) ) {
1071 // We could fall back to expat... YUCK
1075 // SimpleXml whines about the xmlns...
1076 wfSuppressWarnings();
1077 $xml = simplexml_load_file( $entries );
1078 wfRestoreWarnings();
1081 foreach ( $xml->entry
as $entry ) {
1082 if ( $xml->entry
[0]['name'] == '' ) {
1083 // The directory entry should always have a revision marker.
1084 if ( $entry['revision'] ) {
1085 return array( 'checkout-rev' => intval( $entry['revision'] ) );
1094 // Subversion is release 1.4 or above.
1095 if ( count( $lines ) < 11 ) {
1100 'checkout-rev' => intval( trim( $lines[3] ) ),
1101 'url' => trim( $lines[4] ),
1102 'repo-url' => trim( $lines[5] ),
1103 'directory-rev' => intval( trim( $lines[10] ) )
1106 if ( isset( self
::$viewvcUrls[$info['repo-url']] ) ) {
1107 $viewvc = str_replace(
1109 self
::$viewvcUrls[$info['repo-url']],
1113 $viewvc .= '/?pathrev=';
1114 $viewvc .= urlencode( $info['checkout-rev'] );
1115 $info['viewvc-url'] = $viewvc;
1122 * Retrieve the revision number of a Subversion working directory.
1124 * @param string $dir Directory of the svn checkout
1126 * @return int Revision number
1128 public static function getSvnRevision( $dir ) {
1129 $info = self
::getSvnInfo( $dir );
1131 if ( $info === false ) {
1133 } elseif ( isset( $info['checkout-rev'] ) ) {
1134 return $info['checkout-rev'];
1141 * @param string $dir Directory of the git checkout
1142 * @return bool|string Sha1 of commit HEAD points to
1144 public static function getGitHeadSha1( $dir ) {
1145 $repo = new GitInfo( $dir );
1147 return $repo->getHeadSHA1();
1151 * @param string $dir Directory of the git checkout
1152 * @return bool|string Branch currently checked out
1154 public static function getGitCurrentBranch( $dir ) {
1155 $repo = new GitInfo( $dir );
1156 return $repo->getCurrentBranch();
1160 * Get the list of entry points and their URLs
1161 * @return string Wikitext
1163 public function getEntryPointInfo() {
1164 global $wgArticlePath, $wgScriptPath;
1165 $scriptPath = $wgScriptPath ?
$wgScriptPath : "/";
1166 $entryPoints = array(
1167 'version-entrypoints-articlepath' => $wgArticlePath,
1168 'version-entrypoints-scriptpath' => $scriptPath,
1169 'version-entrypoints-index-php' => wfScript( 'index' ),
1170 'version-entrypoints-api-php' => wfScript( 'api' ),
1171 'version-entrypoints-load-php' => wfScript( 'load' ),
1174 $language = $this->getLanguage();
1175 $thAttribures = array(
1176 'dir' => $language->getDir(),
1177 'lang' => $language->getCode()
1179 $out = Html
::element(
1181 array( 'id' => 'mw-version-entrypoints' ),
1182 $this->msg( 'version-entrypoints' )->text()
1184 Html
::openElement( 'table',
1186 'class' => 'wikitable plainlinks',
1187 'id' => 'mw-version-entrypoints-table',
1192 Html
::openElement( 'tr' ) .
1196 $this->msg( 'version-entrypoints-header-entrypoint' )->text()
1201 $this->msg( 'version-entrypoints-header-url' )->text()
1203 Html
::closeElement( 'tr' );
1205 foreach ( $entryPoints as $message => $value ) {
1206 $url = wfExpandUrl( $value, PROTO_RELATIVE
);
1207 $out .= Html
::openElement( 'tr' ) .
1208 // ->text() looks like it should be ->parse(), but this function
1209 // returns wikitext, not HTML, boo
1210 Html
::rawElement( 'td', array(), $this->msg( $message )->text() ) .
1211 Html
::rawElement( 'td', array(), Html
::rawElement( 'code', array(), "[$url $value]" ) ) .
1212 Html
::closeElement( 'tr' );
1215 $out .= Html
::closeElement( 'table' );
1220 protected function getGroupName() {