Compare with mw 1.35

master
落雨楓 4 years ago
parent a7c07147e3
commit 89436af1e2

@ -7,6 +7,7 @@ use MediaWiki\Http\HttpRequestFactory;
use Fukuball\Jieba\Jieba; use Fukuball\Jieba\Jieba;
use Fukuball\Jieba\Finalseg; use Fukuball\Jieba\Finalseg;
use Fukuball\Jieba\Posseg; use Fukuball\Jieba\Posseg;
use MediaWiki\MediaWikiServices;
use Overtrue\Pinyin\Pinyin; use Overtrue\Pinyin\Pinyin;
class ChineseConvertor extends BaseConvertor { class ChineseConvertor extends BaseConvertor {
@ -120,7 +121,7 @@ class ChineseConvertor extends BaseConvertor {
*/ */
public function hookParse($hanzi){ public function hookParse($hanzi){
$pinyinList = null; $pinyinList = null;
\Hooks::run('Pinyin2Hanzi', [$hanzi, &$pinyinList]); MediaWikiServices::getInstance()->getHookContainer()->run('Pinyin2Hanzi', [$hanzi, &$pinyinList]);
if(!$pinyinList){ if(!$pinyinList){
if(isset($this->config['fallback'])){ if(isset($this->config['fallback'])){
return $this->parse($hanzi, $this->config['fallback']); return $this->parse($hanzi, $this->config['fallback']);
@ -142,7 +143,7 @@ class ChineseConvertor extends BaseConvertor {
if(!isset($this->config['url'])){ if(!isset($this->config['url'])){
throw new Exception('LatinizeUrl remote api url not set.'); throw new Exception('LatinizeUrl remote api url not set.');
} }
$factory = new HttpRequestFactory(); $factory = MediaWikiServices::getInstance()->getHttpRequestFactory();
$req = $factory->create($this->config['url'], [ $req = $factory->create($this->config['url'], [
'method' => 'POST', 'method' => 'POST',
'postData' => [ 'postData' => [

@ -4,6 +4,7 @@ namespace LatinizeUrl;
use Exception; use Exception;
use MediaWiki\Http\HttpRequestFactory; use MediaWiki\Http\HttpRequestFactory;
use MediaWiki\MediaWikiServices;
class JapaneseConvertor extends BaseConvertor { class JapaneseConvertor extends BaseConvertor {
private $config; private $config;
@ -32,7 +33,7 @@ class JapaneseConvertor extends BaseConvertor {
if(!isset($this->config['url'])){ if(!isset($this->config['url'])){
throw new Exception('LatinizeUrl remote api url not set.'); throw new Exception('LatinizeUrl remote api url not set.');
} }
$factory = new HttpRequestFactory(); $factory = MediaWikiServices::getInstance()->getHttpRequestFactory();
$req = $factory->create($this->config['url'], [ $req = $factory->create($this->config['url'], [
'method' => 'POST', 'method' => 'POST',
'postData' => [ 'postData' => [

@ -6,6 +6,9 @@
"version": "1.0.1", "version": "1.0.1",
"license-name": "MIT", "license-name": "MIT",
"type": "other", "type": "other",
"requires": {
"MediaWiki": ">= 1.35.0"
},
"MessagesDirs": { "MessagesDirs": {
"JapaneseConvertor": [ "JapaneseConvertor": [
"i18n" "i18n"

@ -3,6 +3,7 @@ require_once dirname(__DIR__, 3) . '/maintenance/Maintenance.php';
require_once dirname(__DIR__) . '/includes/Hanzi2Pinyin.php'; require_once dirname(__DIR__) . '/includes/Hanzi2Pinyin.php';
require_once dirname(__DIR__) . '/includes/Utils.php'; require_once dirname(__DIR__) . '/includes/Utils.php';
use LatinizeUrl\ChineseConvertor;
use LatinizeUrl\Hanzi2Pinyin; use LatinizeUrl\Hanzi2Pinyin;
use LatinizeUrl\Utils; use LatinizeUrl\Utils;
@ -39,7 +40,7 @@ class UpdateLatinizeUrl extends Maintenance {
$this->fatalError( "This change is only needed on MySQL, quitting.\n" ); $this->fatalError( "This change is only needed on MySQL, quitting.\n" );
} }
$convertor = new Hanzi2Pinyin($wgLatinizeUrlConfig); $convertor = new ChineseConvertor($wgLatinizeUrlConfig);
$res = $this->findRows( $dbw ); $res = $this->findRows( $dbw );
foreach($res as $one){ foreach($res as $one){
@ -48,7 +49,7 @@ class UpdateLatinizeUrl extends Maintenance {
if(!$force && !$isCustom && Utils::titleSlugExists($title)) continue; if(!$force && !$isCustom && Utils::titleSlugExists($title)) continue;
$pinyin = $convertor->parse($title); $pinyin = $convertor->parse($title);
$slug = $convertor->pinyin2String($pinyin); $slug = $convertor->parse($pinyin);
echo $title . ' -> ' . $slug . PHP_EOL; echo $title . ' -> ' . $slug . PHP_EOL;
if($outputFile){ if($outputFile){
$pair = [$this->getFullUrl($title), $this->getFullUrl($slug)]; $pair = [$this->getFullUrl($title), $this->getFullUrl($slug)];

@ -3,7 +3,7 @@
"author": "hyperzlib", "author": "hyperzlib",
"url": "https://github.com/Isekai-Project/mediawiki-extension-LatinizeUrl", "url": "https://github.com/Isekai-Project/mediawiki-extension-LatinizeUrl",
"descriptionmsg": "latinizeurl-desc", "descriptionmsg": "latinizeurl-desc",
"version": "1.0.1", "version": "1.0.2",
"license-name": "MIT", "license-name": "MIT",
"type": "other", "type": "other",
"ExtensionMessagesFiles": { "ExtensionMessagesFiles": {

@ -7,6 +7,7 @@ use OutputPage;
use User; use User;
use MediaWiki\Linker\LinkRenderer; use MediaWiki\Linker\LinkRenderer;
use MediaWiki\Linker\LinkTarget; use MediaWiki\Linker\LinkTarget;
use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\DBQueryError; use Wikimedia\Rdbms\DBQueryError;
class Hooks { class Hooks {
@ -112,10 +113,12 @@ class Hooks {
} }
public static function onSkinTemplateOutputPageBeforeExec(\Skin $skin, \QuickTemplate $template){ public static function onSkinTemplateOutputPageBeforeExec(\Skin $skin, \QuickTemplate $template){
global $wgUser; $service = MediaWikiServices::getInstance();
$user = $skin->getContext()->getUser();
$title = $skin->getRelevantTitle(); $title = $skin->getRelevantTitle();
if(in_array($title->getNamespace(), self::$allowedNS)){ if(in_array($title->getNamespace(), self::$allowedNS)){
if($wgUser->isAllowed('delete') || Utils::hasUserEditedPage($title, $wgUser)){ if($service->getPermissionManager()->userHasRight($user, 'delete') || Utils::hasUserEditedPage($title, $user)){
$template->data['content_navigation']['page-secondary']['custom-url'] = [ $template->data['content_navigation']['page-secondary']['custom-url'] = [
'class' => false, 'class' => false,
'text' => wfMessage('latinizeurl-customurl')->text(), 'text' => wfMessage('latinizeurl-customurl')->text(),

@ -29,7 +29,7 @@ class Patcher {
public function patchInitializeParseTitleHook(){ public function patchInitializeParseTitleHook(){
$patchName = 'InitializeParseTitleHook'; $patchName = 'InitializeParseTitleHook';
$patchContent = ['Hooks::run( \'InitializeParseTitle\', [ &$ret, $request ] );']; $patchContent = ['MediaWikiServices::getInstance()->getHookContainer()->run( \'InitializeParseTitle\', [ &$ret, $request ] );'];
$patchFinalContent = $this->makePatchContent($patchName, $patchContent, 2); $patchFinalContent = $this->makePatchContent($patchName, $patchContent, 2);
$currentPatch = $this->findPatchVersion($patchName); $currentPatch = $this->findPatchVersion($patchName);
if($currentPatch){ if($currentPatch){

@ -325,7 +325,7 @@ class Utils {
$convertor = null; $convertor = null;
MWHooks::run('LatinizeUrlGetConvertor', [ MediaWikiServices::getInstance()->getHookContainer()->run('LatinizeUrlGetConvertor', [
$language, $language,
&$convertor, &$convertor,
]); ]);

@ -2,6 +2,7 @@
namespace LatinizeUrl; namespace LatinizeUrl;
use FormSpecialPage; use FormSpecialPage;
use MediaWiki\MediaWikiServices;
class SpecialCustomUrl extends FormSpecialPage class SpecialCustomUrl extends FormSpecialPage
{ {
@ -30,6 +31,7 @@ class SpecialCustomUrl extends FormSpecialPage
} }
protected function setParameter( $par ) { protected function setParameter( $par ) {
$service = MediaWikiServices::getInstance();
$title = \Title::newFromText( $par ); $title = \Title::newFromText( $par );
$this->title = $title; $this->title = $title;
@ -40,7 +42,8 @@ class SpecialCustomUrl extends FormSpecialPage
throw new \ErrorPageError( 'nopagetitle', 'nopagetext' ); throw new \ErrorPageError( 'nopagetitle', 'nopagetext' );
} }
$isAdmin = $this->getUser()->isAllowed('delete');
$isAdmin = $service->getPermissionManager()->userHasRight($this->getUser(), 'delete');
$this->isAdmin = $isAdmin; $this->isAdmin = $isAdmin;
$userEditedPage = Utils::hasUserEditedPage($this->title, $this->getUser()); $userEditedPage = Utils::hasUserEditedPage($this->title, $this->getUser());
$this->userEditedPage = $userEditedPage; $this->userEditedPage = $userEditedPage;

Loading…
Cancel
Save