27require_once __DIR__ .
'/Maintenance.php';
41 parent::__construct();
43 $this->
addOption(
'dfn-only',
'Delete links from nonexistent articles only' );
44 $this->
addOption(
'new-only',
'Only affect articles with just a single edit' );
45 $this->
addOption(
'redirects-only',
'Only fix redirects, not all links' );
46 $this->
addOption(
'old-redirects-only',
'Only fix redirects with no redirect table entry' );
47 $this->
addOption(
'e',
'Last page id to refresh',
false,
true );
48 $this->
addOption(
'dfn-chunk-size',
'Maximum number of existent IDs to check per ' .
49 'query, default 100000',
false,
true );
50 $this->
addOption(
'namespace',
'Only fix pages in this namespace',
false,
true );
51 $this->
addOption(
'category',
'Only fix pages in this category',
false,
true );
52 $this->
addOption(
'tracking-category',
'Only fix pages in this tracking category',
false,
true );
53 $this->
addArg(
'start',
'Page_id to start from, default 1',
false );
62 $start = (int)$this->
getArg( 0 ) ?:
null;
63 $end = (int)$this->
getOption(
'e' ) ?:
null;
64 $dfnChunkSize = (int)$this->
getOption(
'dfn-chunk-size', 100000 );
67 $this->
namespace =
false;
69 $this->
namespace = (int)$ns;
71 if ( ( $category = $this->
getOption(
'category',
false ) ) !==
false ) {
74 $this->
fatalError(
"'$category' is an invalid category name!\n" );
77 } elseif ( ( $category = $this->
getOption(
'tracking-category',
false ) ) !==
false ) {
79 } elseif ( !$this->
hasOption(
'dfn-only' ) ) {
81 $redir = $this->
hasOption(
'redirects-only' );
82 $oldRedir = $this->
hasOption(
'old-redirects-only' );
91 return $this->
namespace !==
false
105 $end =
null, $redirectsOnly =
false, $oldRedirectsOnly =
false
109 if ( $start ===
null ) {
114 Hooks::run(
'MaintenanceRefreshLinksInit', [ $this ] );
116 $what = $redirectsOnly ?
"redirects" :
"links";
118 if ( $oldRedirectsOnly ) {
119 # This entire code path is cut-and-pasted from below. Hurrah.
122 "page_is_redirect=1",
128 [
'page',
'redirect' ],
133 [
'redirect' => [
"LEFT JOIN",
"page_id=rd_from" ] ]
135 $num =
$res->numRows();
136 $this->
output(
"Refreshing $num old redirects from $start...\n" );
140 foreach (
$res as $row ) {
141 if ( !( ++$i % self::REPORTING_INTERVAL ) ) {
147 } elseif ( $newOnly ) {
148 $this->
output(
"Refreshing $what from " );
153 self::intervalCond(
$dbr,
'page_id', $start, $end ),
157 $num =
$res->numRows();
158 $this->
output(
"$num new articles...\n" );
161 foreach (
$res as $row ) {
162 if ( !( ++$i % self::REPORTING_INTERVAL ) ) {
166 if ( $redirectsOnly ) {
174 $maxPage =
$dbr->selectField(
'page',
'max(page_id)',
'', __METHOD__ );
175 $maxRD =
$dbr->selectField(
'redirect',
'max(rd_from)',
'', __METHOD__ );
176 $end = max( $maxPage, $maxRD );
178 $this->
output(
"Refreshing redirects table.\n" );
179 $this->
output(
"Starting from page_id $start of $end.\n" );
181 for ( $id = $start; $id <= $end; $id++ ) {
182 if ( !( $id % self::REPORTING_INTERVAL ) ) {
189 if ( !$redirectsOnly ) {
190 $this->
output(
"Refreshing links tables.\n" );
191 $this->
output(
"Starting from page_id $start of $end.\n" );
193 for ( $id = $start; $id <= $end; $id++ ) {
194 if ( !( $id % self::REPORTING_INTERVAL ) ) {
217 $page = WikiPage::newFromID( $id );
220 if ( $page ===
null ) {
223 $dbw->delete(
'redirect', [
'rd_from' => $id ],
227 } elseif ( $this->
namespace !==
false
228 && !$page->getTitle()->inNamespace( $this->namespace )
236 $rt =
$content->getUltimateRedirectTarget();
239 if ( $rt ===
null ) {
242 $dbw->delete(
'redirect', [
'rd_from' => $id ], __METHOD__ );
245 $page->insertRedirectEntry( $rt );
250 $dbw->update(
'page', [
'page_is_redirect' => $fieldValue ],
251 [
'page_id' => $id ], __METHOD__ );
260 $page = WikiPage::newFromID( $id );
262 MediaWikiServices::getInstance()->getLinkCache()->clear();
264 if ( $page ===
null ) {
266 } elseif ( $ns !==
false
267 && !$page->getTitle()->inNamespace( $ns ) ) {
274 $page->doSecondaryDataUpdates( [
275 'defer' => DeferredUpdates::POSTSEND,
276 'recursive' =>
false,
278 DeferredUpdates::doUpdates();
296 $this->
output(
"Deleting illegal entries from the links tables...\n" );
301 $nextStart =
$dbr->selectField(
304 [ self::intervalCond(
$dbr,
'page_id', $start, $end ) ]
307 [
'ORDER BY' =>
'page_id',
'OFFSET' => $chunkSize ]
310 if ( $nextStart !==
false ) {
315 $chunkEnd = $nextStart - 1;
321 $fmtStart = $start !==
null ?
"[$start" :
'(-INF';
322 $fmtChunkEnd = $chunkEnd !==
null ?
"$chunkEnd]" :
'INF)';
323 $this->
output(
" Checking interval $fmtStart, $fmtChunkEnd\n" );
328 }
while ( $nextStart !==
false );
342 'pagelinks' =>
'pl_from',
343 'imagelinks' =>
'il_from',
344 'categorylinks' =>
'cl_from',
345 'templatelinks' =>
'tl_from',
346 'externallinks' =>
'el_from',
347 'iwlinks' =>
'iwl_from',
348 'langlinks' =>
'll_from',
349 'redirect' =>
'rd_from',
350 'page_props' =>
'pp_page',
353 foreach ( $linksTables
as $table => $field ) {
354 $this->
output(
" $table: 0" );
355 $tableStart = $start;
358 $ids =
$dbr->selectFieldValues(
362 self::intervalCond(
$dbr, $field, $tableStart, $end ),
363 "$field NOT IN ({$dbr->selectSQLText( 'page', 'page_id' )})",
366 [
'DISTINCT',
'ORDER BY' => $field,
'LIMIT' => $batchSize ]
369 $numIds = count( $ids );
372 $dbw->delete( $table, [ $field => $ids ], __METHOD__ );
373 $this->
output(
", $counter" );
374 $tableStart = $ids[$numIds - 1] + 1;
378 }
while ( $numIds >= $batchSize && ( $end ===
null || $tableStart <= $end ) );
380 $this->
output(
" deleted.\n" );
397 if ( $start ===
null && $end ===
null ) {
398 return "$var IS NOT NULL";
399 } elseif ( $end ===
null ) {
400 return "$var >= {$db->addQuotes( $start )}";
401 } elseif ( $start ===
null ) {
402 return "$var <= {$db->addQuotes( $end )}";
404 return "$var BETWEEN {$db->addQuotes( $start )} AND {$db->addQuotes( $end )}";
417 $this->
error(
"Tracking category '$category' is disabled\n" );
421 foreach ( $cats
as $cat ) {
432 $this->
output(
"Refreshing pages in category '{$category->getText()}'...\n" );
439 if ( $this->
namespace !==
false ) {
447 $finalConds = $conds;
448 $timestamp =
$dbr->addQuotes( $timestamp );
450 "(cl_timestamp > $timestamp OR (cl_timestamp = $timestamp AND cl_from > $lastId))";
451 $res =
$dbr->select( [
'page',
'categorylinks' ],
452 [
'page_id',
'cl_timestamp' ],
456 'ORDER BY' => [
'cl_timestamp',
'cl_from' ],
461 foreach (
$res as $row ) {
462 if ( !( ++$i % self::REPORTING_INTERVAL ) ) {
466 $lastId = $row->page_id;
467 $timestamp = $row->cl_timestamp;
471 }
while (
$res->numRows() == $this->getBatchSize() );
482 $cats = $trackingCategories->getTrackingCategories();
483 if ( isset( $cats[$categoryKey] ) ) {
484 return $cats[$categoryKey][
'cats'];
486 $this->
fatalError(
"Unknown tracking category {$categoryKey}\n" );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
error( $err, $die=0)
Throw an error to the user.
addArg( $arg, $description, $required=true)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
hasOption( $name)
Checks to see if a particular option exists.
getBatchSize()
Returns batch size.
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
setBatchSize( $s=0)
Set the batch size.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Maintenance script to refresh link tables.
dfnCheckInterval( $start=null, $end=null, $batchSize=100)
doRefreshLinks( $start, $newOnly=false, $end=null, $redirectsOnly=false, $oldRedirectsOnly=false)
Do the actual link refreshing.
static intervalCond(IDatabase $db, $var, $start, $end)
Build a SQL expression for a closed interval (i.e.
getPossibleCategories( $categoryKey)
Returns a list of possible categories for a given tracking category key.
__construct()
Default constructor.
refreshTrackingCategory( $category)
Refershes links for pages in a tracking category.
static fixLinksFromArticle( $id, $ns=false)
Run LinksUpdate for all links on a given page_id.
execute()
Do the actual work.
refreshCategory(Title $category)
Refreshes links to a category.
fixRedirect( $id)
Update the redirect entry for a given page.
deleteLinksFromNonexistent( $start=null, $end=null, $batchSize=100, $chunkSize=100000)
Removes non-existing links from pages from pagelinks, imagelinks, categorylinks, templatelinks,...
Represents a title within MediaWiki.
getDBkey()
Get the main part with underscores.
This class performs some operations related to tracking categories, such as creating a list of all su...
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
namespace and then decline to actually register it file or subcat img or subcat $title
processing should stop and the error should be shown to the user * false
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
require_once RUN_MAINTENANCE_IF_MAIN