新增根据拉丁化首字母,自动排序分类中的标题的功能。

通过设置 ```$wgCategoryCollation = 'latinize';``` 开启此功能
master
落雨楓 5 years ago
parent 38f295abf1
commit f9d7c82ad1

@ -44,3 +44,8 @@ https://static-www.isekai.cn:8082/api/toolkit/asciiurl/hanzi2pinyin
http://static-www.isekai.cn:8081/api/toolkit/asciiurl/hanzi2pinyin http://static-www.isekai.cn:8081/api/toolkit/asciiurl/hanzi2pinyin
``` ```
不保证稳定性建议自建daemon 不保证稳定性建议自建daemon
### 使用首字母排列分类中的标题
```php
$wgCategoryCollation = 'latinize';
```

@ -18,6 +18,7 @@
"LatinizeUrl\\Hooks": "includes/Hooks.php", "LatinizeUrl\\Hooks": "includes/Hooks.php",
"LatinizeUrl\\Hanzi2Pinyin": "includes/Hanzi2Pinyin.php", "LatinizeUrl\\Hanzi2Pinyin": "includes/Hanzi2Pinyin.php",
"LatinizeUrl\\Utils": "includes/Utils.php", "LatinizeUrl\\Utils": "includes/Utils.php",
"LatinizeUrl\\LatinizeCollation": "includes/LatinizeCollation.php",
"LatinizeUrl\\Patcher": "includes/Patcher.php", "LatinizeUrl\\Patcher": "includes/Patcher.php",
"LatinizeUrl\\SpecialCustomUrl": "specials/SpecialCustomUrl.php" "LatinizeUrl\\SpecialCustomUrl": "specials/SpecialCustomUrl.php"
}, },
@ -25,6 +26,9 @@
"LoadExtensionSchemaUpdates": [ "LoadExtensionSchemaUpdates": [
"LatinizeUrl\\Hooks::onLoadExtensionSchemaUpdates" "LatinizeUrl\\Hooks::onLoadExtensionSchemaUpdates"
], ],
"Collation::factory": [
"LatinizeUrl\\Hooks::onCollationFactory"
],
"SkinTemplateOutputPageBeforeExec": [ "SkinTemplateOutputPageBeforeExec": [
"LatinizeUrl\\Hooks::onSkinTemplateOutputPageBeforeExec" "LatinizeUrl\\Hooks::onSkinTemplateOutputPageBeforeExec"
], ],

@ -1,8 +1,9 @@
{ {
"latinizeurl_desc": "把url中的汉字转换成拼音", "latinizeurl_desc": "把url中的汉字转换成拼音",
"latinizeurl-customurl": "自定义URL", "latinizeurl-customurl": "自定义URL",
"customurl-legend": "自定义URL", "customurl-legend": "自定义URL",
"customurl-url-field-label": "你想要设置的URL", "customurl-url-field-label": "你想要设置的URL",
"customurl-url-field-help": "建议使用纯英语字符留空时会自动根据标题里的汉字生成对应的拼音URL", "customurl-url-field-help": "建议使用纯英语字符留空时会自动根据标题里的汉字生成对应的拼音URL。",
"customurl-set-success": "页面的URL已经设置为[[$1|$2]]" "customurl-set-success": "页面的URL已经设置为[[$1|$2]]",
"customurl-set-failed": "页面URL不可用。"
} }

@ -38,6 +38,7 @@ class Hooks {
public static function onInitializeParseTitle(Title &$title, $request){ public static function onInitializeParseTitle(Title &$title, $request){
global $wgLatinizeUrlForceRedirect; global $wgLatinizeUrlForceRedirect;
if(in_array($title->getNamespace(), self::$allowedNS)){
$realTitle = Utils::getTitleBySlugUrl($title); $realTitle = Utils::getTitleBySlugUrl($title);
if($realTitle){ if($realTitle){
$title = $realTitle; $title = $realTitle;
@ -49,10 +50,11 @@ class Hooks {
if($slug) $title = Title::newFromText($slug, $title->getNamespace()); if($slug) $title = Title::newFromText($slug, $title->getNamespace());
} }
} }
}
public static function onGetArticleUrl(\Title &$title, &$url, $query){ public static function onGetArticleUrl(\Title &$title, &$url, $query){
try { try {
if(Utils::titleSlugExists($title)){ if(in_array($title->getNamespace(), self::$allowedNS) && Utils::titleSlugExists($title)){
$slug = Utils::encodeUriComponent(Utils::getSlugUrlByTitle($title)); $slug = Utils::encodeUriComponent(Utils::getSlugUrlByTitle($title));
$titleEncoded = Utils::encodeUriComponent($title->getText()); $titleEncoded = Utils::encodeUriComponent($title->getText());
$url = str_replace($titleEncoded, $slug, $url); $url = str_replace($titleEncoded, $slug, $url);
@ -127,4 +129,11 @@ class Hooks {
$out->addModules('ext.latinizeurl.timeless'); $out->addModules('ext.latinizeurl.timeless');
} }
} }
public static function onCollationFactory($collationName, &$collationObject){
if($collationName == 'latinize'){
$collationObject = new LatinizeCollation();
}
return true;
}
} }

@ -0,0 +1,25 @@
<?php
namespace LatinizeUrl;
use Collation;
class LatinizeCollation extends Collation {
public function getSortKey($string){
$slug = Utils::getSlugByTitle($string);
if($slug){
return ucfirst($slug);
} else {
return $string;
}
}
public function getFirstLetter($string){
var_dump($string);
$slug = Utils::getSlugByTitle($string);
if($slug){
return strtoupper($slug[0]);
} else {
return mb_substr($string, 0, 1, 'UTF-8');
}
}
}

@ -37,8 +37,8 @@ class Utils {
$cond = [ $cond = [
'slug' => $slug, 'slug' => $slug,
]; ];
$cond['url'] = ['!', self::$dbr->addQuotes($excludeUrl)];
$cond['url'] = ['!', self::$dbr->addQuotes($excludeUrl)];
$res = self::$dbr->selectField('url_slug', 'COUNT(*)', $cond, __METHOD__); $res = self::$dbr->selectField('url_slug', 'COUNT(*)', $cond, __METHOD__);
return intval($res) > 0; return intval($res) > 0;
} else { } else {

@ -8,5 +8,9 @@
#ca-custom-url a { #ca-custom-url a {
.background-image-svg('./images/custom-url.svg', './images/custom-url.png'); .background-image-svg('./images/custom-url.svg', './images/custom-url.png');
} }
#page-tools #ca-custom-url a {
background-image: none;
}
} }
} }

@ -99,6 +99,7 @@ class SpecialCustomUrl extends FormSpecialPage
} else { } else {
$realSlug = Utils::addTitleSlugMap($this->title->getText(), $slug, [$slug], 1); $realSlug = Utils::addTitleSlugMap($this->title->getText(), $slug, [$slug], 1);
} }
$this->slug = $realSlug; $this->slug = $realSlug;
return true; return true;
} }

Loading…
Cancel
Save