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
{
33 protected $firstExtOpened = false;
35 protected static $extensionTypes = false;
37 protected static $viewvcUrls = array(
38 'svn+ssh://svn.wikimedia.org/svnroot/mediawiki' => 'http://svn.wikimedia.org/viewvc/mediawiki',
39 'http://svn.wikimedia.org/svnroot/mediawiki' => 'http://svn.wikimedia.org/viewvc/mediawiki',
40 'https://svn.wikimedia.org/svnroot/mediawiki' => 'https://svn.wikimedia.org/viewvc/mediawiki',
43 public function __construct() {
44 parent
::__construct( 'Version' );
50 public function execute( $par ) {
51 global $IP, $wgExtensionCredits;
54 $this->outputHeader();
55 $out = $this->getOutput();
56 $out->allowClickjacking();
58 // Explode the sub page information into useful bits
59 $parts = explode( '/', (string)$par );
61 if ( isset( $parts[1] ) ) {
62 $extName = str_replace( '_', ' ', $parts[1] );
64 foreach ( $wgExtensionCredits as $group => $extensions ) {
65 foreach ( $extensions as $ext ) {
66 if ( isset( $ext['name'] ) && ( $ext['name'] === $extName ) ) {
73 $out->setStatusCode( 404 );
76 $extName = 'MediaWiki';
79 // Now figure out what to do
80 switch ( strtolower( $parts[0] ) ) {
82 $wikiText = '{{int:version-credits-not-found}}';
83 if ( $extName === 'MediaWiki' ) {
84 $wikiText = file_get_contents( $IP . '/CREDITS' );
85 } elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) {
86 $file = $this->getExtAuthorsFileName( dirname( $extNode['path'] ) );
88 $wikiText = file_get_contents( $file );
89 if ( substr( $file, -4 ) === '.txt' ) {
90 $wikiText = Html
::element( 'pre', array(), $wikiText );
95 $out->setPageTitle( $this->msg( 'version-credits-title', $extName ) );
96 $out->addWikiText( $wikiText );
100 $wikiText = '{{int:version-license-not-found}}';
101 if ( $extName === 'MediaWiki' ) {
102 $wikiText = file_get_contents( $IP . '/COPYING' );
103 } elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) {
104 $file = $this->getExtLicenseFileName( dirname( $extNode['path'] ) );
106 $wikiText = file_get_contents( $file );
107 if ( !isset( $extNode['license-name'] ) ) {
108 // If the developer did not explicitly set license-name they probably
109 // are unaware that we're now sucking this file in and thus it's probably
110 // not wikitext friendly.
111 $wikiText = "<pre>$wikiText</pre>";
116 $out->setPageTitle( $this->msg( 'version-license-title', $extName ) );
117 $out->addWikiText( $wikiText );
121 $out->addModules( 'mediawiki.special.version' );
123 $this->getMediaWikiCredits() .
124 $this->softwareInformation() .
125 $this->getEntryPointInfo()
128 $this->getExtensionCredits() .
129 $this->getParserTags() .
130 $this->getParserFunctionHooks()
132 $out->addWikiText( $this->getWgHooks() );
133 $out->addHTML( $this->IPInfo() );
140 * Returns wiki text showing the license information.
144 private static function getMediaWikiCredits() {
145 $ret = Xml
::element( 'h2', array( 'id' => 'mw-version-license' ), wfMessage( 'version-license' )->text() );
147 // This text is always left-to-right.
148 $ret .= '<div class="plainlinks">';
150 " . self
::getCopyrightAndAuthorList() . "\n
151 " . wfMessage( 'version-license-info' )->text();
154 return str_replace( "\t\t", '', $ret ) . "\n";
158 * Get the "MediaWiki is copyright 2001-20xx by lots of cool guys" text
162 public static function getCopyrightAndAuthorList() {
165 if ( defined( 'MEDIAWIKI_INSTALL' ) ) {
166 $othersLink = '[//www.mediawiki.org/wiki/Special:Version/Credits ' . wfMessage( 'version-poweredby-others' )->text() . ']';
168 $othersLink = '[[Special:Version/Credits|' . wfMessage( 'version-poweredby-others' )->text() . ']]';
171 $translatorsLink = '[//translatewiki.net/wiki/Translating:MediaWiki/Credits ' . wfMessage( 'version-poweredby-translators' )->text() . ']';
174 'Magnus Manske', 'Brion Vibber', 'Lee Daniel Crocker',
175 'Tim Starling', 'Erik Möller', 'Gabriel Wicke', 'Ævar Arnfjörð Bjarmason',
176 'Niklas Laxström', 'Domas Mituzas', 'Rob Church', 'Yuri Astrakhan',
177 'Aryeh Gregor', 'Aaron Schulz', 'Andrew Garrett', 'Raimond Spekking',
178 'Alexandre Emsenhuber', 'Siebrand Mazeland', 'Chad Horohoe',
179 'Roan Kattouw', 'Trevor Parscal', 'Bryan Tong Minh', 'Sam Reed',
180 'Victor Vasiliev', 'Rotem Liss', 'Platonides', 'Antoine Musso',
181 'Timo Tijhof', 'Daniel Kinzler', 'Jeroen De Dauw', $othersLink,
185 return wfMessage( 'version-poweredby-credits', MWTimestamp
::getLocalInstance()->format( 'Y' ),
186 $wgLang->listToText( $authorList ) )->text();
190 * Returns wiki text showing the third party software versions (apache, php, mysql).
194 static function softwareInformation() {
195 $dbr = wfGetDB( DB_SLAVE
);
197 // Put the software in an array of form 'name' => 'version'. All messages should
198 // be loaded here, so feel free to use wfMessage in the 'name'. Raw HTML or
199 // wikimarkup can be used.
201 $software['[https://www.mediawiki.org/ MediaWiki]'] = self
::getVersionLinked();
202 $software['[http://www.php.net/ PHP]'] = phpversion() . " (" . PHP_SAPI
. ")";
203 $software[$dbr->getSoftwareLink()] = $dbr->getServerInfo();
205 // Allow a hook to add/remove items.
206 wfRunHooks( 'SoftwareInfo', array( &$software ) );
208 $out = Xml
::element( 'h2', array( 'id' => 'mw-version-software' ), wfMessage( 'version-software' )->text() ) .
209 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-software' ) ) .
211 <th>" . wfMessage( 'version-software-product' )->text() . "</th>
212 <th>" . wfMessage( 'version-software-version' )->text() . "</th>
215 foreach ( $software as $name => $version ) {
217 <td>" . $name . "</td>
218 <td dir=\"ltr\">" . $version . "</td>
222 return $out . Xml
::closeElement( 'table' );
226 * Return a string of the MediaWiki version with SVN revision if available.
228 * @param $flags String
231 public static function getVersion( $flags = '' ) {
232 global $wgVersion, $IP;
233 wfProfileIn( __METHOD__
);
235 $gitInfo = self
::getGitHeadSha1( $IP );
236 $svnInfo = self
::getSvnInfo( $IP );
237 if ( !$svnInfo && !$gitInfo ) {
238 $version = $wgVersion;
239 } elseif ( $gitInfo && $flags === 'nodb' ) {
240 $shortSha1 = substr( $gitInfo, 0, 7 );
241 $version = "$wgVersion ($shortSha1)";
242 } elseif ( $gitInfo ) {
243 $shortSha1 = substr( $gitInfo, 0, 7 );
244 $shortSha1 = wfMessage( 'parentheses' )->params( $shortSha1 )->escaped();
245 $version = "$wgVersion $shortSha1";
246 } elseif ( $flags === 'nodb' ) {
247 $version = "$wgVersion (r{$svnInfo['checkout-rev']})";
249 $version = $wgVersion . ' ' .
251 'version-svn-revision',
252 isset( $info['directory-rev'] ) ?
$info['directory-rev'] : '',
253 $info['checkout-rev']
257 wfProfileOut( __METHOD__
);
263 * Return a wikitext-formatted string of the MediaWiki version with a link to
264 * the SVN revision or the git SHA1 of head if available.
265 * Git is prefered over Svn
266 * The fallback is just $wgVersion
270 public static function getVersionLinked() {
272 wfProfileIn( __METHOD__
);
274 $gitVersion = self
::getVersionLinkedGit();
278 $svnVersion = self
::getVersionLinkedSvn();
282 $v = $wgVersion; // fallback
286 wfProfileOut( __METHOD__
);
292 * @return string wgVersion + a link to subversion revision of svn BASE
294 private static function getVersionLinkedSvn() {
297 $info = self
::getSvnInfo( $IP );
298 if ( !isset( $info['checkout-rev'] ) ) {
302 $linkText = wfMessage(
303 'version-svn-revision',
304 isset( $info['directory-rev'] ) ?
$info['directory-rev'] : '',
305 $info['checkout-rev']
308 if ( isset( $info['viewvc-url'] ) ) {
309 $version = "[{$info['viewvc-url']} $linkText]";
311 $version = $linkText;
314 return self
::getwgVersionLinked() . " $version";
320 private static function getwgVersionLinked() {
323 if ( wfRunHooks( 'SpecialVersionVersionUrl', array( $wgVersion, &$versionUrl ) ) ) {
324 $versionParts = array();
325 preg_match( "/^(\d+\.\d+)/", $wgVersion, $versionParts );
326 $versionUrl = "https://www.mediawiki.org/wiki/MediaWiki_{$versionParts[1]}";
329 return "[$versionUrl $wgVersion]";
333 * @since 1.22 Returns the HEAD date in addition to the sha1 and link
334 * @return bool|string wgVersion + HEAD sha1 stripped to the first 7 chars with link and date, or false on failure
336 private static function getVersionLinkedGit() {
339 $gitInfo = new GitInfo( $IP );
340 $headSHA1 = $gitInfo->getHeadSHA1();
345 $shortSHA1 = '(' . substr( $headSHA1, 0, 7 ) . ')';
347 $gitHeadUrl = $gitInfo->getHeadViewUrl();
348 if ( $gitHeadUrl !== false ) {
349 $shortSHA1 = "[$gitHeadUrl $shortSHA1]";
352 $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
353 if ( $gitHeadCommitDate ) {
354 $shortSHA1 .= Html
::element( 'br' ) . $wgLang->timeanddate( $gitHeadCommitDate, true );
357 return self
::getwgVersionLinked() . " $shortSHA1";
361 * Returns an array with the base extension types.
362 * Type is stored as array key, the message as array value.
364 * TODO: ideally this would return all extension types, including
365 * those added by SpecialVersionExtensionTypes. This is not possible
366 * since this hook is passing along $this though.
372 public static function getExtensionTypes() {
373 if ( self
::$extensionTypes === false ) {
374 self
::$extensionTypes = array(
375 'specialpage' => wfMessage( 'version-specialpages' )->text(),
376 'parserhook' => wfMessage( 'version-parserhooks' )->text(),
377 'variable' => wfMessage( 'version-variables' )->text(),
378 'media' => wfMessage( 'version-mediahandlers' )->text(),
379 'antispam' => wfMessage( 'version-antispam' )->text(),
380 'skin' => wfMessage( 'version-skins' )->text(),
381 'api' => wfMessage( 'version-api' )->text(),
382 'other' => wfMessage( 'version-other' )->text(),
385 wfRunHooks( 'ExtensionTypes', array( &self
::$extensionTypes ) );
388 return self
::$extensionTypes;
392 * Returns the internationalized name for an extension type.
396 * @param $type String
400 public static function getExtensionTypeName( $type ) {
401 $types = self
::getExtensionTypes();
403 return isset( $types[$type] ) ?
$types[$type] : $types['other'];
407 * Generate wikitext showing extensions name, URL, author and description.
409 * @return String: Wikitext
411 function getExtensionCredits() {
412 global $wgExtensionCredits;
414 if ( !count( $wgExtensionCredits ) ) {
418 $extensionTypes = self
::getExtensionTypes();
421 * @deprecated as of 1.17, use hook ExtensionTypes instead.
423 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
425 $out = Xml
::element( 'h2', array( 'id' => 'mw-version-ext' ), $this->msg( 'version-extensions' )->text() ) .
426 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-ext' ) );
428 // Make sure the 'other' type is set to an array.
429 if ( !array_key_exists( 'other', $wgExtensionCredits ) ) {
430 $wgExtensionCredits['other'] = array();
433 // Find all extensions that do not have a valid type and give them the type 'other'.
434 foreach ( $wgExtensionCredits as $type => $extensions ) {
435 if ( !array_key_exists( $type, $extensionTypes ) ) {
436 $wgExtensionCredits['other'] = array_merge( $wgExtensionCredits['other'], $extensions );
440 // Loop through the extension categories to display their extensions in the list.
441 foreach ( $extensionTypes as $type => $message ) {
442 if ( $type != 'other' ) {
443 $out .= $this->getExtensionCategory( $type, $message );
447 // We want the 'other' type to be last in the list.
448 $out .= $this->getExtensionCategory( 'other', $extensionTypes['other'] );
450 $out .= Xml
::closeElement( 'table' );
456 * Obtains a list of installed parser tags and the associated H2 header
458 * @return string HTML output
460 protected function getParserTags() {
463 $tags = $wgParser->getTags();
465 if ( count( $tags ) ) {
466 $out = Html
::rawElement(
468 array( 'class' => 'mw-headline' ),
469 Linker
::makeExternalLink(
470 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Tag_extensions',
471 $this->msg( 'version-parser-extensiontags' )->parse(),
472 false /* msg()->parse() already escapes */
476 array_walk( $tags, function ( &$value ) {
477 $value = '<' . htmlentities( $value ) . '>';
479 $out .= $this->listToText( $tags );
488 * Obtains a list of installed parser function hooks and the associated H2 header
490 * @return string HTML output
492 protected function getParserFunctionHooks() {
495 $fhooks = $wgParser->getFunctionHooks();
496 if ( count( $fhooks ) ) {
497 $out = Html
::rawElement( 'h2', array( 'class' => 'mw-headline' ), Linker
::makeExternalLink(
498 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Parser_functions',
499 $this->msg( 'version-parser-function-hooks' )->parse(),
500 false /* msg()->parse() already escapes */
503 $out .= $this->listToText( $fhooks );
512 * Creates and returns the HTML for a single extension category.
516 * @param $type String
517 * @param $message String
521 protected function getExtensionCategory( $type, $message ) {
522 global $wgExtensionCredits;
526 if ( array_key_exists( $type, $wgExtensionCredits ) && count( $wgExtensionCredits[$type] ) > 0 ) {
527 $out .= $this->openExtType( $message, 'credits-' . $type );
529 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
531 foreach ( $wgExtensionCredits[$type] as $extension ) {
532 $out .= $this->getCreditsForExtension( $extension );
540 * Callback to sort extensions by type.
545 function compare( $a, $b ) {
546 if ( $a['name'] === $b['name'] ) {
549 return $this->getLanguage()->lc( $a['name'] ) > $this->getLanguage()->lc( $b['name'] )
556 * Creates and formats a version line for a single extension.
558 * Information for five columns will be created. Parameters required in the
559 * $extension array for part rendering are indicated in ()
560 * - The name of (name), and URL link to (url), the extension
561 * - Official version number (version) and if available version control system
562 * revision (path), link, and date
563 * - If available the short name of the license (license-name) and a linke
564 * to ((LICENSE)|(COPYING))(\.txt)? if it exists.
565 * - Description of extension (descriptionmsg or description)
566 * - List of authors (author) and link to a ((AUTHORS)|(CREDITS))(\.txt)? file if it exists
568 * @param $extension Array
570 * @return string raw HTML
572 function getCreditsForExtension( array $extension ) {
573 $out = $this->getOutput();
575 // We must obtain the information for all the bits and pieces!
576 // ... such as extension names and links
577 $extensionName = isset( $extension['name'] ) ?
$extension['name'] : '[no name]';
578 if ( isset( $extension['url'] ) ) {
579 $extensionNameLink = Linker
::makeExternalLink(
584 array( 'class' => 'mw-version-ext-name' )
587 $extensionNameLink = $extensionName;
590 // ... and the version information
591 // If the extension path is set we will check that directory for GIT and SVN
592 // metadata in an attempt to extract date and vcs commit metadata.
593 $canonicalVersion = '–';
594 $extensionPath = null;
599 if ( isset( $extension['version'] ) ) {
600 $canonicalVersion = $out->parseInline( $extension['version'] );
603 if ( isset( $extension['path'] ) ) {
604 $extensionPath = dirname( $extension['path'] );
605 $gitInfo = new GitInfo( $extensionPath );
606 $vcsVersion = $gitInfo->getHeadSHA1();
607 if ( $vcsVersion !== false ) {
608 $vcsVersion = substr( $vcsVersion, 0, 7 );
609 $vcsLink = $gitInfo->getHeadViewUrl();
610 $vcsDate = $gitInfo->getHeadCommitDate();
612 $svnInfo = self
::getSvnInfo( $extensionPath );
613 if ( $svnInfo !== false ) {
614 $vcsVersion = $this->msg( 'version-svn-revision', $svnInfo['checkout-rev'] )->text();
615 $vcsLink = isset( $svnInfo['viewvc-url'] ) ?
$svnInfo['viewvc-url'] : '';
620 $versionString = Html
::rawElement( 'span', array( 'class' => 'mw-version-ext-version' ), $canonicalVersion );
623 $vcsVerString = Linker
::makeExternalLink(
625 $this->msg( 'version-version', $vcsVersion ),
628 array( 'class' => 'mw-version-ext-vcs-version' )
631 $vcsVerString = Html
::element( 'span',
632 array( 'class' => 'mw-version-ext-vcs-version' ),
636 $versionString .= " {$vcsVerString}";
639 $vcsTimeString = Html
::element( 'span',
640 array( 'class' => 'mw-version-ext-vcs-timestamp' ),
641 $this->getLanguage()->timeanddate( $vcsDate )
643 $versionString .= " {$vcsTimeString}";
645 $versionString = Html
::rawElement( 'span',
646 array( 'class' => 'mw-version-ext-meta-version' ),
651 // ... and license information; if a license file exists we
654 if ( isset( $extension['license-name'] ) ) {
655 $licenseLink = Linker
::link(
656 $this->getPageTitle( 'License/' . $extensionName ),
657 $out->parseInline( $extension['license-name'] ),
658 array( 'class' => 'mw-version-ext-license' )
660 } elseif ( $this->getExtLicenseFileName( $extensionPath ) ) {
661 $licenseLink = Linker
::link(
662 $this->getPageTitle( 'License/' . $extensionName ),
663 $this->msg( 'version-ext-license' ),
664 array( 'class' => 'mw-version-ext-license' )
668 // ... and generate the description; which can be a parameterized l10n message
669 // in the form array( <msgname>, <parameter>, <parameter>... ) or just a straight
671 if ( isset( $extension['descriptionmsg'] ) ) {
672 // Localized description of extension
673 $descriptionMsg = $extension['descriptionmsg'];
675 if ( is_array( $descriptionMsg ) ) {
676 $descriptionMsgKey = $descriptionMsg[0]; // Get the message key
677 array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
678 array_map( "htmlspecialchars", $descriptionMsg ); // For sanity
679 $description = $this->msg( $descriptionMsgKey, $descriptionMsg )->text();
681 $description = $this->msg( $descriptionMsg )->text();
683 } elseif ( isset( $extension['description'] ) ) {
684 // Non localized version
685 $description = $extension['description'];
689 $description = $out->parseInline( $description );
691 // ... now get the authors for this extension
692 $authors = isset( $extension['author'] ) ?
$extension['author'] : array();
693 $authors = $this->listAuthors( $authors, $extensionName, $extensionPath );
695 // Finally! Create the table
696 $html = Html
::openElement( 'tr', array(
697 'class' => 'mw-version-ext',
698 'id' => "mw-version-ext-{$extensionName}"
702 $html .= Html
::rawElement( 'td', array(), $extensionNameLink );
703 $html .= Html
::rawElement( 'td', array(), $versionString );
704 $html .= Html
::rawElement( 'td', array(), $licenseLink );
705 $html .= Html
::rawElement( 'td', array( 'class' => 'mw-version-ext-description' ), $description );
706 $html .= Html
::rawElement( 'td', array( 'class' => 'mw-version-ext-authors' ), $authors );
708 $html .= Html
::closeElement( 'td' );
714 * Generate wikitext showing hooks in $wgHooks.
716 * @return String: wikitext
718 private function getWgHooks() {
719 global $wgSpecialVersionShowHooks, $wgHooks;
721 if ( $wgSpecialVersionShowHooks && count( $wgHooks ) ) {
722 $myWgHooks = $wgHooks;
726 $ret[] = '== {{int:version-hooks}} ==';
727 $ret[] = Html
::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-hooks' ) );
728 $ret[] = Html
::openElement( 'tr' );
729 $ret[] = Html
::element( 'th', array(), $this->msg( 'version-hook-name' )->text() );
730 $ret[] = Html
::element( 'th', array(), $this->msg( 'version-hook-subscribedby' )->text() );
731 $ret[] = Html
::closeElement( 'tr' );
733 foreach ( $myWgHooks as $hook => $hooks ) {
734 $ret[] = Html
::openElement( 'tr' );
735 $ret[] = Html
::element( 'td', array(), $hook );
736 $ret[] = Html
::element( 'td', array(), $this->listToText( $hooks ) );
737 $ret[] = Html
::closeElement( 'tr' );
740 $ret[] = Html
::closeElement( 'table' );
742 return implode( "\n", $ret );
748 private function openExtType( $text, $name = null ) {
751 $opt = array( 'colspan' => 5 );
752 if ( $this->firstExtOpened
) {
753 // Insert a spacing line
754 $out .= Html
::rawElement( 'tr', array( 'class' => 'sv-space' ),
755 Html
::element( 'td', $opt )
758 $this->firstExtOpened
= true;
761 $opt['id'] = "sv-$name";
764 $out .= Html
::rawElement( 'tr', array(),
765 Html
::element( 'th', $opt, $text )
768 $out .= Html
::openElement( 'tr' );
769 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
770 $this->msg( 'version-ext-colheader-name' )->text() );
771 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
772 $this->msg( 'version-ext-colheader-version' )->text() );
773 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
774 $this->msg( 'version-ext-colheader-license' )->text() );
775 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
776 $this->msg( 'version-ext-colheader-description' )->text() );
777 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
778 $this->msg( 'version-ext-colheader-credits' )->text() );
779 $out .= Html
::closeElement( 'tr' );
785 * Get information about client's IP address.
787 * @return String: HTML fragment
789 private function IPInfo() {
790 $ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) );
792 return "<!-- visited from $ip -->\n<span style='display:none'>visited from $ip</span>";
796 * Return a formatted unsorted list of authors
799 * If an item in the $authors array is '...' it is assumed to indicate an
800 * 'and others' string which will then be linked to an ((AUTHORS)|(CREDITS))(\.txt)?
801 * file if it exists in $dir.
803 * Similarly an entry ending with ' ...]' is assumed to be a link to an
806 * If no '...' string variant is found, but an authors file is found an
807 * 'and others' will be added to the end of the credits.
809 * @param $authors mixed: string or array of strings
810 * @param $extName string: name of the extension for link creation
811 * @param $extDir string: path to the extension root directory
813 * @return String: HTML fragment
815 function listAuthors( $authors, $extName, $extDir ) {
819 foreach ( (array)$authors as $item ) {
820 if ( $item == '...' ) {
823 if ( $this->getExtAuthorsFileName( $extDir ) ) {
824 $text = Linker
::link(
825 $this->getPageTitle( "Credits/$extName" ),
826 $this->msg( 'version-poweredby-others' )->text()
829 $text = $this->msg( 'version-poweredby-others' )->text();
832 } elseif ( substr( $item, -5 ) == ' ...]' ) {
834 $list[] = $this->getOutput()->parseInline(
835 substr( $item, 0, -4 ) . $this->msg( 'version-poweredby-others' )->text() . "]"
838 $list[] = $this->getOutput()->parseInline( $item );
842 if ( !$hasOthers && $this->getExtAuthorsFileName( $extDir ) ) {
843 $list[] = $text = Linker
::link(
844 $this->getPageTitle( "Credits/$extName" ),
845 $this->msg( 'version-poweredby-others' )->text()
849 return $this->listToText( $list, false );
853 * Obtains the full path of an extensions authors or credits file if
856 * @param string $extDir Path to the extensions root directory
860 * @return bool|string False if no such file exists, otherwise returns
863 public static function getExtAuthorsFileName( $extDir ) {
868 foreach ( scandir( $extDir ) as $file ) {
869 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
870 if ( preg_match( '/^((AUTHORS)|(CREDITS))(\.txt)?$/', $file ) &&
871 is_readable( $fullPath ) &&
882 * Obtains the full path of an extensions copying or license file if
885 * @param string $extDir Path to the extensions root directory
889 * @return bool|string False if no such file exists, otherwise returns
892 public static function getExtLicenseFileName( $extDir ) {
897 foreach ( scandir( $extDir ) as $file ) {
898 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
899 if ( preg_match( '/^((COPYING)|(LICENSE))(\.txt)?$/', $file ) &&
900 is_readable( $fullPath ) &&
911 * Convert an array of items into a list for display.
913 * @param array $list of elements to display
914 * @param $sort Boolean: whether to sort the items in $list
918 function listToText( $list, $sort = true ) {
919 $cnt = count( $list );
922 // Enforce always returning a string
923 return (string)self
::arrayToString( $list[0] );
924 } elseif ( $cnt == 0 ) {
931 return $this->getLanguage()->listToText( array_map( array( __CLASS__
, 'arrayToString' ), $list ) );
936 * Convert an array or object to a string for display.
938 * @param $list Mixed: will convert an array to string if given and return
939 * the paramater unaltered otherwise
943 public static function arrayToString( $list ) {
944 if ( is_array( $list ) && count( $list ) == 1 ) {
947 if ( is_object( $list ) ) {
948 $class = wfMessage( 'parentheses' )->params( get_class( $list ) )->escaped();
951 } elseif ( !is_array( $list ) ) {
954 if ( is_object( $list[0] ) ) {
955 $class = get_class( $list[0] );
960 return wfMessage( 'parentheses' )->params( "$class, {$list[1]}" )->escaped();
965 * Get an associative array of information about a given path, from its .svn
966 * subdirectory. Returns false on error, such as if the directory was not
967 * checked out with subversion.
971 * checkout-rev The revision which was checked out
973 * directory-rev The revision when the directory was last modified
974 * url The subversion URL of the directory
975 * repo-url The base URL of the repository
976 * viewvc-url A ViewVC URL pointing to the checked-out revision
980 public static function getSvnInfo( $dir ) {
981 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
982 $entries = $dir . '/.svn/entries';
984 if ( !file_exists( $entries ) ) {
988 $lines = file( $entries );
989 if ( !count( $lines ) ) {
993 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
994 if ( preg_match( '/^<\?xml/', $lines[0] ) ) {
995 // subversion is release <= 1.3
996 if ( !function_exists( 'simplexml_load_file' ) ) {
997 // We could fall back to expat... YUCK
1001 // SimpleXml whines about the xmlns...
1002 wfSuppressWarnings();
1003 $xml = simplexml_load_file( $entries );
1004 wfRestoreWarnings();
1007 foreach ( $xml->entry
as $entry ) {
1008 if ( $xml->entry
[0]['name'] == '' ) {
1009 // The directory entry should always have a revision marker.
1010 if ( $entry['revision'] ) {
1011 return array( 'checkout-rev' => intval( $entry['revision'] ) );
1020 // Subversion is release 1.4 or above.
1021 if ( count( $lines ) < 11 ) {
1026 'checkout-rev' => intval( trim( $lines[3] ) ),
1027 'url' => trim( $lines[4] ),
1028 'repo-url' => trim( $lines[5] ),
1029 'directory-rev' => intval( trim( $lines[10] ) )
1032 if ( isset( self
::$viewvcUrls[$info['repo-url']] ) ) {
1033 $viewvc = str_replace(
1035 self
::$viewvcUrls[$info['repo-url']],
1039 $viewvc .= '/?pathrev=';
1040 $viewvc .= urlencode( $info['checkout-rev'] );
1041 $info['viewvc-url'] = $viewvc;
1048 * Retrieve the revision number of a Subversion working directory.
1050 * @param string $dir directory of the svn checkout
1052 * @return Integer: revision number as int
1054 public static function getSvnRevision( $dir ) {
1055 $info = self
::getSvnInfo( $dir );
1057 if ( $info === false ) {
1059 } elseif ( isset( $info['checkout-rev'] ) ) {
1060 return $info['checkout-rev'];
1067 * @param string $dir directory of the git checkout
1068 * @return bool|String sha1 of commit HEAD points to
1070 public static function getGitHeadSha1( $dir ) {
1071 $repo = new GitInfo( $dir );
1073 return $repo->getHeadSHA1();
1077 * Get the list of entry points and their URLs
1078 * @return string Wikitext
1080 public function getEntryPointInfo() {
1081 global $wgArticlePath, $wgScriptPath;
1082 $scriptPath = $wgScriptPath ?
$wgScriptPath : "/";
1083 $entryPoints = array(
1084 'version-entrypoints-articlepath' => $wgArticlePath,
1085 'version-entrypoints-scriptpath' => $scriptPath,
1086 'version-entrypoints-index-php' => wfScript( 'index' ),
1087 'version-entrypoints-api-php' => wfScript( 'api' ),
1088 'version-entrypoints-load-php' => wfScript( 'load' ),
1091 $language = $this->getLanguage();
1092 $thAttribures = array(
1093 'dir' => $language->getDir(),
1094 'lang' => $language->getCode()
1096 $out = Html
::element( 'h2', array( 'id' => 'mw-version-entrypoints' ), $this->msg( 'version-entrypoints' )->text() ) .
1097 Html
::openElement( 'table',
1099 'class' => 'wikitable plainlinks',
1100 'id' => 'mw-version-entrypoints-table',
1105 Html
::openElement( 'tr' ) .
1106 Html
::element( 'th', $thAttribures, $this->msg( 'version-entrypoints-header-entrypoint' )->text() ) .
1107 Html
::element( 'th', $thAttribures, $this->msg( 'version-entrypoints-header-url' )->text() ) .
1108 Html
::closeElement( 'tr' );
1110 foreach ( $entryPoints as $message => $value ) {
1111 $url = wfExpandUrl( $value, PROTO_RELATIVE
);
1112 $out .= Html
::openElement( 'tr' ) .
1113 // ->text() looks like it should be ->parse(), but this function
1114 // returns wikitext, not HTML, boo
1115 Html
::rawElement( 'td', array(), $this->msg( $message )->text() ) .
1116 Html
::rawElement( 'td', array(), Html
::rawElement( 'code', array(), "[$url $value]" ) ) .
1117 Html
::closeElement( 'tr' );
1120 $out .= Html
::closeElement( 'table' );
1125 protected function getGroupName() {