Fix description
[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( "$IP/includes/SpecialPage.php" );
9 require_once( "$IP/includes/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 print " --override : update even pages which have had updates disabled\n";
17 wfDie();
18 }
19
20 $wgOut->disable();
21 $dbw = wfGetDB( DB_MASTER );
22
23 foreach ( $wgQueryPages as $page ) {
24 @list( $class, $special, $limit ) = $page;
25
26 # --list : just show the name of pages
27 if( @$options['list'] ) {
28 print "$special\n";
29 continue;
30 }
31
32 if ( !isset( $options['override'] ) && $wgDisableQueryPageUpdate && in_array( $special, $wgDisableQueryPageUpdate ) ) {
33 printf("%-30s disabled\n", $special);
34 continue;
35 }
36
37 $specialObj = SpecialPage::getPage( $special );
38 if ( !$specialObj ) {
39 print "No such special page: $special\n";
40 exit;
41 }
42 if ( !class_exists( $class ) ) {
43 $file = $specialObj->getFile();
44 require_once( $file );
45 }
46 $queryPage = new $class;
47
48 if( !(isset($options['only'])) or ($options['only'] == $queryPage->getName()) ) {
49 printf( '%-30s ', $special );
50
51 if ( $queryPage->isExpensive() ) {
52 $t1 = explode( ' ', microtime() );
53 # Do the query
54 $num = $queryPage->recache( $limit === null ? $wgQueryCacheLimit : $limit );
55 $t2 = explode( ' ', microtime() );
56
57 if ( $num === false ) {
58 print "FAILED: database error\n";
59 } else {
60 print "got $num rows in ";
61
62 $elapsed = ($t2[0] - $t1[0]) + ($t2[1] - $t1[1]);
63 $hours = intval( $elapsed / 3600 );
64 $minutes = intval( $elapsed % 3600 / 60 );
65 $seconds = $elapsed - $hours * 3600 - $minutes * 60;
66 if ( $hours ) {
67 print $hours . 'h ';
68 }
69 if ( $minutes ) {
70 print $minutes . 'm ';
71 }
72 printf( "%.2fs\n", $seconds );
73 }
74
75 # Reopen any connections that have closed
76 if ( !wfGetLB()->pingAll()) {
77 print "\n";
78 do {
79 print "Connection failed, reconnecting in 10 seconds...\n";
80 sleep(10);
81 } while ( !wfGetLB()->pingAll() );
82 print "Reconnected\n\n";
83 } else {
84 # Commit the results
85 $dbw->immediateCommit();
86 }
87
88 # Wait for the slave to catch up
89 /*
90 $slaveDB = wfGetDB( DB_SLAVE, array('QueryPage::recache', 'vslow' ) );
91 while( $slaveDB->getLag() > 600 ) {
92 print "Slave lagged, waiting...\n";
93 sleep(30);
94
95 }
96 */
97 wfWaitForSlaves( 5 );
98
99 } else {
100 print "cheap, skipped\n";
101 }
102 }
103 }
104
105