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 $wgSpecialVersionShowHooks, $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 );
60 if ( isset( $parts[1] ) ) {
61 $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 );
92 $out->setPageTitle( $this->msg( 'version-credits-title', $extName ) );
93 $out->addWikiText( $wikiText );
97 $wikiText = '{{int:version-license-not-found}}';
98 if ( $extName === 'MediaWiki' ) {
99 $wikiText = file_get_contents( $IP . '/COPYING' );
100 } elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) {
101 $file = $this->getExtLicenseFileName( dirname( $extNode['path'] ) );
103 $wikiText = file_get_contents( $file );
104 if ( !isset( $extNode['license-name'] ) ) {
105 // If the developer did not explicitly set license-name they probably
106 // are unaware that we're now sucking this file in and thus it's probably
107 // not wikitext friendly.
108 $wikiText = "<pre>$wikiText</pre>";
113 $out->setPageTitle( $this->msg( 'version-license-title', $extName ) );
114 $out->addWikiText( $wikiText );
119 $this->getMediaWikiCredits() .
120 $this->softwareInformation() .
121 $this->getEntryPointInfo()
123 $out->addHtml( $this->getExtensionCredits() );
124 if ( $wgSpecialVersionShowHooks ) {
125 $out->addWikiText( $this->getWgHooks() );
128 $out->addHTML( $this->IPInfo() );
135 * Returns wiki text showing the license information.
139 private static function getMediaWikiCredits() {
140 $ret = Xml
::element( 'h2', array( 'id' => 'mw-version-license' ), wfMessage( 'version-license' )->text() );
142 // This text is always left-to-right.
143 $ret .= '<div class="plainlinks">';
145 " . self
::getCopyrightAndAuthorList() . "\n
146 " . wfMessage( 'version-license-info' )->text();
149 return str_replace( "\t\t", '', $ret ) . "\n";
153 * Get the "MediaWiki is copyright 2001-20xx by lots of cool guys" text
157 public static function getCopyrightAndAuthorList() {
160 if ( defined( 'MEDIAWIKI_INSTALL' ) ) {
161 $othersLink = '[//www.mediawiki.org/wiki/Special:Version/Credits ' . wfMessage( 'version-poweredby-others' )->text() . ']';
163 $othersLink = '[[Special:Version/Credits|' . wfMessage( 'version-poweredby-others' )->text() . ']]';
166 $translatorsLink = '[//translatewiki.net/wiki/Translating:MediaWiki/Credits ' . wfMessage( 'version-poweredby-translators' )->text() . ']';
169 'Magnus Manske', 'Brion Vibber', 'Lee Daniel Crocker',
170 'Tim Starling', 'Erik Möller', 'Gabriel Wicke', 'Ævar Arnfjörð Bjarmason',
171 'Niklas Laxström', 'Domas Mituzas', 'Rob Church', 'Yuri Astrakhan',
172 'Aryeh Gregor', 'Aaron Schulz', 'Andrew Garrett', 'Raimond Spekking',
173 'Alexandre Emsenhuber', 'Siebrand Mazeland', 'Chad Horohoe',
174 'Roan Kattouw', 'Trevor Parscal', 'Bryan Tong Minh', 'Sam Reed',
175 'Victor Vasiliev', 'Rotem Liss', 'Platonides', 'Antoine Musso',
176 'Timo Tijhof', 'Daniel Kinzler', 'Jeroen De Dauw', $othersLink,
180 return wfMessage( 'version-poweredby-credits', MWTimestamp
::getLocalInstance()->format( 'Y' ),
181 $wgLang->listToText( $authorList ) )->text();
185 * Returns wiki text showing the third party software versions (apache, php, mysql).
189 static function softwareInformation() {
190 $dbr = wfGetDB( DB_SLAVE
);
192 // Put the software in an array of form 'name' => 'version'. All messages should
193 // be loaded here, so feel free to use wfMessage in the 'name'. Raw HTML or
194 // wikimarkup can be used.
196 $software['[https://www.mediawiki.org/ MediaWiki]'] = self
::getVersionLinked();
197 $software['[http://www.php.net/ PHP]'] = phpversion() . " (" . PHP_SAPI
. ")";
198 $software[$dbr->getSoftwareLink()] = $dbr->getServerInfo();
200 // Allow a hook to add/remove items.
201 wfRunHooks( 'SoftwareInfo', array( &$software ) );
203 $out = Xml
::element( 'h2', array( 'id' => 'mw-version-software' ), wfMessage( 'version-software' )->text() ) .
204 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-software' ) ) .
206 <th>" . wfMessage( 'version-software-product' )->text() . "</th>
207 <th>" . wfMessage( 'version-software-version' )->text() . "</th>
210 foreach ( $software as $name => $version ) {
212 <td>" . $name . "</td>
213 <td dir=\"ltr\">" . $version . "</td>
217 return $out . Xml
::closeElement( 'table' );
221 * Return a string of the MediaWiki version with SVN revision if available.
223 * @param $flags String
226 public static function getVersion( $flags = '' ) {
227 global $wgVersion, $IP;
228 wfProfileIn( __METHOD__
);
230 $gitInfo = self
::getGitHeadSha1( $IP );
231 $svnInfo = self
::getSvnInfo( $IP );
232 if ( !$svnInfo && !$gitInfo ) {
233 $version = $wgVersion;
234 } elseif ( $gitInfo && $flags === 'nodb' ) {
235 $shortSha1 = substr( $gitInfo, 0, 7 );
236 $version = "$wgVersion ($shortSha1)";
237 } elseif ( $gitInfo ) {
238 $shortSha1 = substr( $gitInfo, 0, 7 );
239 $shortSha1 = wfMessage( 'parentheses' )->params( $shortSha1 )->escaped();
240 $version = "$wgVersion $shortSha1";
241 } elseif ( $flags === 'nodb' ) {
242 $version = "$wgVersion (r{$svnInfo['checkout-rev']})";
244 $version = $wgVersion . ' ' .
246 'version-svn-revision',
247 isset( $info['directory-rev'] ) ?
$info['directory-rev'] : '',
248 $info['checkout-rev']
252 wfProfileOut( __METHOD__
);
257 * Return a wikitext-formatted string of the MediaWiki version with a link to
258 * the SVN revision or the git SHA1 of head if available.
259 * Git is prefered over Svn
260 * The fallback is just $wgVersion
264 public static function getVersionLinked() {
266 wfProfileIn( __METHOD__
);
268 $gitVersion = self
::getVersionLinkedGit();
272 $svnVersion = self
::getVersionLinkedSvn();
276 $v = $wgVersion; // fallback
280 wfProfileOut( __METHOD__
);
285 * @return string wgVersion + a link to subversion revision of svn BASE
287 private static function getVersionLinkedSvn() {
290 $info = self
::getSvnInfo( $IP );
291 if ( !isset( $info['checkout-rev'] ) ) {
295 $linkText = wfMessage(
296 'version-svn-revision',
297 isset( $info['directory-rev'] ) ?
$info['directory-rev'] : '',
298 $info['checkout-rev']
301 if ( isset( $info['viewvc-url'] ) ) {
302 $version = "[{$info['viewvc-url']} $linkText]";
304 $version = $linkText;
307 return self
::getwgVersionLinked() . " $version";
313 private static function getwgVersionLinked() {
316 if ( wfRunHooks( 'SpecialVersionVersionUrl', array( $wgVersion, &$versionUrl ) ) ) {
317 $versionParts = array();
318 preg_match( "/^(\d+\.\d+)/", $wgVersion, $versionParts );
319 $versionUrl = "https://www.mediawiki.org/wiki/MediaWiki_{$versionParts[1]}";
321 return "[$versionUrl $wgVersion]";
325 * @since 1.22 Returns the HEAD date in addition to the sha1 and link
326 * @return bool|string wgVersion + HEAD sha1 stripped to the first 7 chars with link and date, or false on failure
328 private static function getVersionLinkedGit() {
331 $gitInfo = new GitInfo( $IP );
332 $headSHA1 = $gitInfo->getHeadSHA1();
337 $shortSHA1 = '(' . substr( $headSHA1, 0, 7 ) . ')';
339 $gitHeadUrl = $gitInfo->getHeadViewUrl();
340 if ( $gitHeadUrl !== false ) {
341 $shortSHA1 = "[$gitHeadUrl $shortSHA1]";
344 $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
345 if ( $gitHeadCommitDate ) {
346 $shortSHA1 .= Html
::element( 'br' ) . $wgLang->timeanddate( $gitHeadCommitDate, true );
349 return self
::getwgVersionLinked() . " $shortSHA1";
353 * Returns an array with the base extension types.
354 * Type is stored as array key, the message as array value.
356 * TODO: ideally this would return all extension types, including
357 * those added by SpecialVersionExtensionTypes. This is not possible
358 * since this hook is passing along $this though.
364 public static function getExtensionTypes() {
365 if ( self
::$extensionTypes === false ) {
366 self
::$extensionTypes = array(
367 'specialpage' => wfMessage( 'version-specialpages' )->text(),
368 'parserhook' => wfMessage( 'version-parserhooks' )->text(),
369 'variable' => wfMessage( 'version-variables' )->text(),
370 'media' => wfMessage( 'version-mediahandlers' )->text(),
371 'antispam' => wfMessage( 'version-antispam' )->text(),
372 'skin' => wfMessage( 'version-skins' )->text(),
373 'api' => wfMessage( 'version-api' )->text(),
374 'other' => wfMessage( 'version-other' )->text(),
377 wfRunHooks( 'ExtensionTypes', array( &self
::$extensionTypes ) );
380 return self
::$extensionTypes;
384 * Returns the internationalized name for an extension type.
388 * @param $type String
392 public static function getExtensionTypeName( $type ) {
393 $types = self
::getExtensionTypes();
394 return isset( $types[$type] ) ?
$types[$type] : $types['other'];
398 * Generate wikitext showing extensions name, URL, author and description.
400 * @return String: Wikitext
402 function getExtensionCredits() {
403 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser;
405 if ( !count( $wgExtensionCredits ) && !count( $wgExtensionFunctions ) ) {
409 $extensionTypes = self
::getExtensionTypes();
412 * @deprecated as of 1.17, use hook ExtensionTypes instead.
414 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
416 $out = Xml
::element( 'h2', array( 'id' => 'mw-version-ext' ), $this->msg( 'version-extensions' )->text() ) .
417 Xml
::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-ext' ) );
419 // Make sure the 'other' type is set to an array.
420 if ( !array_key_exists( 'other', $wgExtensionCredits ) ) {
421 $wgExtensionCredits['other'] = array();
424 // Find all extensions that do not have a valid type and give them the type 'other'.
425 foreach ( $wgExtensionCredits as $type => $extensions ) {
426 if ( !array_key_exists( $type, $extensionTypes ) ) {
427 $wgExtensionCredits['other'] = array_merge( $wgExtensionCredits['other'], $extensions );
431 // Loop through the extension categories to display their extensions in the list.
432 foreach ( $extensionTypes as $type => $message ) {
433 if ( $type != 'other' ) {
434 $out .= $this->getExtensionCategory( $type, $message );
438 // We want the 'other' type to be last in the list.
439 $out .= $this->getExtensionCategory( 'other', $extensionTypes['other'] );
441 $tags = $wgParser->getTags();
442 $cnt = count( $tags );
445 for ( $i = 0; $i < $cnt; ++
$i ) {
446 $tags[$i] = "<{$tags[$i]}>";
448 $out .= $this->openExtType( $this->msg( 'version-parser-extensiontags' )->text(), 'parser-tags' );
449 $out .= '<tr><td colspan="4">' . $this->listToText( $tags ) . "</td></tr>\n";
452 $fhooks = $wgParser->getFunctionHooks();
453 if ( count( $fhooks ) ) {
454 $out .= $this->openExtType( $this->msg( 'version-parser-function-hooks' )->text(), 'parser-function-hooks' );
455 $out .= '<tr><td colspan="4">' . $this->listToText( $fhooks ) . "</td></tr>\n";
458 $out .= Xml
::closeElement( 'table' );
464 * Creates and returns the HTML for a single extension category.
468 * @param $type String
469 * @param $message String
473 protected function getExtensionCategory( $type, $message ) {
474 global $wgExtensionCredits;
478 if ( array_key_exists( $type, $wgExtensionCredits ) && count( $wgExtensionCredits[$type] ) > 0 ) {
479 $out .= $this->openExtType( $message, 'credits-' . $type );
481 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
483 foreach ( $wgExtensionCredits[$type] as $extension ) {
484 $out .= $this->getCreditsForExtension( $extension );
492 * Callback to sort extensions by type.
497 function compare( $a, $b ) {
498 if ( $a['name'] === $b['name'] ) {
501 return $this->getLanguage()->lc( $a['name'] ) > $this->getLanguage()->lc( $b['name'] )
508 * Creates and formats a version line for a single extension.
510 * Information for four columns will be created. Parameters required in the
511 * $extension array for part rendering are indicated in ()
512 * - The name of (name), and URL link to (url), the extension
513 * -- Also if available the short name of the license (license-name) and a linke
514 * to ((LICENSE)|(COPYING))(\.txt)? if it exists.
515 * - Official version number (version) and if available version control system
516 * revision (path), link, and date
517 * - Description of extension (descriptionmsg or description)
518 * - List of authors (author) and link to a ((AUTHORS)|(CREDITS))(\.txt)? file if it exists
520 * @param $extension Array
522 * @return string raw HTML
524 function getCreditsForExtension( array $extension ) {
525 $out = $this->getOutput();
527 // We must obtain the information for all the bits and pieces!
528 // ... such as extension names and links
529 $extensionName = isset( $extension['name'] ) ?
$extension['name'] : '[no name]';
530 if ( isset( $extension['url'] ) ) {
531 $extensionNameLink = Linker
::makeExternalLink(
536 array( 'class' => 'mw-version-ext-name' )
539 $extensionNameLink = $extensionName;
542 // ... and the version information
543 // If the extension path is set we will check that directory for GIT and SVN
544 // metadata in an attempt to extract date and vcs commit metadata.
545 $canonicalVersion = '–';
546 $extensionPath = null;
551 if ( isset( $extension['version'] ) ) {
552 $canonicalVersion = $out->parseInline( $extension['version'] );
555 if ( isset( $extension['path'] ) ) {
556 $extensionPath = dirname( $extension['path'] );
557 $gitInfo = new GitInfo( $extensionPath );
558 $vcsVersion = $gitInfo->getHeadSHA1();
559 if ( $vcsVersion !== false ) {
560 $vcsVersion = substr( $vcsVersion, 0, 7 );
561 $vcsLink = $gitInfo->getHeadViewUrl();
562 $vcsDate = $gitInfo->getHeadCommitDate();
564 $svnInfo = self
::getSvnInfo( $extensionPath );
565 if ( $svnInfo !== false ) {
566 $vcsVersion = $this->msg( 'version-svn-revision', $svnInfo['checkout-rev'] )->text();
567 $vcsLink = isset( $svnInfo['viewvc-url'] ) ?
$svnInfo['viewvc-url'] : '';
572 $versionString = Html
::rawElement( 'span', array( 'class' => 'mw-version-ext-version' ), $canonicalVersion );
575 $vcsVerString = Linker
::makeExternalLink(
577 $this->msg( 'version-version', $vcsVersion ),
580 array( 'class' => 'mw-version-ext-vcs-version' )
583 $vcsVerString = Html
::element( 'span',
584 array( 'class' => 'mw-version-ext-vcs-version'),
588 $versionString .= " {$vcsVerString}";
591 $vcsTimeString = Html
::element( 'br' ) .
592 Html
::element( 'span',
593 array( 'class' => 'mw-version-ext-vcs-timestamp'),
594 $this->getLanguage()->timeanddate( $vcsDate )
596 $versionString .= " {$vcsTimeString}";
600 // ... and license information; if a license file exists we
603 if ( isset( $extension['license-name'] ) ) {
604 $licenseLink = Linker
::link(
605 $this->getTitle( 'License/' . $extensionName ),
606 $out->parseInline( $extension['license-name'] ),
607 array( 'class' => 'mw-version-ext-license' )
609 } elseif ( $this->getExtLicenseFileName( $extensionPath ) ) {
610 $licenseLink = Linker
::link(
611 $this->getTitle( 'License/' . $extensionName ),
612 $this->msg( 'version-ext-license' ),
613 array( 'class' => 'mw-version-ext-license' )
617 // ... and generate the description; which can be a parameterized l10n message
618 // in the form array( <msgname>, <parameter>, <parameter>... ) or just a straight
620 if ( isset( $extension['descriptionmsg'] ) ) {
621 // Localized description of extension
622 $descriptionMsg = $extension['descriptionmsg'];
624 if ( is_array( $descriptionMsg ) ) {
625 $descriptionMsgKey = $descriptionMsg[0]; // Get the message key
626 array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
627 array_map( "htmlspecialchars", $descriptionMsg ); // For sanity
628 $description = $this->msg( $descriptionMsgKey, $descriptionMsg )->text();
630 $description = $this->msg( $descriptionMsg )->text();
632 } elseif ( isset( $extension['description'] ) ) {
633 // Non localized version
634 $description = $out->parseInline( $extension['description'] );
638 $description = $out->parseInline( $description );
640 // ... now get the authors for this extension
641 $authors = isset( $extension['author'] ) ?
$extension['author'] : array();
642 $authors = $this->listAuthors( $authors, $extensionName, $extensionPath );
644 // Finally! Create the table
645 $html = Html
::openElement( 'tr', array(
646 'class' => 'mw-version-ext',
647 'id' => "mw-version-ext-{$extensionName}"
651 $html .= Html
::rawElement( 'td', array(), '<b>' . $extensionNameLink . '</b><br />' . $versionString );
652 $html .= Html
::rawElement( 'td', array(), $licenseLink );
653 $html .= Html
::rawElement( 'td', array( 'class' => 'mw-version-ext-description' ), $description );
654 $html .= Html
::rawElement( 'td', array( 'class' => 'mw-version-ext-authors' ), $authors );
656 $html .= Html
::closeElement( 'td' );
662 * Generate wikitext showing hooks in $wgHooks.
664 * @return String: wikitext
666 private function getWgHooks() {
669 if ( count( $wgHooks ) ) {
670 $myWgHooks = $wgHooks;
673 $ret = Xml
::element( 'h2', array( 'id' => 'mw-version-hooks' ), $this->msg( 'version-hooks' )->text() ) .
674 Xml
::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-hooks' ) ) .
676 <th>" . $this->msg( 'version-hook-name' )->text() . "</th>
677 <th>" . $this->msg( 'version-hook-subscribedby' )->text() . "</th>
680 foreach ( $myWgHooks as $hook => $hooks ) {
683 <td>" . $this->listToText( $hooks ) . "</td>
687 $ret .= Xml
::closeElement( 'table' );
694 private function openExtType( $text, $name = null ) {
695 $opt = array( 'colspan' => 4 );
698 if ( $this->firstExtOpened
) {
699 // Insert a spacing line
700 $out .= '<tr class="sv-space">' . Html
::element( 'td', $opt ) . "</tr>\n";
702 $this->firstExtOpened
= true;
705 $opt['id'] = "sv-$name";
708 $out .= "<tr>" . Xml
::element( 'th', $opt, $text ) . "</tr>\n";
714 * Get information about client's IP address.
716 * @return String: HTML fragment
718 private function IPInfo() {
719 $ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) );
720 return "<!-- visited from $ip -->\n<span style='display:none'>visited from $ip</span>";
724 * Return a formatted unsorted list of authors
727 * If an item in the $authors array is '...' it is assumed to indicate an
728 * 'and others' string which will then be linked to an ((AUTHORS)|(CREDITS))(\.txt)?
729 * file if it exists in $dir.
731 * Similarly an entry ending with ' ...]' is assumed to be a link to an
734 * If no '...' string variant is found, but an authors file is found an
735 * 'and others' will be added to the end of the credits.
737 * @param $authors mixed: string or array of strings
738 * @param $extName string: name of the extension for link creation
739 * @param $extDir string: path to the extension root directory
741 * @return String: HTML fragment
743 function listAuthors( $authors, $extName, $extDir ) {
747 foreach ( (array)$authors as $item ) {
748 if ( $item == '...' ) {
751 if ( $this->getExtAuthorsFileName( $extDir ) ) {
752 $text = Linker
::link(
753 $this->getTitle( "Credits/$extName" ),
754 $this->msg( 'version-poweredby-others' )->text()
757 $text = $this->msg( 'version-poweredby-others' )->text();
761 } elseif ( substr( $item, -5 ) == ' ...]' ) {
763 $list[] = $this->getOutput()->parseInline(
764 substr( $item, 0, -4 ) . $this->msg( 'version-poweredby-others' )->text() . "]"
768 $list[] = $this->getOutput()->parseInline( $item );
772 if ( !$hasOthers && $this->getExtAuthorsFileName( $extDir ) ) {
773 $list[] = $text = Linker
::link(
774 $this->getTitle( "Credits/$extName" ),
775 $this->msg( 'version-poweredby-others' )->text()
779 return $this->listToText( $list, false );
783 * Obtains the full path of an extensions authors or credits file if
786 * @param string $extDir: Path to the extensions root directory
790 * @return bool|string False if no such file exists, otherwise returns
793 public static function getExtAuthorsFileName( $extDir ) {
798 foreach ( scandir( $extDir ) as $file ) {
799 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
800 if ( preg_match( '/^((AUTHORS)|(CREDITS))(\.txt)?$/', $file ) &&
801 is_readable( $fullPath ) &&
812 * Obtains the full path of an extensions copying or license file if
815 * @param string $extDir: Path to the extensions root directory
819 * @return bool|string False if no such file exists, otherwise returns
822 public static function getExtLicenseFileName( $extDir ) {
827 foreach ( scandir( $extDir ) as $file ) {
828 $fullPath = $extDir . DIRECTORY_SEPARATOR
. $file;
829 if ( preg_match( '/^((COPYING)|(LICENSE))(\.txt)?$/', $file ) &&
830 is_readable( $fullPath ) &&
841 * Convert an array of items into a list for display.
843 * @param array $list of elements to display
844 * @param $sort Boolean: whether to sort the items in $list
848 function listToText( $list, $sort = true ) {
849 $cnt = count( $list );
852 // Enforce always returning a string
853 return (string)self
::arrayToString( $list[0] );
854 } elseif ( $cnt == 0 ) {
860 return $this->getLanguage()->listToText( array_map( array( __CLASS__
, 'arrayToString' ), $list ) );
865 * Convert an array or object to a string for display.
867 * @param $list Mixed: will convert an array to string if given and return
868 * the paramater unaltered otherwise
872 public static function arrayToString( $list ) {
873 if ( is_array( $list ) && count( $list ) == 1 ) {
876 if ( is_object( $list ) ) {
877 $class = wfMessage( 'parentheses' )->params( get_class( $list ) )->escaped();
879 } elseif ( !is_array( $list ) ) {
882 if ( is_object( $list[0] ) ) {
883 $class = get_class( $list[0] );
887 return wfMessage( 'parentheses' )->params( "$class, {$list[1]}" )->escaped();
892 * Get an associative array of information about a given path, from its .svn
893 * subdirectory. Returns false on error, such as if the directory was not
894 * checked out with subversion.
898 * checkout-rev The revision which was checked out
900 * directory-rev The revision when the directory was last modified
901 * url The subversion URL of the directory
902 * repo-url The base URL of the repository
903 * viewvc-url A ViewVC URL pointing to the checked-out revision
907 public static function getSvnInfo( $dir ) {
908 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
909 $entries = $dir . '/.svn/entries';
911 if ( !file_exists( $entries ) ) {
915 $lines = file( $entries );
916 if ( !count( $lines ) ) {
920 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
921 if ( preg_match( '/^<\?xml/', $lines[0] ) ) {
922 // subversion is release <= 1.3
923 if ( !function_exists( 'simplexml_load_file' ) ) {
924 // We could fall back to expat... YUCK
928 // SimpleXml whines about the xmlns...
929 wfSuppressWarnings();
930 $xml = simplexml_load_file( $entries );
934 foreach ( $xml->entry
as $entry ) {
935 if ( $xml->entry
[0]['name'] == '' ) {
936 // The directory entry should always have a revision marker.
937 if ( $entry['revision'] ) {
938 return array( 'checkout-rev' => intval( $entry['revision'] ) );
947 // Subversion is release 1.4 or above.
948 if ( count( $lines ) < 11 ) {
953 'checkout-rev' => intval( trim( $lines[3] ) ),
954 'url' => trim( $lines[4] ),
955 'repo-url' => trim( $lines[5] ),
956 'directory-rev' => intval( trim( $lines[10] ) )
959 if ( isset( self
::$viewvcUrls[$info['repo-url']] ) ) {
960 $viewvc = str_replace(
962 self
::$viewvcUrls[$info['repo-url']],
966 $viewvc .= '/?pathrev=';
967 $viewvc .= urlencode( $info['checkout-rev'] );
968 $info['viewvc-url'] = $viewvc;
975 * Retrieve the revision number of a Subversion working directory.
977 * @param string $dir directory of the svn checkout
979 * @return Integer: revision number as int
981 public static function getSvnRevision( $dir ) {
982 $info = self
::getSvnInfo( $dir );
984 if ( $info === false ) {
986 } elseif ( isset( $info['checkout-rev'] ) ) {
987 return $info['checkout-rev'];
994 * @param string $dir directory of the git checkout
995 * @return bool|String sha1 of commit HEAD points to
997 public static function getGitHeadSha1( $dir ) {
998 $repo = new GitInfo( $dir );
999 return $repo->getHeadSHA1();
1003 * Get the list of entry points and their URLs
1004 * @return string Wikitext
1006 public function getEntryPointInfo() {
1007 global $wgArticlePath, $wgScriptPath;
1008 $scriptPath = $wgScriptPath ?
$wgScriptPath : "/";
1009 $entryPoints = array(
1010 'version-entrypoints-articlepath' => $wgArticlePath,
1011 'version-entrypoints-scriptpath' => $scriptPath,
1012 'version-entrypoints-index-php' => wfScript( 'index' ),
1013 'version-entrypoints-api-php' => wfScript( 'api' ),
1014 'version-entrypoints-load-php' => wfScript( 'load' ),
1017 $language = $this->getLanguage();
1018 $thAttribures = array(
1019 'dir' => $language->getDir(),
1020 'lang' => $language->getCode()
1022 $out = Html
::element( 'h2', array( 'id' => 'mw-version-entrypoints' ), $this->msg( 'version-entrypoints' )->text() ) .
1023 Html
::openElement( 'table',
1025 'class' => 'wikitable plainlinks',
1026 'id' => 'mw-version-entrypoints-table',
1031 Html
::openElement( 'tr' ) .
1032 Html
::element( 'th', $thAttribures, $this->msg( 'version-entrypoints-header-entrypoint' )->text() ) .
1033 Html
::element( 'th', $thAttribures, $this->msg( 'version-entrypoints-header-url' )->text() ) .
1034 Html
::closeElement( 'tr' );
1036 foreach ( $entryPoints as $message => $value ) {
1037 $url = wfExpandUrl( $value, PROTO_RELATIVE
);
1038 $out .= Html
::openElement( 'tr' ) .
1039 // ->text() looks like it should be ->parse(), but this function
1040 // returns wikitext, not HTML, boo
1041 Html
::rawElement( 'td', array(), $this->msg( $message )->text() ) .
1042 Html
::rawElement( 'td', array(), Html
::rawElement( 'code', array(), "[$url $value]" ) ) .
1043 Html
::closeElement( 'tr' );
1046 $out .= Html
::closeElement( 'table' );
1050 protected function getGroupName() {