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\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' => [

@ -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' => [

@ -6,6 +6,9 @@
"version": "1.0.1",
"license-name": "MIT",
"type": "other",
"requires": {
"MediaWiki": ">= 1.35.0"
},
"MessagesDirs": {
"JapaneseConvertor": [
"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/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)];

@ -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": {

@ -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(),

@ -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){

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

@ -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;

Loading…
Cancel
Save