Extension:Proofread Page/Page viewer

From mediawiki.org
Jump to navigation Jump to search

Background[edit]

The ProofreadPage extension uses the popular OpenSeadragon (OSD) library to provide a zoomable image viewer in the Page namespace and the Pagelist editor. This provides various useful features:

  • A well-known and robust JS API for script and gadget extensibility
  • Zoom and panning that works on desktop and mobile
  • A well-maintained upstream codebase

OpenSeadragon replaced the previous home-made jQuery implementation in release 1.38.0-wmf.9.

Using the viewer[edit]

The main viewport controls are found on the top right of the image viewer:

Wikisource page view controls.png

From left to right:

  • OOjs UI icon crop.svg Select a region of the image for OCR (not merged yet)
  • OOjs UI icon guide-h.svg Add a moveable guide (not merged yet)
  • Zoom in, out and reset zoom to the full page
  • OOjs UI icon arched-arrow-rtl.svg OOjs UI icon arched-arrow-ltr.svg Rotate the image by 90 degrees left or right

Mouse navigation[edit]

Some of these features are not merged yet: Gerrit change 740369

You can scroll and zoom the image as follows:

  • Left click and drag: pan the image
  • Scroll wheel: zoom the image in and out
  • Ctrl+scroll: pan the image up and down
  • Shift+scroll: pan the image side to side
  • Left click: zoom in one step
  • Shift+Left click: zoom out one step

The middle mouse button switches the normal and Ctrl-key modes (so Ctrl+scroll becomes zoom and normal scroll becomes pan). The cursor changes to identify which mode you are in.

Keyboard navigation[edit]

The default OpenSeadraon keyboard bindings are used:

  • w, up arrow — move viewport up
  • s, down arrow — move viewport down
  • a, left arrow — move viewport left
  • d, right arrow — move viewport right
  • 0 — zoom / move viewport home
  • - _, Shift+W, Shift+up arrow — zoom viewport out
  • =, +, Shift+S, Shift+down arrow — zoom viewport in
  • r — rotate clockwise
  • R — rotate counterclockwise

Marker lines[edit]

Not merged yet

The button OOjs UI icon guide-h.svg can be used to add a moveable guide.

  • Click the button to add a guide to the image.
  • Drag a guide to move it
  • Double-click a guide to delete it

Guides will persist when you reload the page, so they can be used to help keep your place while previewing your changes.

Viewer options[edit]

There are some options for the page viewer in your preferences, in the Editing tab, under the Proofreading interface options heading.

Animation speed
This makes the panning and zoom feel smoother. The default is '0', which means there is zero lag and the zoom "snaps" from one level to the next. The OSD default used on many third-party image viewers is 1.2.
Zoom step of the viewer
This adjusts how "fast" the viewer zooms in and out. The default is 1.2. If you find the zoom too aggressive, you could try to lower it to, say, 1.1.

JS API[edit]

mw.hook[edit]

The following mw.hooks are fired:

Hook Description Arguments
ext.proofreadpage.osd-viewer-ready Fired when the OpenSeadragon viewer is ready and an image is loaded.
  • Argument 1: viewer the OpenSeadragon viewer object (also available as mw.proofreadpage.viewer)

mw.proofreadpage[edit]

The following objects are presented in the mw.proofreadpage global object:

mw.proofreadpage.viewer[edit]

The OpenSeadragon viewer object. Only valid after ext.proofreadpage.osd-viewer-ready.

This can change, e.g. after the viewer is swapped from horizontal to vertical mode.

mw.proofreadpage.getPageViewportControls()[edit]

Pending review: Gerrit change 736203

Returns a jQuery object that holds a <div> that contains controls for the viewer, which is placed in the WikiEditor toolbar. Scripts can add new controls to this area. Only valid after ext.proofreadpage.osd-viewer-ready.

Config variables[edit]

The following mw.config variables are added to Page namespace pages. These can be used by gadgets and user scripts.

Variable Content Type Example
prpFormattedPageNumber The formatted page number (usually what's actually written on the page) string "20"
prpImageFullSize The URL of the full-size page image (the largest image of the current page) string "//upload.wikimedia.org/wikipedia/commons/thumb/a/a8/My_mortal_enemy_-_1926.djvu/page20-3893px-My_mortal_enemy_-_1926.djvu.jpg"
prpImageThumbnail The URL of the thumbnail page image (the size used in the page viewer) string "//upload.wikimedia.org/wikipedia/commons/thumb/a/a8/My_mortal_enemy_-_1926.djvu/page20-1024px-My_mortal_enemy_-_1926.djvu.jpg"
prpIndexFields The values of any index fields in the index data config object marked js: true object { Progress: "C", Transclusion: "no", Footer: "\n", … }
prpIndexTitle The name of the associated index page string "Index:My mortal enemy - 1926.djvu"
prpPageQuality The current quality level of the page (0-4, 1 if the page doesn't exist yet) integer 1
prpPageQualityUser The name of the last user to set the quality string "SomeUser"

Use by scripts and gadgets[edit]

Scripts and gadgets can use the API for anything supported by the OpenSeadragon API via the mw.proofreadpage.viewer object.

Changing the image[edit]

The image can be changed by adding an image to the viewer.

For "simple" images (i.e. where you have just an image URL):

mw.hook( 'ext.proofreadpage.osd-viewer-ready' ).add( function ( viewer ) {
    // Can use viewer or mw.proofreadpage.viewer - they're the same
    viewer
        .addSimpleImage( {
            url: image_url
        } );
} );

You can also directly add an IIIF tiled image source:

mw.proofreadpage.viewer
	.addTiledImage( {
		tileSource: iiif_json_url
	} );

Adding buttons to the viewport control toolbar[edit]

These can be directly added to the element returned by mw.proofreadpage.getPageViewportControls():

var button = new OO.ui.ButtonWidget( {
	icon: 'home', // choose an icon
	framed: false,
	classes: [ 'tool' ]
} );

mw.proofreadpage.getPageViewportControls().append( button );

Tools do not have to go in this toolbar to interact with the OpenSeadragon viewer; they can also go in the sidebar, the normal toolbar (for which the WikiEditor toolbar configuration system can be used) or anywhere else in the DOM.

Region selection[edit]

This is not merged yet Gerrit change 741125

A region selection module (ext.proofreadpage.page.regionselection) is provided that allows scripts to add a simple rectangular region selection.

The region selection is communicated by OOUI events. Intantiate a region selector and bind handlers like this:

mw.loader.using( 'ext.proofreadpage.page.regionselection', function( require ) {
    var RegionSelection = require( 'ext.proofreadpage.page.regionselection' );
    var regionSelector = new RegionSelection();
    mw.hook( 'ext.proofreadpage.osd-viewer-ready' ).add( function ( viewer ) {
        regionSelector.register( viewer );
        
        regionSelector.connect( this, {
            [ regionSelector.events.selectionStart ]: [ 'onRegionToggle', true ],
            [ regionSelector.events.selectionEnd ]: [ 'onRegionToggle', false ]
	    } );
    } );
    
    // start a selection
    regionSelector.toggleSelection( true );
} );

In this case onRegionToggle is a handler that you should provide.

Events:

  • selectionStart emitted when a selection starts
  • selectionEnd emitted when a selection ends (the selection is cancelled somehow)

Methods on a RegionSelector:

  • isActive() if a selection is active now
  • getSelection() get the selection rectangle in a co-ordinate system from 0 to 1

See also[edit]