24require_once __DIR__ .
'/Maintenance.php';
36 parent::__construct();
38 $this->
addOption(
'dfn-only',
'Delete links from nonexistent articles only' );
39 $this->
addOption(
'new-only',
'Only affect articles with just a single edit' );
40 $this->
addOption(
'redirects-only',
'Only fix redirects, not all links' );
41 $this->
addOption(
'old-redirects-only',
'Only fix redirects with no redirect table entry' );
42 $this->
addOption(
'e',
'Last page id to refresh',
false,
true );
43 $this->
addOption(
'dfn-chunk-size',
'Maximum number of existent IDs to check per ' .
44 'query, default 100000',
false,
true );
45 $this->
addOption(
'namespace',
'Only fix pages in this namespace',
false,
true );
46 $this->
addArg(
'start',
'Page_id to start from, default 1',
false );
55 $start = (int)$this->
getArg( 0 ) ?:
null;
56 $end = (int)$this->
getOption(
'e' ) ?:
null;
57 $dfnChunkSize = (int)$this->
getOption(
'dfn-chunk-size', 100000 );
60 $this->
namespace =
false;
62 $this->
namespace = (int)$ns;
65 $new = $this->
getOption(
'new-only',
false );
66 $redir = $this->
getOption(
'redirects-only',
false );
67 $oldRedir = $this->
getOption(
'old-redirects-only',
false );
76 return $this->
namespace !==
false
90 $end =
null, $redirectsOnly =
false, $oldRedirectsOnly =
false
92 $reportingInterval = 100;
95 if ( $start ===
null ) {
100 Hooks::run(
'MaintenanceRefreshLinksInit', [ $this ] );
102 $what = $redirectsOnly ?
"redirects" :
"links";
104 if ( $oldRedirectsOnly ) {
105 # This entire code path is cut-and-pasted from below. Hurrah.
108 "page_is_redirect=1",
114 [
'page',
'redirect' ],
119 [
'redirect' => [
"LEFT JOIN",
"page_id=rd_from" ] ]
121 $num =
$res->numRows();
122 $this->
output(
"Refreshing $num old redirects from $start...\n" );
126 foreach (
$res as $row ) {
127 if ( !( ++$i % $reportingInterval ) ) {
133 } elseif ( $newOnly ) {
134 $this->
output(
"Refreshing $what from " );
139 self::intervalCond(
$dbr,
'page_id', $start, $end ),
143 $num =
$res->numRows();
144 $this->
output(
"$num new articles...\n" );
147 foreach (
$res as $row ) {
148 if ( !( ++$i % $reportingInterval ) ) {
152 if ( $redirectsOnly ) {
160 $maxPage =
$dbr->selectField(
'page',
'max(page_id)',
false );
161 $maxRD =
$dbr->selectField(
'redirect',
'max(rd_from)',
false );
162 $end = max( $maxPage, $maxRD );
164 $this->
output(
"Refreshing redirects table.\n" );
165 $this->
output(
"Starting from page_id $start of $end.\n" );
167 for ( $id = $start; $id <= $end; $id++ ) {
169 if ( !( $id % $reportingInterval ) ) {
176 if ( !$redirectsOnly ) {
177 $this->
output(
"Refreshing links tables.\n" );
178 $this->
output(
"Starting from page_id $start of $end.\n" );
180 for ( $id = $start; $id <= $end; $id++ ) {
182 if ( !( $id % $reportingInterval ) ) {
208 if (
$page ===
null ) {
211 $dbw->delete(
'redirect', [
'rd_from' => $id ],
215 } elseif ( $this->
namespace !==
false
216 && !
$page->getTitle()->inNamespace( $this->namespace )
224 $rt =
$content->getUltimateRedirectTarget();
227 if ( $rt ===
null ) {
230 $dbw->delete(
'redirect', [
'rd_from' => $id ], __METHOD__ );
233 $page->insertRedirectEntry( $rt );
238 $dbw->update(
'page', [
'page_is_redirect' => $fieldValue ],
239 [
'page_id' => $id ], __METHOD__ );
250 LinkCache::singleton()->clear();
252 if (
$page ===
null ) {
254 } elseif ( $ns !==
false
255 && !
$page->getTitle()->inNamespace( $ns ) ) {
264 foreach (
$content->getSecondaryDataUpdates(
$page->getTitle() )
as $update ) {
265 DeferredUpdates::addUpdate( $update );
266 DeferredUpdates::doUpdates();
285 $this->
output(
"Deleting illegal entries from the links tables...\n" );
290 $nextStart =
$dbr->selectField(
293 [ self::intervalCond(
$dbr,
'page_id', $start, $end ) ]
296 [
'ORDER BY' =>
'page_id',
'OFFSET' => $chunkSize ]
299 if ( $nextStart !==
false ) {
304 $chunkEnd = $nextStart - 1;
310 $fmtStart = $start !==
null ?
"[$start" :
'(-INF';
311 $fmtChunkEnd = $chunkEnd !==
null ?
"$chunkEnd]" :
'INF)';
312 $this->
output(
" Checking interval $fmtStart, $fmtChunkEnd\n" );
317 }
while ( $nextStart !==
false );
331 'pagelinks' =>
'pl_from',
332 'imagelinks' =>
'il_from',
333 'categorylinks' =>
'cl_from',
334 'templatelinks' =>
'tl_from',
335 'externallinks' =>
'el_from',
336 'iwlinks' =>
'iwl_from',
337 'langlinks' =>
'll_from',
338 'redirect' =>
'rd_from',
339 'page_props' =>
'pp_page',
342 foreach ( $linksTables
as $table => $field ) {
343 $this->
output(
" $table: 0" );
344 $tableStart = $start;
347 $ids =
$dbr->selectFieldValues(
351 self::intervalCond(
$dbr, $field, $tableStart, $end ),
352 "$field NOT IN ({$dbr->selectSQLText( 'page', 'page_id' )})",
355 [
'DISTINCT',
'ORDER BY' => $field,
'LIMIT' => $batchSize ]
358 $numIds = count( $ids );
361 $dbw->delete( $table, [ $field => $ids ], __METHOD__ );
362 $this->
output(
", $counter" );
363 $tableStart = $ids[$numIds - 1] + 1;
367 }
while ( $numIds >= $batchSize && ( $end ===
null || $tableStart <= $end ) );
369 $this->
output(
" deleted.\n" );
385 if ( $start ===
null && $end ===
null ) {
386 return "$var IS NOT NULL";
387 } elseif ( $end ===
null ) {
388 return "$var >= {$db->addQuotes( $start )}";
389 } elseif ( $start ===
null ) {
390 return "$var <= {$db->addQuotes( $end )}";
392 return "$var BETWEEN {$db->addQuotes( $start )} AND {$db->addQuotes( $end )}";
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...
addArg( $arg, $description, $required=true)
Add some args that are needed.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
hasOption( $name)
Checks to see if a particular param exists.
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.
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.
__construct()
Default constructor.
static fixLinksFromArticle( $id, $ns=false)
Run LinksUpdate for all links on a given page_id.
execute()
Do the actual work.
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,...
static newFromID( $id, $from='fromdb')
Constructor from a page id.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
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
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content $content
namespace are movable Hooks may change this value to override the return value of MWNamespace::isMovable(). 'NewDifferenceEngine' do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
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
Basic database interface for live and lazy-loaded relation database handles.
require_once RUN_MAINTENANCE_IF_MAIN