3 * Script to update Pygments CSS
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @author Ori Livneh <ori@wikimedia.org>
22 * @ingroup Maintenance
25 use Symfony\Component\Process\ProcessBuilder;
27 $IP = getenv( 'MW_INSTALL_PATH' ) ?: __DIR__ . '/../../..';
29 require_once "$IP/maintenance/Maintenance.php";
31 class UpdateCSS extends Maintenance {
33 public function __construct() {
34 parent::__construct();
35 $this->addDescription( 'Generate CSS code for SyntaxHighlight_GeSHi' );
38 public function execute() {
39 $target = __DIR__ . '/../modules/pygments.generated.css';
40 $css = "/* Stylesheet generated by updateCSS.php */\n";
42 $builder = new ProcessBuilder();
43 $builder->setPrefix( SyntaxHighlight_GeSHi::getPygmentizePath() );
46 ->add( '-f' )->add( 'html' )
47 ->add( '-S' )->add( 'default' )
48 ->add( '-a' )->add( '.' . SyntaxHighlight::HIGHLIGHT_CSS_CLASS )
53 if ( !$process->isSuccessful() ) {
54 throw new \RuntimeException( $process->getErrorOutput() );
57 $css .= $process->getOutput();
59 if ( file_put_contents( $target, $css ) === false ) {
60 $this->output( "Failed to write to {$target}\n" );
62 $this->output( 'CSS written to ' . realpath( $target ) . "\n" );
67 $maintClass = "UpdateCSS";
68 require_once RUN_MAINTENANCE_IF_MAIN;