增加用户参数配置
parent
45b571cf29
commit
06bbc2c193
@ -1,4 +1,6 @@
|
|||||||
{
|
{
|
||||||
"isekai-offcanvastoc-name": "Isekai Offcanvas TOC",
|
"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-name": "异世界百科 悬浮目录",
|
||||||
"isekai-offcanvastoc-desc": "在页面上显示悬浮目录"
|
"isekai-offcanvastoc-desc": "在页面上显示悬浮目录",
|
||||||
|
"prefs-offcanvas-toc": "悬浮目录",
|
||||||
|
"offcanvas-toc-enabled": "显示悬浮目录"
|
||||||
}
|
}
|
@ -1,26 +1,43 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Isekai\OffcanvasToc;
|
namespace Isekai\OffcanvasToc;
|
||||||
|
|
||||||
|
use MediaWiki\MediaWikiServices;
|
||||||
use Html;
|
use Html;
|
||||||
|
|
||||||
class Hooks {
|
class Hooks {
|
||||||
public static function onLoad(\OutputPage $outputPage) {
|
public static function onLoad(\OutputPage $outputPage) {
|
||||||
$outputPage->enableOOUI();
|
$service = MediaWikiServices::getInstance();
|
||||||
$outputPage->addModules('ext.isekai.offcanvas-toc');
|
if (
|
||||||
$outputPage->addModules('oojs-ui.styles.icons-layout');
|
$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');
|
||||||
|
|
||||||
$outputPage->addHTML(Html::openElement('div', [
|
$outputPage->addHTML(Html::openElement('div', [
|
||||||
'id' => 'isekai-offcanvas-toc',
|
'id' => 'isekai-offcanvas-toc',
|
||||||
'class' => 'toc-offcanvas'
|
'class' => 'toc-offcanvas'
|
||||||
]) . Html::element('ul') . Html::closeElement('div'));
|
]) . Html::element('ul') . Html::closeElement('div'));
|
||||||
|
|
||||||
$outputPage->addHTML(Html::openElement('button', [
|
$outputPage->addHTML(Html::openElement('button', [
|
||||||
'id' => 'iseai-offcanvas-btn',
|
'id' => 'iseai-offcanvas-btn',
|
||||||
'class' => 'toc-offcanvas-btn'
|
'class' => 'toc-offcanvas-btn'
|
||||||
]) . new \OOUI\IconWidget([
|
]) . new \OOUI\IconWidget([
|
||||||
'icon' => 'menu'
|
'icon' => 'menu'
|
||||||
]) . Html::closeElement('button'));
|
]) . Html::closeElement('button'));
|
||||||
|
|
||||||
$outputPage->addElement('div', ['id' => 'isekai-offcanvas-cover', 'class' => 'toc-offcanvas-cover']);
|
$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…
Reference in New Issue