MediaWiki
master
cleanupPageLang.php
Go to the documentation of this file.
1
<?php
24
// @codeCoverageIgnoreStart
25
require_once __DIR__ .
'/TableCleanup.php'
;
26
// @codeCoverageIgnoreEnd
27
28
use
MediaWiki\Language\LanguageCode
;
29
35
class
CleanupPageLang
extends
TableCleanup
{
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;
86
require_once RUN_MAINTENANCE_IF_MAIN;
87
// @codeCoverageIgnoreEnd
CleanupPageLang
Maintenance script to clean up deprecated language codes in page_lang.
Definition
cleanupPageLang.php:35
CleanupPageLang\__construct
__construct()
Default constructor.
Definition
cleanupPageLang.php:36
CleanupPageLang\processRow
processRow( $row)
Definition
cleanupPageLang.php:45
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition
Maintenance.php:481
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition
Maintenance.php:331
Maintenance\getPrimaryDB
getPrimaryDB()
Definition
Maintenance.php:1153
Maintenance\setBatchSize
setBatchSize( $s=0)
Definition
Maintenance.php:421
MediaWiki\Language\LanguageCode
Methods for dealing with language codes.
Definition
LanguageCode.php:32
TableCleanup
Generic class to cleanup a database table.
Definition
TableCleanup.php:35
TableCleanup\progress
progress( $updated)
Definition
TableCleanup.php:87
$maintClass
$maintClass
Definition
cleanupPageLang.php:85
maintenance
cleanupPageLang.php
Generated on Mon Oct 14 2024 02:26:43 for MediaWiki by
1.10.0