d509f218c10fb730239969760b6be6ce4fea93ac
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__
);
262 * Return a wikitext-formatted string of the MediaWiki version with a link to
263 * the SVN revision or the git SHA1 of head if available.
264 * Git is prefered over Svn
265 * The fallback is just $wgVersion
269 public static function getVersionLinked() {
271 wfProfileIn( __METHOD__
);
273 $gitVersion = self
::getVersionLinkedGit();
277 $svnVersion = self
::getVersionLinkedSvn();
281 $v = $wgVersion; // fallback
285 wfProfileOut( __METHOD__
);
290 * @return string wgVersion + a link to subversion revision of svn BASE
292 private static function getVersionLinkedSvn() {
295 $info = self
::getSvnInfo( $IP );
296 if ( !isset( $info['checkout-rev'] ) ) {
300 $linkText = wfMessage(
301 'version-svn-revision',
302 isset( $info['directory-rev'] ) ?
$info['directory-rev'] : '',
303 $info['checkout-rev']
306 if ( isset( $info['viewvc-url'] ) ) {
307 $version = "[{$info['viewvc-url']} $linkText]";
309 $version = $linkText;
312 return self
::getwgVersionLinked() . " $version";
318 private static function getwgVersionLinked() {
321 if ( wfRunHooks( 'SpecialVersionVersionUrl', array( $wgVersion, &$versionUrl ) ) ) {
322 $versionParts = array();
323 preg_match( "/^(\d+\.\d+)/", $wgVersion, $versionParts );
324 $versionUrl = "https://www.mediawiki.org/wiki/MediaWiki_{$versionParts[1]}";
326 return "[$versionUrl $wgVersion]";
330 * @since 1.22 Returns the HEAD date in addition to the sha1 and link
331 * @return bool|string wgVersion + HEAD sha1 stripped to the first 7 chars with link and date, or false on failure
333 private static function getVersionLinkedGit() {
336 $gitInfo = new GitInfo( $IP );
337 $headSHA1 = $gitInfo->getHeadSHA1();
342 $shortSHA1 = '(' . substr( $headSHA1, 0, 7 ) . ')';
344 $gitHeadUrl = $gitInfo->getHeadViewUrl();
345 if ( $gitHeadUrl !== false ) {
346 $shortSHA1 = "[$gitHeadUrl $shortSHA1]";
349 $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
350 if ( $gitHeadCommitDate ) {
351 $shortSHA1 .= Html
::element( 'br' ) . $wgLang->timeanddate( $gitHeadCommitDate, true );
354 return self
::getwgVersionLinked() . " $shortSHA1";
358 * Returns an array with the base extension types.
359 * Type is stored as array key, the message as array value.
361 * TODO: ideally this would return all extension types, including
362 * those added by SpecialVersionExtensionTypes. This is not possible
363 * since this hook is passing along $this though.
369 public static function getExtensionTypes() {
370 if ( self
::$extensionTypes === false ) {
371 self
::$extensionTypes = array(
372 'specialpage' => wfMessage( 'version-specialpages' )->text(),
373 'parserhook' => wfMessage( 'version-parserhooks' )->text(),
374 'variable' => wfMessage( 'version-variables' )->text(),
375 'media' => wfMessage( 'version-mediahandlers' )->text(),
376 'antispam' => wfMessage( 'version-antispam' )->text(),
377 'skin' => wfMessage( 'version-skins' )->text(),
378 'api' => wfMessage( 'version-api' )->text(),
379 'other' => wfMessage( 'version-other' )->text(),
382 wfRunHooks( 'ExtensionTypes', array( &self
::$extensionTypes ) );
385 return self
::$extensionTypes;
389 * Returns the internationalized name for an extension type.
393 * @param $type String
397 public static function getExtensionTypeName( $type ) {
398 $types = self
::getExtensionTypes();
399 return isset( $types[$type] ) ?
$types[$type] : $types['other'];
403 * Generate wikitext showing extensions name, URL, author and description.
405 * @return String: Wikitext
407 function getExtensionCredits() {
408 global $wgExtensionCredits;
410 if ( !count( $wgExtensionCredits ) ) {
414 $extensionTypes = self
::getExtensionTypes();
417 * @deprecated as of 1.17, use hook ExtensionTypes instead.
419 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
421 $out = Xml
::element( 'h2', array( 'id' => 'mw-version-ext' ), $this->msg( 'version-extensions' )->text() ) .
422 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-ext' ) );
424 // Make sure the 'other' type is set to an array.
425 if ( !array_key_exists( 'other', $wgExtensionCredits ) ) {
426 $wgExtensionCredits['other'] = array();
429 // Find all extensions that do not have a valid type and give them the type 'other'.
430 foreach ( $wgExtensionCredits as $type => $extensions ) {
431 if ( !array_key_exists( $type, $extensionTypes ) ) {
432 $wgExtensionCredits['other'] = array_merge( $wgExtensionCredits['other'], $extensions );
436 // Loop through the extension categories to display their extensions in the list.
437 foreach ( $extensionTypes as $type => $message ) {
438 if ( $type != 'other' ) {
439 $out .= $this->getExtensionCategory( $type, $message );
443 // We want the 'other' type to be last in the list.
444 $out .= $this->getExtensionCategory( 'other', $extensionTypes['other'] );
446 $out .= Xml
::closeElement( 'table' );
452 * Obtains a list of installed parser tags and the associated H2 header
454 * @return string HTML output
456 protected function getParserTags() {
459 $tags = $wgParser->getTags();
461 if ( count( $tags ) ) {
462 $out = Html
::rawElement(
464 array( 'class' => 'mw-headline' ),
465 Linker
::makeExternalLink(
466 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Tag_extensions',
467 $this->msg( 'version-parser-extensiontags' )->parse(),
468 false /* msg()->parse() already escapes */
472 array_walk( $tags, function( &$value ) {
473 $value = '<' . htmlentities( $value ) . '>';
475 $out .= $this->listToText( $tags );
484 * Obtains a list of installed parser function hooks and the associated H2 header
486 * @return string HTML output
488 protected function getParserFunctionHooks() {
491 $fhooks = $wgParser->getFunctionHooks();
492 if ( count( $fhooks ) ) {
493 $out = Html
::rawElement( 'h2', array( 'class' => 'mw-headline' ), Linker
::makeExternalLink(
494 '//www.mediawiki.org/wiki/Special:MyLanguage/Manual:Parser_functions',
495 $this->msg( 'version-parser-function-hooks' )->parse(),
496 false /* msg()->parse() already escapes */
499 $out .= $this->listToText( $fhooks );
508 * Creates and returns the HTML for a single extension category.
512 * @param $type String
513 * @param $message String
517 protected function getExtensionCategory( $type, $message ) {
518 global $wgExtensionCredits;
522 if ( array_key_exists( $type, $wgExtensionCredits ) && count( $wgExtensionCredits[$type] ) > 0 ) {
523 $out .= $this->openExtType( $message, 'credits-' . $type );
525 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
527 foreach ( $wgExtensionCredits[$type] as $extension ) {
528 $out .= $this->getCreditsForExtension( $extension );
536 * Callback to sort extensions by type.
541 function compare( $a, $b ) {
542 if ( $a['name'] === $b['name'] ) {
545 return $this->getLanguage()->lc( $a['name'] ) > $this->getLanguage()->lc( $b['name'] )
552 * Creates and formats a version line for a single extension.
554 * Information for five columns will be created. Parameters required in the
555 * $extension array for part rendering are indicated in ()
556 * - The name of (name), and URL link to (url), the extension
557 * - Official version number (version) and if available version control system
558 * revision (path), link, and date
559 * - If available the short name of the license (license-name) and a linke
560 * to ((LICENSE)|(COPYING))(\.txt)? if it exists.
561 * - Description of extension (descriptionmsg or description)
562 * - List of authors (author) and link to a ((AUTHORS)|(CREDITS))(\.txt)? file if it exists
564 * @param $extension Array
566 * @return string raw HTML
568 function getCreditsForExtension( array $extension ) {
569 $out = $this->getOutput();
571 // We must obtain the information for all the bits and pieces!
572 // ... such as extension names and links
573 $extensionName = isset( $extension['name'] ) ?
$extension['name'] : '[no name]';
574 if ( isset( $extension['url'] ) ) {
575 $extensionNameLink = Linker
::makeExternalLink(
580 array( 'class' => 'mw-version-ext-name' )
583 $extensionNameLink = $extensionName;
586 // ... and the version information
587 // If the extension path is set we will check that directory for GIT and SVN
588 // metadata in an attempt to extract date and vcs commit metadata.
589 $canonicalVersion = '–';
590 $extensionPath = null;
595 if ( isset( $extension['version'] ) ) {
596 $canonicalVersion = $out->parseInline( $extension['version'] );
599 if ( isset( $extension['path'] ) ) {
600 $extensionPath = dirname( $extension['path'] );
601 $gitInfo = new GitInfo( $extensionPath );
602 $vcsVersion = $gitInfo->getHeadSHA1();
603 if ( $vcsVersion !== false ) {
604 $vcsVersion = substr( $vcsVersion, 0, 7 );
605 $vcsLink = $gitInfo->getHeadViewUrl();
606 $vcsDate = $gitInfo->getHeadCommitDate();
608 $svnInfo = self
::getSvnInfo( $extensionPath );
609 if ( $svnInfo !== false ) {
610 $vcsVersion = $this->msg( 'version-svn-revision', $svnInfo['checkout-rev'] )->text();
611 $vcsLink = isset( $svnInfo['viewvc-url'] ) ?
$svnInfo['viewvc-url'] : '';
616 $versionString = Html
::rawElement( 'span', array( 'class' => 'mw-version-ext-version' ), $canonicalVersion );
619 $vcsVerString = Linker
::makeExternalLink(
621 $this->msg( 'version-version', $vcsVersion ),
624 array( 'class' => 'mw-version-ext-vcs-version' )
627 $vcsVerString = Html
::element( 'span',
628 array( 'class' => 'mw-version-ext-vcs-version' ),
632 $versionString .= " {$vcsVerString}";
635 $vcsTimeString = Html
::element( 'span',
636 array( 'class' => 'mw-version-ext-vcs-timestamp' ),
637 $this->getLanguage()->timeanddate( $vcsDate )
639 $versionString .= " {$vcsTimeString}";
641 $versionString = Html
::rawElement( 'span',
642 array( 'class' => 'mw-version-ext-meta-version' ),
647 // ... and license information; if a license file exists we
650 if ( isset( $extension['license-name'] ) ) {
651 $licenseLink = Linker
::link(
652 $this->getPageTitle( 'License/' . $extensionName ),
653 $out->parseInline( $extension['license-name'] ),
654 array( 'class' => 'mw-version-ext-license' )
656 } elseif ( $this->getExtLicenseFileName( $extensionPath ) ) {
657 $licenseLink = Linker
::link(
658 $this->getPageTitle( 'License/' . $extensionName ),
659 $this->msg( 'version-ext-license' ),
660 array( 'class' => 'mw-version-ext-license' )
664 // ... and generate the description; which can be a parameterized l10n message
665 // in the form array( <msgname>, <parameter>, <parameter>... ) or just a straight
667 if ( isset( $extension['descriptionmsg'] ) ) {
668 // Localized description of extension
669 $descriptionMsg = $extension['descriptionmsg'];
671 if ( is_array( $descriptionMsg ) ) {
672 $descriptionMsgKey = $descriptionMsg[0]; // Get the message key
673 array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
674 array_map( "htmlspecialchars", $descriptionMsg ); // For sanity
675 $description = $this->msg( $descriptionMsgKey, $descriptionMsg )->text();
677 $description = $this->msg( $descriptionMsg )->text();
679 } elseif ( isset( $extension['description'] ) ) {
680 // Non localized version
681 $description = $extension['description'];
685 $description = $out->parseInline( $description );
687 // ... now get the authors for this extension
688 $authors = isset( $extension['author'] ) ?
$extension['author'] : array();
689 $authors = $this->listAuthors( $authors, $extensionName, $extensionPath );
691 // Finally! Create the table
692 $html = Html
::openElement( 'tr', array(
693 'class' => 'mw-version-ext',
694 'id' => "mw-version-ext-{$extensionName}"
698 $html .= Html
::rawElement( 'td', array(), $extensionNameLink );
699 $html .= Html
::rawElement( 'td', array(), $versionString );
700 $html .= Html
::rawElement( 'td', array(), $licenseLink );
701 $html .= Html
::rawElement( 'td', array( 'class' => 'mw-version-ext-description' ), $description );
702 $html .= Html
::rawElement( 'td', array( 'class' => 'mw-version-ext-authors' ), $authors );
704 $html .= Html
::closeElement( 'td' );
710 * Generate wikitext showing hooks in $wgHooks.
712 * @return String: wikitext
714 private function getWgHooks() {
715 global $wgSpecialVersionShowHooks, $wgHooks;
717 if ( $wgSpecialVersionShowHooks && count( $wgHooks ) ) {
718 $myWgHooks = $wgHooks;
722 $ret[] = '== {{int:version-hooks}} ==';
723 $ret[] = Html
::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-hooks' ) );
724 $ret[] = Html
::openElement( 'tr' );
725 $ret[] = Html
::element( 'th', array(), $this->msg( 'version-hook-name' )->text() );
726 $ret[] = Html
::element( 'th', array(), $this->msg( 'version-hook-subscribedby' )->text() );
727 $ret[] = Html
::closeElement( 'tr' );
729 foreach ( $myWgHooks as $hook => $hooks ) {
730 $ret[] = Html
::openElement( 'tr' );
731 $ret[] = Html
::element( 'td', array(), $hook );
732 $ret[] = Html
::element( 'td', array(), $this->listToText( $hooks ) );
733 $ret[] = Html
::closeElement( 'tr' );
736 $ret[] = Html
::closeElement( 'table' );
738 return implode( "\n", $ret );
744 private function openExtType( $text, $name = null ) {
747 $opt = array( 'colspan' => 5 );
748 if ( $this->firstExtOpened
) {
749 // Insert a spacing line
750 $out .= Html
::rawElement( 'tr', array( 'class' => 'sv-space' ),
751 Html
::element( 'td', $opt )
754 $this->firstExtOpened
= true;
757 $opt['id'] = "sv-$name";
760 $out .= Html
::rawElement( 'tr', array(),
761 Html
::element( 'th', $opt, $text )
764 $out .= Html
::openElement( 'tr' );
765 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
766 $this->msg( 'version-ext-colheader-name' )->text() );
767 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
768 $this->msg( 'version-ext-colheader-version' )->text() );
769 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
770 $this->msg( 'version-ext-colheader-license' )->text() );
771 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
772 $this->msg( 'version-ext-colheader-description' )->text() );
773 $out .= Html
::element( 'th', array( 'class' => 'mw-version-ext-col-label' ),
774 $this->msg( 'version-ext-colheader-credits' )->text() );
775 $out .= Html
::closeElement( 'tr' );
781 * Get information about client's IP address.
783 * @return String: HTML fragment
785 private function IPInfo() {
786 $ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) );
787 return "<!-- visited from $ip -->\n<span style='display:none'>visited from $ip</span>";
791 * Return a formatted unsorted list of authors
794 * If an item in the $authors array is '...' it is assumed to indicate an
795 * 'and others' string which will then be linked to an ((AUTHORS)|(CREDITS))(\.txt)?
796 * file if it exists in $dir.
798 * Similarly an entry ending with ' ...]' is assumed to be a link to an
801 * If no '...' string variant is found, but an authors file is found an
802 * 'and others' will be added to the end of the credits.
804 * @param $authors mixed: string or array of strings
805 * @param $extName string: name of the extension for link creation
806 * @param $extDir string: path to the extension root directory
808 * @return String: HTML fragment
810 function listAuthors( $authors, $extName, $extDir ) {
814 foreach ( (array)$authors as $item ) {
815 if ( $item == '...' ) {
818 if ( $this->getExtAuthorsFileName( $extDir ) ) {
819 $text = Linker
::link(
820 $this->getPageTitle( "Credits/$extName" ),
821 $this->msg( 'version-poweredby-others' )->text()
824 $text = $this->msg( 'version-poweredby-others' )->text();
828 } elseif ( substr( $item, -5 ) == ' ...]' ) {
830 $list[] = $this->getOutput()->parseInline(
831 substr( $item, 0, -4 ) . $this->msg( 'version-poweredby-others' )->text() . "]"
835 $list[] = $this->getOutput()->parseInline( $item );
839 if ( !$hasOthers && $this->getExtAuthorsFileName( $extDir ) ) {
840 $list[] = $text = Linker
::link(
841 $this->getPageTitle( "Credits/$extName" ),
842 $this->msg( 'version-poweredby-others' )->text()
846 return $this->listToText( $list, false );
850 * Obtains the full path of an extensions authors or credits file if
853 * @param string $extDir: Path to the extensions root directory
857 * @return bool|string False if no such file exists, otherwise returns
860 public static function getExtAuthorsFileName( $extDir ) {
865 foreach ( scandir( $extDir ) as $file ) {
866 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
867 if ( preg_match( '/^((AUTHORS)|(CREDITS))(\.txt)?$/', $file ) &&
868 is_readable( $fullPath ) &&
879 * Obtains the full path of an extensions copying or license file if
882 * @param string $extDir: Path to the extensions root directory
886 * @return bool|string False if no such file exists, otherwise returns
889 public static function getExtLicenseFileName( $extDir ) {
894 foreach ( scandir( $extDir ) as $file ) {
895 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
896 if ( preg_match( '/^((COPYING)|(LICENSE))(\.txt)?$/', $file ) &&
897 is_readable( $fullPath ) &&
908 * Convert an array of items into a list for display.
910 * @param array $list of elements to display
911 * @param $sort Boolean: whether to sort the items in $list
915 function listToText( $list, $sort = true ) {
916 $cnt = count( $list );
919 // Enforce always returning a string
920 return (string)self
::arrayToString( $list[0] );
921 } elseif ( $cnt == 0 ) {
927 return $this->getLanguage()->listToText( array_map( array( __CLASS__
, 'arrayToString' ), $list ) );
932 * Convert an array or object to a string for display.
934 * @param $list Mixed: will convert an array to string if given and return
935 * the paramater unaltered otherwise
939 public static function arrayToString( $list ) {
940 if ( is_array( $list ) && count( $list ) == 1 ) {
943 if ( is_object( $list ) ) {
944 $class = wfMessage( 'parentheses' )->params( get_class( $list ) )->escaped();
946 } elseif ( !is_array( $list ) ) {
949 if ( is_object( $list[0] ) ) {
950 $class = get_class( $list[0] );
954 return wfMessage( 'parentheses' )->params( "$class, {$list[1]}" )->escaped();
959 * Get an associative array of information about a given path, from its .svn
960 * subdirectory. Returns false on error, such as if the directory was not
961 * checked out with subversion.
965 * checkout-rev The revision which was checked out
967 * directory-rev The revision when the directory was last modified
968 * url The subversion URL of the directory
969 * repo-url The base URL of the repository
970 * viewvc-url A ViewVC URL pointing to the checked-out revision
974 public static function getSvnInfo( $dir ) {
975 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
976 $entries = $dir . '/.svn/entries';
978 if ( !file_exists( $entries ) ) {
982 $lines = file( $entries );
983 if ( !count( $lines ) ) {
987 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
988 if ( preg_match( '/^<\?xml/', $lines[0] ) ) {
989 // subversion is release <= 1.3
990 if ( !function_exists( 'simplexml_load_file' ) ) {
991 // We could fall back to expat... YUCK
995 // SimpleXml whines about the xmlns...
996 wfSuppressWarnings();
997 $xml = simplexml_load_file( $entries );
1001 foreach ( $xml->entry
as $entry ) {
1002 if ( $xml->entry
[0]['name'] == '' ) {
1003 // The directory entry should always have a revision marker.
1004 if ( $entry['revision'] ) {
1005 return array( 'checkout-rev' => intval( $entry['revision'] ) );
1014 // Subversion is release 1.4 or above.
1015 if ( count( $lines ) < 11 ) {
1020 'checkout-rev' => intval( trim( $lines[3] ) ),
1021 'url' => trim( $lines[4] ),
1022 'repo-url' => trim( $lines[5] ),
1023 'directory-rev' => intval( trim( $lines[10] ) )
1026 if ( isset( self
::$viewvcUrls[$info['repo-url']] ) ) {
1027 $viewvc = str_replace(
1029 self
::$viewvcUrls[$info['repo-url']],
1033 $viewvc .= '/?pathrev=';
1034 $viewvc .= urlencode( $info['checkout-rev'] );
1035 $info['viewvc-url'] = $viewvc;
1042 * Retrieve the revision number of a Subversion working directory.
1044 * @param string $dir directory of the svn checkout
1046 * @return Integer: revision number as int
1048 public static function getSvnRevision( $dir ) {
1049 $info = self
::getSvnInfo( $dir );
1051 if ( $info === false ) {
1053 } elseif ( isset( $info['checkout-rev'] ) ) {
1054 return $info['checkout-rev'];
1061 * @param string $dir directory of the git checkout
1062 * @return bool|String sha1 of commit HEAD points to
1064 public static function getGitHeadSha1( $dir ) {
1065 $repo = new GitInfo( $dir );
1066 return $repo->getHeadSHA1();
1070 * Get the list of entry points and their URLs
1071 * @return string Wikitext
1073 public function getEntryPointInfo() {
1074 global $wgArticlePath, $wgScriptPath;
1075 $scriptPath = $wgScriptPath ?
$wgScriptPath : "/";
1076 $entryPoints = array(
1077 'version-entrypoints-articlepath' => $wgArticlePath,
1078 'version-entrypoints-scriptpath' => $scriptPath,
1079 'version-entrypoints-index-php' => wfScript( 'index' ),
1080 'version-entrypoints-api-php' => wfScript( 'api' ),
1081 'version-entrypoints-load-php' => wfScript( 'load' ),
1084 $language = $this->getLanguage();
1085 $thAttribures = array(
1086 'dir' => $language->getDir(),
1087 'lang' => $language->getCode()
1089 $out = Html
::element( 'h2', array( 'id' => 'mw-version-entrypoints' ), $this->msg( 'version-entrypoints' )->text() ) .
1090 Html
::openElement( 'table',
1092 'class' => 'wikitable plainlinks',
1093 'id' => 'mw-version-entrypoints-table',
1098 Html
::openElement( 'tr' ) .
1099 Html
::element( 'th', $thAttribures, $this->msg( 'version-entrypoints-header-entrypoint' )->text() ) .
1100 Html
::element( 'th', $thAttribures, $this->msg( 'version-entrypoints-header-url' )->text() ) .
1101 Html
::closeElement( 'tr' );
1103 foreach ( $entryPoints as $message => $value ) {
1104 $url = wfExpandUrl( $value, PROTO_RELATIVE
);
1105 $out .= Html
::openElement( 'tr' ) .
1106 // ->text() looks like it should be ->parse(), but this function
1107 // returns wikitext, not HTML, boo
1108 Html
::rawElement( 'td', array(), $this->msg( $message )->text() ) .
1109 Html
::rawElement( 'td', array(), Html
::rawElement( 'code', array(), "[$url $value]" ) ) .
1110 Html
::closeElement( 'tr' );
1113 $out .= Html
::closeElement( 'table' );
1117 protected function getGroupName() {