Jump to content

Extension:LinkTarget

From mediawiki.org
This page is a translated version of the page Extension:LinkTarget and the translation is 100% complete.
This extension is professionally maintained by the WikiTeq team.
WikiTeq provides official support for MediaWiki LTS releases only. It may work with other MediaWiki releases.
MediaWiki 拡張機能マニュアル
LinkTarget
リリースの状態: 安定
実装 自分のウィキ
説明 Adds a target attribute to specified links
作者 Ike Hecht (Tosfosトーク)
メンテナー WikiTeq team
最新バージョン 0.2.0 ()
互換性の方針 長期間サポート リリースであるすべての MediaWiki リリースについて、拡張機能に対応するブランチが存在します。
MediaWiki 1.35, 1.39
データベースの変更 いいえ
ライセンス GNU 一般公衆利用許諾書 2.0 以降
ダウンロード

  • $wgLinkTargetParentClasses
  • $wgLinkTargetDefault
四半期ごとのダウンロード数 28 (Ranked 112nd)
translatewiki.net で翻訳を利用できる場合は、LinkTarget 拡張機能の翻訳にご協力ください
問題点 未解決のタスク · バグを報告

The LinkTarget extension allows admins to add a target attribute to internal and external links. That can be used to, for example, open internal and external links in new windows.

This extension was created for WikiWorks.


インストール

  • ダウンロードして、ファイルをextensions/フォルダー内のLinkTargetという名前のディレクトリ内に配置します。
    開発者とコード寄稿者は、上記の代わりに以下を使用してGitからインストールします:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/LinkTarget
  • 以下のコードを LocalSettings.php ファイルの末尾に追加します:
    wfLoadExtension( 'LinkTarget' );
    $wgLinkTargetParentClasses = ' /*ENTER SOME CLASSES HERE*/ ';
    
  • Yes 完了 – ウィキの「Special:Version」に移動して、拡張機能が正しくインストールされたことを確認します。

設定

$wgLinkTargetParentClasses
The descendants of elements of this class will have their target attribute set by the extension. Expects an array with the format:
[
     target => [ classes ],
     target => [ classes ],
      ... 
]
If target is not specified or is invalid, the target will be set to $wgLinkTargetDefault. Note that it is also valid to specify one class as a string, instead of an array of classes.
$wgLinkTargetDefault
The default target for parent classes that do not have a valid target specified.
Can be set to: _blank, _self, _parent or _top. Defaults to _blank.

In LocalSettings.php:

$wgLinkTargetParentClasses = [ 'foo', 'bar' ];

Adds target="_blank" as an attribute to links that are children of an HTML element that belong to either class "foo" or "bar". To use in the wiki:

This is some text with an <span class="foo">[[Internal link]]</span> and also an <span class="bar">[https://www.mediawiki.org External link]</span>.

In that example, both links will open in new windows or tabs.

Example 2: Open specific images in new windows

Using the same LocalSettings as in Example 1, in the wiki use:

<div class="bar">[[File:SomeImage|link=mediawiki.org]]</div>
$wgExternalLinkTarget = '_blank';
$wgLinkTargetParentClasses = [ 'foo', 'bar' ];
$wgLinkTargetDefault = '_self';

In the wiki:

[[This link]] will open in a new window, but not <span class="foo">[[this one]]</span>.

Example 4: Use with extensions

Surround extension parser functions or tags with some code and open any links generated by those extensions in a new window. As an example, we will use the Flickr API extension, with the LocalSettings code from Example 1:

<div class="foo"><flickr>SOMEIMAGEID</flickr></div>

Actually, that extension helpfully already surrounds any code that it generates with a class so really it is sufficient to set LocalSettings as follows:

$wgLinkTargetParentClasses = [ 'flickrapi' ];

This will apply to all Flickr images generated by the extension. When users click on any image, the link will open in a new window or tab.

Advanced

$wgLinkTargetParentClasses = [
     '_top' => [ 'foo' ],
     [ 'bar' ],
     '_parent' => 'baz'
];

Descendants of 'foo' will have target '_top', descendants of 'bar' will have target '_blank' and descendants of 'baz' will have target '_parent'.

既知の制限

  • The links will not have any special target while viewing the page in "preview" mode.

関連項目