diff --git a/README.md b/README.md index bced053..1b84fbd 100644 --- a/README.md +++ b/README.md @@ -43,4 +43,9 @@ $wgLatinizeUrlConfig['fallback'] = 'inner'; https://static-www.isekai.cn:8082/api/toolkit/asciiurl/hanzi2pinyin http://static-www.isekai.cn:8081/api/toolkit/asciiurl/hanzi2pinyin ``` -不保证稳定性,建议自建daemon \ No newline at end of file +不保证稳定性,建议自建daemon + +### 使用首字母排列分类中的标题 +```php +$wgCategoryCollation = 'latinize'; +``` \ No newline at end of file diff --git a/extension.json b/extension.json index c8f7744..441424b 100644 --- a/extension.json +++ b/extension.json @@ -18,6 +18,7 @@ "LatinizeUrl\\Hooks": "includes/Hooks.php", "LatinizeUrl\\Hanzi2Pinyin": "includes/Hanzi2Pinyin.php", "LatinizeUrl\\Utils": "includes/Utils.php", + "LatinizeUrl\\LatinizeCollation": "includes/LatinizeCollation.php", "LatinizeUrl\\Patcher": "includes/Patcher.php", "LatinizeUrl\\SpecialCustomUrl": "specials/SpecialCustomUrl.php" }, @@ -25,6 +26,9 @@ "LoadExtensionSchemaUpdates": [ "LatinizeUrl\\Hooks::onLoadExtensionSchemaUpdates" ], + "Collation::factory": [ + "LatinizeUrl\\Hooks::onCollationFactory" + ], "SkinTemplateOutputPageBeforeExec": [ "LatinizeUrl\\Hooks::onSkinTemplateOutputPageBeforeExec" ], diff --git a/i18n/zh-hans.json b/i18n/zh-hans.json index fd49662..eb951b6 100644 --- a/i18n/zh-hans.json +++ b/i18n/zh-hans.json @@ -1,8 +1,9 @@ { - "latinizeurl_desc": "把url中的汉字转换成拼音", + "latinizeurl_desc": "把url中的汉字转换成拼音。", "latinizeurl-customurl": "自定义URL", "customurl-legend": "自定义URL", "customurl-url-field-label": "你想要设置的URL:", - "customurl-url-field-help": "建议使用纯英语字符,留空时会自动根据标题里的汉字生成对应的拼音URL", - "customurl-set-success": "页面的URL已经设置为[[$1|$2]]" + "customurl-url-field-help": "建议使用纯英语字符,留空时会自动根据标题里的汉字生成对应的拼音URL。", + "customurl-set-success": "页面的URL已经设置为[[$1|$2]]", + "customurl-set-failed": "页面URL不可用。" } \ No newline at end of file diff --git a/includes/Hooks.php b/includes/Hooks.php index ae180d2..b04bf5f 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -38,21 +38,23 @@ class Hooks { public static function onInitializeParseTitle(Title &$title, $request){ global $wgLatinizeUrlForceRedirect; - $realTitle = Utils::getTitleBySlugUrl($title); - if($realTitle){ - $title = $realTitle; - $request->setVal('title', $title->getDBkey()); - } elseif($wgLatinizeUrlForceRedirect - && !($request->getVal('action') && $request->getVal('action') != 'view') - && in_array($title->getNamespace(), self::$allowedNS)) { //把原标题页面重定向到拼音页面 - $slug = Utils::getSlugUrlByTitle($title); - if($slug) $title = Title::newFromText($slug, $title->getNamespace()); + if(in_array($title->getNamespace(), self::$allowedNS)){ + $realTitle = Utils::getTitleBySlugUrl($title); + if($realTitle){ + $title = $realTitle; + $request->setVal('title', $title->getDBkey()); + } elseif($wgLatinizeUrlForceRedirect + && !($request->getVal('action') && $request->getVal('action') != 'view') + && in_array($title->getNamespace(), self::$allowedNS)) { //把原标题页面重定向到拼音页面 + $slug = Utils::getSlugUrlByTitle($title); + if($slug) $title = Title::newFromText($slug, $title->getNamespace()); + } } } public static function onGetArticleUrl(\Title &$title, &$url, $query){ try { - if(Utils::titleSlugExists($title)){ + if(in_array($title->getNamespace(), self::$allowedNS) && Utils::titleSlugExists($title)){ $slug = Utils::encodeUriComponent(Utils::getSlugUrlByTitle($title)); $titleEncoded = Utils::encodeUriComponent($title->getText()); $url = str_replace($titleEncoded, $slug, $url); @@ -127,4 +129,11 @@ class Hooks { $out->addModules('ext.latinizeurl.timeless'); } } + + public static function onCollationFactory($collationName, &$collationObject){ + if($collationName == 'latinize'){ + $collationObject = new LatinizeCollation(); + } + return true; + } } \ No newline at end of file diff --git a/includes/LatinizeCollation.php b/includes/LatinizeCollation.php new file mode 100644 index 0000000..eb812ce --- /dev/null +++ b/includes/LatinizeCollation.php @@ -0,0 +1,25 @@ + $slug, ]; - $cond['url'] = ['!', self::$dbr->addQuotes($excludeUrl)]; + $cond['url'] = ['!', self::$dbr->addQuotes($excludeUrl)]; $res = self::$dbr->selectField('url_slug', 'COUNT(*)', $cond, __METHOD__); return intval($res) > 0; } else { diff --git a/modules/Timeless.less b/modules/Timeless.less index db35a67..370d571 100644 --- a/modules/Timeless.less +++ b/modules/Timeless.less @@ -8,5 +8,9 @@ #ca-custom-url a { .background-image-svg('./images/custom-url.svg', './images/custom-url.png'); } + + #page-tools #ca-custom-url a { + background-image: none; + } } } \ No newline at end of file diff --git a/specials/SpecialCustomUrl.php b/specials/SpecialCustomUrl.php index a8d14f2..ba90138 100644 --- a/specials/SpecialCustomUrl.php +++ b/specials/SpecialCustomUrl.php @@ -99,6 +99,7 @@ class SpecialCustomUrl extends FormSpecialPage } else { $realSlug = Utils::addTitleSlugMap($this->title->getText(), $slug, [$slug], 1); } + $this->slug = $realSlug; return true; }