2023-07-16 23:53:39
This commit is contained in:
parent
05e3f729e9
commit
965e501aae
|
@ -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
|
||||
|
||||
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
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\PkgStore;
|
||||
|
||||
use ConfigException;
|
||||
use MWException;
|
||||
use OutputPage, Parser, PPFrame, Skin;
|
||||
|
||||
/**
|
||||
* Class MW_EXT_Rating
|
||||
*/
|
||||
class MW_EXT_Rating
|
||||
{
|
||||
/**
|
||||
* Register tag function.
|
||||
*
|
||||
* @param Parser $parser
|
||||
*
|
||||
* @return void
|
||||
* @throws MWException
|
||||
*/
|
||||
public static function onParserFirstCallInit(Parser $parser): void
|
||||
{
|
||||
$parser->setFunctionHook('rating', [__CLASS__, 'onRenderTag'], Parser::SFH_OBJECT_ARGS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render tag function.
|
||||
*
|
||||
* @param Parser $parser
|
||||
* @param PPFrame $frame
|
||||
* @param array $args
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public static function onRenderTag(Parser $parser, PPFrame $frame, array $args): ?string
|
||||
{
|
||||
// Get options parser.
|
||||
$getOption = MW_EXT_Kernel::extractOptions($frame, $args);
|
||||
|
||||
// Argument: title.
|
||||
$getTitle = MW_EXT_Kernel::outClear($getOption['title'] ?? '' ?: '');
|
||||
$outTitle = $getTitle;
|
||||
|
||||
// Argument: count.
|
||||
$getCount = MW_EXT_Kernel::outClear($getOption['count'] ?? '' ?: '');
|
||||
$outCount = $getCount;
|
||||
|
||||
// Argument: icon-plus.
|
||||
$getIconPlus = MW_EXT_Kernel::outClear($getOption['icon-plus'] ?? '' ?: 'fas fa-star');
|
||||
$outIconPlus = $getIconPlus;
|
||||
|
||||
// Argument: icon-minus.
|
||||
$getIconMinus = MW_EXT_Kernel::outClear($getOption['icon-minus'] ?? '' ?: 'far fa-star');
|
||||
$outIconMinus = $getIconMinus;
|
||||
|
||||
// Setting: MW_EXT_Rating_minCount.
|
||||
$setMinCount = MW_EXT_Kernel::getConfig('MW_EXT_Rating_minCount');
|
||||
|
||||
// Setting: MW_EXT_Rating_maxCount.
|
||||
$setMaxCount = MW_EXT_Kernel::getConfig('MW_EXT_Rating_maxCount');
|
||||
|
||||
// Check rating title, count, set error category.
|
||||
if (empty($outTitle) || !ctype_digit($getCount) || $getCount > $setMaxCount) {
|
||||
$parser->addTrackingCategory('mw-rating-error-category');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$outStars = '';
|
||||
|
||||
// Out rating: icon-plus.
|
||||
for ($i = 1; $i <= $getCount; $i++) {
|
||||
$outStars .= '<span class="' . $outIconPlus . ' fa-fw mw-rating-star mw-rating-star-plus"></span>';
|
||||
}
|
||||
|
||||
// Out rating: icon-minus.
|
||||
while ($i <= $setMaxCount) {
|
||||
$outStars .= '<span class="' . $outIconMinus . ' fa-fw mw-rating-star mw-rating-star-minus"></span>';
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Out HTML.
|
||||
$outHTML = '<div class="mw-rating mw-rating-count-' . $outCount . ' navigation-not-searchable" itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating">';
|
||||
$outHTML .= '<div class="mw-rating-body"><div class="mw-rating-content">';
|
||||
$outHTML .= '<div class="mw-rating-text">' . $outTitle . '</div>';
|
||||
$outHTML .= '<div class="mw-rating-count">' . $outStars . '</div>';
|
||||
$outHTML .= '</div></div>';
|
||||
$outHTML .= '<meta itemprop="worstRating" content = "' . $setMinCount . '" />';
|
||||
$outHTML .= '<meta itemprop="ratingValue" content = "' . $outCount . '" />';
|
||||
$outHTML .= '<meta itemprop="bestRating" content = "' . $setMaxCount . '" />';
|
||||
$outHTML .= '</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.rating.styles']);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Internationalization file for extension MW_EXT_Rating (magic words).
|
||||
*
|
||||
* @file
|
||||
* @ingroup Extensions
|
||||
* @license MIT
|
||||
* @author iHub TO <https://ihub.to>
|
||||
*/
|
||||
$magicWords = [];
|
||||
|
||||
/**
|
||||
* English.
|
||||
*
|
||||
* @author iHub TO <https://ihub.to>
|
||||
*/
|
||||
$magicWords['en'] = [
|
||||
'rating' => [0, 'rating'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Russian.
|
||||
*
|
||||
* @author iHub TO <https://ihub.to>
|
||||
*/
|
||||
$magicWords['ru'] = [
|
||||
'rating' => [0, 'rating'],
|
||||
];
|
|
@ -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_Rating');
|
||||
// Keep i18n globals so mergeMessageFileList.php doesn't break.
|
||||
$wgExtensionMessagesFiles['MW_EXT_Rating'] = __DIR__ . '/i18n';
|
||||
|
||||
return;
|
||||
} else {
|
||||
die('This version of the MW_EXT_Rating extension requires MediaWiki 1.31+');
|
||||
}
|
23
README.md
23
README.md
|
@ -1 +1,22 @@
|
|||
# mediawiki-ext-rating
|
||||
# Information
|
||||
|
||||
Интеграция рейтинга в статью.
|
||||
|
||||
## Install
|
||||
|
||||
1. Загрузите папки и файлы в директорию `extensions/MW_EXT_Rating`.
|
||||
2. В самый низ файла `LocalSettings.php` добавьте строку:
|
||||
|
||||
```php
|
||||
wfLoadExtension( 'MW_EXT_Rating' );
|
||||
```
|
||||
|
||||
## Syntax
|
||||
|
||||
```html
|
||||
{{#rating: title = [TITLE]
|
||||
|count = [NUMBER]
|
||||
|icon-plus = fas fa-[ICON]
|
||||
|icon-minus = fas fa-[ICON]
|
||||
}}
|
||||
```
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
{
|
||||
"name": "pkgstore/mediawiki-ext-rating",
|
||||
"type": "mediawiki-extension",
|
||||
"description": "MediaWiki rating extension.",
|
||||
"license": "MIT",
|
||||
"homepage": "https://ihub.to/",
|
||||
"keywords": [
|
||||
"mediawiki",
|
||||
"rating"
|
||||
],
|
||||
"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-rating/issues",
|
||||
"source": "https://github.com/pkgstore/mediawiki-ext-rating"
|
||||
},
|
||||
"require": {
|
||||
"composer/installers": "^1.0.1",
|
||||
"php": ">=8.2",
|
||||
"pkgstore/mediawiki-ext-kernel": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"MW_EXT_Rating.class.php"
|
||||
]
|
||||
},
|
||||
"config": {
|
||||
"optimize-autoloader": true,
|
||||
"prepend-autoloader": false
|
||||
},
|
||||
"extra": {
|
||||
"installer-name": "MW_EXT_Quote"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
{
|
||||
"name": "MW_EXT_Rating",
|
||||
"version": "1.0.0",
|
||||
"author": [
|
||||
"[https://ihub.to/ iHub TO]",
|
||||
"[https://kitsune.solar/ Kitsune Solar]",
|
||||
"..."
|
||||
],
|
||||
"url": "https://ihub.to/",
|
||||
"descriptionmsg": "mw-rating-desc",
|
||||
"license-name": "[https://choosealicense.com/licenses/mit/ MIT]",
|
||||
"type": "parserhook",
|
||||
"require": {
|
||||
"MediaWiki": ">= 1.31.0",
|
||||
"extensions": {
|
||||
"MW_EXT_Kernel": "*"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"MW_EXT_Rating_minCount": {
|
||||
"value": "1"
|
||||
},
|
||||
"MW_EXT_Rating_maxCount": {
|
||||
"value": "10"
|
||||
}
|
||||
},
|
||||
"AutoloadClasses": {
|
||||
"MediaWiki\\Extension\\PkgStore\\MW_EXT_Rating": "MW_EXT_Rating.class.php"
|
||||
},
|
||||
"Hooks": {
|
||||
"ParserFirstCallInit": [
|
||||
"MediaWiki\\Extension\\PkgStore\\MW_EXT_Rating::onParserFirstCallInit"
|
||||
],
|
||||
"BeforePageDisplay": [
|
||||
"MediaWiki\\Extension\\PkgStore\\MW_EXT_Rating::onBeforePageDisplay"
|
||||
]
|
||||
},
|
||||
"ExtensionMessagesFiles": {
|
||||
"MW_EXT_RatingMagic": "MW_EXT_Rating.i18n.magic.php"
|
||||
},
|
||||
"MessagesDirs": {
|
||||
"MW_EXT_Rating": [
|
||||
"i18n"
|
||||
]
|
||||
},
|
||||
"ResourceModules": {
|
||||
"ext.mw.rating.styles": {
|
||||
"styles": [
|
||||
"styles/theme.css"
|
||||
],
|
||||
"position": "top",
|
||||
"targets": [
|
||||
"desktop",
|
||||
"mobile"
|
||||
]
|
||||
}
|
||||
},
|
||||
"ResourceFileModulePaths": {
|
||||
"localBasePath": "modules",
|
||||
"remoteExtPath": "MW_EXT_Rating/modules"
|
||||
},
|
||||
"manifest_version": 2
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"@metadata": {
|
||||
"authors": [
|
||||
"iHub TO"
|
||||
]
|
||||
},
|
||||
"mw-rating-desc": "Интеграция рейтинга в статью.",
|
||||
"mw-rating-error-category": "META:ERROR.EXT.Rating"
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
.mw-rating {
|
||||
.mw-rating {
|
||||
&-body {
|
||||
background: hsl(0, 0%, 98%);
|
||||
padding: .5em;
|
||||
max-width: 40em;
|
||||
|
||||
&:hover {
|
||||
background: hsl(0, 0%, 96%);
|
||||
}
|
||||
}
|
||||
|
||||
&-content {
|
||||
display: grid;
|
||||
grid-template-columns: 20rem max-content;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
&-text,
|
||||
&-count {
|
||||
}
|
||||
|
||||
&-text {
|
||||
font-weight: bold;
|
||||
|
||||
}
|
||||
|
||||
&-count {
|
||||
}
|
||||
|
||||
&-star {
|
||||
display: inline-block;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
&-star-plus {
|
||||
color: hsl(217, 71%, 53%);
|
||||
}
|
||||
|
||||
&-star-minus {
|
||||
color: hsl(0, 0%, 86%);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
@media (max-width: 1087px) {
|
||||
.mw-rating {
|
||||
.mw-rating-content {
|
||||
display: block;
|
||||
width: 20em;
|
||||
}
|
||||
|
||||
.mw-rating-count {
|
||||
margin-top: .5em;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
.mw-rating .mw-rating-body{background:#fafafa;padding:.5em;max-width:40em}.mw-rating .mw-rating-body:hover{background:#f5f5f5}.mw-rating .mw-rating-content{display:grid;grid-template-columns:20rem max-content;align-items:center}.mw-rating .mw-rating-text{font-weight:bold}.mw-rating .mw-rating-star{display:inline-block;font-size:1.2em}.mw-rating .mw-rating-star-plus{color:#3273dc}.mw-rating .mw-rating-star-minus{color:#dbdbdb}@media (max-width: 1087px){.mw-rating .mw-rating-content{display:block;width:20em}.mw-rating .mw-rating-count{margin-top:.5em}}
|
|
@ -0,0 +1,2 @@
|
|||
@import 'main.scss';
|
||||
@import 'media.scss';
|
Loading…
Reference in New Issue