MediaWiki
REL1_24
|
00001 <?php 00024 require_once __DIR__ . '/Maintenance.php'; 00025 00031 class PopulateBacklinkNamespace extends LoggedUpdateMaintenance { 00032 public function __construct() { 00033 parent::__construct(); 00034 $this->mDescription = "Populate the *_from_namespace fields"; 00035 $this->addOption( 'lastUpdatedId', "Highest page_id with updated links", false, true ); 00036 } 00037 00038 protected function getUpdateKey() { 00039 return 'populate *_from_namespace'; 00040 } 00041 00042 protected function updateSkippedMessage() { 00043 return '*_from_namespace column of backlink tables already populated.'; 00044 } 00045 00046 public function doDBUpdates() { 00047 $force = $this->getOption( 'force' ); 00048 00049 $db = $this->getDB( DB_MASTER ); 00050 00051 $this->output( "Updating *_from_namespace fields in links tables.\n" ); 00052 00053 $start = $this->getOption( 'lastUpdatedId' ); 00054 if ( !$start ) { 00055 $start = $db->selectField( 'page', 'MIN(page_id)', false, __METHOD__ ); 00056 } 00057 if ( !$start ) { 00058 $this->output( "Nothing to do." ); 00059 return false; 00060 } 00061 $end = $db->selectField( 'page', 'MAX(page_id)', false, __METHOD__ ); 00062 00063 # Do remaining chunk 00064 $end += $this->mBatchSize - 1; 00065 $blockStart = $start; 00066 $blockEnd = $start + $this->mBatchSize - 1; 00067 while ( $blockEnd <= $end ) { 00068 $this->output( "...doing page_id from $blockStart to $blockEnd\n" ); 00069 $cond = "page_id BETWEEN $blockStart AND $blockEnd"; 00070 $res = $db->select( 'page', array( 'page_id', 'page_namespace' ), $cond, __METHOD__ ); 00071 foreach ( $res as $row ) { 00072 $db->update( 'pagelinks', 00073 array( 'pl_from_namespace' => $row->page_namespace ), 00074 array( 'pl_from' => $row->page_id ), 00075 __METHOD__ 00076 ); 00077 $db->update( 'templatelinks', 00078 array( 'tl_from_namespace' => $row->page_namespace ), 00079 array( 'tl_from' => $row->page_id ), 00080 __METHOD__ 00081 ); 00082 $db->update( 'imagelinks', 00083 array( 'il_from_namespace' => $row->page_namespace ), 00084 array( 'il_from' => $row->page_id ), 00085 __METHOD__ 00086 ); 00087 } 00088 $blockStart += $this->mBatchSize - 1; 00089 $blockEnd += $this->mBatchSize - 1; 00090 wfWaitForSlaves(); 00091 } 00092 return true; 00093 } 00094 } 00095 00096 $maintClass = "PopulateBacklinkNamespace"; 00097 require_once RUN_MAINTENANCE_IF_MAIN;