'isekai-list-item', 'href' => $title->getLocalURL()], Html::rawElement('div', ['class' => 'isekai-list-item-content'], Html::element('div', ['class' => 'isekai-list-item-title'], $title->getPrefixedText()) ) ); } } return Html::openElement('div', [ 'class' => 'fallback-page-list' ]) . Html::openElement('ul', [ 'class' => 'isekai-list' ]) . implode("\n", $pageListHtml) . Html::closeElement('ul') . Html::closeElement('div'); } 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; } $resultHtml = null; switch ($loader) { case 'pages': $pageList = explode("\n", trim($text)); $pageList = array_map(function ($page) { return trim($page); }, $pageList); $resultHtml = Html::openElement('div', [ 'class' => self::CONTAINER_CLASS_NAME, 'data-loader' => $loader, 'data-autofocus' => $autoFocus, 'data-lazyload' => $lazyLoad, ]) . Html::openElement('script', [ 'type' => 'application/json', 'data-pages' => true, ]) . json_encode($pageList) . Html::closeElement('script') . self::buildFallbackPageList($pageList) . Html::closeElement('div'); break; case 'category': $category = $params['category'] ?? null; if (!$category) { return Html::element('span', [ 'class' => 'error' ], wfMessage('isekai-preview-page-list-error-invalid-category')->parse()); } $categoryTitle = Title::newFromText($category, NS_CATEGORY); $categoryTitleText = $categoryTitle->getPrefixedText(); $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 ]); } $resultHtml = Html::openElement('div', [ 'class' => self::CONTAINER_CLASS_NAME, 'data-loader' => $loader, 'data-category' => $categoryTitleText, 'data-autofocus' => $autoFocus, 'data-lazyload' => $lazyLoad, ]) . self::buildFallbackPageList($pageList) . Html::closeElement('div'); break; } if (!$resultHtml) { $resultHtml = Html::element('span', [ 'class' => 'error' ], wfMessage('isekai-preview-page-list-error-invalid-loader', $loader)->parse()); } return $resultHtml; } }