* Use double quoted consistently on attributes in linker output; preparing for new...
[mediawiki.git] / maintenance / updateSpecialPages.php
blob71c688fc397de3311fad482a486b863ad1078382
1 <?php
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";
16 wfDie();
19 $wgOut->disable();
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'] ) {
27 print "$special\n";
28 continue;
31 $specialObj = SpecialPage::getPage( $special );
32 if ( !$specialObj ) {
33 print "No such special page: $special\n";
34 exit;
36 $file = $specialObj->getFile();
37 if ( $file ) {
38 require_once( $file );
40 $queryPage = new $class;
42 if( !(isset($options['only'])) or ($options['only'] == $queryPage->getName()) ) {
43 printf( '%-30s', $special );
45 if ( $queryPage->isExpensive() ) {
46 $t1 = explode( ' ', microtime() );
47 # Do the query
48 $num = $queryPage->recache( $limit === null ? 1000 : $limit );
49 $t2 = explode( ' ', microtime() );
51 if ( $num === false ) {
52 print "FAILED: database error\n";
53 } else {
54 print "got $num rows in ";
56 $elapsed = ($t2[0] - $t1[0]) + ($t2[1] - $t1[1]);
57 $hours = intval( $elapsed / 3600 );
58 $minutes = intval( $elapsed % 3600 / 60 );
59 $seconds = $elapsed - $hours * 3600 - $minutes * 60;
60 if ( $hours ) {
61 print $hours . 'h ';
63 if ( $minutes ) {
64 print $minutes . 'm ';
66 printf( "%.2fs\n", $seconds );
69 # Reopen any connections that have closed
70 if ( !$wgLoadBalancer->pingAll()) {
71 print "\n";
72 do {
73 print "Connection failed, reconnecting in 10 seconds...\n";
74 sleep(10);
75 } while ( !$wgLoadBalancer->pingAll() );
76 print "Reconnected\n\n";
77 } else {
78 # Commit the results
79 $dbw->immediateCommit();
82 # Wait for the slave to catch up
83 $slaveDB =& wfGetDB( DB_SLAVE, array('QueryPage::recache', 'vslow' ) );
84 while( $slaveDB->getLag() > 600 ) {
85 print "Slave lagged, waiting...\n";
86 sleep(30);
90 } else {
91 print "cheap, skipped\n";