2012-05-07 16:28:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
$IP = getenv( 'MW_INSTALL_PATH' );
|
|
|
|
if ( $IP === false ) {
|
2015-11-11 17:33:46 +00:00
|
|
|
$IP = __DIR__ . '/../../..';
|
2012-05-07 16:28:18 +00:00
|
|
|
}
|
|
|
|
require_once( "$IP/maintenance/Maintenance.php" );
|
|
|
|
|
2015-11-16 14:59:34 +00:00
|
|
|
/**
|
|
|
|
* @license WTFPL 2.0
|
2015-11-17 08:54:24 +00:00
|
|
|
* @author Max Semenik
|
2015-11-16 14:59:34 +00:00
|
|
|
*/
|
2012-05-07 16:28:18 +00:00
|
|
|
class InitImageData extends Maintenance {
|
|
|
|
const BATCH_SIZE = 100;
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
parent::__construct();
|
|
|
|
$this->mDescription = 'Initializes PageImages data';
|
|
|
|
$this->addOption( 'namespaces', 'Comma-separated list of namespace(s) to refresh', false, true );
|
|
|
|
$this->addOption( 'earlier-than', 'Run only on pages earlier than this timestamp', false, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute() {
|
2012-12-17 19:22:13 +00:00
|
|
|
global $wgPageImagesNamespaces;
|
|
|
|
|
2012-05-07 16:28:18 +00:00
|
|
|
$id = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
$tables = array( 'page', 'imagelinks' );
|
|
|
|
$conds = array(
|
2015-03-24 19:56:26 +00:00
|
|
|
'page_id > ' . (int) $id,
|
2013-01-18 00:30:26 +00:00
|
|
|
'il_from IS NOT NULL',
|
|
|
|
'page_is_redirect' => 0,
|
2012-05-07 16:28:18 +00:00
|
|
|
);
|
|
|
|
$fields = array( 'page_id' );
|
|
|
|
$joinConds = array( 'imagelinks' => array(
|
|
|
|
'LEFT JOIN', 'page_id = il_from',
|
|
|
|
) );
|
|
|
|
|
2016-04-04 23:34:23 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2012-05-07 16:28:18 +00:00
|
|
|
if ( $this->hasOption( 'namespaces' ) ) {
|
|
|
|
$ns = explode( ',', $this->getOption( 'namespaces' ) );
|
|
|
|
$conds['page_namespace'] = $ns;
|
|
|
|
} else {
|
2012-12-17 19:22:13 +00:00
|
|
|
$conds['page_namespace'] = $wgPageImagesNamespaces;
|
2012-05-07 16:28:18 +00:00
|
|
|
}
|
|
|
|
if ( $this->hasOption( 'earlier-than' ) ) {
|
2016-04-04 23:34:23 +00:00
|
|
|
$conds[] = 'page_touched < '
|
|
|
|
. $dbr->addQuotes( $this->getOption( 'earlier-than' ) );
|
2012-05-07 16:28:18 +00:00
|
|
|
}
|
|
|
|
$res = $dbr->select( $tables, $fields, $conds, __METHOD__,
|
|
|
|
array( 'LIMIT' => self::BATCH_SIZE, 'ORDER_BY' => 'page_id', 'GROUP BY' => 'page_id' ),
|
|
|
|
$joinConds
|
|
|
|
);
|
|
|
|
foreach ( $res as $row ) {
|
|
|
|
$id = $row->page_id;
|
|
|
|
RefreshLinks::fixLinksFromArticle( $id );
|
2013-01-18 00:30:26 +00:00
|
|
|
wfWaitForSlaves();
|
2012-05-07 16:28:18 +00:00
|
|
|
}
|
|
|
|
$this->output( "$id\n" );
|
|
|
|
} while ( $res->numRows() );
|
|
|
|
$this->output( "done\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$maintClass = 'InitImageData';
|
|
|
|
require_once( DO_MAINTENANCE );
|