自动将所有网站链接更改为附属链接 [英] Change all website links to affiliate links automatically

查看:27
本文介绍了自动将所有网站链接更改为附属链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在我的 MediaWiki 安装中自动将链接自动更改为附属链接.这将有助于减少管理链接的时间,以防将来需要更改代码.

I would like to be able to automatically change links into affiliate links automatically on my MediaWiki installation. This would help to reduce the amount of time managing links in case the code needs to be changed in the future.

这是我的 GOG.com 联盟计划的设置:我需要将此密钥附加到每个 GOG.com 链接的末尾:?pp=708a77db476d737e54b8bf4663fc79b346d696d2

This is the setup of my GOG.com affiliate scheme: I need to append this key to the end of every GOG.com link: ?pp=708a77db476d737e54b8bf4663fc79b346d696d2

gog.com/en/gamecard/baldurs_gate_the_original_saga/?pp=708a77db476d737e54b8bf4663fc79b346d696d2

一段代码,比如Javascript,是否可以拦截所有链接(比如http://www.gog.com/en/gamecard/baldurs_gate_the_original_saga/)并附加附属代码最后,如上例所示?

Is it possible for a piece of code, like Javascript, to intercept all links (like http://www.gog.com/en/gamecard/baldurs_gate_the_original_saga/) and append the affiliate code on the end, as in the above example?

我知道这段 Javascript 代码叫做 Amazon Associate Link Localiser 做类似的事情.但是,它仅适用于亚马逊链接,而且它还会本地化链接,这是我不想要的功能.

I'm aware of this piece of Javascript code called Amazon Associate Link Localiser which does a similar thing. However, it only works for Amazon links, and it also localises links which is a feature I don't want.

推荐答案

正确的方法是使用 LinkerMakeExternalLink 像这样的 mediawiki 钩子(你可以把它放在你的 LocalSettings.php 的底部:

Right way is to use LinkerMakeExternalLink mediawiki hook like that ( you can put it at bottom of your LocalSettings.php:

$wgHooks['LinkerMakeExternalLink'][] = 'ExampleExtension::exampleLinkerMakeExternalLink';

class ExampleExtension {
    public static function exampleLinkerMakeExternalLink( &$url, &$text, &$link, &$attribs, $linktype ) {
        if( strpos( $url, 'gog.com') !== false ) {
            $url .= '?pp=708a77db476d737e54b8bf4663fc79b346d696d2';
        }
        return false;
    }
}

这篇关于自动将所有网站链接更改为附属链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆