MediaWiki REL1_31
populateBacklinkNamespace.php
Go to the documentation of this file.
1<?php
24require_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)', '', __METHOD__ );
56 }
57 if ( !$start ) {
58 $this->output( "Nothing to do." );
59 return false;
60 }
61 $end = $db->selectField( 'page', 'MAX(page_id)', '', __METHOD__ );
62 $batchSize = $this->getBatchSize();
63
64 # Do remaining chunk
65 $end += $batchSize - 1;
66 $blockStart = $start;
67 $blockEnd = $start + $batchSize - 1;
68 while ( $blockEnd <= $end ) {
69 $this->output( "...doing page_id from $blockStart to $blockEnd\n" );
70 $cond = "page_id BETWEEN " . (int)$blockStart . " AND " . (int)$blockEnd;
71 $res = $db->select( 'page', [ 'page_id', 'page_namespace' ], $cond, __METHOD__ );
72 foreach ( $res as $row ) {
73 $db->update( 'pagelinks',
74 [ 'pl_from_namespace' => $row->page_namespace ],
75 [ 'pl_from' => $row->page_id ],
76 __METHOD__
77 );
78 $db->update( 'templatelinks',
79 [ 'tl_from_namespace' => $row->page_namespace ],
80 [ 'tl_from' => $row->page_id ],
81 __METHOD__
82 );
83 $db->update( 'imagelinks',
84 [ 'il_from_namespace' => $row->page_namespace ],
85 [ 'il_from' => $row->page_id ],
86 __METHOD__
87 );
88 }
89 $blockStart += $batchSize - 1;
90 $blockEnd += $batchSize - 1;
92 }
93 return true;
94 }
95}
96
97$maintClass = PopulateBacklinkNamespace::class;
98require_once RUN_MAINTENANCE_IF_MAIN;
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
getBatchSize()
Returns batch size.
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.
Maintenance script to populate *_from_namespace fields.
getUpdateKey()
Get the update key name to go in the update log table.
updateSkippedMessage()
Message to show that the update was done already and was just skipped.
$res
Definition database.txt:21
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
require_once RUN_MAINTENANCE_IF_MAIN
const DB_MASTER
Definition defines.php:29