MediaWiki  1.30.0
updateLexerList.php
Go to the documentation of this file.
1 <?php
25 use Symfony\Component\Process\ProcessBuilder;
26 
27 $IP = getenv( 'MW_INSTALL_PATH' ) ?: __DIR__ . '/../../..';
28 
29 require_once "$IP/maintenance/Maintenance.php";
30 
31 class 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';
76 require_once RUN_MAINTENANCE_IF_MAIN;
$IP
$IP
Definition: updateLexerList.php:27
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:287
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
$maintClass
$maintClass
Definition: CountFancyCaptchas.php:54
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
$output
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:2198
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Maintenance::__construct
public function __construct()
Definition: maintenance.txt:41
$line
$line
Definition: cdb.php:58
$header
$header
Definition: updateCredits.php:35
$code
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:781
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:373
Maintenance::execute
public function execute()
Definition: maintenance.txt:45