Merge "Split skins.common up into a proper trio of .elements, .content, and .interfac...
[lhc/web/wiklou.git] / maintenance / checkLess.php
1 <?php
2 /**
3 * Checks LESS files in known resources for errors
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 * @ingroup Maintenance
22 */
23
24 require_once __DIR__ . '/Maintenance.php';
25
26 /**
27 * @ingroup Maintenance
28 */
29 class CheckLess extends Maintenance {
30 public function __construct() {
31 parent::__construct();
32 $this->mDescription = 'Checks LESS files for errors';
33 }
34
35 public function execute() {
36 $result = false;
37 $resourceLoader = new ResourceLoader();
38 foreach ( $resourceLoader->getModuleNames() as $name ) {
39 /** @var ResourceLoaderFileModule $module */
40 $module = $resourceLoader->getModule( $name );
41 if ( !$module || !$module instanceof ResourceLoaderFileModule ) {
42 continue;
43 }
44
45 $hadErrors = false;
46 foreach ( $module->getAllStyleFiles() as $file ) {
47 if ( $module->getStyleSheetLang( $file ) !== 'less' ) {
48 continue;
49 }
50 try {
51 $compiler = ResourceLoader::getLessCompiler();
52 $compiler->compileFile( $file );
53 } catch ( Exception $e ) {
54 if ( !$hadErrors ) {
55 $this->error( "Errors checking module $name:\n" );
56 $hadErrors = true;
57 }
58 $this->error( $e->getMessage() . "\n" );
59 $result = true;
60 }
61 }
62 }
63 if ( !$result ) {
64 $this->output( "No errors found\n" );
65 } else {
66 die( 1 );
67 }
68 }
69 }
70
71 $maintClass = 'CheckLess';
72 require_once RUN_MAINTENANCE_IF_MAIN;