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