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->getExtensionCredits() .
133 $this->getParserTags() .
134 $this->getParserFunctionHooks()
136 $out->addWikiText( $this->getWgHooks() );
137 $out->addHTML( $this->IPInfo() );
144 * Returns wiki text showing the license information.
148 private static function getMediaWikiCredits() {
151 array( 'id' => 'mw-version-license' ),
152 wfMessage( 'version-license' )->text()
155 // This text is always left-to-right.
156 $ret .= '<div class="plainlinks">';
158 " . self
::getCopyrightAndAuthorList() . "\n
159 " . wfMessage( 'version-license-info' )->text();
162 return str_replace( "\t\t", '', $ret ) . "\n";
166 * Get the "MediaWiki is copyright 2001-20xx by lots of cool guys" text
170 public static function getCopyrightAndAuthorList() {
173 if ( defined( 'MEDIAWIKI_INSTALL' ) ) {
174 $othersLink = '[//www.mediawiki.org/wiki/Special:Version/Credits ' .
175 wfMessage( 'version-poweredby-others' )->text() . ']';
177 $othersLink = '[[Special:Version/Credits|' .
178 wfMessage( 'version-poweredby-others' )->text() . ']]';
181 $translatorsLink = '[//translatewiki.net/wiki/Translating:MediaWiki/Credits ' .
182 wfMessage( 'version-poweredby-translators' )->text() . ']';
185 'Magnus Manske', 'Brion Vibber', 'Lee Daniel Crocker',
186 'Tim Starling', 'Erik Möller', 'Gabriel Wicke', 'Ævar Arnfjörð Bjarmason',
187 'Niklas Laxström', 'Domas Mituzas', 'Rob Church', 'Yuri Astrakhan',
188 'Aryeh Gregor', 'Aaron Schulz', 'Andrew Garrett', 'Raimond Spekking',
189 'Alexandre Emsenhuber', 'Siebrand Mazeland', 'Chad Horohoe',
190 'Roan Kattouw', 'Trevor Parscal', 'Bryan Tong Minh', 'Sam Reed',
191 'Victor Vasiliev', 'Rotem Liss', 'Platonides', 'Antoine Musso',
192 'Timo Tijhof', 'Daniel Kinzler', 'Jeroen De Dauw', $othersLink,
196 return wfMessage( 'version-poweredby-credits', MWTimestamp
::getLocalInstance()->format( 'Y' ),
197 $wgLang->listToText( $authorList ) )->text();
201 * Returns wiki text showing the third party software versions (apache, php, mysql).
205 static function softwareInformation() {
206 $dbr = wfGetDB( DB_SLAVE
);
208 // Put the software in an array of form 'name' => 'version'. All messages should
209 // be loaded here, so feel free to use wfMessage in the 'name'. Raw HTML or
210 // wikimarkup can be used.
212 $software['[https://www.mediawiki.org/ MediaWiki]'] = self
::getVersionLinked();
213 $software['[http://www.php.net/ PHP]'] = phpversion() . " (" . PHP_SAPI
. ")";
214 $software[$dbr->getSoftwareLink()] = $dbr->getServerInfo();
216 // Allow a hook to add/remove items.
217 wfRunHooks( 'SoftwareInfo', array( &$software ) );
221 array( 'id' => 'mw-version-software' ),
222 wfMessage( 'version-software' )->text()
224 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-software' ) ) .
226 <th>" . wfMessage( 'version-software-product' )->text() . "</th>
227 <th>" . wfMessage( 'version-software-version' )->text() . "</th>
230 foreach ( $software as $name => $version ) {
232 <td>" . $name . "</td>
233 <td dir=\"ltr\">" . $version . "</td>
237 return $out . Xml
::closeElement( 'table' );
241 * Return a string of the MediaWiki version with SVN revision if available.
243 * @param $flags String
246 public static function getVersion( $flags = '' ) {
247 global $wgVersion, $IP;
248 wfProfileIn( __METHOD__
);
250 $gitInfo = self
::getGitHeadSha1( $IP );
251 $svnInfo = self
::getSvnInfo( $IP );
252 if ( !$svnInfo && !$gitInfo ) {
253 $version = $wgVersion;
254 } elseif ( $gitInfo && $flags === 'nodb' ) {
255 $shortSha1 = substr( $gitInfo, 0, 7 );
256 $version = "$wgVersion ($shortSha1)";
257 } elseif ( $gitInfo ) {
258 $shortSha1 = substr( $gitInfo, 0, 7 );
259 $shortSha1 = wfMessage( 'parentheses' )->params( $shortSha1 )->escaped();
260 $version = "$wgVersion $shortSha1";
261 } elseif ( $flags === 'nodb' ) {
262 $version = "$wgVersion (r{$svnInfo['checkout-rev']})";
264 $version = $wgVersion . ' ' .
266 'version-svn-revision',
267 isset( $info['directory-rev'] ) ?
$info['directory-rev'] : '',
268 $info['checkout-rev']
272 wfProfileOut( __METHOD__
);
278 * Return a wikitext-formatted string of the MediaWiki version with a link to
279 * the SVN revision or the git SHA1 of head if available.
280 * Git is prefered over Svn
281 * The fallback is just $wgVersion
285 public static function getVersionLinked() {
287 wfProfileIn( __METHOD__
);
289 $gitVersion = self
::getVersionLinkedGit();
293 $svnVersion = self
::getVersionLinkedSvn();
297 $v = $wgVersion; // fallback
301 wfProfileOut( __METHOD__
);
307 * @return string wgVersion + a link to subversion revision of svn BASE
309 private static function getVersionLinkedSvn() {
312 $info = self
::getSvnInfo( $IP );
313 if ( !isset( $info['checkout-rev'] ) ) {
317 $linkText = wfMessage(
318 'version-svn-revision',
319 isset( $info['directory-rev'] ) ?
$info['directory-rev'] : '',
320 $info['checkout-rev']
323 if ( isset( $info['viewvc-url'] ) ) {
324 $version = "[{$info['viewvc-url']} $linkText]";
326 $version = $linkText;
329 return self
::getwgVersionLinked() . " $version";
335 private static function getwgVersionLinked() {
338 if ( wfRunHooks( 'SpecialVersionVersionUrl', array( $wgVersion, &$versionUrl ) ) ) {
339 $versionParts = array();
340 preg_match( "/^(\d+\.\d+)/", $wgVersion, $versionParts );
341 $versionUrl = "https://www.mediawiki.org/wiki/MediaWiki_{$versionParts[1]}";
344 return "[$versionUrl $wgVersion]";
348 * @since 1.22 Returns the HEAD date in addition to the sha1 and link
349 * @return bool|string wgVersion + HEAD sha1 stripped to the first 7 chars
350 * with link and date, or false on failure
352 private static function getVersionLinkedGit() {
355 $gitInfo = new GitInfo( $IP );
356 $headSHA1 = $gitInfo->getHeadSHA1();
361 $shortSHA1 = '(' . substr( $headSHA1, 0, 7 ) . ')';
363 $gitHeadUrl = $gitInfo->getHeadViewUrl();
364 if ( $gitHeadUrl !== false ) {
365 $shortSHA1 = "[$gitHeadUrl $shortSHA1]";
368 $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
369 if ( $gitHeadCommitDate ) {
370 $shortSHA1 .= Html
::element( 'br' ) . $wgLang->timeanddate( $gitHeadCommitDate, true );
373 return self
::getwgVersionLinked() . " $shortSHA1";
377 * Returns an array with the base extension types.
378 * Type is stored as array key, the message as array value.
380 * TODO: ideally this would return all extension types, including
381 * those added by SpecialVersionExtensionTypes. This is not possible
382 * since this hook is passing along $this though.
388 public static function getExtensionTypes() {
389 if ( self
::$extensionTypes === false ) {
390 self
::$extensionTypes = array(
391 'specialpage' => wfMessage( 'version-specialpages' )->text(),
392 'parserhook' => wfMessage( 'version-parserhooks' )->text(),
393 'variable' => wfMessage( 'version-variables' )->text(),
394 'media' => wfMessage( 'version-mediahandlers' )->text(),
395 'antispam' => wfMessage( 'version-antispam' )->text(),
396 'skin' => wfMessage( 'version-skins' )->text(),
397 'api' => wfMessage( 'version-api' )->text(),
398 'other' => wfMessage( 'version-other' )->text(),
401 wfRunHooks( 'ExtensionTypes', array( &self
::$extensionTypes ) );
404 return self
::$extensionTypes;
408 * Returns the internationalized name for an extension type.
412 * @param $type String
416 public static function getExtensionTypeName( $type ) {
417 $types = self
::getExtensionTypes();
419 return isset( $types[$type] ) ?
$types[$type] : $types['other'];
423 * Generate wikitext showing extensions name, URL, author and description.
425 * @return string Wikitext
427 function getExtensionCredits() {
428 global $wgExtensionCredits;
430 if ( !count( $wgExtensionCredits ) ) {
434 $extensionTypes = self
::getExtensionTypes();
437 * @deprecated as of 1.17, use hook ExtensionTypes instead.
439 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
443 array( 'id' => 'mw-version-ext' ),
444 $this->msg( 'version-extensions' )->text()
446 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-ext' ) );
448 // Make sure the 'other' type is set to an array.
449 if ( !array_key_exists( 'other', $wgExtensionCredits ) ) {
450 $wgExtensionCredits['other'] = array();
453 // Find all extensions that do not have a valid type and give them the type 'other'.
454 foreach ( $wgExtensionCredits as $type => $extensions ) {
455 if ( !array_key_exists( $type, $extensionTypes ) ) {
456 $wgExtensionCredits['other'] = array_merge( $wgExtensionCredits['other'], $extensions );
460 // Loop through the extension categories to display their extensions in the list.
461 foreach ( $extensionTypes as $type => $message ) {
462 if ( $type != 'other' ) {
463 $out .= $this->getExtensionCategory( $type, $message );
467 // We want the 'other' type to be last in the list.
468 $out .= $this->getExtensionCategory( 'other', $extensionTypes['other'] );
470 $out .= Xml
::closeElement( 'table' );
476 * Obtains a list of installed parser tags and the associated H2 header
478 * @return string HTML output
480 protected function getParserTags() {
483 $tags = $wgParser->getTags();
485 if ( count( $tags ) ) {
486 $out = Html
::rawElement(
488 array( 'class' => 'mw-headline' ),
489 Linker
::makeExternalLink(
490 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Tag_extensions',
491 $this->msg( 'version-parser-extensiontags' )->parse(),
492 false /* msg()->parse() already escapes */
496 array_walk( $tags, function ( &$value ) {
497 $value = '<' . htmlentities( $value ) . '>';
499 $out .= $this->listToText( $tags );
508 * Obtains a list of installed parser function hooks and the associated H2 header
510 * @return string HTML output
512 protected function getParserFunctionHooks() {
515 $fhooks = $wgParser->getFunctionHooks();
516 if ( count( $fhooks ) ) {
517 $out = Html
::rawElement( 'h2', array( 'class' => 'mw-headline' ), Linker
::makeExternalLink(
518 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Parser_functions',
519 $this->msg( 'version-parser-function-hooks' )->parse(),
520 false /* msg()->parse() already escapes */
523 $out .= $this->listToText( $fhooks );
532 * Creates and returns the HTML for a single extension category.
536 * @param $type String
537 * @param $message String
541 protected function getExtensionCategory( $type, $message ) {
542 global $wgExtensionCredits;
546 if ( array_key_exists( $type, $wgExtensionCredits ) && count( $wgExtensionCredits[$type] ) > 0 ) {
547 $out .= $this->openExtType( $message, 'credits-' . $type );
549 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
551 foreach ( $wgExtensionCredits[$type] as $extension ) {
552 $out .= $this->getCreditsForExtension( $extension );
560 * Callback to sort extensions by type.
565 function compare( $a, $b ) {
566 if ( $a['name'] === $b['name'] ) {
569 return $this->getLanguage()->lc( $a['name'] ) > $this->getLanguage()->lc( $b['name'] )
576 * Creates and formats a version line for a single extension.
578 * Information for five columns will be created. Parameters required in the
579 * $extension array for part rendering are indicated in ()
580 * - The name of (name), and URL link to (url), the extension
581 * - Official version number (version) and if available version control system
582 * revision (path), link, and date
583 * - If available the short name of the license (license-name) and a linke
584 * to ((LICENSE)|(COPYING))(\.txt)? if it exists.
585 * - Description of extension (descriptionmsg or description)
586 * - List of authors (author) and link to a ((AUTHORS)|(CREDITS))(\.txt)? file if it exists
588 * @param $extension Array
590 * @return string raw HTML
592 function getCreditsForExtension( array $extension ) {
593 $out = $this->getOutput();
595 // We must obtain the information for all the bits and pieces!
596 // ... such as extension names and links
597 $extensionName = isset( $extension['name'] ) ?
$extension['name'] : '[no name]';
598 if ( isset( $extension['url'] ) ) {
599 $extensionNameLink = Linker
::makeExternalLink(
604 array( 'class' => 'mw-version-ext-name' )
607 $extensionNameLink = $extensionName;
610 // ... and the version information
611 // If the extension path is set we will check that directory for GIT and SVN
612 // metadata in an attempt to extract date and vcs commit metadata.
613 $canonicalVersion = '–';
614 $extensionPath = null;
619 if ( isset( $extension['version'] ) ) {
620 $canonicalVersion = $out->parseInline( $extension['version'] );
623 if ( isset( $extension['path'] ) ) {
625 if ( $this->coreId
== '' ) {
626 wfDebug( 'Looking up core head id' );
627 $coreHeadSHA1 = self
::getGitHeadSha1( $IP );
628 if ( $coreHeadSHA1 ) {
629 $this->coreId
= $coreHeadSHA1;
631 $svnInfo = self
::getSvnInfo( $IP );
632 if ( $svnInfo !== false ) {
633 $this->coreId
= $svnInfo['checkout-rev'];
637 $cache = wfGetCache( CACHE_ANYTHING
);
638 $memcKey = wfMemcKey( 'specialversion-ext-version-text', $extension['path'], $this->coreId
);
639 list( $vcsVersion, $vcsLink, $vcsDate ) = $cache->get( $memcKey );
641 if ( !$vcsVersion ) {
642 wfDebug( "Getting VCS info for extension $extensionName" );
643 $extensionPath = dirname( $extension['path'] );
644 $gitInfo = new GitInfo( $extensionPath );
645 $vcsVersion = $gitInfo->getHeadSHA1();
646 if ( $vcsVersion !== false ) {
647 $vcsVersion = substr( $vcsVersion, 0, 7 );
648 $vcsLink = $gitInfo->getHeadViewUrl();
649 $vcsDate = $gitInfo->getHeadCommitDate();
651 $svnInfo = self
::getSvnInfo( $extensionPath );
652 if ( $svnInfo !== false ) {
653 $vcsVersion = $this->msg( 'version-svn-revision', $svnInfo['checkout-rev'] )->text();
654 $vcsLink = isset( $svnInfo['viewvc-url'] ) ?
$svnInfo['viewvc-url'] : '';
657 $cache->set( $memcKey, array( $vcsVersion, $vcsLink, $vcsDate ), 60 * 60 * 24 );
659 wfDebug( "Pulled VCS info for extension $extensionName from cache" );
663 $versionString = Html
::rawElement(
665 array( 'class' => 'mw-version-ext-version' ),
671 $vcsVerString = Linker
::makeExternalLink(
673 $this->msg( 'version-version', $vcsVersion ),
676 array( 'class' => 'mw-version-ext-vcs-version' )
679 $vcsVerString = Html
::element( 'span',
680 array( 'class' => 'mw-version-ext-vcs-version' ),
684 $versionString .= " {$vcsVerString}";
687 $vcsTimeString = Html
::element( 'span',
688 array( 'class' => 'mw-version-ext-vcs-timestamp' ),
689 $this->getLanguage()->timeanddate( $vcsDate )
691 $versionString .= " {$vcsTimeString}";
693 $versionString = Html
::rawElement( 'span',
694 array( 'class' => 'mw-version-ext-meta-version' ),
699 // ... and license information; if a license file exists we
702 if ( isset( $extension['license-name'] ) ) {
703 $licenseLink = Linker
::link(
704 $this->getPageTitle( 'License/' . $extensionName ),
705 $out->parseInline( $extension['license-name'] ),
706 array( 'class' => 'mw-version-ext-license' )
708 } elseif ( $this->getExtLicenseFileName( $extensionPath ) ) {
709 $licenseLink = Linker
::link(
710 $this->getPageTitle( 'License/' . $extensionName ),
711 $this->msg( 'version-ext-license' ),
712 array( 'class' => 'mw-version-ext-license' )
716 // ... and generate the description; which can be a parameterized l10n message
717 // in the form array( <msgname>, <parameter>, <parameter>... ) or just a straight
719 if ( isset( $extension['descriptionmsg'] ) ) {
720 // Localized description of extension
721 $descriptionMsg = $extension['descriptionmsg'];
723 if ( is_array( $descriptionMsg ) ) {
724 $descriptionMsgKey = $descriptionMsg[0]; // Get the message key
725 array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
726 array_map( "htmlspecialchars", $descriptionMsg ); // For sanity
727 $description = $this->msg( $descriptionMsgKey, $descriptionMsg )->text();
729 $description = $this->msg( $descriptionMsg )->text();
731 } elseif ( isset( $extension['description'] ) ) {
732 // Non localized version
733 $description = $extension['description'];
737 $description = $out->parseInline( $description );
739 // ... now get the authors for this extension
740 $authors = isset( $extension['author'] ) ?
$extension['author'] : array();
741 $authors = $this->listAuthors( $authors, $extensionName, $extensionPath );
743 // Finally! Create the table
744 $html = Html
::openElement( 'tr', array(
745 'class' => 'mw-version-ext',
746 'id' => "mw-version-ext-{$extensionName}"
750 $html .= Html
::rawElement( 'td', array(), $extensionNameLink );
751 $html .= Html
::rawElement( 'td', array(), $versionString );
752 $html .= Html
::rawElement( 'td', array(), $licenseLink );
753 $html .= Html
::rawElement( 'td', array( 'class' => 'mw-version-ext-description' ), $description );
754 $html .= Html
::rawElement( 'td', array( 'class' => 'mw-version-ext-authors' ), $authors );
756 $html .= Html
::closeElement( 'td' );
762 * Generate wikitext showing hooks in $wgHooks.
764 * @return string Wikitext
766 private function getWgHooks() {
767 global $wgSpecialVersionShowHooks, $wgHooks;
769 if ( $wgSpecialVersionShowHooks && count( $wgHooks ) ) {
770 $myWgHooks = $wgHooks;
774 $ret[] = '== {{int:version-hooks}} ==';
775 $ret[] = Html
::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-hooks' ) );
776 $ret[] = Html
::openElement( 'tr' );
777 $ret[] = Html
::element( 'th', array(), $this->msg( 'version-hook-name' )->text() );
778 $ret[] = Html
::element( 'th', array(), $this->msg( 'version-hook-subscribedby' )->text() );
779 $ret[] = Html
::closeElement( 'tr' );
781 foreach ( $myWgHooks as $hook => $hooks ) {
782 $ret[] = Html
::openElement( 'tr' );
783 $ret[] = Html
::element( 'td', array(), $hook );
784 $ret[] = Html
::element( 'td', array(), $this->listToText( $hooks ) );
785 $ret[] = Html
::closeElement( 'tr' );
788 $ret[] = Html
::closeElement( 'table' );
790 return implode( "\n", $ret );
796 private function openExtType( $text, $name = null ) {
799 $opt = array( 'colspan' => 5 );
800 if ( $this->firstExtOpened
) {
801 // Insert a spacing line
802 $out .= Html
::rawElement( 'tr', array( 'class' => 'sv-space' ),
803 Html
::element( 'td', $opt )
806 $this->firstExtOpened
= true;
809 $opt['id'] = "sv-$name";
812 $out .= Html
::rawElement( 'tr', array(),
813 Html
::element( 'th', $opt, $text )
816 $out .= Html
::openElement( 'tr' );
817 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
818 $this->msg( 'version-ext-colheader-name' )->text() );
819 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
820 $this->msg( 'version-ext-colheader-version' )->text() );
821 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
822 $this->msg( 'version-ext-colheader-license' )->text() );
823 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
824 $this->msg( 'version-ext-colheader-description' )->text() );
825 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
826 $this->msg( 'version-ext-colheader-credits' )->text() );
827 $out .= Html
::closeElement( 'tr' );
833 * Get information about client's IP address.
835 * @return string HTML fragment
837 private function IPInfo() {
838 $ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) );
840 return "<!-- visited from $ip -->\n<span style='display:none'>visited from $ip</span>";
844 * Return a formatted unsorted list of authors
847 * If an item in the $authors array is '...' it is assumed to indicate an
848 * 'and others' string which will then be linked to an ((AUTHORS)|(CREDITS))(\.txt)?
849 * file if it exists in $dir.
851 * Similarly an entry ending with ' ...]' is assumed to be a link to an
854 * If no '...' string variant is found, but an authors file is found an
855 * 'and others' will be added to the end of the credits.
857 * @param string|array $authors
858 * @param string $extName Name of the extension for link creation
859 * @param string $extDir Path to the extension root directory
861 * @return string HTML fragment
863 function listAuthors( $authors, $extName, $extDir ) {
867 foreach ( (array)$authors as $item ) {
868 if ( $item == '...' ) {
871 if ( $this->getExtAuthorsFileName( $extDir ) ) {
872 $text = Linker
::link(
873 $this->getPageTitle( "Credits/$extName" ),
874 $this->msg( 'version-poweredby-others' )->text()
877 $text = $this->msg( 'version-poweredby-others' )->text();
880 } elseif ( substr( $item, -5 ) == ' ...]' ) {
882 $list[] = $this->getOutput()->parseInline(
883 substr( $item, 0, -4 ) . $this->msg( 'version-poweredby-others' )->text() . "]"
886 $list[] = $this->getOutput()->parseInline( $item );
890 if ( !$hasOthers && $this->getExtAuthorsFileName( $extDir ) ) {
891 $list[] = $text = Linker
::link(
892 $this->getPageTitle( "Credits/$extName" ),
893 $this->msg( 'version-poweredby-others' )->text()
897 return $this->listToText( $list, false );
901 * Obtains the full path of an extensions authors or credits file if
904 * @param string $extDir Path to the extensions root directory
908 * @return bool|string False if no such file exists, otherwise returns
911 public static function getExtAuthorsFileName( $extDir ) {
916 foreach ( scandir( $extDir ) as $file ) {
917 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
918 if ( preg_match( '/^((AUTHORS)|(CREDITS))(\.txt)?$/', $file ) &&
919 is_readable( $fullPath ) &&
930 * Obtains the full path of an extensions copying or license file if
933 * @param string $extDir Path to the extensions root directory
937 * @return bool|string False if no such file exists, otherwise returns
940 public static function getExtLicenseFileName( $extDir ) {
945 foreach ( scandir( $extDir ) as $file ) {
946 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
947 if ( preg_match( '/^((COPYING)|(LICENSE))(\.txt)?$/', $file ) &&
948 is_readable( $fullPath ) &&
959 * Convert an array of items into a list for display.
961 * @param array $list List of elements to display
962 * @param bool $sort Whether to sort the items in $list
966 function listToText( $list, $sort = true ) {
967 $cnt = count( $list );
970 // Enforce always returning a string
971 return (string)self
::arrayToString( $list[0] );
972 } elseif ( $cnt == 0 ) {
979 return $this->getLanguage()
980 ->listToText( array_map( array( __CLASS__
, 'arrayToString' ), $list ) );
985 * Convert an array or object to a string for display.
987 * @param mixed $list will convert an array to string if given and return
988 * the paramater unaltered otherwise
992 public static function arrayToString( $list ) {
993 if ( is_array( $list ) && count( $list ) == 1 ) {
996 if ( is_object( $list ) ) {
997 $class = wfMessage( 'parentheses' )->params( get_class( $list ) )->escaped();
1000 } elseif ( !is_array( $list ) ) {
1003 if ( is_object( $list[0] ) ) {
1004 $class = get_class( $list[0] );
1009 return wfMessage( 'parentheses' )->params( "$class, {$list[1]}" )->escaped();
1014 * Get an associative array of information about a given path, from its .svn
1015 * subdirectory. Returns false on error, such as if the directory was not
1016 * checked out with subversion.
1018 * Returned keys are:
1020 * checkout-rev The revision which was checked out
1022 * directory-rev The revision when the directory was last modified
1023 * url The subversion URL of the directory
1024 * repo-url The base URL of the repository
1025 * viewvc-url A ViewVC URL pointing to the checked-out revision
1026 * @param $dir string
1027 * @return array|bool
1029 public static function getSvnInfo( $dir ) {
1030 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
1031 $entries = $dir . '/.svn/entries';
1033 if ( !file_exists( $entries ) ) {
1037 $lines = file( $entries );
1038 if ( !count( $lines ) ) {
1042 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
1043 if ( preg_match( '/^<\?xml/', $lines[0] ) ) {
1044 // subversion is release <= 1.3
1045 if ( !function_exists( 'simplexml_load_file' ) ) {
1046 // We could fall back to expat... YUCK
1050 // SimpleXml whines about the xmlns...
1051 wfSuppressWarnings();
1052 $xml = simplexml_load_file( $entries );
1053 wfRestoreWarnings();
1056 foreach ( $xml->entry
as $entry ) {
1057 if ( $xml->entry
[0]['name'] == '' ) {
1058 // The directory entry should always have a revision marker.
1059 if ( $entry['revision'] ) {
1060 return array( 'checkout-rev' => intval( $entry['revision'] ) );
1069 // Subversion is release 1.4 or above.
1070 if ( count( $lines ) < 11 ) {
1075 'checkout-rev' => intval( trim( $lines[3] ) ),
1076 'url' => trim( $lines[4] ),
1077 'repo-url' => trim( $lines[5] ),
1078 'directory-rev' => intval( trim( $lines[10] ) )
1081 if ( isset( self
::$viewvcUrls[$info['repo-url']] ) ) {
1082 $viewvc = str_replace(
1084 self
::$viewvcUrls[$info['repo-url']],
1088 $viewvc .= '/?pathrev=';
1089 $viewvc .= urlencode( $info['checkout-rev'] );
1090 $info['viewvc-url'] = $viewvc;
1097 * Retrieve the revision number of a Subversion working directory.
1099 * @param string $dir directory of the svn checkout
1101 * @return int Revision number
1103 public static function getSvnRevision( $dir ) {
1104 $info = self
::getSvnInfo( $dir );
1106 if ( $info === false ) {
1108 } elseif ( isset( $info['checkout-rev'] ) ) {
1109 return $info['checkout-rev'];
1116 * @param string $dir directory of the git checkout
1117 * @return bool|String sha1 of commit HEAD points to
1119 public static function getGitHeadSha1( $dir ) {
1120 $repo = new GitInfo( $dir );
1122 return $repo->getHeadSHA1();
1126 * Get the list of entry points and their URLs
1127 * @return string Wikitext
1129 public function getEntryPointInfo() {
1130 global $wgArticlePath, $wgScriptPath;
1131 $scriptPath = $wgScriptPath ?
$wgScriptPath : "/";
1132 $entryPoints = array(
1133 'version-entrypoints-articlepath' => $wgArticlePath,
1134 'version-entrypoints-scriptpath' => $scriptPath,
1135 'version-entrypoints-index-php' => wfScript( 'index' ),
1136 'version-entrypoints-api-php' => wfScript( 'api' ),
1137 'version-entrypoints-load-php' => wfScript( 'load' ),
1140 $language = $this->getLanguage();
1141 $thAttribures = array(
1142 'dir' => $language->getDir(),
1143 'lang' => $language->getCode()
1145 $out = Html
::element(
1147 array( 'id' => 'mw-version-entrypoints' ),
1148 $this->msg( 'version-entrypoints' )->text()
1150 Html
::openElement( 'table',
1152 'class' => 'wikitable plainlinks',
1153 'id' => 'mw-version-entrypoints-table',
1158 Html
::openElement( 'tr' ) .
1162 $this->msg( 'version-entrypoints-header-entrypoint' )->text()
1167 $this->msg( 'version-entrypoints-header-url' )->text()
1169 Html
::closeElement( 'tr' );
1171 foreach ( $entryPoints as $message => $value ) {
1172 $url = wfExpandUrl( $value, PROTO_RELATIVE
);
1173 $out .= Html
::openElement( 'tr' ) .
1174 // ->text() looks like it should be ->parse(), but this function
1175 // returns wikitext, not HTML, boo
1176 Html
::rawElement( 'td', array(), $this->msg( $message )->text() ) .
1177 Html
::rawElement( 'td', array(), Html
::rawElement( 'code', array(), "[$url $value]" ) ) .
1178 Html
::closeElement( 'tr' );
1181 $out .= Html
::closeElement( 'table' );
1186 protected function getGroupName() {