-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
SpecialVersion.php
1186 lines (1045 loc) · 33.5 KB
/
SpecialVersion.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Implements Special:Version
*
* Copyright © 2005 Ævar Arnfjörð Bjarmason
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @ingroup SpecialPage
*/
/**
* Give information about the version of MediaWiki, PHP, the DB and extensions
*
* @ingroup SpecialPage
*/
class SpecialVersion extends SpecialPage {
protected $firstExtOpened = false;
/**
* Stores the current rev id/SHA hash of MediaWiki core
*/
protected $coreId = '';
protected static $extensionTypes = false;
public function __construct() {
parent::__construct( 'Version' );
}
/**
* main()
* @param string|null $par
*/
public function execute( $par ) {
global $IP, $wgExtensionCredits;
$this->setHeaders();
$this->outputHeader();
$out = $this->getOutput();
$out->allowClickjacking();
// Explode the sub page information into useful bits
$parts = explode( '/', (string)$par );
$extNode = null;
if ( isset( $parts[1] ) ) {
$extName = str_replace( '_', ' ', $parts[1] );
// Find it!
foreach ( $wgExtensionCredits as $group => $extensions ) {
foreach ( $extensions as $ext ) {
if ( isset( $ext['name'] ) && ( $ext['name'] === $extName ) ) {
$extNode = &$ext;
break 2;
}
}
}
if ( !$extNode ) {
$out->setStatusCode( 404 );
}
} else {
$extName = 'MediaWiki';
}
// Now figure out what to do
switch ( strtolower( $parts[0] ) ) {
case 'credits':
$wikiText = '{{int:version-credits-not-found}}';
if ( $extName === 'MediaWiki' ) {
$wikiText = file_get_contents( $IP . '/CREDITS' );
} elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) {
$file = $this->getExtAuthorsFileName( dirname( $extNode['path'] ) );
if ( $file ) {
$wikiText = file_get_contents( $file );
if ( substr( $file, -4 ) === '.txt' ) {
$wikiText = Html::element(
'pre',
[
'lang' => 'en',
'dir' => 'ltr',
],
$wikiText
);
}
}
}
$out->setPageTitle( $this->msg( 'version-credits-title', $extName ) );
$out->addWikiText( $wikiText );
break;
case 'license':
$wikiText = '{{int:version-license-not-found}}';
if ( $extName === 'MediaWiki' ) {
$wikiText = file_get_contents( $IP . '/COPYING' );
} elseif ( ( $extNode !== null ) && isset( $extNode['path'] ) ) {
$file = $this->getExtLicenseFileName( dirname( $extNode['path'] ) );
if ( $file ) {
$wikiText = file_get_contents( $file );
$wikiText = Html::element(
'pre',
[
'lang' => 'en',
'dir' => 'ltr',
],
$wikiText
);
}
}
$out->setPageTitle( $this->msg( 'version-license-title', $extName ) );
$out->addWikiText( $wikiText );
break;
default:
$out->addModuleStyles( 'mediawiki.special.version' );
$out->addWikiText(
$this->getMediaWikiCredits() .
$this->softwareInformation() .
$this->getEntryPointInfo()
);
$out->addHTML(
$this->getSkinCredits() .
$this->getExtensionCredits() .
$this->getExternalLibraries() .
$this->getParserTags() .
$this->getParserFunctionHooks()
);
$out->addWikiText( $this->getWgHooks() );
$out->addHTML( $this->IPInfo() );
break;
}
}
/**
* Returns wiki text showing the license information.
*
* @return string
*/
private static function getMediaWikiCredits() {
$ret = Xml::element(
'h2',
[ 'id' => 'mw-version-license' ],
wfMessage( 'version-license' )->text()
);
// This text is always left-to-right.
$ret .= '<div class="plainlinks">';
$ret .= "__NOTOC__
" . self::getCopyrightAndAuthorList() . "\n
" . wfMessage( 'version-license-info' )->text();
$ret .= '</div>';
return str_replace( "\t\t", '', $ret ) . "\n";
}
/**
* Get the "MediaWiki is copyright 2001-20xx by lots of cool guys" text
*
* @return string
*/
public static function getCopyrightAndAuthorList() {
global $wgLang;
if ( defined( 'MEDIAWIKI_INSTALL' ) ) {
$othersLink = '[https://www.mediawiki.org/wiki/Special:Version/Credits ' .
wfMessage( 'version-poweredby-others' )->text() . ']';
} else {
$othersLink = '[[Special:Version/Credits|' .
wfMessage( 'version-poweredby-others' )->text() . ']]';
}
$translatorsLink = '[//translatewiki.net/wiki/Translating:MediaWiki/Credits ' .
wfMessage( 'version-poweredby-translators' )->text() . ']';
$authorList = [
'Magnus Manske', 'Brion Vibber', 'Lee Daniel Crocker',
'Tim Starling', 'Erik Möller', 'Gabriel Wicke', 'Ævar Arnfjörð Bjarmason',
'Niklas Laxström', 'Domas Mituzas', 'Rob Church', 'Yuri Astrakhan',
'Aryeh Gregor', 'Aaron Schulz', 'Andrew Garrett', 'Raimond Spekking',
'Alexandre Emsenhuber', 'Siebrand Mazeland', 'Chad Horohoe',
'Roan Kattouw', 'Trevor Parscal', 'Bryan Tong Minh', 'Sam Reed',
'Victor Vasiliev', 'Rotem Liss', 'Platonides', 'Antoine Musso',
'Timo Tijhof', 'Daniel Kinzler', 'Jeroen De Dauw', 'Brad Jorsch',
$othersLink, $translatorsLink
];
return wfMessage( 'version-poweredby-credits', MWTimestamp::getLocalInstance()->format( 'Y' ),
$wgLang->listToText( $authorList ) )->text();
}
/**
* Returns wiki text showing the third party software versions (apache, php, mysql).
*
* @return string
*/
public static function softwareInformation() {
$dbr = wfGetDB( DB_SLAVE );
// Put the software in an array of form 'name' => 'version'. All messages should
// be loaded here, so feel free to use wfMessage in the 'name'. Raw HTML or
// wikimarkup can be used.
$software = [];
$software['[https://www.mediawiki.org/ MediaWiki]'] = self::getVersionLinked();
if ( wfIsHHVM() ) {
$software['[http://hhvm.com/ HHVM]'] = HHVM_VERSION . " (" . PHP_SAPI . ")";
} else {
$software['[https://php.net/ PHP]'] = PHP_VERSION . " (" . PHP_SAPI . ")";
}
$software[$dbr->getSoftwareLink()] = $dbr->getServerInfo();
if ( IcuCollation::getICUVersion() ) {
$software['[http://site.icu-project.org/ ICU]'] = IcuCollation::getICUVersion();
}
// Allow a hook to add/remove items.
Hooks::run( 'SoftwareInfo', [ &$software ] );
$out = Xml::element(
'h2',
[ 'id' => 'mw-version-software' ],
wfMessage( 'version-software' )->text()
) .
Xml::openElement( 'table', [ 'class' => 'wikitable plainlinks', 'id' => 'sv-software' ] ) .
"<tr>
<th>" . wfMessage( 'version-software-product' )->text() . "</th>
<th>" . wfMessage( 'version-software-version' )->text() . "</th>
</tr>\n";
foreach ( $software as $name => $version ) {
$out .= "<tr>
<td>" . $name . "</td>
<td dir=\"ltr\">" . $version . "</td>
</tr>\n";
}
return $out . Xml::closeElement( 'table' );
}
/**
* Return a string of the MediaWiki version with Git revision if available.
*
* @param string $flags
* @param Language|string|null $lang
* @return mixed
*/
public static function getVersion( $flags = '', $lang = null ) {
global $wgVersion, $IP;
$gitInfo = self::getGitHeadSha1( $IP );
if ( !$gitInfo ) {
$version = $wgVersion;
} elseif ( $flags === 'nodb' ) {
$shortSha1 = substr( $gitInfo, 0, 7 );
$version = "$wgVersion ($shortSha1)";
} else {
$shortSha1 = substr( $gitInfo, 0, 7 );
$msg = wfMessage( 'parentheses' );
if ( $lang !== null ) {
$msg->inLanguage( $lang );
}
$shortSha1 = $msg->params( $shortSha1 )->escaped();
$version = "$wgVersion $shortSha1";
}
return $version;
}
/**
* Return a wikitext-formatted string of the MediaWiki version with a link to
* the Git SHA1 of head if available.
* The fallback is just $wgVersion
*
* @return mixed
*/
public static function getVersionLinked() {
global $wgVersion;
$gitVersion = self::getVersionLinkedGit();
if ( $gitVersion ) {
$v = $gitVersion;
} else {
$v = $wgVersion; // fallback
}
return $v;
}
/**
* @return string
*/
private static function getwgVersionLinked() {
global $wgVersion;
$versionUrl = "";
if ( Hooks::run( 'SpecialVersionVersionUrl', [ $wgVersion, &$versionUrl ] ) ) {
$versionParts = [];
preg_match( "/^(\d+\.\d+)/", $wgVersion, $versionParts );
$versionUrl = "https://www.mediawiki.org/wiki/MediaWiki_{$versionParts[1]}";
}
return "[$versionUrl $wgVersion]";
}
/**
* @since 1.22 Returns the HEAD date in addition to the sha1 and link
* @return bool|string Global wgVersion + HEAD sha1 stripped to the first 7 chars
* with link and date, or false on failure
*/
private static function getVersionLinkedGit() {
global $IP, $wgLang;
$gitInfo = new GitInfo( $IP );
$headSHA1 = $gitInfo->getHeadSHA1();
if ( !$headSHA1 ) {
return false;
}
$shortSHA1 = '(' . substr( $headSHA1, 0, 7 ) . ')';
$gitHeadUrl = $gitInfo->getHeadViewUrl();
if ( $gitHeadUrl !== false ) {
$shortSHA1 = "[$gitHeadUrl $shortSHA1]";
}
$gitHeadCommitDate = $gitInfo->getHeadCommitDate();
if ( $gitHeadCommitDate ) {
$shortSHA1 .= Html::element( 'br' ) . $wgLang->timeanddate( $gitHeadCommitDate, true );
}
return self::getwgVersionLinked() . " $shortSHA1";
}
/**
* Returns an array with the base extension types.
* Type is stored as array key, the message as array value.
*
* TODO: ideally this would return all extension types.
*
* @since 1.17
*
* @return array
*/
public static function getExtensionTypes() {
if ( self::$extensionTypes === false ) {
self::$extensionTypes = [
'specialpage' => wfMessage( 'version-specialpages' )->text(),
'parserhook' => wfMessage( 'version-parserhooks' )->text(),
'variable' => wfMessage( 'version-variables' )->text(),
'media' => wfMessage( 'version-mediahandlers' )->text(),
'antispam' => wfMessage( 'version-antispam' )->text(),
'skin' => wfMessage( 'version-skins' )->text(),
'api' => wfMessage( 'version-api' )->text(),
'other' => wfMessage( 'version-other' )->text(),
];
Hooks::run( 'ExtensionTypes', [ &self::$extensionTypes ] );
}
return self::$extensionTypes;
}
/**
* Returns the internationalized name for an extension type.
*
* @since 1.17
*
* @param string $type
*
* @return string
*/
public static function getExtensionTypeName( $type ) {
$types = self::getExtensionTypes();
return isset( $types[$type] ) ? $types[$type] : $types['other'];
}
/**
* Generate wikitext showing the name, URL, author and description of each extension.
*
* @return string Wikitext
*/
public function getExtensionCredits() {
global $wgExtensionCredits;
if (
count( $wgExtensionCredits ) === 0 ||
// Skins are displayed separately, see getSkinCredits()
( count( $wgExtensionCredits ) === 1 && isset( $wgExtensionCredits['skin'] ) )
) {
return '';
}
$extensionTypes = self::getExtensionTypes();
$out = Xml::element(
'h2',
[ 'id' => 'mw-version-ext' ],
$this->msg( 'version-extensions' )->text()
) .
Xml::openElement( 'table', [ 'class' => 'wikitable plainlinks', 'id' => 'sv-ext' ] );
// Make sure the 'other' type is set to an array.
if ( !array_key_exists( 'other', $wgExtensionCredits ) ) {
$wgExtensionCredits['other'] = [];
}
// Find all extensions that do not have a valid type and give them the type 'other'.
foreach ( $wgExtensionCredits as $type => $extensions ) {
if ( !array_key_exists( $type, $extensionTypes ) ) {
$wgExtensionCredits['other'] = array_merge( $wgExtensionCredits['other'], $extensions );
}
}
$this->firstExtOpened = false;
// Loop through the extension categories to display their extensions in the list.
foreach ( $extensionTypes as $type => $message ) {
// Skins have a separate section
if ( $type !== 'other' && $type !== 'skin' ) {
$out .= $this->getExtensionCategory( $type, $message );
}
}
// We want the 'other' type to be last in the list.
$out .= $this->getExtensionCategory( 'other', $extensionTypes['other'] );
$out .= Xml::closeElement( 'table' );
return $out;
}
/**
* Generate wikitext showing the name, URL, author and description of each skin.
*
* @return string Wikitext
*/
public function getSkinCredits() {
global $wgExtensionCredits;
if ( !isset( $wgExtensionCredits['skin'] ) || count( $wgExtensionCredits['skin'] ) === 0 ) {
return '';
}
$out = Xml::element(
'h2',
[ 'id' => 'mw-version-skin' ],
$this->msg( 'version-skins' )->text()
) .
Xml::openElement( 'table', [ 'class' => 'wikitable plainlinks', 'id' => 'sv-skin' ] );
$this->firstExtOpened = false;
$out .= $this->getExtensionCategory( 'skin', null );
$out .= Xml::closeElement( 'table' );
return $out;
}
/**
* Generate an HTML table for external libraries that are installed
*
* @return string
*/
protected function getExternalLibraries() {
global $IP;
$path = "$IP/vendor/composer/installed.json";
if ( !file_exists( $path ) ) {
return '';
}
$installed = new ComposerInstalled( $path );
$out = Html::element(
'h2',
[ 'id' => 'mw-version-libraries' ],
$this->msg( 'version-libraries' )->text()
);
$out .= Html::openElement(
'table',
[ 'class' => 'wikitable plainlinks', 'id' => 'sv-libraries' ]
);
$out .= Html::openElement( 'tr' )
. Html::element( 'th', [], $this->msg( 'version-libraries-library' )->text() )
. Html::element( 'th', [], $this->msg( 'version-libraries-version' )->text() )
. Html::element( 'th', [], $this->msg( 'version-libraries-license' )->text() )
. Html::element( 'th', [], $this->msg( 'version-libraries-description' )->text() )
. Html::element( 'th', [], $this->msg( 'version-libraries-authors' )->text() )
. Html::closeElement( 'tr' );
foreach ( $installed->getInstalledDependencies() as $name => $info ) {
if ( strpos( $info['type'], 'mediawiki-' ) === 0 ) {
// Skip any extensions or skins since they'll be listed
// in their proper section
continue;
}
$authors = array_map( function( $arr ) {
// If a homepage is set, link to it
if ( isset( $arr['homepage'] ) ) {
return "[{$arr['homepage']} {$arr['name']}]";
}
return $arr['name'];
}, $info['authors'] );
$authors = $this->listAuthors( $authors, false, "$IP/vendor/$name" );
// We can safely assume that the libraries' names and descriptions
// are written in English and aren't going to be translated,
// so set appropriate lang and dir attributes
$out .= Html::openElement( 'tr' )
. Html::rawElement(
'td',
[],
Linker::makeExternalLink(
"https://packagist.org/packages/$name", $name,
true, '',
[ 'class' => 'mw-version-library-name' ]
)
)
. Html::element( 'td', [ 'dir' => 'auto' ], $info['version'] )
. Html::element( 'td', [ 'dir' => 'auto' ], $this->listToText( $info['licenses'] ) )
. Html::element( 'td', [ 'lang' => 'en', 'dir' => 'ltr' ], $info['description'] )
. Html::rawElement( 'td', [], $authors )
. Html::closeElement( 'tr' );
}
$out .= Html::closeElement( 'table' );
return $out;
}
/**
* Obtains a list of installed parser tags and the associated H2 header
*
* @return string HTML output
*/
protected function getParserTags() {
global $wgParser;
$tags = $wgParser->getTags();
if ( count( $tags ) ) {
$out = Html::rawElement(
'h2',
[
'class' => 'mw-headline plainlinks',
'id' => 'mw-version-parser-extensiontags',
],
Linker::makeExternalLink(
'https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Tag_extensions',
$this->msg( 'version-parser-extensiontags' )->parse(),
false /* msg()->parse() already escapes */
)
);
array_walk( $tags, function ( &$value ) {
// Bidirectional isolation improves readability in RTL wikis
$value = Html::element(
'bdi',
// Prevent < and > from slipping to another line
[
'style' => 'white-space: nowrap;',
],
"<$value>"
);
} );
$out .= $this->listToText( $tags );
} else {
$out = '';
}
return $out;
}
/**
* Obtains a list of installed parser function hooks and the associated H2 header
*
* @return string HTML output
*/
protected function getParserFunctionHooks() {
global $wgParser;
$fhooks = $wgParser->getFunctionHooks();
if ( count( $fhooks ) ) {
$out = Html::rawElement(
'h2',
[
'class' => 'mw-headline plainlinks',
'id' => 'mw-version-parser-function-hooks',
],
Linker::makeExternalLink(
'https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Parser_functions',
$this->msg( 'version-parser-function-hooks' )->parse(),
false /* msg()->parse() already escapes */
)
);
$out .= $this->listToText( $fhooks );
} else {
$out = '';
}
return $out;
}
/**
* Creates and returns the HTML for a single extension category.
*
* @since 1.17
*
* @param string $type
* @param string $message
*
* @return string
*/
protected function getExtensionCategory( $type, $message ) {
global $wgExtensionCredits;
$out = '';
if ( array_key_exists( $type, $wgExtensionCredits ) && count( $wgExtensionCredits[$type] ) > 0 ) {
$out .= $this->openExtType( $message, 'credits-' . $type );
usort( $wgExtensionCredits[$type], [ $this, 'compare' ] );
foreach ( $wgExtensionCredits[$type] as $extension ) {
$out .= $this->getCreditsForExtension( $extension );
}
}
return $out;
}
/**
* Callback to sort extensions by type.
* @param array $a
* @param array $b
* @return int
*/
public function compare( $a, $b ) {
if ( $a['name'] === $b['name'] ) {
return 0;
} else {
return $this->getLanguage()->lc( $a['name'] ) > $this->getLanguage()->lc( $b['name'] )
? 1
: -1;
}
}
/**
* Creates and formats a version line for a single extension.
*
* Information for five columns will be created. Parameters required in the
* $extension array for part rendering are indicated in ()
* - The name of (name), and URL link to (url), the extension
* - Official version number (version) and if available version control system
* revision (path), link, and date
* - If available the short name of the license (license-name) and a link
* to ((LICENSE)|(COPYING))(\.txt)? if it exists.
* - Description of extension (descriptionmsg or description)
* - List of authors (author) and link to a ((AUTHORS)|(CREDITS))(\.txt)? file if it exists
*
* @param array $extension
*
* @return string Raw HTML
*/
public function getCreditsForExtension( array $extension ) {
$out = $this->getOutput();
// We must obtain the information for all the bits and pieces!
// ... such as extension names and links
if ( isset( $extension['namemsg'] ) ) {
// Localized name of extension
$extensionName = $this->msg( $extension['namemsg'] )->text();
} elseif ( isset( $extension['name'] ) ) {
// Non localized version
$extensionName = $extension['name'];
} else {
$extensionName = $this->msg( 'version-no-ext-name' )->text();
}
if ( isset( $extension['url'] ) ) {
$extensionNameLink = Linker::makeExternalLink(
$extension['url'],
$extensionName,
true,
'',
[ 'class' => 'mw-version-ext-name' ]
);
} else {
$extensionNameLink = $extensionName;
}
// ... and the version information
// If the extension path is set we will check that directory for GIT
// metadata in an attempt to extract date and vcs commit metadata.
$canonicalVersion = '–';
$extensionPath = null;
$vcsVersion = null;
$vcsLink = null;
$vcsDate = null;
if ( isset( $extension['version'] ) ) {
$canonicalVersion = $out->parseInline( $extension['version'] );
}
if ( isset( $extension['path'] ) ) {
global $IP;
$extensionPath = dirname( $extension['path'] );
if ( $this->coreId == '' ) {
wfDebug( 'Looking up core head id' );
$coreHeadSHA1 = self::getGitHeadSha1( $IP );
if ( $coreHeadSHA1 ) {
$this->coreId = $coreHeadSHA1;
}
}
$cache = wfGetCache( CACHE_ANYTHING );
$memcKey = wfMemcKey( 'specialversion-ext-version-text', $extension['path'], $this->coreId );
list( $vcsVersion, $vcsLink, $vcsDate ) = $cache->get( $memcKey );
if ( !$vcsVersion ) {
wfDebug( "Getting VCS info for extension {$extension['name']}" );
$gitInfo = new GitInfo( $extensionPath );
$vcsVersion = $gitInfo->getHeadSHA1();
if ( $vcsVersion !== false ) {
$vcsVersion = substr( $vcsVersion, 0, 7 );
$vcsLink = $gitInfo->getHeadViewUrl();
$vcsDate = $gitInfo->getHeadCommitDate();
}
$cache->set( $memcKey, [ $vcsVersion, $vcsLink, $vcsDate ], 60 * 60 * 24 );
} else {
wfDebug( "Pulled VCS info for extension {$extension['name']} from cache" );
}
}
$versionString = Html::rawElement(
'span',
[ 'class' => 'mw-version-ext-version' ],
$canonicalVersion
);
if ( $vcsVersion ) {
if ( $vcsLink ) {
$vcsVerString = Linker::makeExternalLink(
$vcsLink,
$this->msg( 'version-version', $vcsVersion ),
true,
'',
[ 'class' => 'mw-version-ext-vcs-version' ]
);
} else {
$vcsVerString = Html::element( 'span',
[ 'class' => 'mw-version-ext-vcs-version' ],
"({$vcsVersion})"
);
}
$versionString .= " {$vcsVerString}";
if ( $vcsDate ) {
$vcsTimeString = Html::element( 'span',
[ 'class' => 'mw-version-ext-vcs-timestamp' ],
$this->getLanguage()->timeanddate( $vcsDate, true )
);
$versionString .= " {$vcsTimeString}";
}
$versionString = Html::rawElement( 'span',
[ 'class' => 'mw-version-ext-meta-version' ],
$versionString
);
}
// ... and license information; if a license file exists we
// will link to it
$licenseLink = '';
if ( isset( $extension['name'] ) ) {
$licenseName = null;
if ( isset( $extension['license-name'] ) ) {
$licenseName = $out->parseInline( $extension['license-name'] );
} elseif ( $this->getExtLicenseFileName( $extensionPath ) ) {
$licenseName = $this->msg( 'version-ext-license' )->escaped();
}
if ( $licenseName !== null ) {
$licenseLink = Linker::link(
$this->getPageTitle( 'License/' . $extension['name'] ),
$licenseName,
[
'class' => 'mw-version-ext-license',
'dir' => 'auto',
]
);
}
}
// ... and generate the description; which can be a parameterized l10n message
// in the form array( <msgname>, <parameter>, <parameter>... ) or just a straight
// up string
if ( isset( $extension['descriptionmsg'] ) ) {
// Localized description of extension
$descriptionMsg = $extension['descriptionmsg'];
if ( is_array( $descriptionMsg ) ) {
$descriptionMsgKey = $descriptionMsg[0]; // Get the message key
array_shift( $descriptionMsg ); // Shift out the message key to get the parameters only
array_map( "htmlspecialchars", $descriptionMsg ); // For sanity
$description = $this->msg( $descriptionMsgKey, $descriptionMsg )->text();
} else {
$description = $this->msg( $descriptionMsg )->text();
}
} elseif ( isset( $extension['description'] ) ) {
// Non localized version
$description = $extension['description'];
} else {
$description = '';
}
$description = $out->parseInline( $description );
// ... now get the authors for this extension
$authors = isset( $extension['author'] ) ? $extension['author'] : [];
$authors = $this->listAuthors( $authors, $extension['name'], $extensionPath );
// Finally! Create the table
$html = Html::openElement( 'tr', [
'class' => 'mw-version-ext',
'id' => Sanitizer::escapeId( 'mw-version-ext-' . $extension['name'] )
]
);
$html .= Html::rawElement( 'td', [], $extensionNameLink );
$html .= Html::rawElement( 'td', [], $versionString );
$html .= Html::rawElement( 'td', [], $licenseLink );
$html .= Html::rawElement( 'td', [ 'class' => 'mw-version-ext-description' ], $description );
$html .= Html::rawElement( 'td', [ 'class' => 'mw-version-ext-authors' ], $authors );
$html .= Html::closeElement( 'tr' );
return $html;
}
/**
* Generate wikitext showing hooks in $wgHooks.
*
* @return string Wikitext
*/
private function getWgHooks() {
global $wgSpecialVersionShowHooks, $wgHooks;
if ( $wgSpecialVersionShowHooks && count( $wgHooks ) ) {
$myWgHooks = $wgHooks;
ksort( $myWgHooks );
$ret = [];
$ret[] = '== {{int:version-hooks}} ==';
$ret[] = Html::openElement( 'table', [ 'class' => 'wikitable', 'id' => 'sv-hooks' ] );
$ret[] = Html::openElement( 'tr' );
$ret[] = Html::element( 'th', [], $this->msg( 'version-hook-name' )->text() );
$ret[] = Html::element( 'th', [], $this->msg( 'version-hook-subscribedby' )->text() );
$ret[] = Html::closeElement( 'tr' );
foreach ( $myWgHooks as $hook => $hooks ) {
$ret[] = Html::openElement( 'tr' );
$ret[] = Html::element( 'td', [], $hook );
$ret[] = Html::element( 'td', [], $this->listToText( $hooks ) );
$ret[] = Html::closeElement( 'tr' );
}
$ret[] = Html::closeElement( 'table' );
return implode( "\n", $ret );
} else {
return '';
}
}
private function openExtType( $text = null, $name = null ) {
$out = '';
$opt = [ 'colspan' => 5 ];
if ( $this->firstExtOpened ) {
// Insert a spacing line
$out .= Html::rawElement( 'tr', [ 'class' => 'sv-space' ],
Html::element( 'td', $opt )
);
}
$this->firstExtOpened = true;
if ( $name ) {
$opt['id'] = "sv-$name";
}
if ( $text !== null ) {
$out .= Html::rawElement( 'tr', [],
Html::element( 'th', $opt, $text )
);
}
$firstHeadingMsg = ( $name === 'credits-skin' )
? 'version-skin-colheader-name'
: 'version-ext-colheader-name';
$out .= Html::openElement( 'tr' );
$out .= Html::element( 'th', [ 'class' => 'mw-version-ext-col-label' ],
$this->msg( $firstHeadingMsg )->text() );
$out .= Html::element( 'th', [ 'class' => 'mw-version-ext-col-label' ],
$this->msg( 'version-ext-colheader-version' )->text() );
$out .= Html::element( 'th', [ 'class' => 'mw-version-ext-col-label' ],
$this->msg( 'version-ext-colheader-license' )->text() );
$out .= Html::element( 'th', [ 'class' => 'mw-version-ext-col-label' ],
$this->msg( 'version-ext-colheader-description' )->text() );
$out .= Html::element( 'th', [ 'class' => 'mw-version-ext-col-label' ],
$this->msg( 'version-ext-colheader-credits' )->text() );
$out .= Html::closeElement( 'tr' );
return $out;
}
/**
* Get information about client's IP address.
*
* @return string HTML fragment
*/
private function IPInfo() {
$ip = str_replace( '--', ' - ', htmlspecialchars( $this->getRequest()->getIP() ) );
return "<!-- visited from $ip -->\n<span style='display:none'>visited from $ip</span>";
}
/**
* Return a formatted unsorted list of authors
*
* 'And Others'
* If an item in the $authors array is '...' it is assumed to indicate an
* 'and others' string which will then be linked to an ((AUTHORS)|(CREDITS))(\.txt)?
* file if it exists in $dir.
*
* Similarly an entry ending with ' ...]' is assumed to be a link to an
* 'and others' page.
*
* If no '...' string variant is found, but an authors file is found an
* 'and others' will be added to the end of the credits.
*
* @param string|array $authors
* @param string|bool $extName Name of the extension for link creation,
* false if no links should be created
* @param string $extDir Path to the extension root directory
*
* @return string HTML fragment
*/
public function listAuthors( $authors, $extName, $extDir ) {
$hasOthers = false;
$list = [];
foreach ( (array)$authors as $item ) {
if ( $item == '...' ) {
$hasOthers = true;
if ( $extName && $this->getExtAuthorsFileName( $extDir ) ) {
$text = Linker::link(
$this->getPageTitle( "Credits/$extName" ),
$this->msg( 'version-poweredby-others' )->escaped()
);
} else {
$text = $this->msg( 'version-poweredby-others' )->escaped();
}
$list[] = $text;
} elseif ( substr( $item, -5 ) == ' ...]' ) {
$hasOthers = true;
$list[] = $this->getOutput()->parseInline(
substr( $item, 0, -4 ) . $this->msg( 'version-poweredby-others' )->text() . "]"
);
} else {
$list[] = $this->getOutput()->parseInline( $item );
}
}
if ( $extName && !$hasOthers && $this->getExtAuthorsFileName( $extDir ) ) {
$list[] = $text = Linker::link(
$this->getPageTitle( "Credits/$extName" ),
$this->msg( 'version-poweredby-others' )->escaped()
);
}
return $this->listToText( $list, false );
}
/**
* Obtains the full path of an extensions authors or credits file if
* one exists.
*
* @param string $extDir Path to the extensions root directory
*
* @since 1.23
*