MediaWiki
REL1_20
|
00001 <?php 00025 require_once( __DIR__ . '/Maintenance.php' ); 00026 00032 class UpdateSpecialPages extends Maintenance { 00033 public function __construct() { 00034 parent::__construct(); 00035 $this->addOption( 'list', 'List special page names' ); 00036 $this->addOption( 'only', 'Only update "page". Ex: --only=BrokenRedirects', false, true ); 00037 $this->addOption( 'override', 'Also update pages that have updates disabled' ); 00038 } 00039 00040 public function execute() { 00041 global $IP, $wgSpecialPageCacheUpdates, $wgQueryPages, $wgQueryCacheLimit, $wgDisableQueryPageUpdate; 00042 00043 $dbw = wfGetDB( DB_MASTER ); 00044 00045 foreach ( $wgSpecialPageCacheUpdates as $special => $call ) { 00046 if ( !is_callable( $call ) ) { 00047 $this->error( "Uncallable function $call!" ); 00048 continue; 00049 } 00050 $t1 = explode( ' ', microtime() ); 00051 call_user_func( $call, $dbw ); 00052 $t2 = explode( ' ', microtime() ); 00053 $this->output( sprintf( '%-30s ', $special ) ); 00054 $elapsed = ( $t2[0] - $t1[0] ) + ( $t2[1] - $t1[1] ); 00055 $hours = intval( $elapsed / 3600 ); 00056 $minutes = intval( $elapsed % 3600 / 60 ); 00057 $seconds = $elapsed - $hours * 3600 - $minutes * 60; 00058 if ( $hours ) { 00059 $this->output( $hours . 'h ' ); 00060 } 00061 if ( $minutes ) { 00062 $this->output( $minutes . 'm ' ); 00063 } 00064 $this->output( sprintf( "completed in %.2fs\n", $seconds ) ); 00065 # Wait for the slave to catch up 00066 wfWaitForSlaves(); 00067 } 00068 00069 // This is needed to initialise $wgQueryPages 00070 require_once( "$IP/includes/QueryPage.php" ); 00071 00072 foreach ( $wgQueryPages as $page ) { 00073 list( $class, $special ) = $page; 00074 $limit = isset( $page[2] ) ? $page[2] : null; 00075 00076 # --list : just show the name of pages 00077 if ( $this->hasOption( 'list' ) ) { 00078 $this->output( "$special\n" ); 00079 continue; 00080 } 00081 00082 if ( !$this->hasOption( 'override' ) && $wgDisableQueryPageUpdate && in_array( $special, $wgDisableQueryPageUpdate ) ) { 00083 $this->output( sprintf( "%-30s disabled\n", $special ) ); 00084 continue; 00085 } 00086 00087 $specialObj = SpecialPageFactory::getPage( $special ); 00088 if ( !$specialObj ) { 00089 $this->output( "No such special page: $special\n" ); 00090 exit; 00091 } 00092 if ( $specialObj instanceof QueryPage ) { 00093 $queryPage = $specialObj; 00094 } else { 00095 if ( !class_exists( $class ) ) { 00096 $file = $specialObj->getFile(); 00097 require_once( $file ); 00098 } 00099 $queryPage = new $class; 00100 } 00101 00102 if ( !$this->hasOption( 'only' ) || $this->getOption( 'only' ) == $queryPage->getName() ) { 00103 $this->output( sprintf( '%-30s ', $special ) ); 00104 if ( $queryPage->isExpensive() ) { 00105 $t1 = explode( ' ', microtime() ); 00106 # Do the query 00107 $num = $queryPage->recache( $limit === null ? $wgQueryCacheLimit : $limit ); 00108 $t2 = explode( ' ', microtime() ); 00109 if ( $num === false ) { 00110 $this->output( "FAILED: database error\n" ); 00111 } else { 00112 $this->output( "got $num rows in " ); 00113 00114 $elapsed = ( $t2[0] - $t1[0] ) + ( $t2[1] - $t1[1] ); 00115 $hours = intval( $elapsed / 3600 ); 00116 $minutes = intval( $elapsed % 3600 / 60 ); 00117 $seconds = $elapsed - $hours * 3600 - $minutes * 60; 00118 if ( $hours ) { 00119 $this->output( $hours . 'h ' ); 00120 } 00121 if ( $minutes ) { 00122 $this->output( $minutes . 'm ' ); 00123 } 00124 $this->output( sprintf( "%.2fs\n", $seconds ) ); 00125 } 00126 # Reopen any connections that have closed 00127 if ( !wfGetLB()->pingAll() ) { 00128 $this->output( "\n" ); 00129 do { 00130 $this->error( "Connection failed, reconnecting in 10 seconds..." ); 00131 sleep( 10 ); 00132 } while ( !wfGetLB()->pingAll() ); 00133 $this->output( "Reconnected\n\n" ); 00134 } else { 00135 # Commit the results 00136 $dbw->commit( __METHOD__ ); 00137 } 00138 # Wait for the slave to catch up 00139 wfWaitForSlaves(); 00140 } else { 00141 $this->output( "cheap, skipped\n" ); 00142 } 00143 } 00144 } 00145 } 00146 } 00147 00148 $maintClass = "UpdateSpecialPages"; 00149 require_once( RUN_MAINTENANCE_IF_MAIN );