]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - extensions/SyntaxHighlight_GeSHi/maintenance/updateCSS.php
MediaWiki 1.30.2-scripts
[autoinstalls/mediawiki.git] / extensions / SyntaxHighlight_GeSHi / maintenance / updateCSS.php
1 <?php
2 /**
3  * Script to update Pygments CSS
4  *
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.
9  *
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.
14  *
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
19  *
20  * @file
21  * @author Ori Livneh <ori@wikimedia.org>
22  * @ingroup Maintenance
23  */
24
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 UpdateCSS extends Maintenance {
32
33         public function __construct() {
34                 parent::__construct();
35                 $this->addDescription( 'Generate CSS code for SyntaxHighlight_GeSHi' );
36         }
37
38         public function execute() {
39                 $target = __DIR__ . '/../modules/pygments.generated.css';
40                 $css = "/* Stylesheet generated by updateCSS.php */\n";
41
42                 $builder = new ProcessBuilder();
43                 $builder->setPrefix( SyntaxHighlight_GeSHi::getPygmentizePath() );
44
45                 $process = $builder
46                         ->add( '-f' )->add( 'html' )
47                         ->add( '-S' )->add( 'default' )
48                         ->add( '-a' )->add( '.' . SyntaxHighlight::HIGHLIGHT_CSS_CLASS )
49                         ->getProcess();
50
51                 $process->run();
52
53                 if ( !$process->isSuccessful() ) {
54                         throw new \RuntimeException( $process->getErrorOutput() );
55                 }
56
57                 $css .= $process->getOutput();
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";
68 require_once RUN_MAINTENANCE_IF_MAIN;