AllowAnchorTags
天下维客,你可以修改的网络知识库
| Template:If | |
| Type: | |
|---|---|
| Maturity: | {{{maturity}}} |
| MediaWiki: | 1.9.3 |
| Version: | 1.0 |
| Last Update: | |
| Description: | 此扩展允许 <anchor></anchor> 标记. 他将解析为 <a href=></a> 标记 |
| MediaWiki extensions | |
目录 |
[编辑]
作用
此扩展允许 <anchor></anchor> 标记. 他将解析为 <a href=></a> 标记
[编辑]
用法
例子: <anchor url='http://someurl.com' target='_blank'>说明文字</anchor>
[编辑]
安装
在'LocalSettings.php' 文件底部添加下面的代码.
[编辑]
参数
[编辑]
修改 LocalSettings.php
require_once("/extensions/AllowAnchorTags/anchor_tags.php");
[编辑]
代码(anchor_tags.php)
# Defines the main function to be executed for this extension.
$wgExtensionFunctions[] = 'addAnchorTag';
# Sets the hook to be executed once the parser has stripped HTML tags.
$wgHooks['ParserAfterStrip'][] = 'addAnchorTag';
# This function initiates the hook for the parser to convert <anchor></anchor>
# tags to <a href=''></a> tags.
function addAnchorTag() {
// Declaring the global parser..
global $wgParser;
// Setting the hook to parse <anchor></anchor> tags from the parser output..
$wgParser->setHook( 'anchor', 'startAddAnchor' );
}
# This function extracts the parameters from the <anchor></anchor> tags and
# the text between the <anchor> and </anchor> tags and formats them as "<a href=''>"
# tags and writes them in the document.
function startAddAnchor( $input, $argv ) {
// Matching to see if the URL matches the prefixes in $wgUrlProtocols..
if (preg_match("/^(http:\/\/|https:\/\/|ftp:\/\/|irc:\/\/|gopher:\/\/|news:|mailto:)/", $argv['url'])) {
// Fetching the 'url' parameter..
$url = $argv['url'];
} else {
$url = '';
}
// Fetching the 'target' parameter..
$target = $argv['target'];
if ($url!= '' && $target!= '') {
// If a target parameter exists then print the link with it..
return "<a href=\"" . htmlspecialchars($url) . "\" target=\"" . htmlspecialchars($target) . "\">" . htmlspecialchars($input) . "</a>";
} else if ($url!= '') {
// If a target parameter does not exist then just print the link with the 'href' URL..
return "<a href=\"" . htmlspecialchars($url) . "\">" . htmlspecialchars($input) . "</a>";
} else {
return '';
}
}
[编辑]
参考
在这个网址可以下载此文件:
http://www.esnips.com/doc/7b9b43d8-6f3b-4f5b-99f6-ef9eb52f5a59/anchor_tags
在这个网址可以看见该功能的截图:
http://www.esnips.com/doc/b8119fa7-9130-4528-94a3-324287ebd2eb/anchor_tags_screenshot


