MediaWiki master
cleanupPageLang.php
Go to the documentation of this file.
1<?php
24// @codeCoverageIgnoreStart
25require_once __DIR__ . '/TableCleanup.php';
26// @codeCoverageIgnoreEnd
27
29
36 public function __construct() {
37 parent::__construct();
38 $this->addDescription( 'Script to clean up deprecated language codes in page_lang' );
39 $this->setBatchSize( 1000 );
40 }
41
45 protected function processRow( $row ) {
46 $oldPageLang = $row->page_lang;
47 if ( $oldPageLang === null ) {
48 // Page has no page language
49 $this->progress( 0 );
50 return;
51 }
52
53 $newPageLang = LanguageCode::replaceDeprecatedCodes( $oldPageLang );
54 if ( $newPageLang === $oldPageLang ) {
55 // Page language is unchanged
56 $this->progress( 0 );
57 return;
58 }
59
60 $this->updatePageLang( $row, $oldPageLang, $newPageLang );
61 $this->progress( 1 );
62 }
63
69 private function updatePageLang( $row, $oldPageLang, $newPageLang ) {
70 if ( $this->dryrun ) {
71 $this->output( "DRY RUN: would update page_lang on $row->page_id from $oldPageLang to $newPageLang.\n" );
72 } else {
73 $this->output( "Update page_lang on $row->page_id from $oldPageLang to $newPageLang.\n" );
74 $this->getPrimaryDB()
75 ->newUpdateQueryBuilder()
76 ->update( 'page' )
77 ->set( [ 'page_lang' => $newPageLang ] )
78 ->where( [ 'page_id' => $row->page_id ] )
79 ->caller( __METHOD__ )->execute();
80 }
81 }
82}
83
84// @codeCoverageIgnoreStart
85$maintClass = CleanupPageLang::class;
86require_once RUN_MAINTENANCE_IF_MAIN;
87// @codeCoverageIgnoreEnd
Maintenance script to clean up deprecated language codes in page_lang.
__construct()
Default constructor.
output( $out, $channel=null)
Throw some output to the user.
addDescription( $text)
Set the description text.
setBatchSize( $s=0)
Methods for dealing with language codes.
Generic class to cleanup a database table.
progress( $updated)
$maintClass