Fix for r47482: put the RELEASE-NOTES entry in the "bug fixes" section and not the...
[mediawiki.git] / maintenance / updateSpecialPages.php
blob3eaa62056b0234d35324103a3bcfd367b37a85c2
1 <?php
2 /**
3 * Run this script periodically if you have miser mode enabled, to refresh the
4 * caches
6 * @file
7 * @ingroup Maintenance
8 */
9 $options = array('only','help');
11 require_once( 'commandLine.inc' );
13 require_once( "$IP/includes/SpecialPage.php" );
14 require_once( "$IP/includes/QueryPage.php" );
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();
25 $wgOut->disable();
26 $dbw = wfGetDB( DB_MASTER );
28 foreach( $wgSpecialPageCacheUpdates as $special => $call ) {
29 if( !is_callable($call) ) {
30 print "Uncallable function $call!\n";
31 continue;
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 ';
44 if ( $minutes ) {
45 print $minutes . 'm ';
47 printf( "completed in %.2fs\n", $seconds );
48 # Wait for the slave to catch up
49 wfWaitForSlaves( 5 );
52 foreach( $wgQueryPages as $page ) {
53 @list( $class, $special, $limit ) = $page;
55 # --list : just show the name of pages
56 if( @$options['list'] ) {
57 print "$special\n";
58 continue;
61 if ( !isset( $options['override'] ) && $wgDisableQueryPageUpdate && in_array( $special, $wgDisableQueryPageUpdate ) ) {
62 printf("%-30s disabled\n", $special);
63 continue;
66 $specialObj = SpecialPage::getPage( $special );
67 if ( !$specialObj ) {
68 print "No such special page: $special\n";
69 exit;
71 if ( !class_exists( $class ) ) {
72 $file = $specialObj->getFile();
73 require_once( $file );
75 $queryPage = new $class;
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 ";
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 ';
96 if ( $minutes ) {
97 print $minutes . 'm ';
99 printf( "%.2fs\n", $seconds );
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();
113 # Wait for the slave to catch up
114 wfWaitForSlaves( 5 );
115 } else {
116 print "cheap, skipped\n";