Extension:UrlShortener
UrlShortener リリースの状態: 安定 |
|
---|---|
![]() |
|
実装 | 特別ページ , API , 自分のウィキ |
説明 | Provides a basic URL shortening service |
作者 | YuviPandaトーク |
最新バージョン | Continuous updates |
MediaWiki | 1.25+ |
PHP | 5.4+ |
データベースの変更 | はい |
テーブル | urlshortcodes |
ライセンス | Apache License 2.0 |
ダウンロード | |
|
|
|
|
translatewiki.net で翻訳を利用できる場合は、UrlShortener 拡張機能の翻訳にご協力ください | |
問題点 | 未解決のタスク · バグを報告 |
The UrlShortener extension provides a basic URL shortening service as a MediaWiki extension. It will require some changes to your web server's configuration to operate properly. It was originally designed to implement the URL Shortener RfC.
For user documentation, see m:Wikimedia URL Shortener.
インストール
- Vagrant を使用している場合は、
vagrant roles enable urlshortener --provision
でインストールしてください
- 手動インストール
- ダウンロードして、ファイルを
extensions/
フォルダー内のUrlShortener
という名前のディレクトリ内に配置します。 - 以下のコードを LocalSettings.php の末尾に追加します:
wfLoadExtension( 'UrlShortener' );
- 更新スクリプトを実行します。このスクリプトは、この拡張機能が必要とするデータベース テーブルを自動的に作成します。
- 必要に応じて設定します。
- Adapt as required.
完了 – ウィキの「Special:Version」に移動して、拡張機能が正しくインストールされたことを確認します。
//wiki.ext/r/foo
work properly, you will need to set up rewrite rules for your webserver. Example rules for Apache are provided inside the extension.設定
LocalSettings.php
- URL routing configuration
Configures the template to use when generating the shortened URL.
Using this feature will require mod_rewrite (or an equivalent).
If set to false (default), the short URLs will use the not-so-short /wiki/Special:UrlRedirector/5234
since it will work regardless of web server configuration.
If you want your short URLs in the form of domain.org/r/5234
, you would set:
$wgUrlShortenerTemplate = '/r/$1';
- Short domain name
If you have a custom short domain name, you can set it by using:
$wgUrlShortenerServer = "short.wiki";
If set to false (default), it will use $wgServer
.
- Global database
Set this to the name of a database if you wish to use one central database for your wiki farm. If set to false (default), it will use the wiki's normal database.
$wgUrlShortenerDBName = false;
If the database is on an external cluster, you will also need to configure that.
$wgUrlShortenerDBCluster = false;
- Allow arbitrary ports
By default, only URLs with ports 80 and 443 are accepted and are automatically removed. If your wiki is set up using a custom port, set this to true to allow shortening URLs that have arbitrary ports.
$wgUrlShortenerAllowArbitraryPorts = true
- AllowedDomains の正規表現
Configures the acceptable domains that users can submit links for. This is an array of regular expressions. If set to false (default), it will set up a allowlist for the current domain (using $wgServer).
$wgUrlShortenerAllowedDomains = false;
For example, to only whitelist links to wikipedia.org or wikimedia.org, we would use the following:
$wgUrlShortenerAllowedDomains = array(
'(.*\.)?wikimedia\.org',
'(.*\.)?wikipedia\.org',
);
If we want to allow any domain:
$wgUrlShortenerAllowedDomains = array( '.*' );
- ApprovedDomains の説明文書
This is an array of the allowed domains but in a human-readable form. It will be displayed on Special:UrlShortener.
If set to false (default), it will output a normalized version of $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.
VirtualHost or .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.
Response:
{
"shortenurl": {
"shorturl": "http://127.0.0.1:8080/s/3"
}
}
See also
![]() | この拡張機能は 1 つ以上のウィキメディアのプロジェクトで使用されています。 これはおそらく、この拡張機能が安定していて高いトラフィックのウェブサイトでも十分に動作することを意味します。 この拡張機能がインストールされている場所を確認するには、ウィキメディアの設定ファイル CommonSettings.php および InitialiseSettings.php 内で、この拡張機能の名前を探してください。 特定のウィキにインストールされている拡張機能の完全な一覧は、そのウィキの Special:Version ページにあります。 |
- Stable extensions/ja
- Special page extensions/ja
- API extensions/ja
- Personalization extensions/ja
- Apache licensed extensions/ja
- Extensions in Wikimedia version control/ja
- BeforePageDisplay extensions/ja
- LoadExtensionSchemaUpdates extensions/ja
- SidebarBeforeOutput extensions/ja
- WebRequestPathInfoRouter extensions/ja
- All extensions/ja
- Extensions used on Wikimedia/ja