MediaWiki  1.34.0
updateCSS.php
Go to the documentation of this file.
1 <?php
26 
27 $IP = getenv( 'MW_INSTALL_PATH' ) ?: __DIR__ . '/../../..';
28 
29 require_once "$IP/maintenance/Maintenance.php";
30 
31 class UpdateCSS extends Maintenance {
32 
33  public function __construct() {
34  parent::__construct();
35 
36  $this->requireExtension( 'SyntaxHighlight' );
37  $this->addDescription( 'Generate CSS code for SyntaxHighlight_GeSHi' );
38  }
39 
40  public function execute() {
41  $target = __DIR__ . '/../modules/pygments.generated.css';
42  $css = "/* Stylesheet generated by updateCSS.php */\n";
43 
44  $result = Shell::command(
45  SyntaxHighlight::getPygmentizePath(),
46  '-f', 'html',
47  '-S', 'default',
48  '-a', '.' . SyntaxHighlight::HIGHLIGHT_CSS_CLASS
49  )
50  ->restrict( Shell::RESTRICT_DEFAULT | Shell::NO_NETWORK )
51  ->execute();
52 
53  if ( $result->getExitCode() != 0 ) {
54  throw new \RuntimeException( $result->getStderr() );
55  }
56 
57  $css .= $result->getStdout();
58 
59  if ( file_put_contents( $target, $css ) === false ) {
60  $this->output( "Failed to write to {$target}\n" );
61  } else {
62  $this->output( 'CSS written to ' . realpath( $target ) . "\n" );
63  }
64  }
65 }
66 
67 $maintClass = UpdateCSS::class;
68 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
MediaWiki\Shell\Shell
Executes shell commands.
Definition: Shell.php:44
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:348
UpdateCSS
Definition: updateCSS.php:31
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:82
UpdateCSS\__construct
__construct()
Default constructor.
Definition: updateCSS.php:33
Maintenance\requireExtension
requireExtension( $name)
Indicate that the specified extension must be loaded before the script can run.
Definition: Maintenance.php:638
$IP
$IP
Definition: updateCSS.php:27
UpdateCSS\execute
execute()
Do the actual work.
Definition: updateCSS.php:40
$maintClass
$maintClass
Definition: updateCSS.php:67
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:453