Fix regression probably from r50975 - link was not parsed
[lhc/web/wiklou.git] / maintenance / updateSpecialPages.php
1 <?php
2 /**
3 * Run this script periodically if you have miser mode enabled, to refresh the
4 * caches
5 *
6 * @file
7 * @ingroup Maintenance
8 */
9 $options = array('only','help');
10
11 require_once( 'commandLine.inc' );
12
13 require_once( "$IP/includes/SpecialPage.php" );
14 require_once( "$IP/includes/QueryPage.php" );
15
16 if(@$options['help']) {
17 print "usage:updateSpecialPages.php [--help] [--only=page]\n";
18 print " --help : this help message\n";
19 print " --list : list special pages names\n";
20 print " --only=page : only update 'page'. Ex: --only=BrokenRedirects\n";
21 print " --override : update even pages which have had updates disabled\n";
22 wfDie();
23 }
24
25 $wgOut->disable();
26 $dbw = wfGetDB( DB_MASTER );
27
28 foreach( $wgSpecialPageCacheUpdates as $special => $call ) {
29 if( !is_callable($call) ) {
30 print "Uncallable function $call!\n";
31 continue;
32 }
33 $t1 = explode( ' ', microtime() );
34 call_user_func( $call, $dbw );
35 $t2 = explode( ' ', microtime() );
36 printf( '%-30s ', $special );
37 $elapsed = ($t2[0] - $t1[0]) + ($t2[1] - $t1[1]);
38 $hours = intval( $elapsed / 3600 );
39 $minutes = intval( $elapsed % 3600 / 60 );
40 $seconds = $elapsed - $hours * 3600 - $minutes * 60;
41 if ( $hours ) {
42 print $hours . 'h ';
43 }
44 if ( $minutes ) {
45 print $minutes . 'm ';
46 }
47 printf( "completed in %.2fs\n", $seconds );
48 # Wait for the slave to catch up
49 wfWaitForSlaves( 5 );
50 }
51
52 foreach( $wgQueryPages as $page ) {
53 @list( $class, $special, $limit ) = $page;
54
55 # --list : just show the name of pages
56 if( @$options['list'] ) {
57 print "$special\n";
58 continue;
59 }
60
61 if ( !isset( $options['override'] ) && $wgDisableQueryPageUpdate && in_array( $special, $wgDisableQueryPageUpdate ) ) {
62 printf("%-30s disabled\n", $special);
63 continue;
64 }
65
66 $specialObj = SpecialPage::getPage( $special );
67 if ( !$specialObj ) {
68 print "No such special page: $special\n";
69 exit;
70 }
71 if ( !class_exists( $class ) ) {
72 $file = $specialObj->getFile();
73 require_once( $file );
74 }
75 $queryPage = new $class;
76
77 if( !isset($options['only']) or $options['only'] == $queryPage->getName() ) {
78 printf( '%-30s ', $special );
79 if ( $queryPage->isExpensive() ) {
80 $t1 = explode( ' ', microtime() );
81 # Do the query
82 $num = $queryPage->recache( $limit === null ? $wgQueryCacheLimit : $limit );
83 $t2 = explode( ' ', microtime() );
84 if ( $num === false ) {
85 print "FAILED: database error\n";
86 } else {
87 print "got $num rows in ";
88
89 $elapsed = ($t2[0] - $t1[0]) + ($t2[1] - $t1[1]);
90 $hours = intval( $elapsed / 3600 );
91 $minutes = intval( $elapsed % 3600 / 60 );
92 $seconds = $elapsed - $hours * 3600 - $minutes * 60;
93 if ( $hours ) {
94 print $hours . 'h ';
95 }
96 if ( $minutes ) {
97 print $minutes . 'm ';
98 }
99 printf( "%.2fs\n", $seconds );
100 }
101 # Reopen any connections that have closed
102 if ( !wfGetLB()->pingAll()) {
103 print "\n";
104 do {
105 print "Connection failed, reconnecting in 10 seconds...\n";
106 sleep(10);
107 } while ( !wfGetLB()->pingAll() );
108 print "Reconnected\n\n";
109 } else {
110 # Commit the results
111 $dbw->immediateCommit();
112 }
113 # Wait for the slave to catch up
114 wfWaitForSlaves( 5 );
115 } else {
116 print "cheap, skipped\n";
117 }
118 }
119 }