Content deleted Content added
+bengali translation |
p- |
||
(28 intermediate revisions by 6 users not shown) | |||
Line 7:
// turn on ECMAScript 5 strict mode
'use strict';
// We will not log errors for users using this script due to volume of bugs.
mw.loader.using('mediawiki.storage').then(function () {
mw.storage.session.set( 'client-error-opt-out', '1' );
// define global object
var wikEd; if (wikEd === undefined) { wikEd = {}; }
// default to null (all checks are against null so make sure it starts as null)
if (wikEd.paste === undefined) {
wikEd.paste = null;
wikEd.Meta = function () {/*
// ==UserScript==
// @name wikEd
// @version 0.9.
// @date
// @namespace https://en.wikipedia.org/wiki/User:Cacycle/
// @description A full-featured in-browser editor for Wikipedia and other MediaWikis
Line 1,259 ⟶ 1,270:
// use French rules for fix punctuation
if (wikEd.config.fixPunctFrench === undefined) { wikEd.config.fixPunctFrench = false; }
// convert \xa (nbsp) to character entities so they do not get converted to blanks
if (wikEd.config.convertNbspToEntities === undefined) { wikEd.config.convertNbspToEntities = true; }
// wikEd.config.setupHook, executed after wikEd has been set up, usage: wikEd.config.setupHook.push(YourFunction);
Line 1,386 ⟶ 1,400:
wikEd.InitObject(wikEd.config.translations, {
'en': '',
'af': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:Arnobarnard/wikEd_international_af.js', // Afrikaans
'ar': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:ترجمان05/wikEd_international_ar.js', // Arabic
'bn': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:
'zh-hans': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:CAS222222221/wikEd_international_zh.js', // Chinese (simplified)
'zh-hant': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:Liflon/wikEd_international_zh-hant.js', // Chinese (traditional)
'
'
'
'
'
'
'
'
'
'hu': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:Tsch81/wikEd-hu.js', // Hungarian
'it': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:Jalo/wikEd_international_it.js', // Italian
'ja': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:Hatukanezumi/wikEd_international_ja.js', // Japanese
'kk': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:Arystanbek/wikEd_international_kk.js', // Kazakh
'ko': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:Ilovesabbath/wikEd_international_ko.js', // Korean
'dsb': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:Michalwiki/wikEd_international_dsb.js', // Lower Sorbian
'ms': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:Aviator/wikEd_international_ms.js', // Malay
'
'nn': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:Frokor/wikEd_international_nn.js', // New Norwegian
'
'
'
'
'
'
'
'
'
'
'
'
'
'ur': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:Obaid_Raza/wikEd_international_ur.js', // Urdu
'vi': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:Vinhtantran/wikEd_international_vi.js' // Vietnamese
});
};
Line 1,437 ⟶ 1,453:
// vector (see https://bugzilla.wikimedia.org/show_bug.cgi?id=19527)
vector_old: [ 'p-personal', true, true, ['content', 'bodyContent', 'contentSub', 'left-navigation', 'p-namespaces', 'p-cactions'] ],
vector_new: [ 'p-personal', true, true, ['content', 'bodyContent', 'contentSub', 'left-navigation', 'p-
// citizendium.org
Line 1,497 ⟶ 1,513:
wikEd.editSection = null;
// beta toolbar, CodeEditor, CodeMirror
wikEd.useBetaToolbar = false;
wikEd.useCodeEditor = false;
wikEd.codeEditorButtonPollCount = 0;
wikEd.useCodeMirror = false;
// history
Line 2,042 ⟶ 2,059:
// parse global-context (MediaWiki) variables into hash (for Greasemonkey)
var globalNames = ['skin', 'wgServer', 'wgTitle', 'wgCanonicalNamespace', 'wgArticlePath', 'wgScript', 'wgScriptPath', 'wgUserName', 'wgCurRevisionId', 'wgContentLanguage', 'wgUserLanguage
if (wikEd.greasemonkey === true) {
globalNames.push('wikEdConfig', 'wikEdText');
Line 2,629 ⟶ 2,646:
// do not turn on when code editor is active
if ( ( wikEd.useCodeEditor === true) || ( wikEd.useCodeMirror === true ) ) {
wikEd.disabled = true;
wikEd.SetLogo('incompatible', 'Code Editor');
Line 3,508 ⟶ 3,525:
if (wikEd.fixRegExTypo !== null) {
wikEd.fixRegExTypo.style.display = 'none';
▲ }
if (fixRedirect !== null) {▼
}▼
}
Line 3,837 ⟶ 3,846:
// allow other code to cause us to update the textarea via textSelection( 'getContents' )
$( '#wpTextbox1' ).textSelection(
'register',
▲ {
{
getContents: function () { if ( wikEd && wikEd.useWikEd ) {
wikEd.UpdateTextarea();
}
return $( this ).val();▼
}
▲ return $( this ).val();
}
} catch ( e ) {
▲ );
// catch `Error: Another textSelection API was already registered`
// When something else is registered should it unregister the existing one?
// Or should it detect this earlier and not run at all?
▲ }
}
Line 3,962 ⟶ 3,977:
wikEd.frameHtml = wikEd.frameDocument.documentElement;
wikEd.frameBody = wikEd.frameDocument.body;
if (!wikEd.frameBody) {
return;
}
// set frame body properties
Line 4,076 ⟶ 4,094:
}
// check for code editor cookies
if ( ( wikEd.jsPage === true ) || ( wikEd.cssPage === true ) ) {
if ( wikEd.wikiGlobals.wgPageContentModel === undefined ) {
if ( wikEd.GetCookie( 'wikiEditor-0-codeEditor-enabled' ) == 1 ) {
wikEd.useCodeEditor = true;
}
}
else if ( wikEd.wikiGlobals.wgPageContentModel != 'wikitext' ) {
if ( wikEd.GetCookie( 'wikiEditor-0-codeEditor-enabled' ) == 1 ) {
wikEd.useCodeEditor = true;
}
}
}
// this can't work 100 %, because async...
// not a problem for gadget, as it ensures this dependency is loaded
if ( (window.mw !== undefined) && (window.mw.user !== undefined) && (window.mw.user.options !== undefined) ) {▼
if (
if (window.mw.user.options.get('usebetatoolbar') == 1) {▼
( window.mw !== undefined ) &&
wikEd.useBetaToolbar = true;▼
( window.mw.loader.using !== undefined )
wikEd.useCodeEditor = true;▼
) {
window.mw.loader.using( 'user.options' ).then(
function() {
if (
( ( wikEd.jsPage === true ) || ( wikEd.cssPage === true) ) &&
) {
▲ wikEd.useBetaToolbar = true;
if ( window.mw.user.options.get('usecodeeditor') == 1 ) {
▲ wikEd.useCodeEditor = true;
}
}
// CodeMirror extension for syntax highlighting
if ( window.mw.user.options.get('codemirror-syntax-highlight') == 1 ) {
wikEd.useCodeMirror = true;
}
}
}
return;
Line 5,054 ⟶ 5,089:
wikEd.PastePoll = function () {
if (!wikEd.paste
return;
}
Line 5,199 ⟶ 5,234:
// vertical pos
if (rect && rect.bottom + barHeight <= parseInt(wikEd.frameHeight)) {
wikEd.buttonBarPasted.style.top = rect.bottom + 'px';
}
Line 8,588 ⟶ 8,623:
// check for named references defined outside edited section
if (
true
) {
Line 8,691 ⟶ 8,725:
else {
// attach <style> stylesheet declarations to document
var regExpMatch;
var regExp = /<()style\b[^>]*?type="text\/css">((.|\n)*?)<\/style>/gi;
Line 10,738 ⟶ 10,772:
// check if api is enabled
if
return;
}
Line 12,177 ⟶ 12,211:
else if ( (hrefParamTitle !== null) && (hrefParamSpecial !== true) ) {
linkArticle = hrefParamTitle;
linkArticle = linkArticle && linkArticle.replace(/_/g, ' ');
linkArticle = decodeURIComponent(linkArticle);
}
Line 12,184 ⟶ 12,218:
else if (hrefUrlArticle !== null) {
linkArticle = hrefUrlArticle;
linkArticle = linkArticle && linkArticle.replace(/_/g, ' ');
linkArticle = decodeURIComponent(linkArticle);
}
Line 12,199 ⟶ 12,233:
// format wiki link
if (linkArticle && linkArticle !== '') {
// check for wiki image
Line 16,388 ⟶ 16,422:
else {
wikEd.CleanNodes(wikEd.frameDocument);
obj.html = wikEd.frameBody.innerHTML;
} else {
return;
}
}
Line 16,435 ⟶ 16,474:
// convert \xa (nbsp) to character entities so they do not get converted to blanks
if (wikEd.config.convertNbspToEntities === true) {
obj.html = obj.html.replace(/\xa0/g, '&nbsp;');
}
}
Line 16,787 ⟶ 16,828:
//
wikEd.MainSwitch = function ( event ) {
// ctrl-click for debug info
if ( event.ctrlKey === true ) {
return;
}
// disable function if browser is incompatible
if ( wikEd.browserNotSupported === true ) {
return;
}
// enable wikEd
if ( wikEd.disabled === true ) {
// check for active code editor
Line 16,806 ⟶ 16,847:
// do not turn on when code editor is active
if ( ( wikEd.useCodeEditor === true ) || ( wikEd.useCodeMirror === true ) ) {
wikEd.disabled = true;
wikEd.SetLogo( 'incompatible', 'Code Editor' );
return;
}
wikEd.disabled = false;
wikEd.SetPersistent( 'wikEdDisabled', '0', 0, '/' );
// turn rich text frame on
if ( wikEd.turnedOn === false ) {
// setup wikEd
wikEd.TurnOn( false );
}
else {
wikEd.SetLogo();
var useWikEd = false;
if ( document.getElementById('wikEdUseWikEd').getAttribute('checked') == 'true' ) {
useWikEd = true;
}
wikEd.SetEditArea( useWikEd );
wikEd.useWikEd = useWikEd;
window.wikEdUseWikEd = wikEd.useWikEd;
if ( wikEd.useWikEd === true ) {
wikEd.UpdateFrame();
}
wikEd.buttonBarWrapper.style.display = 'block';
wikEd.buttonBarPreview.style.display = 'block';
if ( wikEd.buttonBarJump !== null ) {
wikEd.buttonBarJump.style.display = 'block';
}
// run scheduled custom functions
wikEd.ExecuteHook( wikEd.config.onHook );
}
}
Line 16,846 ⟶ 16,887:
// disable wikEd
else {
wikEd.SetPersistent( 'wikEdDisabled', '1', 0, '/' );
if ( wikEd.turnedOn === false ) {
wikEd.useWikEd = false;
window.wikEdUseWikEd = wikEd.useWikEd;
Line 16,856 ⟶ 16,897:
// interrupt fullscreen mode
if ( wikEd.fullscreen === true ) {
wikEd.FullScreen( false );
}
// turn classic textarea on
if ( wikEd.useWikEd === true ) {
wikEd.UpdateTextarea();
}
Line 16,867 ⟶ 16,908:
// reset textarea dimensions
wikEd.textarea.style.height = ( wikEd.textareaOffsetHeightInitial - wikEd.frameBorderHeight ) + 'px';
wikEd.textarea.style.width = '100%';
wikEd.frameHeight = ( wikEd.textareaOffsetHeightInitial - wikEd.frameBorderHeight ) + 'px';
wikEd.frameWidth = ( wikEd.editorWrapper.clientWidth - wikEd.frameBorderWidth ) + 'px';
wikEd.frame.style.height = wikEd.frameHeight;
wikEd.frame.style.width = wikEd.frameWidth;
Line 16,883 ⟶ 16,924:
wikEd.localPrevWrapper.style.height = 'auto';
if ( wikEd.buttonBarJump !== null ) {
wikEd.buttonBarJump.style.display = 'none';
}
Line 16,893 ⟶ 16,934:
// run scheduled custom functions
wikEd.ExecuteHook( wikEd.config.offHook );
}
}
Line 18,140 ⟶ 18,181:
// API request
var postFields = {
'format': 'xml',
'action': 'parse',
'
'
'text': textValue
};
var requestUrl = wikEd.scriptURL + 'api.php';
Line 18,179 ⟶ 18,221:
}
else {
postFields[ 'title' ] = 'wikEd_preview';
}
postFields[ 'action' ] = 'submit';
postFields[ 'wpTextbox1' ] = textValue;
if ( wikEd.starttime !== null ) {
postFields[ 'wpStarttime' ] = wikEd.starttime;
}
if ( wikEd.edittime !== null ) {
postFields[ 'wpEdittime' ] = wikEd.edittime;
}
if ( wikEd.editToken !== null ) {
postFields[ 'wpEditToken' ] = wikEd.editToken;
}
if ( wikEd.autoSummary !== null ) {
postFields[ 'wpAutoSummary' ] = wikEd.autoSummary;
}
postFields[ 'wpPreview'] = 'true';
▲ if (livePreview !== false) {
// keep for backward compatibility
postFields['live'] = 'true';▼
▲ postFields[ 'live' ] = 'true';
}
Line 18,325 ⟶ 18,369:
// uses postMessage, head script, and JSON encoding for Greasemonkey global to GM context access
wikEd.GetGlobals = function ( names, gotGlobalsHook ) {
if ( gotGlobalsHook !== undefined ) {
wikEd.gotGlobalsHook.push( gotGlobalsHook );
}
// code already running in global context
if ( wikEd.greasemonkey !== true ) {
var globalScopeCode = '';
for ( var i = 0; i < names.length; i ++ ) {
▲ if ( ( window.mw !== undefined ) && ( window.mw.
}
' wikEd.wikiGlobals.' + names[i] + ' = ' + names[i] + ';' +▼
▲ globalScopeCode += 'if (typeof ' + names[i] + ' != \'undefined\') { wikEd.wikiGlobals.' + names[ i ] + ' = ' + names[ i ] + ';
}
}
if ( gotGlobalsHook !== undefined ) {
globalScopeCode += 'wikEd.ExecuteHook(wikEd.gotGlobalsHook[' + (wikEd.gotGlobalsHook.length - 1) + '], true);';
}
eval( globalScopeCode );
return;
}
// prepare code to be executed in global context for Greasemonkey
if ( ( window.postMessage === undefined ) || ( typeof JSON != 'object' ) ) {
return;
}
var globalScopeCode = 'var globalObj = {};';
if ( gotGlobalsHook !== undefined ) {
wikEd.gotGlobalsHook.push( gotGlobalsHook );
globalScopeCode += 'globalObj.hookNumber = ' + ( wikEd.gotGlobalsHook.length - 1 ) + ';';
}
globalScopeCode += 'globalObj.scriptId = \'wikEdGetGlobalScript' + wikEd.getGlobalsCounter + '\';';
Line 18,360 ⟶ 18,406:
// add global scope variables
for ( var i = 0; i < names.length; i ++ ) {
globalScopeCode += '' +
'if (typeof ' + names[ i ] + ' != \'undefined\') {' +
' globalObj.wikEdGetGlobals[\'' + names[ i ] + '\'] = ' + names[ i ] + ';' +
'}';
}
globalScopeCode += 'var globalObjStr = \'wikEd:\' + JSON.stringify(globalObj);';
var origin = wikEd.pageOrigin;
if ( origin == 'file://' ) {
origin = '*';
}
Line 18,374 ⟶ 18,420:
// create head script to execute the code
var script = document.createElement( 'script' );
script.id = 'wikEdGetGlobalScript' + wikEd.getGlobalsCounter;
wikEd.getGlobalsCounter ++;
if ( script.innerText !== undefined ) {
script.innerText = globalScopeCode;
}
Line 18,383 ⟶ 18,429:
script.textContent = globalScopeCode;
}
wikEd.head.appendChild( script );
return;
};
Line 18,561 ⟶ 18,607:
//
wikEd.Debug = function ( objectName, object, usePopup ) {
// string
var value = '';
if ( typeof object == 'string' ) {
value = ': ' + '"' + object + '"';
}
// objects
else if ( typeof object == 'object' ) {
// null
if ( object === null ) {
value = ': [null]';
}
Line 18,579 ⟶ 18,625:
// whole highlighting parse tree array
// { 'tag': , 'parent': , 'firstChild': , 'nextSibling': , 'start': , 'tagLength': , 'type': , 'paired': , 'pairedPos': , 'left': , 'right': , 'index': , 'attrib': , 'newline': }
else if ( ( typeof object[0] == 'object' ) && ( typeof object[0].type == 'string' ) ) {
value = ': Parse tree full:\n';
for ( var i = 0; i < object.length; i ++ ) {
value += i + ': ';
var node = object[ i ];
if ( node === null ) {
value += '(null)\n';
}
else {
if ( node.type == 'root' ) {
value += '[type: "' + node.type + '"]\n';
}
else {
value += '[type: "' + node.type + '", tag: "' + node.tag + '", start: ' + node.start + ', tagLength: ' + node.tagLength + ', parent: ' + node.parent;
if ( typeof node.left == 'string' ) {
value += ', left: "' + node.left + '", right: "' + node.right + '"';
}
Line 18,640 ⟶ 18,686:
// DOM nodes
else if ( typeof object.nodeName == 'string' ) {
value = ': [node; nodeName: ' + object.nodeName;
if ( typeof object.id == 'string' ) {
if ( object.id !== '' ) {
value += ', id: "' + object.id + '"';
}
}
if ( typeof object.className == 'string' ) {
if ( object.className !== '' ) {
value += ', class: "' + object.className + '"';
}
}
if ( typeof object.nodeValue == 'string' ) {
value += ', nodeValue: "' + object.nodeValue + '"';
}
if ( ( typeof object.innerHTML == 'string' ) && ( object.innerHTML !== '' ) ) {
var html = object.innerHTML;
if ( html.length > wikEd.config.debugInnerHtmlLength ) {
html = html.substr(0, wikEd.config.debugInnerHtmlLength - 3) + '...';
}
Line 18,672 ⟶ 18,718:
// undefined
else if ( object === undefined ) {
value = '';
}
Line 18,683 ⟶ 18,729:
// use debug textarea
var useDebug = false;
if ( ( wikEd.debug !== undefined ) && ( wikEd.debug !== null ) ) {
useDebug = true;
}
if ( useDebug === true ) {
if ( wikEd.debugOpen === false ) {
wikEd.debugWrapper.style.display = 'block';
// resize fullscreen frame
if ( wikEd.fullscreen === true ) {
wikEd.ResizeWindowHandler();
}
else {
window.scroll( 0, wikEd.GetOffsetTop( wikEd.debug ) );
}
wikEd.debugOpen = true;
Line 18,702 ⟶ 18,748:
// cut text if having reached maximum length
value = objectName + value + '\n';
if ( wikEd.debug.value.length > wikEd.config.debugMaxLength ) {
wikEd.debug.value = value + wikEd.debug.value.substr(0, wikEd.config.debugMaxLength * 2 / 3);
}
Line 18,711 ⟶ 18,757:
// use popup alert
else if ( usePopup === true ) {
if ( object === null ) {
window.alert( objectName );
}
else {
window.alert( objectName + ': ' + value );
}
}
Line 18,723 ⟶ 18,769:
else {
var msg;
if ( object === null ) {
msg = objectName;
}
Line 18,729 ⟶ 18,775:
msg = objectName + ' ' + value;
}
wikEd.ConsoleLog( msg );
}
return;
|