add --help --only=Apage
[lhc/web/wiklou.git] / maintenance / updateSpecialPages.php
1 <?php
2
3 # Run this script periodically if you have miser mode enabled, to refresh the caches
4 $options = array('only','help');
5
6 require_once( 'commandLine.inc' );
7
8 require_once( 'SpecialPage.php' );
9 require_once( 'QueryPage.php' );
10
11 if($options['help']) {
12 print "usage:updateSpecialPages.php [--help] [--only=page]\n";
13 print " --help : this help message\n";
14 print " --only=page : only update 'page'. Ex: --only=BrokenRedirects\n";
15 die();
16 }
17
18 $wgOut->disable();
19 $dbw =& wfGetDB( DB_MASTER );
20
21 foreach ( $wgQueryPages as $page ) {
22 list( $class, $special ) = $page;
23
24 $specialObj = SpecialPage::getPage( $special );
25 if ( !$specialObj ) {
26 print "No such special page: $special\n";
27 exit;
28 }
29 $file = $specialObj->getFile();
30 if ( $file ) {
31 require_once( $file );
32 }
33 $queryPage = new $class;
34
35 if( !(isset($options['only'])) or ($options['only'] == $queryPage->getName()) ) {
36 printf( '%-30s', $special );
37
38 if ( $queryPage->isExpensive() ) {
39 $t1 = explode( ' ', microtime() );
40 # Do the query
41 $num = $queryPage->recache();
42 $t2 = explode( ' ', microtime() );
43
44 if ( $num === false ) {
45 print "FAILED: database error\n";
46 } else {
47 print "got $num rows in ";
48
49 $elapsed = ($t2[0] - $t1[0]) + ($t2[1] - $t1[1]);
50 $hours = intval( $elapsed / 3600 );
51 $minutes = intval( $elapsed % 3600 / 60 );
52 $seconds = $elapsed - $hours * 3600 - $minutes * 60;
53 if ( $hours ) {
54 print $hours . 'h ';
55 }
56 if ( $minutes ) {
57 print $minutes . 'm ';
58 }
59 printf( "%.2fs\n", $seconds );
60 }
61
62 # Reopen any connections that have closed
63 if ( !$wgLoadBalancer->pingAll()) {
64 print "\n";
65 do {
66 print "Connection failed, reconnecting in 10 seconds...\n";
67 sleep(10);
68 } while ( !$wgLoadBalancer->pingAll() );
69 print "Reconnected\n\n";
70 } else {
71 # Commit the results
72 $dbw->immediateCommit();
73 }
74
75 # Wait for the slave to catch up
76 $slaveDB =& wfGetDB( DB_SLAVE, array('QueryPage::recache', 'vslow' ) );
77 while( $slaveDB->getLag() > 600 ) {
78 print "Slave lagged, waiting...\n";
79 sleep(30);
80
81 }
82
83 } else {
84 print "cheap, skipped\n";
85 }
86 }
87 }
88
89 ?>