Revert r88502 since this can be done with a gadget
[lhc/web/wiklou.git] / maintenance / purgeNamespace.php
1 <?php
2 /**
3 * Purge squids pages for a given namespace
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 * @ingroup Maintenance
21 */
22
23 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
24
25 # TODO implements a page_touched condition
26
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();
33 }
34
35 public function execute() {
36 $dbr = wfGetDB( DB_SLAVE );
37 $ns = $dbr->addQuotes( $this->getOption( 'namespace') );
38
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' )
45 );
46
47 $start = 0;
48 $end = $dbr->numRows( $result );
49 $this->output( "Will purge $end pages from namespace $ns\n" );
50
51 # Do remaining chunk
52 $end += $this->mBatchSize - 1;
53 $blockStart = $start;
54 $blockEnd = $start + $this->mBatchSize - 1;
55
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,
67 )
68 );
69
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;
76 }
77
78 $this->sendPurgeRequest( $urls );
79
80 $blockStart += $this->mBatchSize;
81 $blockEnd += $this->mBatchSize;
82 }
83
84 $this->output( "Done!\n" );
85 }
86
87 private function sendPurgeRequest( $urls ) {
88 $this->output( "Purging " . count( $urls ). " urls\n" );
89 $u = new SquidUpdate( $urls );
90 $u->doUpdate();
91 }
92 }
93
94 $maintClass = "PurgeNamespace";
95 require_once( RUN_MAINTENANCE_IF_MAIN );
96