MediaWiki
master
cleanupPageLang.php
Go to the documentation of this file.
1
<?php
24
require_once __DIR__ .
'/TableCleanup.php'
;
25
31
class
CleanupPageLang
extends
TableCleanup
{
32
public
function
__construct
() {
33
parent::__construct();
34
$this->
addDescription
(
'Script to clean up deprecated language codes in page_lang'
);
35
$this->
setBatchSize
( 1000 );
36
}
37
41
protected
function
processRow
( $row ) {
42
$oldPageLang = $row->page_lang;
43
if
( $oldPageLang ===
null
) {
44
// Page has no page language
45
$this->
progress
( 0 );
46
return
;
47
}
48
49
$newPageLang = LanguageCode::replaceDeprecatedCodes( $oldPageLang );
50
if
( $newPageLang === $oldPageLang ) {
51
// Page language is unchanged
52
$this->
progress
( 0 );
53
return
;
54
}
55
56
$this->updatePageLang( $row, $oldPageLang, $newPageLang );
57
$this->
progress
( 1 );
58
}
59
65
private
function
updatePageLang( $row, $oldPageLang, $newPageLang ) {
66
if
( $this->dryrun ) {
67
$this->
output
(
"DRY RUN: would update page_lang on $row->page_id from $oldPageLang to $newPageLang.\n"
);
68
}
else
{
69
$this->
output
(
"Update page_lang on $row->page_id from $oldPageLang to $newPageLang.\n"
);
70
$this->
getPrimaryDB
()
71
->newUpdateQueryBuilder()
72
->update(
'page'
)
73
->set( [
'page_lang'
=> $newPageLang ] )
74
->where( [
'page_id'
=> $row->page_id ] )
75
->caller( __METHOD__ )->execute();
76
}
77
}
78
}
79
80
$maintClass
= CleanupPageLang::class;
81
require_once RUN_MAINTENANCE_IF_MAIN;
CleanupPageLang
Maintenance script to clean up deprecated language codes in page_lang.
Definition
cleanupPageLang.php:31
CleanupPageLang\__construct
__construct()
Default constructor.
Definition
cleanupPageLang.php:32
CleanupPageLang\processRow
processRow( $row)
Definition
cleanupPageLang.php:41
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition
Maintenance.php:467
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition
Maintenance.php:329
Maintenance\getPrimaryDB
getPrimaryDB()
Definition
Maintenance.php:1093
Maintenance\setBatchSize
setBatchSize( $s=0)
Definition
Maintenance.php:407
TableCleanup
Generic class to cleanup a database table.
Definition
TableCleanup.php:33
TableCleanup\progress
progress( $updated)
Definition
TableCleanup.php:82
$maintClass
$maintClass
Definition
cleanupPageLang.php:80
maintenance
cleanupPageLang.php
Generated on Wed May 1 2024 22:26:32 for MediaWiki by
1.10.0