3 # Run this script periodically if you have miser mode enabled, to refresh the caches
4 $options = array('only','help');
6 require_once( 'commandLine.inc' );
8 require_once( 'SpecialPage.php' );
9 require_once( 'QueryPage.php' );
11 if(@$options['help']) {
12 print "usage:updateSpecialPages.php [--help] [--only=page]\n";
13 print " --help : this help message\n";
14 print " --list : list special pages names\n";
15 print " --only=page : only update 'page'. Ex: --only=BrokenRedirects\n";
20 $dbw = wfGetDB( DB_MASTER
);
22 foreach ( $wgQueryPages as $page ) {
23 @list
( $class, $special, $limit ) = $page;
25 # --list : just show the name of pages
26 if( @$options['list'] ) {
31 if ( $wgDisableQueryPageUpdate && in_array( $special, $wgDisableQueryPageUpdate ) ) {
32 printf("%-30s disabled\n", $special);
36 $specialObj = SpecialPage
::getPage( $special );
38 print "No such special page: $special\n";
41 if ( !class_exists( $class ) ) {
42 $file = $specialObj->getFile();
43 require_once( $file );
45 $queryPage = new $class;
47 if( !(isset($options['only'])) or ($options['only'] == $queryPage->getName()) ) {
48 printf( '%-30s ', $special );
50 if ( $queryPage->isExpensive() ) {
51 $t1 = explode( ' ', microtime() );
53 $num = $queryPage->recache( $limit === null ?
$wgQueryCacheLimit : $limit );
54 $t2 = explode( ' ', microtime() );
56 if ( $num === false ) {
57 print "FAILED: database error\n";
59 print "got $num rows in ";
61 $elapsed = ($t2[0] - $t1[0]) +
($t2[1] - $t1[1]);
62 $hours = intval( $elapsed / 3600 );
63 $minutes = intval( $elapsed %
3600 / 60 );
64 $seconds = $elapsed - $hours * 3600 - $minutes * 60;
69 print $minutes . 'm ';
71 printf( "%.2fs\n", $seconds );
74 # Reopen any connections that have closed
75 if ( !$wgLoadBalancer->pingAll()) {
78 print "Connection failed, reconnecting in 10 seconds...\n";
80 } while ( !$wgLoadBalancer->pingAll() );
81 print "Reconnected\n\n";
84 $dbw->immediateCommit();
87 # Wait for the slave to catch up
89 $slaveDB = wfGetDB( DB_SLAVE, array('QueryPage::recache', 'vslow' ) );
90 while( $slaveDB->getLag() > 600 ) {
91 print "Slave lagged, waiting...\n";
99 print "cheap, skipped\n";