Wikisource:Tools and scripts

From Wikisource
Jump to: navigation, search

This page contain 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[edit]

Javascript[edit]

File formatting[edit]

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[edit]

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]] */

Scripts[edit]

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[edit]

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.

  1. Copy and paste the code below into your javascript file.
  2. Fill in your username in the username field.
  3. 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[edit]

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

  1. Copy and paste the code into your Javascript file
{{subst:Wikisource:Tools and scripts/SoftRedirect}}

More editing buttons[edit]

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[edit]

This script looks for a running header (i.e. an {{rh}} or {{runningHeader}}) template two pages before the current page (running headers typically repeat on a two-page basis), and fills in the current page.

It will increment an Arabic number (like "102") and Roman numerals ('CII' or 'cii'). If no number is found, the header will just be copied.

Update: First version August 22, 2010.
Authors: Phe, Inductiveload
  1. Copy and paste the code into your Javascript file
importScript('User:Inductiveload/Roman numerals.js');
importScript('User:Inductiveload/Running header.js');

typoscript[edit]

Update: last update October 02, 2016.
Author: AuFCL (Wikipedia)
 

typoscan.js documentation and scripts

 

Introduction[edit]

  • 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[edit]

  • 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[edit]

  • 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[edit]
  • Currently, there are two versions:
  • For the inclusion of the Main namespace pages to be highlighted, copy this code into the submodule:
// 

// main namespace included version
 
var typoFuse;  // overriden by actions.limit

function HighlightTyposUnder( node, actions ){
    if( typoFuse >= 0 && node ){
    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 )
);

// 
 
Exclusion of the Main namespace from highlighting typos[edit]
  • For the exclusion of the Main namespace pages from highlighting typos, copy this code into the submodule:
//  

// main namespace excluded version

var typoFuse;  // overriden by actions.limit
 
function HighlightTyposUnder( node, actions ){
    if( typoFuse >= 0 && node ){
    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 )
);

// 
 

Activation[edit]

  • 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');


FullScreenEditing[edit]

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');

PageCleanUp[edit]

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');

CurlyQuotes[edit]

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');

Tools[edit]

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 (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.

Text editors[edit]

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[edit]

  • w:Wikipedia:Tools has a large collection of tools, though most will not work on Wikisource without modification.