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