2005-04-24 04:16:50 +00:00
|
|
|
<?php
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
/**
|
2012-09-03 18:10:09 +00:00
|
|
|
* Update for cached special pages.
|
|
|
|
|
* Run this script periodically if you have miser mode enabled.
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
*
|
2009-08-02 19:35:17 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2010-09-01 19:36:18 +00:00
|
|
|
* @file
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2009-06-24 02:49:24 +00:00
|
|
|
|
2022-04-27 15:42:24 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2023-09-15 09:32:18 +00:00
|
|
|
use MediaWiki\SpecialPage\QueryPage;
|
2018-05-02 20:12:12 +00:00
|
|
|
|
2012-09-03 18:10:09 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script to update cached special pages.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2009-08-02 19:35:17 +00:00
|
|
|
class UpdateSpecialPages extends Maintenance {
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
|
|
|
|
$this->addOption( 'list', 'List special page names' );
|
2013-08-15 21:47:33 +00:00
|
|
|
$this->addOption( 'only', 'Only update "page"; case sensitive, ' .
|
2014-06-03 03:02:29 +00:00
|
|
|
'check correct case by calling this script with --list. ' .
|
|
|
|
|
'Ex: --only=BrokenRedirects', false, true );
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->addOption( 'override', 'Also update pages that have updates disabled' );
|
2009-06-24 02:49:24 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
public function execute() {
|
2024-01-17 18:53:40 +00:00
|
|
|
$dbw = $this->getPrimaryDB();
|
2021-09-20 20:50:55 +00:00
|
|
|
$config = $this->getConfig();
|
2023-08-31 09:21:12 +00:00
|
|
|
$specialPageFactory = $this->getServiceContainer()->getSpecialPageFactory();
|
2009-08-02 19:49:24 +00:00
|
|
|
|
2014-01-30 17:47:21 +00:00
|
|
|
$this->doSpecialPageCacheUpdates( $dbw );
|
|
|
|
|
|
2022-04-27 15:42:24 +00:00
|
|
|
$queryCacheLimit = (int)$config->get( MainConfigNames::QueryCacheLimit );
|
2021-09-20 20:50:55 +00:00
|
|
|
$disabledQueryPages = QueryPage::getDisabledQueryPages( $config );
|
2014-02-04 19:50:11 +00:00
|
|
|
foreach ( QueryPage::getPages() as $page ) {
|
2019-02-28 11:04:31 +00:00
|
|
|
[ , $special ] = $page;
|
2021-09-20 20:50:55 +00:00
|
|
|
$limit = $page[2] ?? $queryCacheLimit;
|
2009-11-23 18:20:26 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
# --list : just show the name of pages
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( $this->hasOption( 'list' ) ) {
|
2014-01-30 17:47:21 +00:00
|
|
|
$this->output( "$special [QueryPage]\n" );
|
2009-08-02 19:35:17 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2009-11-23 18:20:26 +00:00
|
|
|
|
2014-01-30 17:47:21 +00:00
|
|
|
if ( !$this->hasOption( 'override' )
|
2019-08-19 14:49:43 +00:00
|
|
|
&& isset( $disabledQueryPages[$special] )
|
2014-04-23 18:09:26 +00:00
|
|
|
) {
|
2014-01-30 17:47:21 +00:00
|
|
|
$this->output( sprintf( "%-30s [QueryPage] disabled\n", $special ) );
|
2009-08-02 19:35:17 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2009-11-23 18:20:26 +00:00
|
|
|
|
2021-09-20 20:50:55 +00:00
|
|
|
$specialObj = $specialPageFactory->getPage( $special );
|
2009-08-02 19:35:17 +00:00
|
|
|
if ( !$specialObj ) {
|
|
|
|
|
$this->output( "No such special page: $special\n" );
|
2021-08-30 18:54:47 +00:00
|
|
|
return;
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2010-12-22 15:24:13 +00:00
|
|
|
if ( $specialObj instanceof QueryPage ) {
|
|
|
|
|
$queryPage = $specialObj;
|
|
|
|
|
} else {
|
2015-10-27 16:05:36 +00:00
|
|
|
$class = get_class( $specialObj );
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "$class is not an instance of QueryPage.\n" );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2009-11-23 18:20:26 +00:00
|
|
|
|
2021-09-20 20:50:55 +00:00
|
|
|
if ( !$this->hasOption( 'only' ) || $this->getOption( 'only' ) === $queryPage->getName() ) {
|
2014-01-30 17:47:21 +00:00
|
|
|
$this->output( sprintf( '%-30s [QueryPage] ', $special ) );
|
2009-08-02 19:35:17 +00:00
|
|
|
if ( $queryPage->isExpensive() ) {
|
2014-10-20 17:29:31 +00:00
|
|
|
$t1 = microtime( true );
|
2009-08-02 19:35:17 +00:00
|
|
|
# Do the query
|
2021-09-20 20:50:55 +00:00
|
|
|
$num = $queryPage->recache( $limit );
|
2014-10-20 17:29:31 +00:00
|
|
|
$t2 = microtime( true );
|
2009-08-02 19:35:17 +00:00
|
|
|
if ( $num === false ) {
|
|
|
|
|
$this->output( "FAILED: database error\n" );
|
|
|
|
|
} else {
|
|
|
|
|
$this->output( "got $num rows in " );
|
2009-11-23 18:20:26 +00:00
|
|
|
|
2014-10-20 17:29:31 +00:00
|
|
|
$elapsed = $t2 - $t1;
|
2009-08-02 19:35:17 +00:00
|
|
|
$hours = intval( $elapsed / 3600 );
|
2023-09-20 20:04:46 +00:00
|
|
|
$minutes = intval( (int)$elapsed % 3600 / 60 );
|
2009-08-02 19:35:17 +00:00
|
|
|
$seconds = $elapsed - $hours * 3600 - $minutes * 60;
|
|
|
|
|
if ( $hours ) {
|
|
|
|
|
$this->output( $hours . 'h ' );
|
|
|
|
|
}
|
|
|
|
|
if ( $minutes ) {
|
|
|
|
|
$this->output( $minutes . 'm ' );
|
|
|
|
|
}
|
|
|
|
|
$this->output( sprintf( "%.2fs\n", $seconds ) );
|
2009-08-07 14:05:26 +00:00
|
|
|
}
|
|
|
|
|
# Reopen any connections that have closed
|
2017-09-28 21:35:44 +00:00
|
|
|
$this->reopenAndWaitForReplicas();
|
2009-08-02 19:35:17 +00:00
|
|
|
} else {
|
2021-03-10 19:26:38 +00:00
|
|
|
// Check if this page was expensive before and now cheap
|
|
|
|
|
$cached = $queryPage->getCachedTimestamp();
|
|
|
|
|
if ( $cached ) {
|
|
|
|
|
$queryPage->deleteAllCachedData();
|
|
|
|
|
$this->reopenAndWaitForReplicas();
|
|
|
|
|
$this->output( "cheap, but deleted cached data\n" );
|
|
|
|
|
} else {
|
|
|
|
|
$this->output( "cheap, skipped\n" );
|
|
|
|
|
}
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2013-08-15 22:19:02 +00:00
|
|
|
if ( $this->hasOption( 'only' ) ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2008-08-31 19:29:37 +00:00
|
|
|
}
|
2005-07-10 18:23:06 +00:00
|
|
|
}
|
2013-08-15 22:02:21 +00:00
|
|
|
|
2017-09-26 21:51:31 +00:00
|
|
|
/**
|
|
|
|
|
* Re-open any closed db connection, and wait for replicas
|
|
|
|
|
*
|
|
|
|
|
* Queries that take a really long time, might cause the
|
|
|
|
|
* mysql connection to "go away"
|
|
|
|
|
*/
|
2017-09-28 21:35:44 +00:00
|
|
|
private function reopenAndWaitForReplicas() {
|
2023-08-31 09:21:12 +00:00
|
|
|
$lbFactory = $this->getServiceContainer()->getDBLoadBalancerFactory();
|
2018-05-02 20:12:12 +00:00
|
|
|
$lb = $lbFactory->getMainLB();
|
|
|
|
|
if ( !$lb->pingAll() ) {
|
2017-09-26 21:51:31 +00:00
|
|
|
$this->output( "\n" );
|
|
|
|
|
do {
|
|
|
|
|
$this->error( "Connection failed, reconnecting in 10 seconds..." );
|
|
|
|
|
sleep( 10 );
|
2023-10-09 10:29:07 +00:00
|
|
|
$this->waitForReplication();
|
2018-05-02 20:12:12 +00:00
|
|
|
} while ( !$lb->pingAll() );
|
2017-09-26 21:51:31 +00:00
|
|
|
$this->output( "Reconnected\n\n" );
|
|
|
|
|
}
|
2022-10-24 18:31:49 +00:00
|
|
|
$this->waitForReplication();
|
2017-09-26 21:51:31 +00:00
|
|
|
}
|
|
|
|
|
|
2014-01-30 17:47:21 +00:00
|
|
|
public function doSpecialPageCacheUpdates( $dbw ) {
|
2022-04-27 15:42:24 +00:00
|
|
|
foreach ( $this->getConfig()->get( MainConfigNames::SpecialPageCacheUpdates ) as $special => $call ) {
|
2014-01-30 17:47:21 +00:00
|
|
|
# --list : just show the name of pages
|
|
|
|
|
if ( $this->hasOption( 'list' ) ) {
|
|
|
|
|
$this->output( "$special [callback]\n" );
|
2013-08-15 22:02:21 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2014-01-30 17:47:21 +00:00
|
|
|
|
2021-09-20 20:50:55 +00:00
|
|
|
if ( !$this->hasOption( 'only' ) || $this->getOption( 'only' ) === $special ) {
|
2014-01-30 17:47:21 +00:00
|
|
|
if ( !is_callable( $call ) ) {
|
|
|
|
|
$this->error( "Uncallable function $call!" );
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$this->output( sprintf( '%-30s [callback] ', $special ) );
|
2014-10-20 17:29:31 +00:00
|
|
|
$t1 = microtime( true );
|
2021-09-20 20:50:55 +00:00
|
|
|
$call( $dbw );
|
2014-10-20 17:29:31 +00:00
|
|
|
$t2 = microtime( true );
|
2014-01-30 17:47:21 +00:00
|
|
|
|
|
|
|
|
$this->output( "completed in " );
|
2014-10-20 17:29:31 +00:00
|
|
|
$elapsed = $t2 - $t1;
|
2014-01-30 17:47:21 +00:00
|
|
|
$hours = intval( $elapsed / 3600 );
|
2023-09-20 20:04:46 +00:00
|
|
|
$minutes = intval( (int)$elapsed % 3600 / 60 );
|
2014-01-30 17:47:21 +00:00
|
|
|
$seconds = $elapsed - $hours * 3600 - $minutes * 60;
|
|
|
|
|
if ( $hours ) {
|
|
|
|
|
$this->output( $hours . 'h ' );
|
|
|
|
|
}
|
|
|
|
|
if ( $minutes ) {
|
|
|
|
|
$this->output( $minutes . 'm ' );
|
|
|
|
|
}
|
|
|
|
|
$this->output( sprintf( "%.2fs\n", $seconds ) );
|
2016-09-05 20:14:41 +00:00
|
|
|
# Wait for the replica DB to catch up
|
2017-09-26 21:51:31 +00:00
|
|
|
$this->reopenAndWaitForReplicas();
|
2013-08-15 22:02:21 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-04-24 04:16:50 +00:00
|
|
|
}
|
2009-08-02 19:35:17 +00:00
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = UpdateSpecialPages::class;
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|