In today's world, Wikipedia:WikiProject User scripts/Scripts/livepreview.js is a topic that has captured the attention of many people. Whether due to its relevance in today's society, its impact on people's daily lives, or its importance in history, Wikipedia:WikiProject User scripts/Scripts/livepreview.js is a topic that deserves to be explored in depth. Through this article, we will dive into the different facets that Wikipedia:WikiProject User scripts/Scripts/livepreview.js encompasses, from its origin to its implications in the modern world. We will discover how Wikipedia:WikiProject User scripts/Scripts/livepreview.js has evolved over time and how it continues to influence our lives today. Without a doubt, Wikipedia:WikiProject User scripts/Scripts/livepreview.js is a topic that continues to generate interest and reflection, and through this article we hope to shed light on its importance and relevance in today's society.
// Last update: 10 Sep 2005
// by Lupin (some demunging and commenting) based on Pilaf's version of
// 21:51, 15 Feb 2005 (UTC)
// Script to embed Live Preview in MediaWiki's edit page
function LivePreviewInstall()
{
copywarn = document.getElementById('editpage-copywarn');
if (copywarn != null) {
var cleaner = "<br style=\\'clear:both;\\' />";
LivePreviewHTML = '<input type="button" value="Live Preview"'
+ ' onclick="document.getElementById(\'PreviewBox\').innerHTML = wiki2html(editform.wpTextbox1.value) + \''
+ cleaner + '\';" />';
LivePreviewHTML += '<div style="margin-top: 5px; margin-bottom: 5px;'+
' padding: 5px; border: 3px double orange;" id="PreviewBox"></div>';
copywarn.innerHTML = LivePreviewHTML + copywarn.innerHTML;
}
}
// User options
var wpUserName=wpUserName||'Wikipedian';
var wpUserSignature=wpUserSignature||wpUserName;
var wpShowImages=wpShowImages||true;
// System options
var wpLanguageCode=wpLanguageCode||'en';
var wpInterwikiCodes=wpInterwikiCodes||'ab|aa|af|ak|sq|als|am|ang|ar|an|arc|hy|roa-rup|as|ast|av|ay|az|bm|ba|eu|be|bn|bh|bi|bs|br|bg|my|ca|ch|ce|chr|chy|ny|zh|zh-tw|zh-cn|cho|cv|kw|co|cr|hr|cs|da|dv|nl|dz|en|eo|et|ee|fo|fj|fi|fr|fy|ff|gl|ka|de|got|el|kl|gn|gu|ht|ha|haw|he|hz|hi|ho|hu|is|io|ig|id|ia|ie|iu|ik|ga|it|ja|jv|kn|kr|csb|ks|kk|km|ki|rw|rn|tlh|kv|kg|ko|kj|ku|ky|lo|la|lv|li|ln|lt|jbo|nds|lg|lb|mk|mg|ms|ml|mt|gv|mi|minnan|mr|mh|zh-min-nan|mo|mn|mus|nah|na|nv|ne|se|no|nn|oc|or|om|pi|fa|pl|pt|pa|ps|qu|ro|rm|ru|sm|sg|sa|sc|gd|sr|sh|st|tn|sn|scn|simple|sd|si|sk|sl|so|st|es|su|sw|ss|sv|tl|ty|tg|ta|tt|te|th|bo|ti|tpi|to|tokipona|ts|tum|tr|tk|tw|uk|ur|ug|uz|ve|vi|vo|wa|cy|wo|xh|ii|yi|yo|za|zu';
var wpBaseArticlePath=wpBaseArticlePath||'https://wikious.com/en/';
var wpMathBasePath=wpMathBasePath||'/math/';
var wpImageBasePath=wpImageBasePath||'http://upload.wikimedia.org/wikipedia/'+wpLanguageCode+'/';
var wpImageFallbackPath=wpImageFallbackPath||'http://upload.wikimedia.org/wikipedia/commons/';
var wpDefaultThumbWidth=wpDefaultThumbWidth||180;
var wpSkinMagnifyClip=wpSkinMagnifyClip||'/skins/common/images/magnify-clip.png';
var wpUserNamespace=wpUserNamespace||'User';
var wpImageNamespace=wpImageNamespace||'Image';
var wpCategoryNamespace=wpCategoryNamespace||'Category';
// Somewhat unpacked code
function wiki2html(str) {
str=strip_cr(str);
var w=new WikiCode();
w.lines=str.split(/\n/);
w.parse();
return w.html;
};
// ]
var wpSignature=']';
// [[Image:summat|frame (must include a pipe)
var wpBlockImage=new RegExp('^\\[\\['+wpImageNamespace+
':.*?\\|.*?(?:frame|thumbnail|thumb|none|right|left|center)',
'i');
function WikiCode() {
this.lines=new Array;
this.html=new String;
this._endline=function(str) {
this.html+=str;
this.lines.shift();
};
this.parse=function() {
var p=false;
do {
if (h_match=this.lines.match(/^(={1,6})(.*)\1(.*)$/)) {
// heading: === foo === bar
// BUG: bar passes through without being dewikified
// eg === foo === ''bar''
p=false;
this._endline('<h'+h_match.length+'>'+_parse_inline_nowiki(h_match)+
'</h'+h_match.length+'>'+h_match);
} else if (this.lines.match(/^/)) {
// list element
p=false;
this._parse_list();
} else if (this.lines.charAt(0)==' ') {
// pre (indicated by leading whitespace)
p=false;
this._parse_pre();
} else if (this.lines.substr(0,2)=='{|') {
// start of wikitable
p=false;
this._parse_table();
} else if (this.lines.match(/^----+$/)) {
// hr
p=false;
this._endline('<hr/>');
} else if (this.lines.match(wpBlockImage)) {
// block image
p=false;
this._parse_block_image();
} else { /* fallthrough */
if (this.lines=='') {
// blank line
if ( p=(this.lines.length>1 && this.lines=='') ) {
// two blank lines, not at the end
this._endline('<p><br />');}
} else {
if (!p) {
this.html+='<p>';
p=true;
}
this.html+=_parse_inline_nowiki(this.lines)+' ';
}
this.lines.shift();
} /* end fallthrough */
} while (this.lines.length);
}; /* end this.parse */
this._parse_list=function() {
// called when first line matches /^/
var prev=new String;
var l_match,imatch,dt_match;
while (this.lines.length && (l_match=this.lines.match(/^(+)(.*)$/))) {
this.lines.shift();
imatch=str_imatch(prev,l_match);
for(var i=prev.length-1;i>=imatch;i--) {
if (prev.charAt(i)=='*') {
this.html+='</ul>';
} else if (prev.charAt(i)=='#') {
this.html+='</ol>';
} else {
this.html+='</d'+((prev.charAt(i)==';')?'t':'d')+'>';
switch(l_match.charAt(i)) {
case'':case'*':case'#':
this.html+='</dl>';
}
}
}
for(var i=imatch;i<l_match.length;i++) {
if (l_match.charAt(i)=='*') {
this.html+='<ul>';
} else if (l_match.charAt(i)=='#') {
this.html+='<ol>';
} else {
switch(prev.charAt(i)) {
case'':case'*':case'#':
this.html+='<dl>';
}
this.html+='<d'+((l_match.charAt(i)==';')?'t':'d')+'>';
}
}
switch(l_match.charAt(l_match.length-1)) {
case'*':case'#':
this.html+='<li>'+_parse_inline_nowiki(l_match);
break;
case';':
if (dt_match=l_match.match(/(.*?) (:.*?)$/)) {
this.html+=_parse_inline_nowiki(dt_match);
this.lines.unshift(dt_match);
break;
}
case':':
this.html+=_parse_inline_nowiki(l_match);
}
prev=l_match;
} /* while */
for(i=prev.length-1;i>=0;i--) {
if (prev.charAt(i)=='*') {
this.html+='</ul>';
} else if (prev.charAt(i)=='#') {
this.html+='</ol>';
} else {
this.html+='</d'+((prev.charAt(i)==';')?'t':'d')+'></dl>';
}
}
}; /* end this._parse_list */
this._parse_table=function() {
var table_match;
if (table_match=this.lines.match(/^\{\|( .*)$/)) {
this._endline('<table'+table_match+'>');
} else this._endline('<table>');
do {
if (this.lines.charAt(0)=='|') {
switch(this.lines.charAt(1)) {
case'}':
this._endline('</table>');
return;
case'-':
this._endline('<tr '+this.lines.match(/\|-*(.*)/)+'>');
break;
default:
this._parse_table_data();
}
} else if (this.lines.charAt(0)=='!') {
this._parse_table_data();
} else {
this.lines.shift();
}
} while (this.lines.length)
}; /* end this._parse_table */
this._parse_table_data=function() {
var td_match,td_line;
// the next line really confuses emacs c-mode indentation
td_match=this.lines.shift().match(/^(\|\+|\||!)((?:(*?)\|(?!\|))?(.*))$/);
if (td_match=='|+') {
this.html+='<caption';
} else {
this.html+='<t'+((td_match=='|')?'d':'h');
}
if (typeof td_match!='undefined') {
this.html+=' '+td_match;
td_line=td_match.split('||');
} else {
td_line=td_match.split('||');
}
this.html+='>';while(td_line.length>1) {
this.lines.unshift(td_match+td_line.pop());
}
this.html+=_parse_inline_nowiki(td_line);
var td=new WikiCode;
var table_count=0;
while(this.lines.length) {
if (this.lines.charAt(0)=='|') {
if (table_count==0) break;
else if (this.lines.charAt(1)=='}') table_count--;
} else if (this.lines.charAt(0)=='!'&&table_count==0) { break; }
else if (this.lines.substr(0,2)=='{|')
table_count++;td.lines.push(this.lines.shift());
}
if (td.lines.length) {
td.parse();
}
this.html+=td.html;
}; /* end this._parse_table_data */
this._parse_pre=function() {
this.html+='<pre>';
do {
this._endline(_parse_inline_nowiki(this.lines
.substring(1,this.lines.length))+"\n");
} while(this.lines.length&&this.lines.charAt(0)==' ');
this.html+='</pre>';
};
this._parse_block_image=function() {
this.html+=_parse_image(this.lines.shift());
};
}; /* end WikiCode constructor */
function _parse_image(str) {
var attr=str.substring(wpImageNamespace.length+3,str.length-2).split(/\s*\|\s*/);
var filename=attr;
var caption=attr;
var width,w_match;
var thumb=false;
var frame=false;
var center=false;
var align='';
var html='';
do {
if (w_match=attr.match(/^(\d*)px$/)) {
width=w_match;
} else switch(attr) {
case'thumb':case'thumbnail':
thumb=true;
case'frame':
frame=true;
break;
case'none':case'right':case'left':
center=false;
align=attr;
break;
case'center':
center=true;
align='none';
}
attr.shift();
} while (attr.length);
if (frame) {
if (align=='') align='right';
html+="<div class='thumb t"+align+"'>";
if (thumb) {
if (!width) width=wpDefaultThumbWidth;
html+="<div style='width:" + (2+parseInt(width)) + "px;'>";
html+=_make_image(filename,caption,width);
html+="<div class='thumbcaption'>"
+ "<div class='magnify' style='float:right'><a href='"
+ wpBaseArticlePath+wpImageNamespace+':'+filename
+ "' class='internal' title='Enlarge'><img src='"
+ wpSkinMagnifyClip+"' /></a></div>"+_parse_inline_nowiki(caption)
+ "</div>";
} else {
html+='<div>';
html+=_make_image(filename,caption);
html+="<div class='thumbcaption'>"+_parse_inline_nowiki(caption)+"</div>";
}
html+='</div></div>';
} else if (align!='') {
html+="<div class='float"+align+"'><span>"
+_make_image(filename,caption,width)
+"</span></div>";
} else {
return _make_image(filename,caption,width);
}
if (center) {
return"<div class='center'>"+html+'</div>';
} else {return html;}
};
this._parse_inline_nowiki=function(str) {
var start,lastend=0;
var substart=0,nestlev=0,open,close,subloop;
var html='';
while (-1!=(start=str.indexOf('<'+'nowiki>',substart))) {
html+=_parse_inline_wiki(str.substring(lastend,start));
start+=8;
substart=start;
subloop=true;
do {
open=str.indexOf('<'+'nowiki>',substart);
close=str.indexOf('</nowiki>',substart);
if (close<=open||open==-1) {
if (close==-1) {
return html+html_entities(str.substr(start));
}
substart=close+9;
if (nestlev) {
nestlev--;
} else {
lastend=substart;
html+=html_entities(str.substring(start,lastend-9));subloop=false;
}
} else {
substart=open+8;
nestlev++;
}
} while(subloop);
}
return html+_parse_inline_wiki(str.substr(lastend));
};
function _make_image(filename,caption,width) {
filename=filename.charAt(0).toUpperCase()+filename.substr(1);
filename=filename.replace(/ /g,'_');
var md5=hex_md5(filename);
var source=md5.charAt(0)+'/'+md5.substr(0,2)+'/'+filename;
var img;
if (wpShowImages) {
if (width) {
width="width='"+width+"px'";
}
img="<img onerror='this.onerror=null;this.src=\""
+wpImageFallbackPath+source+"\";' src='"
+wpImageBasePath+source+"' alt='"+caption+"' "+width+"/>";
} else {
img=wpImageNamespace+':'+filename
+" <em style='color:red;'>(images disabled)</em>";
}
caption=_strip_inline_wiki(caption);
return "<a class='image' title='"+caption+"' href='"
+wpBaseArticlePath+wpImageNamespace+':'
+filename+"'>"+img+"</a>";
};
function _parse_inline_images(str) {
var start,substart=0,nestlev=0;
var loop,close,open,wiki,html;
while(-1!=(start=str.indexOf('[[',substart))) {
if (str.substr(start+2).match(RegExp('^'+wpImageNamespace+':','i'))) {
loop=true;substart=start;
do {
substart+=2;close=str.indexOf(']]',substart);
open=str.indexOf('[[',substart);
if (close<=open||open==-1) {
if (close==-1) return str;
substart=close;
if (nestlev) {
nestlev--;
} else {
wiki=str.substring(start,close+2);
html=_parse_image(wiki);
str=str.replace(wiki,html);substart=start+html.length;loop=false;
}
} else {
substart=open;nestlev++;
}
} while(loop);
} else {
break;
}
} /* end while loop */
return str;
};
function _parse_inline_wiki(str) {
var aux_match,math_md5;
str=_parse_inline_images(str);
while(aux_match=str.match(/<(?:)math>(.*?)<\/math>/i)) {
math_md5=hex_md5(aux_match);
str=str.replace(aux_match,"<img src='"+wpMathBasePath+math_md5+'.png'+"' />");
}
return str
.replace(/'''''(.*?)''(.*?)'''/g,'<strong><em>$1</em>$2</strong>')
.replace(/'''''(.*?)'''(.*?)''/g,'<em><strong>$1</strong>$2</em>')
.replace(/'''(.*?)''(.*?)'''''/g,'<strong>$1<em>$2</em></strong>')
.replace(/'''(.*?)'''/g,'<strong>$1</strong>')
.replace(/''(.*?)''/g,'<em>$1</em>')
.replace(/~{5}(?!~)/g,Date())
.replace(/~{4}(?!~)/g,wpSignature+' '+Date())
.replace(/~{3}(?!~)/g,wpSignature)
.replace(RegExp('\\[\\[:((?:'+wpCategoryNamespace
+'|'+wpInterwikiCodes+'):.*?)\\]\\]','gi'),
"<a href='"+wpBaseArticlePath+"$1'>$1</a>")
.replace(RegExp('\\[\\[(?:'+wpCategoryNamespace
+'|'+wpInterwikiCodes+'):.*?\\]\\]','gi')
,'')
.replace(/\*?)\]\](\w*)/g,"<a href='"+wpBaseArticlePath+"$1'>$1$2</a>")
.replace(/\]+?)\]\](\w*)/g,
"<a href='"+wpBaseArticlePath+"$1'>$2$3</a>")
.replace(/\]*?:)?(.*?)( *\(.*?\))?\|\]\]/g,
"<a href='"+wpBaseArticlePath+"$1$2$3'>$2</a>")
.replace(/\]*?) (.*?)\]/g,
"<a href='$1:$2$3'>$4</a>")
.replace(/\/g,"<a href='http://$1'></a>")
.replace(/\/g,
"<a href='$1:$2$3'>$1:$2$3</a>")
.replace(/(^| )(http|news|ftp|mailto|gopher|irc):(\/*)(*)/g,
"$1<a href='$2:$3$4'>$2:$3$4</a>")
.replace('__NOTOC__','')
.replace('__NOEDITSECTION__','');
};
function _strip_inline_wiki(str) {
return str.replace(/\]*\|(.*?)\]\]/g,'$1')
.replace(/\\]/g,'$1')
.replace(/''(.*?)''/g,'$1');
};
function max(a,b) {
if (a>b)return a;
else return b;
};
function min(a,b) {
if (a<b)return a;
else return b;
};
function str_imatch(str_a,str_b) {
var lim=min(str_a.length,str_b.length);
for(var i=0;i<lim;i++) {
if (str_a.charAt(i)!=str_b.charAt(i))
return i;
}
return i;
};
function strip_cr(str) {
return str.replace(/\n\r/g,"\n").replace(/\r/g,'');
};
function html_entities(str) {
return str.replace(/&/g,"&")
.replace(/</g,"<")
.replace(/>/g,">");
};
/* start md5 nonsense */
var chrsz=8;var hex_tab="0123456789abcdef";function hex_md5(s) {
return binl2hex(core_md5(str2binl(s),s.length*chrsz));};function core_md5(x,len)
{x|=0x80<<((len)%32);x=len;var a=1732584193;var b=-271733879;var c=-1732584194;var d=271733878;for(var i=0;i<x.length;i+=16)
{var olda=a;var oldb=b;var oldc=c;var oldd=d;a=md5_ff(a,b,c,d,x,7,-680876936);d=md5_ff(d,a,b,c,x,12,-389564586);c=md5_ff(c,d,a,b,x,17,606105819);b=md5_ff(b,c,d,a,x,22,-1044525330);a=md5_ff(a,b,c,d,x,7,-176418897);d=md5_ff(d,a,b,c,x,12,1200080426);c=md5_ff(c,d,a,b,x,17,-1473231341);b=md5_ff(b,c,d,a,x,22,-45705983);a=md5_ff(a,b,c,d,x,7,1770035416);d=md5_ff(d,a,b,c,x,12,-1958414417);c=md5_ff(c,d,a,b,x,17,-42063);b=md5_ff(b,c,d,a,x,22,-1990404162);a=md5_ff(a,b,c,d,x,7,1804603682);d=md5_ff(d,a,b,c,x,12,-40341101);c=md5_ff(c,d,a,b,x,17,-1502002290);b=md5_ff(b,c,d,a,x,22,1236535329);a=md5_gg(a,b,c,d,x,5,-165796510);d=md5_gg(d,a,b,c,x,9,-1069501632);c=md5_gg(c,d,a,b,x,14,643717713);b=md5_gg(b,c,d,a,x,20,-373897302);a=md5_gg(a,b,c,d,x,5,-701558691);d=md5_gg(d,a,b,c,x,9,38016083);c=md5_gg(c,d,a,b,x,14,-660478335);b=md5_gg(b,c,d,a,x,20,-405537848);a=md5_gg(a,b,c,d,x,5,568446438);d=md5_gg(d,a,b,c,x,9,-1019803690);c=md5_gg(c,d,a,b,x,14,-187363961);b=md5_gg(b,c,d,a,x,20,1163531501);a=md5_gg(a,b,c,d,x,5,-1444681467);d=md5_gg(d,a,b,c,x,9,-51403784);c=md5_gg(c,d,a,b,x,14,1735328473);b=md5_gg(b,c,d,a,x,20,-1926607734);a=md5_hh(a,b,c,d,x,4,-378558);d=md5_hh(d,a,b,c,x,11,-2022574463);c=md5_hh(c,d,a,b,x,16,1839030562);b=md5_hh(b,c,d,a,x,23,-35309556);a=md5_hh(a,b,c,d,x,4,-1530992060);d=md5_hh(d,a,b,c,x,11,1272893353);c=md5_hh(c,d,a,b,x,16,-155497632);b=md5_hh(b,c,d,a,x,23,-1094730640);a=md5_hh(a,b,c,d,x,4,681279174);d=md5_hh(d,a,b,c,x,11,-358537222);c=md5_hh(c,d,a,b,x,16,-722521979);b=md5_hh(b,c,d,a,x,23,76029189);a=md5_hh(a,b,c,d,x,4,-640364487);d=md5_hh(d,a,b,c,x,11,-421815835);c=md5_hh(c,d,a,b,x,16,530742520);b=md5_hh(b,c,d,a,x,23,-995338651);a=md5_ii(a,b,c,d,x,6,-198630844);d=md5_ii(d,a,b,c,x,10,1126891415);c=md5_ii(c,d,a,b,x,15,-1416354905);b=md5_ii(b,c,d,a,x,21,-57434055);a=md5_ii(a,b,c,d,x,6,1700485571);d=md5_ii(d,a,b,c,x,10,-1894986606);c=md5_ii(c,d,a,b,x,15,-1051523);b=md5_ii(b,c,d,a,x,21,-2054922799);a=md5_ii(a,b,c,d,x,6,1873313359);d=md5_ii(d,a,b,c,x,10,-30611744);c=md5_ii(c,d,a,b,x,15,-1560198380);b=md5_ii(b,c,d,a,x,21,1309151649);a=md5_ii(a,b,c,d,x,6,-145523070);d=md5_ii(d,a,b,c,x,10,-1120210379);c=md5_ii(c,d,a,b,x,15,718787259);b=md5_ii(b,c,d,a,x,21,-343485551);a=safe_add(a,olda);b=safe_add(b,oldb);c=safe_add(c,oldc);d=safe_add(d,oldd);};return Array(a,b,c,d);};function md5_cmn(q,a,b,x,s,t){return safe_add(bit_rol(safe_add(safe_add(a,q),safe_add(x,t)),s),b);};function md5_ff(a,b,c,d,x,s,t){return md5_cmn((b&c)|((~b)&d),a,b,x,s,t);};function md5_gg(a,b,c,d,x,s,t){return md5_cmn((b&d)|(c&(~d)),a,b,x,s,t);};function md5_hh(a,b,c,d,x,s,t){return md5_cmn(b^c^d,a,b,x,s,t);};function md5_ii(a,b,c,d,x,s,t){return md5_cmn(c^(b|(~d)),a,b,x,s,t);};function safe_add(x,y){var lsw=(x&0xFFFF)+(y&0xFFFF);var msw=(x>>16)+(y>>16)+(lsw>>16);return(msw<<16)|(lsw&0xFFFF);};function bit_rol(num,cnt){return(num<<cnt)|(num>>>(32-cnt));};function str2binl(str){var bin=Array();var mask=(1<<chrsz)-1;for(var i=0;i<str.length*chrsz;i+=chrsz)bin|=(str.charCodeAt(i/chrsz)&mask)<<(i%32);return bin;};function binl2hex(binarray){var str='';for(var i=0;i<binarray.length*4;i++){str+=hex_tab.charAt((binarray>>((i%4)*8+4))&0xF)+hex_tab.charAt((binarray>>((i%4)*8))&0xF);}return str;};
/* end md5 nonsense */