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( 'pre', array(), $wikiText );
100 $out->setPageTitle( $this->msg( 'version-credits-title', $extName ) );
101 $out->addWikiText( $wikiText );
105 $wikiText = '{{int:version-license-not-found}}';
106 if ( $extName === 'MediaWiki' ) {
107 $wikiText = file_get_contents( $IP . '/COPYING' );
108 } elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) {
109 $file = $this->getExtLicenseFileName( dirname( $extNode['path'] ) );
111 $wikiText = file_get_contents( $file );
112 $wikiText = "<pre>$wikiText</pre>";
116 $out->setPageTitle( $this->msg( 'version-license-title', $extName ) );
117 $out->addWikiText( $wikiText );
121 $out->addModules( 'mediawiki.special.version' );
123 $this->getMediaWikiCredits() .
124 $this->softwareInformation() .
125 $this->getEntryPointInfo()
128 $this->getSkinCredits() .
129 $this->getExtensionCredits() .
130 $this->getExternalLibraries() .
131 $this->getParserTags() .
132 $this->getParserFunctionHooks()
134 $out->addWikiText( $this->getWgHooks() );
135 $out->addHTML( $this->IPInfo() );
142 * Returns wiki text showing the license information.
146 private static function getMediaWikiCredits() {
149 array( 'id' => 'mw-version-license' ),
150 wfMessage( 'version-license' )->text()
153 // This text is always left-to-right.
154 $ret .= '<div class="plainlinks">';
156 " . self
::getCopyrightAndAuthorList() . "\n
157 " . wfMessage( 'version-license-info' )->text();
160 return str_replace( "\t\t", '', $ret ) . "\n";
164 * Get the "MediaWiki is copyright 2001-20xx by lots of cool guys" text
168 public static function getCopyrightAndAuthorList() {
171 if ( defined( 'MEDIAWIKI_INSTALL' ) ) {
172 $othersLink = '[//www.mediawiki.org/wiki/Special:Version/Credits ' .
173 wfMessage( 'version-poweredby-others' )->text() . ']';
175 $othersLink = '[[Special:Version/Credits|' .
176 wfMessage( 'version-poweredby-others' )->text() . ']]';
179 $translatorsLink = '[//translatewiki.net/wiki/Translating:MediaWiki/Credits ' .
180 wfMessage( 'version-poweredby-translators' )->text() . ']';
183 'Magnus Manske', 'Brion Vibber', 'Lee Daniel Crocker',
184 'Tim Starling', 'Erik Möller', 'Gabriel Wicke', 'Ævar Arnfjörð Bjarmason',
185 'Niklas Laxström', 'Domas Mituzas', 'Rob Church', 'Yuri Astrakhan',
186 'Aryeh Gregor', 'Aaron Schulz', 'Andrew Garrett', 'Raimond Spekking',
187 'Alexandre Emsenhuber', 'Siebrand Mazeland', 'Chad Horohoe',
188 'Roan Kattouw', 'Trevor Parscal', 'Bryan Tong Minh', 'Sam Reed',
189 'Victor Vasiliev', 'Rotem Liss', 'Platonides', 'Antoine Musso',
190 'Timo Tijhof', 'Daniel Kinzler', 'Jeroen De Dauw', 'Brad Jorsch',
191 $othersLink, $translatorsLink
194 return wfMessage( 'version-poweredby-credits', MWTimestamp
::getLocalInstance()->format( 'Y' ),
195 $wgLang->listToText( $authorList ) )->text();
199 * Returns wiki text showing the third party software versions (apache, php, mysql).
203 public static function softwareInformation() {
204 $dbr = wfGetDB( DB_SLAVE
);
206 // Put the software in an array of form 'name' => 'version'. All messages should
207 // be loaded here, so feel free to use wfMessage in the 'name'. Raw HTML or
208 // wikimarkup can be used.
210 $software['[https://www.mediawiki.org/ MediaWiki]'] = self
::getVersionLinked();
212 $software['[http://hhvm.com/ HHVM]'] = HHVM_VERSION
. " (" . PHP_SAPI
. ")";
214 $software['[https://php.net/ PHP]'] = PHP_VERSION
. " (" . PHP_SAPI
. ")";
216 $software[$dbr->getSoftwareLink()] = $dbr->getServerInfo();
218 if ( IcuCollation
::getICUVersion() ) {
219 $software['[http://site.icu-project.org/ ICU]'] = IcuCollation
::getICUVersion();
222 // Allow a hook to add/remove items.
223 Hooks
::run( 'SoftwareInfo', array( &$software ) );
227 array( 'id' => 'mw-version-software' ),
228 wfMessage( 'version-software' )->text()
230 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-software' ) ) .
232 <th>" . wfMessage( 'version-software-product' )->text() . "</th>
233 <th>" . wfMessage( 'version-software-version' )->text() . "</th>
236 foreach ( $software as $name => $version ) {
238 <td>" . $name . "</td>
239 <td dir=\"ltr\">" . $version . "</td>
243 return $out . Xml
::closeElement( 'table' );
247 * Return a string of the MediaWiki version with SVN revision if available.
249 * @param string $flags
252 public static function getVersion( $flags = '' ) {
253 global $wgVersion, $IP;
255 $gitInfo = self
::getGitHeadSha1( $IP );
256 $svnInfo = self
::getSvnInfo( $IP );
257 if ( !$svnInfo && !$gitInfo ) {
258 $version = $wgVersion;
259 } elseif ( $gitInfo && $flags === 'nodb' ) {
260 $shortSha1 = substr( $gitInfo, 0, 7 );
261 $version = "$wgVersion ($shortSha1)";
262 } elseif ( $gitInfo ) {
263 $shortSha1 = substr( $gitInfo, 0, 7 );
264 $shortSha1 = wfMessage( 'parentheses' )->params( $shortSha1 )->escaped();
265 $version = "$wgVersion $shortSha1";
266 } elseif ( $flags === 'nodb' ) {
267 $version = "$wgVersion (r{$svnInfo['checkout-rev']})";
269 $version = $wgVersion . ' ' .
271 'version-svn-revision',
272 isset( $svnInfo['directory-rev'] ) ?
$svnInfo['directory-rev'] : '',
273 isset( $svnInfo['checkout-rev'] ) ?
$svnInfo['checkout-rev'] : ''
281 * Return a wikitext-formatted string of the MediaWiki version with a link to
282 * the SVN revision or the git SHA1 of head if available.
283 * Git is prefered over Svn
284 * The fallback is just $wgVersion
288 public static function getVersionLinked() {
291 $gitVersion = self
::getVersionLinkedGit();
295 $svnVersion = self
::getVersionLinkedSvn();
299 $v = $wgVersion; // fallback
307 * @return string Global wgVersion + a link to subversion revision of svn BASE
309 private static function getVersionLinkedSvn() {
312 $info = self
::getSvnInfo( $IP );
313 if ( !isset( $info['checkout-rev'] ) ) {
317 $linkText = wfMessage(
318 'version-svn-revision',
319 isset( $info['directory-rev'] ) ?
$info['directory-rev'] : '',
320 $info['checkout-rev']
323 if ( isset( $info['viewvc-url'] ) ) {
324 $version = "[{$info['viewvc-url']} $linkText]";
326 $version = $linkText;
329 return self
::getwgVersionLinked() . " $version";
335 private static function getwgVersionLinked() {
338 if ( Hooks
::run( 'SpecialVersionVersionUrl', array( $wgVersion, &$versionUrl ) ) ) {
339 $versionParts = array();
340 preg_match( "/^(\d+\.\d+)/", $wgVersion, $versionParts );
341 $versionUrl = "https://www.mediawiki.org/wiki/MediaWiki_{$versionParts[1]}";
344 return "[$versionUrl $wgVersion]";
348 * @since 1.22 Returns the HEAD date in addition to the sha1 and link
349 * @return bool|string Global wgVersion + HEAD sha1 stripped to the first 7 chars
350 * with link and date, or false on failure
352 private static function getVersionLinkedGit() {
355 $gitInfo = new GitInfo( $IP );
356 $headSHA1 = $gitInfo->getHeadSHA1();
361 $shortSHA1 = '(' . substr( $headSHA1, 0, 7 ) . ')';
363 $gitHeadUrl = $gitInfo->getHeadViewUrl();
364 if ( $gitHeadUrl !== false ) {
365 $shortSHA1 = "[$gitHeadUrl $shortSHA1]";
368 $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
369 if ( $gitHeadCommitDate ) {
370 $shortSHA1 .= Html
::element( 'br' ) . $wgLang->timeanddate( $gitHeadCommitDate, true );
373 return self
::getwgVersionLinked() . " $shortSHA1";
377 * Returns an array with the base extension types.
378 * Type is stored as array key, the message as array value.
380 * TODO: ideally this would return all extension types.
386 public static function getExtensionTypes() {
387 if ( self
::$extensionTypes === false ) {
388 self
::$extensionTypes = array(
389 'specialpage' => wfMessage( 'version-specialpages' )->text(),
390 'parserhook' => wfMessage( 'version-parserhooks' )->text(),
391 'variable' => wfMessage( 'version-variables' )->text(),
392 'media' => wfMessage( 'version-mediahandlers' )->text(),
393 'antispam' => wfMessage( 'version-antispam' )->text(),
394 'skin' => wfMessage( 'version-skins' )->text(),
395 'api' => wfMessage( 'version-api' )->text(),
396 'other' => wfMessage( 'version-other' )->text(),
399 Hooks
::run( 'ExtensionTypes', array( &self
::$extensionTypes ) );
402 return self
::$extensionTypes;
406 * Returns the internationalized name for an extension type.
410 * @param string $type
414 public static function getExtensionTypeName( $type ) {
415 $types = self
::getExtensionTypes();
417 return isset( $types[$type] ) ?
$types[$type] : $types['other'];
421 * Generate wikitext showing the name, URL, author and description of each extension.
423 * @return string Wikitext
425 public function getExtensionCredits() {
426 global $wgExtensionCredits;
429 count( $wgExtensionCredits ) === 0 ||
430 // Skins are displayed separately, see getSkinCredits()
431 ( count( $wgExtensionCredits ) === 1 && isset( $wgExtensionCredits['skin'] ) )
436 $extensionTypes = self
::getExtensionTypes();
440 array( 'id' => 'mw-version-ext' ),
441 $this->msg( 'version-extensions' )->text()
443 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-ext' ) );
445 // Make sure the 'other' type is set to an array.
446 if ( !array_key_exists( 'other', $wgExtensionCredits ) ) {
447 $wgExtensionCredits['other'] = array();
450 // Find all extensions that do not have a valid type and give them the type 'other'.
451 foreach ( $wgExtensionCredits as $type => $extensions ) {
452 if ( !array_key_exists( $type, $extensionTypes ) ) {
453 $wgExtensionCredits['other'] = array_merge( $wgExtensionCredits['other'], $extensions );
457 $this->firstExtOpened
= false;
458 // Loop through the extension categories to display their extensions in the list.
459 foreach ( $extensionTypes as $type => $message ) {
460 // Skins have a separate section
461 if ( $type !== 'other' && $type !== 'skin' ) {
462 $out .= $this->getExtensionCategory( $type, $message );
466 // We want the 'other' type to be last in the list.
467 $out .= $this->getExtensionCategory( 'other', $extensionTypes['other'] );
469 $out .= Xml
::closeElement( 'table' );
475 * Generate wikitext showing the name, URL, author and description of each skin.
477 * @return string Wikitext
479 public function getSkinCredits() {
480 global $wgExtensionCredits;
481 if ( !isset( $wgExtensionCredits['skin'] ) ||
count( $wgExtensionCredits['skin'] ) === 0 ) {
487 array( 'id' => 'mw-version-skin' ),
488 $this->msg( 'version-skins' )->text()
490 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-skin' ) );
492 $this->firstExtOpened
= false;
493 $out .= $this->getExtensionCategory( 'skin', null );
495 $out .= Xml
::closeElement( 'table' );
501 * Generate an HTML table for external libraries that are installed
505 protected function getExternalLibraries() {
507 $path = "$IP/composer.lock";
508 if ( !file_exists( $path ) ) {
509 // Maybe they're using mediawiki/vendor?
510 $path = "$IP/vendor/composer.lock";
511 if ( !file_exists( $path ) ) {
516 $lock = new ComposerLock( $path );
517 $out = Html
::element(
519 array( 'id' => 'mw-version-libraries' ),
520 $this->msg( 'version-libraries' )->text()
522 $out .= Html
::openElement(
524 array( 'class' => 'wikitable plainlinks', 'id' => 'sv-libraries' )
526 $out .= Html
::openElement( 'tr' )
527 . Html
::element( 'th', array(), $this->msg( 'version-libraries-library' )->text() )
528 . Html
::element( 'th', array(), $this->msg( 'version-libraries-version' )->text() )
529 . Html
::element( 'th', array(), $this->msg( 'version-libraries-license' )->text() )
530 . Html
::element( 'th', array(), $this->msg( 'version-libraries-description' )->text() )
531 . Html
::element( 'th', array(), $this->msg( 'version-libraries-authors' )->text() )
532 . Html
::closeElement( 'tr' );
534 foreach ( $lock->getInstalledDependencies() as $name => $info ) {
535 if ( strpos( $info['type'], 'mediawiki-' ) === 0 ) {
536 // Skip any extensions or skins since they'll be listed
537 // in their proper section
540 $authors = array_map( function( $arr ) {
541 // If a homepage is set, link to it
542 if ( isset( $arr['homepage'] ) ) {
543 return "[{$arr['homepage']} {$arr['name']}]";
546 }, $info['authors'] );
547 $authors = $this->listAuthors( $authors, false, "$IP/vendor/$name" );
549 // We can safely assume that the libraries' names and descriptions
550 // are written in English and aren't going to be translated,
551 // so set appropriate lang and dir attributes
552 $out .= Html
::openElement( 'tr' )
556 Linker
::makeExternalLink(
557 "https://packagist.org/packages/$name", $name,
559 array( 'class' => 'mw-version-library-name' )
562 . Html
::element( 'td', array( 'dir' => 'auto' ), $info['version'] )
563 . Html
::element( 'td', array( 'dir' => 'auto' ), $this->listToText( $info['licenses'] ) )
564 . Html
::element( 'td', array( 'lang' => 'en', 'dir' => 'ltr' ), $info['description'] )
565 . Html
::rawElement( 'td', array(), $authors )
566 . Html
::closeElement( 'tr' );
568 $out .= Html
::closeElement( 'table' );
574 * Obtains a list of installed parser tags and the associated H2 header
576 * @return string HTML output
578 protected function getParserTags() {
581 $tags = $wgParser->getTags();
583 if ( count( $tags ) ) {
584 $out = Html
::rawElement(
587 'class' => 'mw-headline plainlinks',
588 'id' => 'mw-version-parser-extensiontags',
590 Linker
::makeExternalLink(
591 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Tag_extensions',
592 $this->msg( 'version-parser-extensiontags' )->parse(),
593 false /* msg()->parse() already escapes */
597 array_walk( $tags, function ( &$value ) {
598 // Bidirectional isolation improves readability in RTL wikis
599 $value = Html
::element(
601 // Prevent < and > from slipping to another line
603 'style' => 'white-space: nowrap;',
609 $out .= $this->listToText( $tags );
618 * Obtains a list of installed parser function hooks and the associated H2 header
620 * @return string HTML output
622 protected function getParserFunctionHooks() {
625 $fhooks = $wgParser->getFunctionHooks();
626 if ( count( $fhooks ) ) {
627 $out = Html
::rawElement(
630 'class' => 'mw-headline plainlinks',
631 'id' => 'mw-version-parser-function-hooks',
633 Linker
::makeExternalLink(
634 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Parser_functions',
635 $this->msg( 'version-parser-function-hooks' )->parse(),
636 false /* msg()->parse() already escapes */
640 $out .= $this->listToText( $fhooks );
649 * Creates and returns the HTML for a single extension category.
653 * @param string $type
654 * @param string $message
658 protected function getExtensionCategory( $type, $message ) {
659 global $wgExtensionCredits;
663 if ( array_key_exists( $type, $wgExtensionCredits ) && count( $wgExtensionCredits[$type] ) > 0 ) {
664 $out .= $this->openExtType( $message, 'credits-' . $type );
666 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
668 foreach ( $wgExtensionCredits[$type] as $extension ) {
669 $out .= $this->getCreditsForExtension( $extension );
677 * Callback to sort extensions by type.
682 public function compare( $a, $b ) {
683 if ( $a['name'] === $b['name'] ) {
686 return $this->getLanguage()->lc( $a['name'] ) > $this->getLanguage()->lc( $b['name'] )
693 * Creates and formats a version line for a single extension.
695 * Information for five columns will be created. Parameters required in the
696 * $extension array for part rendering are indicated in ()
697 * - The name of (name), and URL link to (url), the extension
698 * - Official version number (version) and if available version control system
699 * revision (path), link, and date
700 * - If available the short name of the license (license-name) and a linke
701 * to ((LICENSE)|(COPYING))(\.txt)? if it exists.
702 * - Description of extension (descriptionmsg or description)
703 * - List of authors (author) and link to a ((AUTHORS)|(CREDITS))(\.txt)? file if it exists
705 * @param array $extension
707 * @return string Raw HTML
709 public function getCreditsForExtension( array $extension ) {
710 $out = $this->getOutput();
712 // We must obtain the information for all the bits and pieces!
713 // ... such as extension names and links
714 if ( isset( $extension['namemsg'] ) ) {
715 // Localized name of extension
716 $extensionName = $this->msg( $extension['namemsg'] )->text();
717 } elseif ( isset( $extension['name'] ) ) {
718 // Non localized version
719 $extensionName = $extension['name'];
721 $extensionName = $this->msg( 'version-no-ext-name' )->text();
724 if ( isset( $extension['url'] ) ) {
725 $extensionNameLink = Linker
::makeExternalLink(
730 array( 'class' => 'mw-version-ext-name' )
733 $extensionNameLink = $extensionName;
736 // ... and the version information
737 // If the extension path is set we will check that directory for GIT and SVN
738 // metadata in an attempt to extract date and vcs commit metadata.
739 $canonicalVersion = '–';
740 $extensionPath = null;
745 if ( isset( $extension['version'] ) ) {
746 $canonicalVersion = $out->parseInline( $extension['version'] );
749 if ( isset( $extension['path'] ) ) {
751 $extensionPath = dirname( $extension['path'] );
752 if ( $this->coreId
== '' ) {
753 wfDebug( 'Looking up core head id' );
754 $coreHeadSHA1 = self
::getGitHeadSha1( $IP );
755 if ( $coreHeadSHA1 ) {
756 $this->coreId
= $coreHeadSHA1;
758 $svnInfo = self
::getSvnInfo( $IP );
759 if ( $svnInfo !== false ) {
760 $this->coreId
= $svnInfo['checkout-rev'];
764 $cache = wfGetCache( CACHE_ANYTHING
);
765 $memcKey = wfMemcKey( 'specialversion-ext-version-text', $extension['path'], $this->coreId
);
766 list( $vcsVersion, $vcsLink, $vcsDate ) = $cache->get( $memcKey );
768 if ( !$vcsVersion ) {
769 wfDebug( "Getting VCS info for extension {$extension['name']}" );
770 $gitInfo = new GitInfo( $extensionPath );
771 $vcsVersion = $gitInfo->getHeadSHA1();
772 if ( $vcsVersion !== false ) {
773 $vcsVersion = substr( $vcsVersion, 0, 7 );
774 $vcsLink = $gitInfo->getHeadViewUrl();
775 $vcsDate = $gitInfo->getHeadCommitDate();
777 $svnInfo = self
::getSvnInfo( $extensionPath );
778 if ( $svnInfo !== false ) {
779 $vcsVersion = $this->msg( 'version-svn-revision', $svnInfo['checkout-rev'] )->text();
780 $vcsLink = isset( $svnInfo['viewvc-url'] ) ?
$svnInfo['viewvc-url'] : '';
783 $cache->set( $memcKey, array( $vcsVersion, $vcsLink, $vcsDate ), 60 * 60 * 24 );
785 wfDebug( "Pulled VCS info for extension {$extension['name']} from cache" );
789 $versionString = Html
::rawElement(
791 array( 'class' => 'mw-version-ext-version' ),
797 $vcsVerString = Linker
::makeExternalLink(
799 $this->msg( 'version-version', $vcsVersion ),
802 array( 'class' => 'mw-version-ext-vcs-version' )
805 $vcsVerString = Html
::element( 'span',
806 array( 'class' => 'mw-version-ext-vcs-version' ),
810 $versionString .= " {$vcsVerString}";
813 $vcsTimeString = Html
::element( 'span',
814 array( 'class' => 'mw-version-ext-vcs-timestamp' ),
815 $this->getLanguage()->timeanddate( $vcsDate, true )
817 $versionString .= " {$vcsTimeString}";
819 $versionString = Html
::rawElement( 'span',
820 array( 'class' => 'mw-version-ext-meta-version' ),
825 // ... and license information; if a license file exists we
828 if ( isset( $extension['name'] ) ) {
830 if ( isset( $extension['license-name'] ) ) {
831 $licenseName = $out->parseInline( $extension['license-name'] );
832 } elseif ( $this->getExtLicenseFileName( $extensionPath ) ) {
833 $licenseName = $this->msg( 'version-ext-license' );
835 if ( $licenseName !== null ) {
836 $licenseLink = Linker
::link(
837 $this->getPageTitle( 'License/' . $extension['name'] ),
840 'class' => 'mw-version-ext-license',
847 // ... and generate the description; which can be a parameterized l10n message
848 // in the form array( <msgname>, <parameter>, <parameter>... ) or just a straight
850 if ( isset( $extension['descriptionmsg'] ) ) {
851 // Localized description of extension
852 $descriptionMsg = $extension['descriptionmsg'];
854 if ( is_array( $descriptionMsg ) ) {
855 $descriptionMsgKey = $descriptionMsg[0]; // Get the message key
856 array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
857 array_map( "htmlspecialchars", $descriptionMsg ); // For sanity
858 $description = $this->msg( $descriptionMsgKey, $descriptionMsg )->text();
860 $description = $this->msg( $descriptionMsg )->text();
862 } elseif ( isset( $extension['description'] ) ) {
863 // Non localized version
864 $description = $extension['description'];
868 $description = $out->parseInline( $description );
870 // ... now get the authors for this extension
871 $authors = isset( $extension['author'] ) ?
$extension['author'] : array();
872 $authors = $this->listAuthors( $authors, $extension['name'], $extensionPath );
874 // Finally! Create the table
875 $html = Html
::openElement( 'tr', array(
876 'class' => 'mw-version-ext',
877 'id' => Sanitizer
::escapeId( 'mw-version-ext-' . $extension['name'] )
881 $html .= Html
::rawElement( 'td', array(), $extensionNameLink );
882 $html .= Html
::rawElement( 'td', array(), $versionString );
883 $html .= Html
::rawElement( 'td', array(), $licenseLink );
884 $html .= Html
::rawElement( 'td', array( 'class' => 'mw-version-ext-description' ), $description );
885 $html .= Html
::rawElement( 'td', array( 'class' => 'mw-version-ext-authors' ), $authors );
887 $html .= Html
::closeElement( 'tr' );
893 * Generate wikitext showing hooks in $wgHooks.
895 * @return string Wikitext
897 private function getWgHooks() {
898 global $wgSpecialVersionShowHooks, $wgHooks;
900 if ( $wgSpecialVersionShowHooks && count( $wgHooks ) ) {
901 $myWgHooks = $wgHooks;
905 $ret[] = '== {{int:version-hooks}} ==';
906 $ret[] = Html
::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-hooks' ) );
907 $ret[] = Html
::openElement( 'tr' );
908 $ret[] = Html
::element( 'th', array(), $this->msg( 'version-hook-name' )->text() );
909 $ret[] = Html
::element( 'th', array(), $this->msg( 'version-hook-subscribedby' )->text() );
910 $ret[] = Html
::closeElement( 'tr' );
912 foreach ( $myWgHooks as $hook => $hooks ) {
913 $ret[] = Html
::openElement( 'tr' );
914 $ret[] = Html
::element( 'td', array(), $hook );
915 $ret[] = Html
::element( 'td', array(), $this->listToText( $hooks ) );
916 $ret[] = Html
::closeElement( 'tr' );
919 $ret[] = Html
::closeElement( 'table' );
921 return implode( "\n", $ret );
927 private function openExtType( $text = null, $name = null ) {
930 $opt = array( 'colspan' => 5 );
931 if ( $this->firstExtOpened
) {
932 // Insert a spacing line
933 $out .= Html
::rawElement( 'tr', array( 'class' => 'sv-space' ),
934 Html
::element( 'td', $opt )
937 $this->firstExtOpened
= true;
940 $opt['id'] = "sv-$name";
943 if ( $text !== null ) {
944 $out .= Html
::rawElement( 'tr', array(),
945 Html
::element( 'th', $opt, $text )
949 $firstHeadingMsg = ( $name === 'credits-skin' )
950 ?
'version-skin-colheader-name'
951 : 'version-ext-colheader-name';
952 $out .= Html
::openElement( 'tr' );
953 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
954 $this->msg( $firstHeadingMsg )->text() );
955 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
956 $this->msg( 'version-ext-colheader-version' )->text() );
957 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
958 $this->msg( 'version-ext-colheader-license' )->text() );
959 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
960 $this->msg( 'version-ext-colheader-description' )->text() );
961 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
962 $this->msg( 'version-ext-colheader-credits' )->text() );
963 $out .= Html
::closeElement( 'tr' );
969 * Get information about client's IP address.
971 * @return string HTML fragment
973 private function IPInfo() {
974 $ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) );
976 return "<!-- visited from $ip -->\n<span style='display:none'>visited from $ip</span>";
980 * Return a formatted unsorted list of authors
983 * If an item in the $authors array is '...' it is assumed to indicate an
984 * 'and others' string which will then be linked to an ((AUTHORS)|(CREDITS))(\.txt)?
985 * file if it exists in $dir.
987 * Similarly an entry ending with ' ...]' is assumed to be a link to an
990 * If no '...' string variant is found, but an authors file is found an
991 * 'and others' will be added to the end of the credits.
993 * @param string|array $authors
994 * @param string|bool $extName Name of the extension for link creation,
995 * false if no links should be created
996 * @param string $extDir Path to the extension root directory
998 * @return string HTML fragment
1000 public function listAuthors( $authors, $extName, $extDir ) {
1004 foreach ( (array)$authors as $item ) {
1005 if ( $item == '...' ) {
1008 if ( $extName && $this->getExtAuthorsFileName( $extDir ) ) {
1009 $text = Linker
::link(
1010 $this->getPageTitle( "Credits/$extName" ),
1011 $this->msg( 'version-poweredby-others' )->escaped()
1014 $text = $this->msg( 'version-poweredby-others' )->escaped();
1017 } elseif ( substr( $item, -5 ) == ' ...]' ) {
1019 $list[] = $this->getOutput()->parseInline(
1020 substr( $item, 0, -4 ) . $this->msg( 'version-poweredby-others' )->text() . "]"
1023 $list[] = $this->getOutput()->parseInline( $item );
1027 if ( $extName && !$hasOthers && $this->getExtAuthorsFileName( $extDir ) ) {
1028 $list[] = $text = Linker
::link(
1029 $this->getPageTitle( "Credits/$extName" ),
1030 $this->msg( 'version-poweredby-others' )->escaped()
1034 return $this->listToText( $list, false );
1038 * Obtains the full path of an extensions authors or credits file if
1041 * @param string $extDir Path to the extensions root directory
1045 * @return bool|string False if no such file exists, otherwise returns
1048 public static function getExtAuthorsFileName( $extDir ) {
1053 foreach ( scandir( $extDir ) as $file ) {
1054 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
1055 if ( preg_match( '/^((AUTHORS)|(CREDITS))(\.txt)?$/', $file ) &&
1056 is_readable( $fullPath ) &&
1057 is_file( $fullPath )
1067 * Obtains the full path of an extensions copying or license file if
1070 * @param string $extDir Path to the extensions root directory
1074 * @return bool|string False if no such file exists, otherwise returns
1077 public static function getExtLicenseFileName( $extDir ) {
1082 foreach ( scandir( $extDir ) as $file ) {
1083 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
1084 if ( preg_match( '/^((COPYING)|(LICENSE))(\.txt)?$/', $file ) &&
1085 is_readable( $fullPath ) &&
1086 is_file( $fullPath )
1096 * Convert an array of items into a list for display.
1098 * @param array $list List of elements to display
1099 * @param bool $sort Whether to sort the items in $list
1103 public function listToText( $list, $sort = true ) {
1104 if ( !count( $list ) ) {
1111 return $this->getLanguage()
1112 ->listToText( array_map( array( __CLASS__
, 'arrayToString' ), $list ) );
1116 * Convert an array or object to a string for display.
1118 * @param mixed $list Will convert an array to string if given and return
1119 * the parameter unaltered otherwise
1123 public static function arrayToString( $list ) {
1124 if ( is_array( $list ) && count( $list ) == 1 ) {
1127 if ( is_object( $list ) ) {
1128 $class = wfMessage( 'parentheses' )->params( get_class( $list ) )->escaped();
1131 } elseif ( !is_array( $list ) ) {
1134 if ( is_object( $list[0] ) ) {
1135 $class = get_class( $list[0] );
1140 return wfMessage( 'parentheses' )->params( "$class, {$list[1]}" )->escaped();
1145 * Get an associative array of information about a given path, from its .svn
1146 * subdirectory. Returns false on error, such as if the directory was not
1147 * checked out with subversion.
1149 * Returned keys are:
1151 * checkout-rev The revision which was checked out
1153 * directory-rev The revision when the directory was last modified
1154 * url The subversion URL of the directory
1155 * repo-url The base URL of the repository
1156 * viewvc-url A ViewVC URL pointing to the checked-out revision
1157 * @param string $dir
1158 * @return array|bool
1160 public static function getSvnInfo( $dir ) {
1161 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
1162 $entries = $dir . '/.svn/entries';
1164 if ( !file_exists( $entries ) ) {
1168 $lines = file( $entries );
1169 if ( !count( $lines ) ) {
1173 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
1174 if ( preg_match( '/^<\?xml/', $lines[0] ) ) {
1175 // subversion is release <= 1.3
1176 if ( !function_exists( 'simplexml_load_file' ) ) {
1177 // We could fall back to expat... YUCK
1181 // SimpleXml whines about the xmlns...
1182 MediaWiki\
suppressWarnings();
1183 $xml = simplexml_load_file( $entries );
1184 MediaWiki\restoreWarnings
();
1187 foreach ( $xml->entry
as $entry ) {
1188 if ( $xml->entry
[0]['name'] == '' ) {
1189 // The directory entry should always have a revision marker.
1190 if ( $entry['revision'] ) {
1191 return array( 'checkout-rev' => intval( $entry['revision'] ) );
1200 // Subversion is release 1.4 or above.
1201 if ( count( $lines ) < 11 ) {
1206 'checkout-rev' => intval( trim( $lines[3] ) ),
1207 'url' => trim( $lines[4] ),
1208 'repo-url' => trim( $lines[5] ),
1209 'directory-rev' => intval( trim( $lines[10] ) )
1212 if ( isset( self
::$viewvcUrls[$info['repo-url']] ) ) {
1213 $viewvc = str_replace(
1215 self
::$viewvcUrls[$info['repo-url']],
1219 $viewvc .= '/?pathrev=';
1220 $viewvc .= urlencode( $info['checkout-rev'] );
1221 $info['viewvc-url'] = $viewvc;
1228 * Retrieve the revision number of a Subversion working directory.
1230 * @param string $dir Directory of the svn checkout
1232 * @return int Revision number
1234 public static function getSvnRevision( $dir ) {
1235 $info = self
::getSvnInfo( $dir );
1237 if ( $info === false ) {
1239 } elseif ( isset( $info['checkout-rev'] ) ) {
1240 return $info['checkout-rev'];
1247 * @param string $dir Directory of the git checkout
1248 * @return bool|string Sha1 of commit HEAD points to
1250 public static function getGitHeadSha1( $dir ) {
1251 $repo = new GitInfo( $dir );
1253 return $repo->getHeadSHA1();
1257 * @param string $dir Directory of the git checkout
1258 * @return bool|string Branch currently checked out
1260 public static function getGitCurrentBranch( $dir ) {
1261 $repo = new GitInfo( $dir );
1262 return $repo->getCurrentBranch();
1266 * Get the list of entry points and their URLs
1267 * @return string Wikitext
1269 public function getEntryPointInfo() {
1270 global $wgArticlePath, $wgScriptPath;
1271 $scriptPath = $wgScriptPath ?
$wgScriptPath : "/";
1272 $entryPoints = array(
1273 'version-entrypoints-articlepath' => $wgArticlePath,
1274 'version-entrypoints-scriptpath' => $scriptPath,
1275 'version-entrypoints-index-php' => wfScript( 'index' ),
1276 'version-entrypoints-api-php' => wfScript( 'api' ),
1277 'version-entrypoints-load-php' => wfScript( 'load' ),
1280 $language = $this->getLanguage();
1281 $thAttribures = array(
1282 'dir' => $language->getDir(),
1283 'lang' => $language->getHtmlCode()
1285 $out = Html
::element(
1287 array( 'id' => 'mw-version-entrypoints' ),
1288 $this->msg( 'version-entrypoints' )->text()
1290 Html
::openElement( 'table',
1292 'class' => 'wikitable plainlinks',
1293 'id' => 'mw-version-entrypoints-table',
1298 Html
::openElement( 'tr' ) .
1302 $this->msg( 'version-entrypoints-header-entrypoint' )->text()
1307 $this->msg( 'version-entrypoints-header-url' )->text()
1309 Html
::closeElement( 'tr' );
1311 foreach ( $entryPoints as $message => $value ) {
1312 $url = wfExpandUrl( $value, PROTO_RELATIVE
);
1313 $out .= Html
::openElement( 'tr' ) .
1314 // ->text() looks like it should be ->parse(), but this function
1315 // returns wikitext, not HTML, boo
1316 Html
::rawElement( 'td', array(), $this->msg( $message )->text() ) .
1317 Html
::rawElement( 'td', array(), Html
::rawElement( 'code', array(), "[$url $value]" ) ) .
1318 Html
::closeElement( 'tr' );
1321 $out .= Html
::closeElement( 'table' );
1326 protected function getGroupName() {