MediaWiki master
cleanupPageLang.php
Go to the documentation of this file.
1<?php
10// @codeCoverageIgnoreStart
11require_once __DIR__ . '/TableCleanup.php';
12// @codeCoverageIgnoreEnd
13
15
22 public function __construct() {
23 parent::__construct();
24 $this->addDescription( 'Script to clean up deprecated language codes in page_lang' );
25 $this->setBatchSize( 1000 );
26 }
27
31 protected function processRow( $row ) {
32 $oldPageLang = $row->page_lang;
33 if ( $oldPageLang === null ) {
34 // Page has no page language
35 $this->progress( 0 );
36 return;
37 }
38
39 $newPageLang = LanguageCode::replaceDeprecatedCodes( $oldPageLang );
40 if ( $newPageLang === $oldPageLang ) {
41 // Page language is unchanged
42 $this->progress( 0 );
43 return;
44 }
45
46 $this->updatePageLang( $row, $oldPageLang, $newPageLang );
47 $this->progress( 1 );
48 }
49
55 private function updatePageLang( $row, $oldPageLang, $newPageLang ) {
56 if ( $this->dryrun ) {
57 $this->output( "DRY RUN: would update page_lang on $row->page_id from $oldPageLang to $newPageLang.\n" );
58 } else {
59 $this->output( "Update page_lang on $row->page_id from $oldPageLang to $newPageLang.\n" );
60 $this->getPrimaryDB()
61 ->newUpdateQueryBuilder()
62 ->update( 'page' )
63 ->set( [ 'page_lang' => $newPageLang ] )
64 ->where( [ 'page_id' => $row->page_id ] )
65 ->caller( __METHOD__ )->execute();
66 }
67 }
68}
69
70// @codeCoverageIgnoreStart
71$maintClass = CleanupPageLang::class;
72require_once RUN_MAINTENANCE_IF_MAIN;
73// @codeCoverageIgnoreEnd
Maintenance script to clean up deprecated language codes in page_lang.
__construct()
Default constructor.
Methods for dealing with language codes.
output( $out, $channel=null)
Throw some output to the user.
getPrimaryDB(string|false $virtualDomain=false)
addDescription( $text)
Set the description text.
Generic class to cleanup a database table.
progress( $updated)
$maintClass