Page MenuHomePhabricator
Paste P43432

Verify that deprecated language codes are identical to their replacements in the WMF interwiki map
ActivePublic

Authored by Lucas_Werkmeister_WMDE on Jan 27 2023, 2:28 PM.
<?php
$deprecatedMapping = [ // LanguageCode::DEPRECATED_LANGUAGE_CODE_MAPPING
// Note that als is actually a valid ISO 639 code (Tosk Albanian), but it
// was previously used in MediaWiki for Alsatian, which comes under gsw
'als' => 'gsw', // T25215
'bat-smg' => 'sgs', // T27522
'be-x-old' => 'be-tarask', // T11823
'fiu-vro' => 'vro', // T31186
'roa-rup' => 'rup', // T17988
'zh-classical' => 'lzh', // T30443
'zh-min-nan' => 'nan', // T30442
'zh-yue' => 'yue', // T30441
];
$interwikiCache = eval( '?>' . file_get_contents( 'https://noc.wikimedia.org/conf/interwiki.php.txt' ) );
$i = 0;
$ok = true;
foreach ( $interwikiCache as $key => $value ) {
[ $prefix, $interwiki ] = explode( ':', $key, 2 );
if ( ( $replacementInterwiki = $deprecatedMapping[ $interwiki ] ?? null ) !== null ) {
$replacementKey = "$prefix:$replacementInterwiki";
++$i;
if ( ( $replacementValue = $interwikiCache[ $replacementKey ] ) === $value ) {
echo "ok $i - $key == $replacementKey" . PHP_EOL;
} else {
echo "not ok $i - $key ($value) !== $replacementKey ($replacementValue)" . PHP_EOL;
$ok = false;
}
}
}
echo "1..$i" . PHP_EOL;
exit( $ok ? 0 : 1 );

Event Timeline

Script to verify that making Wikibase emit e.g. [[be-tarask:xyz]] instead of [[be-x-old:xyz]], as proposed by Ide36585f2c for T112426, is sound for all deprecated language codes. Emits TAP-like output (but without a version) and exits nonzero on error.