MediaWiki  1.23.2
purgeList.php
Go to the documentation of this file.
1 <?php
24 require_once __DIR__ . '/Maintenance.php';
25 
31 class PurgeList extends Maintenance {
32  public function __construct() {
33  parent::__construct();
34  $this->mDescription = "Send purge requests for listed pages to squid";
35  $this->addOption( 'purge', 'Whether to update page_touched.', false, false );
36  $this->addOption( 'namespace', 'Namespace number', false, true );
37  $this->addOption( 'all', 'Purge all pages', false, false );
38  $this->addOption( 'delay', 'Number of seconds to delay between each purge', false, true );
39  $this->addOption( 'verbose', 'Show more output', false, false, 'v' );
40  $this->setBatchSize( 100 );
41  }
42 
43  public function execute() {
44  if ( $this->hasOption( 'all' ) ) {
45  $this->purgeNamespace( false );
46  } elseif ( $this->hasOption( 'namespace' ) ) {
47  $this->purgeNamespace( intval( $this->getOption( 'namespace' ) ) );
48  } else {
49  $this->doPurge();
50  }
51  $this->output( "Done!\n" );
52  }
53 
57  private function doPurge() {
58  $stdin = $this->getStdin();
59  $urls = array();
60 
61  while ( !feof( $stdin ) ) {
62  $page = trim( fgets( $stdin ) );
63  if ( preg_match( '%^https?://%', $page ) ) {
64  $urls[] = $page;
65  } elseif ( $page !== '' ) {
66  $title = Title::newFromText( $page );
67  if ( $title ) {
68  $url = $title->getInternalURL();
69  $this->output( "$url\n" );
70  $urls[] = $url;
71  if ( $this->getOption( 'purge' ) ) {
72  $title->invalidateCache();
73  }
74  } else {
75  $this->output( "(Invalid title '$page')\n" );
76  }
77  }
78  }
79  $this->output( "Purging " . count( $urls ) . " urls\n" );
80  $this->sendPurgeRequest( $urls );
81  }
82 
86  private function purgeNamespace( $namespace = false ) {
87  $dbr = wfGetDB( DB_SLAVE );
88  $startId = 0;
89  if ( $namespace === false ) {
90  $conds = array();
91  } else {
92  $conds = array( 'page_namespace' => $namespace );
93  }
94  while ( true ) {
95  $res = $dbr->select( 'page',
96  array( 'page_id', 'page_namespace', 'page_title' ),
97  $conds + array( 'page_id > ' . $dbr->addQuotes( $startId ) ),
98  __METHOD__,
99  array(
100  'LIMIT' => $this->mBatchSize,
101  'ORDER BY' => 'page_id'
102 
103  )
104  );
105  if ( !$res->numRows() ) {
106  break;
107  }
108  $urls = array();
109  foreach ( $res as $row ) {
110  $title = Title::makeTitle( $row->page_namespace, $row->page_title );
111  $url = $title->getInternalURL();
112  $urls[] = $url;
113  $startId = $row->page_id;
114  }
115  $this->sendPurgeRequest( $urls );
116  }
117  }
118 
123  private function sendPurgeRequest( $urls ) {
124  if ( $this->hasOption( 'delay' ) ) {
125  $delay = floatval( $this->getOption( 'delay' ) );
126  foreach ( $urls as $url ) {
127  if ( $this->hasOption( 'verbose' ) ) {
128  $this->output( $url . "\n" );
129  }
130  $u = new SquidUpdate( array( $url ) );
131  $u->doUpdate();
132  usleep( $delay * 1e6 );
133  }
134  } else {
135  if ( $this->hasOption( 'verbose' ) ) {
136  $this->output( implode( "\n", $urls ) . "\n" );
137  }
138  $u = new SquidUpdate( $urls );
139  $u->doUpdate();
140  }
141  }
142 
143 }
144 
145 $maintClass = "PurgeList";
146 require_once RUN_MAINTENANCE_IF_MAIN;
Title\makeTitle
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:398
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
Maintenance\getStdin
getStdin( $len=null)
Return input from stdin.
Definition: Maintenance.php:287
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3650
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false)
Add a parameter to the script.
Definition: Maintenance.php:169
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
$maintClass
$maintClass
Definition: purgeList.php:145
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
$dbr
$dbr
Definition: testCompression.php:48
PurgeList
Maintenance script that sends purge requests for listed pages to squid.
Definition: purgeList.php:31
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
PurgeList\execute
execute()
Do the actual work.
Definition: purgeList.php:43
SquidUpdate
Handles purging appropriate Squid URLs given a title (or titles)
Definition: SquidUpdate.php:28
PurgeList\doPurge
doPurge()
Purge URL coming from stdin.
Definition: purgeList.php:57
PurgeList\__construct
__construct()
Default constructor.
Definition: purgeList.php:32
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
DB_SLAVE
const DB_SLAVE
Definition: Defines.php:55
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:191
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:314
PurgeList\purgeNamespace
purgeNamespace( $namespace=false)
Purge a namespace or all pages.
Definition: purgeList.php:86
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular param exists.
Definition: Maintenance.php:181
PurgeList\sendPurgeRequest
sendPurgeRequest( $urls)
Helper to purge an array of $urls.
Definition: purgeList.php:123
$res
$res
Definition: database.txt:21
Maintenance\setBatchSize
setBatchSize( $s=0)
Set the batch size.
Definition: Maintenance.php:254