User:Cacycle/wikEd.js: Difference between revisions

Content deleted Content added
0.9.145 (November 06, 2014) added nbsp support, preview polishing
p-
 
(48 intermediate revisions by 7 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.145155
// @date November 065, 20142017
// @namespace https://en.wikipedia.org/wiki/User:Cacycle/
// @description A full-featured in-browser editor for Wikipedia and other MediaWikis
Line 367 ⟶ 378:
'thinSpace': 'Thin space',
'ideographicSpace': 'Ideographic space',
'nbSpace': 'Non-breaking space',
 
// highlighting
Line 473 ⟶ 483:
'logo': '6/67/WikEd_logo.png',
'minusDash': 'b/ba/WikEd_minus_dash.png',
'nbSpace': '3/37/WikEd_nb_space.png',
'noFile': '8/88/WikEd_no_file.png',
'nowiki': '5/5a/WikEd_nowiki.png',
Line 784 ⟶ 793:
'.wikEdEnSpace': 'background-image: url({wikEdImage:enSpace}); background-position: bottom left; background-repeat: no-repeat; margin: 0 1px; padding: 0 3px;',
'.wikEdThinSpace': 'background-image: url({wikEdImage:thinSpace}); background-position: bottom left; background-repeat: no-repeat; margin: 0 1px; padding: 0 3px;',
'.wikEdIdeographicSpace': 'background-image: url({wikEdImage:ideographicSpace}); background-position: bottom left; background-repeat: no-repeat; margin: 0 1px; padding: 0 3px;',
'.wikEdNbSpace': 'background-image: url({wikEdImage:nbSpace}); background-position: top left; background-repeat: no-repeat;'
});
};
Line 885 ⟶ 893:
// find and replace fields
'.wikEdFindComboInput, .wikEdReplaceComboInput': 'position: relative; margin: 0 5px; top: -1px; white-space: nowrap; vertical-align: bottom; padding: 0; line-height: 20px; font-size: 13px;',
'#wikEdFindText, #wikEdReplaceText': 'padding: 0; font-family: monospace; margin: 0; position: absolute; left: 0; top: 0; z-index: 2; vertical-align: bottom; width: 170px; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; height: 18px;',
'#wikEdFindSelect, #wikEdReplaceSelect': 'font-family: monospace; margin: 0; position: relative; left: 0; top: 0; z-index: 1; vertical-align: bottom; width: 190px; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; height: 18px;',
 
// summary field
'.wikEdSummaryComboInput': 'position: relative; margin: 0 0 0 2px; top: 0; white-space: nowrap; padding: 0; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; font-size: 13px;',
'.wikEdSummaryText': 'padding: 0 2px !important; margin: 0; position: absolute; left: 0; top: 0; z-index: 2; vertical-align: bottom; width: auto; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; height: 21px;',
'.wikEdSummarySelect': 'padding: 0; margin: 0; position: relative; left: 0; top: 0; z-index: 1; vertical-align: text-top; width: auto; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; height: 21px;',
 
Line 911 ⟶ 919:
 
// input wrapper
'.wikEdInputWrapper': 'position: relative; z-index: 100; margin-top: 0.5em; clear: both;',
'.wikEdFullscreen .wikEdInputWrapper ': 'position: fixed; margin-top: 0; top: 0; left: 0; right: 0; background: #f0f0f0;',
'body.wikEdFullscreen': 'overflow: hidden;',
Line 1,262 ⟶ 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,343 ⟶ 1,354:
// copy textarea background color to wikEd edit frame
if (wikEd.config.frameBackgroundColor === undefined) { wikEd.config.frameBackgroundColor = false; }
 
// convert all   character entities to actual characters for textarea editing and saving (not recommended)
if (wikEd.config.nbspToChar === undefined) { wikEd.config.nbspToChar = false; }
 
return;
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
'zh-hansbn': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:Shibo77আফতাবুজ্জামান/wikEd_international_zhwikEd_international_bn.js', // Bengali
'zh-hanthans': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:LiflonCAS222222221/wikEd_international_zh-hant.js', // Chinese (simplified)
'cszh-hant': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:Sevela.pLiflon/wikEd_international_cswikEd_international_zh-hant.js', // Chinese (traditional)
'nlhr': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:JeronevwSpeedyGonsales/wikEd_international_nlwikEd_international_hr.js', // Croatian
'eocs': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=TlustulimuUser:Sevela.p/wikEd_international_eowikEd_international_cs.js', // Czech
'finl': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:Ejs-80Jeronevw/wikEd_international_fiwikEd_international_nl.js', // Dutch
'freo': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:LeagTlustulimu/wikEd-frwikEd_international_eo.js', // Esperanto
'glfi': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:ToliñoEjs-80/wikEd_international_glwikEd_international_fi.js', // Finnish
'defr': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:PerfektesChaosLeag/wikEd_international_dewikEd-fr.js', // French
'hegl': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:שמוליקToliño/wikEd_international_hewikEd_international_gl.js', // Galician
'hrde': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:SpeedyGonsalesPerfektesChaos/wikEd_international_hrwikEd_international_de.js', // German
'huhe': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:Tsch81שמוליק/wikEd-huwikEd_international_he.js', // Hebrew
'ithu': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:JaloTsch81/wikEd_international_itwikEd-hu.js', // Hungarian
'jait': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:HatukanezumiJalo/wikEd_international_jawikEd_international_it.js', // Italian
'kkja': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:ArystanbekHatukanezumi/wikEd_international_kkwikEd_international_ja.js', // Japanese
'kokk': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:IlovesabbathArystanbek/wikEd_international_kowikEd_international_kk.js', // Kazakh
'dsbko': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:MichalwikiIlovesabbath/wikEd_international_dsbwikEd_international_ko.js', // Korean
'msdsb': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:AviatorMichalwiki/wikEd_international_mswikEd_international_dsb.js', // Lower Sorbian
'noms': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:DvyjonesAviator/wikEd_international_nowikEd_international_ms.js', // Malay
'nnmin': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:FrokorIwan_Novirion/wikEd_international_nnwikEd_international_min.js', // Minangkabau
'fann': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:Reza1615Frokor/wikEd_international_fawikEd_international_nn.js', // New Norwegian
'plno': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:KonradekDvyjones/wikEd_international_plwikEd_international_no.js', // Norwegian
'ptfa': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:He7d3rReza1615/Tools/wikEd_international_ptwikEd_international_fa.js', // Persian (Farsi)
'ropl': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:RoamataaKonradek/wikEd_international_rowikEd_international_pl.js', // Polish
'rupt': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:IGWHe7d3r/wikEd_international_ruTools/wikEd_international_pt.js', // Portuguese
'scnro': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:MeloscnRoamataa/wikEd_international_scnwikEd_international_ro.js', // Romanian
'skru': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:Helix84IGW/wikEd_international_skwikEd_international_ru.js', // Russian
'slscn': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:EleassarMeloscn/wikEd_international_slwikEd_international_scn.js', // Sicilian
'essk': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:AxeleiHelix84/wikEd_international_eswikEd_international_sk.js', // Slovak
'svsl': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:Where_next_Columbus?Eleassar/wikEd_international_svwikEd_international_sl.js', // Slovenian
'tres': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:Vito_GenoveseDoblecaña/wikEd_international_trwikEd_international_es.js', // Spanish
'hsbsv': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:MichalwikiWhere_next_Columbus?/wikEd_international_hsbwikEd_international_sv.js', // Swedish
'vitr': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:VinhtantranVito_Genovese/wikEd_international_viwikEd_international_tr.js', // Turkish
'hsb': wikEd.config.homeBaseUrl + 'w/index.php?action=raw&ctype=text/javascript&title=User:Michalwiki/wikEd_international_hsb.js', // Upper Sorbian
'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,436 ⟶ 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-namespacesassociated-pages', 'p-cactions'] ],
 
// citizendium.org
Line 1,496 ⟶ 1,513:
wikEd.editSection = null;
 
// beta toolbar, CodeEditor, CodeMirror
wikEd.useBetaToolbar = false;
wikEd.useCodeEditor = false;
wikEd.codeEditorButtonPollCount = 0;
wikEd.useCodeMirror = false;
 
// history
Line 1,518 ⟶ 1,536:
wikEd.logo = null;
wikEd.logoList = null;
wikEd.bodyContent = null;
wikEd.debug = null;
wikEd.wikiEditor = null;
Line 1,636 ⟶ 1,653:
wikEd.frameScrollTop = null;
wikEd.textareaUpdated = true;
wikEd.previewIsAjax = null;
wikEd.buttonKeyCode = [];
wikEd.direction = null;
Line 1,767 ⟶ 1,785:
if (wikEd.browserFlavor === undefined) { wikEd.browserFlavor = ''; }
if (wikEd.browserVersion === undefined) { wikEd.browserVersion = 0; }
if (wikEd.browserVersionStr === undefined) { wikEd.browserVersionStr = ''; }
if (wikEd.msie === undefined) { wikEd.msie = false; }
if (wikEd.mozilla === undefined) { wikEd.mozilla = false; }
Line 1,897 ⟶ 1,916:
 
// redirect WED shortcut to wikEd.Debug(objectName, object, popup)
window.WED = wikEd.Debug;
 
// extract version info from wikEd.Meta()
Line 1,979 ⟶ 1,998:
// check for Google Chrome (AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.30 Safari/525.13)
else {
regExpMatchAgent = window.navigator.userAgent.match(/\b(Chrome)\W+(\d+\.\d+)(\S+)/i);
if (regExpMatchAgent !== null) {
wikEd.browserName = 'Chrome';
wikEd.browserVersion = parseFloat(regExpMatchAgent[2]);
wikEd.browserVersionStr = regExpMatchAgent[ 2 ] + regExpMatchAgent[ 3 ];
wikEd.chrome = true;
}
Line 2,039 ⟶ 2,059:
 
// parse global-context (MediaWiki) variables into hash (for Greasemonkey)
var globalNames = ['skin', 'wgServer', 'wgTitle', 'wgCanonicalNamespace', 'wgArticlePath', 'wgScript', 'wgScriptPath', 'wgUserName', 'wgCurRevisionId', 'wgContentLanguage', 'wgUserLanguage', 'wgEnableAPI', 'wgPageName', 'wgNamespaceIds', 'wgFormattedNamespaces', 'wgUseAutomaticEditSummaries', 'wgVersion', 'wgPageContentModel'];
if (wikEd.greasemonkey === true) {
globalNames.push('wikEdConfig', 'wikEdText');
Line 2,448 ⟶ 2,468:
if (wikEd.browserVersion < 0.2) {
wikEd.browserNotSupported = true;
}
 
// Chrome bug https://code.google.com/p/chromium/issues/detail?id=528382, version 45.0.2454.85 - 45.0.2454.93
else if (wikEd.browserVersion == 45) {
var regExpMatch = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/.exec( wikEd.browserVersionStr );
if ( ( regExpMatch !== null ) && ( regExpMatch[ 3 ] == 2454 ) && ( regExpMatch[ 4 ] >= 85 ) && ( regExpMatch[ 4 ] < 93 ) ) {
wikEd.browserNotSupported = true;
}
}
break;
Line 2,618 ⟶ 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 2,635 ⟶ 2,663:
if (
section !== null &&
section.length > 0 &&
/^\d+$/.test(section[0].value) === true
) {
wikEd.editSection = section[0].value;
Line 3,496 ⟶ 3,525:
if (wikEd.fixRegExTypo !== null) {
wikEd.fixRegExTypo.style.display = 'none';
}
 
// hide buttons if API is not available
if ( (wikEd.wikiGlobals.wgEnableAPI !== true) && (wikEd.wikiGlobals.wgEnableAPI != 'true') ) {
var fixRedirect = document.getElementById('wikEdFixRedirect');
if (fixRedirect !== null) {
fixRedirect.style.display = 'none';
}
}
 
Line 3,816 ⟶ 3,837:
}
 
// hook wikEd into the enhanced new edit toolbar, not Greasemonkey compatible
if (typeof jQuery == 'function') {
// hook wikEd into the enhanced new edit toolbar, not Greasemonkey compatible
jQuery('#wpTextbox1').bind('encapsulateSelection', function (e, before, inside, after) {
if (wikEd.useWikEd === true) {
Line 3,823 ⟶ 3,844:
}
});
 
// allow other code to cause us to update the textarea via textSelection( 'getContents' )
try {
$( '#wpTextbox1' ).textSelection(
'register',
{
getContents: function () {
if ( wikEd && wikEd.useWikEd ) {
wikEd.UpdateTextarea();
}
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,937 ⟶ 3,977:
wikEd.frameHtml = wikEd.frameDocument.documentElement;
wikEd.frameBody = wikEd.frameDocument.body;
if (!wikEd.frameBody) {
return;
}
 
// set frame body properties
Line 4,051 ⟶ 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...
// wait for landing patch: https://gerrit.wikimedia.org/r/#/c/130068/
// 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;
if( (window.mw.user.options.get('usecodeeditor')loader !== 1undefined ) {&&
( window.mw.loader.using !== undefined )
wikEd.useCodeEditor = true;
) {
window.mw.loader.using( 'user.options' ).then(
function() {
if (
( ( wikEd.jsPage === true ) || ( wikEd.cssPage === true) ) &&
(window.mw.user.options.get( 'usebetatoolbar' ) == 1 )
) {
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,029 ⟶ 5,089:
wikEd.PastePoll = function () {
 
if (!wikEd.paste === null) {
return;
}
Line 5,174 ⟶ 5,234:
 
// vertical pos
if (rect && rect.bottom + barHeight <= parseInt(wikEd.frameHeight)) {
wikEd.buttonBarPasted.style.top = rect.bottom + 'px';
}
Line 7,801 ⟶ 7,861:
// textify, not changing obj.html
wikEd.Textify(obj.changed);
obj.changed.plain = obj.changed.plain.replace(/\xa0/g, ' ');
wikEd.paste.last = 'textify';
 
Line 7,807 ⟶ 7,868:
wikEd.WikifyHTML(obj.changed, false);
obj.changed.html = obj.changed.html.replace(/\s*<br\b[^>]*>\s*/g, '\n');
obj.changed.html = obj.changed.html.replace(/\xa0/g, ' ');
 
// move content before br after paste at end of line, part 2
Line 8,309 ⟶ 8,371:
// highlight the syntax
obj.html = obj.changed.plain;
obj.html = obj.html.replace(/(\xa0)/g, '<span class="wikEdNbSpace">$1</span><!--wikEdNbSpace-->');
 
if (highlightSyntax === true) {
if (obj.changed.from == 'whole') {
Line 8,321 ⟶ 8,381:
// at least highlight tab characters
else {
obj.html = obj.html.replace(/(\xa0)/g, '<span class="wikEdNbSpace">$1</span><!--wikEdNbSpace-->');
obj.html = obj.html.replace(/(\t)/g, '<span class="wikEdTabPlain">$1</span><!--wikEdTabPlain-->');
}
Line 8,490 ⟶ 8,549:
wikEd.previewDiff.style.display = 'none';
wikEd.localPrevWrapper.style.display = 'block';
 
// load MathJax js
if ( window.MathJax === undefined ) {
if ( wikEd.loader === true ) {
 
// prevent error if module is not installed
try {
window.mw.loader.using( 'ext.math.mathjax.enabler', function () {
window.$( '.wikEdPreviewArticle' ).renderTeX();
} );
}
catch ( exception ) {
}
}
}
 
// prepare ajax preview
wikEd.previewIsAjax = false;
var bodyData = wikEd.textarea.value;
if ( wikEd.config.useAjaxPreview === true ) {
Line 8,548 ⟶ 8,623:
// check for named references defined outside edited section
if (
true
wikEd.wikiGlobals.wgEnableAPI === true ||
wikEd.wikiGlobals.wgEnableAPI === 'true'
) {
 
Line 8,596 ⟶ 8,670:
}
 
// GeSHi syntax highlighting support, forCSS legacyis installationsonly provided dynamically and Greasemonkeynot for Live preview
// CSS is only provided dynamically and not for Live preview
// request a full preview and attach CSS to page, remember already loaded languages
var regExp = /<(syntaxhighlight|source)\b[^>]*?lang\s*=\s*("|')(\w+)\2/gi;
if ( wikEd.loader === false ) {
var regExpMatch;
var regExp = /<(syntaxhighlight|source)\b[^>]*?lang\s*=\s*("|')(\w+)\2/gi;
varwhile ( (regExpMatch; = regExp.exec(bodyData)) !== null) {
var lang = regExpMatch[3];
while ( (regExpMatch = regExp.exec(bodyData)) !== null) {
if (wikEd.syntaxHighlightTagCSS['wikEd' + lang] === undefined) {
var lang = regExpMatch[3];
livePreview = false;
if (wikEd.syntaxHighlightTagCSS['wikEd' + lang] === undefined) {
wikEd.syntaxHighlightTagCSS['wikEd' + lang] = true;
livePreview = false;
break;
wikEd.syntaxHighlightTagCSS['wikEd' + lang] = true;
break;
}
}
}
Line 8,614 ⟶ 8,685:
// make the AJAX request
wikEd.AjaxPreview( bodyData, wikEd.LocalPreviewAjaxHandler, livePreview );
}
return;
};
 
 
 
//
// wikEd.AjaxPreview: get rendered page text using an Ajax non-API POST call
//
 
wikEd.AjaxPreview = function (textValue, ResponseHandler, livePreview, format ) {
 
// get format, json preferred for module updates and summary parsing
if ( format === undefined ) {
format = 'json';
}
if ( format === 'json' && typeof JSON !== 'object' ) {
format = 'xml';
}
 
// API request
if ( ( wikEd.wikiGlobals.wgEnableAPI === true || wikEd.wikiGlobals.wgEnableAPI === 'true' ) && livePreview === true ) {
 
// get summary
var summary = '';
if (wikEd.summaryText !== null) {
summary = wikEd.summaryText.value;
}
 
// set request parameters
var postFields = {
'format': format,
'action': 'parse',
'prop': 'text|modules',
'disablepp': '1',
'pst': '1',
'title': wikEd.pageName,
'text': textValue,
'summary': summary
};
var requestUrl = wikEd.scriptURL + 'api.php';
 
// AJAX API request
wikEd.AjaxRequest( 'POST', requestUrl, postFields, 'text/plain', ResponseHandler );
}
 
// legacy support: non-API request, use Live preview if possible
else {
 
// prepare the url
var requestUrl;
if ( wikEd.editForm !== null && wikEd.editUpload !== true && wikEd.editWatchlist !== true && wikEd.viewDeleted !== true ) {
requestUrl = wikEd.editForm.action.replace( /\?.*()/, '' );
if ( /:\/\/()/.test(requestUrl) === false ) {
requestUrl = window.___location.protocol + '//' + window.___location.host + requestUrl;
}
}
else if ( wikEd.wikiGlobals.wgScriptPath !== undefined ) {
requestUrl = wikEd.wikiGlobals.wgScriptPath + '/index.php';
}
else {
requestUrl = window.___location.href;
requestUrl = requestUrl.replace( /\?.*()/, '' );
requestUrl = requestUrl.replace( /\/[\w\.]*$/, '/index.php' );
}
 
// prepare the form fields
var postFields = {};
if ( wikEd.pageName !== null && wikEd.wikiGlobals.wgCanonicalNamespace != 'Special' ) {
postFields['title'] = wikEd.pageName;
}
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) {
postFields['live'] = 'true';
}
 
// AJAX non-API request
wikEd.AjaxRequest( 'POST', requestUrl, postFields, 'text/plain', ResponseHandler );
}
return;
Line 8,720 ⟶ 8,696:
wikEd.LocalPreviewAjaxHandler = function ( ajax ) {
 
wikEd.previewIsAjax = true;
// get preview html
var html = '';
 
// jsonget API reponseresponse
ifvar (html = ajax.responseText.indexOf( '{' ) === 0 ) {;
var responseObj = JSON.parse( ajax.responseText );
if ( responseObj.parse !== undefined ) {
var parse = responseObj.parse;
html = parse.text['*'];
 
// load module js and css
if ( wikEd.loader === true && parse.modules !== undefined ) {
var modules = parse.modules.concat(
parse.modulescripts, parse.modulestyles, parse.modulemessages
);
window.mw.loader.load( modules );
}
 
// add heading to new section
if ( parse.parsedsummary !== undefined && wikEd.editSection === 'new') {
html = '<h2>' + parse.parsedsummary['*'] + '</h2>' + html;
}
}
}
 
// xml API reponse
else if ( ajax.responseTexthtml.indexOf( '<api>' ) !== -1 ) {
html = wikEd.StringGetInnerHTML( ajax.responseTexthtml, 'text', '' )
.replace( /&lt;/g, '<' )
.replace( /&gt;/g, '>' )
Line 8,754 ⟶ 8,710:
}
 
// non-API livepreview (https://www.mediawiki.org/wiki/Manual:Live_preview)
else if ( ajax.responseTexthtml.indexOf( '<livepreview>' ) != -1 ) {
html = wikEd.StringGetInnerHTML( ajax.responseTexthtml, 'preview', '' )
.replace( /&lt;/g, '<' )
.replace( /&gt;/g, '>' )
Line 8,768 ⟶ 8,724:
// full preview page
else {
html = ajax.responseText;
 
// attach <style> stylesheet declarations to document (<source>, <syntaxhighlight>)
var regExpMatch;
var regExp = /<()style\b[^>]*?type="text\/css">((.|\n)*?)<\/style>/gi;
Line 8,804 ⟶ 8,759:
);
wikEd.previewArticle.innerHTML = html;
 
// apply dynamic changes to preview
 
// init sortable tables (wikibits.js)
if ( typeof window.sortables_init === 'function' ) {
window.sortables_init();
}
 
// init collapsible tables (common.js)
if ( typeof window.createCollapseButtons === 'function' ) {
window.createCollapseButtons();
}
 
// collapsible divs (common.js on ru)
if (typeof window.collapsibleDivs === 'function' ) {
window.collapsibleDivs();
}
 
// collapsible tables (common.js on ru)
if (typeof window.collapsibleTables === 'function' ) {
window.collapsibleTables();
}
 
// load MathJax modules and render math elements
if ( wikEd.loader === true ) {
if ( $( '.tex' ).length > 0 && window.mw.user.options.get( 'math' ) === '6' ) {
window.mw.loader.using( 'ext.math.mathjax.enabler', function () {
$( '#wikiPreview' ).renderTex();
} );
}
}
 
// load media player modules and activate media elements, see https://bugzilla.wikimedia.org/show_bug.cgi?id=72675
if ( wikEd.loader === true ) {
window.mw.loader.load( ['mw.MwEmbedSupport', 'mw.EmbedPlayer', 'mw.PopUpMediaTransform'] );
}
 
Line 8,895 ⟶ 8,824:
 
wikEd.GetArticleTextAjaxHandler = function ( ajax ) {
 
wikEd.previewIsAjax = true;
 
// get response
Line 8,955 ⟶ 8,886:
//
 
wikEd.FilePreviewAjaxHandler = function ( ajax ) {
 
// get response
Line 8,971 ⟶ 8,902:
 
// parse response into file url cache
var regExpFile = new RegExp( '\\n((Image|File|Media|' + wikEd.config.text[ 'wikicode Image' ] + '|' + wikEd.config.text[ 'wikicode File' ] + '|' + wikEd.config.text[ 'wikicode Media' ] + '):[^ ]+) +(\\d+) +(.*)', 'ig' );
var regExpMatch;
while ( ( regExpMatch = regExpFile.exec( html ) ) !== null ) {
 
var file = regExpMatch[1];
var filePreviewSize = regExpMatch[3];
var links = regExpMatch[4];
 
var fileObj = {};
var cacheKey = 'wikEd' + file + filePreviewSize;
var regExpMatch;
if ( ( regExpMatch = /\bsrc="(.+?)"/.exec( links ) ) !== null ) {
wikEd.filePreviewCache[ cacheKey ] = {};
var fileObj = wikEd.filePreviewCache[ cacheKey ];
fileObj.url = regExpMatch[1];
if ( ( regExpMatch = /\bwidth="(\d+)"/.exec(links)) !== null ) {
fileObj.width = parseInt(regExpMatch[ 1 ] );
}
if ( ( regExpMatch = /\bheight="(\d+)"/.exec( links ) ) !== null ) {
fileObj.height = parseInt( regExpMatch[ 1 ] );
}
}
else if ( wikEd.filePreviewCache[ cacheKey ] === undefined ) {
else {
fileObj.url = wikEd.config.imagefilePreviewCache['noFile' cacheKey ] = {};
var fileObj = wikEd.filePreviewCache[ cacheKey ];
fileObj.url = wikEd.config.image[ 'noFile' ];
fileObj.width = 16;
fileObj.height = 16;
}
wikEd.filePreviewCache['wikEd' + file + filePreviewSize] = fileObj;
}
 
// cycle through file preview spans and add missing images as background
for ( var i = 0; i < wikEd.filePreviewNo; i ++ ) {
if ( wikEd.filePreviewIds[ i ] !== '' ) {
var span = wikEd.frameDocument.getElementById( 'wikEdFilePreview' + i );
if ( span !== null ) {
var fileNameSizecacheKey = 'wikEd' + wikEd.filePreviewIds[ i ];
var fileObj = wikEd.filePreviewCache['wikEd' +cacheKey fileNameSize];
if ( fileObj !== undefined ) {
span.style.backgroundImage = 'url(' + fileObj.url + ')';
if ( fileObj.height !== null ) {
span.style.height = fileObj.height + 'px';
}
if ( fileObj.width !== null ) {
span.style.width = fileObj.width + 'px';
}
span.style.display = 'block';
}
wikEd.filePreviewIds[ i ] = '';
}
}
Line 9,822 ⟶ 9,758:
obj.whole.code = obj.whole.html;
wikEd.RemoveHighlightingWikify(obj.whole, wikify);
wikEd.HtmlToPlain(obj.whole);
}
}
Line 9,844 ⟶ 9,781:
obj.selection.code = obj.selection.html;
wikEd.RemoveHighlightingWikify(obj.selection, wikify);
wikEd.HtmlToPlain(obj.selection);
}
}
Line 9,878 ⟶ 9,816:
obj.focusWord.code = obj.focusWord.html;
wikEd.RemoveHighlightingWikify(obj.focusWord, wikify);
wikEd.HtmlToPlain(obj.focusWord);
 
// get the wikified plain text for the line under the cursor
Line 9,884 ⟶ 9,823:
obj.focusLine.code = obj.focusLine.html;
wikEd.RemoveHighlightingWikify(obj.focusLine, wikify);
wikEd.HtmlToPlain(obj.focusLine);
 
// get the wikified plain text for the paragraph under the cursor
Line 9,890 ⟶ 9,830:
obj.focusPara.code = obj.focusPara.html;
wikEd.RemoveHighlightingWikify(obj.focusPara, wikify);
wikEd.HtmlToPlain(obj.focusPara);
}
}
Line 9,926 ⟶ 9,867:
obj.selectionWord.code = obj.selectionWord.html;
wikEd.RemoveHighlightingWikify(obj.selectionWord, wikify);
wikEd.HtmlToPlain(obj.selectionWord);
 
// get the wikified plain text for the lines under the selection
Line 9,932 ⟶ 9,874:
obj.selectionLine.code = obj.selectionLine.html;
wikEd.RemoveHighlightingWikify(obj.selectionLine, wikify);
wikEd.HtmlToPlain(obj.selectionLine);
 
// get the wikified plain text for the paragraph under the selection
Line 9,938 ⟶ 9,881:
obj.selectionPara.code = obj.selectionPara.html;
wikEd.RemoveHighlightingWikify(obj.selectionPara, wikify);
wikEd.HtmlToPlain(obj.selectionPara);
}
}
Line 9,995 ⟶ 9,939:
if (useRegExp !== true) {
 
// parameters: window.find(string, caseSensitive, backwards, wrapAround, wholeWord, searchInFrames, showDialog)
found = wikEd.frameWindow.find(findText, caseSensitive, backwards, wrap, false, true, false);
if (found === true) {
Line 10,406 ⟶ 10,350:
obj.plain = obj.plain.replace(/<\/?(table|caption)\b[^>]*>/g, '\x00');
obj.plain = obj.plain.replace(/<\/(tr|th|td)>/g, '\x00');
 
// nbsp
obj.plain = obj.plain.replace(/<span\b[^>]*?\bclass="wikEdNbSpace"[^>]*>((.|\n)*?)<\/span>(<!--wikEdNbSpace-->)?/gi,
function(p, p1, p2) {
p1 = p1.replace(/ /g, '\xa0');
return p1;
}
);
 
// finish html to plain conversion
Line 10,507 ⟶ 10,443:
}
);
 
// non-breaking space character to normal space
obj.plain = obj.plain.replace(/\xa0/g, ' ');
 
// tab to space
Line 10,833 ⟶ 10,772:
 
// check if api is enabled
if ( ( (wikEd.wikiGlobals.wgEnableAPI !== true) && (wikEd.wikiGlobals.wgEnableAPI != 'true') ) || (wikEd.scriptURL === '') ) {
return;
}
Line 11,459 ⟶ 11,398:
);
obj.html = obj.html.replace(/\n/g, '<br>');
 
// trailing, leading, and multi spaces to nbsp
obj.html = obj.html.replace(/^ | $/gm, '\xa0');
obj.html = obj.html.replace(/(\n|\xa0 | ) /g, '$1\xa0');
 
// preserve double spaces after dot
Line 11,934 ⟶ 11,869:
}
}
obj.plain = obj.html;
obj.plain = obj.plain.replace(/<br\b[^>]*>/g, '\n');
 
return;
};
Line 11,944 ⟶ 11,876:
// wikEd.WikifyHTML:
// obj.html contains the text to be wikified
// expects < > &lt; &gt; &amp; spaces instead of &nbsp; <br> (not \n)
// returns <br> (not \n)
// wikiCode === true: allow extended set of attributes for existing wikicode, keep leading spaces
Line 12,279 ⟶ 12,211:
else if ( (hrefParamTitle !== null) && (hrefParamSpecial !== true) ) {
linkArticle = hrefParamTitle;
linkArticle = linkArticle && linkArticle.replace(/_/g, ' ');
linkArticle = decodeURIComponent(linkArticle);
}
Line 12,286 ⟶ 12,218:
else if (hrefUrlArticle !== null) {
linkArticle = hrefUrlArticle;
linkArticle = linkArticle && linkArticle.replace(/_/g, ' ');
linkArticle = decodeURIComponent(linkArticle);
}
Line 12,301 ⟶ 12,233:
 
// format wiki link
if (linkArticle && linkArticle !== '') {
 
// check for wiki image
Line 13,081 ⟶ 13,013:
obj.html = obj.html.replace(/(&lt;(syntaxhighlight|source|pre)\b[^\/]*?&gt;)((.|\n)*?)(&lt;\/\2&gt;)/gi,
function(p, p1, p2, p3, p4, p5) {
p3 = p3.replace(/ /g, '\x02xa0');
p3 = p3.replace(/\n/g, '\x00');
return p1 + p3 + p5;
Line 13,087 ⟶ 13,019:
);
 
// preserve spaces and content in pre, syntaxhighlight, source, and nowiki
// multiple spaces (blank/nbsp/blank/nbsp/...)
obj.htmlplain = obj.htmlplain.replace(/(&lt;(syntaxhighlight|source|pre|nowiki)\b[^\n /]{*?&gt;)((.|\n)*?)(&lt;\/\2,}&gt;)/ggi, ' ');
function(p, p1, p2, p3, p4, p5) {
obj.html = obj.html.replace(/ \xa0/g, ' \x02');
obj.html p3 = obj.htmlp3.replace(/([\xa0 [\]{}=*#:;|&])/g, '\x02 x00$1\x00');
if (/^(syntaxhighlight|source|pre)$/i.test(p2) === true) {
 
p3 = p3.replace(/ /g, '\x01');
// nbsp
p3 = p3.replace(/\n/g, '\x02');
obj.html = obj.html.replace(/<span\b[^>]*?\bclass="wikEdNbSpace"[^>]*>((.|\n)*?)<\/span>(<!--wikEdNbSpace-->)?/gi,
}
function(p, p1, p2) {
return p1 =+ p1.replace(/p3 /g,+ '\xa0')p5;
return p1;
}
);
Line 13,102 ⟶ 13,033:
// remove highlighting error messages
if (wikEd.config.highlightError === true) {
obj.html = obj.html.replace(/<span\b[^>]*?\bclass="wikEdHighlightError"[^>]*>(.|\n)*?<\/span>(<!--wikEdHighlightError-->)?/g, '');
}
 
Line 13,124 ⟶ 13,055:
var isRemove = [];
 
// 12 2 3 3 4 4 5 5 1
obj.html = obj.html.replace(/(([\x00\x01]\s*)?<(\/?)div\b([^>]*)>(\s*[\x00\x01])?)/g,
function(p, p1, p2, p3, p4, p5) {
if (p3 === '') {
Line 13,145 ⟶ 13,076:
}
);
obj.html = obj.html.replace(/[\x00\x01]/g, '');
 
// preserve spaces and newlines in pre tag
obj.html = obj.html.replace(/(<pre\b[^>]*>)((.|\n)*?)(<\/pre>)/g,
function(p, p1, p2, p3, p4) {
p2 = p2.replace(/ /g, '\x02xa0');
p2 = p2.replace(/\n/g, '\x00');
 
return p1 + p2 + p4;
}
Line 13,162 ⟶ 13,094:
// non-breaking spaces
obj.html = obj.html.replace(/&nbsp;/g, '\xa0');
 
// preserved spaces
obj.html = obj.html.replace(/\x02/g, ' ');
 
// check for pasted html content
Line 16,493 ⟶ 16,422:
else {
wikEd.CleanNodes(wikEd.frameDocument);
obj.htmlif =( wikEd.frameBody.innerHTML; ) {
obj.html = wikEd.frameBody.innerHTML;
} else {
return;
}
 
}
 
Line 16,501 ⟶ 16,435:
// remove leading spaces in lines
obj.html = obj.html.replace(/(<br\b[^>]*>)[\n\r]* *()/g, '$1');
 
// nbsp to spaces
obj.html = obj.html.replace(/&nbsp;|&#160;|\xa0/g, ' ');
 
// textify so that no html formatting is submitted
wikEd.Textify(obj);
obj.plain = obj.plain.replace(/&nbsp;|&#160;|\xa0/g, ' ');
obj.plain = obj.plain.replace(/&lt;/g, '<');
obj.plain = obj.plain.replace(/&gt;/g, '>');
obj.plain = obj.plain.replace(/&amp;/g, '&');
 
// convert all &nbsp; char entitities to actual characters (customization option only)
if (wikEd.config.nbspToChar === true) {
obj.plain = obj.plain.replace(/&nbsp;/g, '\xa0');
}
 
// copy to textarea
Line 16,536 ⟶ 16,473:
obj.html = wikEd.EscapeHtml(obj.html);
 
// preserveconvert \xa0xa (nbsp) charactersto character entities so they do not get converted to blanks
if (wikEd.config.convertNbspToEntities === true) {
obj.html = obj.html.replace(/(\xa0)/g, '<span class="wikEdNbSpace">$1</span><!--wikEdNbSpace-->');
obj.html = obj.html.replace(/\xa0/g, '&amp;nbsp;');
}
}
 
Line 16,546 ⟶ 16,485:
}
 
// at least display tabs and nbsp;
else {
obj.html = obj.html.replace(/(\xa0)/g, '<span class="wikEdNbSpace">$1</span><!--wikEdNbSpace-->');
obj.html = obj.html.replace(/(\t)/g, '<span class="wikEdTabPlain">$1</span><!--wikEdTabPlain-->');
}
Line 16,608 ⟶ 16,546:
wikEd.LinkInfoCall();
}
return;
};
 
 
//
// wikEd.HtmlToPlain: convert html to plain text, called from wikEd.GetText
//
 
wikEd.HtmlToPlain = function (obj) {
 
obj.plain = obj.html.replace(/[\n ]{2,}/g, ' ');
obj.plain = obj.plain.replace(/<br\b[^>]*>/g, '\n');
obj.plain = obj.plain.replace(/\xa0/g, ' ');
 
return;
};
Line 16,876 ⟶ 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,895 ⟶ 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,935 ⟶ 16,887:
// disable wikEd
else {
wikEd.SetPersistent( 'wikEdDisabled', '1', 0, '/' );
if ( wikEd.turnedOn === false ) {
wikEd.useWikEd = false;
window.wikEdUseWikEd = wikEd.useWikEd;
Line 16,945 ⟶ 16,897:
 
// interrupt fullscreen mode
if ( wikEd.fullscreen === true ) {
wikEd.FullScreen( false );
}
 
// turn classic textarea on
if ( wikEd.useWikEd === true ) {
wikEd.UpdateTextarea();
}
Line 16,956 ⟶ 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,972 ⟶ 16,924:
wikEd.localPrevWrapper.style.height = 'auto';
 
if ( wikEd.buttonBarJump !== null ) {
wikEd.buttonBarJump.style.display = 'none';
}
Line 16,982 ⟶ 16,934:
 
// run scheduled custom functions
wikEd.ExecuteHook( wikEd.config.offHook );
}
}
Line 17,580 ⟶ 17,532:
//
 
wikEd.GetPersistent = function ( name ) {
 
var getStr;
Line 17,588 ⟶ 17,540:
 
// get a value from web storage
if ( wikEd.webStorage === true ) {
try {
getStr = window.localStorage.getItem(name);
getStr = window.localStorage.getItem( name );
}
catch ( exception ) {
wikEd.webStorage = false;
}
}
if ( wikEd.webStorage === false ) {
 
// else get a Greasemonkey persistent value
else if ( wikEd.greasemonkey === true ) {
getStr = GM_getValue( name, '' );
}
 
// else get a cookie value
else {
getStr = wikEd.GetCookie( name );
}
}
 
// return string
if ( typeof getStr != 'string' ) {
getStr = '';
}
Line 17,614 ⟶ 17,573:
//
 
wikEd.SetPersistent = function ( name, value, expires, path, ___domain, secure ) {
 
// check for web storage
Line 17,620 ⟶ 17,579:
 
// set a value in web storage
if ( wikEd.webStorage === true ) {
if ( expires == -1 ) {
value = '';
}
try {
window.localStorage.setItem(name, value);
window.localStorage.setItem( name, value );
}
catch ( exception ) {
wikEd.webStorage = false;
}
}
if ( wikEd.webStorage === false ) {
 
// else set a Greasemonkey persistent value
else if ( wikEd.greasemonkey === true ) {
if ( expires == -1 ) {
value = '';
}
 
// see http://wiki.greasespot.net/Greasemonkey_access_violation
window.setTimeout( function() {
GM_setValue( name, value );
}, 0 );
}
 
// else set a cookie value
// see http://wiki.greasespot.net/Greasemonkey_access_violation
else {
window.setTimeout(function() {
GM_setValuewikEd.SetCookie( name, value, expires, path, ___domain, secure );
}, 0);
}
 
// set a cookie value
else {
wikEd.SetCookie(name, value, expires, path, ___domain, secure);
}
return;
Line 17,844 ⟶ 17,810:
wikEd.ParseDOMRecursive(obj, topNode, anchorNode, anchorOffset, focusNode, focusOffset);
obj.plain = obj.plainArray.join('');
obj.plain = obj.plain.replace(/\xa0/g, ' ');
// nbsp to spaces in multiple spaces
obj.plain = obj.plain.replace(/\xa0 /g, ' ');
obj.plain = obj.plain.replace(/ \xa0/g, ' ');
obj.plain = obj.plain.replace(/^\xa0|\xa0$/gm, ' ');
return;
};
Line 18,209 ⟶ 18,171:
}
return style;
};
 
 
//
// wikEd.AjaxPreview: get rendered page text using an Ajax non-API POST call
//
 
wikEd.AjaxPreview = function (textValue, ResponseHandler, livePreview) {
 
// API request
if ( ( livePreview === true ) ) {
var postFields = {
'format': 'xml',
'action': 'parse',
'pst': '1',
'title': wikEd.pageName,
'text': textValue
};
var requestUrl = wikEd.scriptURL + 'api.php';
 
// AJAX API request
wikEd.AjaxRequest( 'POST', requestUrl, postFields, 'text/plain', ResponseHandler );
}
 
// legacy support: non-API request, use Live preview if possible
else {
 
// prepare the url
var requestUrl;
if ( wikEd.editForm !== null && wikEd.editUpload !== true && wikEd.editWatchlist !== true && wikEd.viewDeleted !== true ) {
requestUrl = wikEd.editForm.action.replace( /\?.*()/, '' );
if ( /:\/\/()/.test(requestUrl) === false ) {
requestUrl = window.___location.protocol + '//' + window.___location.host + requestUrl;
}
}
else if ( wikEd.wikiGlobals.wgScriptPath !== undefined ) {
requestUrl = wikEd.wikiGlobals.wgScriptPath + '/index.php';
}
else {
requestUrl = window.___location.href;
requestUrl = requestUrl.replace( /\?.*()/, '' );
requestUrl = requestUrl.replace( /\/[\w\.]*$/, '/index.php' );
}
 
// prepare the form fields
var postFields = {};
if ( wikEd.pageName !== null && wikEd.wikiGlobals.wgCanonicalNamespace != 'Special' ) {
postFields['title'] = wikEd.pageName;
}
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';
 
// keep for backward compatibility
if ( livePreview !== false ) {
postFields[ 'live' ] = 'true';
}
 
// AJAX non-API request
wikEd.AjaxRequest( 'POST', requestUrl, postFields, 'text/plain', ResponseHandler );
}
return;
};
 
Line 18,330 ⟶ 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.config !== undefined ) ) {
globalScopeCode += '' +
'ifglobalScopeCode (typeof+= 'wikEd.wikiGlobals.' + names[ i ] + ' != \mw.config.get("'undefined\ + names[ i ] + '"); {' +;
}
' wikEd.wikiGlobals.' + names[i] + ' = ' + names[i] + ';' +
'}';else {
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,365 ⟶ 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,379 ⟶ 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,388 ⟶ 18,429:
script.textContent = globalScopeCode;
}
wikEd.head.appendChild( script );
return;
};
Line 18,566 ⟶ 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,584 ⟶ 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,645 ⟶ 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,677 ⟶ 18,718:
 
// undefined
else if ( object === undefined ) {
value = '';
}
Line 18,688 ⟶ 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,707 ⟶ 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,716 ⟶ 18,757:
 
// use popup alert
else if ( usePopup === true ) {
if ( object === null ) {
window.alert( objectName );
}
else {
window.alert( objectName + ': ' + value );
}
}
Line 18,728 ⟶ 18,769:
else {
var msg;
if ( object === null ) {
msg = objectName;
}
Line 18,734 ⟶ 18,775:
msg = objectName + ' ' + value;
}
wikEd.ConsoleLog( msg );
}
return;