26 private $allNamespaces;
33 parent::__construct();
34 $this->
addDescription(
"Send purge requests for listed pages to CDN.\n"
35 .
"By default this expects a list of URLs or page names from STDIN. "
36 .
"To query the database for input, use --namespace or --all-namespaces instead."
38 $this->
addOption(
'namespace',
'Purge pages with this namespace number',
false,
true );
39 $this->
addOption(
'all-namespaces',
'Purge pages in all namespaces',
false,
false );
41 "Update the page.page_touched database field.\n"
42 .
"This is only considered when purging by title, not when purging by namespace or URL.",
46 $this->
addOption(
'delay',
'Number of seconds to delay between each purge',
false,
true );
47 $this->
addOption(
'verbose',
'Show more output',
false,
false,
'v' );
52 $this->namespaceId = $this->
getOption(
'namespace' );
53 $this->allNamespaces = $this->
hasOption(
'all-namespaces' );
54 $this->doDbTouch = $this->
hasOption(
'db-touch' );
55 $this->delay = intval( $this->
getOption(
'delay',
'0' ) );
57 if ( $this->allNamespaces ) {
58 $this->purgeNamespace(
false );
59 } elseif ( $this->namespaceId !==
null ) {
60 $this->purgeNamespace( intval( $this->namespaceId ) );
64 $this->
output(
"Done!\n" );
70 private function doPurge() {
75 while ( !feof( $stdin ) ) {
76 $page = trim( fgets( $stdin ) );
77 if ( preg_match(
'%^https?://%', $page ) ) {
79 } elseif ( $page !==
'' ) {
80 $title = Title::newFromText( $page );
82 $newUrls = $htmlCacheUpdater->getUrls( $title );
84 foreach ( $newUrls as
$url ) {
88 $urls = array_merge( $urls, $newUrls );
90 if ( $this->doDbTouch ) {
91 $title->invalidateCache();
94 $this->
output(
"(Invalid title '$page')\n" );
98 $this->
output(
"Purging " . count( $urls ) .
" urls\n" );
99 $this->sendPurgeRequest( $urls );
107 private function purgeNamespace( $namespace =
false ) {
108 if ( $this->doDbTouch ) {
112 $this->
fatalError(
'The --db-touch option is not supported when purging by namespace.' );
118 if ( $namespace ===
false ) {
121 $conds = [
'page_namespace' => $namespace ];
124 $res = $dbr->newSelectQueryBuilder()
125 ->select( [
'page_id',
'page_namespace',
'page_title' ] )
128 ->andWhere( $dbr->expr(
'page_id',
'>', $startId ) )
129 ->orderBy(
'page_id' )
131 ->caller( __METHOD__ )->fetchResultSet();
132 if ( !$res->numRows() ) {
136 foreach ( $res as $row ) {
137 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
138 $urls = array_merge( $urls, $htmlCacheUpdater->getUrls( $title ) );
139 $startId = $row->page_id;
141 $this->sendPurgeRequest( $urls );
149 private function sendPurgeRequest( $urls ) {
151 if ( $this->delay > 0 ) {
152 foreach ( $urls as
$url ) {
154 $this->
output( $url .
"\n" );
156 $hcu->purgeUrls(
$url, $hcu::PURGE_NAIVE );
157 sleep( $this->delay );
161 $this->
output( implode(
"\n", $urls ) .
"\n" );
163 $hcu->purgeUrls( $urls, $hcu::PURGE_NAIVE );
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.