2023-07-16 23:53:48
This commit is contained in:
parent
b27ba817b8
commit
fc69dfa423
|
@ -0,0 +1 @@
|
||||||
|
.idea/
|
|
@ -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)
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2023 Package Store
|
Copyright (c) 2023 iHub TO <https://ihub.to>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -0,0 +1,153 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MediaWiki\Extension\PkgStore;
|
||||||
|
|
||||||
|
use MWException;
|
||||||
|
use OutputPage, Parser, Skin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class MW_EXT_URL
|
||||||
|
*/
|
||||||
|
class MW_EXT_URL
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* * Clear URL.
|
||||||
|
*
|
||||||
|
* @param $string
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private static function clearURL($string): string
|
||||||
|
{
|
||||||
|
return rawurlencode(trim($string));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register tag function.
|
||||||
|
*
|
||||||
|
* @param Parser $parser
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @throws MWException
|
||||||
|
*/
|
||||||
|
public static function onParserFirstCallInit(Parser $parser): void
|
||||||
|
{
|
||||||
|
$parser->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 = '<a class="mw-url mw-url-' . $outClass . '" href="' . $outScheme . $outURL . '" target="_blank" rel="nofollow">';
|
||||||
|
$outHTML .= '<i class="fa-icon ' . $outIcon . '"></i>';
|
||||||
|
$outHTML .= '<span>' . $outTitle . '</span>';
|
||||||
|
$outHTML .= '</a>';
|
||||||
|
|
||||||
|
// 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']);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internationalization file for extension MW_EXT_URL (magic words).
|
||||||
|
*
|
||||||
|
* @file
|
||||||
|
* @ingroup Extensions
|
||||||
|
* @license MIT
|
||||||
|
* @author iHub TO <https://ihub.to>
|
||||||
|
*/
|
||||||
|
$magicWords = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* English.
|
||||||
|
*
|
||||||
|
* @author iHub TO <https://ihub.to>
|
||||||
|
*/
|
||||||
|
$magicWords['en'] = [
|
||||||
|
'url' => [0, 'url'],
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Russian.
|
||||||
|
*
|
||||||
|
* @author iHub TO <https://ihub.to>
|
||||||
|
*/
|
||||||
|
$magicWords['ru'] = [
|
||||||
|
'url' => [0, 'url'],
|
||||||
|
];
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// Confirm MediaWiki environment.
|
||||||
|
if (!defined('MEDIAWIKI')) {
|
||||||
|
die('This file is a MediaWiki extension and thus not a valid entry point.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (function_exists('wfLoadExtension')) {
|
||||||
|
wfLoadExtension('MW_EXT_URL');
|
||||||
|
// Keep i18n globals so mergeMessageFileList.php doesn't break.
|
||||||
|
$wgExtensionMessagesFiles['MW_EXT_URL'] = __DIR__ . '/i18n';
|
||||||
|
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
die('This version of the MW_EXT_URL extension requires MediaWiki 1.31+');
|
||||||
|
}
|
19
README.md
19
README.md
|
@ -1 +1,18 @@
|
||||||
# mediawiki-ext-url
|
# Information
|
||||||
|
|
||||||
|
Добавление различных типов ссылок в статью.
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
1. Загрузите папки и файлы в директорию `extensions/MW_EXT_URL`.
|
||||||
|
2. В самый низ файла `LocalSettings.php` добавьте строку:
|
||||||
|
|
||||||
|
```php
|
||||||
|
wfLoadExtension( 'MW_EXT_URL' );
|
||||||
|
```
|
||||||
|
|
||||||
|
## Syntax
|
||||||
|
|
||||||
|
```html
|
||||||
|
{{#url: [TYPE]|[CONTENT]|[TITLE]}}
|
||||||
|
```
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
{
|
||||||
|
"name": "pkgstore/mediawiki-ext-url",
|
||||||
|
"type": "mediawiki-extension",
|
||||||
|
"description": "MediaWiki URL extension.",
|
||||||
|
"license": "MIT",
|
||||||
|
"homepage": "https://ihub.to/",
|
||||||
|
"keywords": [
|
||||||
|
"mediawiki",
|
||||||
|
"url"
|
||||||
|
],
|
||||||
|
"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-url/issues",
|
||||||
|
"source": "https://github.com/pkgstore/mediawiki-ext-url"
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"composer/installers": "^1.0.1",
|
||||||
|
"php": ">=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"
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"@metadata": {
|
||||||
|
"authors": [
|
||||||
|
"iHub TO"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"mw-url-desc": "Добавление различных типов ссылок в статью."
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
.mw-url {
|
||||||
|
.fa-icon {
|
||||||
|
margin-right: .2em;
|
||||||
|
color: hsl(0, 0%, 86%);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
.mw-url .fa-icon{margin-right:.2em;color:#dbdbdb}
|
|
@ -0,0 +1 @@
|
||||||
|
@import 'main.scss';
|
Loading…
Reference in New Issue