MediaWiki
master
cleanupPageLang.php
Go to the documentation of this file.
1
<?php
10
// @codeCoverageIgnoreStart
11
require_once __DIR__ .
'/TableCleanup.php'
;
12
// @codeCoverageIgnoreEnd
13
14
use
MediaWiki\Language\LanguageCode
;
15
21
class
CleanupPageLang
extends
TableCleanup
{
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;
72
require_once RUN_MAINTENANCE_IF_MAIN;
73
// @codeCoverageIgnoreEnd
CleanupPageLang
Maintenance script to clean up deprecated language codes in page_lang.
Definition
cleanupPageLang.php:21
CleanupPageLang\__construct
__construct()
Default constructor.
Definition
cleanupPageLang.php:22
CleanupPageLang\processRow
processRow( $row)
Definition
cleanupPageLang.php:31
MediaWiki\Language\LanguageCode
Methods for dealing with language codes.
Definition
LanguageCode.php:18
MediaWiki\Maintenance\Maintenance\setBatchSize
setBatchSize( $s=0)
Definition
Maintenance.php:426
MediaWiki\Maintenance\Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition
Maintenance.php:486
MediaWiki\Maintenance\Maintenance\getPrimaryDB
getPrimaryDB(string|false $virtualDomain=false)
Definition
Maintenance.php:1151
MediaWiki\Maintenance\Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition
Maintenance.php:336
TableCleanup
Generic class to cleanup a database table.
Definition
TableCleanup.php:23
TableCleanup\progress
progress( $updated)
Definition
TableCleanup.php:75
$maintClass
$maintClass
Definition
cleanupPageLang.php:71
maintenance
cleanupPageLang.php
Generated on Mon Dec 15 2025 14:27:08 for MediaWiki by
1.10.0