diff --git a/extension.json b/extension.json index db6ba84..b8c8f6e 100644 --- a/extension.json +++ b/extension.json @@ -21,7 +21,14 @@ "Hooks": { "BeforePageDisplay": [ "Isekai\\OffcanvasToc\\Hooks::onLoad" - ] + ], + + "GetPreferences": [ + "Isekai\\OffcanvasToc\\Hooks::onGetPreferences" + ] + }, + "DefaultUserOptions": { + "offcanvas-toc-enabled": true }, "ResourceModules": { "ext.isekai.offcanvas-toc": { diff --git a/i18n/en.json b/i18n/en.json index 1ed6f2c..d0a11ff 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -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" } \ No newline at end of file diff --git a/i18n/zh-hans.json b/i18n/zh-hans.json index fa38785..514ec9b 100644 --- a/i18n/zh-hans.json +++ b/i18n/zh-hans.json @@ -1,4 +1,6 @@ { "isekai-offcanvastoc-name": "异世界百科 悬浮目录", - "isekai-offcanvastoc-desc": "在页面上显示悬浮目录" + "isekai-offcanvastoc-desc": "在页面上显示悬浮目录", + "prefs-offcanvas-toc": "悬浮目录", + "offcanvas-toc-enabled": "显示悬浮目录" } \ No newline at end of file diff --git a/includes/Hooks.php b/includes/Hooks.php index e2b29b4..14a85d7 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -1,26 +1,43 @@ enableOOUI(); - $outputPage->addModules('ext.isekai.offcanvas-toc'); - $outputPage->addModules('oojs-ui.styles.icons-layout'); + $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'); - $outputPage->addHTML(Html::openElement('div', [ - 'id' => 'isekai-offcanvas-toc', - 'class' => 'toc-offcanvas' - ]) . Html::element('ul') . Html::closeElement('div')); + $outputPage->addHTML(Html::openElement('div', [ + 'id' => 'isekai-offcanvas-toc', + 'class' => 'toc-offcanvas' + ]) . Html::element('ul') . Html::closeElement('div')); - $outputPage->addHTML(Html::openElement('button', [ - 'id' => 'iseai-offcanvas-btn', - 'class' => 'toc-offcanvas-btn' - ]) . new \OOUI\IconWidget([ - 'icon' => 'menu' - ]) . Html::closeElement('button')); + $outputPage->addHTML(Html::openElement('button', [ + 'id' => 'iseai-offcanvas-btn', + 'class' => 'toc-offcanvas-btn' + ]) . new \OOUI\IconWidget([ + 'icon' => 'menu' + ]) . 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; } } \ No newline at end of file