* Adding a trailing ?>
[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 " --list : list special pages names\n";
15 print " --only=page : only update 'page'. Ex: --only=BrokenRedirects\n";
16 wfDie();
17 }
18
19 $wgOut->disable();
20 $dbw =& wfGetDB( DB_MASTER );
21
22 foreach ( $wgQueryPages as $page ) {
23 @list( $class, $special, $limit ) = $page;
24
25 # --list : just show the name of pages
26 if( @$options['list'] ) {
27 print "$special\n";
28 continue;
29 }
30
31 $specialObj = SpecialPage::getPage( $special );
32 if ( !$specialObj ) {
33 print "No such special page: $special\n";
34 exit;
35 }
36 $file = $specialObj->getFile();
37 if ( $file ) {
38 require_once( $file );
39 }
40 $queryPage = new $class;
41
42 if( !(isset($options['only'])) or ($options['only'] == $queryPage->getName()) ) {
43 printf( '%-30s', $special );
44
45 if ( $queryPage->isExpensive() ) {
46 $t1 = explode( ' ', microtime() );
47 # Do the query
48 $num = $queryPage->recache( $limit === null ? 1000 : $limit );
49 $t2 = explode( ' ', microtime() );
50
51 if ( $num === false ) {
52 print "FAILED: database error\n";
53 } else {
54 print "got $num rows in ";
55
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 ';
62 }
63 if ( $minutes ) {
64 print $minutes . 'm ';
65 }
66 printf( "%.2fs\n", $seconds );
67 }
68
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();
80 }
81
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);
87
88 }
89
90 } else {
91 print "cheap, skipped\n";
92 }
93 }
94 }
95
96 ?>