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' );
53 * @param string|null $par
55 public function execute( $par ) {
56 global $IP, $wgExtensionCredits;
59 $this->outputHeader();
60 $out = $this->getOutput();
61 $out->allowClickjacking();
63 // Explode the sub page information into useful bits
64 $parts = explode( '/', (string)$par );
66 if ( isset( $parts[1] ) ) {
67 $extName = str_replace( '_', ' ', $parts[1] );
69 foreach ( $wgExtensionCredits as $group => $extensions ) {
70 foreach ( $extensions as $ext ) {
71 if ( isset( $ext['name'] ) && ( $ext['name'] === $extName ) ) {
78 $out->setStatusCode( 404 );
81 $extName = 'MediaWiki';
84 // Now figure out what to do
85 switch ( strtolower( $parts[0] ) ) {
87 $wikiText = '{{int:version-credits-not-found}}';
88 if ( $extName === 'MediaWiki' ) {
89 $wikiText = file_get_contents( $IP . '/CREDITS' );
90 } elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) {
91 $file = $this->getExtAuthorsFileName( dirname( $extNode['path'] ) );
93 $wikiText = file_get_contents( $file );
94 if ( substr( $file, -4 ) === '.txt' ) {
95 $wikiText = Html
::element(
107 $out->setPageTitle( $this->msg( 'version-credits-title', $extName ) );
108 $out->addWikiText( $wikiText );
112 $wikiText = '{{int:version-license-not-found}}';
113 if ( $extName === 'MediaWiki' ) {
114 $wikiText = file_get_contents( $IP . '/COPYING' );
115 } elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) {
116 $file = $this->getExtLicenseFileName( dirname( $extNode['path'] ) );
118 $wikiText = file_get_contents( $file );
119 $wikiText = Html
::element(
130 $out->setPageTitle( $this->msg( 'version-license-title', $extName ) );
131 $out->addWikiText( $wikiText );
135 $out->addModules( 'mediawiki.special.version' );
137 $this->getMediaWikiCredits() .
138 $this->softwareInformation() .
139 $this->getEntryPointInfo()
142 $this->getSkinCredits() .
143 $this->getExtensionCredits() .
144 $this->getExternalLibraries() .
145 $this->getParserTags() .
146 $this->getParserFunctionHooks()
148 $out->addWikiText( $this->getWgHooks() );
149 $out->addHTML( $this->IPInfo() );
156 * Returns wiki text showing the license information.
160 private static function getMediaWikiCredits() {
163 array( 'id' => 'mw-version-license' ),
164 wfMessage( 'version-license' )->text()
167 // This text is always left-to-right.
168 $ret .= '<div class="plainlinks">';
170 " . self
::getCopyrightAndAuthorList() . "\n
171 " . wfMessage( 'version-license-info' )->text();
174 return str_replace( "\t\t", '', $ret ) . "\n";
178 * Get the "MediaWiki is copyright 2001-20xx by lots of cool guys" text
182 public static function getCopyrightAndAuthorList() {
185 if ( defined( 'MEDIAWIKI_INSTALL' ) ) {
186 $othersLink = '[//www.mediawiki.org/wiki/Special:Version/Credits ' .
187 wfMessage( 'version-poweredby-others' )->text() . ']';
189 $othersLink = '[[Special:Version/Credits|' .
190 wfMessage( 'version-poweredby-others' )->text() . ']]';
193 $translatorsLink = '[//translatewiki.net/wiki/Translating:MediaWiki/Credits ' .
194 wfMessage( 'version-poweredby-translators' )->text() . ']';
197 'Magnus Manske', 'Brion Vibber', 'Lee Daniel Crocker',
198 'Tim Starling', 'Erik Möller', 'Gabriel Wicke', 'Ævar Arnfjörð Bjarmason',
199 'Niklas Laxström', 'Domas Mituzas', 'Rob Church', 'Yuri Astrakhan',
200 'Aryeh Gregor', 'Aaron Schulz', 'Andrew Garrett', 'Raimond Spekking',
201 'Alexandre Emsenhuber', 'Siebrand Mazeland', 'Chad Horohoe',
202 'Roan Kattouw', 'Trevor Parscal', 'Bryan Tong Minh', 'Sam Reed',
203 'Victor Vasiliev', 'Rotem Liss', 'Platonides', 'Antoine Musso',
204 'Timo Tijhof', 'Daniel Kinzler', 'Jeroen De Dauw', 'Brad Jorsch',
205 $othersLink, $translatorsLink
208 return wfMessage( 'version-poweredby-credits', MWTimestamp
::getLocalInstance()->format( 'Y' ),
209 $wgLang->listToText( $authorList ) )->text();
213 * Returns wiki text showing the third party software versions (apache, php, mysql).
217 public static function softwareInformation() {
218 $dbr = wfGetDB( DB_SLAVE
);
220 // Put the software in an array of form 'name' => 'version'. All messages should
221 // be loaded here, so feel free to use wfMessage in the 'name'. Raw HTML or
222 // wikimarkup can be used.
224 $software['[https://www.mediawiki.org/ MediaWiki]'] = self
::getVersionLinked();
226 $software['[http://hhvm.com/ HHVM]'] = HHVM_VERSION
. " (" . PHP_SAPI
. ")";
228 $software['[https://php.net/ PHP]'] = PHP_VERSION
. " (" . PHP_SAPI
. ")";
230 $software[$dbr->getSoftwareLink()] = $dbr->getServerInfo();
232 if ( IcuCollation
::getICUVersion() ) {
233 $software['[http://site.icu-project.org/ ICU]'] = IcuCollation
::getICUVersion();
236 // Allow a hook to add/remove items.
237 Hooks
::run( 'SoftwareInfo', array( &$software ) );
241 array( 'id' => 'mw-version-software' ),
242 wfMessage( 'version-software' )->text()
244 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-software' ) ) .
246 <th>" . wfMessage( 'version-software-product' )->text() . "</th>
247 <th>" . wfMessage( 'version-software-version' )->text() . "</th>
250 foreach ( $software as $name => $version ) {
252 <td>" . $name . "</td>
253 <td dir=\"ltr\">" . $version . "</td>
257 return $out . Xml
::closeElement( 'table' );
261 * Return a string of the MediaWiki version with SVN revision if available.
263 * @param string $flags
266 public static function getVersion( $flags = '' ) {
267 global $wgVersion, $IP;
269 $gitInfo = self
::getGitHeadSha1( $IP );
270 $svnInfo = self
::getSvnInfo( $IP );
271 if ( !$svnInfo && !$gitInfo ) {
272 $version = $wgVersion;
273 } elseif ( $gitInfo && $flags === 'nodb' ) {
274 $shortSha1 = substr( $gitInfo, 0, 7 );
275 $version = "$wgVersion ($shortSha1)";
276 } elseif ( $gitInfo ) {
277 $shortSha1 = substr( $gitInfo, 0, 7 );
278 $shortSha1 = wfMessage( 'parentheses' )->params( $shortSha1 )->escaped();
279 $version = "$wgVersion $shortSha1";
280 } elseif ( $flags === 'nodb' ) {
281 $version = "$wgVersion (r{$svnInfo['checkout-rev']})";
283 $version = $wgVersion . ' ' .
285 'version-svn-revision',
286 isset( $svnInfo['directory-rev'] ) ?
$svnInfo['directory-rev'] : '',
287 isset( $svnInfo['checkout-rev'] ) ?
$svnInfo['checkout-rev'] : ''
295 * Return a wikitext-formatted string of the MediaWiki version with a link to
296 * the SVN revision or the git SHA1 of head if available.
297 * Git is prefered over Svn
298 * The fallback is just $wgVersion
302 public static function getVersionLinked() {
305 $gitVersion = self
::getVersionLinkedGit();
309 $svnVersion = self
::getVersionLinkedSvn();
313 $v = $wgVersion; // fallback
321 * @return string Global wgVersion + a link to subversion revision of svn BASE
323 private static function getVersionLinkedSvn() {
326 $info = self
::getSvnInfo( $IP );
327 if ( !isset( $info['checkout-rev'] ) ) {
331 $linkText = wfMessage(
332 'version-svn-revision',
333 isset( $info['directory-rev'] ) ?
$info['directory-rev'] : '',
334 $info['checkout-rev']
337 if ( isset( $info['viewvc-url'] ) ) {
338 $version = "[{$info['viewvc-url']} $linkText]";
340 $version = $linkText;
343 return self
::getwgVersionLinked() . " $version";
349 private static function getwgVersionLinked() {
352 if ( Hooks
::run( 'SpecialVersionVersionUrl', array( $wgVersion, &$versionUrl ) ) ) {
353 $versionParts = array();
354 preg_match( "/^(\d+\.\d+)/", $wgVersion, $versionParts );
355 $versionUrl = "https://www.mediawiki.org/wiki/MediaWiki_{$versionParts[1]}";
358 return "[$versionUrl $wgVersion]";
362 * @since 1.22 Returns the HEAD date in addition to the sha1 and link
363 * @return bool|string Global wgVersion + HEAD sha1 stripped to the first 7 chars
364 * with link and date, or false on failure
366 private static function getVersionLinkedGit() {
369 $gitInfo = new GitInfo( $IP );
370 $headSHA1 = $gitInfo->getHeadSHA1();
375 $shortSHA1 = '(' . substr( $headSHA1, 0, 7 ) . ')';
377 $gitHeadUrl = $gitInfo->getHeadViewUrl();
378 if ( $gitHeadUrl !== false ) {
379 $shortSHA1 = "[$gitHeadUrl $shortSHA1]";
382 $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
383 if ( $gitHeadCommitDate ) {
384 $shortSHA1 .= Html
::element( 'br' ) . $wgLang->timeanddate( $gitHeadCommitDate, true );
387 return self
::getwgVersionLinked() . " $shortSHA1";
391 * Returns an array with the base extension types.
392 * Type is stored as array key, the message as array value.
394 * TODO: ideally this would return all extension types.
400 public static function getExtensionTypes() {
401 if ( self
::$extensionTypes === false ) {
402 self
::$extensionTypes = array(
403 'specialpage' => wfMessage( 'version-specialpages' )->text(),
404 'parserhook' => wfMessage( 'version-parserhooks' )->text(),
405 'variable' => wfMessage( 'version-variables' )->text(),
406 'media' => wfMessage( 'version-mediahandlers' )->text(),
407 'antispam' => wfMessage( 'version-antispam' )->text(),
408 'skin' => wfMessage( 'version-skins' )->text(),
409 'api' => wfMessage( 'version-api' )->text(),
410 'other' => wfMessage( 'version-other' )->text(),
413 Hooks
::run( 'ExtensionTypes', array( &self
::$extensionTypes ) );
416 return self
::$extensionTypes;
420 * Returns the internationalized name for an extension type.
424 * @param string $type
428 public static function getExtensionTypeName( $type ) {
429 $types = self
::getExtensionTypes();
431 return isset( $types[$type] ) ?
$types[$type] : $types['other'];
435 * Generate wikitext showing the name, URL, author and description of each extension.
437 * @return string Wikitext
439 public function getExtensionCredits() {
440 global $wgExtensionCredits;
443 count( $wgExtensionCredits ) === 0 ||
444 // Skins are displayed separately, see getSkinCredits()
445 ( count( $wgExtensionCredits ) === 1 && isset( $wgExtensionCredits['skin'] ) )
450 $extensionTypes = self
::getExtensionTypes();
454 array( 'id' => 'mw-version-ext' ),
455 $this->msg( 'version-extensions' )->text()
457 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-ext' ) );
459 // Make sure the 'other' type is set to an array.
460 if ( !array_key_exists( 'other', $wgExtensionCredits ) ) {
461 $wgExtensionCredits['other'] = array();
464 // Find all extensions that do not have a valid type and give them the type 'other'.
465 foreach ( $wgExtensionCredits as $type => $extensions ) {
466 if ( !array_key_exists( $type, $extensionTypes ) ) {
467 $wgExtensionCredits['other'] = array_merge( $wgExtensionCredits['other'], $extensions );
471 $this->firstExtOpened
= false;
472 // Loop through the extension categories to display their extensions in the list.
473 foreach ( $extensionTypes as $type => $message ) {
474 // Skins have a separate section
475 if ( $type !== 'other' && $type !== 'skin' ) {
476 $out .= $this->getExtensionCategory( $type, $message );
480 // We want the 'other' type to be last in the list.
481 $out .= $this->getExtensionCategory( 'other', $extensionTypes['other'] );
483 $out .= Xml
::closeElement( 'table' );
489 * Generate wikitext showing the name, URL, author and description of each skin.
491 * @return string Wikitext
493 public function getSkinCredits() {
494 global $wgExtensionCredits;
495 if ( !isset( $wgExtensionCredits['skin'] ) ||
count( $wgExtensionCredits['skin'] ) === 0 ) {
501 array( 'id' => 'mw-version-skin' ),
502 $this->msg( 'version-skins' )->text()
504 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-skin' ) );
506 $this->firstExtOpened
= false;
507 $out .= $this->getExtensionCategory( 'skin', null );
509 $out .= Xml
::closeElement( 'table' );
515 * Generate an HTML table for external libraries that are installed
519 protected function getExternalLibraries() {
521 $path = "$IP/vendor/composer/installed.json";
522 if ( !file_exists( $path ) ) {
526 $installed = new ComposerInstalled( $path );
527 $out = Html
::element(
529 array( 'id' => 'mw-version-libraries' ),
530 $this->msg( 'version-libraries' )->text()
532 $out .= Html
::openElement(
534 array( 'class' => 'wikitable plainlinks', 'id' => 'sv-libraries' )
536 $out .= Html
::openElement( 'tr' )
537 . Html
::element( 'th', array(), $this->msg( 'version-libraries-library' )->text() )
538 . Html
::element( 'th', array(), $this->msg( 'version-libraries-version' )->text() )
539 . Html
::element( 'th', array(), $this->msg( 'version-libraries-license' )->text() )
540 . Html
::element( 'th', array(), $this->msg( 'version-libraries-description' )->text() )
541 . Html
::element( 'th', array(), $this->msg( 'version-libraries-authors' )->text() )
542 . Html
::closeElement( 'tr' );
544 foreach ( $installed->getInstalledDependencies() as $name => $info ) {
545 if ( strpos( $info['type'], 'mediawiki-' ) === 0 ) {
546 // Skip any extensions or skins since they'll be listed
547 // in their proper section
550 $authors = array_map( function( $arr ) {
551 // If a homepage is set, link to it
552 if ( isset( $arr['homepage'] ) ) {
553 return "[{$arr['homepage']} {$arr['name']}]";
556 }, $info['authors'] );
557 $authors = $this->listAuthors( $authors, false, "$IP/vendor/$name" );
559 // We can safely assume that the libraries' names and descriptions
560 // are written in English and aren't going to be translated,
561 // so set appropriate lang and dir attributes
562 $out .= Html
::openElement( 'tr' )
566 Linker
::makeExternalLink(
567 "https://packagist.org/packages/$name", $name,
569 array( 'class' => 'mw-version-library-name' )
572 . Html
::element( 'td', array( 'dir' => 'auto' ), $info['version'] )
573 . Html
::element( 'td', array( 'dir' => 'auto' ), $this->listToText( $info['licenses'] ) )
574 . Html
::element( 'td', array( 'lang' => 'en', 'dir' => 'ltr' ), $info['description'] )
575 . Html
::rawElement( 'td', array(), $authors )
576 . Html
::closeElement( 'tr' );
578 $out .= Html
::closeElement( 'table' );
584 * Obtains a list of installed parser tags and the associated H2 header
586 * @return string HTML output
588 protected function getParserTags() {
591 $tags = $wgParser->getTags();
593 if ( count( $tags ) ) {
594 $out = Html
::rawElement(
597 'class' => 'mw-headline plainlinks',
598 'id' => 'mw-version-parser-extensiontags',
600 Linker
::makeExternalLink(
601 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Tag_extensions',
602 $this->msg( 'version-parser-extensiontags' )->parse(),
603 false /* msg()->parse() already escapes */
607 array_walk( $tags, function ( &$value ) {
608 // Bidirectional isolation improves readability in RTL wikis
609 $value = Html
::element(
611 // Prevent < and > from slipping to another line
613 'style' => 'white-space: nowrap;',
619 $out .= $this->listToText( $tags );
628 * Obtains a list of installed parser function hooks and the associated H2 header
630 * @return string HTML output
632 protected function getParserFunctionHooks() {
635 $fhooks = $wgParser->getFunctionHooks();
636 if ( count( $fhooks ) ) {
637 $out = Html
::rawElement(
640 'class' => 'mw-headline plainlinks',
641 'id' => 'mw-version-parser-function-hooks',
643 Linker
::makeExternalLink(
644 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Parser_functions',
645 $this->msg( 'version-parser-function-hooks' )->parse(),
646 false /* msg()->parse() already escapes */
650 $out .= $this->listToText( $fhooks );
659 * Creates and returns the HTML for a single extension category.
663 * @param string $type
664 * @param string $message
668 protected function getExtensionCategory( $type, $message ) {
669 global $wgExtensionCredits;
673 if ( array_key_exists( $type, $wgExtensionCredits ) && count( $wgExtensionCredits[$type] ) > 0 ) {
674 $out .= $this->openExtType( $message, 'credits-' . $type );
676 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
678 foreach ( $wgExtensionCredits[$type] as $extension ) {
679 $out .= $this->getCreditsForExtension( $extension );
687 * Callback to sort extensions by type.
692 public function compare( $a, $b ) {
693 if ( $a['name'] === $b['name'] ) {
696 return $this->getLanguage()->lc( $a['name'] ) > $this->getLanguage()->lc( $b['name'] )
703 * Creates and formats a version line for a single extension.
705 * Information for five columns will be created. Parameters required in the
706 * $extension array for part rendering are indicated in ()
707 * - The name of (name), and URL link to (url), the extension
708 * - Official version number (version) and if available version control system
709 * revision (path), link, and date
710 * - If available the short name of the license (license-name) and a linke
711 * to ((LICENSE)|(COPYING))(\.txt)? if it exists.
712 * - Description of extension (descriptionmsg or description)
713 * - List of authors (author) and link to a ((AUTHORS)|(CREDITS))(\.txt)? file if it exists
715 * @param array $extension
717 * @return string Raw HTML
719 public function getCreditsForExtension( array $extension ) {
720 $out = $this->getOutput();
722 // We must obtain the information for all the bits and pieces!
723 // ... such as extension names and links
724 if ( isset( $extension['namemsg'] ) ) {
725 // Localized name of extension
726 $extensionName = $this->msg( $extension['namemsg'] )->text();
727 } elseif ( isset( $extension['name'] ) ) {
728 // Non localized version
729 $extensionName = $extension['name'];
731 $extensionName = $this->msg( 'version-no-ext-name' )->text();
734 if ( isset( $extension['url'] ) ) {
735 $extensionNameLink = Linker
::makeExternalLink(
740 array( 'class' => 'mw-version-ext-name' )
743 $extensionNameLink = $extensionName;
746 // ... and the version information
747 // If the extension path is set we will check that directory for GIT and SVN
748 // metadata in an attempt to extract date and vcs commit metadata.
749 $canonicalVersion = '–';
750 $extensionPath = null;
755 if ( isset( $extension['version'] ) ) {
756 $canonicalVersion = $out->parseInline( $extension['version'] );
759 if ( isset( $extension['path'] ) ) {
761 $extensionPath = dirname( $extension['path'] );
762 if ( $this->coreId
== '' ) {
763 wfDebug( 'Looking up core head id' );
764 $coreHeadSHA1 = self
::getGitHeadSha1( $IP );
765 if ( $coreHeadSHA1 ) {
766 $this->coreId
= $coreHeadSHA1;
768 $svnInfo = self
::getSvnInfo( $IP );
769 if ( $svnInfo !== false ) {
770 $this->coreId
= $svnInfo['checkout-rev'];
774 $cache = wfGetCache( CACHE_ANYTHING
);
775 $memcKey = wfMemcKey( 'specialversion-ext-version-text', $extension['path'], $this->coreId
);
776 list( $vcsVersion, $vcsLink, $vcsDate ) = $cache->get( $memcKey );
778 if ( !$vcsVersion ) {
779 wfDebug( "Getting VCS info for extension {$extension['name']}" );
780 $gitInfo = new GitInfo( $extensionPath );
781 $vcsVersion = $gitInfo->getHeadSHA1();
782 if ( $vcsVersion !== false ) {
783 $vcsVersion = substr( $vcsVersion, 0, 7 );
784 $vcsLink = $gitInfo->getHeadViewUrl();
785 $vcsDate = $gitInfo->getHeadCommitDate();
787 $svnInfo = self
::getSvnInfo( $extensionPath );
788 if ( $svnInfo !== false ) {
789 $vcsVersion = $this->msg( 'version-svn-revision', $svnInfo['checkout-rev'] )->text();
790 $vcsLink = isset( $svnInfo['viewvc-url'] ) ?
$svnInfo['viewvc-url'] : '';
793 $cache->set( $memcKey, array( $vcsVersion, $vcsLink, $vcsDate ), 60 * 60 * 24 );
795 wfDebug( "Pulled VCS info for extension {$extension['name']} from cache" );
799 $versionString = Html
::rawElement(
801 array( 'class' => 'mw-version-ext-version' ),
807 $vcsVerString = Linker
::makeExternalLink(
809 $this->msg( 'version-version', $vcsVersion ),
812 array( 'class' => 'mw-version-ext-vcs-version' )
815 $vcsVerString = Html
::element( 'span',
816 array( 'class' => 'mw-version-ext-vcs-version' ),
820 $versionString .= " {$vcsVerString}";
823 $vcsTimeString = Html
::element( 'span',
824 array( 'class' => 'mw-version-ext-vcs-timestamp' ),
825 $this->getLanguage()->timeanddate( $vcsDate, true )
827 $versionString .= " {$vcsTimeString}";
829 $versionString = Html
::rawElement( 'span',
830 array( 'class' => 'mw-version-ext-meta-version' ),
835 // ... and license information; if a license file exists we
838 if ( isset( $extension['name'] ) ) {
840 if ( isset( $extension['license-name'] ) ) {
841 $licenseName = $out->parseInline( $extension['license-name'] );
842 } elseif ( $this->getExtLicenseFileName( $extensionPath ) ) {
843 $licenseName = $this->msg( 'version-ext-license' );
845 if ( $licenseName !== null ) {
846 $licenseLink = Linker
::link(
847 $this->getPageTitle( 'License/' . $extension['name'] ),
850 'class' => 'mw-version-ext-license',
857 // ... and generate the description; which can be a parameterized l10n message
858 // in the form array( <msgname>, <parameter>, <parameter>... ) or just a straight
860 if ( isset( $extension['descriptionmsg'] ) ) {
861 // Localized description of extension
862 $descriptionMsg = $extension['descriptionmsg'];
864 if ( is_array( $descriptionMsg ) ) {
865 $descriptionMsgKey = $descriptionMsg[0]; // Get the message key
866 array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
867 array_map( "htmlspecialchars", $descriptionMsg ); // For sanity
868 $description = $this->msg( $descriptionMsgKey, $descriptionMsg )->text();
870 $description = $this->msg( $descriptionMsg )->text();
872 } elseif ( isset( $extension['description'] ) ) {
873 // Non localized version
874 $description = $extension['description'];
878 $description = $out->parseInline( $description );
880 // ... now get the authors for this extension
881 $authors = isset( $extension['author'] ) ?
$extension['author'] : array();
882 $authors = $this->listAuthors( $authors, $extension['name'], $extensionPath );
884 // Finally! Create the table
885 $html = Html
::openElement( 'tr', array(
886 'class' => 'mw-version-ext',
887 'id' => Sanitizer
::escapeId( 'mw-version-ext-' . $extension['name'] )
891 $html .= Html
::rawElement( 'td', array(), $extensionNameLink );
892 $html .= Html
::rawElement( 'td', array(), $versionString );
893 $html .= Html
::rawElement( 'td', array(), $licenseLink );
894 $html .= Html
::rawElement( 'td', array( 'class' => 'mw-version-ext-description' ), $description );
895 $html .= Html
::rawElement( 'td', array( 'class' => 'mw-version-ext-authors' ), $authors );
897 $html .= Html
::closeElement( 'tr' );
903 * Generate wikitext showing hooks in $wgHooks.
905 * @return string Wikitext
907 private function getWgHooks() {
908 global $wgSpecialVersionShowHooks, $wgHooks;
910 if ( $wgSpecialVersionShowHooks && count( $wgHooks ) ) {
911 $myWgHooks = $wgHooks;
915 $ret[] = '== {{int:version-hooks}} ==';
916 $ret[] = Html
::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-hooks' ) );
917 $ret[] = Html
::openElement( 'tr' );
918 $ret[] = Html
::element( 'th', array(), $this->msg( 'version-hook-name' )->text() );
919 $ret[] = Html
::element( 'th', array(), $this->msg( 'version-hook-subscribedby' )->text() );
920 $ret[] = Html
::closeElement( 'tr' );
922 foreach ( $myWgHooks as $hook => $hooks ) {
923 $ret[] = Html
::openElement( 'tr' );
924 $ret[] = Html
::element( 'td', array(), $hook );
925 $ret[] = Html
::element( 'td', array(), $this->listToText( $hooks ) );
926 $ret[] = Html
::closeElement( 'tr' );
929 $ret[] = Html
::closeElement( 'table' );
931 return implode( "\n", $ret );
937 private function openExtType( $text = null, $name = null ) {
940 $opt = array( 'colspan' => 5 );
941 if ( $this->firstExtOpened
) {
942 // Insert a spacing line
943 $out .= Html
::rawElement( 'tr', array( 'class' => 'sv-space' ),
944 Html
::element( 'td', $opt )
947 $this->firstExtOpened
= true;
950 $opt['id'] = "sv-$name";
953 if ( $text !== null ) {
954 $out .= Html
::rawElement( 'tr', array(),
955 Html
::element( 'th', $opt, $text )
959 $firstHeadingMsg = ( $name === 'credits-skin' )
960 ?
'version-skin-colheader-name'
961 : 'version-ext-colheader-name';
962 $out .= Html
::openElement( 'tr' );
963 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
964 $this->msg( $firstHeadingMsg )->text() );
965 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
966 $this->msg( 'version-ext-colheader-version' )->text() );
967 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
968 $this->msg( 'version-ext-colheader-license' )->text() );
969 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
970 $this->msg( 'version-ext-colheader-description' )->text() );
971 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
972 $this->msg( 'version-ext-colheader-credits' )->text() );
973 $out .= Html
::closeElement( 'tr' );
979 * Get information about client's IP address.
981 * @return string HTML fragment
983 private function IPInfo() {
984 $ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) );
986 return "<!-- visited from $ip -->\n<span style='display:none'>visited from $ip</span>";
990 * Return a formatted unsorted list of authors
993 * If an item in the $authors array is '...' it is assumed to indicate an
994 * 'and others' string which will then be linked to an ((AUTHORS)|(CREDITS))(\.txt)?
995 * file if it exists in $dir.
997 * Similarly an entry ending with ' ...]' is assumed to be a link to an
1000 * If no '...' string variant is found, but an authors file is found an
1001 * 'and others' will be added to the end of the credits.
1003 * @param string|array $authors
1004 * @param string|bool $extName Name of the extension for link creation,
1005 * false if no links should be created
1006 * @param string $extDir Path to the extension root directory
1008 * @return string HTML fragment
1010 public function listAuthors( $authors, $extName, $extDir ) {
1014 foreach ( (array)$authors as $item ) {
1015 if ( $item == '...' ) {
1018 if ( $extName && $this->getExtAuthorsFileName( $extDir ) ) {
1019 $text = Linker
::link(
1020 $this->getPageTitle( "Credits/$extName" ),
1021 $this->msg( 'version-poweredby-others' )->escaped()
1024 $text = $this->msg( 'version-poweredby-others' )->escaped();
1027 } elseif ( substr( $item, -5 ) == ' ...]' ) {
1029 $list[] = $this->getOutput()->parseInline(
1030 substr( $item, 0, -4 ) . $this->msg( 'version-poweredby-others' )->text() . "]"
1033 $list[] = $this->getOutput()->parseInline( $item );
1037 if ( $extName && !$hasOthers && $this->getExtAuthorsFileName( $extDir ) ) {
1038 $list[] = $text = Linker
::link(
1039 $this->getPageTitle( "Credits/$extName" ),
1040 $this->msg( 'version-poweredby-others' )->escaped()
1044 return $this->listToText( $list, false );
1048 * Obtains the full path of an extensions authors or credits file if
1051 * @param string $extDir Path to the extensions root directory
1055 * @return bool|string False if no such file exists, otherwise returns
1058 public static function getExtAuthorsFileName( $extDir ) {
1063 foreach ( scandir( $extDir ) as $file ) {
1064 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
1065 if ( preg_match( '/^((AUTHORS)|(CREDITS))(\.txt|\.wiki|\.mediawiki)?$/', $file ) &&
1066 is_readable( $fullPath ) &&
1067 is_file( $fullPath )
1077 * Obtains the full path of an extensions copying or license file if
1080 * @param string $extDir Path to the extensions root directory
1084 * @return bool|string False if no such file exists, otherwise returns
1087 public static function getExtLicenseFileName( $extDir ) {
1092 foreach ( scandir( $extDir ) as $file ) {
1093 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
1094 if ( preg_match( '/^((COPYING)|(LICENSE))(\.txt)?$/', $file ) &&
1095 is_readable( $fullPath ) &&
1096 is_file( $fullPath )
1106 * Convert an array of items into a list for display.
1108 * @param array $list List of elements to display
1109 * @param bool $sort Whether to sort the items in $list
1113 public function listToText( $list, $sort = true ) {
1114 if ( !count( $list ) ) {
1121 return $this->getLanguage()
1122 ->listToText( array_map( array( __CLASS__
, 'arrayToString' ), $list ) );
1126 * Convert an array or object to a string for display.
1128 * @param mixed $list Will convert an array to string if given and return
1129 * the parameter unaltered otherwise
1133 public static function arrayToString( $list ) {
1134 if ( is_array( $list ) && count( $list ) == 1 ) {
1137 if ( $list instanceof Closure
) {
1138 // Don't output stuff like "Closure$;1028376090#8$48499d94fe0147f7c633b365be39952b$"
1140 } elseif ( is_object( $list ) ) {
1141 $class = wfMessage( 'parentheses' )->params( get_class( $list ) )->escaped();
1144 } elseif ( !is_array( $list ) ) {
1147 if ( is_object( $list[0] ) ) {
1148 $class = get_class( $list[0] );
1153 return wfMessage( 'parentheses' )->params( "$class, {$list[1]}" )->escaped();
1158 * Get an associative array of information about a given path, from its .svn
1159 * subdirectory. Returns false on error, such as if the directory was not
1160 * checked out with subversion.
1162 * Returned keys are:
1164 * checkout-rev The revision which was checked out
1166 * directory-rev The revision when the directory was last modified
1167 * url The subversion URL of the directory
1168 * repo-url The base URL of the repository
1169 * viewvc-url A ViewVC URL pointing to the checked-out revision
1170 * @param string $dir
1171 * @return array|bool
1173 public static function getSvnInfo( $dir ) {
1174 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
1175 $entries = $dir . '/.svn/entries';
1177 if ( !file_exists( $entries ) ) {
1181 $lines = file( $entries );
1182 if ( !count( $lines ) ) {
1186 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
1187 if ( preg_match( '/^<\?xml/', $lines[0] ) ) {
1188 // subversion is release <= 1.3
1189 if ( !function_exists( 'simplexml_load_file' ) ) {
1190 // We could fall back to expat... YUCK
1194 // SimpleXml whines about the xmlns...
1195 MediaWiki\
suppressWarnings();
1196 $xml = simplexml_load_file( $entries );
1197 MediaWiki\restoreWarnings
();
1200 foreach ( $xml->entry
as $entry ) {
1201 if ( $xml->entry
[0]['name'] == '' ) {
1202 // The directory entry should always have a revision marker.
1203 if ( $entry['revision'] ) {
1204 return array( 'checkout-rev' => intval( $entry['revision'] ) );
1213 // Subversion is release 1.4 or above.
1214 if ( count( $lines ) < 11 ) {
1219 'checkout-rev' => intval( trim( $lines[3] ) ),
1220 'url' => trim( $lines[4] ),
1221 'repo-url' => trim( $lines[5] ),
1222 'directory-rev' => intval( trim( $lines[10] ) )
1225 if ( isset( self
::$viewvcUrls[$info['repo-url']] ) ) {
1226 $viewvc = str_replace(
1228 self
::$viewvcUrls[$info['repo-url']],
1232 $viewvc .= '/?pathrev=';
1233 $viewvc .= urlencode( $info['checkout-rev'] );
1234 $info['viewvc-url'] = $viewvc;
1241 * Retrieve the revision number of a Subversion working directory.
1243 * @param string $dir Directory of the svn checkout
1245 * @return int Revision number
1247 public static function getSvnRevision( $dir ) {
1248 $info = self
::getSvnInfo( $dir );
1250 if ( $info === false ) {
1252 } elseif ( isset( $info['checkout-rev'] ) ) {
1253 return $info['checkout-rev'];
1260 * @param string $dir Directory of the git checkout
1261 * @return bool|string Sha1 of commit HEAD points to
1263 public static function getGitHeadSha1( $dir ) {
1264 $repo = new GitInfo( $dir );
1266 return $repo->getHeadSHA1();
1270 * @param string $dir Directory of the git checkout
1271 * @return bool|string Branch currently checked out
1273 public static function getGitCurrentBranch( $dir ) {
1274 $repo = new GitInfo( $dir );
1275 return $repo->getCurrentBranch();
1279 * Get the list of entry points and their URLs
1280 * @return string Wikitext
1282 public function getEntryPointInfo() {
1283 global $wgArticlePath, $wgScriptPath;
1284 $scriptPath = $wgScriptPath ?
$wgScriptPath : "/";
1285 $entryPoints = array(
1286 'version-entrypoints-articlepath' => $wgArticlePath,
1287 'version-entrypoints-scriptpath' => $scriptPath,
1288 'version-entrypoints-index-php' => wfScript( 'index' ),
1289 'version-entrypoints-api-php' => wfScript( 'api' ),
1290 'version-entrypoints-load-php' => wfScript( 'load' ),
1293 $language = $this->getLanguage();
1294 $thAttribures = array(
1295 'dir' => $language->getDir(),
1296 'lang' => $language->getHtmlCode()
1298 $out = Html
::element(
1300 array( 'id' => 'mw-version-entrypoints' ),
1301 $this->msg( 'version-entrypoints' )->text()
1303 Html
::openElement( 'table',
1305 'class' => 'wikitable plainlinks',
1306 'id' => 'mw-version-entrypoints-table',
1311 Html
::openElement( 'tr' ) .
1315 $this->msg( 'version-entrypoints-header-entrypoint' )->text()
1320 $this->msg( 'version-entrypoints-header-url' )->text()
1322 Html
::closeElement( 'tr' );
1324 foreach ( $entryPoints as $message => $value ) {
1325 $url = wfExpandUrl( $value, PROTO_RELATIVE
);
1326 $out .= Html
::openElement( 'tr' ) .
1327 // ->text() looks like it should be ->parse(), but this function
1328 // returns wikitext, not HTML, boo
1329 Html
::rawElement( 'td', array(), $this->msg( $message )->text() ) .
1330 Html
::rawElement( 'td', array(), Html
::rawElement( 'code', array(), "[$url $value]" ) ) .
1331 Html
::closeElement( 'tr' );
1334 $out .= Html
::closeElement( 'table' );
1339 protected function getGroupName() {