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_URL.class.php b/MW_EXT_URL.class.php new file mode 100644 index 0000000..995d630 --- /dev/null +++ b/MW_EXT_URL.class.php @@ -0,0 +1,153 @@ +setFunctionHook('url', [__CLASS__, 'onRenderTag']); + } + + /** + * Render `URL` function. + * + * @param Parser $parser + * @param string $type + * @param string $content + * @param string $title + * + * @return string|null + */ + public static function onRenderTag(Parser $parser, string $type = '', string $content = '', string $title = ''): ?string + { + // Argument: type. + $getType = MW_EXT_Kernel::outClear($type ?? '' ?: ''); + + // Argument: content. + $getContent = MW_EXT_Kernel::outClear($content ?? '' ?: ''); + + // Argument: title. + $getTitle = MW_EXT_Kernel::outClear($title ?? '' ?: ''); + + // Build URL. + switch ($getType) { + case 'address': + $outContent = $getContent; + $outTitle = $getTitle ? $getTitle : $outContent; + $outScheme = 'https://'; + $outIcon = 'fas fa-map-marker-alt'; + $outClass = 'address'; + $outURL = 'google.ru/maps/place/' . self::clearURL($outContent); + break; + case 'email': + $outContent = $getContent; + $outTitle = $getTitle ? $getTitle : $getContent; + $outScheme = 'mailto:'; + $outIcon = 'fas fa-envelope'; + $outClass = 'email'; + $outURL = $outContent; + break; + case 'tel': + $outContent = preg_replace('#[^0-9\+]#', '', $getContent); + $outTitle = $getTitle ? $getTitle : $getContent; + $outScheme = 'tel:'; + $outIcon = 'fas fa-phone'; + $outClass = 'tel'; + $outURL = $outContent; + break; + case 'fax': + $outContent = preg_replace('#[^0-9\+]#', '', $getContent); + $outTitle = $getTitle ? $getTitle : $getContent; + $outScheme = 'fax:'; + $outIcon = 'fas fa-fax'; + $outClass = 'fax'; + $outURL = $outContent; + break; + case 'whatsapp': + $outContent = preg_replace('#[^0-9]#', '', $getContent); + $outTitle = $getTitle ? $getTitle : $outContent; + $outScheme = 'https://'; + $outIcon = 'fab fa-whatsapp'; + $outClass = 'whatsapp'; + $outURL = 'api.whatsapp.com/send?phone=' . $outContent; + break; + case 'tg': + $outContent = $getContent; + $outTitle = $getTitle ? $getTitle : $outContent; + $outScheme = 'tg://'; + $outIcon = 'fab fa-telegram'; + $outClass = 'tg'; + $outURL = 'resolve?domain=' . $outContent; + break; + case 'viber': + $outContent = $getContent; + $outTitle = $getTitle ? $getTitle : $outContent; + $outScheme = 'viber://'; + $outIcon = 'fab fa-viber'; + $outClass = 'viber'; + $outURL = 'public?id=' . $outContent; + break; + case 'skype': + $outContent = $getContent; + $outTitle = $getTitle ? $getTitle : $outContent; + $outScheme = 'skype:'; + $outIcon = 'fab fa-skype'; + $outClass = 'skype'; + $outURL = $outContent; + break; + default: + $parser->addTrackingCategory('mw-url-error-category'); + + return null; + } + + // Out HTML. + $outHTML = ''; + $outHTML .= ''; + $outHTML .= '' . $outTitle . ''; + $outHTML .= ''; + + // Out parser. + return $parser->insertStripItem($outHTML, $parser->getStripState()); + } + + /** + * Load resource function. + * + * @param OutputPage $out + * @param Skin $skin + * + * @return void + */ + public static function onBeforePageDisplay(OutputPage $out, Skin $skin): void + { + $out->addModuleStyles(['ext.mw.url.styles']); + } +} diff --git a/MW_EXT_URL.i18n.magic.php b/MW_EXT_URL.i18n.magic.php new file mode 100644 index 0000000..7fc4d30 --- /dev/null +++ b/MW_EXT_URL.i18n.magic.php @@ -0,0 +1,29 @@ + + */ +$magicWords = []; + +/** + * English. + * + * @author iHub TO + */ +$magicWords['en'] = [ + 'url' => [0, 'url'], +]; + +/** + * Russian. + * + * @author iHub TO + */ +$magicWords['ru'] = [ + 'url' => [0, 'url'], +]; diff --git a/MW_EXT_URL.php b/MW_EXT_URL.php new file mode 100644 index 0000000..ffd6a33 --- /dev/null +++ b/MW_EXT_URL.php @@ -0,0 +1,16 @@ +=8.2", + "pkgstore/mediawiki-ext-kernel": "*" + }, + "autoload": { + "classmap": [ + "MW_EXT_URL.class.php" + ] + }, + "config": { + "optimize-autoloader": true, + "prepend-autoloader": false + }, + "extra": { + "installer-name": "MW_EXT_URL" + } +} diff --git a/extension.json b/extension.json new file mode 100644 index 0000000..a6b2328 --- /dev/null +++ b/extension.json @@ -0,0 +1,55 @@ +{ + "name": "MW_EXT_URL", + "version": "1.0.0", + "author": [ + "[https://ihub.to/ iHub TO]", + "[https://kitsune.solar/ Kitsune Solar]", + "..." + ], + "url": "https://ihub.to/", + "descriptionmsg": "mw-url-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_URL": "MW_EXT_URL.class.php" + }, + "Hooks": { + "ParserFirstCallInit": [ + "MediaWiki\\Extension\\PkgStore\\MW_EXT_URL::onParserFirstCallInit" + ], + "BeforePageDisplay": [ + "MediaWiki\\Extension\\PkgStore\\MW_EXT_URL::onBeforePageDisplay" + ] + }, + "ExtensionMessagesFiles": { + "MW_EXT_URLMagic": "MW_EXT_URL.i18n.magic.php" + }, + "MessagesDirs": { + "MW_EXT_URL": [ + "i18n" + ] + }, + "ResourceModules": { + "ext.mw.url.styles": { + "styles": [ + "styles/theme.css" + ], + "position": "top", + "targets": [ + "desktop", + "mobile" + ] + } + }, + "ResourceFileModulePaths": { + "localBasePath": "modules", + "remoteExtPath": "MW_EXT_URL/modules" + }, + "manifest_version": 2 +} diff --git a/i18n/ru.json b/i18n/ru.json new file mode 100644 index 0000000..c3e7492 --- /dev/null +++ b/i18n/ru.json @@ -0,0 +1,8 @@ +{ + "@metadata": { + "authors": [ + "iHub TO" + ] + }, + "mw-url-desc": "Добавление различных типов ссылок в статью." +} diff --git a/modules/styles/_main.scss b/modules/styles/_main.scss new file mode 100644 index 0000000..f3c52e3 --- /dev/null +++ b/modules/styles/_main.scss @@ -0,0 +1,6 @@ +.mw-url { + .fa-icon { + margin-right: .2em; + color: hsl(0, 0%, 86%); + } +} diff --git a/modules/styles/theme.css b/modules/styles/theme.css new file mode 100644 index 0000000..91cefb6 --- /dev/null +++ b/modules/styles/theme.css @@ -0,0 +1 @@ +.mw-url .fa-icon{margin-right:.2em;color:#dbdbdb} 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