From 0de9564361bba94e05e2d6b5d31db74a43b514e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Mon, 24 Sep 2012 16:03:11 +0200 Subject: [PATCH 01/10] mention about indexer run --- README | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README b/README index e0b4b79..5dd6914 100644 --- a/README +++ b/README @@ -18,12 +18,14 @@ $ ./moin2doku.py -a -d /var/lib/dokuwiki To convert single page (FrontPage): $ ./moin2doku.py -F moinmoin/data/pages/FrontPage -d out -after conversion be sure to fix ownership +You should invoke bin/indexer.php after conversion to make all pages are indexed. + +and ensure ownership of files is correct: (www-data:www-data being your uid/gid webserver runs): # chown -R www-data:www-data /var/lib/dokuwiki/pages/* # chown -R www-data:www-data /var/lib/dokuwiki/media/* -also, depending on your configuration, you may need to gzip the attic pages. +additionally, depending on your configuration, you may need to gzip the attic pages. History: version 0.1 2010-02 From f2f079986eb6f3e00b8d3d871d0670899dd2ef00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Fri, 31 Jul 2015 11:02:03 +0300 Subject: [PATCH 02/10] rename readme to markdown --- README => README.md | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) rename README => README.md (55%) diff --git a/README b/README.md similarity index 55% rename from README rename to README.md index 5dd6914..b541a69 100644 --- a/README +++ b/README.md @@ -1,4 +1,5 @@ Complete MoinMoin to DokuWiki converter +======================================= Uses native MoinMoin modules to handle converting and translating paths. Converts also page history and edit-log. @@ -13,29 +14,42 @@ it uses current configuration from both wikis. Edit doku.php if your DokuWiki installation is other than /usr/share/dokuwiki To convert moinmoin all pages with history, invoke: +``` $ ./moin2doku.py -a -d /var/lib/dokuwiki +``` To convert single page (FrontPage): +``` $ ./moin2doku.py -F moinmoin/data/pages/FrontPage -d out +``` -You should invoke bin/indexer.php after conversion to make all pages are indexed. +You should invoke `bin/indexer.php` after conversion to make all pages are indexed. and ensure ownership of files is correct: -(www-data:www-data being your uid/gid webserver runs): +(`www-data:www-data` being your uid/gid webserver runs): +``` # chown -R www-data:www-data /var/lib/dokuwiki/pages/* # chown -R www-data:www-data /var/lib/dokuwiki/media/* - +``` additionally, depending on your configuration, you may need to gzip the attic pages. -History: -version 0.1 2010-02 - Slim Gaillard, based on the "extended python" convert.py script here: - https://www.dokuwiki.org/tips:moinmoin2doku?rev=1297006559#extended_python +History +======= -version 0.2 2011 - Elan Ruusamäe, moved to github, track history there - https://github.com/glensc/moin2doku +version 0.1 (2010-02) +------------------- -version 1.0 2012 - Complete moinmoin to dokuwiki converter, uses native moinmoin code to handle - converting and translating paths. Converts also page history and edit-log. +Slim Gaillard, based on the "extended python" convert.py script here: +https://www.dokuwiki.org/tips:moinmoin2doku?rev=1297006559#extended_python + +version 0.2 (2011) +---------------- + +Elan Ruusamäe, moved to github, track history there +https://github.com/glensc/moin2doku + +version 1.0 (2012) +---------------- + +Complete moinmoin to dokuwiki converter, uses native moinmoin code to handle +converting and translating paths. Converts also page history and edit-log. From 8117b6a1e29829b67f8aef74a44579b43efc5b89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Fri, 31 Jul 2015 11:06:40 +0300 Subject: [PATCH 03/10] add note that i do not develop/support this code anymore --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index b541a69..0297c68 100644 --- a/README.md +++ b/README.md @@ -53,3 +53,7 @@ version 1.0 (2012) Complete moinmoin to dokuwiki converter, uses native moinmoin code to handle converting and translating paths. Converts also page history and edit-log. + +This marks the project "done", I will no longer develop it or support it, as I got my conversion done. However, I do accept patches (pull requests) to sane amount. + +I put repo online so others have better starting point than I did. From eb469fe3560ed62ebd165f77ddebf131cd7cd3a8 Mon Sep 17 00:00:00 2001 From: Lukas P Date: Tue, 5 Jan 2016 17:13:48 +0100 Subject: [PATCH 04/10] =?UTF-8?q?Anpassungen=20f=C3=BCr=20neue=20Moin=20Ve?= =?UTF-8?q?rsion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doku.php | 2 +- doku.pyc | Bin 0 -> 1642 bytes moin2doku.py | 10 +- moinformat.py | 14 +- moinformat.pyc | Bin 0 -> 1242 bytes output.txt | 238 ++++++++++++++++ standalone.py | 22 ++ syntaxreference.txt | 2 +- text_dokuwiki.py | 674 ++++++++++++++++++++++---------------------- text_dokuwiki.pyc | Bin 0 -> 13780 bytes 10 files changed, 617 insertions(+), 345 deletions(-) create mode 100644 doku.pyc create mode 100644 moinformat.pyc create mode 100644 output.txt create mode 100644 standalone.py create mode 100644 text_dokuwiki.pyc diff --git a/doku.php b/doku.php index d7a8660..50714df 100755 --- a/doku.php +++ b/doku.php @@ -13,7 +13,7 @@ if ('cli' != php_sapi_name()) die(); -define('DOKU_INC', '/usr/share/dokuwiki/'); +define('DOKU_INC', '/home/caddy/wikifarm/dokuwiki/dokuwiki/'); require_once DOKU_INC.'inc/init.php'; require_once DOKU_INC.'inc/common.php'; require_once DOKU_INC.'inc/cliopts.php'; diff --git a/doku.pyc b/doku.pyc new file mode 100644 index 0000000000000000000000000000000000000000..78db648323cf9f6823de3c1ff4202d0f51daeb97 GIT binary patch literal 1642 zcmbVM$!-%t5UsYI#aRFa1o90D1^E!L1Q&#&2(bvbSkVN5$fY$*x8rd<9&5U-C{l6? z0uEgG7Vi8M9{}&wWZ`N?Q`ObowJ+WLy}q*bBY&UC`Pany3=n!i4!@DH$o?g5WZ#Hu zh--;!%4d-?k&pY>8`NQA~XOm0AU>{7da8J>epVE*L}sY4Kho|<1EdFzCLPE$d3nItfDB~2h|&v zh3{plbH}|SxH(9xqF0pp9RzhHE`qJ_aag*9&di;bB?ui=>2&JdEs*C~sZ&ga2@NFVQtP!5 zx~UiQ6oBQUCCwK%Vm2DJAtpsN*VdM?tuNFN-I&MFD)_BE@G*_CvUY>wwY}>tEjL42 z0lenTFQAADG+1BM8bwFh(7huNdWeeNK5ep3M>qx1By0G|$pPzu_Q##mmc*8f7UTpY zg&!@wpeIY>76t7$YKvQvxB}tUXq5wZ3WhZ~SrE4@ozc3uHWlNqO~KB#TcN(oeTTlh zelyXIfj403>~$G%KX7U{!_&9Rn-GGE`zrN z7ciFKrpPP~9y|%m*k*XJvl+VAKq63)aUP-)Bg|Stn~`lYOoKi2$A}XeW}l{2nfVaZ z{BAk*6BX%~6R*VX+uc`@9Z=N4^*5LPS?tZx~Fh9S3A)_J%4-|bZ*70nU2{oH_T&m7nHu3=P%48ExffFzO_Z^ zW@Bs # Version: 1.0 - -from MoinMoin import wikimacro, wikiutil +#from MoinMoin.web.request import Request as RequestCLI +from MoinMoin.web.contexts import ScriptContext +from MoinMoin import wikiutil from MoinMoin.Page import Page -from MoinMoin.parser.wiki import Parser +from MoinMoin.parser.text_moin_wiki import Parser from text_dokuwiki import Formatter -from MoinMoin.request import RequestCLI import sys import StringIO @@ -37,7 +37,7 @@ def moin2doku(pagename, text): return unicode(output.getvalue().decode('utf-8')) -request = RequestCLI() +request = ScriptContext() formatter = Formatter(request) if __name__ == "__main__": @@ -47,6 +47,6 @@ if __name__ == "__main__": else: inputfile = 'syntaxreference.txt' - with open(inputfile, 'r') as f: - text = f.read() + f = open(inputfile, 'r') + text = f.read() print moin2doku('test', text) diff --git a/moinformat.pyc b/moinformat.pyc new file mode 100644 index 0000000000000000000000000000000000000000..bad5d0ec365a6fc660e43a5ec56c59851e8ecb64 GIT binary patch literal 1242 zcmb7CJCD;q5dL-@CvoDCkb58+M418-iHZUtq?33Q9LSL<+*l^w98UZQ_WJH3zJ6%sAX?B)(y9D6d~ymscBb$$+dzsCB*0{h3I{}=StKS(6>3S>Yo5DEy!5}8Eq zAapEtkhPGz2wjU?$lAy|2s;+L$hycqgr3E1WIcpEQ=9ZY!akA?z5<~SC2&p30Lp_J z;F^xT12sg_#ag2J4mE=6VRe^XiHCIy)wjKc;QernqK$+O7(*REjgjACj*)|{Y}qAkfs^V7gf5^CuO14rMBiSnJ?0H+UPX1mKIsw z$7jl-wn0^`DvLeBFUu;AwN};XLK5T<=J|xa`U?pS>;yCoFL5QI=@p1bI;`wq?4(Pq zTG%-}ywEOIF3)q-f^K8g!Ig`h(W4G_6x!tk4&AvNL00W?#Hz<>E25naH1B-EZJpLG z$wn_9Kb`ob1>B?Vkf_w>M%9|qf#uCC0p}QZtu)WCnVPw-(&FsRJ8GSV+tze2{p+M` zv{CozT(v3EMVZ(%%07>?MwysIv3Ve2Evo3xhTrxw1}dV8>tUiYzrMt0Q^V}6_Wjp-a*v?q+Ha`|{-zh| z<8)!~SsjqWPJZJKIN#jJ8_Sd#w<~z?Zyn3Zlv#>$Dje~=c9VRejh%-!X67^Cr3SpZ zfaeVO4g|N#pragma section-numbers off +#acl All:admin,read,write,delete,revert +#language en +This page tries to use each supported markup element at least once. + + + +'''Index''' +[[TableOfContents(2)]] +**Index** + +[[:TableOfContents(2)|TableOfContents(2)]] + + + +====== Headers ====== + + +===== Header 2 ===== + + +==== Header 3 ==== + + +=== Header 4 === + + +== Header 5 == + + +====== Font styles ====== + + +Normal text, ''emphasized'', '''strong''', __underline__, ,,subscript,,, ^superscript^, `typewriter` and {{{typewriter +.}}} + +Normal text, //emphasized//, **strong**, __underline__, subscript, superscript, ''typewriter'' and ''typewriter''. + + + +===== Syntax Highlighting ===== + + * +# python code +print code.colorize("abc", 1 + 1) + + +====== Hyperlinks ====== + + +===== Internal ===== + + + * MoinMoin + * MoinMoin/TextFormatting + * MoinMoin/InstallDocs + * ../InstallDocs + * /SubPage + * Self:InterWiki + + * [[:MoinMoin|MoinMoin]] + * [[:MoinMoin:TextFormatting|MoinMoin/TextFormatting]] + * [[:MoinMoin:InstallDocs|MoinMoin/InstallDocs]] + * [[:InstallDocs|../InstallDocs]] + * [[:test:SubPage|/SubPage]] + * [[:InterWiki|InterWiki]] + + +[#anchorname Anchor Link] +[#anchorname Anchor Link] + + + +===== External ===== + + + * http://moinmoin.wikiwikiweb.de/ + * [http://moinmoin.wikiwikiweb.de/] + * [http://moinmoin.wikiwikiweb.de/ MoinMoin Wiki] + * [http://moinmoin.wikiwikiweb.de/wiki/classic/img/moinmoin.png] + * http://moinmoin.wikiwikiweb.de/wiki/classic/img/moinmoin.png + * [http://moinmoin.wikiwikiweb.de/wiki/classic/img/moinmoin.png moinmoin.png] + * MeatBall:InterWiki + * wiki:MeatBall/InterWiki + * [wiki:MeatBall/InterWiki] + * [wiki:MeatBall/InterWiki InterWiki page on MeatBall] + * [file://servername/full/path/to/file/filename%20with%20spaces.txt Click here to read filename with spaces.txt] + * me@privacy.net + + * [[http://moinmoin.wikiwikiweb.de/|http://moinmoin.wikiwikiweb.de/]] + * [[[http://moinmoin.wikiwikiweb.de/|http://moinmoin.wikiwikiweb.de/]]] + * [[[http://moinmoin.wikiwikiweb.de/|http://moinmoin.wikiwikiweb.de/]] [[:MoinMoin|MoinMoin]] Wiki] + * [[[http://moinmoin.wikiwikiweb.de/wiki/classic/img/moinmoin.png|http://moinmoin.wikiwikiweb.de/wiki/classic/img/moinmoin.png]]] + * [[http://moinmoin.wikiwikiweb.de/wiki/classic/img/moinmoin.png|http://moinmoin.wikiwikiweb.de/wiki/classic/img/moinmoin.png]] + * [[[http://moinmoin.wikiwikiweb.de/wiki/classic/img/moinmoin.png|http://moinmoin.wikiwikiweb.de/wiki/classic/img/moinmoin.png]] moinmoin.png] + * [[MeatBall>InterWiki|InterWiki]] + * wiki:[[:MeatBall:InterWiki|MeatBall/InterWiki]] + * [wiki:[[:MeatBall:InterWiki|MeatBall/InterWiki]]] + * [wiki:[[:MeatBall:InterWiki|MeatBall/InterWiki]] [[:InterWiki|InterWiki]] page on [[:MeatBall|MeatBall]]] + * [[[file://servername/full/path/to/file/filename%20with%20spaces.txt|file://servername/full/path/to/file/filename%20with%20spaces.txt]] Click here to read filename with spaces.txt] + * [[mailto:me@privacy.net|me@privacy.net]] + + +===== Escaping WikiNames ===== + + +Wiki''''''Name +Wiki``Name +Wiki****Name Wiki''''Name + + + +====== Blockquote ====== + + + This is indented + Even more + + * This is indented + * Even more + + + +====== Bullet list ====== + + + * item 1 + + * item 2, with gap + * item 3 + * item 3.1 + + * item 1 + * item 2, with gap + * item 3 + * item 3.1 + + + +====== Numbered list ====== + + + 1. item 1 + i. item 1 + i. item 2 + + - item 1 + - item 1 + - item 2 + + + + 1. item 2 + a. item 1 + a. item 2 + + - item 2 + - item 1 + - item 2 + + + +====== Descriptions + Definitions ====== + + + Term:: Description + Label:: Definition +Description Definition + +====== Code display ====== + + * line 1 + indented 4 characters + + + +====== Tables ====== + + +===== General table layout and HTML like options ===== + + + ||cell 1||cell2||cell 3|| + + * +|cell 1|cell2|cell 3| + + +====== Rules ====== + + +--- (not a rule) +---- +----- +------ +------- +-------- +--------- +---------- +-------------------------------------------- (not thicker than 10) +--- (not a rule) + + + + +- + + +-- + + +--- + + +---- + + +---- + + +---- + + +---- + (not thicker than 10) + + + +====== Macros ====== + + +[[Anchor(anchorname)]] +'''[[PageCount]]''' pages +[[:Anchor(anchorname)|Anchor(anchorname)]] **[[:PageCount|PageCount]]** pages + + diff --git a/standalone.py b/standalone.py new file mode 100644 index 0000000..413a450 --- /dev/null +++ b/standalone.py @@ -0,0 +1,22 @@ +from MoinMoin.server.standalone import StandaloneConfig, run + +import sys +# Path of the directory where wikiconfig.py is located. +# YOU NEED TO CHANGE THIS TO MATCH YOUR SETUP. +sys.path.insert(0, 'home/caddy/wikifarm/var/wikifarm/config') + +# Path to MoinMoin package, needed if you installed with --prefix=PREFIX +# or if you did not use setup.py. +sys.path.insert(0, '/usr/local/lib/python2.4/site-packages') + +# Path of the directory where farmconfig.py is located (if different). +sys.path.insert(0, '/home/caddy/wikifarm/var/wikifarm/config') + +class Config(StandaloneConfig): + docs = '/home/caddy/wikifarm/var/wikifarm' + user = 'http' + group = 'http' + port = 80 + +run(Config) + \ No newline at end of file diff --git a/syntaxreference.txt b/syntaxreference.txt index ea5bca2..d824f2d 100644 --- a/syntaxreference.txt +++ b/syntaxreference.txt @@ -182,4 +182,4 @@ line 1 '''[[PageCount]]''' pages }}} [[Anchor(anchorname)]] -'''[[PageCount]]''' pages +'''[[PageCount]]''' pages \ No newline at end of file diff --git a/text_dokuwiki.py b/text_dokuwiki.py index 02f93b5..cb444f8 100644 --- a/text_dokuwiki.py +++ b/text_dokuwiki.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # Setup VIM: ex: noet ts=2 sw=2 : """ - MoinMoin - Dokuwiki Formatter + MoinMoin - Dokuwiki Formatter - @copyright: 2000, 2001, 2002 by Jürgen Hermann - @copyright: 2011-2012 Elan Ruusamäe - @license: GNU GPL, see COPYING for details. + @copyright: 2000, 2001, 2002 by Jürgen Hermann + @copyright: 2011-2012 Elan Ruusamäe + @license: GNU GPL, see COPYING for details. """ from xml.sax import saxutils -from MoinMoin.formatter.base import FormatterBase +from MoinMoin.formatter import FormatterBase from MoinMoin import config from MoinMoin.Page import Page from types import * @@ -17,330 +17,340 @@ from types import * # TODO: let base class MoinMoin/formatter/base.py handle not implemented methods class Formatter(FormatterBase): - """ - Send Dokuwiki formatted data. - """ - - hardspace = ' ' -# hardspace = ' ' - - def __init__(self, request, **kw): - apply(FormatterBase.__init__, (self, request), kw) - self._current_depth = 1 - self._base_depth = 0 - self.in_pre = 0 - self.in_table = 0 - self._text = None # XXX does not work with links in headings!!!!! - - self.list_depth = 0 - self.list_type = ' ' - - def _escape(self, text, extra_mapping={"'": "'", '"': """}): - return saxutils.escape(text, extra_mapping) - - def startDocument(self, pagename): - encoding = config.charset - return '\n' % ( - encoding, self._escape(pagename)) - - def endDocument(self): - result = "" - while self._current_depth > 1: - result += "" % self._current_depth - self._current_depth -= 1 - return result + '' - - def lang(self, on, lang_name): - return ('
' % lang_name, '
')[not on] - - def sysmsg(self, on, **kw): - return ('', '')[not on] - - def rawHTML(self, markup): - return '' + markup + '' - - def pagelink(self, on, pagename='', page=None, **kw): - if on: - return '[[:' + ":".join(pagename.split("/")) + "|" - else: - return ']]' - - def interwikilink(self, on, interwiki='', pagename='', **kw): - if on: - if interwiki == 'Self': - return self.pagelink(on, pagename, **kw) - return '[[%s>%s|' % (interwiki, pagename) - else: - return ']]' - - def url(self, on, url='', css=None, **kw): - return ('[[%s|' % (self._escape(url)), ']]')[not on] - - def attachment_link(self, url, text, **kw): - return '{{%s|%s}}' % (url, text) - - def attachment_image(self, url, **kw): - return '{{%s|}}' % (url,) - - def attachment_drawing(self, url, text, **kw): - return '{{%s|%s}}' % (url, text) - - def text(self, text, **kw): - self._did_para = 0 - if self._text is not None: - self._text.append(text) - return text - - def rule(self, size=0, **kw): - # size not supported - if size >= 4: - return '----\n' - else: - return '-' * size + '\n' - - def icon(self, type): - return '' % type - - def strong(self, on, **kw): - return ['**', '**'][not on] - - def emphasis(self, on, **kw): - return ['//', '//'][not on] - - def highlight(self, on, **kw): - return ['**', '**'][not on] - - def number_list(self, on, type=None, start=None, **kw): - # list type not supported - if on: - self.list_depth += 1 - self.list_type = '-' - else: - self.list_depth -= 1 - self.list_type = ' ' - - return ['', '\n'][on] - - def bullet_list(self, on, **kw): - if on: - self.list_depth += 1 - self.list_type = '*' - else: - self.list_depth -= 1 - self.list_type = ' ' - - return ['', '\n'][on] - - def listitem(self, on, **kw): - # somewhy blockquote uses "listitem" call - return [(' ' * self.list_depth * 2) + self.list_type + ' ', '\n'][not on] - - def code(self, on, **kw): - """ `typewriter` or {{{typerwriter}}, for code blocks i hope codeblock works """ - return ["''", "''"][not on] - - def sup(self, on, **kw): - return ['', ''][not on] - - def sub(self, on, **kw): - return ['', ''][not on] - - def strike(self, on, **kw): - return ['', ''][not on] - - def preformatted(self, on, **kw): - FormatterBase.preformatted(self, on) - result = '' - if self.in_p: - result = self.paragraph(0) - return result + ['', '\n'][not on] - - def paragraph(self, on, **kw): - FormatterBase.paragraph(self, on) - if self.in_table or self.list_depth: - return '' - return ['', '\n\n'][not on] - - def linebreak(self, preformatted=1): - return ['\n', '\\\n'][not preformatted] - - def heading(self, on, depth, **kw): - # heading depth reversed in dokuwiki - heading_depth = 7 - depth - - if on: - return u'%s ' % (u'=' * heading_depth) - else: - return u' %s\n' % (u'=' * heading_depth) - - def table(self, on, attrs={}, **kw): - if on: - self.in_table = 1 - else: - self.in_table = 0 - return '' - - def table_row(self, on, attrs={}, **kw): - return ['\n', '|'][not on] - - def table_cell(self, on, attrs={}, **kw): - return ['|', ''][not on] - - def anchordef(self, id): - # not supported - return '' - - def anchorlink(self, on, name='', **kw): - # kw.id not supported, we hope the anchor matches existing heading on page - return ('[[#', ']]') [not on] - - def underline(self, on, **kw): - return ['__', '__'][not on] - - def definition_list(self, on, **kw): - result = '' - if self.in_p: - result = self.paragraph(0) - return result + ['', ''][not on] - - def definition_term(self, on, compact=0, **kw): - return [''][not on] - - def definition_desc(self, on, **kw): - return ['', ''][not on] - - def image(self, src=None, **kw): - valid_attrs = ['src', 'width', 'height', 'alt', 'title'] - - url = src - if '?' in url: - url += '&' - else: - url += '?' - - attrs = {} - for key, value in kw.items(): - if key in valid_attrs: - attrs[key] = value - - # TODO: finish this - if attrs.has_key('width'): - url += attrs['width'] - - return '{{' + url + '}}' - - def code_area(self, on, code_id, code_type='code', show=0, start=-1, step=-1): - syntax = '' - # switch for Python: http://simonwillison.net/2004/may/7/switch/ - try: - syntax = { - 'ColorizedPython': 'python', - 'ColorizedPascal': 'pascal', - 'ColorizedJava': 'java', - 'ColorizedCPlusPlus': 'cpp', - }[code_type] - except KeyError: - pass - - return ('' % syntax , '')[not on] - - def code_line(self, on): - return ('', '\n')[on] - - def code_token(self, on, tok_type): - # not supported - return '' - - def comment(self, text): - # real comments (lines with two hash marks) - if text[0:2] == '##': - return "/* %s */\n" % text[2:].strip() - - # Some kind of Processing Instruction - # http://moinmo.in/HelpOnProcessingInstructions - tokens = text.lstrip('#').split(None, 1) - if tokens[0] in ('language', 'format', 'refresh'): - return '' - - if tokens[0] == 'acl': - # TODO: fill acl.auth.php - return '' - - if tokens[0] == 'deprecated': - return 'This page is deprecated\n' - - if tokens[0] == 'redirect': - return text + "\n" - - if tokens[0] == 'pragma': - # TODO: can do 'description' via 'meta' dokuwiki plugin - return "/* pragma: %s */\n" % " ".join(tokens[1:]) - - return "/* %s */\n" % text.lstrip('#') - - def macro(self, macro_obj, name, args): - def email(args): - mail = args.replace(' AT ', '@') - mail = mail.replace(' DOT ', '.') - return '[[%s|%s]]' % (mail, args) - - # function which will just do what parent class would - def inherit(args): - return apply(FormatterBase.macro, (self, macro_obj, name, args)) - - try: - lookup = { - 'BR' : '\\\\', - 'MailTo' : email, - 'GetText' : args, - 'ShowSmileys' : inherit, - }[name] - except KeyError: - lookup = '/* UndefinedMacro: %s(%s) */' % (name, args) - - if type(lookup) == FunctionType: - text = lookup(args) - else: - text = lookup - return text - - def smiley(self, text): - try: - # https://www.dokuwiki.org/devel:smileys.conf - return { - # note: reverse sorted so that longer smileys get matched first - 'X-(' : ':-X', - '{X}' : ':!:', - '{*}' : '', - '(./)' : u'✓', - ':))' : ':-P', - ':-))' : ':-P', - ':-?' : ':-P', - ':o' : ':-o', - '{OK}' : ':!:', - '{o}' : '', - '{i}' : ':!:', - ':D' : ':-D', - 'B)' : '8-)', - 'B-)' : '8-)', - '{3}' : '<3>', - '{2}' : '<2>', - '{1}' : '<1>', - '(!)' : ':!:', - '/!\\' : ':!:', - ':\\' : ':-\\', - ':))' : ':-)', - ':)' : ':-)', - ':(' : ':-(', - ':-))' : ':-)', - ':-)' : ':-)', - ':-(' : ':-(', - ';)' : ';-)', - '|)' : ':-|', - '|-)' : ':-|', - '>:>' : '^_^', - '' : ':!:', - '<:(' : ':-?', - }[text] - except KeyError: - return text + """ + Send Dokuwiki formatted data. + """ + + hardspace = ' ' +# hardspace = ' ' + + def __init__(self, request, **kw): + apply(FormatterBase.__init__, (self, request), kw) + self._current_depth = 1 + self._base_depth = 0 + self.in_pre = 0 + self.in_table = 0 + self._text = None # XXX does not work with links in headings!!!!! + + self.list_depth = 0 + self.list_type = ' ' + + def _escape(self, text, extra_mapping={"'": "'", '"': """}): + return saxutils.escape(text, extra_mapping) + + def startDocument(self, pagename): + encoding = config.charset + return '\n' % ( + encoding, self._escape(pagename)) + + def endDocument(self): + result = "" + while self._current_depth > 1: + result += "" % self._current_depth + self._current_depth -= 1 + return result + '' + + def lang(self, on, lang_name): + return ('
' % lang_name, '
')[not on] + + def sysmsg(self, on, **kw): + return ('', '')[not on] + + def rawHTML(self, markup): + #return '' + markup + '' + return '' + + def pagelink(self, on, pagename='', page=None, **kw): + if on: + return '[[:' + ":".join(pagename.split("/")) + "|" + else: + return ']]' + + def interwikilink(self, on, interwiki='', pagename='', **kw): + if on: + if interwiki == 'Self': + return self.pagelink(on, pagename, **kw) + return '[[%s>%s|' % (interwiki, pagename) + else: + return ']]' + + def url(self, on, url='', css=None, **kw): + return ('[[%s|' % (self._escape(url)), ']]')[not on] + + def attachment_link(self, on, url=None, querystr=None, **kw): + return '{{ %s | %s }}' % (url, querystr) + + def attachment_image(self, url, **kw): + return '{{%s|}}' % (url,) + + def attachment_drawing(self, url, text, **kw): + return '{{%s|%s}}' % (url, text) + + def text(self, text, **kw): + self._did_para = 0 + if self._text is not None: + self._text.append(text) + return text + + def rule(self, size=0, **kw): + # size not supported + if size >= 4: + return '----\n' + else: + return '-' * size + '\n' + + def icon(self, type): + return '' % type + + def strong(self, on, **kw): + return ['**', '**'][not on] + + def emphasis(self, on, **kw): + return ['//', '//'][not on] + + def highlight(self, on, **kw): + return ['**', '**'][not on] + + def number_list(self, on, type=None, start=None, **kw): + # list type not supported + if on: + self.list_depth += 1 + self.list_type = '-' + else: + self.list_depth -= 1 + self.list_type = ' ' + + return ['', '\n'][on] + + def bullet_list(self, on, **kw): + if on: + self.list_depth += 1 + self.list_type = '*' + else: + self.list_depth -= 1 + self.list_type = ' ' + + return ['', '\n'][on] + + def listitem(self, on, **kw): + # somewhy blockquote uses "listitem" call + return [(' ' * self.list_depth * 2) + self.list_type + ' ', '\n'][not on] + + def code(self, on, **kw): + """ `typewriter` or {{{typerwriter}}, for code blocks i hope codeblock works """ + return ["''", "''"][not on] + + def sup(self, on, **kw): + return ['', ''][not on] + + def sub(self, on, **kw): + return ['', ''][not on] + + def strike(self, on, **kw): + return ['', ''][not on] + + def preformatted(self, on, **kw): + FormatterBase.preformatted(self, on) + result = '' + if self.in_p: + result = self.paragraph(0) + return result + ['', '\n'][not on] + + def paragraph(self, on, **kw): + FormatterBase.paragraph(self, on) + if self.in_table or self.list_depth: + return '' + return ['', '\n\n'][not on] + + def linebreak(self, preformatted=1): + return ['\n', '\\\n'][not preformatted] + + def heading(self, on, depth, **kw): + # heading depth reversed in dokuwiki + heading_depth = 7 - depth + + if on: + return u'%s ' % (u'=' * heading_depth) + else: + return u' %s\n' % (u'=' * heading_depth) + + def table(self, on, attrs={}, **kw): + if on: + self.in_table = 1 + else: + self.in_table = 0 + return '' + + def table_row(self, on, attrs={}, **kw): + return ['\n', '|'][not on] + + def table_cell(self, on, attrs={}, **kw): + return ['|', ''][not on] + + def anchordef(self, id): + # not supported + return '' + + def anchorlink(self, on, name='', **kw): + # kw.id not supported, we hope the anchor matches existing heading on page + return ('[[#', ']]') [not on] + + def underline(self, on, **kw): + return ['__', '__'][not on] + + def definition_list(self, on, **kw): + result = '' + if self.in_p: + result = self.paragraph(0) + return result + ['', ''][not on] + + def definition_term(self, on, compact=0, **kw): + return [''][not on] + + def definition_desc(self, on, **kw): + return ['', ''][not on] + + def image(self, src=None, **kw): + valid_attrs = ['src', 'width', 'height', 'alt', 'title'] + + url = src + if '?' in url: + url += '&' + else: + url += '?' + + attrs = {} + for key, value in kw.items(): + if key in valid_attrs: + attrs[key] = value + + # TODO: finish this + if attrs.has_key('width'): + url += attrs['width'] + + return '{{' + url + '}}' + + def code_area(self, on, code_id, code_type='code', show=0, start=-1, step=-1,msg=None): + syntax = '' + # switch for Python: http://simonwillison.net/2004/may/7/switch/ + try: + syntax = { + 'ColorizedPython': 'python', + 'ColorizedPascal': 'pascal', + 'ColorizedJava': 'java', + 'ColorizedCPlusPlus': 'cpp', + }[code_type] + except KeyError: + pass + + return ('' % syntax , '')[not on] + + def code_line(self, on): + return ('', '\n')[on] + + def code_token(self, on, tok_type): + # not supported + return '' + + def comment(self, text): + # real comments (lines with two hash marks) + if text[0:2] == '##': + #return "/* %s */\n" % text[2:].strip() + return '' + + # Some kind of Processing Instruction + # http://moinmo.in/HelpOnProcessingInstructions + tokens = text.lstrip('#').split(None, 1) + if tokens[0] in ('language', 'format', 'refresh'): + return '' + + if tokens[0] == 'acl': + # TODO: fill acl.auth.php + return '' + + if tokens[0] == 'deprecated': + return 'This page is deprecated\n' + + if tokens[0] == 'redirect': + return text + "\n" + + if tokens[0] == 'pragma': + # TODO: can do 'description' via 'meta' dokuwiki plugin + #return "/* pragma: %s */\n" % " ".join(tokens[1:]) + return '' + + #return "/* %s */\n" % text.lstrip('#') + return '' + + + def macro(self, macro_obj, name, args,markup): + def email(args): + mail = args.replace(' AT ', '@') + mail = mail.replace(' DOT ', '.') + return '[[%s|%s]]' % (mail, args) + + def showAttachedFiles(args): + args = args.split(',') + return self.attachment_link(1,url=args[0].strip(),querystr=args[1].strip()) + + # function which will just do what parent class would + def inherit(args): + return apply(FormatterBase.macro, (self, macro_obj, name, args)) + + try: + lookup = { + 'BR' : '\\\\', + 'MailTo' : email, + 'GetText' : args, + 'ShowSmileys' : inherit, + 'ShowAttachedFiles' : showAttachedFiles + }[name] + except KeyError: + lookup = '/* UndefinedMacro: %s(%s) */' % (name, args) + + if type(lookup) == FunctionType: + text = lookup(args) + else: + text = lookup + return text + + def smiley(self, text): + try: + # https://www.dokuwiki.org/devel:smileys.conf + return { + # note: reverse sorted so that longer smileys get matched first + 'X-(' : ':-X', + '{X}' : ':!:', + '{*}' : '', + '(./)' : u'✓', + ':))' : ':-P', + ':-))' : ':-P', + ':-?' : ':-P', + ':o' : ':-o', + '{OK}' : ':!:', + '{o}' : '', + '{i}' : ':!:', + ':D' : ':-D', + 'B)' : '8-)', + 'B-)' : '8-)', + '{3}' : '<3>', + '{2}' : '<2>', + '{1}' : '<1>', + '(!)' : ':!:', + '/!\\' : ':!:', + ':\\' : ':-\\', + ':))' : ':-)', + ':)' : ':-)', + ':(' : ':-(', + ':-))' : ':-)', + ':-)' : ':-)', + ':-(' : ':-(', + ';)' : ';-)', + '|)' : ':-|', + '|-)' : ':-|', + '>:>' : '^_^', + '' : ':!:', + '<:(' : ':-?', + }[text] + except KeyError: + return text diff --git a/text_dokuwiki.pyc b/text_dokuwiki.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cbff1eb331be1a1d81e5e3111531c6bdd58999af GIT binary patch literal 13780 zcmcIr&2Jn>cCVfp4ml(x>dTU7$x@RNr6DD9M9C|ADVmZ+efUdbxhbz?N%puo-6C6@ z=^l6YnBtN=1QON;HXlef0fNOMd&mcJ$sxA@33A8+0dfce1js*-Taesx36R6)_j}bn zGa{`RD~?EZ)vN02s#ov5dhgY%V)nmx^{@QrPk&TZ$xjyf6+F>nB#u(|ks8X$sG6bb z8FfFS43@L1mR0qfx}VeKoT~MxdS2bn>vE5(^{RTGy5FbEc~vW@J5H~1bLtVk?^Dl| zdaBfC_xqJoPz%L=j``0>`c3@Y3Ot{WIcZ)CR+_8cif7&k!nz&DZrCqPu2h4@TIek; z$1~>nbLY;TWjZbCd2?~i{NPuA7cRNJ`JRipyW)*g9NZu()(tGa&V&X_mLpPDyse{|N2T-Tic`1WV- zmv5Sng3xr_*!F7CRKNFY{1gpLEAHb2?I+C`FLcc=)U+mb)s9?Uokw*w@E>_gx|~D# zw!M_RWnU9aJk+3=Qx}~c<>Zm|s%L0| zg75`Q1W(wuS2_Ix^eJaRfP!)c1pwc6Dd&gE*{z;IE(WEDnjt9y&~NuhaksQYa4l3t$0S=`-ACaC9E9a=x z4=d*l0bW;PAX?i&=^t9DXAP)9#+F? zsXQTYQQ(sTj|)7eoC#@sN+@tfDo-ottW*}2GbzBhOmj-!PAI1&m1krw=cMwia;Bxt zdF9{_q`RP=^{D%k%6U^7PbudI0+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gIL(o}l5 z6}JEJAbqE=j+2FH&D3pp(H7UH4oJX)L^8215J-e@R*T&n1x-%$^Kf4EZ-4Ip04|3` Aj{pDw literal 0 HcmV?d00001 From ac22cb54c2989e484469543d9c5995488bc8b8c9 Mon Sep 17 00:00:00 2001 From: Lukas P Date: Wed, 6 Jan 2016 16:55:45 +0100 Subject: [PATCH 05/10] Collision avoidance for attachments in same namespace --- doku.py | 2 +- moin2doku.py | 16 +++++++++++----- moinformat.py | 4 +++- text_dokuwiki.py | 19 +++++++++++++------ 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/doku.py b/doku.py index ad94aa9..a70abe5 100644 --- a/doku.py +++ b/doku.py @@ -29,5 +29,5 @@ class DokuWiki: cmd = ['./doku.php', method ] + args res = subprocess.Popen(cmd, stdin = None, stdout = subprocess.PIPE, stderr = sys.stderr, close_fds = True).communicate() self.callcache[key] = unicode(res[0].decode('utf-8')) - print "%s->%s" % (cmd, self.callcache[key]) + #print "%s->%s" % (cmd, self.callcache[key]) return self.callcache[key] diff --git a/moin2doku.py b/moin2doku.py index 8d64bb3..7e59bc5 100755 --- a/moin2doku.py +++ b/moin2doku.py @@ -20,6 +20,7 @@ from os import listdir, mkdir from os.path import isdir, basename from doku import DokuWiki from moinformat import moin2doku +import random USEC = 1000000 @@ -63,7 +64,7 @@ def writefile(filename, content, overwrite=False): # page = MoinMoin Page oject # ns = DokuWiki namespace where attachments to copy -def copy_attachments(page, ns): +def copy_attachments(page, ns,randomID): srcdir = page.getPagePath('attachments', check_create = 0) if not isdir(srcdir): return @@ -75,7 +76,7 @@ def copy_attachments(page, ns): attachments = listdir(srcdir) for attachment in attachments: src = os.path.join(srcdir, attachment) - dst = os.path.join(output_dir, 'media', dw.mediaFN(dw.cleanID("%s/%s" % (ns, attachment)))) + dst = os.path.join(output_dir, 'media', dw.mediaFN(dw.cleanID("%s/%s" % (ns, str(randomID)+attachment)))) copyfile(src, dst) copystat(src, dst) @@ -157,8 +158,10 @@ def convert_editlog(page, output = None, overwrite = False): def convertfile(page, output = None, overwrite = False): pagedir = page.getPagePath() pagename = wikiname(pagedir) + if not output: - output = pagename + output = pagename.split("/") + if page.isUnderlayPage(): print "underlay: %s" % page.request.cfg.data_underlay_dir @@ -174,6 +177,9 @@ def convertfile(page, output = None, overwrite = False): else: revs = [current_rev] + # Generate random ID Number for collision avoidance when attachments in Namespace have the same name + randomID = random.randint(101,999) + for rev in revs: page = Page(request, pagename, rev = rev) pagefile, realrev, exists = page.get_rev(rev = rev); @@ -200,7 +206,7 @@ def convertfile(page, output = None, overwrite = False): else: out_file = os.path.join(output_dir, 'attic', dw.wikiFN(output, str(mtime))) - content = moin2doku(pagename, page.get_raw_body()) + content = moin2doku(pagename, page.get_raw_body(),randomID) if len(content) == 0: # raise Exception, "No content" print "NO CONTENT: exists: %s,%s" % (exists, os.path.exists(pagefile)) @@ -209,7 +215,7 @@ def convertfile(page, output = None, overwrite = False): copystat(pagefile, out_file) ID = dw.cleanID(output) - copy_attachments(page, dw.getNS(ID)) + copy_attachments(page, dw.getNS(ID),randomID) # convert edit-log, it's always present even if current page is not convert_editlog(page, output = output, overwrite = overwrite) diff --git a/moinformat.py b/moinformat.py index 846984f..785d7de 100755 --- a/moinformat.py +++ b/moinformat.py @@ -18,9 +18,11 @@ from text_dokuwiki import Formatter import sys import StringIO -def moin2doku(pagename, text): +def moin2doku(pagename, text, randomID=None): parser = Parser(text, request) + formatter.setRandomID(randomID) + # this needed for macros request.formatter = formatter diff --git a/text_dokuwiki.py b/text_dokuwiki.py index cb444f8..99fd531 100644 --- a/text_dokuwiki.py +++ b/text_dokuwiki.py @@ -31,10 +31,13 @@ class Formatter(FormatterBase): self.in_pre = 0 self.in_table = 0 self._text = None # XXX does not work with links in headings!!!!! - + self.randomID= None self.list_depth = 0 self.list_type = ' ' + def setRandomID(self,ID): + self.randomID = str(ID) + def _escape(self, text, extra_mapping={"'": "'", '"': """}): return saxutils.escape(text, extra_mapping) @@ -78,13 +81,16 @@ class Formatter(FormatterBase): return ('[[%s|' % (self._escape(url)), ']]')[not on] def attachment_link(self, on, url=None, querystr=None, **kw): - return '{{ %s | %s }}' % (url, querystr) + if on: + return '{{ %s | }}' % (self.randomID+url) + else: + return ' }}' def attachment_image(self, url, **kw): - return '{{%s|}}' % (url,) + return '{{%s|}}' % (self.randomID+url,) def attachment_drawing(self, url, text, **kw): - return '{{%s|%s}}' % (url, text) + return '{{%s|%s}}' % (self.randomID+url, text) def text(self, text, **kw): self._did_para = 0 @@ -291,7 +297,7 @@ class Formatter(FormatterBase): def showAttachedFiles(args): args = args.split(',') - return self.attachment_link(1,url=args[0].strip(),querystr=args[1].strip()) + return '{{ %s | %s }}' % (self.randomID+args[0].strip(), args[1].strip()) # function which will just do what parent class would def inherit(args): @@ -303,7 +309,8 @@ class Formatter(FormatterBase): 'MailTo' : email, 'GetText' : args, 'ShowSmileys' : inherit, - 'ShowAttachedFiles' : showAttachedFiles + 'ShowAttachedFiles' : showAttachedFiles, + 'Include' : inherit }[name] except KeyError: lookup = '/* UndefinedMacro: %s(%s) */' % (name, args) From 8b7f4c9d339e26f562f4ba65726ba777a8d1361a Mon Sep 17 00:00:00 2001 From: Lukas Pfannschmidt Date: Thu, 7 Jan 2016 18:29:51 +0100 Subject: [PATCH 06/10] Removed temporary files. --- README.md | 0 doku.py | 2 +- doku.pyc | Bin 1642 -> 0 bytes moinformat.pyc | Bin 1242 -> 0 bytes output.txt | 238 -------------------------------------------- standalone.py | 22 ---- syntaxreference.txt | 0 text_dokuwiki.py | 14 ++- text_dokuwiki.pyc | Bin 13780 -> 0 bytes 9 files changed, 13 insertions(+), 263 deletions(-) mode change 100644 => 100755 README.md mode change 100644 => 100755 doku.py delete mode 100644 doku.pyc delete mode 100644 moinformat.pyc delete mode 100644 output.txt delete mode 100644 standalone.py mode change 100644 => 100755 syntaxreference.txt mode change 100644 => 100755 text_dokuwiki.py delete mode 100644 text_dokuwiki.pyc diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/doku.py b/doku.py old mode 100644 new mode 100755 index a70abe5..ad94aa9 --- a/doku.py +++ b/doku.py @@ -29,5 +29,5 @@ class DokuWiki: cmd = ['./doku.php', method ] + args res = subprocess.Popen(cmd, stdin = None, stdout = subprocess.PIPE, stderr = sys.stderr, close_fds = True).communicate() self.callcache[key] = unicode(res[0].decode('utf-8')) - #print "%s->%s" % (cmd, self.callcache[key]) + print "%s->%s" % (cmd, self.callcache[key]) return self.callcache[key] diff --git a/doku.pyc b/doku.pyc deleted file mode 100644 index 78db648323cf9f6823de3c1ff4202d0f51daeb97..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1642 zcmbVM$!-%t5UsYI#aRFa1o90D1^E!L1Q&#&2(bvbSkVN5$fY$*x8rd<9&5U-C{l6? z0uEgG7Vi8M9{}&wWZ`N?Q`ObowJ+WLy}q*bBY&UC`Pany3=n!i4!@DH$o?g5WZ#Hu zh--;!%4d-?k&pY>8`NQA~XOm0AU>{7da8J>epVE*L}sY4Kho|<1EdFzCLPE$d3nItfDB~2h|&v zh3{plbH}|SxH(9xqF0pp9RzhHE`qJ_aag*9&di;bB?ui=>2&JdEs*C~sZ&ga2@NFVQtP!5 zx~UiQ6oBQUCCwK%Vm2DJAtpsN*VdM?tuNFN-I&MFD)_BE@G*_CvUY>wwY}>tEjL42 z0lenTFQAADG+1BM8bwFh(7huNdWeeNK5ep3M>qx1By0G|$pPzu_Q##mmc*8f7UTpY zg&!@wpeIY>76t7$YKvQvxB}tUXq5wZ3WhZ~SrE4@ozc3uHWlNqO~KB#TcN(oeTTlh zelyXIfj403>~$G%KX7U{!_&9Rn-GGE`zrN z7ciFKrpPP~9y|%m*k*XJvl+VAKq63)aUP-)Bg|Stn~`lYOoKi2$A}XeW}l{2nfVaZ z{BAk*6BX%~6R*VX+uc`@9Z=N4^*5LPS?tZx~Fh9S3A)_J%4-|bZ*70nU2{oH_T&m7nHu3=P%48ExffFzO_Z^ zW@BszJ6%sAX?B)(y9D6d~ymscBb$$+dzsCB*0{h3I{}=StKS(6>3S>Yo5DEy!5}8Eq zAapEtkhPGz2wjU?$lAy|2s;+L$hycqgr3E1WIcpEQ=9ZY!akA?z5<~SC2&p30Lp_J z;F^xT12sg_#ag2J4mE=6VRe^XiHCIy)wjKc;QernqK$+O7(*REjgjACj*)|{Y}qAkfs^V7gf5^CuO14rMBiSnJ?0H+UPX1mKIsw z$7jl-wn0^`DvLeBFUu;AwN};XLK5T<=J|xa`U?pS>;yCoFL5QI=@p1bI;`wq?4(Pq zTG%-}ywEOIF3)q-f^K8g!Ig`h(W4G_6x!tk4&AvNL00W?#Hz<>E25naH1B-EZJpLG z$wn_9Kb`ob1>B?Vkf_w>M%9|qf#uCC0p}QZtu)WCnVPw-(&FsRJ8GSV+tze2{p+M` zv{CozT(v3EMVZ(%%07>?MwysIv3Ve2Evo3xhTrxw1}dV8>tUiYzrMt0Q^V}6_Wjp-a*v?q+Ha`|{-zh| z<8)!~SsjqWPJZJKIN#jJ8_Sd#w<~z?Zyn3Zlv#>$Dje~=c9VRejh%-!X67^Cr3SpZ zfaeVO4g|N#pragma section-numbers off -#acl All:admin,read,write,delete,revert -#language en -This page tries to use each supported markup element at least once. - - - -'''Index''' -[[TableOfContents(2)]] -**Index** - -[[:TableOfContents(2)|TableOfContents(2)]] - - - -====== Headers ====== - - -===== Header 2 ===== - - -==== Header 3 ==== - - -=== Header 4 === - - -== Header 5 == - - -====== Font styles ====== - - -Normal text, ''emphasized'', '''strong''', __underline__, ,,subscript,,, ^superscript^, `typewriter` and {{{typewriter -.}}} - -Normal text, //emphasized//, **strong**, __underline__, subscript, superscript, ''typewriter'' and ''typewriter''. - - - -===== Syntax Highlighting ===== - - * -# python code -print code.colorize("abc", 1 + 1) - - -====== Hyperlinks ====== - - -===== Internal ===== - - - * MoinMoin - * MoinMoin/TextFormatting - * MoinMoin/InstallDocs - * ../InstallDocs - * /SubPage - * Self:InterWiki - - * [[:MoinMoin|MoinMoin]] - * [[:MoinMoin:TextFormatting|MoinMoin/TextFormatting]] - * [[:MoinMoin:InstallDocs|MoinMoin/InstallDocs]] - * [[:InstallDocs|../InstallDocs]] - * [[:test:SubPage|/SubPage]] - * [[:InterWiki|InterWiki]] - - -[#anchorname Anchor Link] -[#anchorname Anchor Link] - - - -===== External ===== - - - * http://moinmoin.wikiwikiweb.de/ - * [http://moinmoin.wikiwikiweb.de/] - * [http://moinmoin.wikiwikiweb.de/ MoinMoin Wiki] - * [http://moinmoin.wikiwikiweb.de/wiki/classic/img/moinmoin.png] - * http://moinmoin.wikiwikiweb.de/wiki/classic/img/moinmoin.png - * [http://moinmoin.wikiwikiweb.de/wiki/classic/img/moinmoin.png moinmoin.png] - * MeatBall:InterWiki - * wiki:MeatBall/InterWiki - * [wiki:MeatBall/InterWiki] - * [wiki:MeatBall/InterWiki InterWiki page on MeatBall] - * [file://servername/full/path/to/file/filename%20with%20spaces.txt Click here to read filename with spaces.txt] - * me@privacy.net - - * [[http://moinmoin.wikiwikiweb.de/|http://moinmoin.wikiwikiweb.de/]] - * [[[http://moinmoin.wikiwikiweb.de/|http://moinmoin.wikiwikiweb.de/]]] - * [[[http://moinmoin.wikiwikiweb.de/|http://moinmoin.wikiwikiweb.de/]] [[:MoinMoin|MoinMoin]] Wiki] - * [[[http://moinmoin.wikiwikiweb.de/wiki/classic/img/moinmoin.png|http://moinmoin.wikiwikiweb.de/wiki/classic/img/moinmoin.png]]] - * [[http://moinmoin.wikiwikiweb.de/wiki/classic/img/moinmoin.png|http://moinmoin.wikiwikiweb.de/wiki/classic/img/moinmoin.png]] - * [[[http://moinmoin.wikiwikiweb.de/wiki/classic/img/moinmoin.png|http://moinmoin.wikiwikiweb.de/wiki/classic/img/moinmoin.png]] moinmoin.png] - * [[MeatBall>InterWiki|InterWiki]] - * wiki:[[:MeatBall:InterWiki|MeatBall/InterWiki]] - * [wiki:[[:MeatBall:InterWiki|MeatBall/InterWiki]]] - * [wiki:[[:MeatBall:InterWiki|MeatBall/InterWiki]] [[:InterWiki|InterWiki]] page on [[:MeatBall|MeatBall]]] - * [[[file://servername/full/path/to/file/filename%20with%20spaces.txt|file://servername/full/path/to/file/filename%20with%20spaces.txt]] Click here to read filename with spaces.txt] - * [[mailto:me@privacy.net|me@privacy.net]] - - -===== Escaping WikiNames ===== - - -Wiki''''''Name -Wiki``Name -Wiki****Name Wiki''''Name - - - -====== Blockquote ====== - - - This is indented - Even more - - * This is indented - * Even more - - - -====== Bullet list ====== - - - * item 1 - - * item 2, with gap - * item 3 - * item 3.1 - - * item 1 - * item 2, with gap - * item 3 - * item 3.1 - - - -====== Numbered list ====== - - - 1. item 1 - i. item 1 - i. item 2 - - - item 1 - - item 1 - - item 2 - - - - 1. item 2 - a. item 1 - a. item 2 - - - item 2 - - item 1 - - item 2 - - - -====== Descriptions + Definitions ====== - - - Term:: Description - Label:: Definition -Description Definition - -====== Code display ====== - - * line 1 - indented 4 characters - - - -====== Tables ====== - - -===== General table layout and HTML like options ===== - - - ||cell 1||cell2||cell 3|| - - * -|cell 1|cell2|cell 3| - - -====== Rules ====== - - ---- (not a rule) ----- ------ ------- -------- --------- ---------- ----------- --------------------------------------------- (not thicker than 10) ---- (not a rule) - - - - -- - - --- - - ---- - - ----- - - ----- - - ----- - - ----- - (not thicker than 10) - - - -====== Macros ====== - - -[[Anchor(anchorname)]] -'''[[PageCount]]''' pages -[[:Anchor(anchorname)|Anchor(anchorname)]] **[[:PageCount|PageCount]]** pages - - diff --git a/standalone.py b/standalone.py deleted file mode 100644 index 413a450..0000000 --- a/standalone.py +++ /dev/null @@ -1,22 +0,0 @@ -from MoinMoin.server.standalone import StandaloneConfig, run - -import sys -# Path of the directory where wikiconfig.py is located. -# YOU NEED TO CHANGE THIS TO MATCH YOUR SETUP. -sys.path.insert(0, 'home/caddy/wikifarm/var/wikifarm/config') - -# Path to MoinMoin package, needed if you installed with --prefix=PREFIX -# or if you did not use setup.py. -sys.path.insert(0, '/usr/local/lib/python2.4/site-packages') - -# Path of the directory where farmconfig.py is located (if different). -sys.path.insert(0, '/home/caddy/wikifarm/var/wikifarm/config') - -class Config(StandaloneConfig): - docs = '/home/caddy/wikifarm/var/wikifarm' - user = 'http' - group = 'http' - port = 80 - -run(Config) - \ No newline at end of file diff --git a/syntaxreference.txt b/syntaxreference.txt old mode 100644 new mode 100755 diff --git a/text_dokuwiki.py b/text_dokuwiki.py old mode 100644 new mode 100755 index 99fd531..73df575 --- a/text_dokuwiki.py +++ b/text_dokuwiki.py @@ -82,7 +82,7 @@ class Formatter(FormatterBase): def attachment_link(self, on, url=None, querystr=None, **kw): if on: - return '{{ %s | }}' % (self.randomID+url) + return '{{ %s | ' % (self.randomID+url) else: return ' }}' @@ -138,6 +138,13 @@ class Formatter(FormatterBase): return ['', '\n'][on] + # generic transclude/include: + def transclusion(self, on, **kw): + return '' + + def transclusion_param(self, **kw): + return '' + def listitem(self, on, **kw): # somewhy blockquote uses "listitem" call return [(' ' * self.list_depth * 2) + self.list_type + ' ', '\n'][not on] @@ -297,7 +304,10 @@ class Formatter(FormatterBase): def showAttachedFiles(args): args = args.split(',') - return '{{ %s | %s }}' % (self.randomID+args[0].strip(), args[1].strip()) + if len(args)>1: + return '{{ %s | %s }}' % (self.randomID+args[0].strip(), args[1].strip()) + else: + return '' # function which will just do what parent class would def inherit(args): diff --git a/text_dokuwiki.pyc b/text_dokuwiki.pyc deleted file mode 100644 index cbff1eb331be1a1d81e5e3111531c6bdd58999af..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 13780 zcmcIr&2Jn>cCVfp4ml(x>dTU7$x@RNr6DD9M9C|ADVmZ+efUdbxhbz?N%puo-6C6@ z=^l6YnBtN=1QON;HXlef0fNOMd&mcJ$sxA@33A8+0dfce1js*-Taesx36R6)_j}bn zGa{`RD~?EZ)vN02s#ov5dhgY%V)nmx^{@QrPk&TZ$xjyf6+F>nB#u(|ks8X$sG6bb z8FfFS43@L1mR0qfx}VeKoT~MxdS2bn>vE5(^{RTGy5FbEc~vW@J5H~1b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-{WC--VfefD?)7f!kz+(j2s2&g536xIq^0icQbX1P&%9F?tqCJfa zcd5s9Hh~Oxr_Ulo*OSO_8+{5Y7P@ueuD`FPS*chJ)Gpj}7+56v^@XpQ$$JvWxHnmp zd}d@u^7VV0`uwE1*qqZf6Ppr+{P$n{OjcZRsx+=YnY^v@@o{-EGYNo9pP9UzDIj<2G~0cI~GUtiE)&7M!n z=aceuQl8f3;)wpPH1aS(?4cedE$UHbQuK@Zt)|SS1cyuMTYY6}Ll-v^l)k8ZAzjbS z=%Hsvl6bV;CYwpU>X*$6SWV^P1#~AK zP(`kZ;<`B zotC?F);U7cOlU%K9;rbtW*N%KDZGRg(1!ByAQ7 z^fCs{qMq81C;AdeKAX?vvxR}zvxS~QZy}4{+)#d~ZzwxNI9tdM>RP}<1BL!V4!`sgZ>JaBjjaISE?aJ(#jlJ!drB@D#f@hSY14k@B!1DgIL(o}l5 z6}JEJAbqE=j+2FH&D3pp(H7UH4oJX)L^8215J-e@R*T&n1x-%$^Kf4EZ-4Ip04|3` Aj{pDw From 36f8eaea6bd26c39590d002cb128d17c9e9e513e Mon Sep 17 00:00:00 2001 From: Lukas Pfannschmidt Date: Thu, 7 Jan 2016 18:35:39 +0100 Subject: [PATCH 07/10] Added info to README --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0297c68..7d7674d 100755 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Converts also page history and edit-log. http://www.dokuwiki.org/tips:moinmoin2doku -Tested with MoinMoin 1.5 and DokuWiki 2012-09-10 releases +Tested with MoinMoin 1.9 and DokuWiki 2014-12-09 releases You need to run this on host where both MoinMoin and DokuWiki are configured, it uses current configuration from both wikis. @@ -57,3 +57,8 @@ converting and translating paths. Converts also page history and edit-log. This marks the project "done", I will no longer develop it or support it, as I got my conversion done. However, I do accept patches (pull requests) to sane amount. I put repo online so others have better starting point than I did. + + +version 1.1 (2015) +---------------- +Modifed the script to work with newer Moin versions and API changes. From ec684eaefc3258fbc0a502276375b8c21a475b19 Mon Sep 17 00:00:00 2001 From: Lukas Pfannschmidt Date: Thu, 7 Jan 2016 18:40:29 +0100 Subject: [PATCH 08/10] Removed useless import. --- moin2doku.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/moin2doku.py b/moin2doku.py index 7e59bc5..51ee558 100755 --- a/moin2doku.py +++ b/moin2doku.py @@ -9,7 +9,6 @@ # Version: 1.0 import sys, os, os.path, re, codecs -sys.path.insert(1,'/home/caddy/.conda/envs/moinmoin/lib/python2.7/site-packages/MoinMoin/support') import getopt from MoinMoin import user, wikiutil from MoinMoin.web.contexts import ScriptContext as RequestCLI @@ -160,8 +159,7 @@ def convertfile(page, output = None, overwrite = False): pagename = wikiname(pagedir) if not output: - output = pagename.split("/") - + output = pagename if page.isUnderlayPage(): print "underlay: %s" % page.request.cfg.data_underlay_dir From 9b3341f8369848cb724af379fb199e9d83a24095 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Hofschr=C3=B6er?= Date: Tue, 26 Mar 2019 12:47:14 +0100 Subject: [PATCH 09/10] Gtwiki (#1) * Added Windows hints and v1.2 infos * added some windows batch files * switched from 'cliopts' to 'cli' * "named args" * All arguments passed to php are UTF-8 encoded * removed local path from repository. Use doku.local.php * added/changed support for - small - big - anchordef - definition_list - comment - include and search macros * added #pragma directives as comments to dokuwiki * recreate "_dokuwiki.changes" * Support for non-ascii characters in media files --- .gitignore | 4 + README.md | 33 +++++++- doku.php | 28 ++++--- doku.py | 17 ++++- moin2doku.cmd | 36 +++++++++ moin2doku.py | 22 +++++- reindex.cmd | 69 +++++++++++++++++ settings.cmd | 45 +++++++++++ text_dokuwiki.py | 190 +++++++++++++++++++++++++++++++++++++++++++---- 9 files changed, 412 insertions(+), 32 deletions(-) create mode 100644 .gitignore create mode 100644 moin2doku.cmd create mode 100644 reindex.cmd create mode 100644 settings.cmd diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0e73e3e --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +settings.local.cmd +*.log +*.pyc +out/ diff --git a/README.md b/README.md index 7d7674d..1ccbac4 100755 --- a/README.md +++ b/README.md @@ -6,12 +6,12 @@ Converts also page history and edit-log. http://www.dokuwiki.org/tips:moinmoin2doku -Tested with MoinMoin 1.9 and DokuWiki 2014-12-09 releases +Tested with MoinMoin 1.9.9 and DokuWiki 2018-04-22 releases under Windows 7 You need to run this on host where both MoinMoin and DokuWiki are configured, it uses current configuration from both wikis. -Edit doku.php if your DokuWiki installation is other than /usr/share/dokuwiki +Edit `doku.php` if your DokuWiki installation is other than `/usr/share/dokuwiki` To convert moinmoin all pages with history, invoke: ``` @@ -33,6 +33,28 @@ and ensure ownership of files is correct: ``` additionally, depending on your configuration, you may need to gzip the attic pages. + +Hints for Windows Users +----------------------- + +The Batchfiles (`*.cmd`) should help to do the conversation under Windows. You should +create a copy of the `settings.cmd` and call it `settings.local.cmd` to set your +own local paths. + +Call `moin2doku.cmd` to convert the full MoinMoin Wiki. All DokuWiki pages will be +written to an `out` folder in the current directory. + +This will convert a single page: +``` +D:\moin2doku\> moin2doku.cmd MyMoinPage +``` + +Set `%OUTDIR%` to an alternativ output folder. This should not be the dokuwiki `data` +folder if you want to do a full conversation. + +The `reindex.cmd` will call the `bin/indexer.php`-Skript. + + History ======= @@ -62,3 +84,10 @@ I put repo online so others have better starting point than I did. version 1.1 (2015) ---------------- Modifed the script to work with newer Moin versions and API changes. + + +version 1.2 (2019-01) +---------------- +Some modifications to work with current DokuWiki and added more formattings. + +Search GitHub Forks for newer versions of this project. diff --git a/doku.php b/doku.php index 50714df..65c376a 100755 --- a/doku.php +++ b/doku.php @@ -13,10 +13,14 @@ if ('cli' != php_sapi_name()) die(); -define('DOKU_INC', '/home/caddy/wikifarm/dokuwiki/dokuwiki/'); +//add to following define of 'DOKU_INC' to your "doku.local.php" file and adjust the path: +//define('DOKU_INC', '/home/caddy/wikifarm/dokuwiki/dokuwiki/'); +//define('DOKU_INC', "d:/website/wwwroot/dokuwiki/" ); +require_once './doku.local.php'; + require_once DOKU_INC.'inc/init.php'; require_once DOKU_INC.'inc/common.php'; -require_once DOKU_INC.'inc/cliopts.php'; +require_once DOKU_INC.'inc/cli.php'; # disable gzip regardless of config, then we don't have to compress when converting $conf['compression'] = 0; //compress old revisions: (0: off) ('gz': gnuzip) ('bz2': bzip) @@ -29,29 +33,33 @@ function strip_dir($dir, $fn) { return end(explode($dir.'/', $fn, 2)); } -switch ($argv[1]) { +$action = $argv[1]; +$argPage = $argv[2]; +//filext = $argv[3]; + +switch ($action) { case 'cleanID': - echo cleanID($argv[2]); + echo cleanID($argPage); break; case 'wikiFN': if ($argc > 3 && $argv[3]) { - echo strip_dir($conf['olddir'], wikiFN($argv[2], $argv[3])); + echo strip_dir($conf['olddir'], wikiFN($argPage, $argv[3])); } else { - echo strip_dir($conf['datadir'], wikiFN($argv[2])); + echo strip_dir($conf['datadir'], wikiFN($argPage)); } break; case 'mediaFN': - echo strip_dir($conf['mediadir'], mediaFN($argv[2])); + echo strip_dir($conf['mediadir'], mediaFN($argPage)); break; case 'metaFN': - echo strip_dir($conf['metadir'], metaFN($argv[2], $argv[3])); + echo strip_dir($conf['metadir'], metaFN($argPage, $argv[3])); break; case 'getNS': - echo getNS($argv[2]); + echo getNS($argPage); break; case 'getId': echo getId(); break; default: - die("Unknown knob: {$argv[1]}"); + die("Unknown knob: {$action}"); } diff --git a/doku.py b/doku.py index ad94aa9..c750a19 100755 --- a/doku.py +++ b/doku.py @@ -11,6 +11,9 @@ import sys import subprocess +from MoinMoin import log +logging = log.getLogger(__name__) + class DokuWiki: def __init__(self): self.callcache = {} @@ -24,10 +27,18 @@ class DokuWiki: def __call(self, method, *args): args = list(args) - key = "%s:%s" % (method, ",".join(args)) + uargs = [] + for arg in args: + try: + arg.decode('utf-8') + #already UTF-8 ready + uargs.append(arg) + except UnicodeError: + uargs.append(arg.encode('utf-8')) + key = "%s:%s" % (method, ",".join(uargs)) if not self.callcache.has_key(key): - cmd = ['./doku.php', method ] + args - res = subprocess.Popen(cmd, stdin = None, stdout = subprocess.PIPE, stderr = sys.stderr, close_fds = True).communicate() + cmd = ['php', './doku.php', method ] + uargs + res = subprocess.Popen(cmd, stdin = None, stdout = subprocess.PIPE, stderr = sys.stderr, close_fds = False).communicate() self.callcache[key] = unicode(res[0].decode('utf-8')) print "%s->%s" % (cmd, self.callcache[key]) return self.callcache[key] diff --git a/moin2doku.cmd b/moin2doku.cmd new file mode 100644 index 0000000..bea9f15 --- /dev/null +++ b/moin2doku.cmd @@ -0,0 +1,36 @@ +@echo off +setlocal + +call settings.cmd + +if not "%1"=="" goto :singlePage %1 + +if "%OUTDIR%"=="" ( + call :deldir out\attic || (pause & goto :eof) + call :deldir out\media || (pause & goto :eof) + call :deldir out\meta || (pause & goto :eof) + call :deldir out\pages || (pause & goto :eof) + if exist %~n0.pages.log del %~n0.pages.log + if not exist out md out + set OUTDIR=%CD%\out +) + +call python moin2doku.py %DOKU_FULL_HISTORY% -d "%OUTDIR:\=/%" >"%~n0.log" 2>"%~n0.err.log" + +goto :eof +:deldir +if exist %1 rd /s/q %1 +if exist %1 exit /B 1 + +goto :eof +:singlePage +if "%OUTDIR%"=="" set OUTDIR=%CD%\out +call python moin2doku.py %DOKU_FULL_HISTORY% -p "%MOIN_DATA_HOME%\pages\%~1" -f -d "%OUTDIR:\=/%" >>"%~n0.log" 2>>"%~n0.err.log" || type "%~n0.err.log" +if %ERRORLEVEL% == 0 if exist "%DOKU_ANIMALS_HOME%\%ANIMAL%\conf\local.php" ( + rem touching "%DOKU_ANIMALS_HOME%\%ANIMAL%\conf\local.php" to invalidate cache + pushd "%DOKU_ANIMALS_HOME%\%ANIMAL%\conf" + copy /y/b local.php +,, >nul + popd +) + +goto :eof diff --git a/moin2doku.py b/moin2doku.py index 51ee558..fd60983 100755 --- a/moin2doku.py +++ b/moin2doku.py @@ -21,6 +21,10 @@ from doku import DokuWiki from moinformat import moin2doku import random +# sys.setdefaultencoding() does not exist, here! +reload(sys) # Reload does the trick! +sys.setdefaultencoding('cp1252') + USEC = 1000000 def init_dirs(output_dir): @@ -74,10 +78,13 @@ def copy_attachments(page, ns,randomID): attachments = listdir(srcdir) for attachment in attachments: - src = os.path.join(srcdir, attachment) - dst = os.path.join(output_dir, 'media', dw.mediaFN(dw.cleanID("%s/%s" % (ns, str(randomID)+attachment)))) - copyfile(src, dst) - copystat(src, dst) + try: + src = os.path.join(srcdir, attachment) + dst = os.path.join(output_dir, 'media', dw.mediaFN(dw.cleanID(u"%s/%s" % (ns, str(randomID)+attachment)))) + copyfile(src, dst) + copystat(src, dst) + except UnicodeDecodeError: + print 'ERROR: unable to convert attachment "%s"' % attachment def print_help(): program = sys.argv[0] @@ -161,6 +168,8 @@ def convertfile(page, output = None, overwrite = False): if not output: output = pagename + print "Converting %s" % pagename + if page.isUnderlayPage(): print "underlay: %s" % page.request.cfg.data_underlay_dir print "underlay: %s" % request.cfg.data_underlay_dir @@ -313,6 +322,11 @@ else: del pages[frontpage.page_name] pages[dw.getId()] = frontpage.page_name +print "--------------------------------------------------" +for output, pagename in pages.items(): + print " - %s" % pagename +print "--------------------------------------------------" + converted = 0 for output, pagename in pages.items(): page = Page(request, pagename) diff --git a/reindex.cmd b/reindex.cmd new file mode 100644 index 0000000..38321b0 --- /dev/null +++ b/reindex.cmd @@ -0,0 +1,69 @@ +@echo off +setlocal + +call settings.cmd + +pushd "%DOKU_ANIMALS_HOME%\%ANIMAL%" + +if not exist data\pages\ ( + echo WARNUNG: + echo Es wurden kein "pages" Verzeichnis gefunden. Wurde die neue Version bereits + echo ins Zielverzeichnis kopiert? + pause + goto :eof +) + +if not exist data\media\logo.png ( + echo working in %CD% + rem call :cleanup data\attic || goto :ende + call :cleanup data\cache || goto :ende + call :cleanup data\index || goto :ende + call :cleanup data\locks || goto :ende + call :cleanup data\media_attic || goto :ende + call :cleanup data\media_meta || goto :ende + call :cleanup data\tmp || goto :ende + xcopy /S/I/Y/Q common\*.* data +) + +REM if exist data\pages\startseiteneu.txt ( + REM ren data\pages\startseiteneu.txt startseite.txt + REM ren data\meta\startseiteneu.changes startseite.changes +REM ) + +popd +pushd "%DOKU_HOME%" + +php bin\indexer.php || goto :ende + +popd +pushd "%DOKU_ANIMALS_HOME%\%ANIMAL%" + +if exist data\meta\_dokuwiki.changes del data\meta\_dokuwiki.changes +if exist data\meta\_dokuwiki.changes del data\meta\_dokuwiki.changes +( + for /F "delims=*" %%D in ('dir /b/S/A:D data\meta\*.*') do ( + if exist "%%D\*.changes" type "%%D\*.changes" 2>nul + ) +) > _dokuwiki_unsorted.changes +sort _dokuwiki_unsorted.changes /O data\meta\_dokuwiki.changes +del _dokuwiki_unsorted.changes + +echo --- compressing old files +for /F "delims=*" %%T in ('dir data\attic\*.txt /s/b') do ( + "c:\Program Files\7-Zip\7z.exe" a -bso0 "%%T.gz" "%%T" && del "%%T" || goto :ende +) +echo --- done + +:ende +popd + +pause + +goto :eof +:cleanup +if not exist %1 goto :eof +echo cleaning up %1 +rd /s/q %1 +if exist %1 exit /b 1 +md %1 +echo >nul 2>"%~1\_dummy" diff --git a/settings.cmd b/settings.cmd new file mode 100644 index 0000000..d344fa0 --- /dev/null +++ b/settings.cmd @@ -0,0 +1,45 @@ +@echo off +REM -- no setlocal in this script! +REM make a copy of this file and adjust the paths + +set PHP_HOME=c:\Program Files\php +set PYTHON_HOME=c:\Python27 +REM -- MoinMoin settings +set MOIN_HOME=c:\wwwroot\wiki\moin +set MOIN_CONFIG=%MOIN_HOME%\wiki\config +REM set MOIN_CONFIG=c:\wwwroot\moinfarmdata\config +set MOIN_DATA_HOME=%MOIN_HOME%\wiki\data +REM set MOIN_CONFIG=c:\wwwroot\moinfarmdata\ +REM -- DokuWiki settings +set DOKU_HOME=c:\wwwroot\wiki\dokuwiki +set DOKU_ANIMALS_HOME=%DOKU_HOME% +REM set DOKU_ANIMALS_HOME=c:\wwwroot\dokufarmdata +REM set animal= +REM comment this in to do a full converstion +REM set DOKU_FULL_HISTORY=-a + +REM -- path to your php.ini used by your webserver +REM set PHP_INI_SCAN_DIR=c:\Program Files\ApacheHttpd\conf\ + +REM -- set this to your "production" dokuwiki if you want to update only. +REM set OUTDIR=%DOKU_ANIMALS_HOME%\%animal%\data + +REM ----8<--------8<--------8<--------8<--------8<--------8<--------8<---- +REM -- remove everything beyond the line from your copy +chcp 1252 + +if exist "%~dpn0.local.cmd" call "%~dpn0.local.cmd" + +REM -- %animal% must be lowercase! +( +set animal= +set animal=%animal% +) + +set PATH=%PATH%;%PYTHON_HOME%;%PHP_HOME% + +set PYTHONPATH=. +set PYTHONPATH=%PYTHONPATH%;%MOIN_HOME% +set PYTHONPATH=%PYTHONPATH%;%MOIN_HOME%\MoinMoin\support +set PYTHONPATH=%PYTHONPATH%;%MOIN_CONFIG% +set PYTHONPATH=%PYTHONPATH%; diff --git a/text_dokuwiki.py b/text_dokuwiki.py index 73df575..2eaee12 100755 --- a/text_dokuwiki.py +++ b/text_dokuwiki.py @@ -13,6 +13,9 @@ from MoinMoin.formatter import FormatterBase from MoinMoin import config from MoinMoin.Page import Page from types import * +from MoinMoin import log + +logging = log.getLogger(__name__) # TODO: let base class MoinMoin/formatter/base.py handle not implemented methods @@ -73,6 +76,14 @@ class Formatter(FormatterBase): if on: if interwiki == 'Self': return self.pagelink(on, pagename, **kw) + interwikis = { + 'WikiPedia':'wp', + 'FrWikiPedia':'wpfr', + 'DeWikiPedia':'wpde', + 'MetaWikiPedia':'wpmeta' + } + if interwiki in interwikis: + return '[[%s>%s|' % (interwikis.get(interwiki), pagename) return '[[%s>%s|' % (interwiki, pagename) else: return ']]' @@ -134,7 +145,8 @@ class Formatter(FormatterBase): self.list_type = '*' else: self.list_depth -= 1 - self.list_type = ' ' + if self.list_depth <= 0: + self.list_type = ' ' return ['', '\n'][on] @@ -151,7 +163,7 @@ class Formatter(FormatterBase): def code(self, on, **kw): """ `typewriter` or {{{typerwriter}}, for code blocks i hope codeblock works """ - return ["''", "''"][not on] + return ["''%%", "%%''"][not on] def sup(self, on, **kw): return ['', ''][not on] @@ -162,12 +174,20 @@ class Formatter(FormatterBase): def strike(self, on, **kw): return ['', ''][not on] + def small(self, on, **kw): + #https://www.dokuwiki.org/plugin:wrap + return ['', ''][not on] + + def big(self, on, **kw): + #https://www.dokuwiki.org/plugin:wrap + return ['', ''][not on] + def preformatted(self, on, **kw): FormatterBase.preformatted(self, on) result = '' if self.in_p: result = self.paragraph(0) - return result + ['', '\n'][not on] + return result + ['', '\n'][not on] def paragraph(self, on, **kw): FormatterBase.paragraph(self, on) @@ -192,7 +212,7 @@ class Formatter(FormatterBase): self.in_table = 1 else: self.in_table = 0 - return '' + return ['', '\n'][not on] def table_row(self, on, attrs={}, **kw): return ['\n', '|'][not on] @@ -201,8 +221,8 @@ class Formatter(FormatterBase): return ['|', ''][not on] def anchordef(self, id): - # not supported - return '' + # https://www.dokuwiki.org/plugin:anchor + return '{{anchor:'+id+'}}' def anchorlink(self, on, name='', **kw): # kw.id not supported, we hope the anchor matches existing heading on page @@ -212,16 +232,18 @@ class Formatter(FormatterBase): return ['__', '__'][not on] def definition_list(self, on, **kw): + # https://www.dokuwiki.org/plugin:definitionlist result = '' if self.in_p: result = self.paragraph(0) - return result + ['', ''][not on] + return result def definition_term(self, on, compact=0, **kw): - return [''][not on] + #MoinMoin does no wiki markup in DL-Terms + return [' ;%%', '%%\n'][not on] def definition_desc(self, on, **kw): - return ['', ''][not on] + return [' :', '\n'][not on] def image(self, src=None, **kw): valid_attrs = ['src', 'width', 'height', 'alt', 'title'] @@ -268,8 +290,11 @@ class Formatter(FormatterBase): def comment(self, text): # real comments (lines with two hash marks) if text[0:2] == '##': - #return "/* %s */\n" % text[2:].strip() - return '' + # https://www.dokuwiki.org/plugin:comment + comment = text[2:].strip() + if len(comment)>1: + return "/* %s */\n" % text[2:].strip() + return '\n' # Some kind of Processing Instruction # http://moinmo.in/HelpOnProcessingInstructions @@ -279,6 +304,7 @@ class Formatter(FormatterBase): if tokens[0] == 'acl': # TODO: fill acl.auth.php + logging.info('SKIPPING ACL: %s', text) return '' if tokens[0] == 'deprecated': @@ -289,6 +315,10 @@ class Formatter(FormatterBase): if tokens[0] == 'pragma': # TODO: can do 'description' via 'meta' dokuwiki plugin + pargs = tokens[1].split(None, 1) + if pargs[0]=='section-numbers': + return '/* meta: %s */' % tokens + logging.info('SKIPPING PRAGMA: %s', tokens) #return "/* pragma: %s */\n" % " ".join(tokens[1:]) return '' @@ -313,16 +343,150 @@ class Formatter(FormatterBase): def inherit(args): return apply(FormatterBase.macro, (self, macro_obj, name, args)) + def randomQuote(args): + # https://www.dokuwiki.org/plugin:xfortune + return '{{xfortune>quote:'+args+'.txt}}' + + def monthcal(args): + # https://www.dokuwiki.org/plugin:monthcal + selfname = self.page.page_name + return '{{monthcal:create_links=short,namespace='+selfname.replace('/',':')+'}}' + + def navigation(args): + # https://www.dokuwiki.org/plugin:alphaindex + selfname = self.page.page_name + args = args.split(',') + if len(args)>0: + try: + result = { + 'slides': '[<>]', + 'children': '{{alphaindex>:%s#1|nons incol}}' % selfname.replace('/',':'), + 'siblings': '{{alphaindex>.#1|nons incol}}', + 'slideshow': '/* no support for slideshow navigation */' + }[args[0].strip()] + except KeyError: + result = '/* Unknown Navigation: %s #%s#*/' % args, args[0].strip() + else: + result = '/* Unsupported Navigation: %s */' % args + return result + + def footnote(args): + return '((%s))' % args + + def dateTimeMacro(args): + #https://www.dokuwiki.org/plugin:date + #args = args.split(','); + return '{{date>%%c|timestamp=strtotime("%s")|locale=de}}' % args + + def dateMacro(args): + #https://www.dokuwiki.org/plugin:date + #args = args.split(','); + return '{{date>%%x|timestamp=strtotime("%s")|locale=de}}' % args + + def includeMacro(args): + #https://www.dokuwiki.org/plugin:include + #logging.info('Include(%s)' % args) + args = map(unicode.strip, args.split(',')); + #dokupage = ":".join(pagename.split("/")) + if len(args)==1: + return '{{page>%s&nodate}}' % ":".join(args[0].split("/")) + elif(u'titlesonly' in args): + #https://www.dokuwiki.org/plugin:changes + #https://www.dokuwiki.org/plugin:pagelist + selfname = self.page.page_name + selfNs = ":".join(selfname.split("/")).lower() + pairs = [arg.split('=') for arg in args] + # attrs = {} + # for key, value in pairs: + # attrs[key] = value + #logging.info('pairs:"%s"' % pairs) + + incName = ''#pairs[0] + incCount = -1 + incTitlesOnly = False + notNamedParam = 0 + for pair in pairs: + if len(pair)==1: + if u'titlesonly'==pair: + notNamedParam = -1 + incTitlesOnly = True + elif notNamedParam >=0: + if notNamedParam==0: + incName = pairs[notNamedParam] + notNamedParam += 1; + else: + notNamedParam = -1 + if u'items'==pair[0]: + incCount = int(pair[1]) + + resultArgs = '-h1 -textPages=""' + #(keys,values) = map() + if incCount > 0: + resultArgs += ' -idAndTitle -simpleList -sortId -nbItemsMax=%d' % incCount + else: + resultArgs += ' -nbCol=2' + + ## + ## Lister der letzten 10 Mails: + ## + if incName[0]=='^': + nspagedelim = incName.rfind('/') + ns = ":".join(incName[1:nspagedelim].split('/')).lower() + incPageReg = incName[(nspagedelim+1):] + resultArgs += ' -pregPagesOn="/^%s/"' % incPageReg + else: + ns = selfNs + + return '' % (ns, resultArgs) + + else: + logging.info('UNSUPPORTED INCLUDE "%s"' % args) + return '/* Unsupported Include: %s */' % args + + def fullsearch(args): + #args=None >> {searchform ns=} + #args='' >> {{backlinks>.}} + #args!='' >> {{search>}} + #ignore special searches. see MoinMoin page "HilfeZumSuchen" + if args is None: + return '{searchform ns=}' + elif ':' in args or ' ' in args: + logging.info('UNSUPPORTED SEARCH %s(%s)' % (name, args)) + return '/* Unsupported Search %s(%s). may be backlinks plugin will help */' % (name, args) + elif args=='': + return '{{backlinks>.}}' + elif name=='PageList': + return '{{backlinks>%s}}' % ":".join(args.split('/')).lower(); + else: + logging.info('UNSUPPORTED SEARCH %s(%s)' % (name, args)) + return '/* Unsupported Search %s(%s) */' % (name, args) + try: lookup = { - 'BR' : '\\\\', + 'BR' : ' \\\\ ', + 'br' : ' \\\\ ', 'MailTo' : email, 'GetText' : args, 'ShowSmileys' : inherit, 'ShowAttachedFiles' : showAttachedFiles, - 'Include' : inherit + 'Include' : includeMacro, + #no real fulltext search! + 'FullSearch' : fullsearch, + 'FullSearchCached' : fullsearch, + 'PageList' : fullsearch, + 'MonthCalendar' : monthcal, + 'Navigation' : navigation, + 'TableOfContents' : '', + 'RandomQuote': randomQuote, + 'Anchor': inherit, + 'Action': inherit, + 'Icon': inherit, + 'FootNote': footnote, + 'Date': dateMacro, + 'DateTime': dateTimeMacro }[name] except KeyError: + logging.info('UNDEFINED MACRO "%s"' % name) lookup = '/* UndefinedMacro: %s(%s) */' % (name, args) if type(lookup) == FunctionType: From 9023627fe50f4222b214444d36531fa3e24fb12c Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Tue, 8 Aug 2023 20:21:56 +0200 Subject: [PATCH 10/10] fix: handle non-ascii characters in page names and attachments --- doku.py | 3 +-- moin2doku.py | 17 +++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/doku.py b/doku.py index c750a19..0ecac1a 100755 --- a/doku.py +++ b/doku.py @@ -37,8 +37,7 @@ class DokuWiki: uargs.append(arg.encode('utf-8')) key = "%s:%s" % (method, ",".join(uargs)) if not self.callcache.has_key(key): - cmd = ['php', './doku.php', method ] + uargs + cmd = ['php', './doku.php', method] + [arg.encode("utf-8") for arg in uargs] res = subprocess.Popen(cmd, stdin = None, stdout = subprocess.PIPE, stderr = sys.stderr, close_fds = False).communicate() self.callcache[key] = unicode(res[0].decode('utf-8')) - print "%s->%s" % (cmd, self.callcache[key]) return self.callcache[key] diff --git a/moin2doku.py b/moin2doku.py index fd60983..8d59c0b 100755 --- a/moin2doku.py +++ b/moin2doku.py @@ -65,6 +65,11 @@ def writefile(filename, content, overwrite=False): f.writelines([line + u'\n' for line in content]) f.close() + +def encode_relaxed(text): + return text.encode("ascii", errors="ignore") + + # page = MoinMoin Page oject # ns = DokuWiki namespace where attachments to copy def copy_attachments(page, ns,randomID): @@ -84,7 +89,7 @@ def copy_attachments(page, ns,randomID): copyfile(src, dst) copystat(src, dst) except UnicodeDecodeError: - print 'ERROR: unable to convert attachment "%s"' % attachment + print 'ERROR: unable to convert attachment "%s"' % encode_relaxed(attachment) def print_help(): program = sys.argv[0] @@ -168,12 +173,12 @@ def convertfile(page, output = None, overwrite = False): if not output: output = pagename - print "Converting %s" % pagename + print "Converting %s" % encode_relaxed(pagename) if page.isUnderlayPage(): print "underlay: %s" % page.request.cfg.data_underlay_dir print "underlay: %s" % request.cfg.data_underlay_dir - print "SKIP UNDERLAY: %s" % pagename + print "SKIP UNDERLAY: %s" % encode_relaxed(pagename) return False current_exists = page.exists() @@ -202,7 +207,7 @@ def convertfile(page, output = None, overwrite = False): print "recovered %s: %s" % (rev, mtime) if not mtime: - print "NO REVISION: for %s" % pagefile + print "NO REVISION: for %s" % encode_relaxed(pagefile) continue if rev == current_rev: @@ -237,7 +242,7 @@ def convertfile(page, output = None, overwrite = False): if old_page != ID: redirect_map[old_page] = ID - print "Converted %s as %s" % (pagename, dw.wikiFN(output)) + print "Converted %s as %s" % (encode_relaxed(pagename), dw.wikiFN(output)) return True @@ -324,7 +329,7 @@ else: print "--------------------------------------------------" for output, pagename in pages.items(): - print " - %s" % pagename + print " - %s" % encode_relaxed(pagename) print "--------------------------------------------------" converted = 0