2
0
镜像自地址 https://github.com/nbdd0121/MW-PinyinSort 已同步 2024-05-30 13:42:50 +08:00

Add pinyin-noprefix

这个提交包含在:
Gary Guo 2016-04-14 18:05:37 +01:00
父节点 8a1e0986d6
当前提交 3bea511a0a
共有 5 个文件被更改,包括 58 次插入10 次删除

查看文件

@ -1,4 +1,4 @@
# PinyinSort 0.1.0
# PinyinSort 0.2.0
Add pinyin as a category sorting collation
## Install
@ -7,3 +7,8 @@ Add pinyin as a category sorting collation
* Add `$wgCategoryCollation = 'pinyin';` to your LocalSettings.php to activate PinyinSort
* You need to run `updateCollation.php` as an post-requisite for changing collation.
* You are done!
## Configuration
* Alternatively, you can use `$wgCategoryCollation = 'pinyin-noprefix';` to automatically strip prefixes.
* For example, "Subproject:PageA" will be transformed to "PageA" during collation process.
* You need to run `updateCollation.php` as an post-requisite for changing collation.

查看文件

@ -12,10 +12,12 @@
]
},
"Hooks": {
"Collation::factory": "PinyinSort\\PinyinCollation::onFactory"
"Collation::factory": "PinyinSort\\Hooks::onFactory"
},
"AutoloadClasses": {
"PinyinSort\\Hooks": "includes/Hooks.php",
"PinyinSort\\PinyinCollation": "includes/PinyinCollation.php",
"PinyinSort\\PinyinCollationNoPrefix": "includes/PinyinCollationNoPrefix.php",
"PinyinSort\\Converter": "includes/Converter.php",
"PinyinSort\\ConversionTable": "includes/ConversionTable.php"
},

15
includes/Hooks.php 可执行文件
查看文件

@ -0,0 +1,15 @@
<?php
namespace PinyinSort;
class Hooks {
public static function onFactory($collationName, &$collationObj) {
if ($collationName === 'pinyin') {
$collationObj = new PinyinCollation();
} else if ($collationName === 'pinyin-noprefix') {
$collationObj = new PinyinCollationNoPrefix();
}
return true;
}
}

查看文件

@ -3,14 +3,6 @@ namespace PinyinSort;
class PinyinCollation extends \Collation {
public static function onFactory($collationName, &$collationObj) {
if ($collationName === 'pinyin') {
$collationObj = new PinyinCollation();
return true;
}
return false;
}
public function getSortKey($string) {
return ucfirst(Converter::zh2pinyin($string));
}

查看文件

@ -0,0 +1,34 @@
<?php
namespace PinyinSort;
class PinyinCollationNoPrefix extends \Collation {
private $collation;
public function __construct() {
$this->collation = new PinyinCollation();
}
private function process($string) {
if (strpos($string, "\n") !== false) {
return $string;
} else {
$parts = explode(':', $string, 2);
if (count($parts) !== 2) {
return $string;
} else {
return $parts[1] . "\n" . $string;
}
}
}
public function getSortKey($string) {
$string = $this->process($string);
return $this->collation->getSortKey($string);
}
public function getFirstLetter($string) {
$string = $this->process($string);
return $this->collation->getFirstLetter($string);
}
}