Extension:LinkTitles

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.png
LinkTitles

Release status:Extension status stable

ImplementationTemplate:Extension#type Page action
DescriptionTemplate:Extension#description Automatically adds links to words that match titles of existing pages.
Author(s)Template:Extension#username Daniel Kraus (bovendertalk)
Latest versionTemplate:Extension#version 4.0.9 (2017-03-21)
MediaWikiTemplate:Extension#mediawiki 1.25+
PHPTemplate:Extension#php 5.3
Database changesTemplate:Extension#needs-updatephp No
LicenseTemplate:Extension#license GNU General Public License 2.0
Download Releases on Github
What's new?
ParametersTemplate:Extension#parameters

see the parameter section

Added rightsTemplate:Extension#rights

linktitles-batch

Hooks usedTemplate:Extension#hook
PageContentSaveManual:Hooks/PageContentSave
InternalParseBeforeLinksManual:Hooks/InternalParseBeforeLinks
GetDoubleUnderscoreIDsManual:Hooks/GetDoubleUnderscoreIDs

Translate the LinkTitles extension if it is available at translatewiki.net

Check usage and version matrix.

What can this extension do?[edit]

The LinkTitles extension automatically adds links to existing page titles that occur on a given page. This will automatically cross-reference your wiki for you. The extension can operate in three ways that can be used independently:

  1. Whenever a page is edited and saved, the extension will look if any existing page titles occur in the text, and automatically add links ([[...]]]) to the corresponding pages.
  2. Links may also be added on the fly whenever a page is rendered for display. Most of the time, MediaWiki will fetch previously rendered pages from cache upon a page request, but whenever a page is refreshed, the LinkTitles extension can add its page links. These links are not hard-coded in the Wiki text. The original content will not be modified.
  3. Batch mode enables Wiki administrators to process all pages in a Wiki at once. Batch processing can either be started from a special page, or from the server's command line (see below).

Usage[edit]

There is not much to do. Simply install the extension, and then edit a page. When you save the page, any existing page titles that occur on the page will be converted to MediaWiki links. (See below for configuration options.)

When the checkbox "This is a minor edit" is checked, the extension will not parse the page, in order to save time when you make frequent small edits to a page. To permanently prevent the extension from adding links to a given page, you can add a Magic word to the page.

In the rare case that it messes up your page[edit]

In the past two years, the extension only very rarely added links in the wrong place, resulting in garbled content − this was exclusively when a page contained special content such as HTML passages. With the more recent versions (> 2.4), this should almost never happen.

However, if the extension does mess up your page one day, you can always revert back to a previous version using MediaWiki's 'View history' function. Just make sure to click the "This is a minor edit" checkbox at the bottom of the edit form when you revert the changes. If this box is checked, the extension will leave your page content alone. Of course, the most recent edits that triggered the parsing will be lost.

Download & Installation[edit]

To install this extension, download the archive and extract it to the extensions directory of your MediaWiki installation. Then, add the following line to your LocalSettings.php:

wfLoadExtension( 'LinkTitles' );

Alternatively, if you have Git installed on your server, you can change to the extensions directory, and then clone the LinkTitles GitHub repository to your server (this will copy the entire commit history to your server).

git clone git://github.com/bovender/LinkTitles.git

To update a cloned git repository, change to the LinkTitles directory, then issue the command

git pull

Configuration parameters[edit]

Configuration settings are found in extension.json. Keep in mind that you need to use PHP variables in your LocalSettings.php file, not the original JSON:

$wgLinkTitlesSmartMode = true;

With smart mode enabled, the extension will first perform a case-sensitive search for page titles in the current page; then it will search for occurrences of the page titles in a case-insensitive way and add aliased ('piped') links. Thus, if you have a page "MediaWiki Extensions", but write "Mediawiki extensions" in your text, LinkTitles would generate a link "[[MediaWiki Extensions|Mediawiki extensions]]", obviating the need to add dummy pages for variants of page titles with different cases.

Smart mode is enabled by default. You can disable it to increase performance of the extension.

$wgLinkTitlesParseOnEdit = true;

Parse page content whenever it is edited and saved, unless 'minor edit' box is checked. This is the default mode of operation. It has the disadvantage that newly created pages won't be linked to from existing pages until those existing pages are edited and saved.

$wgLinkTitlesParseOnRender = false;

Parse page content when it is rendered for viewing. Unlike the "parse on edit" mode of operation, this will not hard-code the links in the Wiki text. Thus, if you edit a page that had links added to it during rendering, you will not see the links in the Wiki markup. Note that MediaWiki caches rendered pages in the database, so that pages rarely need to be rendered. Rendering is whenever a page is viewed and saved. Therefore, whether you want to enable both parse-on-edit and parse-on-render depends on whether you want to have links ([[...]]) added to the Wiki markup. Please note that the extension will work on a fully built page when this mode is enabled; therefore, it will add links to text transcluded from templates, regardless of the configuration setting of LinkTitlesSkipTemplages. &emdash; It is also possible to purge the page cache and trigger rendering by adding ?action=purge to the URL.

$wgLinkTitlesParseHeadings = false;

Determines whether or not to add links to headings. By default, the extension will leave your (sub)headings untouched. Only applies to parse-on-edit!

$wgLinkTitlesPreferShortTitles = false;

If $wgLinkTitlesPreferShortTitles is set to true, parsing will begin with shorter page titles. By default, the extension will attempt to link the longest page titles first, as these generally tend to be more specific.

$wgLinkTitlesMinimumTitleLength = 3;

Only link to page titles that have a certain minimum length. In my experience, very short titles can be ambiguous. For example, "mg" may be "milligrams" on a page, but there may be a page title "Mg" which redirects to the page "Magnesium". This settings prevents erroneous linking to very short titles by setting a minimum length. You can adjust this setting to your liking.

$wgLinkTitlesBlackList = [];

Exclude page titles in the array from automatic linking. You can populate this array with common words that happen to be page titles in your Wiki. For example, if for whatever reason you had a page "And" in your Wiki, every occurrence of the word "and" would be linked to this page.

To add page titles to the black list, you can use statements such as $wgLinkTitlesBlackList[] = 'Some special page title'; in your LocalSettings.php. Use one of these for every page title that you want to put on the black list.

Keep in mind that a MediaWiki page title always starts with a capital letter. If you have lowercase first letters in the black list array, they will have no effect.

$wgLinkTitlesSkipTemplates = false;

If set to true, do not parse the variable text of templates, i.e. in {{my template|some variable=some content}}, leave the entire text between the curly brackets untouched. If set to false (default setting), the text after the pipe symbole ("|") will be parsed. &emdash; This setting works only with parse-on-edit; it does not affect parse-on-render!

$wgLinkTitlesFirstOnly = false;

If set to true, only link the first occurrence of a title on a given page.

$wgLinkTitlesWordStartOnly = true;

Restrict linking to occurrences of the page titles at the start of a word. If you want to have only the exact page titles linked, you need to set both options $wgLinkTitlesWordStartOnly and $wgLinkTitlesWordEndOnly to true. On the other hand, if you want to have all occurrences of a page title linked, even if they are in the middle of a word, you need to set both options to false.

$wgLinkTitlesWordEndOnly = true;

See the above option LinkTitlesWordStartOnly for an explanation.

Examples for the LinkTitlesWordStartOnly and LinkTitlesWordEndOnly options.
Lemma: "wiki" LinkTitlesWordEndOnly: true LinkTitlesWordEndOnly: false
$wgLinkTitlesWordStartOnly = true; [[wiki]]

wikipedia
mediawiki
(This is the default behavior.)

[[wiki]]

[[wiki]]pedia
mediawiki

$wgLinkTitlesWordStartOnly = false; [[wiki]]

wikipedia
media[[wiki]]

[[wiki]]

[[wiki]]pedia
media[[wiki]]
(This is the most relaxed behavior, which will link a page title even in the middle of a word, e.g. in the fictitious word "mediawikipedia", the title "wiki" would be linked as well, resulting in media[[wiki]]pedia.)

Keep in mind that linking in MediaWiki is generally case-sensitive.

Magic words[edit]

Wiki editors can add the magic word __NOAUTOLINKS__ to a page to prevent automatic linking of page titles.

The presence of __NOAUTOLINKTARGET__ prevents a page from being automatically linked to from other pages.

Batch processing[edit]

The extension provides two methods to batch-process all pages in a wiki: A special page and a command-line maintenance script.

Special:LinkTitles[edit]

The special page provides a simple web interface to trigger batch processing. To avoid blocking the web server for too long, the page will frequently reload itself (this can be controlled by the $wgLinkTitlesTimeLimit configuration variable that sysops can set in the LocalSettings.php file). For security reasons, by default only users in the 'sysop' group are allowed to view the special page (otherwise unauthorized people could trigger a parsing of your entire wiki). To allow other user groups to view the page as well, add a line $wgGroupPermissions ['<groupname>']['linktitles-batch'] = true to LocalSettings.php.

Maintenance script[edit]

If you have access to a shell on the server that runs your wiki, and are allowed to execute /bin/php on the command line, you can use the extension's maintenance script. Unlike MediaWiki's built-in maintenance scripts, this resides not in the maintenance/ subdirectory but in the extension's own directory (the one where you downloaded and extracted the files to).

To trigger parsing of all pages, issue:

php Linktitles.cli.php

You can interrupt the process by hitting CTRL+C at any time.

To continue parsing at a later time, make a note of the index number of the last page that was processed (e.g., 37), and use the maintenance script with the --start option (or short -s) to indicate the start index:

php LinkTitles.cli.php -s 37

Source code documentation[edit]

The source code documentation can be found over at the Github project pages at http://bovender.github.io/LinkTitles.

Credits[edit]

Ulrich Strauss (c0nnex) contributed code for namespace support. Brent Laabs (labster) fixed bugs.

Credits to Eugene and inhan at StackOverflow for help with the regular expression.

See also[edit]

There used to be another extension that would do something similar, but it has recently been archived, since it no longer appears to be maintained: