Merge "Remove not used private member variable mParserWarnings from OutputPage"
[mediawiki.git] / maintenance / populateBacklinkNamespace.php
blob054f7921fb2b8d6fc73563fb80980f772dd6bda4
1 <?php
2 /**
3 * Optional upgrade script to populate *_from_namespace fields
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup Maintenance
24 require_once __DIR__ . '/Maintenance.php';
26 /**
27 * Maintenance script to populate *_from_namespace fields
29 * @ingroup Maintenance
31 class PopulateBacklinkNamespace extends LoggedUpdateMaintenance {
32 public function __construct() {
33 parent::__construct();
34 $this->mDescription = "Populate the *_from_namespace fields";
35 $this->addOption( 'lastUpdatedId', "Highest page_id with updated links", false, true );
38 protected function getUpdateKey() {
39 return 'populate *_from_namespace';
42 protected function updateSkippedMessage() {
43 return '*_from_namespace column of backlink tables already populated.';
46 public function doDBUpdates() {
47 $force = $this->getOption( 'force' );
49 $db = $this->getDB( DB_MASTER );
51 $this->output( "Updating *_from_namespace fields in links tables.\n" );
53 $start = $this->getOption( 'lastUpdatedId' );
54 if ( !$start ) {
55 $start = $db->selectField( 'page', 'MIN(page_id)', false, __METHOD__ );
57 if ( !$start ) {
58 $this->output( "Nothing to do." );
59 return false;
61 $end = $db->selectField( 'page', 'MAX(page_id)', false, __METHOD__ );
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', array( 'page_id', 'page_namespace' ), $cond, __METHOD__ );
71 foreach ( $res as $row ) {
72 $db->update( 'pagelinks',
73 array( 'pl_from_namespace' => $row->page_namespace ),
74 array( 'pl_from' => $row->page_id ),
75 __METHOD__
77 $db->update( 'templatelinks',
78 array( 'tl_from_namespace' => $row->page_namespace ),
79 array( 'tl_from' => $row->page_id ),
80 __METHOD__
82 $db->update( 'imagelinks',
83 array( 'il_from_namespace' => $row->page_namespace ),
84 array( 'il_from' => $row->page_id ),
85 __METHOD__
88 $blockStart += $this->mBatchSize - 1;
89 $blockEnd += $this->mBatchSize - 1;
90 wfWaitForSlaves();
92 return true;
96 $maintClass = "PopulateBacklinkNamespace";
97 require_once RUN_MAINTENANCE_IF_MAIN;