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;
34 protected static $extensionTypes = false;
36 protected static $viewvcUrls = array(
37 'svn+ssh://svn.wikimedia.org/svnroot/mediawiki' => 'http://svn.wikimedia.org/viewvc/mediawiki',
38 'http://svn.wikimedia.org/svnroot/mediawiki' => 'http://svn.wikimedia.org/viewvc/mediawiki',
39 'https://svn.wikimedia.org/svnroot/mediawiki' => 'https://svn.wikimedia.org/viewvc/mediawiki',
42 public function __construct() {
43 parent
::__construct( 'Version' );
49 public function execute( $par ) {
50 global $IP, $wgExtensionCredits;
53 $this->outputHeader();
54 $out = $this->getOutput();
55 $out->allowClickjacking();
57 // Explode the sub page information into useful bits
58 $parts = explode( '/', (string)$par );
60 if ( isset( $parts[1] ) ) {
61 $extName = str_replace( '_', ' ', $parts[1] );
63 foreach ( $wgExtensionCredits as $group => $extensions ) {
64 foreach ( $extensions as $ext ) {
65 if ( isset( $ext['name'] ) && ( $ext['name'] === $extName ) ) {
72 $out->setStatusCode( 404 );
75 $extName = 'MediaWiki';
78 // Now figure out what to do
79 switch ( strtolower( $parts[0] ) ) {
81 $wikiText = '{{int:version-credits-not-found}}';
82 if ( $extName === 'MediaWiki' ) {
83 $wikiText = file_get_contents( $IP . '/CREDITS' );
84 } elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) {
85 $file = $this->getExtAuthorsFileName( dirname( $extNode['path'] ) );
87 $wikiText = file_get_contents( $file );
88 if ( substr( $file, -4 ) === '.txt' ) {
89 $wikiText = Html
::element( 'pre', array(), $wikiText );
94 $out->setPageTitle( $this->msg( 'version-credits-title', $extName ) );
95 $out->addWikiText( $wikiText );
99 $wikiText = '{{int:version-license-not-found}}';
100 if ( $extName === 'MediaWiki' ) {
101 $wikiText = file_get_contents( $IP . '/COPYING' );
102 } elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) {
103 $file = $this->getExtLicenseFileName( dirname( $extNode['path'] ) );
105 $wikiText = file_get_contents( $file );
106 if ( !isset( $extNode['license-name'] ) ) {
107 // If the developer did not explicitly set license-name they probably
108 // are unaware that we're now sucking this file in and thus it's probably
109 // not wikitext friendly.
110 $wikiText = "<pre>$wikiText</pre>";
115 $out->setPageTitle( $this->msg( 'version-license-title', $extName ) );
116 $out->addWikiText( $wikiText );
120 $out->addModules( 'mediawiki.special.version' );
122 $this->getMediaWikiCredits() .
123 $this->softwareInformation() .
124 $this->getEntryPointInfo()
127 $this->getExtensionCredits() .
128 $this->getParserTags() .
129 $this->getParserFunctionHooks()
131 $out->addWikiText( $this->getWgHooks() );
132 $out->addHTML( $this->IPInfo() );
139 * Returns wiki text showing the license information.
143 private static function getMediaWikiCredits() {
146 array( 'id' => 'mw-version-license' ),
147 wfMessage( 'version-license' )->text()
150 // This text is always left-to-right.
151 $ret .= '<div class="plainlinks">';
153 " . self
::getCopyrightAndAuthorList() . "\n
154 " . wfMessage( 'version-license-info' )->text();
157 return str_replace( "\t\t", '', $ret ) . "\n";
161 * Get the "MediaWiki is copyright 2001-20xx by lots of cool guys" text
165 public static function getCopyrightAndAuthorList() {
168 if ( defined( 'MEDIAWIKI_INSTALL' ) ) {
169 $othersLink = '[//www.mediawiki.org/wiki/Special:Version/Credits ' .
170 wfMessage( 'version-poweredby-others' )->text() . ']';
172 $othersLink = '[[Special:Version/Credits|' .
173 wfMessage( 'version-poweredby-others' )->text() . ']]';
176 $translatorsLink = '[//translatewiki.net/wiki/Translating:MediaWiki/Credits ' .
177 wfMessage( 'version-poweredby-translators' )->text() . ']';
180 'Magnus Manske', 'Brion Vibber', 'Lee Daniel Crocker',
181 'Tim Starling', 'Erik Möller', 'Gabriel Wicke', 'Ævar Arnfjörð Bjarmason',
182 'Niklas Laxström', 'Domas Mituzas', 'Rob Church', 'Yuri Astrakhan',
183 'Aryeh Gregor', 'Aaron Schulz', 'Andrew Garrett', 'Raimond Spekking',
184 'Alexandre Emsenhuber', 'Siebrand Mazeland', 'Chad Horohoe',
185 'Roan Kattouw', 'Trevor Parscal', 'Bryan Tong Minh', 'Sam Reed',
186 'Victor Vasiliev', 'Rotem Liss', 'Platonides', 'Antoine Musso',
187 'Timo Tijhof', 'Daniel Kinzler', 'Jeroen De Dauw', $othersLink,
191 return wfMessage( 'version-poweredby-credits', MWTimestamp
::getLocalInstance()->format( 'Y' ),
192 $wgLang->listToText( $authorList ) )->text();
196 * Returns wiki text showing the third party software versions (apache, php, mysql).
200 static function softwareInformation() {
201 $dbr = wfGetDB( DB_SLAVE
);
203 // Put the software in an array of form 'name' => 'version'. All messages should
204 // be loaded here, so feel free to use wfMessage in the 'name'. Raw HTML or
205 // wikimarkup can be used.
207 $software['[https://www.mediawiki.org/ MediaWiki]'] = self
::getVersionLinked();
208 $software['[http://www.php.net/ PHP]'] = phpversion() . " (" . PHP_SAPI
. ")";
209 $software[$dbr->getSoftwareLink()] = $dbr->getServerInfo();
211 // Allow a hook to add/remove items.
212 wfRunHooks( 'SoftwareInfo', array( &$software ) );
216 array( 'id' => 'mw-version-software' ),
217 wfMessage( 'version-software' )->text()
219 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-software' ) ) .
221 <th>" . wfMessage( 'version-software-product' )->text() . "</th>
222 <th>" . wfMessage( 'version-software-version' )->text() . "</th>
225 foreach ( $software as $name => $version ) {
227 <td>" . $name . "</td>
228 <td dir=\"ltr\">" . $version . "</td>
232 return $out . Xml
::closeElement( 'table' );
236 * Return a string of the MediaWiki version with SVN revision if available.
238 * @param $flags String
241 public static function getVersion( $flags = '' ) {
242 global $wgVersion, $IP;
243 wfProfileIn( __METHOD__
);
245 $gitInfo = self
::getGitHeadSha1( $IP );
246 $svnInfo = self
::getSvnInfo( $IP );
247 if ( !$svnInfo && !$gitInfo ) {
248 $version = $wgVersion;
249 } elseif ( $gitInfo && $flags === 'nodb' ) {
250 $shortSha1 = substr( $gitInfo, 0, 7 );
251 $version = "$wgVersion ($shortSha1)";
252 } elseif ( $gitInfo ) {
253 $shortSha1 = substr( $gitInfo, 0, 7 );
254 $shortSha1 = wfMessage( 'parentheses' )->params( $shortSha1 )->escaped();
255 $version = "$wgVersion $shortSha1";
256 } elseif ( $flags === 'nodb' ) {
257 $version = "$wgVersion (r{$svnInfo['checkout-rev']})";
259 $version = $wgVersion . ' ' .
261 'version-svn-revision',
262 isset( $info['directory-rev'] ) ?
$info['directory-rev'] : '',
263 $info['checkout-rev']
267 wfProfileOut( __METHOD__
);
273 * Return a wikitext-formatted string of the MediaWiki version with a link to
274 * the SVN revision or the git SHA1 of head if available.
275 * Git is prefered over Svn
276 * The fallback is just $wgVersion
280 public static function getVersionLinked() {
282 wfProfileIn( __METHOD__
);
284 $gitVersion = self
::getVersionLinkedGit();
288 $svnVersion = self
::getVersionLinkedSvn();
292 $v = $wgVersion; // fallback
296 wfProfileOut( __METHOD__
);
302 * @return string wgVersion + a link to subversion revision of svn BASE
304 private static function getVersionLinkedSvn() {
307 $info = self
::getSvnInfo( $IP );
308 if ( !isset( $info['checkout-rev'] ) ) {
312 $linkText = wfMessage(
313 'version-svn-revision',
314 isset( $info['directory-rev'] ) ?
$info['directory-rev'] : '',
315 $info['checkout-rev']
318 if ( isset( $info['viewvc-url'] ) ) {
319 $version = "[{$info['viewvc-url']} $linkText]";
321 $version = $linkText;
324 return self
::getwgVersionLinked() . " $version";
330 private static function getwgVersionLinked() {
333 if ( wfRunHooks( 'SpecialVersionVersionUrl', array( $wgVersion, &$versionUrl ) ) ) {
334 $versionParts = array();
335 preg_match( "/^(\d+\.\d+)/", $wgVersion, $versionParts );
336 $versionUrl = "https://www.mediawiki.org/wiki/MediaWiki_{$versionParts[1]}";
339 return "[$versionUrl $wgVersion]";
343 * @since 1.22 Returns the HEAD date in addition to the sha1 and link
344 * @return bool|string wgVersion + HEAD sha1 stripped to the first 7 chars
345 * with link and date, or false on failure
347 private static function getVersionLinkedGit() {
350 $gitInfo = new GitInfo( $IP );
351 $headSHA1 = $gitInfo->getHeadSHA1();
356 $shortSHA1 = '(' . substr( $headSHA1, 0, 7 ) . ')';
358 $gitHeadUrl = $gitInfo->getHeadViewUrl();
359 if ( $gitHeadUrl !== false ) {
360 $shortSHA1 = "[$gitHeadUrl $shortSHA1]";
363 $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
364 if ( $gitHeadCommitDate ) {
365 $shortSHA1 .= Html
::element( 'br' ) . $wgLang->timeanddate( $gitHeadCommitDate, true );
368 return self
::getwgVersionLinked() . " $shortSHA1";
372 * Returns an array with the base extension types.
373 * Type is stored as array key, the message as array value.
375 * TODO: ideally this would return all extension types, including
376 * those added by SpecialVersionExtensionTypes. This is not possible
377 * since this hook is passing along $this though.
383 public static function getExtensionTypes() {
384 if ( self
::$extensionTypes === false ) {
385 self
::$extensionTypes = array(
386 'specialpage' => wfMessage( 'version-specialpages' )->text(),
387 'parserhook' => wfMessage( 'version-parserhooks' )->text(),
388 'variable' => wfMessage( 'version-variables' )->text(),
389 'media' => wfMessage( 'version-mediahandlers' )->text(),
390 'antispam' => wfMessage( 'version-antispam' )->text(),
391 'skin' => wfMessage( 'version-skins' )->text(),
392 'api' => wfMessage( 'version-api' )->text(),
393 'other' => wfMessage( 'version-other' )->text(),
396 wfRunHooks( 'ExtensionTypes', array( &self
::$extensionTypes ) );
399 return self
::$extensionTypes;
403 * Returns the internationalized name for an extension type.
407 * @param $type String
411 public static function getExtensionTypeName( $type ) {
412 $types = self
::getExtensionTypes();
414 return isset( $types[$type] ) ?
$types[$type] : $types['other'];
418 * Generate wikitext showing extensions name, URL, author and description.
420 * @return String: Wikitext
422 function getExtensionCredits() {
423 global $wgExtensionCredits;
425 if ( !count( $wgExtensionCredits ) ) {
429 $extensionTypes = self
::getExtensionTypes();
432 * @deprecated as of 1.17, use hook ExtensionTypes instead.
434 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
438 array( 'id' => 'mw-version-ext' ),
439 $this->msg( 'version-extensions' )->text()
441 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-ext' ) );
443 // Make sure the 'other' type is set to an array.
444 if ( !array_key_exists( 'other', $wgExtensionCredits ) ) {
445 $wgExtensionCredits['other'] = array();
448 // Find all extensions that do not have a valid type and give them the type 'other'.
449 foreach ( $wgExtensionCredits as $type => $extensions ) {
450 if ( !array_key_exists( $type, $extensionTypes ) ) {
451 $wgExtensionCredits['other'] = array_merge( $wgExtensionCredits['other'], $extensions );
455 // Loop through the extension categories to display their extensions in the list.
456 foreach ( $extensionTypes as $type => $message ) {
457 if ( $type != 'other' ) {
458 $out .= $this->getExtensionCategory( $type, $message );
462 // We want the 'other' type to be last in the list.
463 $out .= $this->getExtensionCategory( 'other', $extensionTypes['other'] );
465 $out .= Xml
::closeElement( 'table' );
471 * Obtains a list of installed parser tags and the associated H2 header
473 * @return string HTML output
475 protected function getParserTags() {
478 $tags = $wgParser->getTags();
480 if ( count( $tags ) ) {
481 $out = Html
::rawElement(
483 array( 'class' => 'mw-headline' ),
484 Linker
::makeExternalLink(
485 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Tag_extensions',
486 $this->msg( 'version-parser-extensiontags' )->parse(),
487 false /* msg()->parse() already escapes */
491 array_walk( $tags, function ( &$value ) {
492 $value = '<' . htmlentities( $value ) . '>';
494 $out .= $this->listToText( $tags );
503 * Obtains a list of installed parser function hooks and the associated H2 header
505 * @return string HTML output
507 protected function getParserFunctionHooks() {
510 $fhooks = $wgParser->getFunctionHooks();
511 if ( count( $fhooks ) ) {
512 $out = Html
::rawElement( 'h2', array( 'class' => 'mw-headline' ), Linker
::makeExternalLink(
513 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Parser_functions',
514 $this->msg( 'version-parser-function-hooks' )->parse(),
515 false /* msg()->parse() already escapes */
518 $out .= $this->listToText( $fhooks );
527 * Creates and returns the HTML for a single extension category.
531 * @param $type String
532 * @param $message String
536 protected function getExtensionCategory( $type, $message ) {
537 global $wgExtensionCredits;
541 if ( array_key_exists( $type, $wgExtensionCredits ) && count( $wgExtensionCredits[$type] ) > 0 ) {
542 $out .= $this->openExtType( $message, 'credits-' . $type );
544 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
546 foreach ( $wgExtensionCredits[$type] as $extension ) {
547 $out .= $this->getCreditsForExtension( $extension );
555 * Callback to sort extensions by type.
560 function compare( $a, $b ) {
561 if ( $a['name'] === $b['name'] ) {
564 return $this->getLanguage()->lc( $a['name'] ) > $this->getLanguage()->lc( $b['name'] )
571 * Creates and formats a version line for a single extension.
573 * Information for five columns will be created. Parameters required in the
574 * $extension array for part rendering are indicated in ()
575 * - The name of (name), and URL link to (url), the extension
576 * - Official version number (version) and if available version control system
577 * revision (path), link, and date
578 * - If available the short name of the license (license-name) and a linke
579 * to ((LICENSE)|(COPYING))(\.txt)? if it exists.
580 * - Description of extension (descriptionmsg or description)
581 * - List of authors (author) and link to a ((AUTHORS)|(CREDITS))(\.txt)? file if it exists
583 * @param $extension Array
585 * @return string raw HTML
587 function getCreditsForExtension( array $extension ) {
588 $out = $this->getOutput();
590 // We must obtain the information for all the bits and pieces!
591 // ... such as extension names and links
592 $extensionName = isset( $extension['name'] ) ?
$extension['name'] : '[no name]';
593 if ( isset( $extension['url'] ) ) {
594 $extensionNameLink = Linker
::makeExternalLink(
599 array( 'class' => 'mw-version-ext-name' )
602 $extensionNameLink = $extensionName;
605 // ... and the version information
606 // If the extension path is set we will check that directory for GIT and SVN
607 // metadata in an attempt to extract date and vcs commit metadata.
608 $canonicalVersion = '–';
609 $extensionPath = null;
614 if ( isset( $extension['version'] ) ) {
615 $canonicalVersion = $out->parseInline( $extension['version'] );
618 if ( isset( $extension['path'] ) ) {
619 $extensionPath = dirname( $extension['path'] );
620 $gitInfo = new GitInfo( $extensionPath );
621 $vcsVersion = $gitInfo->getHeadSHA1();
622 if ( $vcsVersion !== false ) {
623 $vcsVersion = substr( $vcsVersion, 0, 7 );
624 $vcsLink = $gitInfo->getHeadViewUrl();
625 $vcsDate = $gitInfo->getHeadCommitDate();
627 $svnInfo = self
::getSvnInfo( $extensionPath );
628 if ( $svnInfo !== false ) {
629 $vcsVersion = $this->msg( 'version-svn-revision', $svnInfo['checkout-rev'] )->text();
630 $vcsLink = isset( $svnInfo['viewvc-url'] ) ?
$svnInfo['viewvc-url'] : '';
635 $versionString = Html
::rawElement(
637 array( 'class' => 'mw-version-ext-version' ),
643 $vcsVerString = Linker
::makeExternalLink(
645 $this->msg( 'version-version', $vcsVersion ),
648 array( 'class' => 'mw-version-ext-vcs-version' )
651 $vcsVerString = Html
::element( 'span',
652 array( 'class' => 'mw-version-ext-vcs-version' ),
656 $versionString .= " {$vcsVerString}";
659 $vcsTimeString = Html
::element( 'span',
660 array( 'class' => 'mw-version-ext-vcs-timestamp' ),
661 $this->getLanguage()->timeanddate( $vcsDate )
663 $versionString .= " {$vcsTimeString}";
665 $versionString = Html
::rawElement( 'span',
666 array( 'class' => 'mw-version-ext-meta-version' ),
671 // ... and license information; if a license file exists we
674 if ( isset( $extension['license-name'] ) ) {
675 $licenseLink = Linker
::link(
676 $this->getPageTitle( 'License/' . $extensionName ),
677 $out->parseInline( $extension['license-name'] ),
678 array( 'class' => 'mw-version-ext-license' )
680 } elseif ( $this->getExtLicenseFileName( $extensionPath ) ) {
681 $licenseLink = Linker
::link(
682 $this->getPageTitle( 'License/' . $extensionName ),
683 $this->msg( 'version-ext-license' ),
684 array( 'class' => 'mw-version-ext-license' )
688 // ... and generate the description; which can be a parameterized l10n message
689 // in the form array( <msgname>, <parameter>, <parameter>... ) or just a straight
691 if ( isset( $extension['descriptionmsg'] ) ) {
692 // Localized description of extension
693 $descriptionMsg = $extension['descriptionmsg'];
695 if ( is_array( $descriptionMsg ) ) {
696 $descriptionMsgKey = $descriptionMsg[0]; // Get the message key
697 array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
698 array_map( "htmlspecialchars", $descriptionMsg ); // For sanity
699 $description = $this->msg( $descriptionMsgKey, $descriptionMsg )->text();
701 $description = $this->msg( $descriptionMsg )->text();
703 } elseif ( isset( $extension['description'] ) ) {
704 // Non localized version
705 $description = $extension['description'];
709 $description = $out->parseInline( $description );
711 // ... now get the authors for this extension
712 $authors = isset( $extension['author'] ) ?
$extension['author'] : array();
713 $authors = $this->listAuthors( $authors, $extensionName, $extensionPath );
715 // Finally! Create the table
716 $html = Html
::openElement( 'tr', array(
717 'class' => 'mw-version-ext',
718 'id' => "mw-version-ext-{$extensionName}"
722 $html .= Html
::rawElement( 'td', array(), $extensionNameLink );
723 $html .= Html
::rawElement( 'td', array(), $versionString );
724 $html .= Html
::rawElement( 'td', array(), $licenseLink );
725 $html .= Html
::rawElement( 'td', array( 'class' => 'mw-version-ext-description' ), $description );
726 $html .= Html
::rawElement( 'td', array( 'class' => 'mw-version-ext-authors' ), $authors );
728 $html .= Html
::closeElement( 'td' );
734 * Generate wikitext showing hooks in $wgHooks.
736 * @return String: wikitext
738 private function getWgHooks() {
739 global $wgSpecialVersionShowHooks, $wgHooks;
741 if ( $wgSpecialVersionShowHooks && count( $wgHooks ) ) {
742 $myWgHooks = $wgHooks;
746 $ret[] = '== {{int:version-hooks}} ==';
747 $ret[] = Html
::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-hooks' ) );
748 $ret[] = Html
::openElement( 'tr' );
749 $ret[] = Html
::element( 'th', array(), $this->msg( 'version-hook-name' )->text() );
750 $ret[] = Html
::element( 'th', array(), $this->msg( 'version-hook-subscribedby' )->text() );
751 $ret[] = Html
::closeElement( 'tr' );
753 foreach ( $myWgHooks as $hook => $hooks ) {
754 $ret[] = Html
::openElement( 'tr' );
755 $ret[] = Html
::element( 'td', array(), $hook );
756 $ret[] = Html
::element( 'td', array(), $this->listToText( $hooks ) );
757 $ret[] = Html
::closeElement( 'tr' );
760 $ret[] = Html
::closeElement( 'table' );
762 return implode( "\n", $ret );
768 private function openExtType( $text, $name = null ) {
771 $opt = array( 'colspan' => 5 );
772 if ( $this->firstExtOpened
) {
773 // Insert a spacing line
774 $out .= Html
::rawElement( 'tr', array( 'class' => 'sv-space' ),
775 Html
::element( 'td', $opt )
778 $this->firstExtOpened
= true;
781 $opt['id'] = "sv-$name";
784 $out .= Html
::rawElement( 'tr', array(),
785 Html
::element( 'th', $opt, $text )
788 $out .= Html
::openElement( 'tr' );
789 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
790 $this->msg( 'version-ext-colheader-name' )->text() );
791 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
792 $this->msg( 'version-ext-colheader-version' )->text() );
793 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
794 $this->msg( 'version-ext-colheader-license' )->text() );
795 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
796 $this->msg( 'version-ext-colheader-description' )->text() );
797 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
798 $this->msg( 'version-ext-colheader-credits' )->text() );
799 $out .= Html
::closeElement( 'tr' );
805 * Get information about client's IP address.
807 * @return String: HTML fragment
809 private function IPInfo() {
810 $ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) );
812 return "<!-- visited from $ip -->\n<span style='display:none'>visited from $ip</span>";
816 * Return a formatted unsorted list of authors
819 * If an item in the $authors array is '...' it is assumed to indicate an
820 * 'and others' string which will then be linked to an ((AUTHORS)|(CREDITS))(\.txt)?
821 * file if it exists in $dir.
823 * Similarly an entry ending with ' ...]' is assumed to be a link to an
826 * If no '...' string variant is found, but an authors file is found an
827 * 'and others' will be added to the end of the credits.
829 * @param $authors mixed: string or array of strings
830 * @param $extName string: name of the extension for link creation
831 * @param $extDir string: path to the extension root directory
833 * @return String: HTML fragment
835 function listAuthors( $authors, $extName, $extDir ) {
839 foreach ( (array)$authors as $item ) {
840 if ( $item == '...' ) {
843 if ( $this->getExtAuthorsFileName( $extDir ) ) {
844 $text = Linker
::link(
845 $this->getPageTitle( "Credits/$extName" ),
846 $this->msg( 'version-poweredby-others' )->text()
849 $text = $this->msg( 'version-poweredby-others' )->text();
852 } elseif ( substr( $item, -5 ) == ' ...]' ) {
854 $list[] = $this->getOutput()->parseInline(
855 substr( $item, 0, -4 ) . $this->msg( 'version-poweredby-others' )->text() . "]"
858 $list[] = $this->getOutput()->parseInline( $item );
862 if ( !$hasOthers && $this->getExtAuthorsFileName( $extDir ) ) {
863 $list[] = $text = Linker
::link(
864 $this->getPageTitle( "Credits/$extName" ),
865 $this->msg( 'version-poweredby-others' )->text()
869 return $this->listToText( $list, false );
873 * Obtains the full path of an extensions authors or credits file if
876 * @param string $extDir Path to the extensions root directory
880 * @return bool|string False if no such file exists, otherwise returns
883 public static function getExtAuthorsFileName( $extDir ) {
888 foreach ( scandir( $extDir ) as $file ) {
889 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
890 if ( preg_match( '/^((AUTHORS)|(CREDITS))(\.txt)?$/', $file ) &&
891 is_readable( $fullPath ) &&
902 * Obtains the full path of an extensions copying or license file if
905 * @param string $extDir Path to the extensions root directory
909 * @return bool|string False if no such file exists, otherwise returns
912 public static function getExtLicenseFileName( $extDir ) {
917 foreach ( scandir( $extDir ) as $file ) {
918 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
919 if ( preg_match( '/^((COPYING)|(LICENSE))(\.txt)?$/', $file ) &&
920 is_readable( $fullPath ) &&
931 * Convert an array of items into a list for display.
933 * @param array $list of elements to display
934 * @param $sort Boolean: whether to sort the items in $list
938 function listToText( $list, $sort = true ) {
939 $cnt = count( $list );
942 // Enforce always returning a string
943 return (string)self
::arrayToString( $list[0] );
944 } elseif ( $cnt == 0 ) {
951 return $this->getLanguage()
952 ->listToText( array_map( array( __CLASS__
, 'arrayToString' ), $list ) );
957 * Convert an array or object to a string for display.
959 * @param $list Mixed: will convert an array to string if given and return
960 * the paramater unaltered otherwise
964 public static function arrayToString( $list ) {
965 if ( is_array( $list ) && count( $list ) == 1 ) {
968 if ( is_object( $list ) ) {
969 $class = wfMessage( 'parentheses' )->params( get_class( $list ) )->escaped();
972 } elseif ( !is_array( $list ) ) {
975 if ( is_object( $list[0] ) ) {
976 $class = get_class( $list[0] );
981 return wfMessage( 'parentheses' )->params( "$class, {$list[1]}" )->escaped();
986 * Get an associative array of information about a given path, from its .svn
987 * subdirectory. Returns false on error, such as if the directory was not
988 * checked out with subversion.
992 * checkout-rev The revision which was checked out
994 * directory-rev The revision when the directory was last modified
995 * url The subversion URL of the directory
996 * repo-url The base URL of the repository
997 * viewvc-url A ViewVC URL pointing to the checked-out revision
1001 public static function getSvnInfo( $dir ) {
1002 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
1003 $entries = $dir . '/.svn/entries';
1005 if ( !file_exists( $entries ) ) {
1009 $lines = file( $entries );
1010 if ( !count( $lines ) ) {
1014 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
1015 if ( preg_match( '/^<\?xml/', $lines[0] ) ) {
1016 // subversion is release <= 1.3
1017 if ( !function_exists( 'simplexml_load_file' ) ) {
1018 // We could fall back to expat... YUCK
1022 // SimpleXml whines about the xmlns...
1023 wfSuppressWarnings();
1024 $xml = simplexml_load_file( $entries );
1025 wfRestoreWarnings();
1028 foreach ( $xml->entry
as $entry ) {
1029 if ( $xml->entry
[0]['name'] == '' ) {
1030 // The directory entry should always have a revision marker.
1031 if ( $entry['revision'] ) {
1032 return array( 'checkout-rev' => intval( $entry['revision'] ) );
1041 // Subversion is release 1.4 or above.
1042 if ( count( $lines ) < 11 ) {
1047 'checkout-rev' => intval( trim( $lines[3] ) ),
1048 'url' => trim( $lines[4] ),
1049 'repo-url' => trim( $lines[5] ),
1050 'directory-rev' => intval( trim( $lines[10] ) )
1053 if ( isset( self
::$viewvcUrls[$info['repo-url']] ) ) {
1054 $viewvc = str_replace(
1056 self
::$viewvcUrls[$info['repo-url']],
1060 $viewvc .= '/?pathrev=';
1061 $viewvc .= urlencode( $info['checkout-rev'] );
1062 $info['viewvc-url'] = $viewvc;
1069 * Retrieve the revision number of a Subversion working directory.
1071 * @param string $dir directory of the svn checkout
1073 * @return Integer: revision number as int
1075 public static function getSvnRevision( $dir ) {
1076 $info = self
::getSvnInfo( $dir );
1078 if ( $info === false ) {
1080 } elseif ( isset( $info['checkout-rev'] ) ) {
1081 return $info['checkout-rev'];
1088 * @param string $dir directory of the git checkout
1089 * @return bool|String sha1 of commit HEAD points to
1091 public static function getGitHeadSha1( $dir ) {
1092 $repo = new GitInfo( $dir );
1094 return $repo->getHeadSHA1();
1098 * Get the list of entry points and their URLs
1099 * @return string Wikitext
1101 public function getEntryPointInfo() {
1102 global $wgArticlePath, $wgScriptPath;
1103 $scriptPath = $wgScriptPath ?
$wgScriptPath : "/";
1104 $entryPoints = array(
1105 'version-entrypoints-articlepath' => $wgArticlePath,
1106 'version-entrypoints-scriptpath' => $scriptPath,
1107 'version-entrypoints-index-php' => wfScript( 'index' ),
1108 'version-entrypoints-api-php' => wfScript( 'api' ),
1109 'version-entrypoints-load-php' => wfScript( 'load' ),
1112 $language = $this->getLanguage();
1113 $thAttribures = array(
1114 'dir' => $language->getDir(),
1115 'lang' => $language->getCode()
1117 $out = Html
::element(
1119 array( 'id' => 'mw-version-entrypoints' ),
1120 $this->msg( 'version-entrypoints' )->text()
1122 Html
::openElement( 'table',
1124 'class' => 'wikitable plainlinks',
1125 'id' => 'mw-version-entrypoints-table',
1130 Html
::openElement( 'tr' ) .
1134 $this->msg( 'version-entrypoints-header-entrypoint' )->text()
1139 $this->msg( 'version-entrypoints-header-url' )->text()
1141 Html
::closeElement( 'tr' );
1143 foreach ( $entryPoints as $message => $value ) {
1144 $url = wfExpandUrl( $value, PROTO_RELATIVE
);
1145 $out .= Html
::openElement( 'tr' ) .
1146 // ->text() looks like it should be ->parse(), but this function
1147 // returns wikitext, not HTML, boo
1148 Html
::rawElement( 'td', array(), $this->msg( $message )->text() ) .
1149 Html
::rawElement( 'td', array(), Html
::rawElement( 'code', array(), "[$url $value]" ) ) .
1150 Html
::closeElement( 'tr' );
1153 $out .= Html
::closeElement( 'table' );
1158 protected function getGroupName() {