From 89436af1e2819087c5ea2c56f76d16f880d09870 Mon Sep 17 00:00:00 2001 From: hyperzlib Date: Mon, 12 Oct 2020 10:42:06 +0800 Subject: [PATCH] Compare with mw 1.35 --- ChineseConvertor/ChineseConvertor.php | 5 +++-- JapaneseConvertor/JapaneseConvertor.php | 3 ++- JapaneseConvertor/extension.json | 3 +++ bin/updatePinyinUrl.php | 5 +++-- extension.json | 2 +- includes/Hooks.php | 7 +++++-- includes/Patcher.php | 2 +- includes/Utils.php | 2 +- specials/SpecialCustomUrl.php | 5 ++++- 9 files changed, 23 insertions(+), 11 deletions(-) diff --git a/ChineseConvertor/ChineseConvertor.php b/ChineseConvertor/ChineseConvertor.php index a8f24bc..8695c1f 100644 --- a/ChineseConvertor/ChineseConvertor.php +++ b/ChineseConvertor/ChineseConvertor.php @@ -7,6 +7,7 @@ use MediaWiki\Http\HttpRequestFactory; use Fukuball\Jieba\Jieba; use Fukuball\Jieba\Finalseg; use Fukuball\Jieba\Posseg; +use MediaWiki\MediaWikiServices; use Overtrue\Pinyin\Pinyin; class ChineseConvertor extends BaseConvertor { @@ -120,7 +121,7 @@ class ChineseConvertor extends BaseConvertor { */ public function hookParse($hanzi){ $pinyinList = null; - \Hooks::run('Pinyin2Hanzi', [$hanzi, &$pinyinList]); + MediaWikiServices::getInstance()->getHookContainer()->run('Pinyin2Hanzi', [$hanzi, &$pinyinList]); if(!$pinyinList){ if(isset($this->config['fallback'])){ return $this->parse($hanzi, $this->config['fallback']); @@ -142,7 +143,7 @@ class ChineseConvertor extends BaseConvertor { if(!isset($this->config['url'])){ throw new Exception('LatinizeUrl remote api url not set.'); } - $factory = new HttpRequestFactory(); + $factory = MediaWikiServices::getInstance()->getHttpRequestFactory(); $req = $factory->create($this->config['url'], [ 'method' => 'POST', 'postData' => [ diff --git a/JapaneseConvertor/JapaneseConvertor.php b/JapaneseConvertor/JapaneseConvertor.php index 9a78e33..144fa92 100644 --- a/JapaneseConvertor/JapaneseConvertor.php +++ b/JapaneseConvertor/JapaneseConvertor.php @@ -4,6 +4,7 @@ namespace LatinizeUrl; use Exception; use MediaWiki\Http\HttpRequestFactory; +use MediaWiki\MediaWikiServices; class JapaneseConvertor extends BaseConvertor { private $config; @@ -32,7 +33,7 @@ class JapaneseConvertor extends BaseConvertor { if(!isset($this->config['url'])){ throw new Exception('LatinizeUrl remote api url not set.'); } - $factory = new HttpRequestFactory(); + $factory = MediaWikiServices::getInstance()->getHttpRequestFactory(); $req = $factory->create($this->config['url'], [ 'method' => 'POST', 'postData' => [ diff --git a/JapaneseConvertor/extension.json b/JapaneseConvertor/extension.json index bae4a20..437e714 100644 --- a/JapaneseConvertor/extension.json +++ b/JapaneseConvertor/extension.json @@ -6,6 +6,9 @@ "version": "1.0.1", "license-name": "MIT", "type": "other", + "requires": { + "MediaWiki": ">= 1.35.0" + }, "MessagesDirs": { "JapaneseConvertor": [ "i18n" diff --git a/bin/updatePinyinUrl.php b/bin/updatePinyinUrl.php index 2a02066..7d0c80c 100644 --- a/bin/updatePinyinUrl.php +++ b/bin/updatePinyinUrl.php @@ -3,6 +3,7 @@ require_once dirname(__DIR__, 3) . '/maintenance/Maintenance.php'; require_once dirname(__DIR__) . '/includes/Hanzi2Pinyin.php'; require_once dirname(__DIR__) . '/includes/Utils.php'; +use LatinizeUrl\ChineseConvertor; use LatinizeUrl\Hanzi2Pinyin; use LatinizeUrl\Utils; @@ -39,7 +40,7 @@ class UpdateLatinizeUrl extends Maintenance { $this->fatalError( "This change is only needed on MySQL, quitting.\n" ); } - $convertor = new Hanzi2Pinyin($wgLatinizeUrlConfig); + $convertor = new ChineseConvertor($wgLatinizeUrlConfig); $res = $this->findRows( $dbw ); foreach($res as $one){ @@ -48,7 +49,7 @@ class UpdateLatinizeUrl extends Maintenance { if(!$force && !$isCustom && Utils::titleSlugExists($title)) continue; $pinyin = $convertor->parse($title); - $slug = $convertor->pinyin2String($pinyin); + $slug = $convertor->parse($pinyin); echo $title . ' -> ' . $slug . PHP_EOL; if($outputFile){ $pair = [$this->getFullUrl($title), $this->getFullUrl($slug)]; diff --git a/extension.json b/extension.json index fd6ec78..af38cf1 100644 --- a/extension.json +++ b/extension.json @@ -3,7 +3,7 @@ "author": "hyperzlib", "url": "https://github.com/Isekai-Project/mediawiki-extension-LatinizeUrl", "descriptionmsg": "latinizeurl-desc", - "version": "1.0.1", + "version": "1.0.2", "license-name": "MIT", "type": "other", "ExtensionMessagesFiles": { diff --git a/includes/Hooks.php b/includes/Hooks.php index b823f10..925196a 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -7,6 +7,7 @@ use OutputPage; use User; use MediaWiki\Linker\LinkRenderer; use MediaWiki\Linker\LinkTarget; +use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\DBQueryError; class Hooks { @@ -112,10 +113,12 @@ class Hooks { } public static function onSkinTemplateOutputPageBeforeExec(\Skin $skin, \QuickTemplate $template){ - global $wgUser; + $service = MediaWikiServices::getInstance(); + $user = $skin->getContext()->getUser(); + $title = $skin->getRelevantTitle(); 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'] = [ 'class' => false, 'text' => wfMessage('latinizeurl-customurl')->text(), diff --git a/includes/Patcher.php b/includes/Patcher.php index 5f09087..a9e0ba9 100644 --- a/includes/Patcher.php +++ b/includes/Patcher.php @@ -29,7 +29,7 @@ class Patcher { public function patchInitializeParseTitleHook(){ $patchName = 'InitializeParseTitleHook'; - $patchContent = ['Hooks::run( \'InitializeParseTitle\', [ &$ret, $request ] );']; + $patchContent = ['MediaWikiServices::getInstance()->getHookContainer()->run( \'InitializeParseTitle\', [ &$ret, $request ] );']; $patchFinalContent = $this->makePatchContent($patchName, $patchContent, 2); $currentPatch = $this->findPatchVersion($patchName); if($currentPatch){ diff --git a/includes/Utils.php b/includes/Utils.php index f525fbb..55291be 100644 --- a/includes/Utils.php +++ b/includes/Utils.php @@ -325,7 +325,7 @@ class Utils { $convertor = null; - MWHooks::run('LatinizeUrlGetConvertor', [ + MediaWikiServices::getInstance()->getHookContainer()->run('LatinizeUrlGetConvertor', [ $language, &$convertor, ]); diff --git a/specials/SpecialCustomUrl.php b/specials/SpecialCustomUrl.php index 40ed9eb..ee4d9bb 100644 --- a/specials/SpecialCustomUrl.php +++ b/specials/SpecialCustomUrl.php @@ -2,6 +2,7 @@ namespace LatinizeUrl; use FormSpecialPage; +use MediaWiki\MediaWikiServices; class SpecialCustomUrl extends FormSpecialPage { @@ -30,6 +31,7 @@ class SpecialCustomUrl extends FormSpecialPage } protected function setParameter( $par ) { + $service = MediaWikiServices::getInstance(); $title = \Title::newFromText( $par ); $this->title = $title; @@ -40,7 +42,8 @@ class SpecialCustomUrl extends FormSpecialPage throw new \ErrorPageError( 'nopagetitle', 'nopagetext' ); } - $isAdmin = $this->getUser()->isAllowed('delete'); + + $isAdmin = $service->getPermissionManager()->userHasRight($this->getUser(), 'delete'); $this->isAdmin = $isAdmin; $userEditedPage = Utils::hasUserEditedPage($this->title, $this->getUser()); $this->userEditedPage = $userEditedPage;