MediaWiki  1.30.0
populateBacklinkNamespace.php
Go to the documentation of this file.
1 <?php
24 require_once __DIR__ . '/Maintenance.php';
25 
32  public function __construct() {
33  parent::__construct();
34  $this->addDescription( 'Populate the *_from_namespace fields' );
35  $this->addOption( 'lastUpdatedId', "Highest page_id with updated links", false, true );
36  }
37 
38  protected function getUpdateKey() {
39  return 'populate *_from_namespace';
40  }
41 
42  protected function updateSkippedMessage() {
43  return '*_from_namespace column of backlink tables already populated.';
44  }
45 
46  public function doDBUpdates() {
47  $force = $this->getOption( 'force' );
48 
49  $db = $this->getDB( DB_MASTER );
50 
51  $this->output( "Updating *_from_namespace fields in links tables.\n" );
52 
53  $start = $this->getOption( 'lastUpdatedId' );
54  if ( !$start ) {
55  $start = $db->selectField( 'page', 'MIN(page_id)', false, __METHOD__ );
56  }
57  if ( !$start ) {
58  $this->output( "Nothing to do." );
59  return false;
60  }
61  $end = $db->selectField( 'page', 'MAX(page_id)', false, __METHOD__ );
62 
63  # Do remaining chunk
64  $end += $this->mBatchSize - 1;
65  $blockStart = $start;
66  $blockEnd = $start + $this->mBatchSize - 1;
67  while ( $blockEnd <= $end ) {
68  $this->output( "...doing page_id from $blockStart to $blockEnd\n" );
69  $cond = "page_id BETWEEN $blockStart AND $blockEnd";
70  $res = $db->select( 'page', [ 'page_id', 'page_namespace' ], $cond, __METHOD__ );
71  foreach ( $res as $row ) {
72  $db->update( 'pagelinks',
73  [ 'pl_from_namespace' => $row->page_namespace ],
74  [ 'pl_from' => $row->page_id ],
75  __METHOD__
76  );
77  $db->update( 'templatelinks',
78  [ 'tl_from_namespace' => $row->page_namespace ],
79  [ 'tl_from' => $row->page_id ],
80  __METHOD__
81  );
82  $db->update( 'imagelinks',
83  [ 'il_from_namespace' => $row->page_namespace ],
84  [ 'il_from' => $row->page_id ],
85  __METHOD__
86  );
87  }
88  $blockStart += $this->mBatchSize - 1;
89  $blockEnd += $this->mBatchSize - 1;
91  }
92  return true;
93  }
94 }
95 
96 $maintClass = "PopulateBacklinkNamespace";
97 require_once RUN_MAINTENANCE_IF_MAIN;
PopulateBacklinkNamespace
Maintenance script to populate *_from_namespace fields.
Definition: populateBacklinkNamespace.php:31
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:287
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
$res
$res
Definition: database.txt:21
wfWaitForSlaves
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
Definition: GlobalFunctions.php:3010
php
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
Definition: injection.txt:35
LoggedUpdateMaintenance
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
Definition: Maintenance.php:1562
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:215
DB_MASTER
const DB_MASTER
Definition: defines.php:26
PopulateBacklinkNamespace\updateSkippedMessage
updateSkippedMessage()
Message to show that the update was done already and was just skipped.
Definition: populateBacklinkNamespace.php:42
PopulateBacklinkNamespace\__construct
__construct()
Default constructor.
Definition: populateBacklinkNamespace.php:32
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:250
as
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
Definition: distributors.txt:9
Maintenance\getDB
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1251
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:373
PopulateBacklinkNamespace\doDBUpdates
doDBUpdates()
Do the actual work.
Definition: populateBacklinkNamespace.php:46
$maintClass
$maintClass
Definition: populateBacklinkNamespace.php:96
PopulateBacklinkNamespace\getUpdateKey
getUpdateKey()
Get the update key name to go in the update log table.
Definition: populateBacklinkNamespace.php:38