Whitelist the <wbr> element.
[mediawiki.git] / maintenance / cleanupRemovedModules.php
blob84eec289696a6a13b316aed3aebc3de973629614
1 <?php
2 /**
3 * Remove cache entries for removed ResourceLoader modules from the database.
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
20 * @file
21 * @ingroup Maintenance
22 * @author Roan Kattouw
25 require_once __DIR__ . '/Maintenance.php';
27 /**
28 * Maintenance script to remove cache entries for removed ResourceLoader modules
29 * from the database.
31 * @ingroup Maintenance
33 class CleanupRemovedModules extends Maintenance {
35 public function __construct() {
36 parent::__construct();
37 $this->mDescription = 'Remove cache entries for removed ResourceLoader modules from the database';
38 $this->addOption( 'batchsize', 'Delete rows in batches of this size. Default: 500', false, true );
39 $this->addOption( 'max-slave-lag', 'If the slave lag exceeds this many seconds, wait until it drops below this value. Default: 5', false, true );
42 public function execute() {
43 $dbw = wfGetDB( DB_MASTER );
44 $rl = new ResourceLoader();
45 $moduleNames = $rl->getModuleNames();
46 $moduleList = implode( ', ', array_map( array( $dbw, 'addQuotes' ), $moduleNames ) );
47 $limit = max( 1, intval( $this->getOption( 'batchsize', 500 ) ) );
48 $maxlag = intval( $this->getOption( 'max-slave-lag', 5 ) );
50 $this->output( "Cleaning up module_deps table...\n" );
51 $i = 1;
52 $modDeps = $dbw->tableName( 'module_deps' );
53 do {
54 // $dbw->delete() doesn't support LIMIT :(
55 $where = $moduleList ? "md_module NOT IN ($moduleList)" : '1=1';
56 $dbw->query( "DELETE FROM $modDeps WHERE $where LIMIT $limit", __METHOD__ );
57 $numRows = $dbw->affectedRows();
58 $this->output( "Batch $i: $numRows rows\n" );
59 $i++;
60 wfWaitForSlaves( $maxlag );
61 } while ( $numRows > 0 );
62 $this->output( "done\n" );
64 $this->output( "Cleaning up msg_resource table...\n" );
65 $i = 1;
67 $mrRes = $dbw->tableName( 'msg_resource' );
68 do {
69 $where = $moduleList ? "mr_resource NOT IN ($moduleList)" : '1=1';
70 $dbw->query( "DELETE FROM $mrRes WHERE $where LIMIT $limit", __METHOD__ );
71 $numRows = $dbw->affectedRows();
72 $this->output( "Batch $i: $numRows rows\n" );
73 $i++;
74 wfWaitForSlaves( $maxlag );
75 } while ( $numRows > 0 );
76 $this->output( "done\n" );
78 $this->output( "Cleaning up msg_resource_links table...\n" );
79 $i = 1;
80 $msgResLinks = $dbw->tableName( 'msg_resource_links' );
81 do {
82 $where = $moduleList ? "mrl_resource NOT IN ($moduleList)" : '1=1';
83 $dbw->query( "DELETE FROM $msgResLinks WHERE $where LIMIT $limit", __METHOD__ );
84 $numRows = $dbw->affectedRows();
85 $this->output( "Batch $i: $numRows rows\n" );
86 $i++;
87 wfWaitForSlaves( $maxlag );
88 } while ( $numRows > 0 );
89 $this->output( "done\n" );
93 $maintClass = "CleanupRemovedModules";
94 require_once RUN_MAINTENANCE_IF_MAIN;