40 private $allNamespaces;
47 parent::__construct();
48 $this->
addDescription(
"Send purge requests for listed pages to CDN.\n"
49 .
"By default this expects a list of URLs or page names from STDIN. "
50 .
"To query the database for input, use --namespace or --all-namespaces instead."
52 $this->
addOption(
'namespace',
'Purge pages with this namespace number',
false,
true );
53 $this->
addOption(
'all-namespaces',
'Purge pages in all namespaces',
false,
false );
55 "Update the page.page_touched database field.\n"
56 .
"This is only considered when purging by title, not when purging by namespace or URL.",
60 $this->
addOption(
'delay',
'Number of seconds to delay between each purge',
false,
true );
61 $this->
addOption(
'verbose',
'Show more output',
false,
false,
'v' );
66 $this->namespaceId = $this->
getOption(
'namespace' );
67 $this->allNamespaces = $this->
hasOption(
'all-namespaces' );
68 $this->doDbTouch = $this->
hasOption(
'db-touch' );
69 $this->delay = intval( $this->
getOption(
'delay',
'0' ) );
71 if ( $this->allNamespaces ) {
72 $this->purgeNamespace(
false );
73 } elseif ( $this->namespaceId !==
null ) {
74 $this->purgeNamespace( intval( $this->namespaceId ) );
78 $this->
output(
"Done!\n" );
84 private function doPurge() {
89 while ( !feof( $stdin ) ) {
90 $page = trim( fgets( $stdin ) );
91 if ( preg_match(
'%^https?://%', $page ) ) {
93 } elseif ( $page !==
'' ) {
94 $title = Title::newFromText( $page );
96 $newUrls = $htmlCacheUpdater->getUrls( $title );
98 foreach ( $newUrls as
$url ) {
102 $urls = array_merge( $urls, $newUrls );
104 if ( $this->doDbTouch ) {
105 $title->invalidateCache();
108 $this->
output(
"(Invalid title '$page')\n" );
112 $this->
output(
"Purging " . count( $urls ) .
" urls\n" );
113 $this->sendPurgeRequest( $urls );
121 private function purgeNamespace( $namespace =
false ) {
122 if ( $this->doDbTouch ) {
126 $this->
fatalError(
'The --db-touch option is not supported when purging by namespace.' );
132 if ( $namespace ===
false ) {
135 $conds = [
'page_namespace' => $namespace ];
138 $res = $dbr->newSelectQueryBuilder()
139 ->select( [
'page_id',
'page_namespace',
'page_title' ] )
142 ->andWhere( $dbr->expr(
'page_id',
'>', $startId ) )
143 ->orderBy(
'page_id' )
145 ->caller( __METHOD__ )->fetchResultSet();
146 if ( !$res->numRows() ) {
150 foreach ( $res as $row ) {
151 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
152 $urls = array_merge( $urls, $htmlCacheUpdater->getUrls( $title ) );
153 $startId = $row->page_id;
155 $this->sendPurgeRequest( $urls );
163 private function sendPurgeRequest( $urls ) {
165 if ( $this->delay > 0 ) {
166 foreach ( $urls as
$url ) {
168 $this->
output( $url .
"\n" );
170 $hcu->purgeUrls(
$url, $hcu::PURGE_NAIVE );
171 sleep( $this->delay );
175 $this->
output( implode(
"\n", $urls ) .
"\n" );
177 $hcu->purgeUrls( $urls, $hcu::PURGE_NAIVE );
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.