Skip to content

Instantly share code, notes, and snippets.

@2nd-player
Created August 8, 2018 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 2nd-player/256e6ba09dfc2a56b4e0ebddf134df75 to your computer and use it in GitHub Desktop.
Save 2nd-player/256e6ba09dfc2a56b4e0ebddf134df75 to your computer and use it in GitHub Desktop.
<?php
if ( !defined( 'MEDIAWIKI' ) ) {
die( 'This file is a MediaWiki extension, it is not a valid entry point' );
}
# pwLatin1 MediaWiki Extension
# version 0.0.0a
# 2018 (c) Copyright 2nd-player
# ポケモンWiki 拡張機能案
#
# 記事名が拡張ラテン文字を含むとき、ASCIIに転写したDISPLAYTITLEを設定する. そして山札を切る.
#
# 使用法は例のごとくLocalSetings.phpでこのファイルをrequire_once
#
# compatible with MediaWiki 1.27.0 - 1.31.0
$wgExtensionCredits[][] = array(
'path' => __FILE__,
'name' => 'pwLatin1',
'author' => '[[User:2P]]',
'descriptionmsg' => '[[Project:環境依存文字]]'
);
$wgHooks['OutputPageParserOutput'][] = 'pwLatin1::pwLatin1Title';
$wgHooks['SkinTemplateOutputPageBeforeExec'][] = 'pwLatin1::pwLatin1Notice';
class pwLatin1{
static function pwLatin1subst($txt){
return str_replace(
array( 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'Þ', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'þ', 'ÿ'),
array( 'A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 'Y', 'S', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'd', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'y'),
$txt
);
}
static function pwLatin1Title(&$out,$parserout){
$title = $out->getTitle();
$ns = $title->getNamespace();
if ($ns == NS_MAIN){
$origtitle = $title->getText();
if($origtitle === $parserout->getDisplayTitle()){
$canonical = pwLatin1::pwLatin1subst($origtitle);
if ($canonical != $origtitle){
$parserout->setDisplayTitle( $canonical );
}
}
}
}
static function pwLatin1Notice(&$qtpl,&$tpl){
if ($qtpl->getRequest()->getVal( 'action', 'view' ) !== 'view'){
return 1;
}
$title = $qtpl->getTitle();
$ns = $title->getNamespace();
if ($ns == NS_MAIN){
$origtitle = $title->getText();
if ( $origtitle != pwLatin1::pwLatin1subst($origtitle) ){
# この位置からどうやってDISPLAYTITLE読むんだっけ?
$tpl->set( 'subtitle', "正確な記事名: ${origtitle}" );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment