2023-07-16 23:53:34

This commit is contained in:
z17CX 2023-07-16 23:53:34 +00:00
parent 6ed8a1aed0
commit ac7a3ebb44
Signed by: z17cx
GPG key ID: 3F5F87C84EE943E4
17 changed files with 292 additions and 2 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
.idea/

0
CHANGELOG.md Normal file
View file

13
CONTRIBUTING.md Normal file
View file

@ -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)

View file

@ -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

123
MW_EXT_Note.class.php Normal file
View file

@ -0,0 +1,123 @@
<?php
namespace MediaWiki\Extension\PkgStore;
use MWException;
use OutputPage, Parser, PPFrame, Skin;
/**
* Class MW_EXT_Note
*/
class MW_EXT_Note
{
/**
* Get note.
*
* @param $type
*
* @return array
*/
private static function getNote($type): array
{
$note = MW_EXT_Kernel::getYAML(__DIR__ . '/store/' . $type . '.json');
return $note ?? [] ?: [];
}
/**
* Get note ID.
*
* @param $type
*
* @return string
*/
private static function getID($type): string
{
$note = self::getNote($type) ? self::getNote($type) : '';
return $note['id'] ?? '' ?: '';
}
/**
* Get note icon.
*
* @param $type
*
* @return string
*/
private static function getIcon($type): string
{
$note = self::getNote($type) ? self::getNote($type) : '';
return $note['icon'] ?? '' ?: '';
}
/**
* Register tag function.
*
* @param Parser $parser
*
* @return void
* @throws MWException
*/
public static function onParserFirstCallInit(Parser $parser): void
{
$parser->setHook('note', [__CLASS__, 'onRenderTag']);
}
/**
* Render tag function.
*
* @param $input
* @param array $args
* @param Parser $parser
* @param PPFrame $frame
*
* @return string|null
*/
public static function onRenderTag($input, array $args, Parser $parser, PPFrame $frame): ?string
{
// Argument: type.
$getType = MW_EXT_Kernel::outClear($args['type'] ?? '' ?: '');
$outType = MW_EXT_Kernel::outNormalize($getType);
// Check note type, set error category.
if (!self::getNote($outType)) {
$parser->addTrackingCategory('mw-note-error-category');
return null;
}
// Get icon.
$getIcon = self::getIcon($outType);
$outIcon = $getIcon;
// Get ID.
$getID = self::getID($outType);
$outID = $getID;
// Get content.
$getContent = trim($input);
$outContent = $parser->recursiveTagParse($getContent, $frame);
// Out HTML.
$outHTML = '<div class="mw-note mw-note-' . $outID . ' navigation-not-searchable mw-box">';
$outHTML .= '<div class="mw-note-body">';
$outHTML .= '<div class="mw-note-icon"><div><i class="' . $outIcon . '"></i></div></div>';
$outHTML .= '<div class="mw-note-content">' . "\n\r" . $outContent . "\n\r" . '</div>';
$outHTML .= '</div></div>';
// 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.note.styles']);
}
}

16
MW_EXT_Note.php Normal file
View file

@ -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_Note');
// Keep i18n globals so mergeMessageFileList.php doesn't break.
$wgExtensionMessagesFiles['MW_EXT_Note'] = __DIR__ . '/i18n';
return;
} else {
die('This version of the MW_EXT_Note extension requires MediaWiki 1.31+');
}

View file

@ -1 +1,18 @@
# mediawiki-ext-note # Information
Интеграция пользовательских сообщений в статью.
## Install
1. Загрузите папки и файлы в директорию `extensions/MW_EXT_Note`.
2. В самый низ файла `LocalSettings.php` добавьте строку:
```php
wfLoadExtension( 'MW_EXT_Note' );
```
## Syntax
```html
<note type="[TYPE]">[CONTENT]</note>
```

46
composer.json Normal file
View file

@ -0,0 +1,46 @@
{
"name": "pkgstore/mediawiki-ext-note",
"type": "mediawiki-extension",
"description": "MediaWiki notes extension.",
"license": "MIT",
"homepage": "https://ihub.to/",
"keywords": [
"mediawiki",
"note"
],
"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-note/issues",
"source": "https://github.com/pkgstore/mediawiki-ext-note"
},
"require": {
"composer/installers": "^1.0.1",
"php": ">=8.2",
"pkgstore/mediawiki-ext-kernel": "*"
},
"autoload": {
"classmap": [
"MW_EXT_Note.class.php"
]
},
"config": {
"optimize-autoloader": true,
"prepend-autoloader": false
},
"extra": {
"installer-name": "MW_EXT_Note"
}
}

52
extension.json Normal file
View file

@ -0,0 +1,52 @@
{
"name": "MW_EXT_Note",
"version": "1.0.0",
"author": [
"[https://ihub.to/ iHub TO]",
"[https://kitsune.solar/ Kitsune Solar]",
"..."
],
"url": "https://ihub.to/",
"descriptionmsg": "mw-note-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_Note": "MW_EXT_Note.class.php"
},
"Hooks": {
"ParserFirstCallInit": [
"MediaWiki\\Extension\\PkgStore\\MW_EXT_Note::onParserFirstCallInit"
],
"BeforePageDisplay": [
"MediaWiki\\Extension\\PkgStore\\MW_EXT_Note::onBeforePageDisplay"
]
},
"MessagesDirs": {
"MW_EXT_Note": [
"i18n"
]
},
"ResourceModules": {
"ext.mw.note.styles": {
"styles": [
"styles/theme.css"
],
"position": "top",
"targets": [
"desktop",
"mobile"
]
}
},
"ResourceFileModulePaths": {
"localBasePath": "modules",
"remoteExtPath": "MW_EXT_Note/modules"
},
"manifest_version": 2
}

8
i18n/ru.json Normal file
View file

@ -0,0 +1,8 @@
{
"@metadata": {
"authors": [
"iHub TO"
]
},
"mw-note-desc": "Добавление в статью всевозможных комментариев и заметок."
}

View file

@ -0,0 +1,4 @@
.mw-note {
max-width: 80%;
margin: 1em auto;
}

1
modules/styles/theme.css Normal file
View file

@ -0,0 +1 @@
.mw-note{max-width:80%;margin:1em auto}

View file

@ -0,0 +1 @@
@import 'main.scss';

2
store/important.yml Normal file
View file

@ -0,0 +1,2 @@
id: important
icon: fas fa-exclamation-triangle

2
store/info.yml Normal file
View file

@ -0,0 +1,2 @@
id: info
icon: fas fa-sticky-note

2
store/tip.yml Normal file
View file

@ -0,0 +1,2 @@
id: tip
icon: fas fa-lightbulb

2
store/warning.yml Normal file
View file

@ -0,0 +1,2 @@
id: warning
icon: fas fa-times-circle