Support offsets in prefix searching
[mediawiki.git] / includes / specials / SpecialVersion.php
blob34f434f6f7930a251eeff6fd3ffc20c792cc1a6c
1 <?php
2 /**
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
22 * @file
23 * @ingroup SpecialPage
26 /**
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;
34 /**
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' );
51 /**
52 * main()
53 * @param string|null $par
55 public function execute( $par ) {
56 global $IP, $wgExtensionCredits;
58 $this->setHeaders();
59 $this->outputHeader();
60 $out = $this->getOutput();
61 $out->allowClickjacking();
63 // Explode the sub page information into useful bits
64 $parts = explode( '/', (string)$par );
65 $extNode = null;
66 if ( isset( $parts[1] ) ) {
67 $extName = str_replace( '_', ' ', $parts[1] );
68 // Find it!
69 foreach ( $wgExtensionCredits as $group => $extensions ) {
70 foreach ( $extensions as $ext ) {
71 if ( isset( $ext['name'] ) && ( $ext['name'] === $extName ) ) {
72 $extNode = &$ext;
73 break 2;
77 if ( !$extNode ) {
78 $out->setStatusCode( 404 );
80 } else {
81 $extName = 'MediaWiki';
84 // Now figure out what to do
85 switch ( strtolower( $parts[0] ) ) {
86 case 'credits':
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'] ) );
92 if ( $file ) {
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 );
102 break;
104 case 'license':
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'] ) );
110 if ( $file ) {
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 );
123 break;
125 default:
126 $out->addModules( 'mediawiki.special.version' );
127 $out->addWikiText(
128 $this->getMediaWikiCredits() .
129 $this->softwareInformation() .
130 $this->getEntryPointInfo()
132 $out->addHtml(
133 $this->getSkinCredits() .
134 $this->getExtensionCredits() .
135 $this->getParserTags() .
136 $this->getParserFunctionHooks()
138 $out->addWikiText( $this->getWgHooks() );
139 $out->addHTML( $this->IPInfo() );
141 break;
146 * Returns wiki text showing the license information.
148 * @return string
150 private static function getMediaWikiCredits() {
151 $ret = Xml::element(
152 'h2',
153 array( 'id' => 'mw-version-license' ),
154 wfMessage( 'version-license' )->text()
157 // This text is always left-to-right.
158 $ret .= '<div class="plainlinks">';
159 $ret .= "__NOTOC__
160 " . self::getCopyrightAndAuthorList() . "\n
161 " . wfMessage( 'version-license-info' )->text();
162 $ret .= '</div>';
164 return str_replace( "\t\t", '', $ret ) . "\n";
168 * Get the "MediaWiki is copyright 2001-20xx by lots of cool guys" text
170 * @return string
172 public static function getCopyrightAndAuthorList() {
173 global $wgLang;
175 if ( defined( 'MEDIAWIKI_INSTALL' ) ) {
176 $othersLink = '[//www.mediawiki.org/wiki/Special:Version/Credits ' .
177 wfMessage( 'version-poweredby-others' )->text() . ']';
178 } else {
179 $othersLink = '[[Special:Version/Credits|' .
180 wfMessage( 'version-poweredby-others' )->text() . ']]';
183 $translatorsLink = '[//translatewiki.net/wiki/Translating:MediaWiki/Credits ' .
184 wfMessage( 'version-poweredby-translators' )->text() . ']';
186 $authorList = array(
187 'Magnus Manske', 'Brion Vibber', 'Lee Daniel Crocker',
188 'Tim Starling', 'Erik Möller', 'Gabriel Wicke', 'Ævar Arnfjörð Bjarmason',
189 'Niklas Laxström', 'Domas Mituzas', 'Rob Church', 'Yuri Astrakhan',
190 'Aryeh Gregor', 'Aaron Schulz', 'Andrew Garrett', 'Raimond Spekking',
191 'Alexandre Emsenhuber', 'Siebrand Mazeland', 'Chad Horohoe',
192 'Roan Kattouw', 'Trevor Parscal', 'Bryan Tong Minh', 'Sam Reed',
193 'Victor Vasiliev', 'Rotem Liss', 'Platonides', 'Antoine Musso',
194 'Timo Tijhof', 'Daniel Kinzler', 'Jeroen De Dauw', 'Brad Jorsch',
195 $othersLink, $translatorsLink
198 return wfMessage( 'version-poweredby-credits', MWTimestamp::getLocalInstance()->format( 'Y' ),
199 $wgLang->listToText( $authorList ) )->text();
203 * Returns wiki text showing the third party software versions (apache, php, mysql).
205 * @return string
207 public static function softwareInformation() {
208 $dbr = wfGetDB( DB_SLAVE );
210 // Put the software in an array of form 'name' => 'version'. All messages should
211 // be loaded here, so feel free to use wfMessage in the 'name'. Raw HTML or
212 // wikimarkup can be used.
213 $software = array();
214 $software['[https://www.mediawiki.org/ MediaWiki]'] = self::getVersionLinked();
215 if ( wfIsHHVM() ) {
216 $software['[http://hhvm.com/ HHVM]'] = HHVM_VERSION . " (" . PHP_SAPI . ")";
217 } else {
218 $software['[https://php.net/ PHP]'] = PHP_VERSION . " (" . PHP_SAPI . ")";
220 $software[$dbr->getSoftwareLink()] = $dbr->getServerInfo();
222 // Allow a hook to add/remove items.
223 wfRunHooks( 'SoftwareInfo', array( &$software ) );
225 $out = Xml::element(
226 'h2',
227 array( 'id' => 'mw-version-software' ),
228 wfMessage( 'version-software' )->text()
230 Xml::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-software' ) ) .
231 "<tr>
232 <th>" . wfMessage( 'version-software-product' )->text() . "</th>
233 <th>" . wfMessage( 'version-software-version' )->text() . "</th>
234 </tr>\n";
236 foreach ( $software as $name => $version ) {
237 $out .= "<tr>
238 <td>" . $name . "</td>
239 <td dir=\"ltr\">" . $version . "</td>
240 </tr>\n";
243 return $out . Xml::closeElement( 'table' );
247 * Return a string of the MediaWiki version with SVN revision if available.
249 * @param string $flags
250 * @return mixed
252 public static function getVersion( $flags = '' ) {
253 global $wgVersion, $IP;
254 wfProfileIn( __METHOD__ );
256 $gitInfo = self::getGitHeadSha1( $IP );
257 $svnInfo = self::getSvnInfo( $IP );
258 if ( !$svnInfo && !$gitInfo ) {
259 $version = $wgVersion;
260 } elseif ( $gitInfo && $flags === 'nodb' ) {
261 $shortSha1 = substr( $gitInfo, 0, 7 );
262 $version = "$wgVersion ($shortSha1)";
263 } elseif ( $gitInfo ) {
264 $shortSha1 = substr( $gitInfo, 0, 7 );
265 $shortSha1 = wfMessage( 'parentheses' )->params( $shortSha1 )->escaped();
266 $version = "$wgVersion $shortSha1";
267 } elseif ( $flags === 'nodb' ) {
268 $version = "$wgVersion (r{$svnInfo['checkout-rev']})";
269 } else {
270 $version = $wgVersion . ' ' .
271 wfMessage(
272 'version-svn-revision',
273 isset( $info['directory-rev'] ) ? $info['directory-rev'] : '',
274 $info['checkout-rev']
275 )->text();
278 wfProfileOut( __METHOD__ );
280 return $version;
284 * Return a wikitext-formatted string of the MediaWiki version with a link to
285 * the SVN revision or the git SHA1 of head if available.
286 * Git is prefered over Svn
287 * The fallback is just $wgVersion
289 * @return mixed
291 public static function getVersionLinked() {
292 global $wgVersion;
293 wfProfileIn( __METHOD__ );
295 $gitVersion = self::getVersionLinkedGit();
296 if ( $gitVersion ) {
297 $v = $gitVersion;
298 } else {
299 $svnVersion = self::getVersionLinkedSvn();
300 if ( $svnVersion ) {
301 $v = $svnVersion;
302 } else {
303 $v = $wgVersion; // fallback
307 wfProfileOut( __METHOD__ );
309 return $v;
313 * @return string Global wgVersion + a link to subversion revision of svn BASE
315 private static function getVersionLinkedSvn() {
316 global $IP;
318 $info = self::getSvnInfo( $IP );
319 if ( !isset( $info['checkout-rev'] ) ) {
320 return false;
323 $linkText = wfMessage(
324 'version-svn-revision',
325 isset( $info['directory-rev'] ) ? $info['directory-rev'] : '',
326 $info['checkout-rev']
327 )->text();
329 if ( isset( $info['viewvc-url'] ) ) {
330 $version = "[{$info['viewvc-url']} $linkText]";
331 } else {
332 $version = $linkText;
335 return self::getwgVersionLinked() . " $version";
339 * @return string
341 private static function getwgVersionLinked() {
342 global $wgVersion;
343 $versionUrl = "";
344 if ( wfRunHooks( 'SpecialVersionVersionUrl', array( $wgVersion, &$versionUrl ) ) ) {
345 $versionParts = array();
346 preg_match( "/^(\d+\.\d+)/", $wgVersion, $versionParts );
347 $versionUrl = "https://www.mediawiki.org/wiki/MediaWiki_{$versionParts[1]}";
350 return "[$versionUrl $wgVersion]";
354 * @since 1.22 Returns the HEAD date in addition to the sha1 and link
355 * @return bool|string Global wgVersion + HEAD sha1 stripped to the first 7 chars
356 * with link and date, or false on failure
358 private static function getVersionLinkedGit() {
359 global $IP, $wgLang;
361 $gitInfo = new GitInfo( $IP );
362 $headSHA1 = $gitInfo->getHeadSHA1();
363 if ( !$headSHA1 ) {
364 return false;
367 $shortSHA1 = '(' . substr( $headSHA1, 0, 7 ) . ')';
369 $gitHeadUrl = $gitInfo->getHeadViewUrl();
370 if ( $gitHeadUrl !== false ) {
371 $shortSHA1 = "[$gitHeadUrl $shortSHA1]";
374 $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
375 if ( $gitHeadCommitDate ) {
376 $shortSHA1 .= Html::element( 'br' ) . $wgLang->timeanddate( $gitHeadCommitDate, true );
379 return self::getwgVersionLinked() . " $shortSHA1";
383 * Returns an array with the base extension types.
384 * Type is stored as array key, the message as array value.
386 * TODO: ideally this would return all extension types.
388 * @since 1.17
390 * @return array
392 public static function getExtensionTypes() {
393 if ( self::$extensionTypes === false ) {
394 self::$extensionTypes = array(
395 'specialpage' => wfMessage( 'version-specialpages' )->text(),
396 'parserhook' => wfMessage( 'version-parserhooks' )->text(),
397 'variable' => wfMessage( 'version-variables' )->text(),
398 'media' => wfMessage( 'version-mediahandlers' )->text(),
399 'antispam' => wfMessage( 'version-antispam' )->text(),
400 'skin' => wfMessage( 'version-skins' )->text(),
401 'api' => wfMessage( 'version-api' )->text(),
402 'other' => wfMessage( 'version-other' )->text(),
405 wfRunHooks( 'ExtensionTypes', array( &self::$extensionTypes ) );
408 return self::$extensionTypes;
412 * Returns the internationalized name for an extension type.
414 * @since 1.17
416 * @param string $type
418 * @return string
420 public static function getExtensionTypeName( $type ) {
421 $types = self::getExtensionTypes();
423 return isset( $types[$type] ) ? $types[$type] : $types['other'];
427 * Generate wikitext showing the name, URL, author and description of each extension.
429 * @return string Wikitext
431 public function getExtensionCredits() {
432 global $wgExtensionCredits;
434 if (
435 count( $wgExtensionCredits ) === 0 ||
436 // Skins are displayed separately, see getSkinCredits()
437 ( count( $wgExtensionCredits ) === 1 && isset( $wgExtensionCredits['skin'] ) )
439 return '';
442 $extensionTypes = self::getExtensionTypes();
444 $out = Xml::element(
445 'h2',
446 array( 'id' => 'mw-version-ext' ),
447 $this->msg( 'version-extensions' )->text()
449 Xml::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-ext' ) );
451 // Make sure the 'other' type is set to an array.
452 if ( !array_key_exists( 'other', $wgExtensionCredits ) ) {
453 $wgExtensionCredits['other'] = array();
456 // Find all extensions that do not have a valid type and give them the type 'other'.
457 foreach ( $wgExtensionCredits as $type => $extensions ) {
458 if ( !array_key_exists( $type, $extensionTypes ) ) {
459 $wgExtensionCredits['other'] = array_merge( $wgExtensionCredits['other'], $extensions );
463 $this->firstExtOpened = false;
464 // Loop through the extension categories to display their extensions in the list.
465 foreach ( $extensionTypes as $type => $message ) {
466 // Skins have a separate section
467 if ( $type !== 'other' && $type !== 'skin' ) {
468 $out .= $this->getExtensionCategory( $type, $message );
472 // We want the 'other' type to be last in the list.
473 $out .= $this->getExtensionCategory( 'other', $extensionTypes['other'] );
475 $out .= Xml::closeElement( 'table' );
477 return $out;
481 * Generate wikitext showing the name, URL, author and description of each skin.
483 * @return string Wikitext
485 public function getSkinCredits() {
486 global $wgExtensionCredits;
487 if ( !isset( $wgExtensionCredits['skin'] ) || count( $wgExtensionCredits['skin'] ) === 0 ) {
488 return '';
491 $out = Xml::element(
492 'h2',
493 array( 'id' => 'mw-version-skin' ),
494 $this->msg( 'version-skins' )->text()
496 Xml::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-skin' ) );
498 $this->firstExtOpened = false;
499 $out .= $this->getExtensionCategory( 'skin', null );
501 $out .= Xml::closeElement( 'table' );
503 return $out;
507 * Obtains a list of installed parser tags and the associated H2 header
509 * @return string HTML output
511 protected function getParserTags() {
512 global $wgParser;
514 $tags = $wgParser->getTags();
516 if ( count( $tags ) ) {
517 $out = Html::rawElement(
518 'h2',
519 array( 'class' => 'mw-headline' ),
520 Linker::makeExternalLink(
521 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Tag_extensions',
522 $this->msg( 'version-parser-extensiontags' )->parse(),
523 false /* msg()->parse() already escapes */
527 array_walk( $tags, function ( &$value ) {
528 // Bidirectional isolation improves readability in RTL wikis
529 $value = Html::element(
530 'bdi',
531 // Prevent < and > from slipping to another line
532 array(
533 'style' => 'white-space: nowrap;',
535 "<$value>"
537 } );
539 $out .= $this->listToText( $tags );
540 } else {
541 $out = '';
544 return $out;
548 * Obtains a list of installed parser function hooks and the associated H2 header
550 * @return string HTML output
552 protected function getParserFunctionHooks() {
553 global $wgParser;
555 $fhooks = $wgParser->getFunctionHooks();
556 if ( count( $fhooks ) ) {
557 $out = Html::rawElement( 'h2', array( 'class' => 'mw-headline' ), Linker::makeExternalLink(
558 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Parser_functions',
559 $this->msg( 'version-parser-function-hooks' )->parse(),
560 false /* msg()->parse() already escapes */
561 ) );
563 $out .= $this->listToText( $fhooks );
564 } else {
565 $out = '';
568 return $out;
572 * Creates and returns the HTML for a single extension category.
574 * @since 1.17
576 * @param string $type
577 * @param string $message
579 * @return string
581 protected function getExtensionCategory( $type, $message ) {
582 global $wgExtensionCredits;
584 $out = '';
586 if ( array_key_exists( $type, $wgExtensionCredits ) && count( $wgExtensionCredits[$type] ) > 0 ) {
587 $out .= $this->openExtType( $message, 'credits-' . $type );
589 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
591 foreach ( $wgExtensionCredits[$type] as $extension ) {
592 $out .= $this->getCreditsForExtension( $extension );
596 return $out;
600 * Callback to sort extensions by type.
601 * @param array $a
602 * @param array $b
603 * @return int
605 public function compare( $a, $b ) {
606 if ( $a['name'] === $b['name'] ) {
607 return 0;
608 } else {
609 return $this->getLanguage()->lc( $a['name'] ) > $this->getLanguage()->lc( $b['name'] )
611 : -1;
616 * Creates and formats a version line for a single extension.
618 * Information for five columns will be created. Parameters required in the
619 * $extension array for part rendering are indicated in ()
620 * - The name of (name), and URL link to (url), the extension
621 * - Official version number (version) and if available version control system
622 * revision (path), link, and date
623 * - If available the short name of the license (license-name) and a linke
624 * to ((LICENSE)|(COPYING))(\.txt)? if it exists.
625 * - Description of extension (descriptionmsg or description)
626 * - List of authors (author) and link to a ((AUTHORS)|(CREDITS))(\.txt)? file if it exists
628 * @param array $extension
630 * @return string Raw HTML
632 public function getCreditsForExtension( array $extension ) {
633 $out = $this->getOutput();
635 // We must obtain the information for all the bits and pieces!
636 // ... such as extension names and links
637 if ( isset( $extension['namemsg'] ) ) {
638 // Localized name of extension
639 $extensionName = $this->msg( $extension['namemsg'] )->text();
640 } elseif ( isset( $extension['name'] ) ) {
641 // Non localized version
642 $extensionName = $extension['name'];
643 } else {
644 $extensionName = $this->msg( 'version-no-ext-name' )->text();
647 if ( isset( $extension['url'] ) ) {
648 $extensionNameLink = Linker::makeExternalLink(
649 $extension['url'],
650 $extensionName,
651 true,
653 array( 'class' => 'mw-version-ext-name' )
655 } else {
656 $extensionNameLink = $extensionName;
659 // ... and the version information
660 // If the extension path is set we will check that directory for GIT and SVN
661 // metadata in an attempt to extract date and vcs commit metadata.
662 $canonicalVersion = '&ndash;';
663 $extensionPath = null;
664 $vcsVersion = null;
665 $vcsLink = null;
666 $vcsDate = null;
668 if ( isset( $extension['version'] ) ) {
669 $canonicalVersion = $out->parseInline( $extension['version'] );
672 if ( isset( $extension['path'] ) ) {
673 global $IP;
674 $extensionPath = dirname( $extension['path'] );
675 if ( $this->coreId == '' ) {
676 wfDebug( 'Looking up core head id' );
677 $coreHeadSHA1 = self::getGitHeadSha1( $IP );
678 if ( $coreHeadSHA1 ) {
679 $this->coreId = $coreHeadSHA1;
680 } else {
681 $svnInfo = self::getSvnInfo( $IP );
682 if ( $svnInfo !== false ) {
683 $this->coreId = $svnInfo['checkout-rev'];
687 $cache = wfGetCache( CACHE_ANYTHING );
688 $memcKey = wfMemcKey( 'specialversion-ext-version-text', $extension['path'], $this->coreId );
689 list( $vcsVersion, $vcsLink, $vcsDate ) = $cache->get( $memcKey );
691 if ( !$vcsVersion ) {
692 wfDebug( "Getting VCS info for extension $extensionName" );
693 $gitInfo = new GitInfo( $extensionPath );
694 $vcsVersion = $gitInfo->getHeadSHA1();
695 if ( $vcsVersion !== false ) {
696 $vcsVersion = substr( $vcsVersion, 0, 7 );
697 $vcsLink = $gitInfo->getHeadViewUrl();
698 $vcsDate = $gitInfo->getHeadCommitDate();
699 } else {
700 $svnInfo = self::getSvnInfo( $extensionPath );
701 if ( $svnInfo !== false ) {
702 $vcsVersion = $this->msg( 'version-svn-revision', $svnInfo['checkout-rev'] )->text();
703 $vcsLink = isset( $svnInfo['viewvc-url'] ) ? $svnInfo['viewvc-url'] : '';
706 $cache->set( $memcKey, array( $vcsVersion, $vcsLink, $vcsDate ), 60 * 60 * 24 );
707 } else {
708 wfDebug( "Pulled VCS info for extension $extensionName from cache" );
712 $versionString = Html::rawElement(
713 'span',
714 array( 'class' => 'mw-version-ext-version' ),
715 $canonicalVersion
718 if ( $vcsVersion ) {
719 if ( $vcsLink ) {
720 $vcsVerString = Linker::makeExternalLink(
721 $vcsLink,
722 $this->msg( 'version-version', $vcsVersion ),
723 true,
725 array( 'class' => 'mw-version-ext-vcs-version' )
727 } else {
728 $vcsVerString = Html::element( 'span',
729 array( 'class' => 'mw-version-ext-vcs-version' ),
730 "({$vcsVersion})"
733 $versionString .= " {$vcsVerString}";
735 if ( $vcsDate ) {
736 $vcsTimeString = Html::element( 'span',
737 array( 'class' => 'mw-version-ext-vcs-timestamp' ),
738 $this->getLanguage()->timeanddate( $vcsDate, true )
740 $versionString .= " {$vcsTimeString}";
742 $versionString = Html::rawElement( 'span',
743 array( 'class' => 'mw-version-ext-meta-version' ),
744 $versionString
748 // ... and license information; if a license file exists we
749 // will link to it
750 $licenseLink = '';
751 if ( isset( $extension['license-name'] ) ) {
752 $licenseLink = Linker::link(
753 $this->getPageTitle( 'License/' . $extensionName ),
754 $out->parseInline( $extension['license-name'] ),
755 array(
756 'class' => 'mw-version-ext-license',
757 'dir' => 'auto',
760 } elseif ( $this->getExtLicenseFileName( $extensionPath ) ) {
761 $licenseLink = Linker::link(
762 $this->getPageTitle( 'License/' . $extensionName ),
763 $this->msg( 'version-ext-license' ),
764 array(
765 'class' => 'mw-version-ext-license',
766 'dir' => 'auto',
771 // ... and generate the description; which can be a parameterized l10n message
772 // in the form array( <msgname>, <parameter>, <parameter>... ) or just a straight
773 // up string
774 if ( isset( $extension['descriptionmsg'] ) ) {
775 // Localized description of extension
776 $descriptionMsg = $extension['descriptionmsg'];
778 if ( is_array( $descriptionMsg ) ) {
779 $descriptionMsgKey = $descriptionMsg[0]; // Get the message key
780 array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
781 array_map( "htmlspecialchars", $descriptionMsg ); // For sanity
782 $description = $this->msg( $descriptionMsgKey, $descriptionMsg )->text();
783 } else {
784 $description = $this->msg( $descriptionMsg )->text();
786 } elseif ( isset( $extension['description'] ) ) {
787 // Non localized version
788 $description = $extension['description'];
789 } else {
790 $description = '';
792 $description = $out->parseInline( $description );
794 // ... now get the authors for this extension
795 $authors = isset( $extension['author'] ) ? $extension['author'] : array();
796 $authors = $this->listAuthors( $authors, $extensionName, $extensionPath );
798 // Finally! Create the table
799 $html = Html::openElement( 'tr', array(
800 'class' => 'mw-version-ext',
801 'id' => "mw-version-ext-{$extensionName}"
805 $html .= Html::rawElement( 'td', array(), $extensionNameLink );
806 $html .= Html::rawElement( 'td', array(), $versionString );
807 $html .= Html::rawElement( 'td', array(), $licenseLink );
808 $html .= Html::rawElement( 'td', array( 'class' => 'mw-version-ext-description' ), $description );
809 $html .= Html::rawElement( 'td', array( 'class' => 'mw-version-ext-authors' ), $authors );
811 $html .= Html::closeElement( 'tr' );
813 return $html;
817 * Generate wikitext showing hooks in $wgHooks.
819 * @return string Wikitext
821 private function getWgHooks() {
822 global $wgSpecialVersionShowHooks, $wgHooks;
824 if ( $wgSpecialVersionShowHooks && count( $wgHooks ) ) {
825 $myWgHooks = $wgHooks;
826 ksort( $myWgHooks );
828 $ret = array();
829 $ret[] = '== {{int:version-hooks}} ==';
830 $ret[] = Html::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-hooks' ) );
831 $ret[] = Html::openElement( 'tr' );
832 $ret[] = Html::element( 'th', array(), $this->msg( 'version-hook-name' )->text() );
833 $ret[] = Html::element( 'th', array(), $this->msg( 'version-hook-subscribedby' )->text() );
834 $ret[] = Html::closeElement( 'tr' );
836 foreach ( $myWgHooks as $hook => $hooks ) {
837 $ret[] = Html::openElement( 'tr' );
838 $ret[] = Html::element( 'td', array(), $hook );
839 $ret[] = Html::element( 'td', array(), $this->listToText( $hooks ) );
840 $ret[] = Html::closeElement( 'tr' );
843 $ret[] = Html::closeElement( 'table' );
845 return implode( "\n", $ret );
846 } else {
847 return '';
851 private function openExtType( $text = null, $name = null ) {
852 $out = '';
854 $opt = array( 'colspan' => 5 );
855 if ( $this->firstExtOpened ) {
856 // Insert a spacing line
857 $out .= Html::rawElement( 'tr', array( 'class' => 'sv-space' ),
858 Html::element( 'td', $opt )
861 $this->firstExtOpened = true;
863 if ( $name ) {
864 $opt['id'] = "sv-$name";
867 if ( $text !== null ) {
868 $out .= Html::rawElement( 'tr', array(),
869 Html::element( 'th', $opt, $text )
873 $firstHeadingMsg = ( $name === 'credits-skin' )
874 ? 'version-skin-colheader-name'
875 : 'version-ext-colheader-name';
876 $out .= Html::openElement( 'tr' );
877 $out .= Html::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
878 $this->msg( $firstHeadingMsg )->text() );
879 $out .= Html::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
880 $this->msg( 'version-ext-colheader-version' )->text() );
881 $out .= Html::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
882 $this->msg( 'version-ext-colheader-license' )->text() );
883 $out .= Html::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
884 $this->msg( 'version-ext-colheader-description' )->text() );
885 $out .= Html::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
886 $this->msg( 'version-ext-colheader-credits' )->text() );
887 $out .= Html::closeElement( 'tr' );
889 return $out;
893 * Get information about client's IP address.
895 * @return string HTML fragment
897 private function IPInfo() {
898 $ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) );
900 return "<!-- visited from $ip -->\n<span style='display:none'>visited from $ip</span>";
904 * Return a formatted unsorted list of authors
906 * 'And Others'
907 * If an item in the $authors array is '...' it is assumed to indicate an
908 * 'and others' string which will then be linked to an ((AUTHORS)|(CREDITS))(\.txt)?
909 * file if it exists in $dir.
911 * Similarly an entry ending with ' ...]' is assumed to be a link to an
912 * 'and others' page.
914 * If no '...' string variant is found, but an authors file is found an
915 * 'and others' will be added to the end of the credits.
917 * @param string|array $authors
918 * @param string $extName Name of the extension for link creation
919 * @param string $extDir Path to the extension root directory
921 * @return string HTML fragment
923 public function listAuthors( $authors, $extName, $extDir ) {
924 $hasOthers = false;
926 $list = array();
927 foreach ( (array)$authors as $item ) {
928 if ( $item == '...' ) {
929 $hasOthers = true;
931 if ( $this->getExtAuthorsFileName( $extDir ) ) {
932 $text = Linker::link(
933 $this->getPageTitle( "Credits/$extName" ),
934 $this->msg( 'version-poweredby-others' )->text()
936 } else {
937 $text = $this->msg( 'version-poweredby-others' )->text();
939 $list[] = $text;
940 } elseif ( substr( $item, -5 ) == ' ...]' ) {
941 $hasOthers = true;
942 $list[] = $this->getOutput()->parseInline(
943 substr( $item, 0, -4 ) . $this->msg( 'version-poweredby-others' )->text() . "]"
945 } else {
946 $list[] = $this->getOutput()->parseInline( $item );
950 if ( !$hasOthers && $this->getExtAuthorsFileName( $extDir ) ) {
951 $list[] = $text = Linker::link(
952 $this->getPageTitle( "Credits/$extName" ),
953 $this->msg( 'version-poweredby-others' )->text()
957 return $this->listToText( $list, false );
961 * Obtains the full path of an extensions authors or credits file if
962 * one exists.
964 * @param string $extDir Path to the extensions root directory
966 * @since 1.23
968 * @return bool|string False if no such file exists, otherwise returns
969 * a path to it.
971 public static function getExtAuthorsFileName( $extDir ) {
972 if ( !$extDir ) {
973 return false;
976 foreach ( scandir( $extDir ) as $file ) {
977 $fullPath = $extDir . DIRECTORY_SEPARATOR . $file;
978 if ( preg_match( '/^((AUTHORS)|(CREDITS))(\.txt)?$/', $file ) &&
979 is_readable( $fullPath ) &&
980 is_file( $fullPath )
982 return $fullPath;
986 return false;
990 * Obtains the full path of an extensions copying or license file if
991 * one exists.
993 * @param string $extDir Path to the extensions root directory
995 * @since 1.23
997 * @return bool|string False if no such file exists, otherwise returns
998 * a path to it.
1000 public static function getExtLicenseFileName( $extDir ) {
1001 if ( !$extDir ) {
1002 return false;
1005 foreach ( scandir( $extDir ) as $file ) {
1006 $fullPath = $extDir . DIRECTORY_SEPARATOR . $file;
1007 if ( preg_match( '/^((COPYING)|(LICENSE))(\.txt)?$/', $file ) &&
1008 is_readable( $fullPath ) &&
1009 is_file( $fullPath )
1011 return $fullPath;
1015 return false;
1019 * Convert an array of items into a list for display.
1021 * @param array $list List of elements to display
1022 * @param bool $sort Whether to sort the items in $list
1024 * @return string
1026 public function listToText( $list, $sort = true ) {
1027 if ( !count( $list ) ) {
1028 return '';
1030 if ( $sort ) {
1031 sort( $list );
1034 return $this->getLanguage()
1035 ->listToText( array_map( array( __CLASS__, 'arrayToString' ), $list ) );
1039 * Convert an array or object to a string for display.
1041 * @param mixed $list Will convert an array to string if given and return
1042 * the paramater unaltered otherwise
1044 * @return mixed
1046 public static function arrayToString( $list ) {
1047 if ( is_array( $list ) && count( $list ) == 1 ) {
1048 $list = $list[0];
1050 if ( is_object( $list ) ) {
1051 $class = wfMessage( 'parentheses' )->params( get_class( $list ) )->escaped();
1053 return $class;
1054 } elseif ( !is_array( $list ) ) {
1055 return $list;
1056 } else {
1057 if ( is_object( $list[0] ) ) {
1058 $class = get_class( $list[0] );
1059 } else {
1060 $class = $list[0];
1063 return wfMessage( 'parentheses' )->params( "$class, {$list[1]}" )->escaped();
1068 * Get an associative array of information about a given path, from its .svn
1069 * subdirectory. Returns false on error, such as if the directory was not
1070 * checked out with subversion.
1072 * Returned keys are:
1073 * Required:
1074 * checkout-rev The revision which was checked out
1075 * Optional:
1076 * directory-rev The revision when the directory was last modified
1077 * url The subversion URL of the directory
1078 * repo-url The base URL of the repository
1079 * viewvc-url A ViewVC URL pointing to the checked-out revision
1080 * @param string $dir
1081 * @return array|bool
1083 public static function getSvnInfo( $dir ) {
1084 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
1085 $entries = $dir . '/.svn/entries';
1087 if ( !file_exists( $entries ) ) {
1088 return false;
1091 $lines = file( $entries );
1092 if ( !count( $lines ) ) {
1093 return false;
1096 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
1097 if ( preg_match( '/^<\?xml/', $lines[0] ) ) {
1098 // subversion is release <= 1.3
1099 if ( !function_exists( 'simplexml_load_file' ) ) {
1100 // We could fall back to expat... YUCK
1101 return false;
1104 // SimpleXml whines about the xmlns...
1105 wfSuppressWarnings();
1106 $xml = simplexml_load_file( $entries );
1107 wfRestoreWarnings();
1109 if ( $xml ) {
1110 foreach ( $xml->entry as $entry ) {
1111 if ( $xml->entry[0]['name'] == '' ) {
1112 // The directory entry should always have a revision marker.
1113 if ( $entry['revision'] ) {
1114 return array( 'checkout-rev' => intval( $entry['revision'] ) );
1120 return false;
1123 // Subversion is release 1.4 or above.
1124 if ( count( $lines ) < 11 ) {
1125 return false;
1128 $info = array(
1129 'checkout-rev' => intval( trim( $lines[3] ) ),
1130 'url' => trim( $lines[4] ),
1131 'repo-url' => trim( $lines[5] ),
1132 'directory-rev' => intval( trim( $lines[10] ) )
1135 if ( isset( self::$viewvcUrls[$info['repo-url']] ) ) {
1136 $viewvc = str_replace(
1137 $info['repo-url'],
1138 self::$viewvcUrls[$info['repo-url']],
1139 $info['url']
1142 $viewvc .= '/?pathrev=';
1143 $viewvc .= urlencode( $info['checkout-rev'] );
1144 $info['viewvc-url'] = $viewvc;
1147 return $info;
1151 * Retrieve the revision number of a Subversion working directory.
1153 * @param string $dir Directory of the svn checkout
1155 * @return int Revision number
1157 public static function getSvnRevision( $dir ) {
1158 $info = self::getSvnInfo( $dir );
1160 if ( $info === false ) {
1161 return false;
1162 } elseif ( isset( $info['checkout-rev'] ) ) {
1163 return $info['checkout-rev'];
1164 } else {
1165 return false;
1170 * @param string $dir Directory of the git checkout
1171 * @return bool|string Sha1 of commit HEAD points to
1173 public static function getGitHeadSha1( $dir ) {
1174 $repo = new GitInfo( $dir );
1176 return $repo->getHeadSHA1();
1180 * @param string $dir Directory of the git checkout
1181 * @return bool|string Branch currently checked out
1183 public static function getGitCurrentBranch( $dir ) {
1184 $repo = new GitInfo( $dir );
1185 return $repo->getCurrentBranch();
1189 * Get the list of entry points and their URLs
1190 * @return string Wikitext
1192 public function getEntryPointInfo() {
1193 global $wgArticlePath, $wgScriptPath;
1194 $scriptPath = $wgScriptPath ? $wgScriptPath : "/";
1195 $entryPoints = array(
1196 'version-entrypoints-articlepath' => $wgArticlePath,
1197 'version-entrypoints-scriptpath' => $scriptPath,
1198 'version-entrypoints-index-php' => wfScript( 'index' ),
1199 'version-entrypoints-api-php' => wfScript( 'api' ),
1200 'version-entrypoints-load-php' => wfScript( 'load' ),
1203 $language = $this->getLanguage();
1204 $thAttribures = array(
1205 'dir' => $language->getDir(),
1206 'lang' => $language->getHtmlCode()
1208 $out = Html::element(
1209 'h2',
1210 array( 'id' => 'mw-version-entrypoints' ),
1211 $this->msg( 'version-entrypoints' )->text()
1213 Html::openElement( 'table',
1214 array(
1215 'class' => 'wikitable plainlinks',
1216 'id' => 'mw-version-entrypoints-table',
1217 'dir' => 'ltr',
1218 'lang' => 'en'
1221 Html::openElement( 'tr' ) .
1222 Html::element(
1223 'th',
1224 $thAttribures,
1225 $this->msg( 'version-entrypoints-header-entrypoint' )->text()
1227 Html::element(
1228 'th',
1229 $thAttribures,
1230 $this->msg( 'version-entrypoints-header-url' )->text()
1232 Html::closeElement( 'tr' );
1234 foreach ( $entryPoints as $message => $value ) {
1235 $url = wfExpandUrl( $value, PROTO_RELATIVE );
1236 $out .= Html::openElement( 'tr' ) .
1237 // ->text() looks like it should be ->parse(), but this function
1238 // returns wikitext, not HTML, boo
1239 Html::rawElement( 'td', array(), $this->msg( $message )->text() ) .
1240 Html::rawElement( 'td', array(), Html::rawElement( 'code', array(), "[$url $value]" ) ) .
1241 Html::closeElement( 'tr' );
1244 $out .= Html::closeElement( 'table' );
1246 return $out;
1249 protected function getGroupName() {
1250 return 'wiki';