3 * Implements Special:Version
5 * Copyright © 2005 Ævar Arnfjörð Bjarmason
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
23 * @ingroup SpecialPage
27 * Give information about the version of MediaWiki, PHP, the DB and extensions
29 * @ingroup SpecialPage
31 class SpecialVersion
extends SpecialPage
{
32 protected $firstExtOpened = false;
35 * Stores the current rev id/SHA hash of MediaWiki core
37 protected $coreId = '';
39 protected static $extensionTypes = false;
41 protected static $viewvcUrls = array(
42 'svn+ssh://svn.wikimedia.org/svnroot/mediawiki' => 'http://svn.wikimedia.org/viewvc/mediawiki',
43 'http://svn.wikimedia.org/svnroot/mediawiki' => 'http://svn.wikimedia.org/viewvc/mediawiki',
44 'https://svn.wikimedia.org/svnroot/mediawiki' => 'https://svn.wikimedia.org/viewvc/mediawiki',
47 public function __construct() {
48 parent
::__construct( 'Version' );
54 public function execute( $par ) {
55 global $IP, $wgExtensionCredits;
58 $this->outputHeader();
59 $out = $this->getOutput();
60 $out->allowClickjacking();
62 // Explode the sub page information into useful bits
63 $parts = explode( '/', (string)$par );
65 if ( isset( $parts[1] ) ) {
66 $extName = str_replace( '_', ' ', $parts[1] );
68 foreach ( $wgExtensionCredits as $group => $extensions ) {
69 foreach ( $extensions as $ext ) {
70 if ( isset( $ext['name'] ) && ( $ext['name'] === $extName ) ) {
77 $out->setStatusCode( 404 );
80 $extName = 'MediaWiki';
83 // Now figure out what to do
84 switch ( strtolower( $parts[0] ) ) {
86 $wikiText = '{{int:version-credits-not-found}}';
87 if ( $extName === 'MediaWiki' ) {
88 $wikiText = file_get_contents( $IP . '/CREDITS' );
89 } elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) {
90 $file = $this->getExtAuthorsFileName( dirname( $extNode['path'] ) );
92 $wikiText = file_get_contents( $file );
93 if ( substr( $file, -4 ) === '.txt' ) {
94 $wikiText = Html
::element( 'pre', array(), $wikiText );
99 $out->setPageTitle( $this->msg( 'version-credits-title', $extName ) );
100 $out->addWikiText( $wikiText );
104 $wikiText = '{{int:version-license-not-found}}';
105 if ( $extName === 'MediaWiki' ) {
106 $wikiText = file_get_contents( $IP . '/COPYING' );
107 } elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) {
108 $file = $this->getExtLicenseFileName( dirname( $extNode['path'] ) );
110 $wikiText = file_get_contents( $file );
111 if ( !isset( $extNode['license-name'] ) ) {
112 // If the developer did not explicitly set license-name they probably
113 // are unaware that we're now sucking this file in and thus it's probably
114 // not wikitext friendly.
115 $wikiText = "<pre>$wikiText</pre>";
120 $out->setPageTitle( $this->msg( 'version-license-title', $extName ) );
121 $out->addWikiText( $wikiText );
125 $out->addModules( 'mediawiki.special.version' );
127 $this->getMediaWikiCredits() .
128 $this->softwareInformation() .
129 $this->getEntryPointInfo()
132 $this->getSkinCredits() .
133 $this->getExtensionCredits() .
134 $this->getParserTags() .
135 $this->getParserFunctionHooks()
137 $out->addWikiText( $this->getWgHooks() );
138 $out->addHTML( $this->IPInfo() );
145 * Returns wiki text showing the license information.
149 private static function getMediaWikiCredits() {
152 array( 'id' => 'mw-version-license' ),
153 wfMessage( 'version-license' )->text()
156 // This text is always left-to-right.
157 $ret .= '<div class="plainlinks">';
159 " . self
::getCopyrightAndAuthorList() . "\n
160 " . wfMessage( 'version-license-info' )->text();
163 return str_replace( "\t\t", '', $ret ) . "\n";
167 * Get the "MediaWiki is copyright 2001-20xx by lots of cool guys" text
171 public static function getCopyrightAndAuthorList() {
174 if ( defined( 'MEDIAWIKI_INSTALL' ) ) {
175 $othersLink = '[//www.mediawiki.org/wiki/Special:Version/Credits ' .
176 wfMessage( 'version-poweredby-others' )->text() . ']';
178 $othersLink = '[[Special:Version/Credits|' .
179 wfMessage( 'version-poweredby-others' )->text() . ']]';
182 $translatorsLink = '[//translatewiki.net/wiki/Translating:MediaWiki/Credits ' .
183 wfMessage( 'version-poweredby-translators' )->text() . ']';
186 'Magnus Manske', 'Brion Vibber', 'Lee Daniel Crocker',
187 'Tim Starling', 'Erik Möller', 'Gabriel Wicke', 'Ævar Arnfjörð Bjarmason',
188 'Niklas Laxström', 'Domas Mituzas', 'Rob Church', 'Yuri Astrakhan',
189 'Aryeh Gregor', 'Aaron Schulz', 'Andrew Garrett', 'Raimond Spekking',
190 'Alexandre Emsenhuber', 'Siebrand Mazeland', 'Chad Horohoe',
191 'Roan Kattouw', 'Trevor Parscal', 'Bryan Tong Minh', 'Sam Reed',
192 'Victor Vasiliev', 'Rotem Liss', 'Platonides', 'Antoine Musso',
193 'Timo Tijhof', 'Daniel Kinzler', 'Jeroen De Dauw', $othersLink,
197 return wfMessage( 'version-poweredby-credits', MWTimestamp
::getLocalInstance()->format( 'Y' ),
198 $wgLang->listToText( $authorList ) )->text();
202 * Returns wiki text showing the third party software versions (apache, php, mysql).
206 static function softwareInformation() {
207 $dbr = wfGetDB( DB_SLAVE
);
209 // Put the software in an array of form 'name' => 'version'. All messages should
210 // be loaded here, so feel free to use wfMessage in the 'name'. Raw HTML or
211 // wikimarkup can be used.
213 $software['[https://www.mediawiki.org/ MediaWiki]'] = self
::getVersionLinked();
214 $phpKey = wfIsHHVM() ?
'[http://hhvm.com/ HHVM]' :
215 '[https://php.net/ PHP]';
216 $software[$phpKey] = PHP_VERSION
. " (" . PHP_SAPI
. ")";
217 $software[$dbr->getSoftwareLink()] = $dbr->getServerInfo();
219 // Allow a hook to add/remove items.
220 wfRunHooks( 'SoftwareInfo', array( &$software ) );
224 array( 'id' => 'mw-version-software' ),
225 wfMessage( 'version-software' )->text()
227 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-software' ) ) .
229 <th>" . wfMessage( 'version-software-product' )->text() . "</th>
230 <th>" . wfMessage( 'version-software-version' )->text() . "</th>
233 foreach ( $software as $name => $version ) {
235 <td>" . $name . "</td>
236 <td dir=\"ltr\">" . $version . "</td>
240 return $out . Xml
::closeElement( 'table' );
244 * Return a string of the MediaWiki version with SVN revision if available.
246 * @param string $flags
249 public static function getVersion( $flags = '' ) {
250 global $wgVersion, $IP;
251 wfProfileIn( __METHOD__
);
253 $gitInfo = self
::getGitHeadSha1( $IP );
254 $svnInfo = self
::getSvnInfo( $IP );
255 if ( !$svnInfo && !$gitInfo ) {
256 $version = $wgVersion;
257 } elseif ( $gitInfo && $flags === 'nodb' ) {
258 $shortSha1 = substr( $gitInfo, 0, 7 );
259 $version = "$wgVersion ($shortSha1)";
260 } elseif ( $gitInfo ) {
261 $shortSha1 = substr( $gitInfo, 0, 7 );
262 $shortSha1 = wfMessage( 'parentheses' )->params( $shortSha1 )->escaped();
263 $version = "$wgVersion $shortSha1";
264 } elseif ( $flags === 'nodb' ) {
265 $version = "$wgVersion (r{$svnInfo['checkout-rev']})";
267 $version = $wgVersion . ' ' .
269 'version-svn-revision',
270 isset( $info['directory-rev'] ) ?
$info['directory-rev'] : '',
271 $info['checkout-rev']
275 wfProfileOut( __METHOD__
);
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() {
290 wfProfileIn( __METHOD__
);
292 $gitVersion = self
::getVersionLinkedGit();
296 $svnVersion = self
::getVersionLinkedSvn();
300 $v = $wgVersion; // fallback
304 wfProfileOut( __METHOD__
);
310 * @return string Global wgVersion + a link to subversion revision of svn BASE
312 private static function getVersionLinkedSvn() {
315 $info = self
::getSvnInfo( $IP );
316 if ( !isset( $info['checkout-rev'] ) ) {
320 $linkText = wfMessage(
321 'version-svn-revision',
322 isset( $info['directory-rev'] ) ?
$info['directory-rev'] : '',
323 $info['checkout-rev']
326 if ( isset( $info['viewvc-url'] ) ) {
327 $version = "[{$info['viewvc-url']} $linkText]";
329 $version = $linkText;
332 return self
::getwgVersionLinked() . " $version";
338 private static function getwgVersionLinked() {
341 if ( wfRunHooks( 'SpecialVersionVersionUrl', array( $wgVersion, &$versionUrl ) ) ) {
342 $versionParts = array();
343 preg_match( "/^(\d+\.\d+)/", $wgVersion, $versionParts );
344 $versionUrl = "https://www.mediawiki.org/wiki/MediaWiki_{$versionParts[1]}";
347 return "[$versionUrl $wgVersion]";
351 * @since 1.22 Returns the HEAD date in addition to the sha1 and link
352 * @return bool|string Global wgVersion + HEAD sha1 stripped to the first 7 chars
353 * with link and date, or false on failure
355 private static function getVersionLinkedGit() {
358 $gitInfo = new GitInfo( $IP );
359 $headSHA1 = $gitInfo->getHeadSHA1();
364 $shortSHA1 = '(' . substr( $headSHA1, 0, 7 ) . ')';
366 $gitHeadUrl = $gitInfo->getHeadViewUrl();
367 if ( $gitHeadUrl !== false ) {
368 $shortSHA1 = "[$gitHeadUrl $shortSHA1]";
371 $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
372 if ( $gitHeadCommitDate ) {
373 $shortSHA1 .= Html
::element( 'br' ) . $wgLang->timeanddate( $gitHeadCommitDate, true );
376 return self
::getwgVersionLinked() . " $shortSHA1";
380 * Returns an array with the base extension types.
381 * Type is stored as array key, the message as array value.
383 * TODO: ideally this would return all extension types.
389 public static function getExtensionTypes() {
390 if ( self
::$extensionTypes === false ) {
391 self
::$extensionTypes = array(
392 'specialpage' => wfMessage( 'version-specialpages' )->text(),
393 'parserhook' => wfMessage( 'version-parserhooks' )->text(),
394 'variable' => wfMessage( 'version-variables' )->text(),
395 'media' => wfMessage( 'version-mediahandlers' )->text(),
396 'antispam' => wfMessage( 'version-antispam' )->text(),
397 'skin' => wfMessage( 'version-skins' )->text(),
398 'api' => wfMessage( 'version-api' )->text(),
399 'other' => wfMessage( 'version-other' )->text(),
402 wfRunHooks( 'ExtensionTypes', array( &self
::$extensionTypes ) );
405 return self
::$extensionTypes;
409 * Returns the internationalized name for an extension type.
413 * @param string $type
417 public static function getExtensionTypeName( $type ) {
418 $types = self
::getExtensionTypes();
420 return isset( $types[$type] ) ?
$types[$type] : $types['other'];
424 * Generate wikitext showing the name, URL, author and description of each extension.
426 * @return string Wikitext
428 function getExtensionCredits() {
429 global $wgExtensionCredits;
431 if ( !count( $wgExtensionCredits ) ) {
435 $extensionTypes = self
::getExtensionTypes();
439 array( 'id' => 'mw-version-ext' ),
440 $this->msg( 'version-extensions' )->text()
442 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-ext' ) );
444 // Make sure the 'other' type is set to an array.
445 if ( !array_key_exists( 'other', $wgExtensionCredits ) ) {
446 $wgExtensionCredits['other'] = array();
449 // Find all extensions that do not have a valid type and give them the type 'other'.
450 foreach ( $wgExtensionCredits as $type => $extensions ) {
451 if ( !array_key_exists( $type, $extensionTypes ) ) {
452 $wgExtensionCredits['other'] = array_merge( $wgExtensionCredits['other'], $extensions );
456 $this->firstExtOpened
= false;
457 // Loop through the extension categories to display their extensions in the list.
458 foreach ( $extensionTypes as $type => $message ) {
459 // Skins have a separate section
460 if ( $type !== 'other' && $type !== 'skin' ) {
461 $out .= $this->getExtensionCategory( $type, $message );
465 // We want the 'other' type to be last in the list.
466 $out .= $this->getExtensionCategory( 'other', $extensionTypes['other'] );
468 $out .= Xml
::closeElement( 'table' );
474 * Generate wikitext showing the name, URL, author and description of each skin.
476 * @return string Wikitext
478 function getSkinCredits() {
481 array( 'id' => 'mw-version-skin' ),
482 $this->msg( 'version-skins' )->text()
484 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-skin' ) );
486 $this->firstExtOpened
= false;
487 $out .= $this->getExtensionCategory( 'skin', null );
489 $out .= Xml
::closeElement( 'table' );
495 * Obtains a list of installed parser tags and the associated H2 header
497 * @return string HTML output
499 protected function getParserTags() {
502 $tags = $wgParser->getTags();
504 if ( count( $tags ) ) {
505 $out = Html
::rawElement(
507 array( 'class' => 'mw-headline' ),
508 Linker
::makeExternalLink(
509 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Tag_extensions',
510 $this->msg( 'version-parser-extensiontags' )->parse(),
511 false /* msg()->parse() already escapes */
515 array_walk( $tags, function ( &$value ) {
516 $value = '<' . htmlspecialchars( $value ) . '>';
518 $out .= $this->listToText( $tags );
527 * Obtains a list of installed parser function hooks and the associated H2 header
529 * @return string HTML output
531 protected function getParserFunctionHooks() {
534 $fhooks = $wgParser->getFunctionHooks();
535 if ( count( $fhooks ) ) {
536 $out = Html
::rawElement( 'h2', array( 'class' => 'mw-headline' ), Linker
::makeExternalLink(
537 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Parser_functions',
538 $this->msg( 'version-parser-function-hooks' )->parse(),
539 false /* msg()->parse() already escapes */
542 $out .= $this->listToText( $fhooks );
551 * Creates and returns the HTML for a single extension category.
555 * @param string $type
556 * @param string $message
560 protected function getExtensionCategory( $type, $message ) {
561 global $wgExtensionCredits;
565 if ( array_key_exists( $type, $wgExtensionCredits ) && count( $wgExtensionCredits[$type] ) > 0 ) {
566 $out .= $this->openExtType( $message, 'credits-' . $type );
568 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
570 foreach ( $wgExtensionCredits[$type] as $extension ) {
571 $out .= $this->getCreditsForExtension( $extension );
579 * Callback to sort extensions by type.
584 function compare( $a, $b ) {
585 if ( $a['name'] === $b['name'] ) {
588 return $this->getLanguage()->lc( $a['name'] ) > $this->getLanguage()->lc( $b['name'] )
595 * Creates and formats a version line for a single extension.
597 * Information for five columns will be created. Parameters required in the
598 * $extension array for part rendering are indicated in ()
599 * - The name of (name), and URL link to (url), the extension
600 * - Official version number (version) and if available version control system
601 * revision (path), link, and date
602 * - If available the short name of the license (license-name) and a linke
603 * to ((LICENSE)|(COPYING))(\.txt)? if it exists.
604 * - Description of extension (descriptionmsg or description)
605 * - List of authors (author) and link to a ((AUTHORS)|(CREDITS))(\.txt)? file if it exists
607 * @param array $extension
609 * @return string Raw HTML
611 function getCreditsForExtension( array $extension ) {
612 $out = $this->getOutput();
614 // We must obtain the information for all the bits and pieces!
615 // ... such as extension names and links
616 if ( isset( $extension['namemsg'] ) ) {
617 // Localized name of extension
618 $extensionName = $this->msg( $extension['namemsg'] )->text();
619 } elseif ( isset( $extension['name'] ) ) {
620 // Non localized version
621 $extensionName = $extension['name'];
623 $extensionName = $this->msg( 'version-no-ext-name' )->text();
626 if ( isset( $extension['url'] ) ) {
627 $extensionNameLink = Linker
::makeExternalLink(
632 array( 'class' => 'mw-version-ext-name' )
635 $extensionNameLink = $extensionName;
638 // ... and the version information
639 // If the extension path is set we will check that directory for GIT and SVN
640 // metadata in an attempt to extract date and vcs commit metadata.
641 $canonicalVersion = '–';
642 $extensionPath = null;
647 if ( isset( $extension['version'] ) ) {
648 $canonicalVersion = $out->parseInline( $extension['version'] );
651 if ( isset( $extension['path'] ) ) {
653 $extensionPath = dirname( $extension['path'] );
654 if ( $this->coreId
== '' ) {
655 wfDebug( 'Looking up core head id' );
656 $coreHeadSHA1 = self
::getGitHeadSha1( $IP );
657 if ( $coreHeadSHA1 ) {
658 $this->coreId
= $coreHeadSHA1;
660 $svnInfo = self
::getSvnInfo( $IP );
661 if ( $svnInfo !== false ) {
662 $this->coreId
= $svnInfo['checkout-rev'];
666 $cache = wfGetCache( CACHE_ANYTHING
);
667 $memcKey = wfMemcKey( 'specialversion-ext-version-text', $extension['path'], $this->coreId
);
668 list( $vcsVersion, $vcsLink, $vcsDate ) = $cache->get( $memcKey );
670 if ( !$vcsVersion ) {
671 wfDebug( "Getting VCS info for extension $extensionName" );
672 $gitInfo = new GitInfo( $extensionPath );
673 $vcsVersion = $gitInfo->getHeadSHA1();
674 if ( $vcsVersion !== false ) {
675 $vcsVersion = substr( $vcsVersion, 0, 7 );
676 $vcsLink = $gitInfo->getHeadViewUrl();
677 $vcsDate = $gitInfo->getHeadCommitDate();
679 $svnInfo = self
::getSvnInfo( $extensionPath );
680 if ( $svnInfo !== false ) {
681 $vcsVersion = $this->msg( 'version-svn-revision', $svnInfo['checkout-rev'] )->text();
682 $vcsLink = isset( $svnInfo['viewvc-url'] ) ?
$svnInfo['viewvc-url'] : '';
685 $cache->set( $memcKey, array( $vcsVersion, $vcsLink, $vcsDate ), 60 * 60 * 24 );
687 wfDebug( "Pulled VCS info for extension $extensionName from cache" );
691 $versionString = Html
::rawElement(
693 array( 'class' => 'mw-version-ext-version' ),
699 $vcsVerString = Linker
::makeExternalLink(
701 $this->msg( 'version-version', $vcsVersion ),
704 array( 'class' => 'mw-version-ext-vcs-version' )
707 $vcsVerString = Html
::element( 'span',
708 array( 'class' => 'mw-version-ext-vcs-version' ),
712 $versionString .= " {$vcsVerString}";
715 $vcsTimeString = Html
::element( 'span',
716 array( 'class' => 'mw-version-ext-vcs-timestamp' ),
717 $this->getLanguage()->timeanddate( $vcsDate )
719 $versionString .= " {$vcsTimeString}";
721 $versionString = Html
::rawElement( 'span',
722 array( 'class' => 'mw-version-ext-meta-version' ),
727 // ... and license information; if a license file exists we
730 if ( isset( $extension['license-name'] ) ) {
731 $licenseLink = Linker
::link(
732 $this->getPageTitle( 'License/' . $extensionName ),
733 $out->parseInline( $extension['license-name'] ),
734 array( 'class' => 'mw-version-ext-license' )
736 } elseif ( $this->getExtLicenseFileName( $extensionPath ) ) {
737 $licenseLink = Linker
::link(
738 $this->getPageTitle( 'License/' . $extensionName ),
739 $this->msg( 'version-ext-license' ),
740 array( 'class' => 'mw-version-ext-license' )
744 // ... and generate the description; which can be a parameterized l10n message
745 // in the form array( <msgname>, <parameter>, <parameter>... ) or just a straight
747 if ( isset( $extension['descriptionmsg'] ) ) {
748 // Localized description of extension
749 $descriptionMsg = $extension['descriptionmsg'];
751 if ( is_array( $descriptionMsg ) ) {
752 $descriptionMsgKey = $descriptionMsg[0]; // Get the message key
753 array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
754 array_map( "htmlspecialchars", $descriptionMsg ); // For sanity
755 $description = $this->msg( $descriptionMsgKey, $descriptionMsg )->text();
757 $description = $this->msg( $descriptionMsg )->text();
759 } elseif ( isset( $extension['description'] ) ) {
760 // Non localized version
761 $description = $extension['description'];
765 $description = $out->parseInline( $description );
767 // ... now get the authors for this extension
768 $authors = isset( $extension['author'] ) ?
$extension['author'] : array();
769 $authors = $this->listAuthors( $authors, $extensionName, $extensionPath );
771 // Finally! Create the table
772 $html = Html
::openElement( 'tr', array(
773 'class' => 'mw-version-ext',
774 'id' => "mw-version-ext-{$extensionName}"
778 $html .= Html
::rawElement( 'td', array(), $extensionNameLink );
779 $html .= Html
::rawElement( 'td', array(), $versionString );
780 $html .= Html
::rawElement( 'td', array(), $licenseLink );
781 $html .= Html
::rawElement( 'td', array( 'class' => 'mw-version-ext-description' ), $description );
782 $html .= Html
::rawElement( 'td', array( 'class' => 'mw-version-ext-authors' ), $authors );
784 $html .= Html
::closeElement( 'td' );
790 * Generate wikitext showing hooks in $wgHooks.
792 * @return string Wikitext
794 private function getWgHooks() {
795 global $wgSpecialVersionShowHooks, $wgHooks;
797 if ( $wgSpecialVersionShowHooks && count( $wgHooks ) ) {
798 $myWgHooks = $wgHooks;
802 $ret[] = '== {{int:version-hooks}} ==';
803 $ret[] = Html
::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-hooks' ) );
804 $ret[] = Html
::openElement( 'tr' );
805 $ret[] = Html
::element( 'th', array(), $this->msg( 'version-hook-name' )->text() );
806 $ret[] = Html
::element( 'th', array(), $this->msg( 'version-hook-subscribedby' )->text() );
807 $ret[] = Html
::closeElement( 'tr' );
809 foreach ( $myWgHooks as $hook => $hooks ) {
810 $ret[] = Html
::openElement( 'tr' );
811 $ret[] = Html
::element( 'td', array(), $hook );
812 $ret[] = Html
::element( 'td', array(), $this->listToText( $hooks ) );
813 $ret[] = Html
::closeElement( 'tr' );
816 $ret[] = Html
::closeElement( 'table' );
818 return implode( "\n", $ret );
824 private function openExtType( $text = null, $name = null ) {
827 $opt = array( 'colspan' => 5 );
828 if ( $this->firstExtOpened
) {
829 // Insert a spacing line
830 $out .= Html
::rawElement( 'tr', array( 'class' => 'sv-space' ),
831 Html
::element( 'td', $opt )
834 $this->firstExtOpened
= true;
837 $opt['id'] = "sv-$name";
840 if ( $text !== null ) {
841 $out .= Html
::rawElement( 'tr', array(),
842 Html
::element( 'th', $opt, $text )
846 $firstHeadingMsg = ( $name === 'credits-skin' )
847 ?
'version-skin-colheader-name'
848 : 'version-ext-colheader-name';
849 $out .= Html
::openElement( 'tr' );
850 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
851 $this->msg( $firstHeadingMsg )->text() );
852 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
853 $this->msg( 'version-ext-colheader-version' )->text() );
854 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
855 $this->msg( 'version-ext-colheader-license' )->text() );
856 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
857 $this->msg( 'version-ext-colheader-description' )->text() );
858 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
859 $this->msg( 'version-ext-colheader-credits' )->text() );
860 $out .= Html
::closeElement( 'tr' );
866 * Get information about client's IP address.
868 * @return string HTML fragment
870 private function IPInfo() {
871 $ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) );
873 return "<!-- visited from $ip -->\n<span style='display:none'>visited from $ip</span>";
877 * Return a formatted unsorted list of authors
880 * If an item in the $authors array is '...' it is assumed to indicate an
881 * 'and others' string which will then be linked to an ((AUTHORS)|(CREDITS))(\.txt)?
882 * file if it exists in $dir.
884 * Similarly an entry ending with ' ...]' is assumed to be a link to an
887 * If no '...' string variant is found, but an authors file is found an
888 * 'and others' will be added to the end of the credits.
890 * @param string|array $authors
891 * @param string $extName Name of the extension for link creation
892 * @param string $extDir Path to the extension root directory
894 * @return string HTML fragment
896 function listAuthors( $authors, $extName, $extDir ) {
900 foreach ( (array)$authors as $item ) {
901 if ( $item == '...' ) {
904 if ( $this->getExtAuthorsFileName( $extDir ) ) {
905 $text = Linker
::link(
906 $this->getPageTitle( "Credits/$extName" ),
907 $this->msg( 'version-poweredby-others' )->text()
910 $text = $this->msg( 'version-poweredby-others' )->text();
913 } elseif ( substr( $item, -5 ) == ' ...]' ) {
915 $list[] = $this->getOutput()->parseInline(
916 substr( $item, 0, -4 ) . $this->msg( 'version-poweredby-others' )->text() . "]"
919 $list[] = $this->getOutput()->parseInline( $item );
923 if ( !$hasOthers && $this->getExtAuthorsFileName( $extDir ) ) {
924 $list[] = $text = Linker
::link(
925 $this->getPageTitle( "Credits/$extName" ),
926 $this->msg( 'version-poweredby-others' )->text()
930 return $this->listToText( $list, false );
934 * Obtains the full path of an extensions authors or credits file if
937 * @param string $extDir Path to the extensions root directory
941 * @return bool|string False if no such file exists, otherwise returns
944 public static function getExtAuthorsFileName( $extDir ) {
949 foreach ( scandir( $extDir ) as $file ) {
950 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
951 if ( preg_match( '/^((AUTHORS)|(CREDITS))(\.txt)?$/', $file ) &&
952 is_readable( $fullPath ) &&
963 * Obtains the full path of an extensions copying or license file if
966 * @param string $extDir Path to the extensions root directory
970 * @return bool|string False if no such file exists, otherwise returns
973 public static function getExtLicenseFileName( $extDir ) {
978 foreach ( scandir( $extDir ) as $file ) {
979 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
980 if ( preg_match( '/^((COPYING)|(LICENSE))(\.txt)?$/', $file ) &&
981 is_readable( $fullPath ) &&
992 * Convert an array of items into a list for display.
994 * @param array $list List of elements to display
995 * @param bool $sort Whether to sort the items in $list
999 function listToText( $list, $sort = true ) {
1000 if ( !count( $list ) ) {
1007 return $this->getLanguage()
1008 ->listToText( array_map( array( __CLASS__
, 'arrayToString' ), $list ) );
1012 * Convert an array or object to a string for display.
1014 * @param mixed $list Will convert an array to string if given and return
1015 * the paramater unaltered otherwise
1019 public static function arrayToString( $list ) {
1020 if ( is_array( $list ) && count( $list ) == 1 ) {
1023 if ( is_object( $list ) ) {
1024 $class = wfMessage( 'parentheses' )->params( get_class( $list ) )->escaped();
1027 } elseif ( !is_array( $list ) ) {
1030 if ( is_object( $list[0] ) ) {
1031 $class = get_class( $list[0] );
1036 return wfMessage( 'parentheses' )->params( "$class, {$list[1]}" )->escaped();
1041 * Get an associative array of information about a given path, from its .svn
1042 * subdirectory. Returns false on error, such as if the directory was not
1043 * checked out with subversion.
1045 * Returned keys are:
1047 * checkout-rev The revision which was checked out
1049 * directory-rev The revision when the directory was last modified
1050 * url The subversion URL of the directory
1051 * repo-url The base URL of the repository
1052 * viewvc-url A ViewVC URL pointing to the checked-out revision
1053 * @param string $dir
1054 * @return array|bool
1056 public static function getSvnInfo( $dir ) {
1057 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
1058 $entries = $dir . '/.svn/entries';
1060 if ( !file_exists( $entries ) ) {
1064 $lines = file( $entries );
1065 if ( !count( $lines ) ) {
1069 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
1070 if ( preg_match( '/^<\?xml/', $lines[0] ) ) {
1071 // subversion is release <= 1.3
1072 if ( !function_exists( 'simplexml_load_file' ) ) {
1073 // We could fall back to expat... YUCK
1077 // SimpleXml whines about the xmlns...
1078 wfSuppressWarnings();
1079 $xml = simplexml_load_file( $entries );
1080 wfRestoreWarnings();
1083 foreach ( $xml->entry
as $entry ) {
1084 if ( $xml->entry
[0]['name'] == '' ) {
1085 // The directory entry should always have a revision marker.
1086 if ( $entry['revision'] ) {
1087 return array( 'checkout-rev' => intval( $entry['revision'] ) );
1096 // Subversion is release 1.4 or above.
1097 if ( count( $lines ) < 11 ) {
1102 'checkout-rev' => intval( trim( $lines[3] ) ),
1103 'url' => trim( $lines[4] ),
1104 'repo-url' => trim( $lines[5] ),
1105 'directory-rev' => intval( trim( $lines[10] ) )
1108 if ( isset( self
::$viewvcUrls[$info['repo-url']] ) ) {
1109 $viewvc = str_replace(
1111 self
::$viewvcUrls[$info['repo-url']],
1115 $viewvc .= '/?pathrev=';
1116 $viewvc .= urlencode( $info['checkout-rev'] );
1117 $info['viewvc-url'] = $viewvc;
1124 * Retrieve the revision number of a Subversion working directory.
1126 * @param string $dir Directory of the svn checkout
1128 * @return int Revision number
1130 public static function getSvnRevision( $dir ) {
1131 $info = self
::getSvnInfo( $dir );
1133 if ( $info === false ) {
1135 } elseif ( isset( $info['checkout-rev'] ) ) {
1136 return $info['checkout-rev'];
1143 * @param string $dir Directory of the git checkout
1144 * @return bool|string Sha1 of commit HEAD points to
1146 public static function getGitHeadSha1( $dir ) {
1147 $repo = new GitInfo( $dir );
1149 return $repo->getHeadSHA1();
1153 * @param string $dir Directory of the git checkout
1154 * @return bool|string Branch currently checked out
1156 public static function getGitCurrentBranch( $dir ) {
1157 $repo = new GitInfo( $dir );
1158 return $repo->getCurrentBranch();
1162 * Get the list of entry points and their URLs
1163 * @return string Wikitext
1165 public function getEntryPointInfo() {
1166 global $wgArticlePath, $wgScriptPath;
1167 $scriptPath = $wgScriptPath ?
$wgScriptPath : "/";
1168 $entryPoints = array(
1169 'version-entrypoints-articlepath' => $wgArticlePath,
1170 'version-entrypoints-scriptpath' => $scriptPath,
1171 'version-entrypoints-index-php' => wfScript( 'index' ),
1172 'version-entrypoints-api-php' => wfScript( 'api' ),
1173 'version-entrypoints-load-php' => wfScript( 'load' ),
1176 $language = $this->getLanguage();
1177 $thAttribures = array(
1178 'dir' => $language->getDir(),
1179 'lang' => $language->getCode()
1181 $out = Html
::element(
1183 array( 'id' => 'mw-version-entrypoints' ),
1184 $this->msg( 'version-entrypoints' )->text()
1186 Html
::openElement( 'table',
1188 'class' => 'wikitable plainlinks',
1189 'id' => 'mw-version-entrypoints-table',
1194 Html
::openElement( 'tr' ) .
1198 $this->msg( 'version-entrypoints-header-entrypoint' )->text()
1203 $this->msg( 'version-entrypoints-header-url' )->text()
1205 Html
::closeElement( 'tr' );
1207 foreach ( $entryPoints as $message => $value ) {
1208 $url = wfExpandUrl( $value, PROTO_RELATIVE
);
1209 $out .= Html
::openElement( 'tr' ) .
1210 // ->text() looks like it should be ->parse(), but this function
1211 // returns wikitext, not HTML, boo
1212 Html
::rawElement( 'td', array(), $this->msg( $message )->text() ) .
1213 Html
::rawElement( 'td', array(), Html
::rawElement( 'code', array(), "[$url $value]" ) ) .
1214 Html
::closeElement( 'tr' );
1217 $out .= Html
::closeElement( 'table' );
1222 protected function getGroupName() {