3 * Update for cached special pages.
4 * Run this script periodically if you have miser mode enabled.
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
22 * @ingroup Maintenance
25 require_once( __DIR__
. '/Maintenance.php' );
28 * Maintenance script to update cached special pages.
30 * @ingroup Maintenance
32 class UpdateSpecialPages
extends Maintenance
{
33 public function __construct() {
34 parent
::__construct();
35 $this->addOption( 'list', 'List special page names' );
36 $this->addOption( 'only', 'Only update "page". Ex: --only=BrokenRedirects', false, true );
37 $this->addOption( 'override', 'Also update pages that have updates disabled' );
40 public function execute() {
41 global $IP, $wgSpecialPageCacheUpdates, $wgQueryPages, $wgQueryCacheLimit, $wgDisableQueryPageUpdate;
43 $dbw = wfGetDB( DB_MASTER
);
45 foreach ( $wgSpecialPageCacheUpdates as $special => $call ) {
46 if ( !is_callable( $call ) ) {
47 $this->error( "Uncallable function $call!" );
50 $this->output( sprintf( '%-30s ', $special ) );
51 $t1 = explode( ' ', microtime() );
52 call_user_func( $call, $dbw );
53 $t2 = explode( ' ', microtime() );
54 $elapsed = ( $t2[0] - $t1[0] ) +
( $t2[1] - $t1[1] );
55 $hours = intval( $elapsed / 3600 );
56 $minutes = intval( $elapsed %
3600 / 60 );
57 $seconds = $elapsed - $hours * 3600 - $minutes * 60;
59 $this->output( $hours . 'h ' );
62 $this->output( $minutes . 'm ' );
64 $this->output( sprintf( "completed in %.2fs\n", $seconds ) );
65 # Wait for the slave to catch up
69 // This is needed to initialise $wgQueryPages
70 require_once( "$IP/includes/QueryPage.php" );
72 foreach ( $wgQueryPages as $page ) {
73 list( $class, $special ) = $page;
74 $limit = isset( $page[2] ) ?
$page[2] : null;
76 # --list : just show the name of pages
77 if ( $this->hasOption( 'list' ) ) {
78 $this->output( "$special\n" );
82 if ( !$this->hasOption( 'override' ) && $wgDisableQueryPageUpdate && in_array( $special, $wgDisableQueryPageUpdate ) ) {
83 $this->output( sprintf( "%-30s disabled\n", $special ) );
87 $specialObj = SpecialPageFactory
::getPage( $special );
89 $this->output( "No such special page: $special\n" );
92 if ( $specialObj instanceof QueryPage
) {
93 $queryPage = $specialObj;
95 if ( !class_exists( $class ) ) {
96 $file = $specialObj->getFile();
97 require_once( $file );
99 $queryPage = new $class;
102 if ( !$this->hasOption( 'only' ) ||
$this->getOption( 'only' ) == $queryPage->getName() ) {
103 $this->output( sprintf( '%-30s ', $special ) );
104 if ( $queryPage->isExpensive() ) {
105 $t1 = explode( ' ', microtime() );
107 $num = $queryPage->recache( $limit === null ?
$wgQueryCacheLimit : $limit );
108 $t2 = explode( ' ', microtime() );
109 if ( $num === false ) {
110 $this->output( "FAILED: database error\n" );
112 $this->output( "got $num rows in " );
114 $elapsed = ( $t2[0] - $t1[0] ) +
( $t2[1] - $t1[1] );
115 $hours = intval( $elapsed / 3600 );
116 $minutes = intval( $elapsed %
3600 / 60 );
117 $seconds = $elapsed - $hours * 3600 - $minutes * 60;
119 $this->output( $hours . 'h ' );
122 $this->output( $minutes . 'm ' );
124 $this->output( sprintf( "%.2fs\n", $seconds ) );
126 # Reopen any connections that have closed
127 if ( !wfGetLB()->pingAll() ) {
128 $this->output( "\n" );
130 $this->error( "Connection failed, reconnecting in 10 seconds..." );
132 } while ( !wfGetLB()->pingAll() );
133 $this->output( "Reconnected\n\n" );
136 $dbw->commit( __METHOD__
);
138 # Wait for the slave to catch up
141 $this->output( "cheap, skipped\n" );
148 $maintClass = "UpdateSpecialPages";
149 require_once( RUN_MAINTENANCE_IF_MAIN
);