考虑一个自定义的 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 页面源中的参数传递给我的自定义标签?
答案 0 :(得分:3)
尝试在模板中使用 #tag
函数而不是 html,如下所示:
{{#tag:simplified_example|value={brew autoremove
} }}