Utilisateur:FreeCorp/vector.js
Note : après avoir enregistré vos modifications, il se peut que vous deviez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
- Firefox / Safari : Maintenez la touche Maj (Shift) en cliquant sur le bouton Actualiser ou pressez Ctrl-F5 ou Ctrl-R (⌘-R sur un Mac) ;
- Google Chrome : Appuyez sur Ctrl-Maj-R (⌘-Shift-R sur un Mac) ;
- Internet Explorer : Maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5 ;
- Opera : Allez dans Menu → Settings (Opera → Préférences sur un Mac) et ensuite à Confidentialité & sécurité → Effacer les données d'exploration → Images et fichiers en cache.
/*jshint boss:true*/
/*global $, mw*/
/*
* Query an ocr for a given Page:, first try to get the hocr text layer as it's available
* for most book, fast and of a better quality. If it fails, try the older and slower
* ocr method. hocr fail around 1/5000 books. ocr should never fails as it use the image
* visible on the Page:.
*/
mw.loader.load('http://en.wikisource.org/w/index.php?title=User:Ineuw/OCR.js&action=raw&ctype=text/javascript');
mw.loader.load('//nap.wikisource.org/w/index.php?title=User:George2etexte/GoogleOCRFrench.js&action=raw&ctype=text/javascript');
mw.loader.load('//fr.wikisource.org/w/index.php?title=Utilisateur:Seudo/LongSRestore2.js&action=raw&ctype=text/javascript');
mw.loader.load( 'https://ru.wikipedia.org/w/index.php?title=MediaWiki:WEF AllEditors.js&action=raw&ctype=text/javascript' );
mw.loader.load("//www.wikidata.org/w/index.php?title=User:Yair rand/WikidataInfo.js&action=raw&ctype=text/javascript");
importScript('User:Tpt/ws2wd.js');
importScript('MediaWiki:Gadget-MiseEnPage.js');
importScript('MediaWiki:Gadget-Typo.js');
var lang = mw.config.get( 'wgContentLanguage' );
function disable_input(set)
{
if (set) {
$(document).keyup(function(e) {
if (e.which == 27) { disable_input(false); }
});
}
set ? $('#wsOcr1').off('click') : $('#wsOcr1').on('click', do_hocr);
set ? $('#wsOcr2').off('click') : $('#wsOcr1').on('click', fraktur_ocr);
$('#wpTextbox1').prop('disabled', set);
}
function ocr_callback(data) {
if (data.error) {
alert(data.text);
} else {
// Checking if tb is disabled is required with chrome as ESC doesn't kill
// the query.
var tb = document.getElementById("wpTextbox1");
if (tb.disabled)
tb.value = data.text;
}
disable_input(false);
}
function hocr_callback(data) {
// Fallback to old OCR when data.text doesn’t contain XML to workaround T228594
if ( data.error || data.text.substring(0,5)!="<?xml" ) {
// Fallback to the slow way.
disable_input(false);
do_ocr();
return;
} else {
// Checking if tb is disabled is required with chrome as ESC doesn't kill
// the query.
var tb = document.getElementById("wpTextbox1");
if (tb.disabled) {
localStorage.ws_hOCR = data.text;
var text = $(data.text).text();
// Ugly as hell.
text = text.replace(/^ +/mg, '')
.replace(/\n{4,}/g, '@_@_@_@')
.replace(/\n{2,}/g, '____SPACE____')
.replace(/\n/g, ' ')
.replace(/____SPACE____/g, '\n')
.replace(/@_@_@_@/g, '\n\n');
tb.value = $.trim(text);
}
}
disable_input(false);
}
function do_hocr() {
disable_input(true);
var request_url = '//phetools.toolforge.org//hocr_cgi.py?cmd=hocr&book='
+ encodeURIComponent(mw.config.get('wgTitle')) + '&lang=' + lang + '&user=' + mw.config.get('wgUserName');
$.getJSON(request_url).done(hocr_callback).fail(do_ocr);
}
function do_ocr() {
if ($( '.prp-page-image img' ).length) {
disable_input(true);
// server side can't use protocol relative url, request it as https:
var url_image = 'https:' + $( '.prp-page-image img' ).attr('src');
var request_url = "//phetools.toolforge.org/ocr.php?cmd=ocr&url="+url_image+"&lang="+lang+"&user="+mw.config.get('wgUserName');
$.getJSON( request_url ).done( ocr_callback );
}
}
function fraktur_ocr()
{
lang = 'de-f';
// For fraktur we need to use the slow way, all hocr for 'de'
// are done with non-fraktur.
do_ocr();
lang = mw.config.get( 'wgContentLanguage' );
}
function addButtonToWikiEditorToolbar( b ){
var tools = {};
tools[ b.imageId ] = {
label: b.speedTip,
type: 'button',
icon: b.imageFile,
action: {
type: 'callback',
execute: b.onClick
}
};
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
section: 'main',
group: 'insert',
tools: tools
} );
$( '[rel="' + b.imageId + '"]' ).width( 42 );
}
function addButtonToClassicToolbar( b ){
mw.toolbar.addButton( {
imageFile: b.imageFile,
speedTip: b.speedTip,
imageId: b.imageId
} );
$( '#' + b.imageId ).off( 'click' ).click( function () {
b.onClick();
return false;
} ).width( 46 );
}
function customizeToolbar()
{
var modules, add, img;
// This can be the string "0" if the user disabled the preference ([[bugzilla:52542#c3]])
if( mw.user.options.get( 'usebetatoolbar' ) == 1 ){
modules = [ 'ext.wikiEditor' ];
img = '//upload.wikimedia.org/wikipedia/commons/c/c9/Toolbaricon_OCR.png';
add = addButtonToWikiEditorToolbar;
} else if ( mw.user.options.get( 'showtoolbar' ) == 1 ){
modules = 'mediawiki.toolbar';
img = '//upload.wikimedia.org/wikipedia/commons/e/e0/Button_ocr.png';
add = addButtonToClassicToolbar;
} else {
return;
}
$.when(
mw.loader.using( modules ),
$.ready
).then( function(){
if( mw.config.get( 'wgContentLanguage' ) === 'de' ){
add( {
imageFile: img,
speedTip: 'Normale OCR',
imageId: 'wsOcr1',
onClick: do_hocr
} );
add( {
imageFile: '//upload.wikimedia.org/wikipedia/commons/a/af/Button_Fractur_OCR.png',
speedTip: 'Fraktur OCR',
imageId: 'wsOcr2',
onClick: fraktur_ocr
} );
} else {
add( {
imageFile: img,
speedTip: 'Get the text by OCR',
imageId: 'wsOcr1',
onClick: do_hocr
} );
}
} );
}
if ( mw.config.get( 'wgCanonicalNamespace' ) === 'Page' &&
$.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 &&
!self.proofreadpage_disable_ocr
) {
mw.loader.using( 'user.options' ).done( customizeToolbar );
}
//============================================================
// Script pour le Trévoux (Phe's product)
// le troisième document.write() n'est pas indispensable (il ajoute un bouton dans la fenêtre des diffs en dessous des diffs pour avoir des meilleurs diffs), il
// est utile pour voir plus facilement les modifications faites par le script. Le code est dans Trévoux.js, la plupart des regexp dans Trévoux_data_1.js pour
// alléger le script principal.
//============================================================
var server = mw.config.get('wgServer');
jQuery.getScript(server + '/w/index.php?title=User:Acer11/Trévoux_data_1.js&action=raw&ctype=text/javascript&dontcountme=s', function() {
jQuery.getScript(server + '/w/index.php?title=User:Acer11/Trévoux_data_2.js&action=raw&ctype=text/javascript&dontcountme=s', function() {
mw.loader.load(server + '/w/index.php?title=User:Acer11/Trévoux.js&action=raw&ctype=text/javascript&dontcountme=s');
});
});
//Boutons pour le trévoux : sc et latin
if(typeof $ != 'undefined' && typeof $.fn.wikiEditor != 'undefined') {
$(function() {
$('#wpTextbox1').wikiEditor('addToToolbar', {
section: 'advanced',
group: 'format',
tools: {
'sc': {
label: 'Small caps',
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/6/6e/Small_caps.svg?size=23px',
action: {
type: 'encapsulate',
options: {
pre: '{{sc|',
peri: '',
post: '}}',
ownline: false
}
}
},
'la': {
label: 'Latin',
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/thumb/0/04/ISO_639_Icon_la.svg/23px-ISO_639_Icon_la.svg.png',
action: {
type: 'encapsulate',
options: {
pre: "''{{lang|la|",
peri: '',
post: "}}''",
ownline: false
}
}
},
'section': {
label: 'Section',
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/c/c5/Toolbaricon_bold_sharp.png',
action: {
type: 'encapsulate',
options: {
regex: /^\n?(☞? ?)(.*)$/,
regexReplace: '##"$2"##\n<nowiki/>\n\n$1$2',
}
}
}
}
});
});
} else if (mwCustomEditButtons) {
mwCustomEditButtons[mwCustomEditButtons.length] = {
"imageFile": "http://upload.wikimedia.org/wikipedia/commons/a/a2/SmallcapsButton.png",
"speedTip": "small caps",
"tagOpen": '{{sc|',
"tagClose": '}}',
"sampleText": ""};
mwCustomEditButtons[mwCustomEditButtons.length] = {
"imageFile": "http://bits.wikimedia.org/skins-1.5/common/images/button_sig.png",
"speedTip": "latin",
"tagOpen": "''{{lang|la|",
"tagClose": "}}''",
"sampleText": ""};
}