Wikisource:Tools and scripts
This page contains various tools, scripts, and tutorials intended to simplify, make more efficient, or provide additional functionality to Wikisourcers.
If you're having trouble with anything on this page, make sure you've copied the code exactly as it is on this page, and you followed the instructions carefully. Try refreshing your browser to reset the cache. Try starting over from step 1, in case you made an accidental change. If this fails, feel free to ask for help on the talk page.
Notes before using this page
Javascript
File formatting
The instructions on this page depend on Javascript pages and may not be formatted using <pre> or <nowiki> tags. These break the installation templates and prevent categorisation for opt-in automated updating. The best way to ensure correct formatting is to add at least one space at the start of every line (" //
" for blank lines), which is the correct wikisyntax method for plaintext formatting.
Updating scripts
Many of the scripts on this page are being actively developed. This occasionally requires that users replace scripts they're using with updated versions, which can be tedious and irregular. Users can ignore these updates, but they will not benefit from recent bugfixes or new features. Additionally, many scripts depending on external code will cease to work if they are very outdated.
Automated updates
There is a bot which will automatically update scripts in users' script files as necessary. This keeps all users at the cutting-edge versions and ensures that latest bugfixes and features are implemented immediately. This is an opt-in service, and some users may wish to update manually if they extensively customise the scripts they use.
To subscribe, add the code below at the very top of the javascript file you'd like to update. A bot will periodically scan pages in this category for outdated scripts, and update them as necessary. All scripts listed on this page will be updated as necessary as long as they are copied and pasted as shown on this page.
You can subscribe to automated updates, but disable updates for one script in particular. To do so, change the update field in the script template to anything except "yes".
/* </pre>[[Category:Bots/Script files to update]] */
TemplateScript
TemplateScript is a powerful user script framework that adds custom one-click templates and scripts to the sidebar (on the left, below Tools). Currently various tools are available for proofreading and typography; see the page for details.
Scripts
These are typically added to your common.js page with something like the following code:
mw.loader.load('//en.wikisource.org/w/index.php?title=User:Username/ScriptName.js&action=raw&ctype=text/javascript');
With the text in red being replaced by the relevant script page name. For detailed help, see User styles on Meta.
InstaView
Update: last update February 14, 2006.
Author: Pilaf (Wikipedia)
Contributor: Pathoschild (ported to Wikisource)
Caution: This is an experimental script. It is not recommended for users unfamiliar with wikis.
InstaView is an extension to Wikipedia's edit page which allows you to generate instant previews of the page you're editing. Unlike the normal preview mode, you don't need to refresh the page; except for very large pages, there is no delay whatsoever. However, the script does not recognize templates or signatures.
- Copy and paste the code below into your javascript file.
- Fill in your username in the username field.
- See Updating scripts for details on the update field (usually doesn't need to be changed).
{{subst:Wikisource:Tools and scripts/InstaView |username=USERNAME |update=yes }}
SoftRedirect
This script allows you to convert pages that are redirects to {{dated soft redirect}}. If no "#REDIRECT Blah" is found on the page, you will be prompted for the page that the soft redirect should point to.
Update: last update June 09, 2006.
Author: Jude
- Copy and paste the code into your Javascript file
{{subst:Wikisource:Tools and scripts/SoftRedirect}}
More editing buttons
This script includes more edit buttons in your editing toolbar, reducing time when writing and proofreading text.
Update: First version April 29, 2008.
Authors: Steve Sanbeg[1] (coding)
Contributor: Mtmelendez (individual buttons)
A full list of extra edit buttons is here.
Running header lookup
This script has been moved to the running header gadget.
typoscript
Update: last update October 02, 2016.
Author: AuFCL (Wikipedia)
typoscan.js documentation and scripts
Introduction
- The typoscan.js script highlights out of place characters and anomalies in the text created by the OCR process, but it is not a spell checking script. The typos are highlighted on the pages of the the Main namespace, Page namespace, and Page Preview, but not in edit mode.
- There are two versions, one of which excludes highlighting text in the Main namespace.
Examples
- Out of place characters are considered to be . . . .
Mix of letters with numbers and vice versa: 18G7 or 6eorge
Mix of upper and lower characters: HoUse, or hOuse
Word like modem, instead of modern.
Punctuation preceded by space, excluding ellipsis: comma , and period . . . . . .
Floating (unattached) punctuation and symbols, excluding emdash, or endash: " ' ( ) +, ^
Opening quote " w" at the start of the word.
Scan error of the N character.
St or Ave when followed by space or a comma.
Some highlighted typo segments are to be examined for context. | Incorrect | Correct |
whicli | Pompeii. |
Installation
- Create a typoscan.js submodule of the common.js module named User:username/common.js/typoscan.js. Replace "username" with your username.
Inclusion of the Main namespace in highlighting typos
- Currently, there are two versions:
- For the inclusion of the Main namespace pages to be highlighted, copy this code into the submodule:
// <nowiki>
// main namespace included version
var typoFuse; // overriden by actions.limit
function HighlightTyposUnder( node, actions ){
if( typoFuse >= 0 && node ){
if( node.tagName === "STYLE") {
return;
}
if( node.nodeType == 3 /* TEXT_NODE */ ){
for( var I = 0; I < actions.patterns.length; I++ ){
var pattern = actions.patterns[ I ];
if( node.nodeValue.match( pattern ) ){
if( node.parentNode ){
node.parentNode.innerHTML = node.parentNode.innerHTML.replace( pattern, '<span style="' + actions.styling + '">$&</span>' );
typoFuse--;
}
}
}
}
if( node.childNodes.length ){
for( var subnode=0; subnode < node.childNodes.length; subnode++ ){
if( node.childNodes[ subnode ].getAttribute ){
if( !/pagenumber/.test( node.childNodes[ subnode ].getAttribute( "class" ) ) ){
HighlightTyposUnder( node.childNodes[ subnode ], actions );
}
} else {
HighlightTyposUnder( node.childNodes[ subnode ], actions );
}
}
}
}
}
function HighlightTyposLike( actions ){
self.typoscan = self.typoscan || { exclude: true };
if( !( actions.exclude ) ){ //don't bother scanning historical, edit-in-progress or given ns pages.
var content=document.getElementById('wikiPreview'); //presume currently editing page (must not touch unsafe structures like wpEditToken!)
if( !content ){
content=document.getElementById('mw-content-text'); //user not currently editing: assume safe to address entire display region
}
typoFuse = actions.limit;
for( var N=0; N<actions.groups.length; N++ ){
if( actions.groups[ N ].include ){
HighlightTyposUnder( content, actions.groups[ N ] );
}
}
}
}
self.typoscan={
exclude:
/(action=history|(diff|oldid|search)=|(author|category|extension|file|help|index|mediawiki|meta|module|special|talk|template|topic|user|wiki([mp]edia|source))(:|%3A))/i.test( location.href ),
limit:
40,
groups: [
{
include:
true, // this group applies to all pages not already excluded
patterns: [
/\\\S/g, // back-slash escape?
/;[.,:]/g, // chained punctuation, semicolon-led
/,[.,;:]/g, // chained punctuation, comma-led
/:[.,;]/g, // chained punctuation, colon-led
/(^|[^'])Ave(?!([.!]| Maria))(\W|$)/g, // typo of "we" (but "'Ave", "Ave." or "Ave Maria" is O.K.)
/\|[-+]?/g, // wikicode leaking into HTML (yes the '?' is dodgy but enlarges the match for table caption/row)
/\Wim(der|desirable|less|productive)/g, // typo of "under"/"undesirable"/"unless"/"unproductive"
/(?!na)vv(?!(ies|y))/g, // typo of "w" (though legitimate in "navvy" or plural)
/(^|\W)Sts?(?!\.)(\W|$)/g, // typo of "St."
/\s["'`;:,!?$%*()=+~]\s/g, // floating punctuation mark: WARNING: modern style: floating "=" OK
/modem/gi, // typo of "modern"
/\w&/g, // embedded or trailing "&"
/&(?!c\.)\w/g, // leading "&" ("&c." O.K.)
/(^|\W)[a-z]+[A-Z]+[A-Za-z]+(\W|$)/g, // upper case embedded within lower case word
/(^|\W)[A-Z]{2,}[a-z]+[A-Za-z]+(\W|$)/g, // lower case embedded within upper case word
/(^|\W)[a-zA-Z]+\d+[a-zA-Z]*(\W|$)/g, // digit embedded within word
/(^|\W)\d+[a-zA-Z]+\d+(\W|$)/g, // alphabetic embedded within digits
/(^|\W)[a-zA-Z]+ \.[a-zA-Z]+(\W|$)/g, // period surrounded by letters
/ tlie /g, // typo of "he"
/li /g, // typo of "h"
/ Av/g, // " w" at the start of the word
/ op /g, // typo of standalone " of "
/lI /g, // typo of "ll" or "h"
/ii/g, // "u" or ü"
/jj/g, // "p" or "g"
/\^/g, // standalone "^"?
/{[[\]]}{1,}/g, // mis-terminated template, link or standalone "^"?
/{[(\)}^]{1,}/g // plagiarised parenthesis
],
styling:
'background:LightSalmon;'
},
// end of add
]
};
jQuery( document ).ready(
HighlightTyposLike( self.typoscan )
);
// </nowiki>
Exclusion of the Main namespace from highlighting typos
- For the exclusion of the Main namespace pages from highlighting typos, copy this code into the submodule:
// <nowiki>
// main namespace excluded version
var typoFuse; // overriden by actions.limit
function HighlightTyposUnder( node, actions ){
if( typoFuse >= 0 && node ){
if( node.tagName === "STYLE") {
return;
}
if( node.nodeType == 3 /* TEXT_NODE */ ){
for( var I = 0; I < actions.patterns.length; I++ ){
var pattern = actions.patterns[ I ];
if( node.nodeValue.match( pattern ) ){
if( node.parentNode ){
node.parentNode.innerHTML = node.parentNode.innerHTML.replace( pattern, '<span style="' + actions.styling + '">$&</span>' );
typoFuse--;
}
}
}
}
if( node.childNodes.length ){
for( var subnode=0; subnode < node.childNodes.length; subnode++ ){
if( node.childNodes[ subnode ].getAttribute ){
if( !/pagenumber/.test( node.childNodes[ subnode ].getAttribute( "class" ) ) ){
HighlightTyposUnder( node.childNodes[ subnode ], actions );
}
} else {
HighlightTyposUnder( node.childNodes[ subnode ], actions );
}
}
}
}
}
function HighlightTyposLike( actions ){
self.typoscan = self.typoscan || { exclude: true };
if( !( actions.exclude ) ){ //don't bother scanning historical, edit-in-progress or given ns pages.
var content=document.getElementById('wikiPreview'); //presume currently editing page (must not touch unsafe structures like wpEditToken!)
if( !content ){
content=document.getElementById('mw-content-text'); //user not currently editing: assume safe to address entire display region
}
typoFuse = actions.limit;
for( var N=0; N<actions.groups.length; N++ ){
if( actions.groups[ N ].include ){
HighlightTyposUnder( content, actions.groups[ N ] );
}
}
}
}
self.typoscan={
exclude:
/(action=history|(diff|oldid|search)=|(author|category|extension|file|help|index|mediawiki|meta|module|special|talk|template|topic|user|wiki([mp]edia|source))(:|%3A))/i.test( location.href ),
limit:
40,
groups: [
{
include:
document.evaluate(
"//body[contains(@class,'ns-0')]",
document,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null
).snapshotLength===0, // skip pages in main name-space...
patterns: [
/\\\S/g, // back-slash escape?
/;[.,:]/g, // chained punctuation, semicolon-led
/,[.,;:]/g, // chained punctuation, comma-led
/:[.,;]/g, // chained punctuation, colon-led
/(^|[^'])Ave(?!([.!]| Maria))(\W|$)/g, // typo of "we" (but "'Ave", "Ave." or "Ave Maria" is O.K.)
/\|[-+]?/g, // wikicode leaking into HTML (yes the '?' is dodgy but enlarges the match for table caption/row)
/\Wim(der|desirable|less|productive)/g, // typo of "under"/"undesirable"/"unless"/"unproductive"
/(?!na)vv(?!(ies|y))/g, // typo of "w" (though legitimate in "navvy" or plural)
/(^|\W)Sts?(?!\.)(\W|$)/g, // typo of "St."
/\s["'`;:,!?$%*()=+~]\s/g, // floating punctuation mark: WARNING: modern style: floating "=" OK
/modem/gi, // typo of "modern"
/\w&/g, // embedded or trailing "&"
/&(?!c\.)\w/g, // leading "&" ("&c." O.K.)
/(^|\W)[a-z]+[A-Z]+[A-Za-z]+(\W|$)/g, // upper case embedded within lower case word
/(^|\W)[A-Z]{2,}[a-z]+[A-Za-z]+(\W|$)/g, // lower case embedded within upper case word
/(^|\W)[a-zA-Z]+\d+[a-zA-Z]*(\W|$)/g, // digit embedded within word
/(^|\W)\d+[a-zA-Z]+\d+(\W|$)/g, // alphabetic embedded within digits
/(^|\W)[a-zA-Z]+ \.[a-zA-Z]+(\W|$)/g, // period surrounded by letters
/ tlie /g, // typo of "he"
/li /g, // typo of "h"
/ Av/g, // " w" at the start of the word
/ op /g, // typo of standalone " of "
/lI /g, // typo of "ll" or "h"
/ii/g, // "u" or ü"
/jj/g, // "p" or "g"
/\^/g, // standalone "^"?
/{[[\]]}{1,}/g, // mis-terminated template, link or standalone "^"?
/{[(\)}^]{1,}/g // plagiarised parenthesis
],
styling:
'background:LightSalmon;'
},
// end of add
]
};
jQuery( document ).ready(
HighlightTyposLike( self.typoscan )
);
// </nowiki>
Activation
- The script is activated by the following code placed in the common.js. Use the following script and replace "username" with your username.
//activate typoscan script of User:username/common.js/typoscan.js mw.loader.load('//en.wikisource.org/w/index.php?title=User:username/common.js/typoscan.js&action=raw&ctype=text/javascript');
This enables a toolbar button when editing in the Page namespace that switches in and out of full-screen mode, making it easier to proofread on smaller screens. The sidebar, and lots of other parts of the wiki layout, are removed completely; only things necessary for proofreading are kept.
Its effect can further be enhanced in many web browsers by entering the browser's full screen mode as well (F11 in most browsers).
To enable, add this line to your common.js page:
mw.loader.load('//en.wikisource.org/w/index.php?title=User:Samwilson/FullScreenEditing.js&action=raw&ctype=text/javascript');
Adds a toolbar button to clean up OCR text. This is a fork of part of MediaWiki:TemplateScript/proofreading.js, to re-implement it as a toolbar button. To use, add this to your common.js page:
mw.loader.load('//en.wikisource.org/w/index.php?title=User:Samwilson/PageCleanUp.js&action=raw&ctype=text/javascript');
There is also a slightly changed version of this Samwilson’s tool which lacks replacement of fullstops for commas before capital letters (as this may be a source of frequent errors in some texts):
mw.loader.load('//en.wikisource.org/w/index.php?title=User:Jan.Kamenicek/PageCleanUp.js&action=raw&ctype=text/javascript');
Adds a toolbar button for converting all quotation marks, apostrophes, and dashes to their correct nicer typographical selves. To use, add this to your common.js page:
mw.loader.load('//en.wikisource.org/w/index.php?title=User:Samwilson/CurlyQuotes.js&action=raw&ctype=text/javascript');
LinkedLintErrors
Adds a sidebar link which shows a list of lint errors for the current page and every page linked from it. Should work on all Wikimedia projects. To use, add this to your global.js page on Meta:
mw.loader.load('//en.wikisource.org/w/index.php?title=User:Samwilson/LinkedLintErrors.js&action=raw&ctype=text/javascript');
Quick Access
Adds a sidebar link that pops up a searchable list of all actions for a page. The link can be invoked with a hotkey (Shift+Alt+A), so it enables keyboard driven use of tools, even when the tools aren't visible on the page due to being scrolled off-screen.
mw.loader.load('//en.wikisource.org/w/index.php?title=User:Inductiveload/quick_access.js&action=raw&ctype=text/javascript');
Index Preview
Adds a button to show a grid of the page in an Index, which can be helpful for page listing operations. Alt-clicking allows to quickly mark pages as without text, raw images or with tables.
mw.loader.load('//en.wikisource.org/w/index.php?title=User:Inductiveload/index_preview.js&action=raw&ctype=text/javascript');
Tools
- Tools Labs-based
- Intersection search tool, negative and positive searches. help
- Direct uploading of one or more files to Commons (utilises OAuth)
- Internet Archive upload tool (IA Upload) (utilises OAuth)
- Wikimedia file transfer to Commons
- Dictionary of National Biography project tool
Purpose:To identify pages that have been proofread with the Wikisource:WikiProject DNB and ancillary mainteance tasks
Usage:Click the link, no refinement available.
- Article page history
Purpose: Enables a deep look at the edits to a page, including when, who, size, statistics.
Usage: Currently available as a link from the history of each page, or to paste in the name of the page of interest, eg. for this page Wikisource:Tools and scripts
- Index: @ Page: transclusion check tool
Purpose: Maintenance tool to check the transclusion status of the Page: namespace pages that are linked to from the overarching Index: page. Useful to find pages that may have been missed when transcluding a work to main namespace, or to identify pages that need to be managed following maintenance to the related djvu file.
Usage: As a link from each Index: page for a work, or to paste in the name of the Index page with its namespace, eg. Index:The Dictionary of Australasian Biography.djvu.
- Book scroll
- Purpose: Tool to scroll through a djvu file. Active links from the Index: page of works.
- Category browser for all validated works on English Wikisource.
- Purpose: To give a quick overview of the category hierarchy when determining what categories to use for a work in the main namespace.
- Wikisource Image Uploader
- Purpose: streamlined image upload for images and illustrations extracted from books.
- Usage: visit the tool, fill in the form, auto-generate the file description and upload the image
Text editors
Editing Wikisource may involve using a wide range of characters, some of which are not found on most English keyboards. Although it's possible to change one's keyboard language, this can be cumbersome for a few words. Many UTF-8 text editors allow the user to display a pop-up list of Unicode characters. Text strings in UTF-8 can be generated for pasting into Wikisource documents.
See also
- w:Wikipedia:Tools has a large collection of tools, though most will not work on Wikisource without modification.