将 MediaWiki 模板参数传递给自定义 HTML 属性

问题描述

考虑一个自定义的 Mediawiki 扩展,它使用一些 JavaScript 添加一个名为 simplified_example 的新标签(为了简单起见,只需使用提供的参数调用 alert):

<?PHP
if ( ! defined( 'MEdiawiKI' ) ) die();

$wgExtensionFunctions[] = 'registerTags';
$wgExtensionCredits['parserhook'][] = array(
    'name' => 'mytags',);

function registerTags() {
    global $wgParser;
    $wgParser->setHook('simplified_example',function ($input,$argv,$parser,$frame) {
        $output = $parser->recursiveTagParse($input,$frame);
        $title = $argv["value"];
        return "<div onclick=\"alert('$title')\">$output</div>";
    });
}
?>

使用它,我可以将以下代码放入 Mediawiki 页面源中:

<simplified_example value="Testing">...</simplified_example>

这导致 ... div 可点击 - 显示带有提供文本的消息框。现在我想把这个标签放在一个模板中,就像这样:

<simplified_example value="{{{TestTemplate|Testing...}}
}">...</simplified_example>

当我将此模板放入 Mediawiki 页面时:

...

我再次获得可点击的 {Testing...},但未评估显示的消息,而是显示 TableRecycleGridLayout: id: row_controller key_selection: "selectable" cols: root.total_col_headings cols_minimum: root.cols_minimum default_size: None,dp(52) default_size_hint: 1,None size_hint: None,None height: self.minimum_height width: self.minimum_width multiselect: True touch_multiselect: True 而不是提供的 { "compilerOptions": { "target": "es2015","module": "esnext","moduleResolution": "node","lib": [ "es2018","dom" ],"noImplicitReturns": true,"experimentalDecorators": true,"emitDecoratorMetadata": true,"noEmitOnError": true,"removeComments": true,"sourceMap": true,"skipLibCheck": true,"strictFunctionTypes": true,"strictPropertyInitialization": false,"noUnusedLocals": false,"noImplicitAny": false,"noImplicitThis": false,"strictnullchecks": false,"allowUnreachableCode": false,"downlevelIteration": true },"angularCompilerOptions": { "entryModule": "/src/app.module#MyModule","skipMetadataEmit": true,"enableIvy": false },"exclude": [ "node_modules"] } }

如何通过模板将 Mediawiki 页面源中的参数传递给我的自定义标签

解决方法

尝试在模板中使用 #tag 函数而不是 html,如下所示:

{{#tag:simplified_example|value={brew autoremove} }}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...