3 * Run this script periodically if you have miser mode enabled, to refresh the
10 require_once( "Maintenance.php" );
12 class UpdateSpecialPages
extends Maintenance
{
13 public function __construct() {
14 parent
::__construct();
15 $this->addParam( 'list', 'List special page names' );
16 $this->addParam( 'only', 'Only update "page". Ex: --only=BrokenRedirects', false, true );
17 $this->addParam( 'override', 'Also update pages that have updates disabled' );
20 public function execute() {
23 $dbw = wfGetDB( DB_MASTER
);
25 foreach( $wgSpecialPageCacheUpdates as $special => $call ) {
26 if( !is_callable($call) ) {
27 $this->error( "Uncallable function $call!\n" );
30 $t1 = explode( ' ', microtime() );
31 call_user_func( $call, $dbw );
32 $t2 = explode( ' ', microtime() );
33 $this->output( sprintf( '%-30s ', $special ) );
34 $elapsed = ($t2[0] - $t1[0]) +
($t2[1] - $t1[1]);
35 $hours = intval( $elapsed / 3600 );
36 $minutes = intval( $elapsed %
3600 / 60 );
37 $seconds = $elapsed - $hours * 3600 - $minutes * 60;
39 $this->output( $hours . 'h ' );
42 $this->output( $minutes . 'm ' );
44 $this->output( sprintf( "completed in %.2fs\n", $seconds ) );
45 # Wait for the slave to catch up
49 foreach( $wgQueryPages as $page ) {
50 @list
( $class, $special, $limit ) = $page;
52 # --list : just show the name of pages
53 if( $this->hasOption('list') ) {
54 $this->output( "$special\n" );
58 if ( $this->hasOption('override') && $wgDisableQueryPageUpdate && in_array( $special, $wgDisableQueryPageUpdate ) ) {
59 $this->output( sprintf( "%-30s disabled\n", $special ) );
63 $specialObj = SpecialPage
::getPage( $special );
65 $this->output( "No such special page: $special\n" );
68 if ( !class_exists( $class ) ) {
69 $file = $specialObj->getFile();
70 require_once( $file );
72 $queryPage = new $class;
74 if( !$this->hasOption('only') ||
$this->getOption('only') == $queryPage->getName() ) {
75 $this->output( sprintf( '%-30s ', $special ) );
76 if ( $queryPage->isExpensive() ) {
77 $t1 = explode( ' ', microtime() );
79 $num = $queryPage->recache( $limit === null ?
$wgQueryCacheLimit : $limit );
80 $t2 = explode( ' ', microtime() );
81 if ( $num === false ) {
82 $this->output( "FAILED: database error\n" );
84 $this->output( "got $num rows in " );
86 $elapsed = ($t2[0] - $t1[0]) +
($t2[1] - $t1[1]);
87 $hours = intval( $elapsed / 3600 );
88 $minutes = intval( $elapsed %
3600 / 60 );
89 $seconds = $elapsed - $hours * 3600 - $minutes * 60;
91 $this->output( $hours . 'h ' );
94 $this->output( $minutes . 'm ' );
96 $this->output( sprintf( "%.2fs\n", $seconds ) );
98 # Reopen any connections that have closed
99 if ( !wfGetLB()->pingAll()) {
100 $this->output( "\n" );
102 $this->error( "Connection failed, reconnecting in 10 seconds...\n" );
104 } while ( !wfGetLB()->pingAll() );
105 $this->output( "Reconnected\n\n" );
108 $dbw->immediateCommit();
110 # Wait for the slave to catch up
111 wfWaitForSlaves( 5 );
113 $this->output( "cheap, skipped\n" );