00001 <?php 00009 $options = array('only','help'); 00010 00011 require_once( 'commandLine.inc' ); 00012 00013 require_once( "$IP/includes/SpecialPage.php" ); 00014 require_once( "$IP/includes/QueryPage.php" ); 00015 00016 if(@$options['help']) { 00017 print "usage:updateSpecialPages.php [--help] [--only=page]\n"; 00018 print " --help : this help message\n"; 00019 print " --list : list special pages names\n"; 00020 print " --only=page : only update 'page'. Ex: --only=BrokenRedirects\n"; 00021 print " --override : update even pages which have had updates disabled\n"; 00022 wfDie(); 00023 } 00024 00025 $wgOut->disable(); 00026 $dbw = wfGetDB( DB_MASTER ); 00027 00028 foreach( $wgSpecialPageCacheUpdates as $special => $call ) { 00029 if( !is_callable($call) ) { 00030 print "Uncallable function $call!\n"; 00031 continue; 00032 } 00033 $t1 = explode( ' ', microtime() ); 00034 call_user_func( $call, $dbw ); 00035 $t2 = explode( ' ', microtime() ); 00036 printf( '%-30s ', $special ); 00037 $elapsed = ($t2[0] - $t1[0]) + ($t2[1] - $t1[1]); 00038 $hours = intval( $elapsed / 3600 ); 00039 $minutes = intval( $elapsed % 3600 / 60 ); 00040 $seconds = $elapsed - $hours * 3600 - $minutes * 60; 00041 if ( $hours ) { 00042 print $hours . 'h '; 00043 } 00044 if ( $minutes ) { 00045 print $minutes . 'm '; 00046 } 00047 printf( "completed in %.2fs\n", $seconds ); 00048 # Wait for the slave to catch up 00049 wfWaitForSlaves( 5 ); 00050 } 00051 00052 foreach( $wgQueryPages as $page ) { 00053 @list( $class, $special, $limit ) = $page; 00054 00055 # --list : just show the name of pages 00056 if( @$options['list'] ) { 00057 print "$special\n"; 00058 continue; 00059 } 00060 00061 if ( !isset( $options['override'] ) && $wgDisableQueryPageUpdate && in_array( $special, $wgDisableQueryPageUpdate ) ) { 00062 printf("%-30s disabled\n", $special); 00063 continue; 00064 } 00065 00066 $specialObj = SpecialPage::getPage( $special ); 00067 if ( !$specialObj ) { 00068 print "No such special page: $special\n"; 00069 exit; 00070 } 00071 if ( !class_exists( $class ) ) { 00072 $file = $specialObj->getFile(); 00073 require_once( $file ); 00074 } 00075 $queryPage = new $class; 00076 00077 if( !isset($options['only']) or $options['only'] == $queryPage->getName() ) { 00078 printf( '%-30s ', $special ); 00079 if ( $queryPage->isExpensive() ) { 00080 $t1 = explode( ' ', microtime() ); 00081 # Do the query 00082 $num = $queryPage->recache( $limit === null ? $wgQueryCacheLimit : $limit ); 00083 $t2 = explode( ' ', microtime() ); 00084 if ( $num === false ) { 00085 print "FAILED: database error\n"; 00086 } else { 00087 print "got $num rows in "; 00088 00089 $elapsed = ($t2[0] - $t1[0]) + ($t2[1] - $t1[1]); 00090 $hours = intval( $elapsed / 3600 ); 00091 $minutes = intval( $elapsed % 3600 / 60 ); 00092 $seconds = $elapsed - $hours * 3600 - $minutes * 60; 00093 if ( $hours ) { 00094 print $hours . 'h '; 00095 } 00096 if ( $minutes ) { 00097 print $minutes . 'm '; 00098 } 00099 printf( "%.2fs\n", $seconds ); 00100 } 00101 # Reopen any connections that have closed 00102 if ( !wfGetLB()->pingAll()) { 00103 print "\n"; 00104 do { 00105 print "Connection failed, reconnecting in 10 seconds...\n"; 00106 sleep(10); 00107 } while ( !wfGetLB()->pingAll() ); 00108 print "Reconnected\n\n"; 00109 } else { 00110 # Commit the results 00111 $dbw->immediateCommit(); 00112 } 00113 # Wait for the slave to catch up 00114 wfWaitForSlaves( 5 ); 00115 } else { 00116 print "cheap, skipped\n"; 00117 } 00118 } 00119 }