Skip to content

Commit b62bee6

Browse files
committed
Store the source language of TL-included pages.
Originally, this was meant to establish consistency with a new `tpc_games` table, which would have included a language code in order to automatically set the correct source language for non-TL-included pages (like the omake.txt and HTML Manual ones). After thinking about that idea for a while, I wasn't convinced that it justified the added complexity, but this commit still seems like a good one: Adding a code to `tpc_tl_source_pages` allows us to ditch getNamespaceBaseLanguage(), and supports the hypothetical use case of non-Japanese game translation with this extension.
1 parent 44d9f3f commit b62bee6

File tree

5 files changed

+17
-19
lines changed

5 files changed

+17
-19
lines changed

TPCPatchMap.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ protected static function mergePatch( &$map, &$patch ) {
2626
// -------------------------
2727

2828
/**
29-
* @return bool `true` if the given page is part of `tpc_tl_source_pages`.
29+
* @return ?string Source language of the given page, if it is part of `tpc_tl_source_pages`.
3030
*/
31-
public static function isTLIncludedPage( int $namespace, string $title ): bool {
31+
public static function getTLPageSourceLanguage( int $namespace, string $title ): ?string {
3232
$dbr = MediaWikiServices::getInstance()->getDBLoadBalancer()->getConnection( DB_REPLICA );
33-
return $dbr->selectRow( 'tpc_tl_source_pages', 1, array(
33+
$row = $dbr->selectRow( 'tpc_tl_source_pages', 'tlsp_code', array(
3434
'tlsp_namespace' => $namespace,
3535
'tlsp_title' => $title
36-
)) !== false;
36+
));
37+
return ( $row->tlsp_code ?? null );
3738
}
3839

3940
/**
@@ -115,17 +116,17 @@ public static function get( $title ) {
115116
$root = $title->getRootText(); // Might indicate a game
116117

117118
// Source page?
118-
if ( self::isTLIncludedPage( $namespace, $title->getText() ) ) {
119+
if ( $code = self::getTLPageSourceLanguage( $namespace, $title->getText() ) ) {
119120
$game = $title->isSubpage() ? lcfirst( $root ) : "";
120-
return self::buildTLMapping( $game, TPCUtil::getNamespaceBaseLanguage( $namespace ) );
121+
return self::buildTLMapping( $game, $code );
121122
}
122123

123124
// If $title is a translated page, getBaseText() gives us the source page…
124125
$base = $title->getBaseText();
125126

126127
// … which we can check against the same database table to check if this is a translated
127128
// page of a registered source page.
128-
if ( self::isTLIncludedPage( $namespace, $base ) ) {
129+
if ( self::getTLPageSourceLanguage( $namespace, $base ) ) {
129130
$game = ( $root != $base ) ? lcfirst( $root ) : "";
130131
return self::buildTLMapping( $game, $title->getSubpageText() );
131132
}

TPCUtil.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@
88
*/
99

1010
class TPCUtil {
11-
/**
12-
* Returns the language of original content in the given namespace.
13-
*
14-
* @param int $namespace Namespace number
15-
* @return string Language code
16-
*/
17-
public static function getNamespaceBaseLanguage( $namespace ) {
18-
return $namespace == 0 ? 'ja' : $wgLanguageCode;
19-
}
20-
2111
/**
2212
* Normalizes a hook name.
2313
*

TouhouPatchCenter.body.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ public static function onMultiContentSave(
226226

227227
public static function onPageContentLanguage( Title $title, &$pageLang, $userLang ) {
228228
$namespace = $title->getNamespace();
229-
if ( TPCPatchMap::isTLIncludedPage( $namespace, $title->getText() ) ) {
230-
$pageLang = Language::factory( TPCUtil::getNamespaceBaseLanguage( $namespace ) );
229+
if ( $code = TPCPatchMap::getTLPageSourceLanguage( $namespace, $title->getText() ) ) {
230+
$pageLang = Language::factory( $code );
231231
}
232232
}
233233

hooks/TPCInclude.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ public static function onTLInclude( &$tpcState, &$title, &$temp ) {
7676
$insert = array(
7777
'tlsp_namespace' => $targetTitle->getNamespace(),
7878
'tlsp_title' => $targetTitle->getText(),
79+
80+
// This makes hypothetical support for non-Japanese games as easy as reading this value
81+
// from $temp->params[2] instead.
82+
'tlsp_code' => 'ja',
7983
);
8084
$dbw->insert( 'tpc_tl_source_pages', $insert, __METHOD__, 'IGNORE' );
8185
return true;

tpc_tl_source_pages.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ CREATE TABLE /*_*/tpc_tl_source_pages (
77
-- Page title
88
tlsp_title varchar(255) NOT NULL,
99

10+
-- Source language code
11+
tlsp_code varchar(63) NOT NULL,
12+
1013
PRIMARY KEY (tlsp_namespace, tlsp_title)
1114
) /*$wgDBTableOptions*/;

0 commit comments

Comments
 (0)