User:Alex brollo/Editing tools

From Wikisource
Jump to navigation Jump to search

Welcome into my strange, but rich, editing environment. Please leave a message into talk page, or into my personal talk page, or write me an email - as you like, if you like, when you like.

Just to begin[edit]

Please add to your vector.js or common.js (you're using vector skin, aren't you?) this:

importScript("User:Alex brollo/common.js");

.

or - better - copy the content of User:Alex brollo/common.js into your common.js or vector.js page.

Then go in edit mode into any nsPage page. Here I am to explain edit tools (into sidebar) and buttons (at the bottom of the page) that you'll see.

Just to wet whet your appetite, this is what I do entering into a new page of Index:De re metallica (1912).djvu facing with draft OCR:

  • one click to (Header Row) Riga intestazione, a complete code for Running header pops up:
  • one click to (Line 1 eliminator) elimina riga 1, first row of text disappears;
  • one click to (paragraph adjustors) aggiusta paragrafi, empty rows are added at the end of paragraphs (the script being right in 90% of cases);
  • one click to (postOcr,?) postOcr, hypenated words and text of lines are joined and small OCR (typos?) scannos are fixed;
    • some more selections-and-clicks, annotations are regularly wrapped into ref tags and moved into the right position of text … :-)

My screen (2013.07.18)[edit]

You can see ""Sidebar tools" (left) and "bottom tools" (bottom)


Most useful tools: details[edit]

I apologize for the Italian, I'll fix it as soon as possible editing the source code in it.source. The idea and most code comes from Regex Menu Framework by Pathoschild (thanks!)

Sidebar tools ("Edit tools")[edit]

  1. find & replace: a Find and Replace tool with some interesting features; it imports selection into find and into replace fields, it is not so much large, and in it.source it has a "ricorda" (remember), cookie-based option, so that recurrent find-and-replace sequences can be shot again by postOCR tool in other related pages.
  2. delete row n.1: deletes the first row in edit box, often containing original page header from OCR.
  3. fix paragraphs: OCR from djvu text layer doesn't save paragraph identifiers nor adds an empty after a paragraph end. Nevertheless, most paragraphs can be identified by a sequence of a period + new line; this tools searches text for such sequences and adds an empty row (t.i. a new line) after the sequence when such an empty row doesn't exists. In regular texts, it runs on most paragraphs. It does nothing into poems (identified by poem tags)
  4. postOCR: it does a lot of edits converting the OCR output into a decently formatted text (it joins hyphenated words broken by a new line; it removes new lines but those at the end of paragraphs; it fixes small, frequent OCR scannos; if cookie-based trick to "remember" find-and-replace sequences is activated, it runs such sequences). It does not join rows into poems, when identified by a poem tag; it doesn't join lines in they begin with a list-repalet wiki markup (;:*#).
  5. auto Running header: it writes into header a complete code for running header. Nothing magic in it: simply, when you edit a page, the wole text of previous page (current djvu page -1) and of previous page of that page (cirrent djvu page -2) are loaded unto memory; so, basing on running header of page -2, and adding 2 to the only number usually present, a perfect header is built "automagically". Obviously it runs when editing pages in sequence, and only when page -2 has its running header perfectly compiled. It "goes wrong" when running header is not the same (usually when a new chapter-section of the book begins); no matter, the code can be easily changed and will run for following pages, till the chapter name changes again.
  6. toggle annotations: this is a most useful tool both for OCR edit and for following edits. Usually annotation text is on the bottom of the book page; it is comfortable to edit it leaving it into its original position, then moving it into the text. Usually this can be done only once; then, who reads the page again is faced with a difficult edit, since it finds a terrible "mixture" of text coming from main text, and text wrapped into ref tags. The tool toggles refs from normal position (inside text) and edit position (to the bottom of the page) with a simple click; this is done replacing ref tags into the bottom of the page, and leaving into text a "bookmark". If you like, you can use this trick too in the first edit: simmly edit the text of annotations where they are (at the bottom of the page), wrap them into ref tags, then add bookmarks to the text in the right position, and click the tool. If the number of bookmarks doesn't match numbero of annotation (a common mistake when annotations are many), the tool doesn't run and gives an error message. It moves any kind of ref tags but ref follow= ones. Theres another tool "note" among buttons tool which helps to add ref tags and to insert bookmarks.
  7. capitalize rows: it capitalizes first character of selectioned text lines (most useful in poems)

More about "toggle annotations"[edit]

Here three screenshots.

A screenshot of an example text where a base text and three annotations are mixed; it's very difficult to understand what you are reading. In red, the "toggle annotations" tool. Click on it.....
... and you will get this: annotations moved to the bottom of the page, leaving in place a bookmark <sup>nota</sup>. Read confortably, fix what is to be fixed, click again and....
... annotations moved again to their normal place. :-). Repeat how times you want; if you save befor toggling annotations into their normal location, nothing is lost: edit the text and use the tool again.

bottom tools ("buttons")[edit]

This is something new. Buttons are added into a fixed div into the bottom of the page; it doesn't scroll and is indipendent from page layer. Both icons and text buttons can be used. New personal buttons can be added to default ones with a mostly simple js syntax. You can add as many buttons you want. The code to build buttons is into User:Alex_brollo/libreriaVector.js; many functions called by buttons are into it:User:Alex_brollo/Gadget-Tools.js. I apologyze for lacking doc and for random order of things; they were "personal tools", then the whole thing became larger by itself :-).

Code for new buttons can be added into a personal "button page", User:User name/PersonalButtons.js.

Examples from default buttons

This is the code for Center template button (icon style; "encapsulate" action):

newButton("//upload.wikimedia.org/wikipedia/commons/5/5f/Button_center.png", "incapsula('{{Center|','}}')", "es");

This is the code for Center template button (text button style; "callback" action):

newButton("preOCR", "preOCR()", "es");

This the mostly simple syntax:

parameter 1
a string: a "text button style" button will be built
a link to the image of an icon: a "icon style" button will be built
parameter 2
any javascript function (if there are no parameters, parentheses are optional)
parameter 3
when the button has to be displayed (e= edit; s= preview; v= view)
Example for a new button, "encapsulate" action
A new button is needed, to encapsulate selection into a tl|Pag; here what is needed to have a text button, into edit and preview mode only:
newButton("Pag","incapsula('{{Pag|','}}')","es");
Copy the code into your User:User name/PersonalButtons.js. Purge your cache. Done.

State of art, oct 2013[edit]

My edit tools[edit]

This is a today (15.10) screenshot of my present edit environment. As into previous creenshot, marks point to the two "families" of tools: Edit tools (at the bottom of sidebar; inspired by Pathoshild Regex menu framework and using some of his code) and Button bar fixed at the bottom of the page).

Source scripts[edit]

Presently there are four scripts to run the whole stuff.

into oldwikisource (add the code into your personal common.js or vector.js page)
  1. Library.js: general utilities
  2. RMF_tools.js: Edit tools scripts
  3. Buttons_tools.js: Button bar generic scripts
  • To run them copy this into your User:your_name/vector.js or User:your_name/common.js:
mw.loader.load('https://wikisource.org/w/index.php?title=User:Alex_brollo/Library.js&action=raw&ctype=text/javascript');
mw.loader.load('https://wikisource.org/w/index.php?title=User:Alex_brollo/RMF_tools.js&action=raw&ctype=text/javascript');
mw.loader.load('https://wikisource.org/w/index.php?title=Buttons_tools.js&action=raw&ctype=text/javascript');


into local project
  1. User:Alex brollo bis/PersonalButtons.js list of buttons to fill Button bar. This set is both project and user-specific and any user, even without sysop profile, can edit it freely.

Button syntax[edit]

As soon as you upload Library.js, RMF_tools.js, and Button_tools.js, you'll run a newButton() function, and you can use it to add or edit buttons into your buttons bar adding code to your User:your_name/PersonalButtons.js.

Here the basics to build a new button of the simpler type - a "normal" button calling a js function.

Let we anatomyze the "NewPP" button's code.

newButton("NewPP", "NewPP()", "v");

You see:

  1. a free button name, it will be shown into the button;
  2. a javascript function call, NewPP(); this function has been loaded into one of general script listed previously, but you are free to call any js function existing into the running environment; thei can come from main mediawiki scripts, or from gadgets, or from your personal js files, or from Chrome Shortcut manager, or from your js console to test them!
  3. a "actions context" , "v" for "view", you can use e for edit, v for view, s for submit into any combination; so many buttons have a "es" actions context and they will be activated only when editing or previewing.

So, NewPP button launches NewPP() function and appears in view mode only.

With some care to apostrophes, you can add to function call parameters:

newButton("show", "show('wiki text')", "evs");

calls show('wikitext') from any action (edit, view or submit).

There' too a incapsula() function that emulates the most common button action, t.i. to wrap selection into a prefix and a suffix; it is built to be called by a button.

Let we see a function created here to wrap selection into “”:

newButton("“ ”", "incapsula('“','”')", "es");

Note the use of single and double apostrophes to pass parameters to incapsula() function; if confused use html entities for special characters <, >, " and & into incapsula() parameters.

If you replace the first parameter with the direct link to an image (an icon), a "icon button" will be created:

newButton("//upload.wikimedia.org/wikipedia/commons/5/5f/Button_center.png", "incapsula('{{Center|','}}')", "es");

That's all. :-)