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 // Allow a hook to add/remove items.
219 Hooks
::run( 'SoftwareInfo', array( &$software ) );
223 array( 'id' => 'mw-version-software' ),
224 wfMessage( 'version-software' )->text()
226 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-software' ) ) .
228 <th>" . wfMessage( 'version-software-product' )->text() . "</th>
229 <th>" . wfMessage( 'version-software-version' )->text() . "</th>
232 foreach ( $software as $name => $version ) {
234 <td>" . $name . "</td>
235 <td dir=\"ltr\">" . $version . "</td>
239 return $out . Xml
::closeElement( 'table' );
243 * Return a string of the MediaWiki version with SVN revision if available.
245 * @param string $flags
248 public static function getVersion( $flags = '' ) {
249 global $wgVersion, $IP;
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( $svnInfo['directory-rev'] ) ?
$svnInfo['directory-rev'] : '',
269 isset( $svnInfo['checkout-rev'] ) ?
$svnInfo['checkout-rev'] : ''
277 * Return a wikitext-formatted string of the MediaWiki version with a link to
278 * the SVN revision or the git SHA1 of head if available.
279 * Git is prefered over Svn
280 * The fallback is just $wgVersion
284 public static function getVersionLinked() {
287 $gitVersion = self
::getVersionLinkedGit();
291 $svnVersion = self
::getVersionLinkedSvn();
295 $v = $wgVersion; // fallback
303 * @return string Global wgVersion + a link to subversion revision of svn BASE
305 private static function getVersionLinkedSvn() {
308 $info = self
::getSvnInfo( $IP );
309 if ( !isset( $info['checkout-rev'] ) ) {
313 $linkText = wfMessage(
314 'version-svn-revision',
315 isset( $info['directory-rev'] ) ?
$info['directory-rev'] : '',
316 $info['checkout-rev']
319 if ( isset( $info['viewvc-url'] ) ) {
320 $version = "[{$info['viewvc-url']} $linkText]";
322 $version = $linkText;
325 return self
::getwgVersionLinked() . " $version";
331 private static function getwgVersionLinked() {
334 if ( Hooks
::run( 'SpecialVersionVersionUrl', array( $wgVersion, &$versionUrl ) ) ) {
335 $versionParts = array();
336 preg_match( "/^(\d+\.\d+)/", $wgVersion, $versionParts );
337 $versionUrl = "https://www.mediawiki.org/wiki/MediaWiki_{$versionParts[1]}";
340 return "[$versionUrl $wgVersion]";
344 * @since 1.22 Returns the HEAD date in addition to the sha1 and link
345 * @return bool|string Global wgVersion + HEAD sha1 stripped to the first 7 chars
346 * with link and date, or false on failure
348 private static function getVersionLinkedGit() {
351 $gitInfo = new GitInfo( $IP );
352 $headSHA1 = $gitInfo->getHeadSHA1();
357 $shortSHA1 = '(' . substr( $headSHA1, 0, 7 ) . ')';
359 $gitHeadUrl = $gitInfo->getHeadViewUrl();
360 if ( $gitHeadUrl !== false ) {
361 $shortSHA1 = "[$gitHeadUrl $shortSHA1]";
364 $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
365 if ( $gitHeadCommitDate ) {
366 $shortSHA1 .= Html
::element( 'br' ) . $wgLang->timeanddate( $gitHeadCommitDate, true );
369 return self
::getwgVersionLinked() . " $shortSHA1";
373 * Returns an array with the base extension types.
374 * Type is stored as array key, the message as array value.
376 * TODO: ideally this would return all extension types.
382 public static function getExtensionTypes() {
383 if ( self
::$extensionTypes === false ) {
384 self
::$extensionTypes = array(
385 'specialpage' => wfMessage( 'version-specialpages' )->text(),
386 'parserhook' => wfMessage( 'version-parserhooks' )->text(),
387 'variable' => wfMessage( 'version-variables' )->text(),
388 'media' => wfMessage( 'version-mediahandlers' )->text(),
389 'antispam' => wfMessage( 'version-antispam' )->text(),
390 'skin' => wfMessage( 'version-skins' )->text(),
391 'api' => wfMessage( 'version-api' )->text(),
392 'other' => wfMessage( 'version-other' )->text(),
395 Hooks
::run( 'ExtensionTypes', array( &self
::$extensionTypes ) );
398 return self
::$extensionTypes;
402 * Returns the internationalized name for an extension type.
406 * @param string $type
410 public static function getExtensionTypeName( $type ) {
411 $types = self
::getExtensionTypes();
413 return isset( $types[$type] ) ?
$types[$type] : $types['other'];
417 * Generate wikitext showing the name, URL, author and description of each extension.
419 * @return string Wikitext
421 public function getExtensionCredits() {
422 global $wgExtensionCredits;
425 count( $wgExtensionCredits ) === 0 ||
426 // Skins are displayed separately, see getSkinCredits()
427 ( count( $wgExtensionCredits ) === 1 && isset( $wgExtensionCredits['skin'] ) )
432 $extensionTypes = self
::getExtensionTypes();
436 array( 'id' => 'mw-version-ext' ),
437 $this->msg( 'version-extensions' )->text()
439 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-ext' ) );
441 // Make sure the 'other' type is set to an array.
442 if ( !array_key_exists( 'other', $wgExtensionCredits ) ) {
443 $wgExtensionCredits['other'] = array();
446 // Find all extensions that do not have a valid type and give them the type 'other'.
447 foreach ( $wgExtensionCredits as $type => $extensions ) {
448 if ( !array_key_exists( $type, $extensionTypes ) ) {
449 $wgExtensionCredits['other'] = array_merge( $wgExtensionCredits['other'], $extensions );
453 $this->firstExtOpened
= false;
454 // Loop through the extension categories to display their extensions in the list.
455 foreach ( $extensionTypes as $type => $message ) {
456 // Skins have a separate section
457 if ( $type !== 'other' && $type !== 'skin' ) {
458 $out .= $this->getExtensionCategory( $type, $message );
462 // We want the 'other' type to be last in the list.
463 $out .= $this->getExtensionCategory( 'other', $extensionTypes['other'] );
465 $out .= Xml
::closeElement( 'table' );
471 * Generate wikitext showing the name, URL, author and description of each skin.
473 * @return string Wikitext
475 public function getSkinCredits() {
476 global $wgExtensionCredits;
477 if ( !isset( $wgExtensionCredits['skin'] ) ||
count( $wgExtensionCredits['skin'] ) === 0 ) {
483 array( 'id' => 'mw-version-skin' ),
484 $this->msg( 'version-skins' )->text()
486 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-skin' ) );
488 $this->firstExtOpened
= false;
489 $out .= $this->getExtensionCategory( 'skin', null );
491 $out .= Xml
::closeElement( 'table' );
497 * Generate an HTML table for external libraries that are installed
501 protected function getExternalLibraries() {
503 $path = "$IP/composer.lock";
504 if ( !file_exists( $path ) ) {
505 // Maybe they're using mediawiki/vendor?
506 $path = "$IP/vendor/composer.lock";
507 if ( !file_exists( $path ) ) {
512 $lock = new ComposerLock( $path );
513 $out = Html
::element(
515 array( 'id' => 'mw-version-libraries' ),
516 $this->msg( 'version-libraries' )->text()
518 $out .= Html
::openElement(
520 array( 'class' => 'wikitable plainlinks', 'id' => 'sv-libraries' )
522 $out .= Html
::openElement( 'tr' )
523 . Html
::element( 'th', array(), $this->msg( 'version-libraries-library' )->text() )
524 . Html
::element( 'th', array(), $this->msg( 'version-libraries-version' )->text() )
525 . Html
::element( 'th', array(), $this->msg( 'version-libraries-license' )->text() )
526 . Html
::element( 'th', array(), $this->msg( 'version-libraries-description' )->text() )
527 . Html
::element( 'th', array(), $this->msg( 'version-libraries-authors' )->text() )
528 . Html
::closeElement( 'tr' );
530 foreach ( $lock->getInstalledDependencies() as $name => $info ) {
531 if ( strpos( $info['type'], 'mediawiki-' ) === 0 ) {
532 // Skip any extensions or skins since they'll be listed
533 // in their proper section
536 $authors = array_map( function( $arr ) {
537 // If a homepage is set, link to it
538 if ( isset( $arr['homepage'] ) ) {
539 return "[{$arr['homepage']} {$arr['name']}]";
542 }, $info['authors'] );
543 $authors = $this->listAuthors( $authors, false, "$IP/vendor/$name" );
545 // We can safely assume that the libraries' names and descriptions
546 // are written in English and aren't going to be translated,
547 // so set appropriate lang and dir attributes
548 $out .= Html
::openElement( 'tr' )
552 Linker
::makeExternalLink(
553 "https://packagist.org/packages/$name", $name,
555 array( 'class' => 'mw-version-library-name' )
558 . Html
::element( 'td', array( 'dir' => 'auto' ), $info['version'] )
559 . Html
::element( 'td', array( 'dir' => 'auto' ), $this->listToText( $info['licenses'] ) )
560 . Html
::element( 'td', array( 'lang' => 'en', 'dir' => 'ltr' ), $info['description'] )
561 . Html
::rawElement( 'td', array(), $authors )
562 . Html
::closeElement( 'tr' );
564 $out .= Html
::closeElement( 'table' );
570 * Obtains a list of installed parser tags and the associated H2 header
572 * @return string HTML output
574 protected function getParserTags() {
577 $tags = $wgParser->getTags();
579 if ( count( $tags ) ) {
580 $out = Html
::rawElement(
583 'class' => 'mw-headline plainlinks',
584 'id' => 'mw-version-parser-extensiontags',
586 Linker
::makeExternalLink(
587 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Tag_extensions',
588 $this->msg( 'version-parser-extensiontags' )->parse(),
589 false /* msg()->parse() already escapes */
593 array_walk( $tags, function ( &$value ) {
594 // Bidirectional isolation improves readability in RTL wikis
595 $value = Html
::element(
597 // Prevent < and > from slipping to another line
599 'style' => 'white-space: nowrap;',
605 $out .= $this->listToText( $tags );
614 * Obtains a list of installed parser function hooks and the associated H2 header
616 * @return string HTML output
618 protected function getParserFunctionHooks() {
621 $fhooks = $wgParser->getFunctionHooks();
622 if ( count( $fhooks ) ) {
623 $out = Html
::rawElement(
626 'class' => 'mw-headline plainlinks',
627 'id' => 'mw-version-parser-function-hooks',
629 Linker
::makeExternalLink(
630 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Parser_functions',
631 $this->msg( 'version-parser-function-hooks' )->parse(),
632 false /* msg()->parse() already escapes */
636 $out .= $this->listToText( $fhooks );
645 * Creates and returns the HTML for a single extension category.
649 * @param string $type
650 * @param string $message
654 protected function getExtensionCategory( $type, $message ) {
655 global $wgExtensionCredits;
659 if ( array_key_exists( $type, $wgExtensionCredits ) && count( $wgExtensionCredits[$type] ) > 0 ) {
660 $out .= $this->openExtType( $message, 'credits-' . $type );
662 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
664 foreach ( $wgExtensionCredits[$type] as $extension ) {
665 $out .= $this->getCreditsForExtension( $extension );
673 * Callback to sort extensions by type.
678 public function compare( $a, $b ) {
679 if ( $a['name'] === $b['name'] ) {
682 return $this->getLanguage()->lc( $a['name'] ) > $this->getLanguage()->lc( $b['name'] )
689 * Creates and formats a version line for a single extension.
691 * Information for five columns will be created. Parameters required in the
692 * $extension array for part rendering are indicated in ()
693 * - The name of (name), and URL link to (url), the extension
694 * - Official version number (version) and if available version control system
695 * revision (path), link, and date
696 * - If available the short name of the license (license-name) and a linke
697 * to ((LICENSE)|(COPYING))(\.txt)? if it exists.
698 * - Description of extension (descriptionmsg or description)
699 * - List of authors (author) and link to a ((AUTHORS)|(CREDITS))(\.txt)? file if it exists
701 * @param array $extension
703 * @return string Raw HTML
705 public function getCreditsForExtension( array $extension ) {
706 $out = $this->getOutput();
708 // We must obtain the information for all the bits and pieces!
709 // ... such as extension names and links
710 if ( isset( $extension['namemsg'] ) ) {
711 // Localized name of extension
712 $extensionName = $this->msg( $extension['namemsg'] )->text();
713 } elseif ( isset( $extension['name'] ) ) {
714 // Non localized version
715 $extensionName = $extension['name'];
717 $extensionName = $this->msg( 'version-no-ext-name' )->text();
720 if ( isset( $extension['url'] ) ) {
721 $extensionNameLink = Linker
::makeExternalLink(
726 array( 'class' => 'mw-version-ext-name' )
729 $extensionNameLink = $extensionName;
732 // ... and the version information
733 // If the extension path is set we will check that directory for GIT and SVN
734 // metadata in an attempt to extract date and vcs commit metadata.
735 $canonicalVersion = '–';
736 $extensionPath = null;
741 if ( isset( $extension['version'] ) ) {
742 $canonicalVersion = $out->parseInline( $extension['version'] );
745 if ( isset( $extension['path'] ) ) {
747 $extensionPath = dirname( $extension['path'] );
748 if ( $this->coreId
== '' ) {
749 wfDebug( 'Looking up core head id' );
750 $coreHeadSHA1 = self
::getGitHeadSha1( $IP );
751 if ( $coreHeadSHA1 ) {
752 $this->coreId
= $coreHeadSHA1;
754 $svnInfo = self
::getSvnInfo( $IP );
755 if ( $svnInfo !== false ) {
756 $this->coreId
= $svnInfo['checkout-rev'];
760 $cache = wfGetCache( CACHE_ANYTHING
);
761 $memcKey = wfMemcKey( 'specialversion-ext-version-text', $extension['path'], $this->coreId
);
762 list( $vcsVersion, $vcsLink, $vcsDate ) = $cache->get( $memcKey );
764 if ( !$vcsVersion ) {
765 wfDebug( "Getting VCS info for extension {$extension['name']}" );
766 $gitInfo = new GitInfo( $extensionPath );
767 $vcsVersion = $gitInfo->getHeadSHA1();
768 if ( $vcsVersion !== false ) {
769 $vcsVersion = substr( $vcsVersion, 0, 7 );
770 $vcsLink = $gitInfo->getHeadViewUrl();
771 $vcsDate = $gitInfo->getHeadCommitDate();
773 $svnInfo = self
::getSvnInfo( $extensionPath );
774 if ( $svnInfo !== false ) {
775 $vcsVersion = $this->msg( 'version-svn-revision', $svnInfo['checkout-rev'] )->text();
776 $vcsLink = isset( $svnInfo['viewvc-url'] ) ?
$svnInfo['viewvc-url'] : '';
779 $cache->set( $memcKey, array( $vcsVersion, $vcsLink, $vcsDate ), 60 * 60 * 24 );
781 wfDebug( "Pulled VCS info for extension {$extension['name']} from cache" );
785 $versionString = Html
::rawElement(
787 array( 'class' => 'mw-version-ext-version' ),
793 $vcsVerString = Linker
::makeExternalLink(
795 $this->msg( 'version-version', $vcsVersion ),
798 array( 'class' => 'mw-version-ext-vcs-version' )
801 $vcsVerString = Html
::element( 'span',
802 array( 'class' => 'mw-version-ext-vcs-version' ),
806 $versionString .= " {$vcsVerString}";
809 $vcsTimeString = Html
::element( 'span',
810 array( 'class' => 'mw-version-ext-vcs-timestamp' ),
811 $this->getLanguage()->timeanddate( $vcsDate, true )
813 $versionString .= " {$vcsTimeString}";
815 $versionString = Html
::rawElement( 'span',
816 array( 'class' => 'mw-version-ext-meta-version' ),
821 // ... and license information; if a license file exists we
824 if ( isset( $extension['name'] ) ) {
826 if ( isset( $extension['license-name'] ) ) {
827 $licenseName = $out->parseInline( $extension['license-name'] );
828 } elseif ( $this->getExtLicenseFileName( $extensionPath ) ) {
829 $licenseName = $this->msg( 'version-ext-license' );
831 if ( $licenseName !== null ) {
832 $licenseLink = Linker
::link(
833 $this->getPageTitle( 'License/' . $extension['name'] ),
836 'class' => 'mw-version-ext-license',
843 // ... and generate the description; which can be a parameterized l10n message
844 // in the form array( <msgname>, <parameter>, <parameter>... ) or just a straight
846 if ( isset( $extension['descriptionmsg'] ) ) {
847 // Localized description of extension
848 $descriptionMsg = $extension['descriptionmsg'];
850 if ( is_array( $descriptionMsg ) ) {
851 $descriptionMsgKey = $descriptionMsg[0]; // Get the message key
852 array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
853 array_map( "htmlspecialchars", $descriptionMsg ); // For sanity
854 $description = $this->msg( $descriptionMsgKey, $descriptionMsg )->text();
856 $description = $this->msg( $descriptionMsg )->text();
858 } elseif ( isset( $extension['description'] ) ) {
859 // Non localized version
860 $description = $extension['description'];
864 $description = $out->parseInline( $description );
866 // ... now get the authors for this extension
867 $authors = isset( $extension['author'] ) ?
$extension['author'] : array();
868 $authors = $this->listAuthors( $authors, $extension['name'], $extensionPath );
870 // Finally! Create the table
871 $html = Html
::openElement( 'tr', array(
872 'class' => 'mw-version-ext',
873 'id' => Sanitizer
::escapeId( 'mw-version-ext-' . $extension['name'] )
877 $html .= Html
::rawElement( 'td', array(), $extensionNameLink );
878 $html .= Html
::rawElement( 'td', array(), $versionString );
879 $html .= Html
::rawElement( 'td', array(), $licenseLink );
880 $html .= Html
::rawElement( 'td', array( 'class' => 'mw-version-ext-description' ), $description );
881 $html .= Html
::rawElement( 'td', array( 'class' => 'mw-version-ext-authors' ), $authors );
883 $html .= Html
::closeElement( 'tr' );
889 * Generate wikitext showing hooks in $wgHooks.
891 * @return string Wikitext
893 private function getWgHooks() {
894 global $wgSpecialVersionShowHooks, $wgHooks;
896 if ( $wgSpecialVersionShowHooks && count( $wgHooks ) ) {
897 $myWgHooks = $wgHooks;
901 $ret[] = '== {{int:version-hooks}} ==';
902 $ret[] = Html
::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-hooks' ) );
903 $ret[] = Html
::openElement( 'tr' );
904 $ret[] = Html
::element( 'th', array(), $this->msg( 'version-hook-name' )->text() );
905 $ret[] = Html
::element( 'th', array(), $this->msg( 'version-hook-subscribedby' )->text() );
906 $ret[] = Html
::closeElement( 'tr' );
908 foreach ( $myWgHooks as $hook => $hooks ) {
909 $ret[] = Html
::openElement( 'tr' );
910 $ret[] = Html
::element( 'td', array(), $hook );
911 $ret[] = Html
::element( 'td', array(), $this->listToText( $hooks ) );
912 $ret[] = Html
::closeElement( 'tr' );
915 $ret[] = Html
::closeElement( 'table' );
917 return implode( "\n", $ret );
923 private function openExtType( $text = null, $name = null ) {
926 $opt = array( 'colspan' => 5 );
927 if ( $this->firstExtOpened
) {
928 // Insert a spacing line
929 $out .= Html
::rawElement( 'tr', array( 'class' => 'sv-space' ),
930 Html
::element( 'td', $opt )
933 $this->firstExtOpened
= true;
936 $opt['id'] = "sv-$name";
939 if ( $text !== null ) {
940 $out .= Html
::rawElement( 'tr', array(),
941 Html
::element( 'th', $opt, $text )
945 $firstHeadingMsg = ( $name === 'credits-skin' )
946 ?
'version-skin-colheader-name'
947 : 'version-ext-colheader-name';
948 $out .= Html
::openElement( 'tr' );
949 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
950 $this->msg( $firstHeadingMsg )->text() );
951 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
952 $this->msg( 'version-ext-colheader-version' )->text() );
953 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
954 $this->msg( 'version-ext-colheader-license' )->text() );
955 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
956 $this->msg( 'version-ext-colheader-description' )->text() );
957 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
958 $this->msg( 'version-ext-colheader-credits' )->text() );
959 $out .= Html
::closeElement( 'tr' );
965 * Get information about client's IP address.
967 * @return string HTML fragment
969 private function IPInfo() {
970 $ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) );
972 return "<!-- visited from $ip -->\n<span style='display:none'>visited from $ip</span>";
976 * Return a formatted unsorted list of authors
979 * If an item in the $authors array is '...' it is assumed to indicate an
980 * 'and others' string which will then be linked to an ((AUTHORS)|(CREDITS))(\.txt)?
981 * file if it exists in $dir.
983 * Similarly an entry ending with ' ...]' is assumed to be a link to an
986 * If no '...' string variant is found, but an authors file is found an
987 * 'and others' will be added to the end of the credits.
989 * @param string|array $authors
990 * @param string|bool $extName Name of the extension for link creation,
991 * false if no links should be created
992 * @param string $extDir Path to the extension root directory
994 * @return string HTML fragment
996 public function listAuthors( $authors, $extName, $extDir ) {
1000 foreach ( (array)$authors as $item ) {
1001 if ( $item == '...' ) {
1004 if ( $extName && $this->getExtAuthorsFileName( $extDir ) ) {
1005 $text = Linker
::link(
1006 $this->getPageTitle( "Credits/$extName" ),
1007 $this->msg( 'version-poweredby-others' )->escaped()
1010 $text = $this->msg( 'version-poweredby-others' )->escaped();
1013 } elseif ( substr( $item, -5 ) == ' ...]' ) {
1015 $list[] = $this->getOutput()->parseInline(
1016 substr( $item, 0, -4 ) . $this->msg( 'version-poweredby-others' )->text() . "]"
1019 $list[] = $this->getOutput()->parseInline( $item );
1023 if ( $extName && !$hasOthers && $this->getExtAuthorsFileName( $extDir ) ) {
1024 $list[] = $text = Linker
::link(
1025 $this->getPageTitle( "Credits/$extName" ),
1026 $this->msg( 'version-poweredby-others' )->escaped()
1030 return $this->listToText( $list, false );
1034 * Obtains the full path of an extensions authors or credits file if
1037 * @param string $extDir Path to the extensions root directory
1041 * @return bool|string False if no such file exists, otherwise returns
1044 public static function getExtAuthorsFileName( $extDir ) {
1049 foreach ( scandir( $extDir ) as $file ) {
1050 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
1051 if ( preg_match( '/^((AUTHORS)|(CREDITS))(\.txt)?$/', $file ) &&
1052 is_readable( $fullPath ) &&
1053 is_file( $fullPath )
1063 * Obtains the full path of an extensions copying or license file if
1066 * @param string $extDir Path to the extensions root directory
1070 * @return bool|string False if no such file exists, otherwise returns
1073 public static function getExtLicenseFileName( $extDir ) {
1078 foreach ( scandir( $extDir ) as $file ) {
1079 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
1080 if ( preg_match( '/^((COPYING)|(LICENSE))(\.txt)?$/', $file ) &&
1081 is_readable( $fullPath ) &&
1082 is_file( $fullPath )
1092 * Convert an array of items into a list for display.
1094 * @param array $list List of elements to display
1095 * @param bool $sort Whether to sort the items in $list
1099 public function listToText( $list, $sort = true ) {
1100 if ( !count( $list ) ) {
1107 return $this->getLanguage()
1108 ->listToText( array_map( array( __CLASS__
, 'arrayToString' ), $list ) );
1112 * Convert an array or object to a string for display.
1114 * @param mixed $list Will convert an array to string if given and return
1115 * the parameter unaltered otherwise
1119 public static function arrayToString( $list ) {
1120 if ( is_array( $list ) && count( $list ) == 1 ) {
1123 if ( is_object( $list ) ) {
1124 $class = wfMessage( 'parentheses' )->params( get_class( $list ) )->escaped();
1127 } elseif ( !is_array( $list ) ) {
1130 if ( is_object( $list[0] ) ) {
1131 $class = get_class( $list[0] );
1136 return wfMessage( 'parentheses' )->params( "$class, {$list[1]}" )->escaped();
1141 * Get an associative array of information about a given path, from its .svn
1142 * subdirectory. Returns false on error, such as if the directory was not
1143 * checked out with subversion.
1145 * Returned keys are:
1147 * checkout-rev The revision which was checked out
1149 * directory-rev The revision when the directory was last modified
1150 * url The subversion URL of the directory
1151 * repo-url The base URL of the repository
1152 * viewvc-url A ViewVC URL pointing to the checked-out revision
1153 * @param string $dir
1154 * @return array|bool
1156 public static function getSvnInfo( $dir ) {
1157 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
1158 $entries = $dir . '/.svn/entries';
1160 if ( !file_exists( $entries ) ) {
1164 $lines = file( $entries );
1165 if ( !count( $lines ) ) {
1169 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
1170 if ( preg_match( '/^<\?xml/', $lines[0] ) ) {
1171 // subversion is release <= 1.3
1172 if ( !function_exists( 'simplexml_load_file' ) ) {
1173 // We could fall back to expat... YUCK
1177 // SimpleXml whines about the xmlns...
1178 MediaWiki\
suppressWarnings();
1179 $xml = simplexml_load_file( $entries );
1180 MediaWiki\restoreWarnings
();
1183 foreach ( $xml->entry
as $entry ) {
1184 if ( $xml->entry
[0]['name'] == '' ) {
1185 // The directory entry should always have a revision marker.
1186 if ( $entry['revision'] ) {
1187 return array( 'checkout-rev' => intval( $entry['revision'] ) );
1196 // Subversion is release 1.4 or above.
1197 if ( count( $lines ) < 11 ) {
1202 'checkout-rev' => intval( trim( $lines[3] ) ),
1203 'url' => trim( $lines[4] ),
1204 'repo-url' => trim( $lines[5] ),
1205 'directory-rev' => intval( trim( $lines[10] ) )
1208 if ( isset( self
::$viewvcUrls[$info['repo-url']] ) ) {
1209 $viewvc = str_replace(
1211 self
::$viewvcUrls[$info['repo-url']],
1215 $viewvc .= '/?pathrev=';
1216 $viewvc .= urlencode( $info['checkout-rev'] );
1217 $info['viewvc-url'] = $viewvc;
1224 * Retrieve the revision number of a Subversion working directory.
1226 * @param string $dir Directory of the svn checkout
1228 * @return int Revision number
1230 public static function getSvnRevision( $dir ) {
1231 $info = self
::getSvnInfo( $dir );
1233 if ( $info === false ) {
1235 } elseif ( isset( $info['checkout-rev'] ) ) {
1236 return $info['checkout-rev'];
1243 * @param string $dir Directory of the git checkout
1244 * @return bool|string Sha1 of commit HEAD points to
1246 public static function getGitHeadSha1( $dir ) {
1247 $repo = new GitInfo( $dir );
1249 return $repo->getHeadSHA1();
1253 * @param string $dir Directory of the git checkout
1254 * @return bool|string Branch currently checked out
1256 public static function getGitCurrentBranch( $dir ) {
1257 $repo = new GitInfo( $dir );
1258 return $repo->getCurrentBranch();
1262 * Get the list of entry points and their URLs
1263 * @return string Wikitext
1265 public function getEntryPointInfo() {
1266 global $wgArticlePath, $wgScriptPath;
1267 $scriptPath = $wgScriptPath ?
$wgScriptPath : "/";
1268 $entryPoints = array(
1269 'version-entrypoints-articlepath' => $wgArticlePath,
1270 'version-entrypoints-scriptpath' => $scriptPath,
1271 'version-entrypoints-index-php' => wfScript( 'index' ),
1272 'version-entrypoints-api-php' => wfScript( 'api' ),
1273 'version-entrypoints-load-php' => wfScript( 'load' ),
1276 $language = $this->getLanguage();
1277 $thAttribures = array(
1278 'dir' => $language->getDir(),
1279 'lang' => $language->getHtmlCode()
1281 $out = Html
::element(
1283 array( 'id' => 'mw-version-entrypoints' ),
1284 $this->msg( 'version-entrypoints' )->text()
1286 Html
::openElement( 'table',
1288 'class' => 'wikitable plainlinks',
1289 'id' => 'mw-version-entrypoints-table',
1294 Html
::openElement( 'tr' ) .
1298 $this->msg( 'version-entrypoints-header-entrypoint' )->text()
1303 $this->msg( 'version-entrypoints-header-url' )->text()
1305 Html
::closeElement( 'tr' );
1307 foreach ( $entryPoints as $message => $value ) {
1308 $url = wfExpandUrl( $value, PROTO_RELATIVE
);
1309 $out .= Html
::openElement( 'tr' ) .
1310 // ->text() looks like it should be ->parse(), but this function
1311 // returns wikitext, not HTML, boo
1312 Html
::rawElement( 'td', array(), $this->msg( $message )->text() ) .
1313 Html
::rawElement( 'td', array(), Html
::rawElement( 'code', array(), "[$url $value]" ) ) .
1314 Html
::closeElement( 'tr' );
1317 $out .= Html
::closeElement( 'table' );
1322 protected function getGroupName() {