Smart Linking
Previewing a disambiguation page
DescriptionHelps linking to the correct articles by letting you preview them while editing
Author(s)V111P
StatusBeta
UpdatedMay 2, 2014; 9 years ago (2014-05-02)
Browser supportAll browsers
Skin supportAll skins
SourceSee below
By default most of the times only a single line of text will be shown
Expanded with the handle to the right of the display
Maybe you actually want to link to one of these articles
Disambiguation pages auto-expand the display

Smart Linking is a tool for linking articles and previewing the linked pages while source-editing Wikipedia/MediaWiki articles. (The visual editor is not supported.) Using it helps prevent linking to the wrong articles, including to redirecting or disambiguation pages.

The WikEd gadget is supported only partially at this time - you have to select the link text (instead of just placing the cursor within it) and if an article with that name exists Smart Linking will display it, but won't fix redirects for you in the wiki code.

You can edit this page. If I don't like or understand something you wrote, I will correct it. ;)

How to use

To use Smart Linking (after installing it), position the text cursor anywhere within or just after the second closing bracket of a link and press the Smart Linking button, or select an existing link (with or without its square brackets) or select unlinked text you want to make a link from, and press the Smart Linking button. (See the section Selecting and focusing wiki links - Examples below for a clearer explanation). Smart Linking's display with the linked article's contents (or just the title of the page in red, if there is no such page yet) will appear above the textarea (tables, images, and templates are removed from the articles).

You can learn how to use most of the features by hovering with the mouse pointer over the various icons and links and reading the tooltips. Some less obvious things you need to know are:

Menus/Icons

The toolbar icon
The button used for the classic toolbar

Selecting and focusing wiki links - Examples

In the following cases a valid already-existing wiki link is focused (the caret is after the first opening square bracket and at the latest right after the second closing square bracket, the caret's position here is marked with a vertical bar): [|[Wikipedia]], [[|Wikipedia]], [[Wiki|pedia]], [[Wikipedia|]], [[Wikipedia]|], [[Wikipedia]]|.

In the following cases no valid link is selected or focused (the caret's position here is marked with a vertical bar):

In the following cases a valid link is selected: [[Wikipedia]], [[Wikipedia]], [[Wikipedia]], [[Wikipedia]], [[Wikipedia]], [[Wikipedia]], [[Wikipedia]], [[Wikipedia]]. If you are using the gadget Navigation Popups, selecting wiki links with all four of the square brackets ([[Wikipedia]]) will cause Navigation Popups to load the article. You can disable this behavior by adding var popupOnEditSelection = false; to your common.js or equivalent file.

In the following cases the selected text will be turned into a wiki link: English Wikipedia,  English Wikipedia, English Wikipedia ,  English Wikipedia . The spaces around the text won't be included in the link, so it's not a problem if they are also selected.

In the following case, the selected text won't be turned into a wiki link: 2 > 1 (invalid article title).

Installation

For the English Wikipedia, add this code to your common.js (or vecor.js, or monobook.js, whichever you are using) file:

if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) > -1 ) {
	importScript('User:V111P/js/smartLinkingLoader.js'); // [[User:V111P/js/smartLinkingLoader.js]]
}

The wiki link is there so that your common.js file appears in the "What links here" list of that page. This way we can see how many people have installed the script.

You should move all your JavaScript code that you need only when editing wiki pages before the last closing } in the code above. That way it won't get loaded and executed on every page.

In other Wikipedias

To try Smart Linking in other Wikipedias, you can use the code below.

if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) > -1 ) {
	mw.loader.load('//en.wikipedia.org/w/index.php?title=User:V111P/js/smartLinkingLoader.js'
			+ '&action=raw&ctype=text/javascript');
}

However, Smart Linking won't be able to detect your other-meaning and main-article templates, so you're losing some important features. That's why you need to set up a configuration file and load it instead of directly loading smartLinkingLoader.js as above. See the template configuration file for more information, read all the comments there and don't hesitate to ask if you need help. Let me know if you set Smart Linking up for another Wikipedia, so I can mention it here.

Customizing

To configure Smart Linking's display, in your common.js or equivalent file add these lines first:

$.extend(window.smartLinkingConfig = window.smartLinkingConfig || {}, {

});

Then you can set properties by inserting them between the first and the last line of that code. To set a property, use this as a template: propertyName: value, where propertyName is one of the property names listed below, and value is an appropriate value for that property. Values which are not numbers or the keywords true and false need to be enclosed in either single or double quotes, as you can see in the example. All these lines must end with a comma, except the last one, right before the closing }); line (where a comma will actually cause an error in very old versions of Internet Explorer).

Here is an example setting several properties:

$.extend(window.smartLinkingConfig = window.smartLinkingConfig || {}, {
	blurChar: '!',
	height: '3em',
	expandHeight: '20em',
	background: 'cyan',
	insertRelation: 'after'
});

Here is a list of the possible properties:

For developers

If you would like to experiment and improve Smart Linking, I am ready to explain any and all parts of it - just ask.

Smart Linking is using several main components:

If you are experimenting and make a change in one or more of the files msgDisplay.js, wikiParserV.js, or addToolbarButtons.js, you can test it by (1) setting the main object to undefined or null (e.g. for msgDisplay.js: mediaWiki.libs.msgDisplay = null;), (2) executing the code from that file in the JavaScript console of your browser, then (3) executing the code from smartLinking.js, and finally (4) pressing the Smart Linking toolbar button. You don't need step (3) if you haven't already clicked Smart Linking's toolbar button since opening the page for editing. If you make a change only in smartLinking.js, than just execute that script.