From 4a055965ec24ef60680bfc878f39c12583d2c3ef Mon Sep 17 00:00:00 2001 From: KitsuneSolar Date: Sun, 16 Jul 2023 23:53:43 +0000 Subject: [PATCH] 2023-07-16 23:53:43 --- .gitignore | 1 + CHANGELOG.md | 0 CONTRIBUTING.md | 13 ++++++ LICENSE | 2 +- MW_EXT_Spoiler.class.php | 93 +++++++++++++++++++++++++++++++++++++++ MW_EXT_Spoiler.php | 16 +++++++ README.md | 19 +++++++- composer.json | 46 +++++++++++++++++++ extension.json | 52 ++++++++++++++++++++++ i18n/ru.json | 9 ++++ modules/styles/_main.scss | 55 +++++++++++++++++++++++ modules/styles/theme.css | 1 + modules/styles/theme.scss | 1 + 13 files changed, 306 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 CONTRIBUTING.md create mode 100644 MW_EXT_Spoiler.class.php create mode 100644 MW_EXT_Spoiler.php create mode 100644 composer.json create mode 100644 extension.json create mode 100644 i18n/ru.json create mode 100644 modules/styles/_main.scss create mode 100644 modules/styles/theme.css create mode 100644 modules/styles/theme.scss diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f11b75 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e69de29 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..969906b --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,13 @@ +# Contributing + +- Feedback, wishes and suggestions can be sent by email. +- Constructive criticism, bug descriptions and other reports are welcome. +- Email: mail@ihub.to + +## Sources + +- [**GitHub**](https://github.com/pkgstore) +- [GitLab](https://gitlab.com/pkgstore) (MIRROR) +- [Codeberg](https://codeberg.org/pkgstore) (MIRROR) +- [MosHub](https://hub.mos.ru/pkgstore) (MIRROR) +- [Git.Org.Ru](https://git.org.ru/pkgstore) (MIRROR) diff --git a/LICENSE b/LICENSE index 8dbae8f..62a7665 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Package Store +Copyright (c) 2023 iHub TO Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/MW_EXT_Spoiler.class.php b/MW_EXT_Spoiler.class.php new file mode 100644 index 0000000..bae6234 --- /dev/null +++ b/MW_EXT_Spoiler.class.php @@ -0,0 +1,93 @@ +setHook('spoiler', [__CLASS__, 'onRenderTagSpoiler']); + $parser->setHook('hide', [__CLASS__, 'onRenderTagHide']); + } + + /** + * Render tag function: Spoiler. + * + * @param $input + * @param array $args + * @param Parser $parser + * @param PPFrame $frame + * + * @return string + */ + public static function onRenderTagSpoiler($input, array $args, Parser $parser, PPFrame $frame): string + { + // Argument: title. + $getTitle = MW_EXT_Kernel::outClear($args['title'] ?? '' ?: ''); + $outTitle = empty($getTitle) ? MW_EXT_Kernel::getMessageText('spoiler', 'title') : $getTitle; + + // Get content. + $getContent = trim($input); + $outContent = $parser->recursiveTagParse($getContent, $frame); + + // Out HTML. + $outHTML = ''; + + // Out parser. + return $outHTML; + } + + /** + * Render tag function: Hide. + * + * @param $input + * @param Parser $parser + * @param PPFrame $frame + * + * @return string + */ + public static function onRenderTagHide($input, Parser $parser, PPFrame $frame): string + { + // Get content. + $getContent = trim($input); + $outContent = $parser->recursiveTagParse($getContent, $frame); + + // Out HTML. + $outHTML = ''; + $outHTML .= '' . $outContent . ''; + $outHTML .= ''; + + // Out parser. + return $outHTML; + } + + /** + * Load resource function. + * + * @param OutputPage $out + * @param Skin $skin + * + * @return void + */ + public static function onBeforePageDisplay(OutputPage $out, Skin $skin): void + { + $out->addModuleStyles(['ext.mw.spoiler.styles']); + } +} diff --git a/MW_EXT_Spoiler.php b/MW_EXT_Spoiler.php new file mode 100644 index 0000000..bb7158e --- /dev/null +++ b/MW_EXT_Spoiler.php @@ -0,0 +1,16 @@ +[CONTENT] +``` diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..6496805 --- /dev/null +++ b/composer.json @@ -0,0 +1,46 @@ +{ + "name": "pkgstore/mediawiki-ext-spoiler", + "type": "mediawiki-extension", + "description": "MediaWiki spoiler extension.", + "license": "MIT", + "homepage": "https://ihub.to/", + "keywords": [ + "mediawiki", + "spoiler" + ], + "authors": [ + { + "name": "iHub TO", + "email": "mail@ihub.to", + "homepage": "https://ihub.to/", + "role": "Developer" + }, + { + "name": "Kitsune Solar", + "email": "mail@kitsune.solar", + "homepage": "https://kitsune.solar/", + "role": "Developer" + } + ], + "support": { + "issues": "https://github.com/pkgstore/mediawiki-ext-spoiler/issues", + "source": "https://github.com/pkgstore/mediawiki-ext-spoiler" + }, + "require": { + "composer/installers": "^1.0.1", + "php": ">=8.2", + "pkgstore/mediawiki-ext-kernel": "*" + }, + "autoload": { + "classmap": [ + "MW_EXT_Spoiler.class.php" + ] + }, + "config": { + "optimize-autoloader": true, + "prepend-autoloader": false + }, + "extra": { + "installer-name": "MW_EXT_Spoiler" + } +} diff --git a/extension.json b/extension.json new file mode 100644 index 0000000..9426d92 --- /dev/null +++ b/extension.json @@ -0,0 +1,52 @@ +{ + "name": "MW_EXT_Spoiler", + "version": "1.0.0", + "author": [ + "[https://ihub.to/ iHub TO]", + "[https://kitsune.solar/ Kitsune Solar]", + "..." + ], + "url": "https://ihub.to/", + "descriptionmsg": "mw-spoiler-desc", + "license-name": "[https://choosealicense.com/licenses/mit/ MIT]", + "type": "parserhook", + "require": { + "MediaWiki": ">= 1.31.0", + "extensions": { + "MW_EXT_Kernel": "*" + } + }, + "AutoloadClasses": { + "MediaWiki\\Extension\\PkgStore\\MW_EXT_Spoiler": "MW_EXT_Spoiler.class.php" + }, + "Hooks": { + "ParserFirstCallInit": [ + "MediaWiki\\Extension\\PkgStore\\MW_EXT_Spoiler::onParserFirstCallInit" + ], + "BeforePageDisplay": [ + "MediaWiki\\Extension\\PkgStore\\MW_EXT_Spoiler::onBeforePageDisplay" + ] + }, + "MessagesDirs": { + "MW_EXT_Spoiler": [ + "i18n" + ] + }, + "ResourceModules": { + "ext.mw.spoiler.styles": { + "styles": [ + "styles/theme.css" + ], + "position": "top", + "targets": [ + "desktop", + "mobile" + ] + } + }, + "ResourceFileModulePaths": { + "localBasePath": "modules", + "remoteExtPath": "MW_EXT_Spoiler/modules" + }, + "manifest_version": 2 +} diff --git a/i18n/ru.json b/i18n/ru.json new file mode 100644 index 0000000..a28c9b3 --- /dev/null +++ b/i18n/ru.json @@ -0,0 +1,9 @@ +{ + "@metadata": { + "authors": [ + "iHub TO" + ] + }, + "mw-spoiler-desc": "Блок со скрытой и отображаемой информацией.", + "mw-spoiler-title": "Скрытая информация" +} diff --git a/modules/styles/_main.scss b/modules/styles/_main.scss new file mode 100644 index 0000000..93da594 --- /dev/null +++ b/modules/styles/_main.scss @@ -0,0 +1,55 @@ +.mw-spoiler { + box-shadow: 0 2px 3px rgba(10, 10, 10, .1), 0 0 0 1px rgba(10, 10, 10, .1); + margin: 1em 0; + padding: 1em; + + summary { + cursor: pointer; + -webkit-touch-callout: none; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; + } + + &[open] { + .mw-spoiler-content { + animation: open .5s ease-in-out; + } + } + + &-body { + border-top: 1px solid hsl(0, 0%, 86%); + padding: 1em 0 0; + margin: 1em 0 0; + } + + &-content { + background: hsl(0, 0%, 98%); + border: 1px solid hsl(0, 0%, 86%); + box-shadow: inset 0 1px 2px rgba(10, 10, 10, .1); + padding: 1em; + } + + @keyframes open { + 0% { + opacity: 0; + } + 100% { + opacity: 1; + } + } +} + +.mw-hide { + &-body { + cursor: help; + visibility: hidden; + } + + &:hover { + &-body { + visibility: visible; + } + } +} diff --git a/modules/styles/theme.css b/modules/styles/theme.css new file mode 100644 index 0000000..1aa527e --- /dev/null +++ b/modules/styles/theme.css @@ -0,0 +1 @@ +.mw-spoiler{box-shadow:0 2px 3px rgba(10,10,10,0.1),0 0 0 1px rgba(10,10,10,0.1);margin:1em 0;padding:1em}.mw-spoiler summary{cursor:pointer;-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.mw-spoiler[open] .mw-spoiler-content{animation:open .5s ease-in-out}.mw-spoiler-body{border-top:1px solid #dbdbdb;padding:1em 0 0;margin:1em 0 0}.mw-spoiler-content{background:#fafafa;border:1px solid #dbdbdb;box-shadow:inset 0 1px 2px rgba(10,10,10,0.1);padding:1em}@keyframes open{0%{opacity:0}100%{opacity:1}}.mw-hide-body{cursor:help;visibility:hidden}.mw-hide:hover-body{visibility:visible} diff --git a/modules/styles/theme.scss b/modules/styles/theme.scss new file mode 100644 index 0000000..2059d52 --- /dev/null +++ b/modules/styles/theme.scss @@ -0,0 +1 @@ +@import 'main.scss'; \ No newline at end of file