This page is a translated version of the page Extension:UrlShortener and the translation is 4% complete.
Nie mylić z Extension:ShortUrl.
Podręcznik rozszerzeń MediaWiki
Status wydania: stabilne
Realizacja Strona specjalna , API , MyWiki
Opis Provides a basic URL shortening service
Autor(zy) YuviPandadyskusja
Ostatnia wersja Continuous updates
MediaWiki 1.25+
PHP 5.4+
Zmiany w bazie danych Tak
Tabele urlshortcodes
Licencja Apache License 2.0
Pomoc Help:Extension:UrlShortener/pl
  • $wgUrlShortenerAllowArbitraryPorts
  • $wgUrlShortenerAllowedDomains
  • $wgUrlShortenerEnableQrCode
  • $wgUrlShortenerQrCodeShortenLimit
  • $wgUrlShortenerUrlSizeLimit
  • $wgUrlShortenerApprovedDomains
  • $wgUrlShortenerEnableSidebar
  • $wgUrlShortenerIdMapping
  • $wgUrlShortenerAltPrefix
  • $wgUrlShortenerTemplate
  • $wgUrlShortenerServer
  • $wgUrlShortenerReadOnly
  • $wgUrlShortenerIdSet
  • urlshortener-manage-url
  • urlshortener-create-url
  • urlshortener-view-log
Quarterly downloads 41 (Ranked 104th)
Public wikis using 872 (Ranked 276th)
Przetłumacz rozszerzenie UrlShortener jeżeli jest dostępne na translatewiki.net
Problemy Otwarte zadania · Zgłoś błąd

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 instructions on using UrlShortener with Wikimedia projects, see the information at m:Wikimedia URL Shortener.
  • Pobierz i umieść plik(i) w katalogu o nazwie UrlShortener w folderze extensions/.
    Developers and code contributors should install the extension from Git instead, using:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/UrlShortener
  • Dodaj poniższy kod na dole twojego pliku LocalSettings.php :
    wfLoadExtension( 'UrlShortener' );
  • Uruchom skrypt aktualizujący, który automatycznie stworzy potrzebne tabele dla tego rozszerzenia.
  • Configure as required.
  • Adapt as required.
  • Yes Zrobione – Przejdź do Special:Version na twojej wiki, aby sprawdzić czy rozszerzenie zostało pomyślnie zainstalowane.

Instalacja Vagranta:

  • Jeżeli korzystasz z Vagrant a, zainstaluj poprzez vagrant roles enable urlshortener --provision
To make //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.



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 regex:

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(

If we want to allow any domain:

$wgUrlShortenerAllowedDomains = array( '.*' );

ApprovedDomains documentation:

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(

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.

Kody QR:

Wersja MediaWiki:

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 "Pobierz kod 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;

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.


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": ""

Zobacz też