Merge branch 'master' of git-ssh.isekai.cn:Isekai-Project/IsekaiMisc

master
落雨楓 1 month ago
commit d1ffc0fd27

@ -1,6 +1,7 @@
<?php <?php
namespace Isekai; namespace Isekai;
use Wikimedia\Parsoid\DOM\Element;
use Wikimedia\Parsoid\Ext\ExtensionTagHandler; use Wikimedia\Parsoid\Ext\ExtensionTagHandler;
use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI; use Wikimedia\Parsoid\Ext\ParsoidExtensionAPI;
@ -8,18 +9,17 @@ class BlockQuoteTagHandler extends ExtensionTagHandler {
public function sourceToDom(ParsoidExtensionAPI $extApi, string $src, array $extArgs) { public function sourceToDom(ParsoidExtensionAPI $extApi, string $src, array $extArgs) {
return $extApi->extTagToDOM( return $extApi->extTagToDOM(
$extArgs, $extArgs,
'',
$src, $src,
[ [
'wrapperTag' => 'span', 'wrapperTag' => 'span',
'parseOpts' => [ 'parseOpts' => [
'extTag' => 'blockquote', 'extTag' => 'blockquote',
], ],
], ]
); );
} }
public function getInnerWikitext(ParsoidExtensionAPI $extApi, \DOMElement $dom) { public function getInnerWikitext(ParsoidExtensionAPI $extApi, Element $dom) {
$wikiText = ''; $wikiText = '';
foreach($dom->childNodes as $child){ foreach($dom->childNodes as $child){
if($child instanceof \DOMText){ if($child instanceof \DOMText){
@ -31,7 +31,7 @@ class BlockQuoteTagHandler extends ExtensionTagHandler {
return $wikiText; return $wikiText;
} }
public function domToWikitext(ParsoidExtensionAPI $extApi, \DOMElement $node, bool $wrapperUnmodified): string { public function domToWikitext(ParsoidExtensionAPI $extApi, Element $node, bool $wrapperUnmodified): string {
$innerCode = $this->getInnerWikitext($extApi, $node); $innerCode = $this->getInnerWikitext($extApi, $node);
return "<span>\n{$innerCode}\n</span>"; return "<span>\n{$innerCode}\n</span>";
} }

@ -3,14 +3,15 @@
namespace Isekai; namespace Isekai;
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
use Config; use MediaWiki\Config\Config;
use OutputPage; use MediaWiki\Output\OutputPage;
use Html; use MediaWiki\Html\Html;
use Title; use MediaWiki\Title\Title;
use MediaWiki\User\User;
use MediaWiki\EditPage\EditPage;
use MediaWiki\Linker\LinkRenderer; use MediaWiki\Linker\LinkRenderer;
use MediaWiki\Linker\LinkTarget; use MediaWiki\Linker\LinkTarget;
use User; use MediaWiki\Parser\Parser;
use EditPage;
use Isekai\Job\CheckActivatedEditorJob; use Isekai\Job\CheckActivatedEditorJob;
class Isekai { class Isekai {
@ -268,10 +269,10 @@ HTML
} }
} }
public static function onParserBeforeInternalParse(\Parser $parser, &$text, $strip_state) { public static function onParserBeforeInternalParse(Parser $parser, &$text, $strip_state) {
$title = $parser->getPage(); $title = $parser->getPage();
if ($title !== null && $title instanceof \Title && $title->isSubpage()) { if ($title !== null && $title instanceof Title && $title->isSubpage()) {
//更改显示的标题 //更改显示的标题
$titleText = $title->getPrefixedText(); $titleText = $title->getPrefixedText();
if ($titleText) { if ($titleText) {

@ -1,7 +1,7 @@
<?php <?php
namespace Isekai; namespace Isekai;
use Html; use MediaWiki\Html\Html;
class IsekaiChart { class IsekaiChart {
/** /**

@ -1,11 +1,10 @@
<?php <?php
namespace Isekai\Job; namespace Isekai\Job;
use Exception;
use Isekai\MiscUtils; use Isekai\MiscUtils;
use Job; use Job;
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
use Title; use MediaWiki\Title\Title;
class CheckActivatedEditorJob extends Job { class CheckActivatedEditorJob extends Job {
public function __construct(Title $title, array $params){ public function __construct(Title $title, array $params){

@ -2,8 +2,8 @@
namespace Isekai; namespace Isekai;
use ApiMain; use ApiMain;
use FauxRequest; use MediaWiki\Request\FauxRequest;
use User; use MediaWiki\User\User;
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
class MiscUtils { class MiscUtils {

@ -2,13 +2,9 @@
namespace Isekai\Maintenance; namespace Isekai\Maintenance;
use Maintenance; use Maintenance;
use Config; use MediaWiki\Config\Config;
use ApiMain;
use FauxRequest;
use Isekai\MiscUtills;
use Isekai\MiscUtils; use Isekai\MiscUtils;
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
use Title;
use Wikimedia\Rdbms\IDatabase; use Wikimedia\Rdbms\IDatabase;
$IP = getenv( 'MW_INSTALL_PATH' ); $IP = getenv( 'MW_INSTALL_PATH' );

@ -31,4 +31,4 @@ if (mw.config.get('skin') === "timeless") {
veReadyTimer = setInterval(waitForVE, 500); veReadyTimer = setInterval(waitForVE, 500);
window.addEventListener('resize', updateToolbar, { passive: true }); window.addEventListener('resize', updateToolbar, { passive: true });
} }

@ -30,6 +30,63 @@ function updateVisualEditorConfig() {
} else { } else {
console.warn('Cannot find ve lib'); console.warn('Cannot find ve lib');
} }
if (mw.libs && mw.libs.ve && mw.libs.ve.targetLoader) {
var _oldRequestParsoidData = mw.libs.ve.targetLoader.requestParsoidData;
/**
* Request the page data and various metadata from the MediaWiki API (which will use
* Parsoid or RESTBase).
*
* @param {string} mode Target mode: 'visual' or 'source'
* @param {string} pageName Page name to request, in prefixed DB key form (underscores instead of spaces)
* @param {Object} [options]
* @param {boolean} [options.sessionStore] Store result in session storage (by page+mode+section) for auto-save
* @param {null|string} [options.section] Section to edit; number, 'T-'-prefixed, null or 'new' (currently just source mode)
* @param {number} [options.oldId] Old revision ID. Current if omitted.
* @param {string} [options.targetName] Optional target name for tracking
* @param {boolean} [options.modified] The page was been modified before loading (e.g. in source mode)
* @param {string} [options.wikitext] Wikitext to convert to HTML. The original document is fetched if undefined.
* @param {string} [options.editintro] Name of a page to use as edit intro message
* @param {string} [options.preload] Name of a page to use as preloaded content if pageName is empty
* @param {Array} [options.preloadparams] Parameters to substitute into preload if it's used
* @return {jQuery.Promise} Abortable promise resolved with a JSON object
*/
mw.libs.ve.targetLoader.requestParsoidData = function ( mode, pageName, options ) {
console.log('loading page data: ', pageName);
if (window.URL) {
var urlInfo = new URL(location.href);
let tplPageName = urlInfo.searchParams.get('tplPageName');
if (tplPageName) {
// 使用模板页面名替代页面名
pageName = tplPageName;
}
}
return _oldRequestParsoidData(mode, pageName, options);
}
} else {
console.log('mw.libs.ve.targetLoader not defined');
}
// 重写参数输入框
// 1. 添加下拉框类型
if (ve.ui && ve.ui.MWParameterPage) {
var _oldCreateValueInput = ve.ui.MWParameterPage.prototype.createValueInput;
ve.ui.MWParameterPage.prototype.createValueInput = function () {
var type = this.parameter.getType(),
value = this.parameter.getValue(),
valueInputConfig = this.getDefaultInputConfig();
if ( type === 'dropdown' ) {
return new ve.ui.MWParameterDropdownInputWidget( valueInputConfig, this.parameter.getDefaultValue() );
}
return _oldCreateValueInput.call(this);
}
} else {
console.log('ve.ui.MWParameterPage not defined');
}
} }
updateVisualEditorConfig(); updateVisualEditorConfig();
Loading…
Cancel
Save