Description | Helps linking to the correct articles by letting you preview them while editing |
---|---|
Author(s) | V111P |
Status | Beta |
Updated | May 2, 2014 |
Browser support | All browsers |
Skin support | All skins |
Source | See below |
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. ;)
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:
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):
Wikipedia|
(the caret is not within a wiki link or right after a wiki link)|[[Wikipedia]]
(the caret is before the wiki link)[[Wikipedia]] |
(the caret is not right after the wiki link, there is an interval between them)[[2 > 1]]|
(invalid article title)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).
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.
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/?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.
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:
closeChar
- a character which, when typed while the keyboard focus is on the display, causes the display to disappear and the keyboard focus to be returned to the textarea. The default is ` (grave accent).expandCollapseChar
- a character which, when typed while the keyboard focus is on the display, causes the display to expand if it is not already expanded, otherwise it collapses and return the keyboard focus to the textarea. The default is !blurChar
- a character which, when typed while the keyboard focus is on the display, causes the display to collapse and returns the keyboard focus to the textarea. The default is ^height
- the initial height of the display. Can be just a number (which means it's in pixels) or a string with a number and one of the CSS units. The default value is '1.4em'
. If you set this, set also expandHeight
to the same or a larger value.minHeight
- height in number of pixels (no CSS units allowed). You can't resize the display with the mouse to be shorter in height than that. The default is whatever value you give to height
. If you set this, try to set it to less than or equal to the value you give to height
. If you don't set this, you can't make the display shorter than its initial height.expandHeight
- the height to which the display will be expanded in certain cases, such as on double click or when opening a disambiguation page. Set this to greater than or equal to height
. If you don't want the display to expand automatically on double click, or when clicking certain links in it, or on disambiguation pages, set expandHeight
to the same value as height
.background
- set the background with a CSS value (which can be a color or an image url). The default is '#fed'
. An example value with an image: 'url(//upload.wikimedia.org/wikipedia/commons/0/0f/Wiki_background.jpg)'
. The image needs to be very light in color, or the text won't be readable.insertRelToSelector
(advanced) - a jQuery selector for the element before, after or within which the display is to be inserted. The default is '#wpTextbox1'
(the textarea).insertRelation
- one of 'before', 'after', 'prepend', 'append'
with meanings as in jQuery (for example 'prepend'
means insert as a first element of the element selected with insertDisplayRelToSelector
). The default is 'before'
. Try using 'after'
without setting insertDisplayRelToSelector
('prepend'
or 'append'
don't make sense for a textarea and won't work though).addButton
- set this to false
(without quotes) to disable adding the Smart Linking button to the toolbar. Then, to use Smart Linking, you'll need to have some other way to call mw.libs.smartLinkingLoader.smartLinking()
allPossibleOtherMeaningTemplates
- set this to true
(without quotes) to cause all templates which appear in the wiki code on a line by themselves near the top of the article or section to be considered other-meaning or main-article templates. This is only useful while testing to find templates which need to be included in the configuration file for that wiki.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:
window.smartLinking()
any way you like (no button will be added to the toolbar).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.
Description | Helps linking to the correct articles by letting you preview them while editing |
---|---|
Author(s) | V111P |
Status | Beta |
Updated | May 2, 2014 |
Browser support | All browsers |
Skin support | All skins |
Source | See below |
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. ;)
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:
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):
Wikipedia|
(the caret is not within a wiki link or right after a wiki link)|[[Wikipedia]]
(the caret is before the wiki link)[[Wikipedia]] |
(the caret is not right after the wiki link, there is an interval between them)[[2 > 1]]|
(invalid article title)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).
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.
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/?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.
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:
closeChar
- a character which, when typed while the keyboard focus is on the display, causes the display to disappear and the keyboard focus to be returned to the textarea. The default is ` (grave accent).expandCollapseChar
- a character which, when typed while the keyboard focus is on the display, causes the display to expand if it is not already expanded, otherwise it collapses and return the keyboard focus to the textarea. The default is !blurChar
- a character which, when typed while the keyboard focus is on the display, causes the display to collapse and returns the keyboard focus to the textarea. The default is ^height
- the initial height of the display. Can be just a number (which means it's in pixels) or a string with a number and one of the CSS units. The default value is '1.4em'
. If you set this, set also expandHeight
to the same or a larger value.minHeight
- height in number of pixels (no CSS units allowed). You can't resize the display with the mouse to be shorter in height than that. The default is whatever value you give to height
. If you set this, try to set it to less than or equal to the value you give to height
. If you don't set this, you can't make the display shorter than its initial height.expandHeight
- the height to which the display will be expanded in certain cases, such as on double click or when opening a disambiguation page. Set this to greater than or equal to height
. If you don't want the display to expand automatically on double click, or when clicking certain links in it, or on disambiguation pages, set expandHeight
to the same value as height
.background
- set the background with a CSS value (which can be a color or an image url). The default is '#fed'
. An example value with an image: 'url(//upload.wikimedia.org/wikipedia/commons/0/0f/Wiki_background.jpg)'
. The image needs to be very light in color, or the text won't be readable.insertRelToSelector
(advanced) - a jQuery selector for the element before, after or within which the display is to be inserted. The default is '#wpTextbox1'
(the textarea).insertRelation
- one of 'before', 'after', 'prepend', 'append'
with meanings as in jQuery (for example 'prepend'
means insert as a first element of the element selected with insertDisplayRelToSelector
). The default is 'before'
. Try using 'after'
without setting insertDisplayRelToSelector
('prepend'
or 'append'
don't make sense for a textarea and won't work though).addButton
- set this to false
(without quotes) to disable adding the Smart Linking button to the toolbar. Then, to use Smart Linking, you'll need to have some other way to call mw.libs.smartLinkingLoader.smartLinking()
allPossibleOtherMeaningTemplates
- set this to true
(without quotes) to cause all templates which appear in the wiki code on a line by themselves near the top of the article or section to be considered other-meaning or main-article templates. This is only useful while testing to find templates which need to be included in the configuration file for that wiki.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:
window.smartLinking()
any way you like (no button will be added to the toolbar).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.