MediaWiki
REL1_20
|
00001 <?php 00024 require_once( __DIR__ . '/Maintenance.php' ); 00025 00031 class PurgeList extends Maintenance { 00032 public function __construct() { 00033 parent::__construct(); 00034 $this->mDescription = "Send purge requests for listed pages to squid"; 00035 $this->addOption( 'purge', 'Whether to update page_touched.' , false, false ); 00036 $this->addOption( 'namespace', 'Namespace number', false, true ); 00037 $this->setBatchSize( 100 ); 00038 } 00039 00040 public function execute() { 00041 if( $this->hasOption( 'namespace' ) ) { 00042 $this->purgeNamespace(); 00043 } else { 00044 $this->purgeList(); 00045 } 00046 $this->output( "Done!\n" ); 00047 } 00048 00050 private function purgeList() { 00051 $stdin = $this->getStdin(); 00052 $urls = array(); 00053 00054 while ( !feof( $stdin ) ) { 00055 $page = trim( fgets( $stdin ) ); 00056 if ( preg_match( '%^https?://%', $page ) ) { 00057 $urls[] = $page; 00058 } elseif ( $page !== '' ) { 00059 $title = Title::newFromText( $page ); 00060 if ( $title ) { 00061 $url = $title->getInternalUrl(); 00062 $this->output( "$url\n" ); 00063 $urls[] = $url; 00064 if ( $this->getOption( 'purge' ) ) { 00065 $title->invalidateCache(); 00066 } 00067 } else { 00068 $this->output( "(Invalid title '$page')\n" ); 00069 } 00070 } 00071 } 00072 $this->sendPurgeRequest( $urls ); 00073 } 00074 00076 private function purgeNamespace() { 00077 $dbr = wfGetDB( DB_SLAVE ); 00078 $ns = $dbr->addQuotes( $this->getOption( 'namespace') ); 00079 00080 $result = $dbr->select( 00081 array( 'page' ), 00082 array( 'page_namespace', 'page_title' ), 00083 array( "page_namespace = $ns" ), 00084 __METHOD__, 00085 array( 'ORDER BY' => 'page_id' ) 00086 ); 00087 00088 $start = 0; 00089 $end = $dbr->numRows( $result ); 00090 $this->output( "Will purge $end pages from namespace $ns\n" ); 00091 00092 # Do remaining chunk 00093 $end += $this->mBatchSize - 1; 00094 $blockStart = $start; 00095 $blockEnd = $start + $this->mBatchSize - 1; 00096 00097 while( $blockEnd <= $end ) { 00098 # Select pages we will purge: 00099 $result = $dbr->select( 00100 array( 'page' ), 00101 array( 'page_namespace', 'page_title' ), 00102 array( "page_namespace = $ns" ), 00103 __METHOD__, 00104 array( # conditions 00105 'ORDER BY' => 'page_id', 00106 'LIMIT' => $this->mBatchSize, 00107 'OFFSET' => $blockStart, 00108 ) 00109 ); 00110 # Initialize/reset URLs to be purged 00111 $urls = array(); 00112 foreach( $result as $row ) { 00113 $title = Title::makeTitle( $row->page_namespace, $row->page_title ); 00114 $url = $title->getInternalUrl(); 00115 $urls[] = $url; 00116 } 00117 00118 $this->sendPurgeRequest( $urls ); 00119 00120 $blockStart += $this->mBatchSize; 00121 $blockEnd += $this->mBatchSize; 00122 } 00123 } 00124 00129 private function sendPurgeRequest( $urls ) { 00130 $this->output( "Purging " . count( $urls ). " urls\n" ); 00131 $u = new SquidUpdate( $urls ); 00132 $u->doUpdate(); 00133 } 00134 00135 } 00136 00137 $maintClass = "PurgeList"; 00138 require_once( RUN_MAINTENANCE_IF_MAIN );