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(
41 array( 'page_namespace', 'page_title' ),
42 array( "page_namespace = $ns" ),
44 array( 'ORDER BY' => 'page_id' )
48 $end = $dbr->numRows( $result );
49 $this->output( "Will purge $end pages from namespace $ns\n" );
52 $end +
= $this->mBatchSize
- 1;
54 $blockEnd = $start +
$this->mBatchSize
- 1;
56 while( $blockEnd <= $end ) {
57 # Select pages we will purge:
58 $result = $dbr->select(
60 array( 'page_namespace', 'page_title' ),
61 array( "page_namespace = $ns" ),
64 'ORDER BY' => 'page_id',
65 'LIMIT' => $this->mBatchSize
,
66 'OFFSET' => $blockStart,
70 # Initialize/reset URLs to be purged
72 foreach( $result as $row ) {
73 $title = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
74 $url = $title->getFullUrl();
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 );
94 $maintClass = "PurgeNamespace";
95 require_once( RUN_MAINTENANCE_IF_MAIN
);