Page MenuHomePhabricator

Get Google OCR tool to reliably load in the toolbar
Closed, ResolvedPublic1 Estimated Story Points

Description

Sometimes the OCR button doesn't actually load in the toolbar. Might be a race condition with it trying to add the button before the rest of the toolbar is loaded. We should investigate how the RefToolbar (default gadget) on English Wikipedia loads it's Cite button in the toolbar since it seems to be reliable.

Feel free to implement this fix on the sandbox version: https://wikisource.org/wiki/Wikisource:Google_OCR/sandbox.js

Event Timeline

kaldari triaged this task as Medium priority.Sep 15 2016, 7:08 AM
kaldari moved this task from New & TBD Tickets to Estimated on the Community-Tech board.
kaldari moved this task from Estimated to To Be Estimated/Discussed on the Community-Tech board.
Samwilson added a subscriber: Samwilson.

Other people have had this trouble (I quote: "Is there a Math.random() call in the resource loader?"). And thanks to their trouble I think I've fixed it. At least it seems to be no worse broken by replacing

$( '#wpTextbox1' ).on( 'wikiEditor-toolbar-doneInitialSections', function () {

with

$(document).ready( function() {

Sounds strange, and surely that's not how it's mean to work, but so far I can't make it fail to load. It was reasonably easy to replicate by editing the JS and then reloading a Page edit form; the OCR button would fail to load on the first (and only the first) load.

The diff with my sandbox is at https://wikisource.org/wiki/Special:ComparePages?page1=MediaWiki%3AGoogleOCR.js&rev1=&page2=User%3ASWilson+%28WMF%29%2FGoogleOcr.js&rev2=&action=&diffonly=&unhide=

(@kaldari: have you noticed this trouble with the proofreadpage toolbar section as well? I have sometimes. I'm wondering if the trouble lies in the way that extension [[https://github.com/wikimedia/mediawiki-extensions-ProofreadPage/blob/bfcf44e48e70234143963d2cba5a6d7cbb3fb2ae/modules/page/ext.proofreadpage.page.edit.js#L191|calls wikiEditor( 'addToToolbar', ...)]]. But that's another issue.)

The toolbar is shown with JavaScript, right? I think $(document).ready is only triggered when the DOM is ready, where the JS might take longer to manipulate the DOM.

There are also hooks built into JS core, and ways to add your own hooks:
https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook

The toolbar might have its own hook registered which we could go off of, or we could add one.

@Samwilson: That's a pretty unexpected solution. I'll try it out and see...

@Samwilson: Also, please claim tasks and move them into the In Development column when you start working on them. Thanks!

kaldari claimed this task.

Hmm, seems to be working.

DannyH set the point value for this task to 1.Sep 16 2016, 12:08 AM