增加用户参数配置

main
落雨楓 3 years ago
parent 45b571cf29
commit 06bbc2c193

@ -21,8 +21,15 @@
"Hooks": {
"BeforePageDisplay": [
"Isekai\\OffcanvasToc\\Hooks::onLoad"
],
"GetPreferences": [
"Isekai\\OffcanvasToc\\Hooks::onGetPreferences"
]
},
"DefaultUserOptions": {
"offcanvas-toc-enabled": true
},
"ResourceModules": {
"ext.isekai.offcanvas-toc": {
"scripts": ["ext.isekai.offcanvas-toc.js"],

@ -1,4 +1,6 @@
{
"isekai-offcanvastoc-name": "Isekai Offcanvas TOC",
"isekai-offcanvastoc-desc": "Show Offcanvas TOC on wiki"
"isekai-offcanvastoc-desc": "Show Offcanvas TOC on wiki",
"prefs-offcanvas-toc": "Offcanvas TOC",
"offcanvas-toc-enabled": "Show offcanvas TOC"
}

@ -1,4 +1,6 @@
{
"isekai-offcanvastoc-name": "异世界百科 悬浮目录",
"isekai-offcanvastoc-desc": "在页面上显示悬浮目录"
"isekai-offcanvastoc-desc": "在页面上显示悬浮目录",
"prefs-offcanvas-toc": "悬浮目录",
"offcanvas-toc-enabled": "显示悬浮目录"
}

@ -1,10 +1,16 @@
<?php
namespace Isekai\OffcanvasToc;
use MediaWiki\MediaWikiServices;
use Html;
class Hooks {
public static function onLoad(\OutputPage $outputPage) {
$service = MediaWikiServices::getInstance();
if (
$outputPage->getTitle()->isContentPage() &&
$service->getUserOptionsLookup()->getOption($outputPage->getUser(), 'offcanvas-toc-enabled')
) {
$outputPage->enableOOUI();
$outputPage->addModules('ext.isekai.offcanvas-toc');
$outputPage->addModules('oojs-ui.styles.icons-layout');
@ -23,4 +29,15 @@ class Hooks {
$outputPage->addElement('div', ['id' => 'isekai-offcanvas-cover', 'class' => 'toc-offcanvas-cover']);
}
}
public static function onGetPreferences(\User $user, array &$preferences) {
$preferences['offcanvas-toc-enabled'] = [
'type' => 'toggle',
'label-message' => 'offcanvas-toc-enabled',
'section' => 'rendering/offcanvas-toc'
];
return true;
}
}
Loading…
Cancel
Save