MediaWiki REL1_34
updateLexerList.php
Go to the documentation of this file.
1<?php
27
28$IP = getenv( 'MW_INSTALL_PATH' ) ?: __DIR__ . '/../../..';
29
30require_once "$IP/maintenance/Maintenance.php";
31
33 public function __construct() {
34 parent::__construct();
35
36 $this->requireExtension( 'SyntaxHighlight' );
37 $this->addDescription( 'Update list of lexers supported by SyntaxHighlight_GeSHi' );
38 }
39
40 public function execute() {
41 $header = 'Generated by ' . basename( __FILE__ );
42
43 $lexers = [];
44
45 $result = Shell::command(
47 '-L', 'lexer'
48 )
49 ->restrict( Shell::RESTRICT_DEFAULT | Shell::NO_NETWORK )
50 ->execute();
51
52 if ( $result->getExitCode() != 0 ) {
53 throw new \RuntimeException( $result->getStderr() );
54 }
55
56 $output = $result->getStdout();
57 foreach ( explode( "\n", $output ) as $line ) {
58 if ( substr( $line, 0, 1 ) === '*' ) {
59 $newLexers = explode( ', ', trim( $line, "* :\n" ) );
60 $lexers = array_merge( $lexers, $newLexers );
61 }
62 }
63 $lexers = array_unique( $lexers );
64 sort( $lexers );
65 $data = [];
66 foreach ( $lexers as $lexer ) {
67 $data[$lexer] = true;
68 }
69
70 $writer = new StaticArrayWriter();
71 $code = $writer->create( $data, $header );
72
73 file_put_contents( __DIR__ . '/../SyntaxHighlight.lexers.php', $code );
74 $this->output( "Updated language list written to SyntaxHighlight.lexers.php\n" );
75 }
76}
77
78$maintClass = UpdateLexerList::class;
79require_once RUN_MAINTENANCE_IF_MAIN;
const RUN_MAINTENANCE_IF_MAIN
$line
Definition cdb.php:59
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
requireExtension( $name)
Indicate that the specified extension must be loaded before the script can run.
output( $out, $channel=null)
Throw some output to the user.
addDescription( $text)
Set the description text.
Executes shell commands.
Definition Shell.php:44
execute()
Do the actual work.
__construct()
Default constructor.
Format a static PHP array to be written to a file.
$header
$maintClass