Move translators credits list to a wiki page
[lhc/web/wiklou.git] / includes / specials / SpecialVersion.php
1 <?php
2 /**
3 * Implements Special:Version
4 *
5 * Copyright © 2005 Ævar Arnfjörð Bjarmason
6 *
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.
11 *
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.
16 *
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
21 *
22 * @file
23 * @ingroup SpecialPage
24 */
25
26 /**
27 * Give information about the version of MediaWiki, PHP, the DB and extensions
28 *
29 * @ingroup SpecialPage
30 */
31 class SpecialVersion extends SpecialPage {
32
33 protected $firstExtOpened = false;
34
35 protected static $extensionTypes = false;
36
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',
41 );
42
43 public function __construct() {
44 parent::__construct( 'Version' );
45 }
46
47 /**
48 * main()
49 */
50 public function execute( $par ) {
51 global $wgSpecialVersionShowHooks, $IP;
52
53 $this->setHeaders();
54 $this->outputHeader();
55 $out = $this->getOutput();
56 $out->allowClickjacking();
57
58 if ( $par !== 'Credits' ) {
59 $text =
60 $this->getMediaWikiCredits() .
61 $this->softwareInformation() .
62 $this->getEntryPointInfo() .
63 $this->getExtensionCredits();
64 if ( $wgSpecialVersionShowHooks ) {
65 $text .= $this->getWgHooks();
66 }
67
68 $out->addWikiText( $text );
69 $out->addHTML( $this->IPInfo() );
70
71 if ( $this->getRequest()->getVal( 'easteregg' ) ) {
72 // TODO: put something interesting here
73 }
74 } else {
75 // Credits sub page
76
77 // Header
78 $out->addHTML( wfMessage( 'version-credits-summary' )->parseAsBlock() );
79
80 $wikiText = file_get_contents( $IP . '/CREDITS' );
81
82 // Take everything from the first section onwards, to remove the (not localized) header
83 $wikiText = substr( $wikiText, strpos( $wikiText, '==' ) );
84
85 $out->addWikiText( $wikiText );
86 }
87 }
88
89 /**
90 * Returns wiki text showing the license information.
91 *
92 * @return string
93 */
94 private static function getMediaWikiCredits() {
95 $ret = Xml::element( 'h2', array( 'id' => 'mw-version-license' ), wfMessage( 'version-license' )->text() );
96
97 // This text is always left-to-right.
98 $ret .= '<div class="plainlinks">';
99 $ret .= "__NOTOC__
100 " . self::getCopyrightAndAuthorList() . "\n
101 " . wfMessage( 'version-license-info' )->text();
102 $ret .= '</div>';
103
104 return str_replace( "\t\t", '', $ret ) . "\n";
105 }
106
107 /**
108 * Get the "MediaWiki is copyright 2001-20xx by lots of cool guys" text
109 *
110 * @return String
111 */
112 public static function getCopyrightAndAuthorList() {
113 global $wgLang;
114
115 if ( defined( 'MEDIAWIKI_INSTALL' ) ) {
116 $othersLink = '[//www.mediawiki.org/wiki/Special:Version/Credits ' . wfMessage( 'version-poweredby-others' )->text() . ']';
117 } else {
118 $othersLink = '[[Special:Version/Credits|' . wfMessage( 'version-poweredby-others' )->text() . ']]';
119 }
120
121 $translatorsLink = '[//translatewiki.net/wiki/Translating:MediaWiki/Credits ' . wfMessage( 'version-poweredby-translators' )->text() . ']';
122
123 $authorList = array(
124 'Magnus Manske', 'Brion Vibber', 'Lee Daniel Crocker',
125 'Tim Starling', 'Erik Möller', 'Gabriel Wicke', 'Ævar Arnfjörð Bjarmason',
126 'Niklas Laxström', 'Domas Mituzas', 'Rob Church', 'Yuri Astrakhan',
127 'Aryeh Gregor', 'Aaron Schulz', 'Andrew Garrett', 'Raimond Spekking',
128 'Alexandre Emsenhuber', 'Siebrand Mazeland', 'Chad Horohoe',
129 'Roan Kattouw', 'Trevor Parscal', 'Bryan Tong Minh', 'Sam Reed',
130 'Victor Vasiliev', 'Rotem Liss', 'Platonides', 'Antoine Musso',
131 'Timo Tijhof', 'Daniel Kinzler', 'Jeroen De Dauw', $othersLink,
132 $translatorsLink
133 );
134
135 return wfMessage( 'version-poweredby-credits', MWTimestamp::getLocalInstance()->format( 'Y' ),
136 $wgLang->listToText( $authorList ) )->text();
137 }
138
139 /**
140 * Returns wiki text showing the third party software versions (apache, php, mysql).
141 *
142 * @return string
143 */
144 static function softwareInformation() {
145 $dbr = wfGetDB( DB_SLAVE );
146
147 // Put the software in an array of form 'name' => 'version'. All messages should
148 // be loaded here, so feel free to use wfMessage in the 'name'. Raw HTML or
149 // wikimarkup can be used.
150 $software = array();
151 $software['[https://www.mediawiki.org/ MediaWiki]'] = self::getVersionLinked();
152 $software['[http://www.php.net/ PHP]'] = phpversion() . " (" . PHP_SAPI . ")";
153 $software[$dbr->getSoftwareLink()] = $dbr->getServerInfo();
154
155 // Allow a hook to add/remove items.
156 wfRunHooks( 'SoftwareInfo', array( &$software ) );
157
158 $out = Xml::element( 'h2', array( 'id' => 'mw-version-software' ), wfMessage( 'version-software' )->text() ) .
159 Xml::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-software' ) ) .
160 "<tr>
161 <th>" . wfMessage( 'version-software-product' )->text() . "</th>
162 <th>" . wfMessage( 'version-software-version' )->text() . "</th>
163 </tr>\n";
164
165 foreach ( $software as $name => $version ) {
166 $out .= "<tr>
167 <td>" . $name . "</td>
168 <td dir=\"ltr\">" . $version . "</td>
169 </tr>\n";
170 }
171
172 return $out . Xml::closeElement( 'table' );
173 }
174
175 /**
176 * Return a string of the MediaWiki version with SVN revision if available.
177 *
178 * @param $flags String
179 * @return mixed
180 */
181 public static function getVersion( $flags = '' ) {
182 global $wgVersion, $IP;
183 wfProfileIn( __METHOD__ );
184
185 $gitInfo = self::getGitHeadSha1( $IP );
186 $svnInfo = self::getSvnInfo( $IP );
187 if ( !$svnInfo && !$gitInfo ) {
188 $version = $wgVersion;
189 } elseif ( $gitInfo && $flags === 'nodb' ) {
190 $shortSha1 = substr( $gitInfo, 0, 7 );
191 $version = "$wgVersion ($shortSha1)";
192 } elseif ( $gitInfo ) {
193 $shortSha1 = substr( $gitInfo, 0, 7 );
194 $shortSha1 = wfMessage( 'parentheses' )->params( $shortSha1 )->escaped();
195 $version = "$wgVersion $shortSha1";
196 } elseif ( $flags === 'nodb' ) {
197 $version = "$wgVersion (r{$svnInfo['checkout-rev']})";
198 } else {
199 $version = $wgVersion . ' ' .
200 wfMessage(
201 'version-svn-revision',
202 isset( $info['directory-rev'] ) ? $info['directory-rev'] : '',
203 $info['checkout-rev']
204 )->text();
205 }
206
207 wfProfileOut( __METHOD__ );
208 return $version;
209 }
210
211 /**
212 * Return a wikitext-formatted string of the MediaWiki version with a link to
213 * the SVN revision or the git SHA1 of head if available.
214 * Git is prefered over Svn
215 * The fallback is just $wgVersion
216 *
217 * @return mixed
218 */
219 public static function getVersionLinked() {
220 global $wgVersion;
221 wfProfileIn( __METHOD__ );
222
223 $gitVersion = self::getVersionLinkedGit();
224 if ( $gitVersion ) {
225 $v = $gitVersion;
226 } else {
227 $svnVersion = self::getVersionLinkedSvn();
228 if ( $svnVersion ) {
229 $v = $svnVersion;
230 } else {
231 $v = $wgVersion; // fallback
232 }
233 }
234
235 wfProfileOut( __METHOD__ );
236 return $v;
237 }
238
239 /**
240 * @return string wgVersion + a link to subversion revision of svn BASE
241 */
242 private static function getVersionLinkedSvn() {
243 global $IP;
244
245 $info = self::getSvnInfo( $IP );
246 if ( !isset( $info['checkout-rev'] ) ) {
247 return false;
248 }
249
250 $linkText = wfMessage(
251 'version-svn-revision',
252 isset( $info['directory-rev'] ) ? $info['directory-rev'] : '',
253 $info['checkout-rev']
254 )->text();
255
256 if ( isset( $info['viewvc-url'] ) ) {
257 $version = "[{$info['viewvc-url']} $linkText]";
258 } else {
259 $version = $linkText;
260 }
261
262 return self::getwgVersionLinked() . " $version";
263 }
264
265 /**
266 * @return string
267 */
268 private static function getwgVersionLinked() {
269 global $wgVersion;
270 $versionUrl = "";
271 if ( wfRunHooks( 'SpecialVersionVersionUrl', array( $wgVersion, &$versionUrl ) ) ) {
272 $versionParts = array();
273 preg_match( "/^(\d+\.\d+)/", $wgVersion, $versionParts );
274 $versionUrl = "https://www.mediawiki.org/wiki/MediaWiki_{$versionParts[1]}";
275 }
276 return "[$versionUrl $wgVersion]";
277 }
278
279 /**
280 * @since 1.22 Returns the HEAD date in addition to the sha1 and link
281 * @return bool|string wgVersion + HEAD sha1 stripped to the first 7 chars with link and date, or false on failure
282 */
283 private static function getVersionLinkedGit() {
284 global $IP, $wgLang;
285
286 $gitInfo = new GitInfo( $IP );
287 $headSHA1 = $gitInfo->getHeadSHA1();
288 if ( !$headSHA1 ) {
289 return false;
290 }
291
292 $shortSHA1 = '(' . substr( $headSHA1, 0, 7 ) . ')';
293
294 $gitHeadUrl = $gitInfo->getHeadViewUrl();
295 if ( $gitHeadUrl !== false ) {
296 $shortSHA1 = "[$gitHeadUrl $shortSHA1]";
297 }
298
299 $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
300 if ( $gitHeadCommitDate ) {
301 $shortSHA1 .= "<br/>" . $wgLang->timeanddate( $gitHeadCommitDate, true );
302 }
303
304 return self::getwgVersionLinked() . " $shortSHA1";
305 }
306
307 /**
308 * Returns an array with the base extension types.
309 * Type is stored as array key, the message as array value.
310 *
311 * TODO: ideally this would return all extension types, including
312 * those added by SpecialVersionExtensionTypes. This is not possible
313 * since this hook is passing along $this though.
314 *
315 * @since 1.17
316 *
317 * @return array
318 */
319 public static function getExtensionTypes() {
320 if ( self::$extensionTypes === false ) {
321 self::$extensionTypes = array(
322 'specialpage' => wfMessage( 'version-specialpages' )->text(),
323 'parserhook' => wfMessage( 'version-parserhooks' )->text(),
324 'variable' => wfMessage( 'version-variables' )->text(),
325 'media' => wfMessage( 'version-mediahandlers' )->text(),
326 'antispam' => wfMessage( 'version-antispam' )->text(),
327 'skin' => wfMessage( 'version-skins' )->text(),
328 'api' => wfMessage( 'version-api' )->text(),
329 'other' => wfMessage( 'version-other' )->text(),
330 );
331
332 wfRunHooks( 'ExtensionTypes', array( &self::$extensionTypes ) );
333 }
334
335 return self::$extensionTypes;
336 }
337
338 /**
339 * Returns the internationalized name for an extension type.
340 *
341 * @since 1.17
342 *
343 * @param $type String
344 *
345 * @return string
346 */
347 public static function getExtensionTypeName( $type ) {
348 $types = self::getExtensionTypes();
349 return isset( $types[$type] ) ? $types[$type] : $types['other'];
350 }
351
352 /**
353 * Generate wikitext showing extensions name, URL, author and description.
354 *
355 * @return String: Wikitext
356 */
357 function getExtensionCredits() {
358 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser;
359
360 if ( !count( $wgExtensionCredits ) && !count( $wgExtensionFunctions ) ) {
361 return '';
362 }
363
364 $extensionTypes = self::getExtensionTypes();
365
366 /**
367 * @deprecated as of 1.17, use hook ExtensionTypes instead.
368 */
369 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
370
371 $out = Xml::element( 'h2', array( 'id' => 'mw-version-ext' ), $this->msg( 'version-extensions' )->text() ) .
372 Xml::openElement( 'table', array( 'class' => 'wikitable plainlinks', 'id' => 'sv-ext' ) );
373
374 // Make sure the 'other' type is set to an array.
375 if ( !array_key_exists( 'other', $wgExtensionCredits ) ) {
376 $wgExtensionCredits['other'] = array();
377 }
378
379 // Find all extensions that do not have a valid type and give them the type 'other'.
380 foreach ( $wgExtensionCredits as $type => $extensions ) {
381 if ( !array_key_exists( $type, $extensionTypes ) ) {
382 $wgExtensionCredits['other'] = array_merge( $wgExtensionCredits['other'], $extensions );
383 }
384 }
385
386 // Loop through the extension categories to display their extensions in the list.
387 foreach ( $extensionTypes as $type => $message ) {
388 if ( $type != 'other' ) {
389 $out .= $this->getExtensionCategory( $type, $message );
390 }
391 }
392
393 // We want the 'other' type to be last in the list.
394 $out .= $this->getExtensionCategory( 'other', $extensionTypes['other'] );
395
396 $tags = $wgParser->getTags();
397 $cnt = count( $tags );
398
399 if ( $cnt ) {
400 for ( $i = 0; $i < $cnt; ++$i ) {
401 $tags[$i] = "&lt;{$tags[$i]}&gt;";
402 }
403 $out .= $this->openExtType( $this->msg( 'version-parser-extensiontags' )->text(), 'parser-tags' );
404 $out .= '<tr><td colspan="4">' . $this->listToText( $tags ) . "</td></tr>\n";
405 }
406
407 $fhooks = $wgParser->getFunctionHooks();
408 if ( count( $fhooks ) ) {
409 $out .= $this->openExtType( $this->msg( 'version-parser-function-hooks' )->text(), 'parser-function-hooks' );
410 $out .= '<tr><td colspan="4">' . $this->listToText( $fhooks ) . "</td></tr>\n";
411 }
412
413 $out .= Xml::closeElement( 'table' );
414
415 return $out;
416 }
417
418 /**
419 * Creates and returns the HTML for a single extension category.
420 *
421 * @since 1.17
422 *
423 * @param $type String
424 * @param $message String
425 *
426 * @return string
427 */
428 protected function getExtensionCategory( $type, $message ) {
429 global $wgExtensionCredits;
430
431 $out = '';
432
433 if ( array_key_exists( $type, $wgExtensionCredits ) && count( $wgExtensionCredits[$type] ) > 0 ) {
434 $out .= $this->openExtType( $message, 'credits-' . $type );
435
436 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
437
438 foreach ( $wgExtensionCredits[$type] as $extension ) {
439 $out .= $this->getCreditsForExtension( $extension );
440 }
441 }
442
443 return $out;
444 }
445
446 /**
447 * Callback to sort extensions by type.
448 * @param $a array
449 * @param $b array
450 * @return int
451 */
452 function compare( $a, $b ) {
453 if ( $a['name'] === $b['name'] ) {
454 return 0;
455 } else {
456 return $this->getLanguage()->lc( $a['name'] ) > $this->getLanguage()->lc( $b['name'] )
457 ? 1
458 : -1;
459 }
460 }
461
462 /**
463 * Creates and formats the credits for a single extension and returns this.
464 *
465 * @param $extension Array
466 *
467 * @return string
468 */
469 function getCreditsForExtension( array $extension ) {
470 global $wgLang;
471
472 $name = isset( $extension['name'] ) ? $extension['name'] : '[no name]';
473
474 $vcsText = false;
475
476 if ( isset( $extension['path'] ) ) {
477 $gitInfo = new GitInfo( dirname( $extension['path'] ) );
478 $gitHeadSHA1 = $gitInfo->getHeadSHA1();
479 if ( $gitHeadSHA1 !== false ) {
480 $vcsText = '(' . substr( $gitHeadSHA1, 0, 7 ) . ')';
481 $gitViewerUrl = $gitInfo->getHeadViewUrl();
482 if ( $gitViewerUrl !== false ) {
483 $vcsText = "[$gitViewerUrl $vcsText]";
484 }
485 $gitHeadCommitDate = $gitInfo->getHeadCommitDate();
486 if ( $gitHeadCommitDate ) {
487 $vcsText .= "<br/>" . $wgLang->timeanddate( $gitHeadCommitDate, true );
488 }
489 } else {
490 $svnInfo = self::getSvnInfo( dirname( $extension['path'] ) );
491 # Make subversion text/link.
492 if ( $svnInfo !== false ) {
493 $directoryRev = isset( $svnInfo['directory-rev'] ) ? $svnInfo['directory-rev'] : null;
494 $vcsText = $this->msg( 'version-svn-revision', $directoryRev, $svnInfo['checkout-rev'] )->text();
495 $vcsText = isset( $svnInfo['viewvc-url'] ) ? '[' . $svnInfo['viewvc-url'] . " $vcsText]" : $vcsText;
496 }
497 }
498 }
499
500 # Make main link (or just the name if there is no URL).
501 if ( isset( $extension['url'] ) ) {
502 $mainLink = "[{$extension['url']} $name]";
503 } else {
504 $mainLink = $name;
505 }
506
507 if ( isset( $extension['version'] ) ) {
508 $versionText = '<span class="mw-version-ext-version">' .
509 $this->msg( 'version-version', $extension['version'] )->text() .
510 '</span>';
511 } else {
512 $versionText = '';
513 }
514
515 # Make description text.
516 $description = isset( $extension['description'] ) ? $extension['description'] : '';
517
518 if ( isset( $extension['descriptionmsg'] ) ) {
519 # Look for a localized description.
520 $descriptionMsg = $extension['descriptionmsg'];
521
522 if ( is_array( $descriptionMsg ) ) {
523 $descriptionMsgKey = $descriptionMsg[0]; // Get the message key
524 array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
525 array_map( "htmlspecialchars", $descriptionMsg ); // For sanity
526 $description = $this->msg( $descriptionMsgKey, $descriptionMsg )->text();
527 } else {
528 $description = $this->msg( $descriptionMsg )->text();
529 }
530 }
531
532 if ( $vcsText !== false ) {
533 $extNameVer = "<tr>
534 <td><em>$mainLink $versionText</em></td>
535 <td><em>$vcsText</em></td>";
536 } else {
537 $extNameVer = "<tr>
538 <td colspan=\"2\"><em>$mainLink $versionText</em></td>";
539 }
540
541 $author = isset( $extension['author'] ) ? $extension['author'] : array();
542 $extDescAuthor = "<td>$description</td>
543 <td>" . $this->listAuthors( $author, false ) . "</td>
544 </tr>\n";
545
546 return $extNameVer . $extDescAuthor;
547 }
548
549 /**
550 * Generate wikitext showing hooks in $wgHooks.
551 *
552 * @return String: wikitext
553 */
554 private function getWgHooks() {
555 global $wgHooks;
556
557 if ( count( $wgHooks ) ) {
558 $myWgHooks = $wgHooks;
559 ksort( $myWgHooks );
560
561 $ret = Xml::element( 'h2', array( 'id' => 'mw-version-hooks' ), $this->msg( 'version-hooks' )->text() ) .
562 Xml::openElement( 'table', array( 'class' => 'wikitable', 'id' => 'sv-hooks' ) ) .
563 "<tr>
564 <th>" . $this->msg( 'version-hook-name' )->text() . "</th>
565 <th>" . $this->msg( 'version-hook-subscribedby' )->text() . "</th>
566 </tr>\n";
567
568 foreach ( $myWgHooks as $hook => $hooks ) {
569 $ret .= "<tr>
570 <td>$hook</td>
571 <td>" . $this->listToText( $hooks ) . "</td>
572 </tr>\n";
573 }
574
575 $ret .= Xml::closeElement( 'table' );
576 return $ret;
577 } else {
578 return '';
579 }
580 }
581
582 private function openExtType( $text, $name = null ) {
583 $opt = array( 'colspan' => 4 );
584 $out = '';
585
586 if ( $this->firstExtOpened ) {
587 // Insert a spacing line
588 $out .= '<tr class="sv-space">' . Html::element( 'td', $opt ) . "</tr>\n";
589 }
590 $this->firstExtOpened = true;
591
592 if ( $name ) {
593 $opt['id'] = "sv-$name";
594 }
595
596 $out .= "<tr>" . Xml::element( 'th', $opt, $text ) . "</tr>\n";
597
598 return $out;
599 }
600
601 /**
602 * Get information about client's IP address.
603 *
604 * @return String: HTML fragment
605 */
606 private function IPInfo() {
607 $ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) );
608 return "<!-- visited from $ip -->\n<span style='display:none'>visited from $ip</span>";
609 }
610
611 /**
612 * Return a formatted unsorted list of authors
613 *
614 * @param $authors mixed: string or array of strings
615 * @return String: HTML fragment
616 */
617 function listAuthors( $authors ) {
618 $list = array();
619 foreach ( (array)$authors as $item ) {
620 if ( $item == '...' ) {
621 $list[] = $this->msg( 'version-poweredby-others' )->text();
622 } elseif ( substr( $item, -5 ) == ' ...]' ) {
623 $list[] = substr( $item, 0, -4 ) . $this->msg( 'version-poweredby-others' )->text() . "]";
624 } else {
625 $list[] = $item;
626 }
627 }
628 return $this->listToText( $list, false );
629 }
630
631 /**
632 * Convert an array of items into a list for display.
633 *
634 * @param array $list of elements to display
635 * @param $sort Boolean: whether to sort the items in $list
636 *
637 * @return String
638 */
639 function listToText( $list, $sort = true ) {
640 $cnt = count( $list );
641
642 if ( $cnt == 1 ) {
643 // Enforce always returning a string
644 return (string)self::arrayToString( $list[0] );
645 } elseif ( $cnt == 0 ) {
646 return '';
647 } else {
648 if ( $sort ) {
649 sort( $list );
650 }
651 return $this->getLanguage()->listToText( array_map( array( __CLASS__, 'arrayToString' ), $list ) );
652 }
653 }
654
655 /**
656 * Convert an array or object to a string for display.
657 *
658 * @param $list Mixed: will convert an array to string if given and return
659 * the paramater unaltered otherwise
660 *
661 * @return Mixed
662 */
663 public static function arrayToString( $list ) {
664 if ( is_array( $list ) && count( $list ) == 1 ) {
665 $list = $list[0];
666 }
667 if ( is_object( $list ) ) {
668 $class = wfMessage( 'parentheses' )->params( get_class( $list ) )->escaped();
669 return $class;
670 } elseif ( !is_array( $list ) ) {
671 return $list;
672 } else {
673 if ( is_object( $list[0] ) ) {
674 $class = get_class( $list[0] );
675 } else {
676 $class = $list[0];
677 }
678 return wfMessage( 'parentheses' )->params( "$class, {$list[1]}" )->escaped();
679 }
680 }
681
682 /**
683 * Get an associative array of information about a given path, from its .svn
684 * subdirectory. Returns false on error, such as if the directory was not
685 * checked out with subversion.
686 *
687 * Returned keys are:
688 * Required:
689 * checkout-rev The revision which was checked out
690 * Optional:
691 * directory-rev The revision when the directory was last modified
692 * url The subversion URL of the directory
693 * repo-url The base URL of the repository
694 * viewvc-url A ViewVC URL pointing to the checked-out revision
695 * @param $dir string
696 * @return array|bool
697 */
698 public static function getSvnInfo( $dir ) {
699 // http://svnbook.red-bean.com/nightly/en/svn.developer.insidewc.html
700 $entries = $dir . '/.svn/entries';
701
702 if ( !file_exists( $entries ) ) {
703 return false;
704 }
705
706 $lines = file( $entries );
707 if ( !count( $lines ) ) {
708 return false;
709 }
710
711 // check if file is xml (subversion release <= 1.3) or not (subversion release = 1.4)
712 if ( preg_match( '/^<\?xml/', $lines[0] ) ) {
713 // subversion is release <= 1.3
714 if ( !function_exists( 'simplexml_load_file' ) ) {
715 // We could fall back to expat... YUCK
716 return false;
717 }
718
719 // SimpleXml whines about the xmlns...
720 wfSuppressWarnings();
721 $xml = simplexml_load_file( $entries );
722 wfRestoreWarnings();
723
724 if ( $xml ) {
725 foreach ( $xml->entry as $entry ) {
726 if ( $xml->entry[0]['name'] == '' ) {
727 // The directory entry should always have a revision marker.
728 if ( $entry['revision'] ) {
729 return array( 'checkout-rev' => intval( $entry['revision'] ) );
730 }
731 }
732 }
733 }
734
735 return false;
736 }
737
738 // Subversion is release 1.4 or above.
739 if ( count( $lines ) < 11 ) {
740 return false;
741 }
742
743 $info = array(
744 'checkout-rev' => intval( trim( $lines[3] ) ),
745 'url' => trim( $lines[4] ),
746 'repo-url' => trim( $lines[5] ),
747 'directory-rev' => intval( trim( $lines[10] ) )
748 );
749
750 if ( isset( self::$viewvcUrls[$info['repo-url']] ) ) {
751 $viewvc = str_replace(
752 $info['repo-url'],
753 self::$viewvcUrls[$info['repo-url']],
754 $info['url']
755 );
756
757 $viewvc .= '/?pathrev=';
758 $viewvc .= urlencode( $info['checkout-rev'] );
759 $info['viewvc-url'] = $viewvc;
760 }
761
762 return $info;
763 }
764
765 /**
766 * Retrieve the revision number of a Subversion working directory.
767 *
768 * @param string $dir directory of the svn checkout
769 *
770 * @return Integer: revision number as int
771 */
772 public static function getSvnRevision( $dir ) {
773 $info = self::getSvnInfo( $dir );
774
775 if ( $info === false ) {
776 return false;
777 } elseif ( isset( $info['checkout-rev'] ) ) {
778 return $info['checkout-rev'];
779 } else {
780 return false;
781 }
782 }
783
784 /**
785 * @param string $dir directory of the git checkout
786 * @return bool|String sha1 of commit HEAD points to
787 */
788 public static function getGitHeadSha1( $dir ) {
789 $repo = new GitInfo( $dir );
790 return $repo->getHeadSHA1();
791 }
792
793 /**
794 * Get the list of entry points and their URLs
795 * @return string Wikitext
796 */
797 public function getEntryPointInfo() {
798 global $wgArticlePath, $wgScriptPath;
799 $scriptPath = $wgScriptPath ? $wgScriptPath : "/";
800 $entryPoints = array(
801 'version-entrypoints-articlepath' => $wgArticlePath,
802 'version-entrypoints-scriptpath' => $scriptPath,
803 'version-entrypoints-index-php' => wfScript( 'index' ),
804 'version-entrypoints-api-php' => wfScript( 'api' ),
805 'version-entrypoints-load-php' => wfScript( 'load' ),
806 );
807
808 $language = $this->getLanguage();
809 $thAttribures = array(
810 'dir' => $language->getDir(),
811 'lang' => $language->getCode()
812 );
813 $out = Html::element( 'h2', array( 'id' => 'mw-version-entrypoints' ), $this->msg( 'version-entrypoints' )->text() ) .
814 Html::openElement( 'table',
815 array(
816 'class' => 'wikitable plainlinks',
817 'id' => 'mw-version-entrypoints-table',
818 'dir' => 'ltr',
819 'lang' => 'en'
820 )
821 ) .
822 Html::openElement( 'tr' ) .
823 Html::element( 'th', $thAttribures, $this->msg( 'version-entrypoints-header-entrypoint' )->text() ) .
824 Html::element( 'th', $thAttribures, $this->msg( 'version-entrypoints-header-url' )->text() ) .
825 Html::closeElement( 'tr' );
826
827 foreach ( $entryPoints as $message => $value ) {
828 $url = wfExpandUrl( $value, PROTO_RELATIVE );
829 $out .= Html::openElement( 'tr' ) .
830 // ->text() looks like it should be ->parse(), but this function
831 // returns wikitext, not HTML, boo
832 Html::rawElement( 'td', array(), $this->msg( $message )->text() ) .
833 Html::rawElement( 'td', array(), Html::rawElement( 'code', array(), "[$url $value]" ) ) .
834 Html::closeElement( 'tr' );
835 }
836
837 $out .= Html::closeElement( 'table' );
838 return $out;
839 }
840
841 protected function getGroupName() {
842 return 'wiki';
843 }
844
845 }