=0}},ID:function(g,h){return g.nodeType===1&&g.getAttribute("id")===h},TAG:function(g,h){return h==="*"&&g.nodeType===1||g.nodeName.toLowerCase()===h},CLASS:function(g,h){return(" "+(g.className||g.getAttribute("class"))+" ").indexOf(h)>-1},ATTR:function(g,h){var l=h[1];g=n.attrHandle[l]?n.attrHandle[l](g):g[l]!=null?g[l]:g.getAttribute(l);l=g+"";var m=h[2];h=h[4];return g==null?m==="!=":m===
-"="?l===h:m==="*="?l.indexOf(h)>=0:m==="~="?(" "+l+" ").indexOf(h)>=0:!h?l&&g!==false:m==="!="?l!==h:m==="^="?l.indexOf(h)===0:m==="$="?l.substr(l.length-h.length)===h:m==="|="?l===h||l.substr(0,h.length+1)===h+"-":false},POS:function(g,h,l,m){var q=n.setFilters[h[2]];if(q)return q(g,l,h,m)}}},r=n.match.POS;for(var u in n.match){n.match[u]=new RegExp(n.match[u].source+/(?![^\[]*\])(?![^\(]*\))/.source);n.leftMatch[u]=new RegExp(/(^(?:.|\r|\n)*?)/.source+n.match[u].source.replace(/\\(\d+)/g,function(g,
-h){return"\\"+(h-0+1)}))}var z=function(g,h){g=Array.prototype.slice.call(g,0);if(h){h.push.apply(h,g);return h}return g};try{Array.prototype.slice.call(s.documentElement.childNodes,0)}catch(C){z=function(g,h){h=h||[];if(j.call(g)==="[object Array]")Array.prototype.push.apply(h,g);else if(typeof g.length==="number")for(var l=0,m=g.length;l";var l=s.documentElement;l.insertBefore(g,l.firstChild);if(s.getElementById(h)){n.find.ID=function(m,q,p){if(typeof q.getElementById!=="undefined"&&!p)return(q=q.getElementById(m[1]))?q.id===m[1]||typeof q.getAttributeNode!=="undefined"&&
-q.getAttributeNode("id").nodeValue===m[1]?[q]:w:[]};n.filter.ID=function(m,q){var p=typeof m.getAttributeNode!=="undefined"&&m.getAttributeNode("id");return m.nodeType===1&&p&&p.nodeValue===q}}l.removeChild(g);l=g=null})();(function(){var g=s.createElement("div");g.appendChild(s.createComment(""));if(g.getElementsByTagName("*").length>0)n.find.TAG=function(h,l){l=l.getElementsByTagName(h[1]);if(h[1]==="*"){h=[];for(var m=0;l[m];m++)l[m].nodeType===1&&h.push(l[m]);l=h}return l};g.innerHTML="";
-if(g.firstChild&&typeof g.firstChild.getAttribute!=="undefined"&&g.firstChild.getAttribute("href")!=="#")n.attrHandle.href=function(h){return h.getAttribute("href",2)};g=null})();s.querySelectorAll&&function(){var g=k,h=s.createElement("div");h.innerHTML="";if(!(h.querySelectorAll&&h.querySelectorAll(".TEST").length===0)){k=function(m,q,p,v){q=q||s;if(!v&&q.nodeType===9&&!x(q))try{return z(q.querySelectorAll(m),p)}catch(t){}return g(m,q,p,v)};for(var l in g)k[l]=g[l];h=null}}();
-(function(){var g=s.createElement("div");g.innerHTML="";if(!(!g.getElementsByClassName||g.getElementsByClassName("e").length===0)){g.lastChild.className="e";if(g.getElementsByClassName("e").length!==1){n.order.splice(1,0,"CLASS");n.find.CLASS=function(h,l,m){if(typeof l.getElementsByClassName!=="undefined"&&!m)return l.getElementsByClassName(h[1])};g=null}}})();var E=s.compareDocumentPosition?function(g,h){return!!(g.compareDocumentPosition(h)&16)}:
-function(g,h){return g!==h&&(g.contains?g.contains(h):true)},x=function(g){return(g=(g?g.ownerDocument||g:0).documentElement)?g.nodeName!=="HTML":false},ga=function(g,h){var l=[],m="",q;for(h=h.nodeType?[h]:h;q=n.match.PSEUDO.exec(g);){m+=q[0];g=g.replace(n.match.PSEUDO,"")}g=n.relative[g]?g+"*":g;q=0;for(var p=h.length;q=0===d})};c.fn.extend({find:function(a){for(var b=this.pushStack("","find",a),d=0,f=0,e=this.length;f0)for(var j=d;j0},closest:function(a,b){if(c.isArray(a)){var d=[],f=this[0],e,j=
-{},i;if(f&&a.length){e=0;for(var o=a.length;e-1:c(f).is(e)){d.push({selector:i,elem:f});delete j[i]}}f=f.parentNode}}return d}var k=c.expr.match.POS.test(a)?c(a,b||this.context):null;return this.map(function(n,r){for(;r&&r.ownerDocument&&r!==b;){if(k?k.index(r)>-1:c(r).is(a))return r;r=r.parentNode}return null})},index:function(a){if(!a||typeof a===
-"string")return c.inArray(this[0],a?c(a):this.parent().children());return c.inArray(a.jquery?a[0]:a,this)},add:function(a,b){a=typeof a==="string"?c(a,b||this.context):c.makeArray(a);b=c.merge(this.get(),a);return this.pushStack(qa(a[0])||qa(b[0])?b:c.unique(b))},andSelf:function(){return this.add(this.prevObject)}});c.each({parent:function(a){return(a=a.parentNode)&&a.nodeType!==11?a:null},parents:function(a){return c.dir(a,"parentNode")},parentsUntil:function(a,b,d){return c.dir(a,"parentNode",
-d)},next:function(a){return c.nth(a,2,"nextSibling")},prev:function(a){return c.nth(a,2,"previousSibling")},nextAll:function(a){return c.dir(a,"nextSibling")},prevAll:function(a){return c.dir(a,"previousSibling")},nextUntil:function(a,b,d){return c.dir(a,"nextSibling",d)},prevUntil:function(a,b,d){return c.dir(a,"previousSibling",d)},siblings:function(a){return c.sibling(a.parentNode.firstChild,a)},children:function(a){return c.sibling(a.firstChild)},contents:function(a){return c.nodeName(a,"iframe")?
-a.contentDocument||a.contentWindow.document:c.makeArray(a.childNodes)}},function(a,b){c.fn[a]=function(d,f){var e=c.map(this,b,d);eb.test(a)||(f=d);if(f&&typeof f==="string")e=c.filter(f,e);e=this.length>1?c.unique(e):e;if((this.length>1||gb.test(f))&&fb.test(a))e=e.reverse();return this.pushStack(e,a,R.call(arguments).join(","))}});c.extend({filter:function(a,b,d){if(d)a=":not("+a+")";return c.find.matches(a,b)},dir:function(a,b,d){var f=[];for(a=a[b];a&&a.nodeType!==9&&(d===w||a.nodeType!==1||!c(a).is(d));){a.nodeType===
-1&&f.push(a);a=a[b]}return f},nth:function(a,b,d){b=b||1;for(var f=0;a;a=a[d])if(a.nodeType===1&&++f===b)break;return a},sibling:function(a,b){for(var d=[];a;a=a.nextSibling)a.nodeType===1&&a!==b&&d.push(a);return d}});var Ja=/ jQuery\d+="(?:\d+|null)"/g,V=/^\s+/,Ka=/(<([\w:]+)[^>]*?)\/>/g,hb=/^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i,La=/<([\w:]+)/,ib=/"+d+">"},F={option:[1,""],legend:[1,""],thead:[1,""],tr:[2,""],td:[3,""],col:[2,""],area:[1,""],_default:[0,"",""]};F.optgroup=F.option;F.tbody=F.tfoot=F.colgroup=F.caption=F.thead;F.th=F.td;if(!c.support.htmlSerialize)F._default=[1,"div","
"];c.fn.extend({text:function(a){if(c.isFunction(a))return this.each(function(b){var d=
-c(this);d.text(a.call(this,b,d.text()))});if(typeof a!=="object"&&a!==w)return this.empty().append((this[0]&&this[0].ownerDocument||s).createTextNode(a));return c.text(this)},wrapAll:function(a){if(c.isFunction(a))return this.each(function(d){c(this).wrapAll(a.call(this,d))});if(this[0]){var b=c(a,this[0].ownerDocument).eq(0).clone(true);this[0].parentNode&&b.insertBefore(this[0]);b.map(function(){for(var d=this;d.firstChild&&d.firstChild.nodeType===1;)d=d.firstChild;return d}).append(this)}return this},
-wrapInner:function(a){if(c.isFunction(a))return this.each(function(b){c(this).wrapInner(a.call(this,b))});return this.each(function(){var b=c(this),d=b.contents();d.length?d.wrapAll(a):b.append(a)})},wrap:function(a){return this.each(function(){c(this).wrapAll(a)})},unwrap:function(){return this.parent().each(function(){c.nodeName(this,"body")||c(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,true,function(a){this.nodeType===1&&this.appendChild(a)})},
-prepend:function(){return this.domManip(arguments,true,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,false,function(b){this.parentNode.insertBefore(b,this)});else if(arguments.length){var a=c(arguments[0]);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,false,function(b){this.parentNode.insertBefore(b,
-this.nextSibling)});else if(arguments.length){var a=this.pushStack(this,"after",arguments);a.push.apply(a,c(arguments[0]).toArray());return a}},remove:function(a,b){for(var d=0,f;(f=this[d])!=null;d++)if(!a||c.filter(a,[f]).length){if(!b&&f.nodeType===1){c.cleanData(f.getElementsByTagName("*"));c.cleanData([f])}f.parentNode&&f.parentNode.removeChild(f)}return this},empty:function(){for(var a=0,b;(b=this[a])!=null;a++)for(b.nodeType===1&&c.cleanData(b.getElementsByTagName("*"));b.firstChild;)b.removeChild(b.firstChild);
-return this},clone:function(a){var b=this.map(function(){if(!c.support.noCloneEvent&&!c.isXMLDoc(this)){var d=this.outerHTML,f=this.ownerDocument;if(!d){d=f.createElement("div");d.appendChild(this.cloneNode(true));d=d.innerHTML}return c.clean([d.replace(Ja,"").replace(/=([^="'>\s]+\/)>/g,'="$1">').replace(V,"")],f)[0]}else return this.cloneNode(true)});if(a===true){ra(this,b);ra(this.find("*"),b.find("*"))}return b},html:function(a){if(a===w)return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(Ja,
-""):null;else if(typeof a==="string"&&!ta.test(a)&&(c.support.leadingWhitespace||!V.test(a))&&!F[(La.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(Ka,Ma);try{for(var b=0,d=this.length;b0||e.cacheable||this.length>1?k.cloneNode(true):k)}o.length&&c.each(o,Qa)}return this}});c.fragments={};c.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){c.fn[a]=function(d){var f=[];d=c(d);var e=this.length===1&&this[0].parentNode;if(e&&e.nodeType===11&&e.childNodes.length===1&&d.length===1){d[b](this[0]);
-return this}else{e=0;for(var j=d.length;e0?this.clone(true):this).get();c.fn[b].apply(c(d[e]),i);f=f.concat(i)}return this.pushStack(f,a,d.selector)}}});c.extend({clean:function(a,b,d,f){b=b||s;if(typeof b.createElement==="undefined")b=b.ownerDocument||b[0]&&b[0].ownerDocument||s;for(var e=[],j=0,i;(i=a[j])!=null;j++){if(typeof i==="number")i+="";if(i){if(typeof i==="string"&&!jb.test(i))i=b.createTextNode(i);else if(typeof i==="string"){i=i.replace(Ka,Ma);var o=(La.exec(i)||["",
-""])[1].toLowerCase(),k=F[o]||F._default,n=k[0],r=b.createElement("div");for(r.innerHTML=k[1]+i+k[2];n--;)r=r.lastChild;if(!c.support.tbody){n=ib.test(i);o=o==="table"&&!n?r.firstChild&&r.firstChild.childNodes:k[1]===""&&!n?r.childNodes:[];for(k=o.length-1;k>=0;--k)c.nodeName(o[k],"tbody")&&!o[k].childNodes.length&&o[k].parentNode.removeChild(o[k])}!c.support.leadingWhitespace&&V.test(i)&&r.insertBefore(b.createTextNode(V.exec(i)[0]),r.firstChild);i=r.childNodes}if(i.nodeType)e.push(i);else e=
-c.merge(e,i)}}if(d)for(j=0;e[j];j++)if(f&&c.nodeName(e[j],"script")&&(!e[j].type||e[j].type.toLowerCase()==="text/javascript"))f.push(e[j].parentNode?e[j].parentNode.removeChild(e[j]):e[j]);else{e[j].nodeType===1&&e.splice.apply(e,[j+1,0].concat(c.makeArray(e[j].getElementsByTagName("script"))));d.appendChild(e[j])}return e},cleanData:function(a){for(var b,d,f=c.cache,e=c.event.special,j=c.support.deleteExpando,i=0,o;(o=a[i])!=null;i++)if(d=o[c.expando]){b=f[d];if(b.events)for(var k in b.events)e[k]?
-c.event.remove(o,k):Ca(o,k,b.handle);if(j)delete o[c.expando];else o.removeAttribute&&o.removeAttribute(c.expando);delete f[d]}}});var kb=/z-?index|font-?weight|opacity|zoom|line-?height/i,Na=/alpha\([^)]*\)/,Oa=/opacity=([^)]*)/,ha=/float/i,ia=/-([a-z])/ig,lb=/([A-Z])/g,mb=/^-?\d+(?:px)?$/i,nb=/^-?\d/,ob={position:"absolute",visibility:"hidden",display:"block"},pb=["Left","Right"],qb=["Top","Bottom"],rb=s.defaultView&&s.defaultView.getComputedStyle,Pa=c.support.cssFloat?"cssFloat":"styleFloat",ja=
-function(a,b){return b.toUpperCase()};c.fn.css=function(a,b){return X(this,a,b,true,function(d,f,e){if(e===w)return c.curCSS(d,f);if(typeof e==="number"&&!kb.test(f))e+="px";c.style(d,f,e)})};c.extend({style:function(a,b,d){if(!a||a.nodeType===3||a.nodeType===8)return w;if((b==="width"||b==="height")&&parseFloat(d)<0)d=w;var f=a.style||a,e=d!==w;if(!c.support.opacity&&b==="opacity"){if(e){f.zoom=1;b=parseInt(d,10)+""==="NaN"?"":"alpha(opacity="+d*100+")";a=f.filter||c.curCSS(a,"filter")||"";f.filter=
-Na.test(a)?a.replace(Na,b):b}return f.filter&&f.filter.indexOf("opacity=")>=0?parseFloat(Oa.exec(f.filter)[1])/100+"":""}if(ha.test(b))b=Pa;b=b.replace(ia,ja);if(e)f[b]=d;return f[b]},css:function(a,b,d,f){if(b==="width"||b==="height"){var e,j=b==="width"?pb:qb;function i(){e=b==="width"?a.offsetWidth:a.offsetHeight;f!=="border"&&c.each(j,function(){f||(e-=parseFloat(c.curCSS(a,"padding"+this,true))||0);if(f==="margin")e+=parseFloat(c.curCSS(a,"margin"+this,true))||0;else e-=parseFloat(c.curCSS(a,
-"border"+this+"Width",true))||0})}a.offsetWidth!==0?i():c.swap(a,ob,i);return Math.max(0,Math.round(e))}return c.curCSS(a,b,d)},curCSS:function(a,b,d){var f,e=a.style;if(!c.support.opacity&&b==="opacity"&&a.currentStyle){f=Oa.test(a.currentStyle.filter||"")?parseFloat(RegExp.$1)/100+"":"";return f===""?"1":f}if(ha.test(b))b=Pa;if(!d&&e&&e[b])f=e[b];else if(rb){if(ha.test(b))b="float";b=b.replace(lb,"-$1").toLowerCase();e=a.ownerDocument.defaultView;if(!e)return null;if(a=e.getComputedStyle(a,null))f=
-a.getPropertyValue(b);if(b==="opacity"&&f==="")f="1"}else if(a.currentStyle){d=b.replace(ia,ja);f=a.currentStyle[b]||a.currentStyle[d];if(!mb.test(f)&&nb.test(f)){b=e.left;var j=a.runtimeStyle.left;a.runtimeStyle.left=a.currentStyle.left;e.left=d==="fontSize"?"1em":f||0;f=e.pixelLeft+"px";e.left=b;a.runtimeStyle.left=j}}return f},swap:function(a,b,d){var f={};for(var e in b){f[e]=a.style[e];a.style[e]=b[e]}d.call(a);for(e in b)a.style[e]=f[e]}});if(c.expr&&c.expr.filters){c.expr.filters.hidden=function(a){var b=
-a.offsetWidth,d=a.offsetHeight,f=a.nodeName.toLowerCase()==="tr";return b===0&&d===0&&!f?true:b>0&&d>0&&!f?false:c.curCSS(a,"display")==="none"};c.expr.filters.visible=function(a){return!c.expr.filters.hidden(a)}}var sb=J(),tb=/
-% endif
-
-% if editable and inline:
-
-% endif
-
-% if editable and error:
- ${error}
-% endif
-
-% if not editable and value:
- ${data|n}
-% endif
-
diff --git a/addons/document_page/web/widgets/wiki.py b/addons/document_page/web/widgets/wiki.py
deleted file mode 100644
index ccf2a75899c..00000000000
--- a/addons/document_page/web/widgets/wiki.py
+++ /dev/null
@@ -1,224 +0,0 @@
-###############################################################################
-#
-# Copyright (C) 2007-TODAY Tiny ERP Pvt Ltd. All Rights Reserved.
-#
-# $Id$
-#
-# Developed by Tiny (http://openerp.com) and Axelor (http://axelor.com).
-#
-# The OpenERP web client is distributed under the "OpenERP Public License".
-# It's based on Mozilla Public License Version (MPL) 1.1 with following
-# restrictions:
-#
-# - All names, links and logos of Tiny, OpenERP and Axelor must be
-# kept as in original distribution without any changes in all software
-# screens, especially in start-up page and the software header, even if
-# the application source code has been changed or updated or code has been
-# added.
-#
-# - All distributions of the software must keep source code with OEPL.
-#
-# - All integrations to any other software must keep source code with OEPL.
-#
-# If you need commercial licence to remove this kind of restriction please
-# contact us.
-#
-# You can see the MPL licence at: http://www.mozilla.org/MPL/MPL-1.1.html
-#
-###############################################################################
-
-import re
-
-import cherrypy
-import wikimarkup
-
-from openobject import rpc
-from openobject.widgets import CSSLink
-
-
-from openerp.widgets import register_widget
-from openerp.widgets.form import Text
-
-
-_image = re.compile(r'img:(.*)\.(.*)', re.UNICODE)
-_rss = re.compile(r'rss:(.*)\.(.*)', re.UNICODE)
-_attach = re.compile(r'attach:(.*)\.(.*)', re.UNICODE)
-_internalLinks = re.compile(r'\[\[.*\]\]', re.UNICODE)
-_edit = re.compile(r'edit:(.*)\|(.*)', re.UNICODE)
-_view = re.compile(r'view:(.*)\|(.*)', re.UNICODE)
-
-class WikiParser(wikimarkup.Parser):
-
- def parse(self, text, id):
- text = text.replace(' ', 'n-b-s-p')
- text = text.replace('&', 'n-a-m-p')
- text = text.replace('&','&')
- text = text.replace('n-b-s-p', ' ')
- text = text.replace('n-a-m-p', '&')
- text = text.replace('', '')
- text = text.replace('', '')
-
- text = wikimarkup.to_unicode(text)
- text = self.strip(text)
-
- text = super(WikiParser, self).parse(text)
- text = self.addImage(text, id)
- text = self.attachDoc(text, id)
- text = self.recordLink(text)
- text = self.viewRecordLink(text)
- text = self.addInternalLinks(text)
- #TODO : already implemented but we will implement it later after releasing the 5.0
- #text = self.addRss(text, id)
- return text
-
- def viewRecordLink(self, text):
- def record(path):
- record = path.group().replace('view:','').split("|")
- model = record[0]
- text = record[1].replace('\r','').strip()
- label = "View Record"
- if len(record) > 2:
- label = record[2]
- proxy = rpc.RPCProxy(model)
- ids = proxy.name_search(text, [], 'ilike', {})
- if len(ids):
- id = ids[0][0]
- else:
- try:
- id = int(text)
- except:
- id = 0
- return "[[/openerp/form/view?model=%s&id=%d | %s]]" % (model, id, label)
-
- bits = _view.sub(record, text)
- return bits
-
- def addRss(self, text, id):
- def addrss(path):
- rssurl = path.group().replace('rss:','')
- import rss.feedparser as feedparser
- data = feedparser.parse(rssurl)
- values = "%s
" % (data.feed.title)
- values += "%s
" % (data.channel.description)
- for entry in data['entries']:
- values += "
" % (entry.link, entry.title)
- values += "%s
" % (entry.summary)
-
- return values
-
- bits = _rss.sub(addrss, text)
- return bits
-
- def attachDoc(self, text, id):
- def document(path):
- file = path.group().replace('attach:','')
- if file.startswith('http') or file.startswith('ftp'):
- return "Download File" % (file)
- else:
- proxy = rpc.RPCProxy('ir.attachment')
- ids = proxy.search([('datas_fname','=',file.strip()), ('res_model','=','wiki.wiki'), ('res_id','=',id)])
- if len(ids) > 0:
- return "%s" % (file, id, file)
- else:
- return """Attach : %s """ % (id, file)
- bits = _attach.sub(document, text)
- return bits
-
- def addImage(self, text, id):
- def image(path):
- file = path.group().replace('img:','')
- if file.startswith('http') or file.startswith('ftp'):
- return "
" % (file)
- else:
- proxy = rpc.RPCProxy('ir.attachment')
- ids = proxy.search([('datas_fname','=',file.strip()), ('res_model','=','wiki.wiki'), ('res_id','=',id)])
- if len(ids) > 0:
- return "
" % (file, id)
- else:
- return """Attach : %s """ % (id, file)
- #"[[/attachment/?model=wiki.wiki&id=%d | Attach:%s]]" % (id, file)
- bits = _image.sub(image, text)
- return bits
-
- def recordLink(self, text):
- def record(path):
- record = path.group().replace('edit:','').split("|")
- model = record[0]
- text = record[1].replace('\r','').strip()
- label = "Edit Record"
- if len(record) > 2:
- label = record[2]
- proxy = rpc.RPCProxy(model)
- ids = proxy.name_search(text, [], '=', {})
- if len(ids):
- id = ids[0][0]
- else:
- try:
- id = int(text)
- except:
- id = 0
- return "[[/openerp/form/edit?model=%s&id=%d | %s]]" % (model, id, label)
-
- bits = _edit.sub(record, text)
- return bits
-
- def addInternalLinks(self, text):
- proxy = rpc.RPCProxy('wiki.wiki')
-
- def link(path):
- link = path.group().replace('[','').replace('[','').replace(']','').replace(']','').split("|")
- name_to_search = link[0].strip()
- mids = proxy.search([('name','ilike', name_to_search)])
- link_str = ""
- if mids:
- if len(link) == 2:
- link_str = "%s" % (mids[0], link[1])
- elif len(link) == 1:
- link_str = "%s" % (mids[0], link[0])
- else:
- if len(link) == 2:
- link_str = "%s" % (link[0], link[1])
- elif len(link) == 1:
- link_str = "%s" % (link[0])
-
- return link_str
-
- bits = _internalLinks.sub(link, text)
- return bits
-
-def wiki2html(text, showToc, id):
- p = WikiParser(show_toc=showToc)
- return p.parse(text, id)
-
-class WikiWidget(Text):
- template = "/wiki/widgets/templates/wiki.mako"
-
- params = ["data"]
-
- css = [CSSLink("wiki", "css/wiki.css")]
-
- data = None
-
- def set_value(self, value):
- super(WikiWidget, self).set_value(value)
-
- if value:
- toc = True
- id = False
- if hasattr(cherrypy.request, 'terp_record'):
- params = cherrypy.request.terp_params
- if params._terp_model == 'wiki.wiki':
- proxy = rpc.RPCProxy('wiki.wiki')
- toc = proxy.read([params.id], ['toc'])[0]['toc']
- id = params.id
-
- text = value+'\n\n'
- html = wiki2html(text, toc, id)
-
- self.data = html
-
-register_widget(WikiWidget, ["text_wiki"])
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/document_page/web/widgets/wikimarkup/__init__.py b/addons/document_page/web/widgets/wikimarkup/__init__.py
deleted file mode 100644
index f5fe67fada1..00000000000
--- a/addons/document_page/web/widgets/wikimarkup/__init__.py
+++ /dev/null
@@ -1,2146 +0,0 @@
-# coding: latin1
-"""
-MediaWiki-style markup
-
-Copyright (C) 2008 David Cramer
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see .
-"""
-
-import re, random, locale
-from base64 import b64encode, b64decode
-
-# a few patterns we use later
-
-MW_COLON_STATE_TEXT = 0
-MW_COLON_STATE_TAG = 1
-MW_COLON_STATE_TAGSTART = 2
-MW_COLON_STATE_CLOSETAG = 3
-MW_COLON_STATE_TAGSLASH = 4
-MW_COLON_STATE_COMMENT = 5
-MW_COLON_STATE_COMMENTDASH = 6
-MW_COLON_STATE_COMMENTDASHDASH = 7
-
-_attributePat = re.compile(ur'''(?:^|\s)([A-Za-z0-9]+)(?:\s*=\s*(?:"([^<"]*)"|'([^<']*)'|([a-zA-Z0-9!#$%&()*,\-./:;<>?@[\]^_`{|}~]+)|#([0-9a-fA-F]+)))''', re.UNICODE)
-_space = re.compile(ur'\s+', re.UNICODE)
-_closePrePat = re.compile(u"]*?)(/?>)([^<]*)$', re.UNICODE)
-
-_htmlpairs = ( # Tags that must be closed
- u'b', u'del', u'i', u'ins', u'u', u'font', u'big', u'small', u'sub', u'sup', u'h1',
- u'h2', u'h3', u'h4', u'h5', u'h6', u'cite', u'code', u'em', u's',
- u'strike', u'strong', u'tt', u'var', u'div', u'center',
- u'blockquote', u'ol', u'ul', u'dl', u'table', u'caption', u'pre',
- u'ruby', u'rt' , u'rb' , u'rp', u'p', u'span', u'u',
-)
-_htmlsingle = (
- u'br', u'hr', u'li', u'dt', u'dd', u'img',
-)
-_htmlsingleonly = ( # Elements that cannot have close tags
- u'br', u'hr', u'img',
-)
-_htmlnest = ( # Tags that can be nested--??
- u'table', u'tr', u'td', u'th', u'div', u'blockquote', u'ol', u'ul',
- u'dl', u'font', u'big', u'small', u'sub', u'sup', u'span', u'img',
-)
-_tabletags = ( # Can only appear inside table
- u'td', u'th', u'tr',
-)
-_htmllist = ( # Tags used by list
- u'ul', u'ol',
-)
-_listtags = ( # Tags that can appear in a list
- u'li',
-)
-_htmlsingleallowed = _htmlsingle + _tabletags
-_htmlelements = _htmlsingle + _htmlpairs + _htmlnest
-
-_htmlEntities = {
- u'Aacute': 193, u'aacute': 225, u'Acirc': 194, u'acirc': 226, u'acute': 180,
- u'AElig': 198, u'aelig': 230, u'Agrave': 192, u'agrave': 224, u'alefsym': 8501,
- u'Alpha': 913, u'alpha': 945, u'amp': 38, u'and': 8743, u'ang': 8736, u'Aring': 197,
- u'aring': 229,
- u'asymp': 8776,
- u'Atilde': 195,
- u'atilde': 227,
- u'Auml': 196,
- u'auml': 228,
- u'bdquo': 8222,
- u'Beta': 914,
- u'beta': 946,
- u'brvbar': 166,
- u'bull': 8226,
- u'cap': 8745,
- u'Ccedil': 199,
- u'ccedil': 231,
- u'cedil': 184,
- u'cent': 162,
- u'Chi': 935,
- u'chi': 967,
- u'circ': 710,
- u'clubs': 9827,
- u'cong': 8773,
- u'copy': 169,
- u'crarr': 8629,
- u'cup': 8746,
- u'curren': 164,
- u'dagger': 8224,
- u'Dagger': 8225,
- u'darr': 8595,
- u'dArr': 8659,
- u'deg': 176,
- u'Delta': 916,
- u'delta': 948,
- u'diams': 9830,
- u'divide': 247,
- u'Eacute': 201,
- u'eacute': 233,
- u'Ecirc': 202,
- u'ecirc': 234,
- u'Egrave': 200,
- u'egrave': 232,
- u'empty': 8709,
- u'emsp': 8195,
- u'ensp': 8194,
- u'Epsilon': 917,
- u'epsilon': 949,
- u'equiv': 8801,
- u'Eta': 919,
- u'eta': 951,
- u'ETH': 208,
- u'eth': 240,
- u'Euml': 203,
- u'euml': 235,
- u'euro': 8364,
- u'exist': 8707,
- u'fnof': 402,
- u'forall': 8704,
- u'frac12': 189,
- u'frac14': 188,
- u'frac34': 190,
- u'frasl': 8260,
- u'Gamma': 915,
- u'gamma': 947,
- u'ge': 8805,
- u'gt': 62,
- u'harr': 8596,
- u'hArr': 8660,
- u'hearts': 9829,
- u'hellip': 8230,
- u'Iacute': 205,
- u'iacute': 237,
- u'Icirc': 206,
- u'icirc': 238,
- u'iexcl': 161,
- u'Igrave': 204,
- u'igrave': 236,
- u'image': 8465,
- u'infin': 8734,
- u'int': 8747,
- u'Iota': 921,
- u'iota': 953,
- u'iquest': 191,
- u'isin': 8712,
- u'Iuml': 207,
- u'iuml': 239,
- u'Kappa': 922,
- u'kappa': 954,
- u'Lambda': 923,
- u'lambda': 955,
- u'lang': 9001,
- u'laquo': 171,
- u'larr': 8592,
- u'lArr': 8656,
- u'lceil': 8968,
- u'ldquo': 8220,
- u'le': 8804,
- u'lfloor': 8970,
- u'lowast': 8727,
- u'loz': 9674,
- u'lrm': 8206,
- u'lsaquo': 8249,
- u'lsquo': 8216,
- u'lt': 60,
- u'macr': 175,
- u'mdash': 8212,
- u'micro': 181,
- u'middot': 183,
- u'minus': 8722,
- u'Mu': 924,
- u'mu': 956,
- u'nabla': 8711,
- u'nbsp': 160,
- u'ndash': 8211,
- u'ne': 8800,
- u'ni': 8715,
- u'not': 172,
- u'notin': 8713,
- u'nsub': 8836,
- u'Ntilde': 209,
- u'ntilde': 241,
- u'Nu': 925,
- u'nu': 957,
- u'Oacute': 211,
- u'oacute': 243,
- u'Ocirc': 212,
- u'ocirc': 244,
- u'OElig': 338,
- u'oelig': 339,
- u'Ograve': 210,
- u'ograve': 242,
- u'oline': 8254,
- u'Omega': 937,
- u'omega': 969,
- u'Omicron': 927,
- u'omicron': 959,
- u'oplus': 8853,
- u'or': 8744,
- u'ordf': 170,
- u'ordm': 186,
- u'Oslash': 216,
- u'oslash': 248,
- u'Otilde': 213,
- u'otilde': 245,
- u'otimes': 8855,
- u'Ouml': 214,
- u'ouml': 246,
- u'para': 182,
- u'part': 8706,
- u'permil': 8240,
- u'perp': 8869,
- u'Phi': 934,
- u'phi': 966,
- u'Pi': 928,
- u'pi': 960,
- u'piv': 982,
- u'plusmn': 177,
- u'pound': 163,
- u'prime': 8242,
- u'Prime': 8243,
- u'prod': 8719,
- u'prop': 8733,
- u'Psi': 936,
- u'psi': 968,
- u'quot': 34,
- u'radic': 8730,
- u'rang': 9002,
- u'raquo': 187,
- u'rarr': 8594,
- u'rArr': 8658,
- u'rceil': 8969,
- u'rdquo': 8221,
- u'real': 8476,
- u'reg': 174,
- u'rfloor': 8971,
- u'Rho': 929,
- u'rho': 961,
- u'rlm': 8207,
- u'rsaquo': 8250,
- u'rsquo': 8217,
- u'sbquo': 8218,
- u'Scaron': 352,
- u'scaron': 353,
- u'sdot': 8901,
- u'sect': 167,
- u'shy': 173,
- u'Sigma': 931,
- u'sigma': 963,
- u'sigmaf': 962,
- u'sim': 8764,
- u'spades': 9824,
- u'sub': 8834,
- u'sube': 8838,
- u'sum': 8721,
- u'sup': 8835,
- u'sup1': 185,
- u'sup2': 178,
- u'sup3': 179,
- u'supe': 8839,
- u'szlig': 223,
- u'Tau': 932,
- u'tau': 964,
- u'there4': 8756,
- u'Theta': 920,
- u'theta': 952,
- u'thetasym': 977,
- u'thinsp': 8201,
- u'THORN': 222,
- u'thorn': 254,
- u'tilde': 732,
- u'times': 215,
- u'trade': 8482,
- u'Uacute': 218,
- u'uacute': 250,
- u'uarr': 8593,
- u'uArr': 8657,
- u'Ucirc': 219,
- u'ucirc': 251,
- u'Ugrave': 217,
- u'ugrave': 249,
- u'uml': 168,
- u'upsih': 978,
- u'Upsilon': 933,
- u'upsilon': 965,
- u'Uuml': 220,
- u'uuml': 252,
- u'weierp': 8472,
- u'Xi': 926,
- u'xi': 958,
- u'Yacute': 221,
- u'yacute': 253,
- u'yen': 165,
- u'Yuml': 376,
- u'yuml': 255,
- u'Zeta': 918,
- u'zeta': 950,
- u'zwj': 8205,
- u'zwnj': 8204
-}
-
-_charRefsPat = re.compile(ur'''(&([A-Za-z0-9]+);|([0-9]+);|[xX]([0-9A-Za-z]+);|(&))''', re.UNICODE)
-_cssCommentPat = re.compile(ur'''\*.*?\*''', re.UNICODE)
-_toUTFPat = re.compile(ur'''\\([0-9A-Fa-f]{1,6})[\s]?''', re.UNICODE)
-_hackPat = re.compile(ur'''(expression|tps*://|url\s*\().*''', re.UNICODE | re.IGNORECASE)
-_hrPat = re.compile(u'''^-----*''', re.UNICODE | re.MULTILINE)
-_h1Pat = re.compile(u'^=(.+)=\s*$', re.UNICODE | re.MULTILINE)
-_h2Pat = re.compile(u'^==(.+)==\s*$', re.UNICODE | re.MULTILINE)
-_h3Pat = re.compile(u'^===(.+)===\s*$', re.UNICODE | re.MULTILINE)
-_h4Pat = re.compile(u'^====(.+)====\s*$', re.UNICODE | re.MULTILINE)
-_h5Pat = re.compile(u'^=====(.+)=====\s*$', re.UNICODE | re.MULTILINE)
-_h6Pat = re.compile(u'^======(.+)======\s*$', re.UNICODE | re.MULTILINE)
-_quotePat = re.compile(u"""(''+)""", re.UNICODE)
-_removePat = re.compile(ur'\b(' + ur'|'.join((u"a", u"an", u"as", u"at", u"before", u"but", u"by", u"for", u"from",
- u"is", u"in", u"into", u"like", u"of", u"off", u"on", u"onto", u"per",
- u"since", u"than", u"the", u"this", u"that", u"to", u"up", u"via",
- u"with")) + ur')\b', re.UNICODE | re.IGNORECASE)
-_nonWordSpaceDashPat = re.compile(ur'[^\w\s\-\./]', re.UNICODE)
-_multiSpacePat = re.compile(ur'[\s\-_\./]+', re.UNICODE)
-_spacePat = re.compile(ur' ', re.UNICODE)
-_linkPat = re.compile(ur'^(?:([A-Za-z0-9]+):)?([^\|]+)(?:\|([^\n]+?))?\]\](.*)$', re.UNICODE | re.DOTALL)
-_bracketedLinkPat = re.compile(ur'(?:\[((?:mailto:|irc://|https?://|ftp://|/)[^<>\]\[' + u"\x00-\x20\x7f" + ur']*)\s*(.*?)\])', re.UNICODE)
-_protocolPat = re.compile(ur'(\b(?:mailto:|irc://|https?://|ftp://))', re.UNICODE)
-_specialUrlPat = re.compile(ur'^([^<>\]\[' + u"\x00-\x20\x7f" + ur']+)(.*)$', re.UNICODE)
-_protocolsPat = re.compile(ur'^(mailto:|irc://|https?://|ftp://)$', re.UNICODE)
-_controlCharsPat = re.compile(ur'[\]\[<>"' + u"\\x00-\\x20\\x7F" + ur']]', re.UNICODE)
-_hostnamePat = re.compile(ur'^([^:]+:)(//[^/]+)?(.*)$', re.UNICODE)
-_stripPat = re.compile(u'\\s|\u00ad|\u1806|\u200b|\u2060|\ufeff|\u03f4|\u034f|\u180b|\u180c|\u180d|\u200c|\u200d|[\ufe00-\ufe0f]', re.UNICODE)
-_zomgPat = re.compile(ur'^(:*)\{\|(.*)$', re.UNICODE)
-_headerPat = re.compile(ur"<[Hh]([1-6])(.*?)>(.*?)[Hh][1-6] *>", re.UNICODE)
-_templateSectionPat = re.compile(ur"", re.UNICODE)
-_tagPat = re.compile(ur"<.*?>", re.UNICODE)
-_startRegexHash = {}
-_endRegexHash = {}
-_endCommentPat = re.compile(ur'(-->)', re.UNICODE)
-_extractTagsAndParams_n = 1
-_guillemetLeftPat = re.compile(ur'(.) (\?|:|;|!|\302\273)', re.UNICODE)
-_guillemetRightPat = re.compile(ur'(\302\253) ', re.UNICODE)
-
-def setupAttributeWhitelist():
- common = ( u'id', u'class', u'lang', u'dir', u'title', u'style' )
- block = common + (u'align',)
- tablealign = ( u'align', u'char', u'charoff', u'valign' )
- tablecell = ( u'abbr',
- u'axis',
- u'headers',
- u'scope',
- u'rowspan',
- u'colspan',
- u'nowrap', # deprecated
- u'width', # deprecated
- u'height', # deprecated
- u'bgcolor' # deprecated
- )
- return {
- u'div': block,
- u'center': common, # deprecated
- u'span': block, # ??
- u'h1': block,
- u'h2': block,
- u'h3': block,
- u'h4': block,
- u'h5': block,
- u'h6': block,
- u'em': common,
- u'strong': common,
- u'cite': common,
- u'code': common,
- u'var': common,
- u'img': common + (u'src', u'alt', u'width', u'height',),
- u'blockquote': common + (u'cite',),
- u'sub': common,
- u'sup': common,
- u'p': block,
- u'br': (u'id', u'class', u'title', u'style', u'clear',),
- u'pre': common + (u'width',),
- u'ins': common + (u'cite', u'datetime'),
- u'del': common + (u'cite', u'datetime'),
- u'ul': common + (u'type',),
- u'ol': common + (u'type', u'start'),
- u'li': common + (u'type', u'value'),
- u'dl': common,
- u'dd': common,
- u'dt': common,
- u'table': common + ( u'summary', u'width', u'border', u'frame',
- u'rules', u'cellspacing', u'cellpadding',
- u'align', u'bgcolor',
- ),
- u'caption': common + (u'align',),
- u'thead': common + tablealign,
- u'tfoot': common + tablealign,
- u'tbody': common + tablealign,
- u'colgroup': common + ( u'span', u'width' ) + tablealign,
- u'col': common + ( u'span', u'width' ) + tablealign,
- u'tr': common + ( u'bgcolor', ) + tablealign,
- u'td': common + tablecell + tablealign,
- u'th': common + tablecell + tablealign,
- u'tt': common,
- u'b': common,
- u'i': common,
- u'big': common,
- u'small': common,
- u'strike': common,
- u's': common,
- u'u': common,
- u'font': common + ( u'size', u'color', u'face' ),
- u'hr': common + ( u'noshade', u'size', u'width' ),
- u'ruby': common,
- u'rb': common,
- u'rt': common, #array_merge( $common, array( 'rbspan' ) ),
- u'rp': common,
- }
-_whitelist = setupAttributeWhitelist()
-_page_cache = {}
-env = {}
-
-def registerTagHook(tag, function):
- mTagHooks[tag] = function
-
-class BaseParser(object):
- def __init__(self):
- self.uniq_prefix = u"\x07UNIQ" + unicode(random.randint(1, 1000000000))
- self.strip_state = {}
- self.arg_stack = []
- self.env = env
- self.keep_env = (env != {})
-
- def __del__(self):
- if not self.keep_env:
- global env
- env = {}
-
- ''' Used to store objects in the environment
- used to prevent recursive imports '''
- def store_object(self, namespace, key, value=True):
- # Store the item to not reprocess it
- if namespace not in self.env:
- self.env[namespace] = {}
- self.env[namespace][key] = value
-
- def has_object(self, namespace, key):
- if namespace not in self.env:
- self.env[namespace] = {}
- if hasattr(self, 'count'):
- data = self.env[namespace]
- test = key in data
- self.count = True
- return key in self.env[namespace]
-
- def retrieve_object(self, namespace, key, default=None):
- if not self.env.get(namespace):
- self.env[namespace] = {}
- return self.env[namespace].get(key, default)
-
- def parse(self, text):
- utf8 = isinstance(text, str)
- text = to_unicode(text)
- if text[-1:] != u'\n':
- text = text + u'\n'
- taggedNewline = True
- else:
- taggedNewline = False
-
- text = self.strip(text)
- text = self.removeHtmlTags(text)
- text = self.parseHorizontalRule(text)
- text = self.parseAllQuotes(text)
- text = self.replaceExternalLinks(text)
- text = self.unstrip(text)
- text = self.fixtags(text)
- text = self.doBlockLevels(text, True)
- text = self.unstripNoWiki(text)
- text = text.split(u'\n')
- text = u'\n'.join(text)
- if taggedNewline and text[-1:] == u'\n':
- text = text[:-1]
- if utf8:
- return text.encode("utf-8")
- return text
-
- def strip(self, text, stripcomments=False, dontstrip=[]):
- render = True
-
- commentState = {}
-
- elements = ['nowiki',] + mTagHooks.keys()
- if True: #wgRawHtml
- elements.append('html')
-
- # Removing $dontstrip tags from $elements list (currently only 'gallery', fixing bug 2700)
- for k in dontstrip:
- if k in elements:
- del elements[k]
-
- matches = {}
- text = self.extractTagsAndParams(elements, text, matches)
-
- for marker in matches:
- element, content, params, tag = matches[marker]
- if render:
- tagName = element.lower()
- if tagName == u'!--':
- # comment
- output = tag
- if tag[-3:] != u'-->':
- output += "-->"
- elif tagName == u'html':
- output = content
- elif tagName == u'nowiki':
- output = content.replace(u'&', u'&').replace(u'<', u'<').replace(u'>', u'>')
- else:
- if tagName in mTagHooks:
- output = mTagHooks[tagName](self, content, params)
- else:
- output = content.replace(u'&', u'&').replace(u'<', u'<').replace(u'>', u'>')
- else:
- # Just stripping tags; keep the source
- output = tag
-
- # Unstrip the output, because unstrip() is no longer recursive so
- # it won't do it itself
- output = self.unstrip(output)
-
- if not stripcomments and element == u'!--':
- commentState[marker] = output
- elif element == u'html' or element == u'nowiki':
- if 'nowiki' not in self.strip_state:
- self.strip_state['nowiki'] = {}
- self.strip_state['nowiki'][marker] = output
- else:
- if 'general' not in self.strip_state:
- self.strip_state['general'] = {}
- self.strip_state['general'][marker] = output
-
- # Unstrip comments unless explicitly told otherwise.
- # (The comments are always stripped prior to this point, so as to
- # not invoke any extension tags / parser hooks contained within
- # a comment.)
- if not stripcomments:
- # Put them all back and forget them
- for k in commentState:
- v = commentState[k]
- text = text.replace(k, v)
-
- return text
-
- def removeHtmlTags(self, text):
- """convert bad tags into HTML identities"""
- sb = []
- text = self.removeHtmlComments(text)
- bits = text.split(u'<')
- sb.append(bits.pop(0))
- tagstack = []
- tablestack = tagstack
- for x in bits:
- m = _tagPattern.match(x)
- if not m:
- continue
- slash, t, params, brace, rest = m.groups()
- t = t.lower()
- badtag = False
- if t in _htmlelements:
- # Check our stack
- if slash:
- # Closing a tag...
- if t in _htmlsingleonly or len(tagstack) == 0:
- badtag = True
- else:
- ot = tagstack.pop()
- if ot != t:
- if ot in _htmlsingleallowed:
- # Pop all elements with an optional close tag
- # and see if we find a match below them
- optstack = []
- optstack.append(ot)
- while True:
- if len(tagstack) == 0:
- break
- ot = tagstack.pop()
- if ot == t or ot not in _htmlsingleallowed:
- break
- optstack.append(ot)
- if t != ot:
- # No match. Push the optinal elements back again
- badtag = True
- tagstack += reversed(optstack)
- else:
- tagstack.append(ot)
- # can be nested in or , skip those cases:
- if ot not in _htmllist and t in _listtags:
- badtag = True
- elif t == u'table':
- if len(tablestack) == 0:
- bagtag = True
- else:
- tagstack = tablestack.pop()
- newparams = u''
- else:
- # Keep track for later
- if t in _tabletags and u'table' not in tagstack:
- badtag = True
- elif t in tagstack and t not in _htmlnest:
- badtag = True
- # Is it a self-closed htmlpair? (bug 5487)
- elif brace == u'/>' and t in _htmlpairs:
- badTag = True
- elif t in _htmlsingleonly:
- # Hack to force empty tag for uncloseable elements
- brace = u'/>'
- elif t in _htmlsingle:
- # Hack to not close $htmlsingle tags
- brace = None
- else:
- if t == u'table':
- tablestack.append(tagstack)
- tagstack = []
- tagstack.append(t)
- newparams = self.fixTagAttributes(params, t)
- if not badtag:
- rest = rest.replace(u'>', u'>')
- if brace == u'/>':
- close = u' /'
- else:
- close = u''
- sb.append(u'<')
- sb.append(slash)
- sb.append(t)
- sb.append(newparams)
- sb.append(close)
- sb.append(u'>')
- sb.append(rest)
- continue
- sb.append(u'<')
- sb.append(x.replace(u'>', u'>'))
-
- # Close off any remaining tags
- while tagstack:
- t = tagstack.pop()
- sb.append(u'')
- sb.append(t)
- sb.append(u'>\n')
- if t == u'table':
- if not tablestack:
- break
- tagstack = tablestack.pop()
-
- return u''.join(sb)
-
- def removeHtmlComments(self, text):
- """remove comments from given text"""
- sb = []
- start = text.find(u'', start)
- if end == -1:
- break
- end += 3
-
- spaceStart = max(0, start-1)
- spaceEnd = end
- while text[spaceStart] == u' ' and spaceStart > 0:
- spaceStart -= 1
- while text[spaceEnd] == u' ':
- spaceEnd += 1
-
- if text[spaceStart] == u'\n' and text[spaceEnd] == u'\n':
- sb.append(text[last:spaceStart])
- sb.append(u'\n')
- last = spaceEnd+1
- else:
- sb.append(text[last:spaceStart+1])
- last = spaceEnd
-
- start = text.find(u''
-
- return result, mDTopen
-
- def nextItem(self, char, mDTopen):
- if char == u'*' or char == '#':
- return u'
', None
- elif char == u':' or char == u';':
- close = u''
- if mDTopen:
- close = ''
- if char == u';':
- return close + u'', True
- else:
- return close + u'', False
- return u''
-
- def closeList(self, char, mDTopen):
- if char == u'*':
- return u'\n'
- elif char == u'#':
- return u'\n'
- elif char == u':':
- if mDTopen:
- return u'\n'
- else:
- return u'\n'
- else:
- return u''
-
- def findColonNoLinks(self, text, before, after):
- try:
- pos = text.search(':')
- except:
- return False
-
- lt = text.find('<')
- if lt == -1 or lt > pos:
- # Easy; no tag nesting to worry about
- before = text[0:pos]
- after = text[0:pos+1]
- return before, after, pos
-
- # Ugly state machine to walk through avoiding tags.
- state = MW_COLON_STATE_TEXT;
- stack = 0;
- i = 0
- while i < len(text):
- c = text[i];
-
- if state == 0: # MW_COLON_STATE_TEXT:
- if text[i] == '<':
- # Could be either a tag or an tag
- state = MW_COLON_STATE_TAGSTART
- elif text[i] == ':':
- if stack == 0:
- # we found it
- return text[0:i], text[i+1], i
- else:
- # Skip ahead looking for something interesting
- try:
- colon = text.search(':', i)
- except:
- return False
- lt = text.find('<', i)
- if stack == 0:
- if lt == -1 or colon < lt:
- # we found it
- return text[0:colon], text[colon+1], i
- if lt == -1:
- break
- # Skip ahead to next tag start
- i = lt
- state = MW_COLON_STATE_TAGSTART
- elif state == 1: # MW_COLON_STATE_TAG:
- # In a
- if text[i] == '>':
- stack += 1
- state = MW_COLON_STATE_TEXT
- elif text[i] == '/':
- state = MW_COLON_STATE_TAGSLASH
- elif state == 2: # MW_COLON_STATE_TAGSTART:
- if text[i] == '/':
- state = MW_COLON_STATE_CLOSETAG
- elif text[i] == '!':
- state = MW_COLON_STATE_COMMENT
- elif text[i] == '>':
- # Illegal early close? This shouldn't happen D:
- state = MW_COLON_STATE_TEXT
- else:
- state = MW_COLON_STATE_TAG
- elif state == 3: # MW_COLON_STATE_CLOSETAG:
- # In a
- if text[i] == '>':
- stack -= 1
- if stack < 0:
- return False
- state = MW_COLON_STATE_TEXT
- elif state == MW_COLON_STATE_TAGSLASH:
- if text[i] == '>':
- # Yes, a self-closed tag
- state = MW_COLON_STATE_TEXT
- else:
- # Probably we're jumping the gun, and this is an attribute
- state = MW_COLON_STATE_TAG
- elif state == 5: # MW_COLON_STATE_COMMENT:
- if text[i] == '-':
- state = MW_COLON_STATE_COMMENTDASH
- elif state == MW_COLON_STATE_COMMENTDASH:
- if text[i] == '-':
- state = MW_COLON_STATE_COMMENTDASHDASH
- else:
- state = MW_COLON_STATE_COMMENT
- elif state == MW_COLON_STATE_COMMENTDASHDASH:
- if text[i] == '>':
- state = MW_COLON_STATE_TEXT
- else:
- state = MW_COLON_STATE_COMMENT
- else:
- raise
- if stack > 0:
- return False
- return False
-
- def doBlockLevels(self, text, linestart):
- # Parsing through the text line by line. The main thing
- # happening here is handling of block-level elements p, pre,
- # and making lists from lines starting with * # : etc.
- lastPrefix = u''
- mDTopen = inBlockElem = False
- prefixLength = 0
- paragraphStack = False
- _closeMatchPat = re.compile(ur"(
0:
- tmpOutput, tmpMDTopen = self.nextItem(pref[commonPrefixLength-1], mDTopen)
- output.append(tmpOutput)
- if tmpMDTopen is not None:
- mDTopen = tmpMDTopen
-
- while prefixLength > commonPrefixLength:
- char = pref[commonPrefixLength:commonPrefixLength+1]
- tmpOutput, tmpMDTOpen = self.openList(char, mLastSection)
- if tmpMDTOpen:
- mDTopen = True
- output.append(tmpOutput)
- mLastSection = u''
- mInPre = False
-
- if char == u';':
- # FIXME: This is dupe of code above
- term = t2 = u''
- z = self.findColonNoLinks(t, term, t2)
- if z != False:
- term, t2 = z[1:2]
- t = t2
- output.append(term)
- tmpOutput, tmpMDTopen = self.nextItem(u':', mDTopen)
- output.append(tmpOutput)
- if tmpMDTopen is not None:
- mDTopen = tmpMDTopen
-
- commonPrefixLength += 1
-
- lastPrefix = pref2
-
- if prefixLength == 0:
- # No prefix (not in list)--go to paragraph mode
- # XXX: use a stack for nestable elements like span, table and div
- openmatch = _openMatchPat.search(t)
- closematch = _closeMatchPat.search(t)
- if openmatch or closematch:
- paragraphStack = False
- output.append(self.closeParagraph(mLastSection))
- mLastSection = u''
- if preCloseMatch:
- mInPre = False
- if preOpenMatch:
- mInPre = True
- inBlockElem = bool(not closematch)
- elif not inBlockElem and not mInPre:
- if t[0:1] == u' ' and (mLastSection == u'pre' or t.strip() != u''):
- # pre
- if mLastSection != u'pre':
- paragraphStack = False
- output.append(self.closeParagraph(u'') + u'')
- mInPre = False
- mLastSection = u'pre'
- t = t[1:]
- else:
- # paragraph
- if t.strip() == u'':
- if paragraphStack:
- output.append(paragraphStack + u'
')
- paragraphStack = False
- mLastSection = u'p'
- else:
- if mLastSection != u'p':
- output.append(self.closeParagraph(mLastSection))
- mLastSection = u''
- mInPre = False
- paragraphStack = u''
- else:
- paragraphStack = u'
'
- else:
- if paragraphStack:
- output.append(paragraphStack)
- paragraphStack = False
- mLastSection = u'p'
- elif mLastSection != u'p':
- output.append(self.closeParagraph(mLastSection) + u'
')
- mLastSection = u'p'
- mInPre = False
-
- # somewhere above we forget to get out of pre block (bug 785)
- if preCloseMatch and mInPre:
- mInPre = False
-
- if paragraphStack == False:
- output.append(t + u"\n")
-
- while prefixLength:
- output.append(self.closeList(pref2[prefixLength-1], mDTopen))
- mDTopen = False
- prefixLength -= 1
-
- if mLastSection != u'':
- output.append(u'' + mLastSection + u'>')
- mLastSection = u''
-
- return ''.join(output)
-
-class Parser(BaseParser):
- def __init__(self, show_toc=True):
- super(Parser, self).__init__()
- self.show_toc = show_toc
-
- def parse(self, text):
- utf8 = isinstance(text, str)
- text = to_unicode(text)
- if text[-1:] != u'\n':
- text = text + u'\n'
- taggedNewline = True
- else:
- taggedNewline = False
-
- text = self.strip(text)
- text = self.removeHtmlTags(text)
- text = self.doTableStuff(text)
- text = self.parseHorizontalRule(text)
- text = self.checkTOC(text)
- text = self.parseHeaders(text)
- text = self.parseAllQuotes(text)
- text = self.replaceExternalLinks(text)
- if not self.show_toc and text.find(u"") == -1:
- self.show_toc = False
- text = self.formatHeadings(text, True)
- text = self.unstrip(text)
- text = self.fixtags(text)
- text = self.doBlockLevels(text, True)
- text = self.unstripNoWiki(text)
- text = text.split(u'\n')
- text = u'\n'.join(text)
- if taggedNewline and text[-1:] == u'\n':
- text = text[:-1]
- if utf8:
- return text.encode("utf-8")
- return text
-
- def checkTOC(self, text):
- if text.find(u"__NOTOC__") != -1:
- text = text.replace(u"__NOTOC__", u"")
- self.show_toc = False
- if text.find(u"__TOC__") != -1:
- text = text.replace(u"__TOC__", u"")
- self.show_toc = True
- return text
-
- def doTableStuff(self, text):
- t = text.split(u"\n")
- td = [] # Is currently a td tag open?
- ltd = [] # Was it TD or TH?
- tr = [] # Is currently a tr tag open?
- ltr = [] # tr attributes
- has_opened_tr = [] # Did this table open a
element?
- indent_level = 0 # indent level of the table
-
- for k, x in zip(range(len(t)), t):
- x = x.strip()
- fc = x[0:1]
- matches = _zomgPat.match(x)
- if matches:
- indent_level = len(matches.group(1))
-
- attributes = self.unstripForHTML(matches.group(2))
-
- t[k] = u'- '*indent_level + u'
'
- td.append(False)
- ltd.append(u'')
- tr.append(False)
- ltr.append(u'')
- has_opened_tr.append(False)
- elif len(td) == 0:
- pass
- elif u'|}' == x[0:2]:
- z = u"
" + x[2:]
- l = ltd.pop()
- if not has_opened_tr.pop():
- z = u" |
" + z
- if tr.pop():
- z = u"
" + z
- if td.pop():
- z = u'' + l + u'>' + z
- ltr.pop()
- t[k] = z + u'
'*indent_level
- elif u'|-' == x[0:2]: # Allows for |-------------
- x = x[1:]
- while x != u'' and x[0:1] == '-':
- x = x[1:]
- z = ''
- l = ltd.pop()
- has_opened_tr.pop()
- has_opened_tr.append(True)
- if tr.pop():
- z = u'
' + z
- if td.pop():
- z = u'' + l + u'>' + z
- ltr.pop()
- t[k] = z
- tr.append(False)
- td.append(False)
- ltd.append(u'')
- attributes = self.unstripForHTML(x)
- ltr.append(self.fixTagAttributes(attributes, u'tr'))
- elif u'|' == fc or u'!' == fc or u'|+' == x[0:2]: # Caption
- # x is a table row
- if u'|+' == x[0:2]:
- fc = u'+'
- x = x[1:]
- x = x[1:]
- if fc == u'!':
- x = x.replace(u'!!', u'||')
- # Split up multiple cells on the same line.
- # FIXME: This can result in improper nesting of tags processed
- # by earlier parser steps, but should avoid splitting up eg
- # attribute values containing literal "||".
- x = x.split(u'||')
-
- t[k] = u''
-
- # Loop through each table cell
- for theline in x:
- z = ''
- if fc != u'+':
- tra = ltr.pop()
- if not tr.pop():
- z = u'\n'
- tr.append(True)
- ltr.append(u'')
- has_opened_tr.pop()
- has_opened_tr.append(True)
- l = ltd.pop()
- if td.pop():
- z = u'' + l + u'>' + z
- if fc == u'|':
- l = u'td'
- elif fc == u'!':
- l = u'th'
- elif fc == u'+':
- l = u'caption'
- else:
- l = u''
- ltd.append(l)
-
- #Cell parameters
- y = theline.split(u'|', 1)
- # Note that a '|' inside an invalid link should not
- # be mistaken as delimiting cell parameters
- if y[0].find(u'[[') != -1:
- y = [theline]
-
- if len(y) == 1:
- y = z + u"<" + l + u">" + y[0]
- else:
- attributes = self.unstripForHTML(y[0])
- y = z + u"<" + l + self.fixTagAttributes(attributes, l) + u">" + y[1]
-
- t[k] += y
- td.append(True)
-
- while len(td) > 0:
- l = ltd.pop()
- if td.pop():
- t.append(u'')
- if tr.pop():
- t.append(u'
')
- if not has_opened_tr.pop():
- t.append(u' |
')
- t.append(u'')
-
- text = u'\n'.join(t)
- # special case: don't return empty table
- if text == u"
":
- text = u''
-
- return text
-
- def formatHeadings(self, text, isMain):
- """
- This function accomplishes several tasks:
- 1) Auto-number headings if that option is enabled
- 2) Add an [edit] link to sections for logged in users who have enabled the option
- 3) Add a Table of contents on the top for users who have enabled the option
- 4) Auto-anchor headings
-
- It loops through all headlines, collects the necessary data, then splits up the
- string and re-inserts the newly formatted headlines.
- """
- doNumberHeadings = False
- showEditLink = True # Can User Edit
-
- if text.find(u"__NOEDITSECTION__") != -1:
- showEditLink = False
- text = text.replace(u"__NOEDITSECTION__", u"")
-
- # Get all headlines for numbering them and adding funky stuff like [edit]
- # links - this is for later, but we need the number of headlines right now
- matches = _headerPat.findall(text)
- numMatches = len(matches)
-
- # if there are fewer than 4 headlines in the article, do not show TOC
- # unless it's been explicitly enabled.
- enoughToc = self.show_toc and (numMatches >= 4 or text.find(u"") != -1)
-
- # Allow user to stipulate that a page should have a "new section"
- # link added via __NEWSECTIONLINK__
- showNewSection = False
- if text.find(u"__NEWSECTIONLINK__") != -1:
- showNewSection = True
- text = text.replace(u"__NEWSECTIONLINK__", u"")
- # if the string __FORCETOC__ (not case-sensitive) occurs in the HTML,
- # override above conditions and always show TOC above first header
- if text.find(u"__FORCETOC__") != -1:
- self.show_toc = True
- enoughToc = True
- text = text.replace(u"__FORCETOC__", u"")
- # Never ever show TOC if no headers
- if numMatches < 1:
- enoughToc = False
-
- # headline counter
- headlineCount = 0
- sectionCount = 0 # headlineCount excluding template sections
-
- # Ugh .. the TOC should have neat indentation levels which can be
- # passed to the skin functions. These are determined here
- toc = []
- head = {}
- sublevelCount = {}
- levelCount = {}
- toclevel = 0
- level = 0
- prevlevel = 0
- toclevel = 0
- prevtoclevel = 0
- refers = {}
- refcount = {}
- wgMaxTocLevel = 5
-
- for match in matches:
- headline = match[2]
- istemplate = False
- templatetitle = u''
- templatesection = 0
- numbering = []
-
- m = _templateSectionPat.search(headline)
- if m:
- istemplate = True
- templatetitle = b64decode(m[0])
- templatesection = 1 + int(b64decode(m[1]))
- headline = _templateSectionPat.sub(u'', headline)
-
- if toclevel:
- prevlevel = level
- prevtoclevel = toclevel
-
- level = matches[headlineCount][0]
-
- if doNumberHeadings or enoughToc:
- if level > prevlevel:
- toclevel += 1
- sublevelCount[toclevel] = 0
- if toclevel < wgMaxTocLevel:
- toc.append(u'\n')
- elif level < prevlevel and toclevel > 1:
- # Decrease TOC level, find level to jump to
-
- if toclevel == 2 and level < levelCount[1]:
- toclevel = 1
- else:
- for i in range(toclevel, 0, -1):
- if levelCount[i] == level:
- # Found last matching level
- toclevel = i
- break
- elif levelCount[i] < level:
- toclevel = i + 1
- break
- if toclevel < wgMaxTocLevel:
- toc.append(u"\n")
- toc.append(u"
\n\n" * max(prevtoclevel - toclevel, 0))
- else:
- if toclevel < wgMaxTocLevel:
- toc.append(u"\n")
-
- levelCount[toclevel] = level
-
- # count number of headlines for each level
- sublevelCount[toclevel] += 1
- for i in range(1, toclevel+1):
- if sublevelCount[i]:
- numbering.append(to_unicode(sublevelCount[i]))
-
- # The canonized header is a version of the header text safe to use for links
- # Avoid insertion of weird stuff like