allwiki首页  
天下维客 你可以修改的网络知识库
首页最近更改优秀条目专题展示电脑科技词典软件学习网络知识电脑安全明星时尚天下百科
 

AllowAnchorTags

天下维客,你可以修改的网络知识库

Jump to: navigation, search
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

Personal tools
工具
金银币拍卖 金币拍卖预展  金银币网店 熊猫金银币 生肖金银币