ff9a618dcfbba9979b1a766ef8b7d05c29882a56
3 * Run this script periodically if you have miser mode enabled, to refresh the
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup Maintenance
24 require_once( dirname(__FILE__
) . '/Maintenance.php' );
26 class UpdateSpecialPages
extends Maintenance
{
27 public function __construct() {
28 parent
::__construct();
29 $this->addOption( 'list', 'List special page names' );
30 $this->addOption( 'only', 'Only update "page". Ex: --only=BrokenRedirects', false, true );
31 $this->addOption( 'override', 'Also update pages that have updates disabled' );
34 public function execute() {
35 global $wgOut, $wgSpecialPageCacheUpdates, $wgQueryPages;
37 $dbw = wfGetDB( DB_MASTER
);
39 foreach( $wgSpecialPageCacheUpdates as $special => $call ) {
40 if( !is_callable($call) ) {
41 $this->error( "Uncallable function $call!" );
44 $t1 = explode( ' ', microtime() );
45 call_user_func( $call, $dbw );
46 $t2 = explode( ' ', microtime() );
47 $this->output( sprintf( '%-30s ', $special ) );
48 $elapsed = ($t2[0] - $t1[0]) +
($t2[1] - $t1[1]);
49 $hours = intval( $elapsed / 3600 );
50 $minutes = intval( $elapsed %
3600 / 60 );
51 $seconds = $elapsed - $hours * 3600 - $minutes * 60;
53 $this->output( $hours . 'h ' );
56 $this->output( $minutes . 'm ' );
58 $this->output( sprintf( "completed in %.2fs\n", $seconds ) );
59 # Wait for the slave to catch up
63 foreach( $wgQueryPages as $page ) {
64 @list
( $class, $special, $limit ) = $page;
66 # --list : just show the name of pages
67 if( $this->hasOption('list') ) {
68 $this->output( "$special\n" );
72 if ( $this->hasOption('override') && $wgDisableQueryPageUpdate && in_array( $special, $wgDisableQueryPageUpdate ) ) {
73 $this->output( sprintf( "%-30s disabled\n", $special ) );
77 $specialObj = SpecialPage
::getPage( $special );
79 $this->output( "No such special page: $special\n" );
82 if ( !class_exists( $class ) ) {
83 $file = $specialObj->getFile();
84 require_once( $file );
86 $queryPage = new $class;
88 if( !$this->hasOption('only') ||
$this->getOption('only') == $queryPage->getName() ) {
89 $this->output( sprintf( '%-30s ', $special ) );
90 if ( $queryPage->isExpensive() ) {
91 $t1 = explode( ' ', microtime() );
93 $num = $queryPage->recache( $limit === null ?
$wgQueryCacheLimit : $limit );
94 $t2 = explode( ' ', microtime() );
95 if ( $num === false ) {
96 $this->output( "FAILED: database error\n" );
98 $this->output( "got $num rows in " );
100 $elapsed = ($t2[0] - $t1[0]) +
($t2[1] - $t1[1]);
101 $hours = intval( $elapsed / 3600 );
102 $minutes = intval( $elapsed %
3600 / 60 );
103 $seconds = $elapsed - $hours * 3600 - $minutes * 60;
105 $this->output( $hours . 'h ' );
108 $this->output( $minutes . 'm ' );
110 $this->output( sprintf( "%.2fs\n", $seconds ) );
112 # Reopen any connections that have closed
113 if ( !wfGetLB()->pingAll()) {
114 $this->output( "\n" );
116 $this->error( "Connection failed, reconnecting in 10 seconds..." );
118 } while ( !wfGetLB()->pingAll() );
119 $this->output( "Reconnected\n\n" );
122 $dbw->immediateCommit();
124 # Wait for the slave to catch up
125 wfWaitForSlaves( 5 );
127 $this->output( "cheap, skipped\n" );
134 $maintClass = "UpdateSpecialPages";
135 require_once( DO_MAINTENANCE
);