r94444 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94443‎ | r94444 | r94445 >
Date:08:51, 14 August 2011
Author:hashar
Status:resolved (Comments)
Tags:
Comment:
(bug 28273) Merge purgeList and purgeNamespace scripts

Nothing fancy, just copy pasted from purgeNamespace into purgeList.
This need to be in 1.18 to avoid publishing purgeNamespace to everyone
and removing it in 1.19 =)
Modified paths:
  • /trunk/phase3/maintenance/purgeList.php (modified) (history)
  • /trunk/phase3/maintenance/purgeNamespace.php (deleted) (history)

Diff [purge]

Index: trunk/phase3/maintenance/purgeNamespace.php
@@ -1,96 +0,0 @@
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 -
Index: trunk/phase3/maintenance/purgeList.php
@@ -27,9 +27,21 @@
2828 parent::__construct();
2929 $this->mDescription = "Send purge requests for listed pages to squid";
3030 $this->addOption( 'purge', 'Whether to update page_touched.' , false, false );
 31+ $this->addOption( 'namespace', 'Namespace number', false, true );
 32+ $this->setBatchSize( 100 );
3133 }
3234
3335 public function execute() {
 36+ if( $this->hasOption( 'namespace' ) ) {
 37+ $this->purgeNamespace();
 38+ } else {
 39+ $this->purgeList();
 40+ }
 41+ $this->output( "Done!\n" );
 42+ }
 43+
 44+ /** Purge URL coming from stdin */
 45+ private function purgeList() {
3446 $stdin = $this->getStdin();
3547 $urls = array();
3648
@@ -51,13 +63,70 @@
5264 }
5365 }
5466 }
 67+ $this->sendPurgeRequest( $urls );
 68+ }
5569
56 - $this->output( "Purging " . count( $urls ) . " urls...\n" );
57 - $u = new SquidUpdate( $urls );
58 - $u->doUpdate();
 70+ /** Purge a namespace given by --namespace */
 71+ private function purgeNamespace() {
 72+ $dbr = wfGetDB( DB_SLAVE );
 73+ $ns = $dbr->addQuotes( $this->getOption( 'namespace') );
5974
60 - $this->output( "Done!\n" );
61 - }
 75+ $result = $dbr->select(
 76+ array( 'page' ),
 77+ array( 'page_namespace', 'page_title' ),
 78+ array( "page_namespace = $ns" ),
 79+ __METHOD__,
 80+ array( 'ORDER BY' => 'page_id' )
 81+ );
 82+
 83+ $start = 0;
 84+ $end = $dbr->numRows( $result );
 85+ $this->output( "Will purge $end pages from namespace $ns\n" );
 86+
 87+ # Do remaining chunk
 88+ $end += $this->mBatchSize - 1;
 89+ $blockStart = $start;
 90+ $blockEnd = $start + $this->mBatchSize - 1;
 91+
 92+ while( $blockEnd <= $end ) {
 93+ # Select pages we will purge:
 94+ $result = $dbr->select(
 95+ array( 'page' ),
 96+ array( 'page_namespace', 'page_title' ),
 97+ array( "page_namespace = $ns" ),
 98+ __METHOD__,
 99+ array( # conditions
 100+ 'ORDER BY' => 'page_id',
 101+ 'LIMIT' => $this->mBatchSize,
 102+ 'OFFSET' => $blockStart,
 103+ )
 104+ );
 105+ # Initialize/reset URLs to be purged
 106+ $urls = array();
 107+ foreach( $result as $row ) {
 108+ $title = Title::makeTitle( $row->page_namespace, $row->page_title );
 109+ $url = $title->getFullUrl();
 110+ $urls[] = $url;
 111+ }
 112+
 113+ $this->sendPurgeRequest( $urls );
 114+
 115+ $blockStart += $this->mBatchSize;
 116+ $blockEnd += $this->mBatchSize;
 117+ }
 118+ }
 119+
 120+ /**
 121+ * Helper to purge an array of $urls
 122+ * @param $urls array List of URLS to purge from squids
 123+ */
 124+ private function sendPurgeRequest( $urls ) {
 125+ $this->output( "Purging " . count( $urls ). " urls\n" );
 126+ $u = new SquidUpdate( $urls );
 127+ $u->doUpdate();
 128+ }
 129+
 130+
62131 }
63132
64133 $maintClass = "PurgeList";

Follow-up revisions

RevisionCommit summaryAuthorDate
r94498Fix space/tab indentation FU r94444hashar10:23, 15 August 2011
r95607MFT to REL1_18...hashar19:28, 27 August 2011

Comments

#Comment by 😂 (talk | contribs)   15:59, 14 August 2011

Has a mix of tabs and spaces for indentation.

Status & tagging log