You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.5 KiB
PHTML
71 lines
2.5 KiB
PHTML
2 years ago
|
<?php
|
||
|
namespace Isekai\Widgets;
|
||
|
|
||
|
use Html;
|
||
|
use Title;
|
||
|
|
||
|
class PreviewPageListWidget {
|
||
|
public const CONTAINER_CLASS_NAME = 'isekai-card isekai-preview-page-list-card';
|
||
|
|
||
|
public static function create($text, $params, \Parser $parser, \PPFrame $frame) {
|
||
|
$parser->getOutput()->addModules(['ext.isekai.previewPageList']);
|
||
|
|
||
|
$loader = $params['loader'] ?? 'unknown';
|
||
|
if ($loader === 'unknown' && !empty(trim($text))) {
|
||
|
$loader = 'pages';
|
||
|
}
|
||
|
|
||
|
$autoFocus = $params['autofocus'] ?? false;
|
||
|
if ($autoFocus === 'false' || $autoFocus === '0') {
|
||
|
$autoFocus = false;
|
||
|
} else {
|
||
|
$autoFocus = true;
|
||
|
}
|
||
|
|
||
|
$lazyLoad = $params['lazyload'] ?? false;
|
||
|
if ($lazyLoad === 'false' || $lazyLoad === '0') {
|
||
|
$lazyLoad = false;
|
||
|
} else {
|
||
|
$lazyLoad = true;
|
||
|
}
|
||
|
|
||
|
switch ($loader) {
|
||
|
case 'pages':
|
||
|
$pageList = explode("\n", trim($text));
|
||
|
$pageList = array_map(function ($page) {
|
||
|
return trim($page);
|
||
|
}, $pageList);
|
||
|
|
||
|
return Html::openElement('div', [
|
||
|
'class' => self::CONTAINER_CLASS_NAME,
|
||
|
'data-loader' => $loader,
|
||
|
'data-autofocus' => $autoFocus,
|
||
|
'data-lazyload' => $lazyLoad,
|
||
|
]) . Html::element('script', [
|
||
|
'type' => 'application/json',
|
||
|
'data-pages' => true,
|
||
|
], json_encode($pageList)) . Html::closeElement('div');
|
||
|
case 'category':
|
||
|
$category = $params['category'] ?? null;
|
||
|
if (!$category) {
|
||
|
return Html::element('span', [
|
||
|
'class' => 'error'
|
||
|
], wfMessage('isekai-preview-page-list-error-invalid-category')->parse());
|
||
|
}
|
||
|
|
||
|
$categoryTitle = new Title($category, NS_CATEGORY);
|
||
|
$categoryTitleText = $categoryTitle->getPrefixedText();
|
||
|
|
||
|
return Html::element('div', [
|
||
|
'class' => self::CONTAINER_CLASS_NAME,
|
||
|
'data-category' => $categoryTitleText,
|
||
|
'data-autofocus' => $autoFocus,
|
||
|
'data-lazyload' => $lazyLoad,
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
return Html::element('span', [
|
||
|
'class' => 'error'
|
||
|
], wfMessage('isekai-preview-page-list-error-invalid-loader', $loader)->parse());
|
||
|
}
|
||
|
}
|