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 if ( !isset( $extNode['license-name'] ) ) {
113 // If the developer did not explicitly set license-name they probably
114 // are unaware that we're now sucking this file in and thus it's probably
115 // not wikitext friendly.
116 $wikiText = "<pre>$wikiText</pre>";
121 $out->setPageTitle( $this->msg( 'version-license-title', $extName ) );
122 $out->addWikiText( $wikiText );
126 $out->addModules( 'mediawiki.special.version' );
128 $this->getMediaWikiCredits() .
129 $this->softwareInformation() .
130 $this->getEntryPointInfo()
133 $this->getSkinCredits() .
134 $this->getExtensionCredits() .
135 $this->getExternalLibraries() .
136 $this->getParserTags() .
137 $this->getParserFunctionHooks()
139 $out->addWikiText( $this->getWgHooks() );
140 $out->addHTML( $this->IPInfo() );
147 * Returns wiki text showing the license information.
151 private static function getMediaWikiCredits() {
154 array( 'id' => 'mw-version-license' ),
155 wfMessage( 'version-license' )->text()
158 // This text is always left-to-right.
159 $ret .= '<div class="plainlinks">';
161 " . self
::getCopyrightAndAuthorList() . "\n
162 " . wfMessage( 'version-license-info' )->text();
165 return str_replace( "\t\t", '', $ret ) . "\n";
169 * Get the "MediaWiki is copyright 2001-20xx by lots of cool guys" text
173 public static function getCopyrightAndAuthorList() {
176 if ( defined( 'MEDIAWIKI_INSTALL' ) ) {
177 $othersLink = '[//www.mediawiki.org/wiki/Special:Version/Credits ' .
178 wfMessage( 'version-poweredby-others' )->text() . ']';
180 $othersLink = '[[Special:Version/Credits|' .
181 wfMessage( 'version-poweredby-others' )->text() . ']]';
184 $translatorsLink = '[//translatewiki.net/wiki/Translating:MediaWiki/Credits ' .
185 wfMessage( 'version-poweredby-translators' )->text() . ']';
188 'Magnus Manske', 'Brion Vibber', 'Lee Daniel Crocker',
189 'Tim Starling', 'Erik Möller', 'Gabriel Wicke', 'Ævar Arnfjörð Bjarmason',
190 'Niklas Laxström', 'Domas Mituzas', 'Rob Church', 'Yuri Astrakhan',
191 'Aryeh Gregor', 'Aaron Schulz', 'Andrew Garrett', 'Raimond Spekking',
192 'Alexandre Emsenhuber', 'Siebrand Mazeland', 'Chad Horohoe',
193 'Roan Kattouw', 'Trevor Parscal', 'Bryan Tong Minh', 'Sam Reed',
194 'Victor Vasiliev', 'Rotem Liss', 'Platonides', 'Antoine Musso',
195 'Timo Tijhof', 'Daniel Kinzler', 'Jeroen De Dauw', 'Brad Jorsch',
196 $othersLink, $translatorsLink
199 return wfMessage( 'version-poweredby-credits', MWTimestamp
::getLocalInstance()->format( 'Y' ),
200 $wgLang->listToText( $authorList ) )->text();
204 * Returns wiki text showing the third party software versions (apache, php, mysql).
208 public static function softwareInformation() {
209 $dbr = wfGetDB( DB_SLAVE
);
211 // Put the software in an array of form 'name' => 'version'. All messages should
212 // be loaded here, so feel free to use wfMessage in the 'name'. Raw HTML or
213 // wikimarkup can be used.
215 $software['[https://www.mediawiki.org/ MediaWiki]'] = self
::getVersionLinked();
217 $software['[http://hhvm.com/ HHVM]'] = HHVM_VERSION
. " (" . PHP_SAPI
. ")";
219 $software['[https://php.net/ PHP]'] = PHP_VERSION
. " (" . PHP_SAPI
. ")";
221 $software[$dbr->getSoftwareLink()] = $dbr->getServerInfo();
223 // Allow a hook to add/remove items.
224 Hooks
::run( 'SoftwareInfo', array( &$software ) );
228 array( 'id' => 'mw-version-software' ),
229 wfMessage( 'version-software' )->text()
231 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-software' ) ) .
233 <th>" . wfMessage( 'version-software-product' )->text() . "</th>
234 <th>" . wfMessage( 'version-software-version' )->text() . "</th>
237 foreach ( $software as $name => $version ) {
239 <td>" . $name . "</td>
240 <td dir=\"ltr\">" . $version . "</td>
244 return $out . Xml
::closeElement( 'table' );
248 * Return a string of the MediaWiki version with SVN revision if available.
250 * @param string $flags
253 public static function getVersion( $flags = '' ) {
254 global $wgVersion, $IP;
255 wfProfileIn( __METHOD__
);
257 $gitInfo = self
::getGitHeadSha1( $IP );
258 $svnInfo = self
::getSvnInfo( $IP );
259 if ( !$svnInfo && !$gitInfo ) {
260 $version = $wgVersion;
261 } elseif ( $gitInfo && $flags === 'nodb' ) {
262 $shortSha1 = substr( $gitInfo, 0, 7 );
263 $version = "$wgVersion ($shortSha1)";
264 } elseif ( $gitInfo ) {
265 $shortSha1 = substr( $gitInfo, 0, 7 );
266 $shortSha1 = wfMessage( 'parentheses' )->params( $shortSha1 )->escaped();
267 $version = "$wgVersion $shortSha1";
268 } elseif ( $flags === 'nodb' ) {
269 $version = "$wgVersion (r{$svnInfo['checkout-rev']})";
271 $version = $wgVersion . ' ' .
273 'version-svn-revision',
274 isset( $info['directory-rev'] ) ?
$info['directory-rev'] : '',
275 $info['checkout-rev']
279 wfProfileOut( __METHOD__
);
285 * Return a wikitext-formatted string of the MediaWiki version with a link to
286 * the SVN revision or the git SHA1 of head if available.
287 * Git is prefered over Svn
288 * The fallback is just $wgVersion
292 public static function getVersionLinked() {
294 wfProfileIn( __METHOD__
);
296 $gitVersion = self
::getVersionLinkedGit();
300 $svnVersion = self
::getVersionLinkedSvn();
304 $v = $wgVersion; // fallback
308 wfProfileOut( __METHOD__
);
314 * @return string Global wgVersion + a link to subversion revision of svn BASE
316 private static function getVersionLinkedSvn() {
319 $info = self
::getSvnInfo( $IP );
320 if ( !isset( $info['checkout-rev'] ) ) {
324 $linkText = wfMessage(
325 'version-svn-revision',
326 isset( $info['directory-rev'] ) ?
$info['directory-rev'] : '',
327 $info['checkout-rev']
330 if ( isset( $info['viewvc-url'] ) ) {
331 $version = "[{$info['viewvc-url']} $linkText]";
333 $version = $linkText;
336 return self
::getwgVersionLinked() . " $version";
342 private static function getwgVersionLinked() {
345 if ( Hooks
::run( 'SpecialVersionVersionUrl', array( $wgVersion, &$versionUrl ) ) ) {
346 $versionParts = array();
347 preg_match( "/^(\d+\.\d+)/", $wgVersion, $versionParts );
348 $versionUrl = "https://www.mediawiki.org/wiki/MediaWiki_{$versionParts[1]}";
351 return "[$versionUrl $wgVersion]";
355 * @since 1.22 Returns the HEAD date in addition to the sha1 and link
356 * @return bool|string Global wgVersion + HEAD sha1 stripped to the first 7 chars
357 * with link and date, or false on failure
359 private static function getVersionLinkedGit() {
362 $gitInfo = new GitInfo( $IP );
363 $headSHA1 = $gitInfo->getHeadSHA1();
368 $shortSHA1 = '(' . substr( $headSHA1, 0, 7 ) . ')';
370 $gitHeadUrl = $gitInfo->getHeadViewUrl();
371 if ( $gitHeadUrl !== false ) {
372 $shortSHA1 = "[$gitHeadUrl $shortSHA1]";
375 $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
376 if ( $gitHeadCommitDate ) {
377 $shortSHA1 .= Html
::element( 'br' ) . $wgLang->timeanddate( $gitHeadCommitDate, true );
380 return self
::getwgVersionLinked() . " $shortSHA1";
384 * Returns an array with the base extension types.
385 * Type is stored as array key, the message as array value.
387 * TODO: ideally this would return all extension types.
393 public static function getExtensionTypes() {
394 if ( self
::$extensionTypes === false ) {
395 self
::$extensionTypes = array(
396 'specialpage' => wfMessage( 'version-specialpages' )->text(),
397 'parserhook' => wfMessage( 'version-parserhooks' )->text(),
398 'variable' => wfMessage( 'version-variables' )->text(),
399 'media' => wfMessage( 'version-mediahandlers' )->text(),
400 'antispam' => wfMessage( 'version-antispam' )->text(),
401 'skin' => wfMessage( 'version-skins' )->text(),
402 'api' => wfMessage( 'version-api' )->text(),
403 'other' => wfMessage( 'version-other' )->text(),
406 Hooks
::run( 'ExtensionTypes', array( &self
::$extensionTypes ) );
409 return self
::$extensionTypes;
413 * Returns the internationalized name for an extension type.
417 * @param string $type
421 public static function getExtensionTypeName( $type ) {
422 $types = self
::getExtensionTypes();
424 return isset( $types[$type] ) ?
$types[$type] : $types['other'];
428 * Generate wikitext showing the name, URL, author and description of each extension.
430 * @return string Wikitext
432 public function getExtensionCredits() {
433 global $wgExtensionCredits;
436 count( $wgExtensionCredits ) === 0 ||
437 // Skins are displayed separately, see getSkinCredits()
438 ( count( $wgExtensionCredits ) === 1 && isset( $wgExtensionCredits['skin'] ) )
443 $extensionTypes = self
::getExtensionTypes();
447 array( 'id' => 'mw-version-ext' ),
448 $this->msg( 'version-extensions' )->text()
450 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-ext' ) );
452 // Make sure the 'other' type is set to an array.
453 if ( !array_key_exists( 'other', $wgExtensionCredits ) ) {
454 $wgExtensionCredits['other'] = array();
457 // Find all extensions that do not have a valid type and give them the type 'other'.
458 foreach ( $wgExtensionCredits as $type => $extensions ) {
459 if ( !array_key_exists( $type, $extensionTypes ) ) {
460 $wgExtensionCredits['other'] = array_merge( $wgExtensionCredits['other'], $extensions );
464 $this->firstExtOpened
= false;
465 // Loop through the extension categories to display their extensions in the list.
466 foreach ( $extensionTypes as $type => $message ) {
467 // Skins have a separate section
468 if ( $type !== 'other' && $type !== 'skin' ) {
469 $out .= $this->getExtensionCategory( $type, $message );
473 // We want the 'other' type to be last in the list.
474 $out .= $this->getExtensionCategory( 'other', $extensionTypes['other'] );
476 $out .= Xml
::closeElement( 'table' );
482 * Generate wikitext showing the name, URL, author and description of each skin.
484 * @return string Wikitext
486 public function getSkinCredits() {
487 global $wgExtensionCredits;
488 if ( !isset( $wgExtensionCredits['skin'] ) ||
count( $wgExtensionCredits['skin'] ) === 0 ) {
494 array( 'id' => 'mw-version-skin' ),
495 $this->msg( 'version-skins' )->text()
497 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-skin' ) );
499 $this->firstExtOpened
= false;
500 $out .= $this->getExtensionCategory( 'skin', null );
502 $out .= Xml
::closeElement( 'table' );
508 * Generate an HTML table for external libraries that are installed
512 protected function getExternalLibraries() {
514 $path = "$IP/composer.lock";
515 if ( !file_exists( $path ) ) {
516 // Maybe they're using mediawiki/vendor?
517 $path = "$IP/vendor/composer.lock";
518 if ( !file_exists( $path ) ) {
523 $lock = new ComposerLock( $path );
524 $out = Html
::element(
526 array( 'id' => 'mw-version-libraries' ),
527 $this->msg( 'version-libraries' )->text()
529 $out .= Html
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-libraries' ) );
530 $out .= Html
::openElement( 'tr' )
531 . Html
::element( 'th', array(), $this->msg( 'version-libraries-library' )->text() )
532 . Html
::element( 'th', array(), $this->msg( 'version-libraries-version' )->text() )
533 . Html
::closeElement( 'tr' );
535 foreach ( $lock->getInstalledDependencies() as $name => $version ) {
536 $out .= Html
::openElement( 'tr' )
537 . Html
::rawElement( 'td', array(), Linker
::makeExternalLink( "https://packagist.org/packages/$name", $name ) )
538 . Html
::element( 'td', array(), $version )
539 . Html
::closeElement( 'tr' );
541 $out .= Html
::closeElement( 'table' );
547 * Obtains a list of installed parser tags and the associated H2 header
549 * @return string HTML output
551 protected function getParserTags() {
554 $tags = $wgParser->getTags();
556 if ( count( $tags ) ) {
557 $out = Html
::rawElement(
559 array( 'class' => 'mw-headline' ),
560 Linker
::makeExternalLink(
561 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Tag_extensions',
562 $this->msg( 'version-parser-extensiontags' )->parse(),
563 false /* msg()->parse() already escapes */
567 array_walk( $tags, function ( &$value ) {
568 // Bidirectional isolation improves readability in RTL wikis
569 $value = Html
::element(
571 // Prevent < and > from slipping to another line
573 'style' => 'white-space: nowrap;',
579 $out .= $this->listToText( $tags );
588 * Obtains a list of installed parser function hooks and the associated H2 header
590 * @return string HTML output
592 protected function getParserFunctionHooks() {
595 $fhooks = $wgParser->getFunctionHooks();
596 if ( count( $fhooks ) ) {
597 $out = Html
::rawElement( 'h2', array( 'class' => 'mw-headline' ), Linker
::makeExternalLink(
598 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Parser_functions',
599 $this->msg( 'version-parser-function-hooks' )->parse(),
600 false /* msg()->parse() already escapes */
603 $out .= $this->listToText( $fhooks );
612 * Creates and returns the HTML for a single extension category.
616 * @param string $type
617 * @param string $message
621 protected function getExtensionCategory( $type, $message ) {
622 global $wgExtensionCredits;
626 if ( array_key_exists( $type, $wgExtensionCredits ) && count( $wgExtensionCredits[$type] ) > 0 ) {
627 $out .= $this->openExtType( $message, 'credits-' . $type );
629 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
631 foreach ( $wgExtensionCredits[$type] as $extension ) {
632 $out .= $this->getCreditsForExtension( $extension );
640 * Callback to sort extensions by type.
645 public function compare( $a, $b ) {
646 if ( $a['name'] === $b['name'] ) {
649 return $this->getLanguage()->lc( $a['name'] ) > $this->getLanguage()->lc( $b['name'] )
656 * Creates and formats a version line for a single extension.
658 * Information for five columns will be created. Parameters required in the
659 * $extension array for part rendering are indicated in ()
660 * - The name of (name), and URL link to (url), the extension
661 * - Official version number (version) and if available version control system
662 * revision (path), link, and date
663 * - If available the short name of the license (license-name) and a linke
664 * to ((LICENSE)|(COPYING))(\.txt)? if it exists.
665 * - Description of extension (descriptionmsg or description)
666 * - List of authors (author) and link to a ((AUTHORS)|(CREDITS))(\.txt)? file if it exists
668 * @param array $extension
670 * @return string Raw HTML
672 public function getCreditsForExtension( array $extension ) {
673 $out = $this->getOutput();
675 // We must obtain the information for all the bits and pieces!
676 // ... such as extension names and links
677 if ( isset( $extension['namemsg'] ) ) {
678 // Localized name of extension
679 $extensionName = $this->msg( $extension['namemsg'] )->text();
680 } elseif ( isset( $extension['name'] ) ) {
681 // Non localized version
682 $extensionName = $extension['name'];
684 $extensionName = $this->msg( 'version-no-ext-name' )->text();
687 if ( isset( $extension['url'] ) ) {
688 $extensionNameLink = Linker
::makeExternalLink(
693 array( 'class' => 'mw-version-ext-name' )
696 $extensionNameLink = $extensionName;
699 // ... and the version information
700 // If the extension path is set we will check that directory for GIT and SVN
701 // metadata in an attempt to extract date and vcs commit metadata.
702 $canonicalVersion = '–';
703 $extensionPath = null;
708 if ( isset( $extension['version'] ) ) {
709 $canonicalVersion = $out->parseInline( $extension['version'] );
712 if ( isset( $extension['path'] ) ) {
714 $extensionPath = dirname( $extension['path'] );
715 if ( $this->coreId
== '' ) {
716 wfDebug( 'Looking up core head id' );
717 $coreHeadSHA1 = self
::getGitHeadSha1( $IP );
718 if ( $coreHeadSHA1 ) {
719 $this->coreId
= $coreHeadSHA1;
721 $svnInfo = self
::getSvnInfo( $IP );
722 if ( $svnInfo !== false ) {
723 $this->coreId
= $svnInfo['checkout-rev'];
727 $cache = wfGetCache( CACHE_ANYTHING
);
728 $memcKey = wfMemcKey( 'specialversion-ext-version-text', $extension['path'], $this->coreId
);
729 list( $vcsVersion, $vcsLink, $vcsDate ) = $cache->get( $memcKey );
731 if ( !$vcsVersion ) {
732 wfDebug( "Getting VCS info for extension $extensionName" );
733 $gitInfo = new GitInfo( $extensionPath );
734 $vcsVersion = $gitInfo->getHeadSHA1();
735 if ( $vcsVersion !== false ) {
736 $vcsVersion = substr( $vcsVersion, 0, 7 );
737 $vcsLink = $gitInfo->getHeadViewUrl();
738 $vcsDate = $gitInfo->getHeadCommitDate();
740 $svnInfo = self
::getSvnInfo( $extensionPath );
741 if ( $svnInfo !== false ) {
742 $vcsVersion = $this->msg( 'version-svn-revision', $svnInfo['checkout-rev'] )->text();
743 $vcsLink = isset( $svnInfo['viewvc-url'] ) ?
$svnInfo['viewvc-url'] : '';
746 $cache->set( $memcKey, array( $vcsVersion, $vcsLink, $vcsDate ), 60 * 60 * 24 );
748 wfDebug( "Pulled VCS info for extension $extensionName from cache" );
752 $versionString = Html
::rawElement(
754 array( 'class' => 'mw-version-ext-version' ),
760 $vcsVerString = Linker
::makeExternalLink(
762 $this->msg( 'version-version', $vcsVersion ),
765 array( 'class' => 'mw-version-ext-vcs-version' )
768 $vcsVerString = Html
::element( 'span',
769 array( 'class' => 'mw-version-ext-vcs-version' ),
773 $versionString .= " {$vcsVerString}";
776 $vcsTimeString = Html
::element( 'span',
777 array( 'class' => 'mw-version-ext-vcs-timestamp' ),
778 $this->getLanguage()->timeanddate( $vcsDate, true )
780 $versionString .= " {$vcsTimeString}";
782 $versionString = Html
::rawElement( 'span',
783 array( 'class' => 'mw-version-ext-meta-version' ),
788 // ... and license information; if a license file exists we
791 if ( isset( $extension['name'] ) ) {
793 if ( isset( $extension['license-name'] ) ) {
794 $licenseName = $out->parseInline( $extension['license-name'] );
795 } elseif ( $this->getExtLicenseFileName( $extensionPath ) ) {
796 $licenseName = $this->msg( 'version-ext-license' );
798 if ( $licenseName !== null ) {
799 $licenseLink = Linker
::link(
800 $this->getPageTitle( 'License/' . $extension['name'] ),
803 'class' => 'mw-version-ext-license',
810 // ... and generate the description; which can be a parameterized l10n message
811 // in the form array( <msgname>, <parameter>, <parameter>... ) or just a straight
813 if ( isset( $extension['descriptionmsg'] ) ) {
814 // Localized description of extension
815 $descriptionMsg = $extension['descriptionmsg'];
817 if ( is_array( $descriptionMsg ) ) {
818 $descriptionMsgKey = $descriptionMsg[0]; // Get the message key
819 array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
820 array_map( "htmlspecialchars", $descriptionMsg ); // For sanity
821 $description = $this->msg( $descriptionMsgKey, $descriptionMsg )->text();
823 $description = $this->msg( $descriptionMsg )->text();
825 } elseif ( isset( $extension['description'] ) ) {
826 // Non localized version
827 $description = $extension['description'];
831 $description = $out->parseInline( $description );
833 // ... now get the authors for this extension
834 $authors = isset( $extension['author'] ) ?
$extension['author'] : array();
835 $authors = $this->listAuthors( $authors, $extensionName, $extensionPath );
837 // Finally! Create the table
838 $html = Html
::openElement( 'tr', array(
839 'class' => 'mw-version-ext',
840 'id' => "mw-version-ext-{$extensionName}"
844 $html .= Html
::rawElement( 'td', array(), $extensionNameLink );
845 $html .= Html
::rawElement( 'td', array(), $versionString );
846 $html .= Html
::rawElement( 'td', array(), $licenseLink );
847 $html .= Html
::rawElement( 'td', array( 'class' => 'mw-version-ext-description' ), $description );
848 $html .= Html
::rawElement( 'td', array( 'class' => 'mw-version-ext-authors' ), $authors );
850 $html .= Html
::closeElement( 'tr' );
856 * Generate wikitext showing hooks in $wgHooks.
858 * @return string Wikitext
860 private function getWgHooks() {
861 global $wgSpecialVersionShowHooks, $wgHooks;
863 if ( $wgSpecialVersionShowHooks && count( $wgHooks ) ) {
864 $myWgHooks = $wgHooks;
868 $ret[] = '== {{int:version-hooks}} ==';
869 $ret[] = Html
::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-hooks' ) );
870 $ret[] = Html
::openElement( 'tr' );
871 $ret[] = Html
::element( 'th', array(), $this->msg( 'version-hook-name' )->text() );
872 $ret[] = Html
::element( 'th', array(), $this->msg( 'version-hook-subscribedby' )->text() );
873 $ret[] = Html
::closeElement( 'tr' );
875 foreach ( $myWgHooks as $hook => $hooks ) {
876 $ret[] = Html
::openElement( 'tr' );
877 $ret[] = Html
::element( 'td', array(), $hook );
878 $ret[] = Html
::element( 'td', array(), $this->listToText( $hooks ) );
879 $ret[] = Html
::closeElement( 'tr' );
882 $ret[] = Html
::closeElement( 'table' );
884 return implode( "\n", $ret );
890 private function openExtType( $text = null, $name = null ) {
893 $opt = array( 'colspan' => 5 );
894 if ( $this->firstExtOpened
) {
895 // Insert a spacing line
896 $out .= Html
::rawElement( 'tr', array( 'class' => 'sv-space' ),
897 Html
::element( 'td', $opt )
900 $this->firstExtOpened
= true;
903 $opt['id'] = "sv-$name";
906 if ( $text !== null ) {
907 $out .= Html
::rawElement( 'tr', array(),
908 Html
::element( 'th', $opt, $text )
912 $firstHeadingMsg = ( $name === 'credits-skin' )
913 ?
'version-skin-colheader-name'
914 : 'version-ext-colheader-name';
915 $out .= Html
::openElement( 'tr' );
916 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
917 $this->msg( $firstHeadingMsg )->text() );
918 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
919 $this->msg( 'version-ext-colheader-version' )->text() );
920 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
921 $this->msg( 'version-ext-colheader-license' )->text() );
922 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
923 $this->msg( 'version-ext-colheader-description' )->text() );
924 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
925 $this->msg( 'version-ext-colheader-credits' )->text() );
926 $out .= Html
::closeElement( 'tr' );
932 * Get information about client's IP address.
934 * @return string HTML fragment
936 private function IPInfo() {
937 $ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) );
939 return "<!-- visited from $ip -->\n<span style='display:none'>visited from $ip</span>";
943 * Return a formatted unsorted list of authors
946 * If an item in the $authors array is '...' it is assumed to indicate an
947 * 'and others' string which will then be linked to an ((AUTHORS)|(CREDITS))(\.txt)?
948 * file if it exists in $dir.
950 * Similarly an entry ending with ' ...]' is assumed to be a link to an
953 * If no '...' string variant is found, but an authors file is found an
954 * 'and others' will be added to the end of the credits.
956 * @param string|array $authors
957 * @param string $extName Name of the extension for link creation
958 * @param string $extDir Path to the extension root directory
960 * @return string HTML fragment
962 public function listAuthors( $authors, $extName, $extDir ) {
966 foreach ( (array)$authors as $item ) {
967 if ( $item == '...' ) {
970 if ( $this->getExtAuthorsFileName( $extDir ) ) {
971 $text = Linker
::link(
972 $this->getPageTitle( "Credits/$extName" ),
973 $this->msg( 'version-poweredby-others' )->text()
976 $text = $this->msg( 'version-poweredby-others' )->text();
979 } elseif ( substr( $item, -5 ) == ' ...]' ) {
981 $list[] = $this->getOutput()->parseInline(
982 substr( $item, 0, -4 ) . $this->msg( 'version-poweredby-others' )->text() . "]"
985 $list[] = $this->getOutput()->parseInline( $item );
989 if ( !$hasOthers && $this->getExtAuthorsFileName( $extDir ) ) {
990 $list[] = $text = Linker
::link(
991 $this->getPageTitle( "Credits/$extName" ),
992 $this->msg( 'version-poweredby-others' )->text()
996 return $this->listToText( $list, false );
1000 * Obtains the full path of an extensions authors or credits file if
1003 * @param string $extDir Path to the extensions root directory
1007 * @return bool|string False if no such file exists, otherwise returns
1010 public static function getExtAuthorsFileName( $extDir ) {
1015 foreach ( scandir( $extDir ) as $file ) {
1016 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
1017 if ( preg_match( '/^((AUTHORS)|(CREDITS))(\.txt)?$/', $file ) &&
1018 is_readable( $fullPath ) &&
1019 is_file( $fullPath )
1029 * Obtains the full path of an extensions copying or license file if
1032 * @param string $extDir Path to the extensions root directory
1036 * @return bool|string False if no such file exists, otherwise returns
1039 public static function getExtLicenseFileName( $extDir ) {
1044 foreach ( scandir( $extDir ) as $file ) {
1045 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
1046 if ( preg_match( '/^((COPYING)|(LICENSE))(\.txt)?$/', $file ) &&
1047 is_readable( $fullPath ) &&
1048 is_file( $fullPath )
1058 * Convert an array of items into a list for display.
1060 * @param array $list List of elements to display
1061 * @param bool $sort Whether to sort the items in $list
1065 public function listToText( $list, $sort = true ) {
1066 if ( !count( $list ) ) {
1073 return $this->getLanguage()
1074 ->listToText( array_map( array( __CLASS__
, 'arrayToString' ), $list ) );
1078 * Convert an array or object to a string for display.
1080 * @param mixed $list Will convert an array to string if given and return
1081 * the parameter unaltered otherwise
1085 public static function arrayToString( $list ) {
1086 if ( is_array( $list ) && count( $list ) == 1 ) {
1089 if ( is_object( $list ) ) {
1090 $class = wfMessage( 'parentheses' )->params( get_class( $list ) )->escaped();
1093 } elseif ( !is_array( $list ) ) {
1096 if ( is_object( $list[0] ) ) {
1097 $class = get_class( $list[0] );
1102 return wfMessage( 'parentheses' )->params( "$class, {$list[1]}" )->escaped();
1107 * Get an associative array of information about a given path, from its .svn
1108 * subdirectory. Returns false on error, such as if the directory was not
1109 * checked out with subversion.
1111 * Returned keys are:
1113 * checkout-rev The revision which was checked out
1115 * directory-rev The revision when the directory was last modified
1116 * url The subversion URL of the directory
1117 * repo-url The base URL of the repository
1118 * viewvc-url A ViewVC URL pointing to the checked-out revision
1119 * @param string $dir
1120 * @return array|bool
1122 public static function getSvnInfo( $dir ) {
1123 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
1124 $entries = $dir . '/.svn/entries';
1126 if ( !file_exists( $entries ) ) {
1130 $lines = file( $entries );
1131 if ( !count( $lines ) ) {
1135 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
1136 if ( preg_match( '/^<\?xml/', $lines[0] ) ) {
1137 // subversion is release <= 1.3
1138 if ( !function_exists( 'simplexml_load_file' ) ) {
1139 // We could fall back to expat... YUCK
1143 // SimpleXml whines about the xmlns...
1144 wfSuppressWarnings();
1145 $xml = simplexml_load_file( $entries );
1146 wfRestoreWarnings();
1149 foreach ( $xml->entry
as $entry ) {
1150 if ( $xml->entry
[0]['name'] == '' ) {
1151 // The directory entry should always have a revision marker.
1152 if ( $entry['revision'] ) {
1153 return array( 'checkout-rev' => intval( $entry['revision'] ) );
1162 // Subversion is release 1.4 or above.
1163 if ( count( $lines ) < 11 ) {
1168 'checkout-rev' => intval( trim( $lines[3] ) ),
1169 'url' => trim( $lines[4] ),
1170 'repo-url' => trim( $lines[5] ),
1171 'directory-rev' => intval( trim( $lines[10] ) )
1174 if ( isset( self
::$viewvcUrls[$info['repo-url']] ) ) {
1175 $viewvc = str_replace(
1177 self
::$viewvcUrls[$info['repo-url']],
1181 $viewvc .= '/?pathrev=';
1182 $viewvc .= urlencode( $info['checkout-rev'] );
1183 $info['viewvc-url'] = $viewvc;
1190 * Retrieve the revision number of a Subversion working directory.
1192 * @param string $dir Directory of the svn checkout
1194 * @return int Revision number
1196 public static function getSvnRevision( $dir ) {
1197 $info = self
::getSvnInfo( $dir );
1199 if ( $info === false ) {
1201 } elseif ( isset( $info['checkout-rev'] ) ) {
1202 return $info['checkout-rev'];
1209 * @param string $dir Directory of the git checkout
1210 * @return bool|string Sha1 of commit HEAD points to
1212 public static function getGitHeadSha1( $dir ) {
1213 $repo = new GitInfo( $dir );
1215 return $repo->getHeadSHA1();
1219 * @param string $dir Directory of the git checkout
1220 * @return bool|string Branch currently checked out
1222 public static function getGitCurrentBranch( $dir ) {
1223 $repo = new GitInfo( $dir );
1224 return $repo->getCurrentBranch();
1228 * Get the list of entry points and their URLs
1229 * @return string Wikitext
1231 public function getEntryPointInfo() {
1232 global $wgArticlePath, $wgScriptPath;
1233 $scriptPath = $wgScriptPath ?
$wgScriptPath : "/";
1234 $entryPoints = array(
1235 'version-entrypoints-articlepath' => $wgArticlePath,
1236 'version-entrypoints-scriptpath' => $scriptPath,
1237 'version-entrypoints-index-php' => wfScript( 'index' ),
1238 'version-entrypoints-api-php' => wfScript( 'api' ),
1239 'version-entrypoints-load-php' => wfScript( 'load' ),
1242 $language = $this->getLanguage();
1243 $thAttribures = array(
1244 'dir' => $language->getDir(),
1245 'lang' => $language->getHtmlCode()
1247 $out = Html
::element(
1249 array( 'id' => 'mw-version-entrypoints' ),
1250 $this->msg( 'version-entrypoints' )->text()
1252 Html
::openElement( 'table',
1254 'class' => 'wikitable plainlinks',
1255 'id' => 'mw-version-entrypoints-table',
1260 Html
::openElement( 'tr' ) .
1264 $this->msg( 'version-entrypoints-header-entrypoint' )->text()
1269 $this->msg( 'version-entrypoints-header-url' )->text()
1271 Html
::closeElement( 'tr' );
1273 foreach ( $entryPoints as $message => $value ) {
1274 $url = wfExpandUrl( $value, PROTO_RELATIVE
);
1275 $out .= Html
::openElement( 'tr' ) .
1276 // ->text() looks like it should be ->parse(), but this function
1277 // returns wikitext, not HTML, boo
1278 Html
::rawElement( 'td', array(), $this->msg( $message )->text() ) .
1279 Html
::rawElement( 'td', array(), Html
::rawElement( 'code', array(), "[$url $value]" ) ) .
1280 Html
::closeElement( 'tr' );
1283 $out .= Html
::closeElement( 'table' );
1288 protected function getGroupName() {