MediaWiki REL1_30
updateLexerList.php
Go to the documentation of this file.
1<?php
25use Symfony\Component\Process\ProcessBuilder;
26
27$IP = getenv( 'MW_INSTALL_PATH' ) ?: __DIR__ . '/../../..';
28
29require_once "$IP/maintenance/Maintenance.php";
30
31class UpdateLanguageList extends Maintenance {
32 public function __construct() {
33 parent::__construct();
34 $this->addDescription( 'Update list of lexers supported by SyntaxHighlight_GeSHi' );
35 }
36
37 public function execute() {
38 function lang_filter( $val ) {
39 return preg_match( '/^[a-zA-Z0-9\-_]+$/', $val );
40 }
41
42 $header = '// Generated by ' . basename( __FILE__ ) . "\n\n";
43
44 $lexers = [];
45
46 $builder = new ProcessBuilder();
47 $builder->setPrefix( SyntaxHighlight_GeSHi::getPygmentizePath() );
48
49 $process = $builder->add( '-L' )->add( 'lexer' )->getProcess();
50 $process->run();
51
52 if ( !$process->isSuccessful() ) {
53 throw new \RuntimeException( $process->getErrorOutput() );
54 }
55
56 $output = $process->getOutput();
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
66 $code = "<?php\n" . $header . 'return ' . var_export( $lexers, true ) . ";\n";
67 $code = preg_replace( '/(\d+ \=>| (?=\‍())/i', '', $code );
68 $code = preg_replace( "/^ +/m", "\t", $code );
69
70 file_put_contents( __DIR__ . '/../SyntaxHighlight.lexers.php', $code );
71 $this->output( "Updated language list written to SyntaxHighlight.lexers.php\n" );
72 }
73}
74
75$maintClass = 'UpdateLanguageList';
76require_once RUN_MAINTENANCE_IF_MAIN;
$line
Definition cdb.php:58
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
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:2225
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:863
$batch execute()
class DemoMaint extends Maintenance $maintClass
require_once RUN_MAINTENANCE_IF_MAIN
$header