MediaWiki REL1_31
updateLexerList.php
Go to the documentation of this file.
1<?php
26
27$IP = getenv( 'MW_INSTALL_PATH' ) ?: __DIR__ . '/../../..';
28
29require_once "$IP/maintenance/Maintenance.php";
30
31class UpdateLexerList extends Maintenance {
32 public function __construct() {
33 parent::__construct();
34
35 $this->requireExtension( 'SyntaxHighlight' );
36 $this->addDescription( 'Update list of lexers supported by SyntaxHighlight_GeSHi' );
37 }
38
39 public function execute() {
40 function lang_filter( $val ) {
41 return preg_match( '/^[a-zA-Z0-9\-_]+$/', $val );
42 }
43
44 $header = '// Generated by ' . basename( __FILE__ ) . "\n\n";
45
46 $lexers = [];
47
48 $result = Shell::command(
50 '-L', 'lexer'
51 )
52 ->restrict( Shell::RESTRICT_DEFAULT | Shell::NO_NETWORK )
53 ->execute();
54
55 if ( $result->getExitCode() != 0 ) {
56 throw new \RuntimeException( $result->getStderr() );
57 }
58
59 $output = $result->getStdout();
60 foreach ( explode( "\n", $output ) as $line ) {
61 if ( substr( $line, 0, 1 ) === '*' ) {
62 $newLexers = explode( ', ', trim( $line, "* :\n" ) );
63 $lexers = array_merge( $lexers, $newLexers );
64 }
65 }
66 $lexers = array_unique( $lexers );
67 sort( $lexers );
68
69 $code = "<?php\n" . $header . 'return ' . var_export( $lexers, true ) . ";\n";
70 $code = preg_replace( '/(\d+ \=>| (?=\‍())/i', '', $code );
71 $code = preg_replace( "/^ +/m", "\t", $code );
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';
79require_once RUN_MAINTENANCE_IF_MAIN;
$line
Definition cdb.php:59
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Executes shell commands.
Definition Shell.php:44
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place $output
Definition hooks.txt:2255
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
Definition hooks.txt:865
$batch execute()
class DemoMaint extends Maintenance $maintClass
require_once RUN_MAINTENANCE_IF_MAIN
$header