|
|
@ -1,7 +1,12 @@
|
|
|
|
<?php
|
|
|
|
<?php
|
|
|
|
namespace Isekai\Widgets;
|
|
|
|
namespace Isekai\Widgets;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use ApiMain;
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
|
|
|
|
use FauxRequest;
|
|
|
|
use Html;
|
|
|
|
use Html;
|
|
|
|
|
|
|
|
use MediaWiki\Linker\LinkRenderer;
|
|
|
|
|
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
use Title;
|
|
|
|
use Title;
|
|
|
|
|
|
|
|
|
|
|
|
class PreviewPageListWidget {
|
|
|
|
class PreviewPageListWidget {
|
|
|
@ -36,15 +41,30 @@ class PreviewPageListWidget {
|
|
|
|
return trim($page);
|
|
|
|
return trim($page);
|
|
|
|
}, $pageList);
|
|
|
|
}, $pageList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$pageListHtml = [];
|
|
|
|
|
|
|
|
$linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
|
|
|
|
|
|
|
|
foreach ($pageList as $pageTitle) {
|
|
|
|
|
|
|
|
$title = Title::newFromText($pageTitle);
|
|
|
|
|
|
|
|
$pageListHtml[] = Html::rawElement('li', [], $linkRenderer->makeLink($title));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Html::openElement('div', [
|
|
|
|
return Html::openElement('div', [
|
|
|
|
'class' => self::CONTAINER_CLASS_NAME,
|
|
|
|
'class' => self::CONTAINER_CLASS_NAME,
|
|
|
|
'data-loader' => $loader,
|
|
|
|
'data-loader' => $loader,
|
|
|
|
'data-autofocus' => $autoFocus,
|
|
|
|
'data-autofocus' => $autoFocus,
|
|
|
|
'data-lazyload' => $lazyLoad,
|
|
|
|
'data-lazyload' => $lazyLoad,
|
|
|
|
]) . Html::element('script', [
|
|
|
|
]) .
|
|
|
|
|
|
|
|
Html::element('script', [
|
|
|
|
'type' => 'application/json',
|
|
|
|
'type' => 'application/json',
|
|
|
|
'data-pages' => true,
|
|
|
|
'data-pages' => true,
|
|
|
|
], json_encode($pageList)) . Html::closeElement('div');
|
|
|
|
], json_encode($pageList)) .
|
|
|
|
|
|
|
|
Html::openElement('div', [
|
|
|
|
|
|
|
|
'class' => 'fallback-page-list'
|
|
|
|
|
|
|
|
]) . Html::openElement('ul', []) .
|
|
|
|
|
|
|
|
implode("\n", $pageListHtml) .
|
|
|
|
|
|
|
|
Html::closeElement('ul') .
|
|
|
|
|
|
|
|
Html::closeElement('div') .
|
|
|
|
|
|
|
|
Html::closeElement('div');
|
|
|
|
case 'category':
|
|
|
|
case 'category':
|
|
|
|
$category = $params['category'] ?? null;
|
|
|
|
$category = $params['category'] ?? null;
|
|
|
|
if (!$category) {
|
|
|
|
if (!$category) {
|
|
|
@ -53,15 +73,56 @@ class PreviewPageListWidget {
|
|
|
|
], wfMessage('isekai-preview-page-list-error-invalid-category')->parse());
|
|
|
|
], wfMessage('isekai-preview-page-list-error-invalid-category')->parse());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$categoryTitle = new Title($category, NS_CATEGORY);
|
|
|
|
$categoryTitle = Title::newFromText($category, NS_CATEGORY);
|
|
|
|
$categoryTitleText = $categoryTitle->getPrefixedText();
|
|
|
|
$categoryTitleText = $categoryTitle->getPrefixedText();
|
|
|
|
|
|
|
|
|
|
|
|
return Html::element('div', [
|
|
|
|
$pageList = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$request = [
|
|
|
|
|
|
|
|
'action' => 'query',
|
|
|
|
|
|
|
|
'list' => 'categorymembers',
|
|
|
|
|
|
|
|
'cmtitle' => $categoryTitleText,
|
|
|
|
|
|
|
|
'cmtype' => 'page',
|
|
|
|
|
|
|
|
'cmnamespace' => 0,
|
|
|
|
|
|
|
|
'cmlimit' => 100,
|
|
|
|
|
|
|
|
'cmsort' => 'sortkey',
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$api = new ApiMain(new FauxRequest($request));
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
$api->execute();
|
|
|
|
|
|
|
|
$categoryMembers = $api->getResult()->getResultData(['query', 'categorymembers']);
|
|
|
|
|
|
|
|
foreach ($categoryMembers as $categoryMember) {
|
|
|
|
|
|
|
|
if (is_array($categoryMember) && isset($categoryMember['title'])) {
|
|
|
|
|
|
|
|
$pageList[] = $categoryMember['title'];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
|
|
|
wfDebugLog('exception', $e->getMessage(), 'all', [
|
|
|
|
|
|
|
|
'exception' => $e
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$pageListHtml = [];
|
|
|
|
|
|
|
|
$linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
|
|
|
|
|
|
|
|
foreach ($pageList as $pageTitle) {
|
|
|
|
|
|
|
|
$title = Title::newFromText($pageTitle);
|
|
|
|
|
|
|
|
$pageListHtml[] = Html::rawElement('li', [], $linkRenderer->makeLink($title));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Html::openElement('div', [
|
|
|
|
'class' => self::CONTAINER_CLASS_NAME,
|
|
|
|
'class' => self::CONTAINER_CLASS_NAME,
|
|
|
|
|
|
|
|
'data-loader' => $loader,
|
|
|
|
'data-category' => $categoryTitleText,
|
|
|
|
'data-category' => $categoryTitleText,
|
|
|
|
'data-autofocus' => $autoFocus,
|
|
|
|
'data-autofocus' => $autoFocus,
|
|
|
|
'data-lazyload' => $lazyLoad,
|
|
|
|
'data-lazyload' => $lazyLoad,
|
|
|
|
]);
|
|
|
|
]) . Html::openElement('div', [
|
|
|
|
|
|
|
|
'class' => 'fallback-page-list'
|
|
|
|
|
|
|
|
]) . Html::openElement('ul', []) .
|
|
|
|
|
|
|
|
implode("\n", $pageListHtml) .
|
|
|
|
|
|
|
|
Html::closeElement('ul') .
|
|
|
|
|
|
|
|
Html::closeElement('div') .
|
|
|
|
|
|
|
|
Html::closeElement('div');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Html::element('span', [
|
|
|
|
return Html::element('span', [
|
|
|
|