移除不受支持的API,修复一些错误

master
落雨楓 2 years ago
parent 6ea1671ec4
commit 63fea40ae4

@ -2,8 +2,6 @@
namespace LatinizeUrl;
use Exception;
use MWHttpRequest;
use MediaWiki\Http\HttpRequestFactory;
use Fukuball\Jieba\Jieba;
use Fukuball\Jieba\Finalseg;
use Fukuball\Jieba\Posseg;
@ -19,7 +17,11 @@ class ChineseConvertor extends BaseConvertor {
public static function standalone(){
if(!self::$standalone){
global $wgLatinizeUrlChineseConvertorConfig;
$service = MediaWikiServices::getInstance();
$config = $service->getMainConfig();
$wgLatinizeUrlChineseConvertorConfig = $config->get('LatinizeUrlChineseConvertorConfig');
self::$standalone = new self($wgLatinizeUrlChineseConvertorConfig);
}
return self::$standalone;

@ -3,7 +3,6 @@
namespace LatinizeUrl;
use Exception;
use MediaWiki\Http\HttpRequestFactory;
use MediaWiki\MediaWikiServices;
class JapaneseConvertor extends BaseConvertor {
@ -12,7 +11,11 @@ class JapaneseConvertor extends BaseConvertor {
public static function standalone(){
if(!self::$standalone){
global $wgLatinizeUrlJapaneseConvertorConfig;
$service = MediaWikiServices::getInstance();
$config = $service->getMainConfig();
$wgLatinizeUrlJapaneseConvertorConfig = $config->get('LatinizeUrlJapaneseConvertorConfig');
self::$standalone = new self($wgLatinizeUrlJapaneseConvertorConfig);
}
return self::$standalone;

@ -1,3 +1,3 @@
{
"latinizeurl-japanese-convertor-desc": "LatinizeUrlの専用漢字をローマ字に変換するためのツール。"
"latinizeurl-japanese-convertor-desc": "LatinizeUrlの専用漢字と仮名をローマ字に変換するためのツール。"
}

@ -43,8 +43,7 @@ $LatinizeUrlChineseConvertorConfig['fallback'] = 'inner';
```
虚拟主机可以使用异世界百科的开放api
```
https://static-www.isekai.cn:8082/api/toolkit/asciiurl/hanzi2pinyin
http://static-www.isekai.cn:8081/api/toolkit/asciiurl/hanzi2pinyin
https://www.isekai.cn/api/toolkit/asciiurl/hanzi2pinyin
```
不保证稳定性建议自建daemon

@ -1,11 +1,12 @@
<?php
require_once dirname(__DIR__, 3) . '/maintenance/Maintenance.php';
require_once dirname(__DIR__) . '/includes/Hanzi2Pinyin.php';
require_once dirname(__DIR__) . '/ChineseConvertor/ChineseConvertor.php';
require_once dirname(__DIR__) . '/includes/Utils.php';
use LatinizeUrl\ChineseConvertor;
use LatinizeUrl\Hanzi2Pinyin;
use LatinizeUrl\Utils;
use MediaWiki\MediaWikiServices;
/**
* Maintenance script to normalize double-byte Latin UTF-8 characters.
@ -26,7 +27,10 @@ class UpdateLatinizeUrl extends Maintenance {
}
public function execute() {
global $wgLatinizeUrlConfig;
$service = MediaWikiServices::getInstance();
$config = $service->getMainConfig();
$latinizeUrlConf = $config->get('LatinizeUrlConfig');
$force = $this->hasOption( 'force' );
$outputFileName = $this->getArg( 0 );
@ -35,12 +39,12 @@ class UpdateLatinizeUrl extends Maintenance {
$outputFile = fopen($outputFileName, 'w');
}
$dbw = $this->getDB( DB_MASTER );
$dbw = $this->getDB( DB_PRIMARY );
if ( $dbw->getType() !== 'mysql' ) {
$this->fatalError( "This change is only needed on MySQL, quitting.\n" );
}
$convertor = new ChineseConvertor($wgLatinizeUrlConfig);
$convertor = new ChineseConvertor($latinizeUrlConf);
$res = $this->findRows( $dbw );
foreach($res as $one){
@ -65,11 +69,16 @@ class UpdateLatinizeUrl extends Maintenance {
}
public function searchIndexUpdateCallback( $dbw, $row ) {
return $this->updateSearchIndexForPage( $dbw, $row->si_page );
// return $this->updateSearchIndexForPage( $dbw, $row->si_page );
}
private function getFullUrl($pageName) {
global $wgServer, $wgArticlePath, $wgUsePathInfo;
$service = MediaWikiServices::getInstance();
$config = $service->getMainConfig();
$wgServer = $config->get('Server');
$wgArticlePath = $config->get('ArticlePath');
$wgUsePathInfo = $config->get('UsePathInfo');
$pageName = implode("/", array_map("urlencode", explode("/", $pageName)));
if($wgUsePathInfo){
return $wgServer . str_replace('$1', $pageName, $wgArticlePath);

@ -1,9 +1,9 @@
{
"name": "chs/pinyin-url",
"name": "hyperzlib/pinyin-url",
"type": "project",
"authors": [
{
"name": "无名写手",
"name": "hyperzlib",
"email": "hyperzlib@outlook.com"
}
],

@ -1,11 +1,14 @@
{
"name": "LatinizeUrl",
"author": "hyperzlib",
"author": "Hyperzlib",
"url": "https://github.com/Isekai-Project/mediawiki-extension-LatinizeUrl",
"descriptionmsg": "latinizeurl-desc",
"version": "1.0.4",
"license-name": "MIT",
"type": "other",
"requires": {
"MediaWiki": ">= 1.39.0"
},
"ExtensionMessagesFiles": {
"LatinizeUrlAlias": "LatinizeUrl.alias.php"
},
@ -29,8 +32,8 @@
"Collation::factory": [
"LatinizeUrl\\Hooks::onCollationFactory"
],
"SkinTemplateOutputPageBeforeExec": [
"LatinizeUrl\\Hooks::onSkinTemplateOutputPageBeforeExec"
"SkinTemplateNavigation::Universal": [
"LatinizeUrl\\Hooks::addToolboxLink"
],
"BeforePageDisplay": [
"LatinizeUrl\\Hooks::onBeforePageDisplay"
@ -38,14 +41,14 @@
"InitializeParseTitle": [
"LatinizeUrl\\Hooks::onInitializeParseTitle"
],
"ArticleDeleteComplete": [
"LatinizeUrl\\Hooks::onArticleDeleteComplete"
"PageDeleteComplete": [
"LatinizeUrl\\Hooks::onPageDeleteComplete"
],
"PageContentInsertComplete": [
"LatinizeUrl\\Hooks::onPageContentInsertComplete"
"PageSaveComplete": [
"LatinizeUrl\\Hooks::onPageSaveComplete"
],
"TitleMoveComplete": [
"LatinizeUrl\\Hooks::onTitleMoveComplete"
"PageMoveComplete": [
"LatinizeUrl\\Hooks::onPageMoveComplete"
],
"GetLocalURL": [
"LatinizeUrl\\Hooks::onGetArticleUrl"
@ -67,7 +70,12 @@
"remoteExtPath": "LatinizeUrl"
},
"config": {
"LatinizeUrlForceRedirect": true
"LatinizeUrlConfig": {
"value": {}
},
"LatinizeUrlForceRedirect": {
"value": true
}
},
"manifest_version": 1
"manifest_version": 2
}

@ -1,5 +1,5 @@
{
"latinizeurl-desc": "Latinize none-ASCII chars in url.",
"latinizeurl-desc": "Convert none-ASCII chars to ASCII chars in url.",
"latinizeurl-customurl": "Custom URL",
"customurl-legend": "Custom URL",
"customurl-url-field-label": "The URL you want to use:",

@ -1,10 +1,10 @@
{
"latinizeurl-desc": "漢字をローマ字に変換する",
"latinizeurl-desc": "URLの漢字と仮名をローマ字に変換する",
"latinizeurl-customurl": "URLの編集",
"customurl-legend": "URLの編集",
"customurl-url-field-label": "使用したいURL",
"customurl-url-field-help": "ASCII文字をお勧めします。入力しない場合は、漢字に対応するローマ字が自動的に生成されます。",
"customurl-url-field-help": "ASCII文字をお勧めします。入力しない場合は、漢字と仮名に対応するローマ字が自動的に変換されます。",
"rename-subpage-checkbox-label": "下位ページのURLを一緒に変更する",
"customurl-set-success": "このページの新しいURLは [[$1|$2]].",
"customurl-set-success": "このページの新しいURLは [[$1|$2]] です.",
"customurl-set-failed": "このURLは無効です。"
}

@ -1,5 +1,5 @@
{
"latinizeurl-desc": "把url中的汉字转换成拼音。",
"latinizeurl-desc": "将URL中的汉字转换成拼音。",
"latinizeurl-customurl": "自定义URL",
"customurl-legend": "自定义URL",
"customurl-url-field-label": "你想要设置的URL",

@ -1,13 +1,14 @@
<?php
namespace LatinizeUrl;
use MediaWiki\Linker\LinkTarget;
use Title;
use Article;
use OutputPage;
use User;
use MediaWiki\Linker\LinkRenderer;
use MediaWiki\Linker\LinkTarget;
use MediaWiki\MediaWikiServices;
use MediaWiki\Page\ProperPageIdentity;
use MediaWiki\Permissions\Authority;
use MediaWiki\User\UserIdentity;
use TitleValue;
use Wikimedia\Rdbms\DBQueryError;
class Hooks {
@ -37,7 +38,10 @@ class Hooks {
/* 将拼音映射转换为原标题 */
public static function onInitializeParseTitle(Title &$title, $request) {
global $wgLatinizeUrlForceRedirect;
$service = MediaWikiServices::getInstance();
$config = $service->getMainConfig();
$wgLatinizeUrlForceRedirect = $config->get('LatinizeUrlForceRedirect');
if(in_array($title->getNamespace(), self::$allowedNS)){
$realTitle = Utils::getTitleBySlugUrl($title, $title->getNamespace());
@ -59,43 +63,54 @@ class Hooks {
try {
if(in_array($title->getNamespace(), self::$allowedNS) && Utils::titleSlugExists($title)){
$slug = Title::newFromText(Utils::getSlugUrlByTitle($title), $title->getNamespace());
if ($slug) {
$slugEncoded = Utils::encodeUriComponent($slug->getPrefixedText());
$titleEncoded = Utils::encodeUriComponent($title->getPrefixedText());
$url = str_replace($titleEncoded, $slugEncoded, $url);
}
}
} catch(DBQueryError $ex){
}
}
public static function onArticleDeleteComplete(&$article, User &$user, $reason, $id, \Content $content = null, \LogEntry $logEntry){
if(in_array($article->getTitle()->getNamespace(), self::$allowedNS)){
Utils::removeTitleSlugMap($article->getTitle()->getText());
public static function onPageDeleteComplete(ProperPageIdentity $page, Authority $deleter, $reason, $pageID, $deletedRev, $logEntry, $archivedRevisionCount) {
$title = TitleValue::newFromPage( $page );
if(in_array($title->getNamespace(), self::$allowedNS)){ //不是普通页面就跳过
Utils::removeTitleSlugMap($title->getText());
}
}
public static function onPageContentInsertComplete(\WikiPage &$wikiPage, User &$user, $content, $summary, $isMinor, $isWatch, $section, &$flags, $revision){
/**
* @param \WikiPage $wikiPage
* @param \MediaWiki\User\UserIdentity $user
* @param string $summary
* @param int $flags
* @param \MediaWiki\Revision\RevisionRecord $revisionRecord
* @param \MediaWiki\Storage\EditResult $editResult
*/
public static function onPageSaveComplete(&$wikiPage, $user, $summary, $flags, $revisionRecord, $editResult){
if(!in_array($wikiPage->getTitle()->getNamespace(), self::$allowedNS)){ //不是普通页面就跳过
return;
}
try {
if ($flags & EDIT_NEW) {
$title = $wikiPage->getTitle();
$parsedData = Utils::parseTitleToAscii($title, $title->getPageLanguage());
Utils::addTitleSlugMap($title->getText(), $parsedData['slug'], $parsedData['latinize']);
} catch (\Exception $e) {
}
}
public static function onTitleMoveComplete(Title &$title, Title &$newTitle, User $user, $oldid, $newid, $reason, $revision){
if(!in_array($newTitle->getNamespace(), self::$allowedNS)){ //不是普通页面就跳过
public static function onPageMoveComplete(LinkTarget $old, LinkTarget $new, UserIdentity $userIdentity, $pageid, $redirid, $reason, $revision) {
if (!in_array($new->getNamespace(), self::$allowedNS)) { //不是普通页面就跳过
return;
}
$title = MediaWikiServices::getInstance()->getTitleFactory()->newFromLinkTarget($new);
try {
$parsedData = Utils::parseTitleToAscii($newTitle, $newTitle->getPageLanguage());
Utils::addTitleSlugMap($newTitle->getText(), $parsedData['slug'], $parsedData['latinize']);
$parsedData = Utils::parseTitleToAscii($title, $title->getPageLanguage());
Utils::addTitleSlugMap($title->getText(), $parsedData['slug'], $parsedData['latinize']);
} catch (\Exception $e) {
}
@ -117,14 +132,14 @@ class Hooks {
}
}
public static function onSkinTemplateOutputPageBeforeExec(\Skin $skin, \QuickTemplate $template){
public static function addToolboxLink(\Skin $skin, array &$links){
$service = MediaWikiServices::getInstance();
$user = $skin->getContext()->getUser();
$title = $skin->getRelevantTitle();
if(in_array($title->getNamespace(), self::$allowedNS)){
if($service->getPermissionManager()->userHasRight($user, 'delete') || Utils::hasUserEditedPage($title, $user)){
$template->data['content_navigation']['page-secondary']['custom-url'] = [
$links['page-secondary']['custom-url'] = [
'class' => false,
'text' => wfMessage('latinizeurl-customurl')->text(),
'href' => \SpecialPage::getTitleFor('CustomUrl', $title->getPrefixedDBKey())->getLocalURL(),

@ -5,7 +5,7 @@ use Collation;
use MediaWiki\MediaWikiServices;
class LatinizeCollation extends Collation {
private $cache = null;
private $cache;
public function __construct(){
$this->cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
@ -18,8 +18,7 @@ class LatinizeCollation extends Collation {
function() use($string){
$convertor = Utils::getConvertor();
$latinize = $convertor->parse($string);
$slug = Utils::wordListToUrl($latinize);
return $slug;
return Utils::wordListToUrl($latinize);
}
);
}

@ -15,7 +15,7 @@ class Patcher {
}
public function findPatchVersion($name){
$regex = '/\/\/ Start ' . $this->tag . ' ([0-9\.\-]+) ' . $name . ' Patch\n.*?\/\/ End ' . $this->tag . ' [0-9\.\-]+ ' . $name . ' Patch/is';
$regex = '/\/\/ Start ' . $this->tag . ' ([0-9.\-]+) ' . $name . ' Patch\n.*?\/\/ End ' . $this->tag . ' [0-9.\-]+ ' . $name . ' Patch/is';
if(preg_match($regex, $this->content, $matches, PREG_OFFSET_CAPTURE)){
$ret = [];
$ret['start'] = $matches[0][1];
@ -53,7 +53,7 @@ class Patcher {
if(!is_array($content)) $content = explode("\n", $content);
$lines = array_merge([
'// Start ' . $this->tag . ' ' . $this->version . ' ' . $name . ' Patch',
'// This code is added by ' . $this->tag . ', Donnot remove this code untill you uninstall ' . $this->tag . '.',
'// This code is added by ' . $this->tag . ' extension, Do not remove this code until you uninstall ' . $this->tag . ' extension.',
], $content, [
'// End ' . $this->tag . ' ' . $this->version . ' ' . $name . ' Patch',
]);

@ -7,7 +7,9 @@ use ExtensionRegistry;
use Title;
use User;
use Language;
use MediaWiki\Extension\AbuseFilter\Consequences\Consequence\Tag;
use MediaWiki\MediaWikiServices;
use StubUserLang;
class Utils {
private static $dbr = null;
@ -16,13 +18,15 @@ class Utils {
public static function initMasterDb(){
if(!self::$dbw){
self::$dbw = wfGetDB(DB_MASTER);
self::$dbw = MediaWikiServices::getInstance()->getDBLoadBalancer()
->getMaintenanceConnectionRef(DB_PRIMARY);
}
}
public static function initReplicaDb(){
if(!self::$dbr){
self::$dbr = wfGetDB(DB_REPLICA);
self::$dbr = MediaWikiServices::getInstance()->getDBLoadBalancer()
->getMaintenanceConnectionRef(DB_REPLICA);
}
}
@ -336,7 +340,7 @@ class Utils {
}
/**
* @param Language|string|null $language - 语言
* @param Language|StubUserLang|string|null $language - 语言
* @return BaseConvertor 转换器
*/
public static function getConvertor($language = null) {
@ -344,7 +348,7 @@ class Utils {
$language = MediaWikiServices::getInstance()->getContentLanguage();
}
if($language instanceof Language){
if (is_callable([$language, 'getCode'])) {
$language = $language->getCode();
}
@ -360,7 +364,7 @@ class Utils {
/**
* @param Title $title - 要转换的标题
* @param Language|string|null $language - 语言
* @param Language|StubUserLang|string|null $language - 语言
* @return mixed 转换器
*/
public static function parseTitleToAscii(Title $title, Language $language){

@ -1,70 +1,184 @@
<?php
namespace LatinizeUrl;
use FormSpecialPage;
use UnlistedSpecialPage;
use Html;
use MediaWiki\MediaWikiServices;
use phpDocumentor\Reflection\DocBlock\Tags\Var_;
use MediaWiki\Session\CsrfTokenSet;
use ThrottledError;
class SpecialCustomUrl extends FormSpecialPage
{
class SpecialCustomUrl extends UnlistedSpecialPage {
/**
* @var \Title $title
* @var string
*/
protected $target;
/**
* @var \Title
*/
protected $title;
/** @var string */
protected $slug;
/** @var bool */
protected $isAdmin;
/** @var bool */
protected $userEditedPage;
public function __construct()
{
/** @var NamespaceInfo */
private $nsInfo;
/** @var LinkBatchFactory */
private $linkBatchFactory;
public function __construct() {
parent::__construct('CustomUrl', '', false);
$service = MediaWikiServices::getInstance();
$this->nsInfo = $service->getNamespaceInfo();
$this->linkBatchFactory = $service->getLinkBatchFactory();
}
public function doesWrites()
{
public function doesWrites() {
return true;
}
public function execute($par)
{
parent::execute($par);
public function execute($par) {
$this->useTransactionalTimeLimit();
$this->getSkin()->setRelevantTitle($this->title);
$out = $this->getOutput();
$out->setPageTitle($this->msg('latinizeurl-customurl', $this->title->getPrefixedText()));
}
$this->checkReadOnly();
$this->setHeaders();
$this->outputHeader();
protected function setParameter( $par ) {
$service = MediaWikiServices::getInstance();
$title = \Title::newFromText( $par );
$request = $this->getRequest();
$this->target = $par ?? $request->getText('target');
$title = \Title::newFromText($this->target);
$this->title = $title;
$this->getSkin()->setRelevantTitle($this->title);
$user = $this->getUser();
if (!$title) {
throw new \ErrorPageError( 'notargettitle', 'notargettext' );
return;
}
if (!$title->exists()) {
throw new \ErrorPageError( 'nopagetitle', 'nopagetext' );
}
$isAdmin = $service->getPermissionManager()->userHasRight($this->getUser(), 'delete');
$isAdmin = $service->getPermissionManager()->userHasRight($this->getUser(), 'move');
$this->isAdmin = $isAdmin;
$userEditedPage = Utils::hasUserEditedPage($this->title, $this->getUser());
$this->userEditedPage = $userEditedPage;
$this->slug = $this->getCurrentSlug();
if (!$this->hasAccess()){
throw new \PermissionsError('move');
}
$this->slug = $this->getCurrentSlug();
if ($request->getRawVal('action') == 'submit' && $request->wasPosted() && $user->matchEditToken($request->getVal('wpEditToken'))) {
$this->doSubmit();
} else {
$this->showForm( [] );
}
}
protected function hasAccess(){
return $this->isAdmin || $this->userEditedPage;
}
protected function showForm($err, $isPermErr){
protected function showForm($err, $isPermError = false){
$user = $this->getUser();
$out = $this->getOutput();
$out->setPageTitle($this->msg('latinizeurl-customurl'));
$out->addModuleStyles([
'mediawiki.special',
'mediawiki.interface.helpers.styles'
]);
$out->addModules('mediawiki.misc-authed-ooui');
$out->enableOOUI();
$fields = [];
$fields[] = new \OOUI\FieldLayout(
new \OOUI\TextInputWidget([
'name' => 'wpSlug',
'id' => 'wpSlug',
'value' => $this->getCurrentSlug(),
]),
[
'label' => $this->msg('customurl-url-field-label')->text(),
'help' => $this->msg('customurl-url-field-help')->text(),
'align' => 'top',
]
);
if ($this->title->hasSubpages()) {
$fields[] = new \OOUI\FieldLayout(
new \OOUI\CheckboxInputWidget([
'name' => 'wpRenameSubpage',
'id' => 'wpRenameSubpage',
'value' => '1',
]),
[
'label' => $this->msg('rename-subpage-checkbox-label')->text(),
'align' => 'inline',
]
);
}
$fields[] = new \OOUI\FieldLayout(
new \OOUI\ButtonInputWidget( [
'name' => 'wpConfirm',
'value' => $this->msg('htmlform-submit')->text(),
'label' => $this->msg('htmlform-submit')->text(),
'flags' => ['primary', 'progressive'],
'type' => 'submit',
]),
[
'align' => 'top',
]
);
$fieldset = new \OOUI\FieldsetLayout( [
'label' => $this->msg('customurl-legend')->text(),
'id' => 'mw-customurl-table',
'items' => $fields,
] );
$form = new \OOUI\FormLayout([
'method' => 'post',
'action' => $this->getPageTitle($this->target)->getLocalURL('action=submit'),
'id' => 'customurl',
]);
$form->appendContent(
$fieldset,
new \OOUI\HtmlSnippet(
Html::hidden('wpEditToken', $user->getEditToken())
)
);
$out->addHTML(
new \OOUI\PanelLayout([
'classes' => ['movepage-wrapper', 'customurl-wrapper'],
'expanded' => false,
'padded' => true,
'framed' => true,
'content' => $form,
])
);
if ($this->title->hasSubpages()) {
$this->showSubpages($this->title);
}
}
private function getCurrentSlug(){
@ -76,30 +190,19 @@ class SpecialCustomUrl extends FormSpecialPage
}
}
protected function getFormFields() {
$fields = [];
$fields['slug'] = [
'type' => 'text',
'label-message' => 'customurl-url-field-label',
'help-message' => 'customurl-url-field-help',
'default' => $this->getCurrentSlug(),
];
public function doSubmit() {
$user = $this->getUser();
if($this->title->hasSubpages()){
$fields['rename-subpage'] = [
'type' => 'check',
'label-message' => 'rename-subpage-checkbox-label',
'default' => false,
];
if ($user->pingLimiter('customurl')) {
throw new ThrottledError;
}
return $fields;
}
$request = $this->getRequest();
$slug = $request->getText('wpSlug');
$renameSubpages = $request->getBool('wpRenameSubpage');
public function onSubmit(array $data, \HTMLForm $form = null ) {
$originSlug = Utils::getSlugByTitle($this->title);
$slug = $data['slug'];
$latinize = [];
if (empty($slug)) { //自动生成
$parsedData = Utils::parseTitleToAscii($this->title, $this->title->getPageLanguage());
@ -118,7 +221,7 @@ class SpecialCustomUrl extends FormSpecialPage
$realSlug = Utils::addTitleSlugMap($this->title->getText(), $slug, $latinize, $custom);
}
if(isset($data['rename-subpage']) && $data['rename-subpage']){
if($renameSubpages){
//更新子页面的slug
$subpages = $this->title->getSubpages();
$originSlugLen = strlen($originSlug);
@ -132,11 +235,76 @@ class SpecialCustomUrl extends FormSpecialPage
}
}
$this->slug = $realSlug;
$this->onSuccess();
return true;
}
/**
* Show subpages of the page being moved. Section is not shown if both current
* namespace does not support subpages and no talk subpages were found.
*
* @param Title $title Page being moved.
*/
private function showSubpages( $title ) {
$nsHasSubpages = $this->nsInfo->hasSubpages( $title->getNamespace() );
$subpages = $title->getSubpages();
$count = $subpages instanceof \TitleArray ? $subpages->count() : 0;
$titleIsTalk = $title->isTalkPage();
$subpagesTalk = $title->getTalkPage()->getSubpages();
$countTalk = $subpagesTalk instanceof \TitleArray ? $subpagesTalk->count() : 0;
$totalCount = $count + $countTalk;
if ( !$nsHasSubpages && $countTalk == 0 ) {
return;
}
$this->getOutput()->wrapWikiMsg(
'== $1 ==',
[ 'movesubpage', ( $titleIsTalk ? $count : $totalCount ) ]
);
if ( $nsHasSubpages ) {
$this->showSubpagesList( $subpages, $count, 'movesubpagetext', true );
}
if ( !$titleIsTalk && $countTalk > 0 ) {
$this->showSubpagesList( $subpagesTalk, $countTalk, 'movesubpagetalktext' );
}
}
private function showSubpagesList( $subpages, $pagecount, $wikiMsg, $noSubpageMsg = false ) {
$out = $this->getOutput();
# No subpages.
if ( $pagecount == 0 && $noSubpageMsg ) {
$out->addWikiMsg( 'movenosubpage' );
return;
}
$out->addWikiMsg( $wikiMsg, $this->getLanguage()->formatNum( $pagecount ) );
$out->addHTML( "<ul>\n" );
$linkBatch = $this->linkBatchFactory->newLinkBatch( $subpages );
$linkBatch->setCaller( __METHOD__ );
$linkBatch->execute();
$linkRenderer = $this->getLinkRenderer();
foreach ( $subpages as $subpage ) {
$link = $linkRenderer->makeLink( $subpage );
$out->addHTML( "<li>$link</li>\n" );
}
$out->addHTML( "</ul>\n" );
}
public function onSuccess(){
$out = $this->getOutput();
$out->setPageTitle($this->msg('latinizeurl-customurl'));
$out->addWikiMsg('customurl-set-success', $this->title->getText(), str_replace(' ', '_', $this->slug));
}
protected function getGroupName() {
return 'pagetools';
}
}

Loading…
Cancel
Save