Extension:UrlShortener

From mediawiki.org
This page is a translated version of the page Extension:UrlShortener and the translation is 74% complete.
混同しないでください: Extension:ShortUrl.
MediaWiki 拡張機能マニュアル
UrlShortener
リリースの状態: 安定
実装 特別ページ , API , 自分のウィキ
説明 Provides a basic URL shortening service
作者 YuviPandaトーク
最新バージョン Continuous updates
MediaWiki 1.25+
PHP 5.4+
データベースの変更 はい
テーブル urlshortcodes
ライセンス Apache ライセンス 2.0
ダウンロード
ヘルプ Help:Extension:UrlShortener/ja
  • $wgUrlShortenerAllowArbitraryPorts
  • $wgUrlShortenerAllowedDomains
  • $wgUrlShortenerEnableQrCode
  • $wgUrlShortenerQrCodeShortenLimit
  • $wgUrlShortenerUrlSizeLimit
  • $wgUrlShortenerApprovedDomains
  • $wgUrlShortenerEnableSidebar
  • $wgUrlShortenerIdMapping
  • $wgUrlShortenerAltPrefix
  • $wgUrlShortenerTemplate
  • $wgUrlShortenerServer
  • $wgUrlShortenerReadOnly
  • $wgUrlShortenerIdSet
  • urlshortener-manage-url
  • urlshortener-create-url
  • urlshortener-view-log
Quarterly downloads 49 (Ranked 102nd)
Public wikis using 872 (Ranked 276th)
translatewiki.net で翻訳を利用できる場合は、UrlShortener 拡張機能の翻訳にご協力ください
問題点 未解決のタスク · バグを報告

UrlShortener拡張機能は、MediaWiki拡張機能として基本的なURL短縮サービスを提供します。 正しく動作するには、Webサーバーの構成を変更する必要があります。 もともとはURL ShortenerRfCを実装するために設計されました。

ウィキメディアプロジェクトでUrlShortenerを使用する手順については、m:Wikimedia URL Shortenerの情報を参照してください。

インストール

  • ダウンロードして、ファイルをextensions/フォルダー内のUrlShortenerという名前のディレクトリ内に配置します。
    開発者とコード寄稿者は、上記の代わりに以下を使用してGitからインストールします:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/UrlShortener
  • 以下のコードを LocalSettings.php ファイルの末尾に追加します:
    wfLoadExtension( 'UrlShortener' );
    
  • 更新スクリプトを実行します。このスクリプトは、この拡張機能が必要とするデータベーステーブルを自動的に作成します。
  • 必要に応じて設定します。
  • 必要に応じて適応させます。
  • Yes 完了 – ウィキの「Special:Version」に移動して、拡張機能が正しくインストールされたことを確認します。


Vagrant installation:

  • Vagrant を使用している場合は、vagrant roles enable urlshortener --provisionでインストールしてください。
//wiki.ext/r/fooを正しく機能させるには、ウェブサーバーの書き換えルールを設定する必要があります。 Apacheのルールの例は、拡張機能内に提供されています。

設定

LocalSettings.php

URLルーティング構成:

短縮URLを生成するときに使用するテンプレートを構成します。 この機能を使用するには、mod_rewrite(または同等のもの)が必要です。 false(デフォルト)に設定すると、Webサーバーの構成に関係なく機能するため、短縮URLはそれほど短くない/wiki/Special:UrlRedirector/5234を使用します。

domain.org/r/5234の形式の短縮URLが必要な場合は、次のように設定します。

$wgUrlShortenerTemplate = '/r/$1';

短いドメイン名:

短いドメイン名がある場合は、次を使用して設定できます。

$wgUrlShortenerServer = "short.wiki";

false(デフォルト)に設定すると、$wgServer が使用されます。

グローバルデータベース:

Wikiファームに1つの中央データベースを使用する場合は、これをデータベースの名前に設定します。 false(デフォルト)に設定すると、Wikiの通常のデータベースが使用されます。

$wgUrlShortenerDBName = false;

データベースが外部クラスター上にある場合は、それも構成する必要があります。

$wgUrlShortenerDBCluster = false;

任意のポートを許可する:

デフォルトでは、ポート80および443のURLのみが受け入れられ、自動的に削除されます。 Wikiがカスタムポートを使用して設定されている場合は、これをtrueに設定して、任意のポートを持つURLを短縮できるようにします。

$wgUrlShortenerAllowArbitraryPorts = true

AllowedDomains の正規表現:

ユーザーがリンクを送信できる受け入れ可能なドメインを構成します。 これは正規表現の配列です。 false(デフォルト)に設定すると、現在のドメインの許可リストが設定されます($wgServerを使用)。

$wgUrlShortenerAllowedDomains = false;

たとえば、wikipedia.orgまたはwikimedia.orgへのリンクのみをホワイトリストに登録するには、次を使用します。

$wgUrlShortenerAllowedDomains = array(
	'(.*\.)?wikimedia\.org',
	'(.*\.)?wikipedia\.org',
);

任意のドメインを許可する場合:

$wgUrlShortenerAllowedDomains = array( '.*' );

ApprovedDomains の説明文書:

これは許可されたドメインの配列ですが、人間が読める形式です。 特別:UrlShortenerに表示されます。

false(デフォルト)に設定すると、正規化されたバージョンの$wgServerが出力されます。

$wgUrlShortenerApprovedDomains = false;

If you only allow wikipedia.org and wikimedia.org in the above example:

$wgUrlShortenerApprovedDomains = array(
	'*.wikimedia.org',
	'*.wikipedia.org',
);

Shortcode character set:

If you want to customize the character set the shortcodes use, you can override this setting. This should be done only once during the setup. Once changed thereafter, any existing short URLs will go to the wrong destination.

$wgUrlShortenerIdSet = '23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz$';

The first character in the list is treated as a leading zero; no shortcodes beginning with that character will be created, and it is ignored when used at the start of the shortcode in a URL (e.g. https://w.wiki/22222222w is the same as https://w.wiki/w).

Read-only mode:

Set $wgUrlShortenerReadOnly to true to prevent users from creating new short URLs.

This is mainly intended as a hack while deploying to Wikimedia sites and will be removed once it is no longer needed.

QR codes:

MediaWiki バージョン:
1.41

As of UrlShortener version 1.1.0, you can enable QR code sharing. This has two configurations settings. One is simply to enable QR code sharing.

$wgUrlShortenerEnableQrCode = true;

Note that currently, $wgUrlShortenerEnableSidebar must also be set if you want the "QRコードをダウンロード" link to appear in the sidebar.

The link the QR codes point to is only shortened if it is very long. This is because users would prefer to see a familiar domain when scanning a QR code, but if the URL is too long then the pixel density of the QR code will be too difficult to scan. You can control the length of URLs that, when exceeded, will first be shortened before creating a QR code. The number here refers to the number of bytes, not characters.

$wgUrlShortenerQrCodeShortenLimit = 200;

バーチャルホストまたは.htaccess

To have truly short URLs, you will need to set up rewrite rules, using mod_rewrite or something similar. An example of what to put in your .htaccess file comes with the extension. If our template was set up to /r/$1, then we could use:

RewriteEngine On
RewriteRule ^r/(.*)$ /w/index.php?title=Special:UrlRedirector/$1 [PT]

If you are using nginx, you can add the following within a server { definition.

location ~ ^/r/(.*) {
	return 301 /w/index.php?title=Special:UrlRedirector/$1;
}

This assumes your $wgScriptPath is set to /w.

API

This extension provides the API module action=shortenurl to get the shortened url for a given url, creating it if does not exist already. See the API documentation here: https://meta.wikimedia.org/w/api.php?action=help&modules=shortenurl.

  • url - URL to shorten.

レスポンス:

{
    "shortenurl": {
        "shorturl": "http://127.0.0.1:8080/s/3"
    }
}

関連項目