Index: trunk/phase3/maintenance/purgeNamespace.php |
— | — | @@ -0,0 +1,96 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Purge squids pages for a given namespace |
| 5 | + * |
| 6 | + * This program is free software; you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation; either version 2 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License along |
| 17 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | + * http://www.gnu.org/copyleft/gpl.html |
| 20 | + * |
| 21 | + * @ingroup Maintenance |
| 22 | + */ |
| 23 | + |
| 24 | +require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
| 25 | + |
| 26 | +# TODO implements a page_touched condition |
| 27 | + |
| 28 | +class PurgeNamespace extends Maintenance { |
| 29 | + public function __construct() { |
| 30 | + $this->mDescription = "Purge squids pages for a given namespace"; |
| 31 | + $this->addOption( "namespace", "Namespace number", true, true ); |
| 32 | + $this->setBatchSize( 100 ); |
| 33 | + parent::__construct(); |
| 34 | + } |
| 35 | + |
| 36 | + public function execute() { |
| 37 | + $dbr = wfGetDB( DB_SLAVE ); |
| 38 | + $ns = $dbr->addQuotes( $this->getOption( 'namespace') ); |
| 39 | + |
| 40 | + $result = $dbr->select( |
| 41 | + array( 'page' ), |
| 42 | + array( 'page_namespace', 'page_title' ), |
| 43 | + array( "page_namespace = $ns" ), |
| 44 | + __METHOD__, |
| 45 | + array( 'ORDER BY' => 'page_id' ) |
| 46 | + ); |
| 47 | + |
| 48 | + $start = 0; |
| 49 | + $end = $dbr->numRows( $result ); |
| 50 | + $this->output( "Will purge $end pages from namespace $ns\n" ); |
| 51 | + |
| 52 | + # Do remaining chunk |
| 53 | + $end += $this->mBatchSize - 1; |
| 54 | + $blockStart = $start; |
| 55 | + $blockEnd = $start + $this->mBatchSize - 1; |
| 56 | + |
| 57 | + while( $blockEnd <= $end ) { |
| 58 | + # Select pages we will purge: |
| 59 | + $result = $dbr->select( |
| 60 | + array( 'page' ), |
| 61 | + array( 'page_namespace', 'page_title' ), |
| 62 | + array( "page_namespace = $ns" ), |
| 63 | + __METHOD__, |
| 64 | + array( # conditions |
| 65 | + 'ORDER BY' => 'page_id', |
| 66 | + 'LIMIT' => $this->mBatchSize, |
| 67 | + 'OFFSET' => $blockStart, |
| 68 | + ) |
| 69 | + ); |
| 70 | + |
| 71 | + # Initialize/reset URLs to be purged |
| 72 | + $urls = array(); |
| 73 | + foreach( $result as $row ) { |
| 74 | + $title = Title::makeTitle( $row->page_namespace, $row->page_title ); |
| 75 | + $url = $title->getFullUrl(); |
| 76 | + $urls[] = $url; |
| 77 | + } |
| 78 | + |
| 79 | + $this->sendPurgeRequest( $urls ); |
| 80 | + |
| 81 | + $blockStart += $this->mBatchSize; |
| 82 | + $blockEnd += $this->mBatchSize; |
| 83 | + } |
| 84 | + |
| 85 | + $this->output( "Done!\n" ); |
| 86 | + } |
| 87 | + |
| 88 | + private function sendPurgeRequest( $urls ) { |
| 89 | + $this->output( "Purging " . count( $urls ). " urls\n" ); |
| 90 | + $u = new SquidUpdate( $urls ); |
| 91 | + $u->doUpdate(); |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +$maintClass = "PurgeNamespace"; |
| 96 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
| 97 | + |
Property changes on: trunk/phase3/maintenance/purgeNamespace.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 98 | + native |