fix warbubg when the array is set to false
[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 if ( $wgDisableQueryPageUpdate && in_array( $special, $wgDisableQueryPageUpdate ) ) {
32 printf("%-30s disabled\n", $special);
33 continue;
34 }
35
36 $specialObj = SpecialPage::getPage( $special );
37 if ( !$specialObj ) {
38 print "No such special page: $special\n";
39 exit;
40 }
41 if ( !class_exists( $class ) ) {
42 $file = $specialObj->getFile();
43 require_once( $file );
44 }
45 $queryPage = new $class;
46
47 if( !(isset($options['only'])) or ($options['only'] == $queryPage->getName()) ) {
48 printf( '%-30s ', $special );
49
50 if ( $queryPage->isExpensive() ) {
51 $t1 = explode( ' ', microtime() );
52 # Do the query
53 $num = $queryPage->recache( $limit === null ? $wgQueryCacheLimit : $limit );
54 $t2 = explode( ' ', microtime() );
55
56 if ( $num === false ) {
57 print "FAILED: database error\n";
58 } else {
59 print "got $num rows in ";
60
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;
65 if ( $hours ) {
66 print $hours . 'h ';
67 }
68 if ( $minutes ) {
69 print $minutes . 'm ';
70 }
71 printf( "%.2fs\n", $seconds );
72 }
73
74 # Reopen any connections that have closed
75 if ( !$wgLoadBalancer->pingAll()) {
76 print "\n";
77 do {
78 print "Connection failed, reconnecting in 10 seconds...\n";
79 sleep(10);
80 } while ( !$wgLoadBalancer->pingAll() );
81 print "Reconnected\n\n";
82 } else {
83 # Commit the results
84 $dbw->immediateCommit();
85 }
86
87 # Wait for the slave to catch up
88 /*
89 $slaveDB =& wfGetDB( DB_SLAVE, array('QueryPage::recache', 'vslow' ) );
90 while( $slaveDB->getLag() > 600 ) {
91 print "Slave lagged, waiting...\n";
92 sleep(30);
93
94 }
95 */
96 wfWaitForSlaves( 5 );
97
98 } else {
99 print "cheap, skipped\n";
100 }
101 }
102 }
103
104 ?>