Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F33760
cleanupPageLang.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
cleanupPageLang.php
View Options
<?php
/**
* Clean up deprecated language codes in page_lang
*
* @license GPL-2.0-or-later
* @file
* @ingroup Maintenance
*/
// @codeCoverageIgnoreStart
require_once
__DIR__
.
'/TableCleanup.php'
;
// @codeCoverageIgnoreEnd
use
MediaWiki\Language\LanguageCode
;
/**
* Maintenance script to clean up deprecated language codes in page_lang
*
* @ingroup Maintenance
*/
class
CleanupPageLang
extends
TableCleanup
{
public
function
__construct
()
{
parent
::
__construct
();
$this
->
addDescription
(
'Script to clean up deprecated language codes in page_lang'
);
$this
->
setBatchSize
(
1000
);
}
/**
* @param stdClass $row
*/
protected
function
processRow
(
$row
)
{
$oldPageLang
=
$row
->
page_lang
;
if
(
$oldPageLang
===
null
)
{
// Page has no page language
$this
->
progress
(
0
);
return
;
}
$newPageLang
=
LanguageCode
::
replaceDeprecatedCodes
(
$oldPageLang
);
if
(
$newPageLang
===
$oldPageLang
)
{
// Page language is unchanged
$this
->
progress
(
0
);
return
;
}
$this
->
updatePageLang
(
$row
,
$oldPageLang
,
$newPageLang
);
$this
->
progress
(
1
);
}
/**
* @param stdClass $row
* @param string $oldPageLang
* @param string $newPageLang
*/
private
function
updatePageLang
(
$row
,
$oldPageLang
,
$newPageLang
)
{
if
(
$this
->
dryrun
)
{
$this
->
output
(
"DRY RUN: would update page_lang on $row->page_id from $oldPageLang to $newPageLang.
\n
"
);
}
else
{
$this
->
output
(
"Update page_lang on $row->page_id from $oldPageLang to $newPageLang.
\n
"
);
$this
->
getPrimaryDB
()
->
newUpdateQueryBuilder
()
->
update
(
'page'
)
->
set
(
[
'page_lang'
=>
$newPageLang
]
)
->
where
(
[
'page_id'
=>
$row
->
page_id
]
)
->
caller
(
__METHOD__
)->
execute
();
}
}
}
// @codeCoverageIgnoreStart
$maintClass
=
CleanupPageLang
::
class
;
require_once
RUN_MAINTENANCE_IF_MAIN
;
// @codeCoverageIgnoreEnd
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Thu, Dec 18, 08:44 (38 m, 53 s)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
38/70/bb81d60a0980368ea45a4e6379e8
Default Alt Text
cleanupPageLang.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment