Notice: Use of undefined constant GAID_FOR_UPDATE - assumed 'GAID_FOR_UPDATE' in...
[mediawiki.git] / maintenance / purgeNamespace.php
blob0759ca0f3c08bd15007aaf1060cb6d5c8d2d9102
1 <?php
2 /**
3 * Purge squids pages for a given namespace
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 * @ingroup Maintenance
23 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
25 # TODO implements a page_touched condition
27 class PurgeNamespace extends Maintenance {
28 public function __construct() {
29 $this->mDescription = "Purge squids pages for a given namespace";
30 $this->addOption( "namespace", "Namespace number", true, true );
31 $this->setBatchSize( 100 );
32 parent::__construct();
35 public function execute() {
36 $dbr = wfGetDB( DB_SLAVE );
37 $ns = $dbr->addQuotes( $this->getOption( 'namespace') );
39 $result = $dbr->select(
40 array( 'page' ),
41 array( 'page_namespace', 'page_title' ),
42 array( "page_namespace = $ns" ),
43 __METHOD__,
44 array( 'ORDER BY' => 'page_id' )
47 $start = 0;
48 $end = $dbr->numRows( $result );
49 $this->output( "Will purge $end pages from namespace $ns\n" );
51 # Do remaining chunk
52 $end += $this->mBatchSize - 1;
53 $blockStart = $start;
54 $blockEnd = $start + $this->mBatchSize - 1;
56 while( $blockEnd <= $end ) {
57 # Select pages we will purge:
58 $result = $dbr->select(
59 array( 'page' ),
60 array( 'page_namespace', 'page_title' ),
61 array( "page_namespace = $ns" ),
62 __METHOD__,
63 array( # conditions
64 'ORDER BY' => 'page_id',
65 'LIMIT' => $this->mBatchSize,
66 'OFFSET' => $blockStart,
70 # Initialize/reset URLs to be purged
71 $urls = array();
72 foreach( $result as $row ) {
73 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
74 $url = $title->getFullUrl();
75 $urls[] = $url;
78 $this->sendPurgeRequest( $urls );
80 $blockStart += $this->mBatchSize;
81 $blockEnd += $this->mBatchSize;
84 $this->output( "Done!\n" );
87 private function sendPurgeRequest( $urls ) {
88 $this->output( "Purging " . count( $urls ). " urls\n" );
89 $u = new SquidUpdate( $urls );
90 $u->doUpdate();
94 $maintClass = "PurgeNamespace";
95 require_once( RUN_MAINTENANCE_IF_MAIN );