comparison MoinMoin/wikiutil.py @ 2730:a907a61c33b3

* The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better (bug) compatibility. * Wiki parser fixes. * Reverted split_wiki/resolve_wiki to 1.5.8 code. The 1.6/1.7 code supported pagename quoting and this is not used any more. Also we need the (broken) 1.5.8 code to have the converter behave as 1.5.8 would do. Added deprecation notes for this old code. * Added new split_interwiki/resolve_interwiki code as replacement. * HTML formatter's attachment_link method got a new kw arg 'text_format' so we can call it with non-text link descriptions (e.g. images), too. * misc. fixes/cleanups
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 19 Aug 2007 19:28:35 +0200
parents 59b3d8b8971f
children 7bfe80df6772
comparison
equal deleted inserted replaced
2729:012d5ec31f92 2730:a907a61c33b3
576 request.cfg.cache.interwiki_mtime = get_max_mtime(request.cfg.shared_intermap_files, Page(request, INTERWIKI_PAGE)) 576 request.cfg.cache.interwiki_mtime = get_max_mtime(request.cfg.shared_intermap_files, Page(request, INTERWIKI_PAGE))
577 577
578 return _interwiki_list 578 return _interwiki_list
579 579
580 def split_wiki(wikiurl): 580 def split_wiki(wikiurl):
581 """ Split a wiki url, e.g: 581 """
582 582 Split a wiki url.
583 'MoinMoin:FrontPage' -> "MoinMoin", "FrontPage", ""
584 'FrontPage' -> "Self", "FrontPage", ""
585 'MoinMoin:"Page with blanks" link title' -> "MoinMoin", "Page with blanks", "link title"
586
587 can also be used for:
588
589 'attachment:"filename with blanks.txt" other title' -> "attachment", "filename with blanks.txt", "other title"
590 583
591 *** DEPRECATED FUNCTION FOR OLD 1.5 SYNTAX - ONLY STILL HERE FOR THE 1.5 -> 1.6 MIGRATION *** 584 *** DEPRECATED FUNCTION FOR OLD 1.5 SYNTAX - ONLY STILL HERE FOR THE 1.5 -> 1.6 MIGRATION ***
592 Use split_interwiki(), see below. 585 Use split_interwiki(), see below.
593 586
594 @param wikiurl: the url to split 587 @param wikiurl: the url to split
595 @rtype: tuple 588 @rtype: tuple
596 @return: (wikiname, pagename, linktext) 589 @return: (tag, tail)
597 """ 590 """
591 # !!! use a regex here!
598 try: 592 try:
599 wikiname, rest = wikiurl.split(":", 1) # e.g. MoinMoin:FrontPage 593 wikitag, tail = wikiurl.split(":", 1)
600 except ValueError: 594 except ValueError:
601 try: 595 try:
602 wikiname, rest = wikiurl.split("/", 1) # for what is this used? 596 wikitag, tail = wikiurl.split("/", 1)
603 except ValueError: 597 except ValueError:
604 wikiname, rest = 'Self', wikiurl 598 wikitag, tail = 'Self', wikiurl
605 if rest: 599 return wikitag, tail
606 if rest[0] == '"': # quoted pagename
607 idx = 1
608 max = len(rest)
609 while idx < max:
610 if idx + 1 < max:
611 next = rest[idx + 1]
612 else:
613 next = None
614 if next == rest[idx] == '"':
615 idx += 2
616 continue
617 if next != '"' and rest[idx] == '"':
618 break
619 idx += 1
620 pagename_linktext = rest[1:idx].replace('""', '"'), rest[idx+1:]
621 else: # not quoted, split on whitespace
622 pagename_linktext = rest.split(None, 1)
623 else:
624 pagename_linktext = "", ""
625 if len(pagename_linktext) == 1:
626 pagename, linktext = pagename_linktext[0], ""
627 else:
628 pagename, linktext = pagename_linktext
629 linktext = linktext.strip()
630 return wikiname, pagename, linktext
631 600
632 def split_interwiki(wikiurl): 601 def split_interwiki(wikiurl):
633 """ Split a interwiki name, into wikiname and pagename, e.g: 602 """ Split a interwiki name, into wikiname and pagename, e.g:
634 603
635 'MoinMoin:FrontPage' -> "MoinMoin", "FrontPage" 604 'MoinMoin:FrontPage' -> "MoinMoin", "FrontPage"
650 except ValueError: 619 except ValueError:
651 wikiname, pagename = 'Self', wikiurl 620 wikiname, pagename = 'Self', wikiurl
652 return wikiname, pagename 621 return wikiname, pagename
653 622
654 def resolve_wiki(request, wikiurl): 623 def resolve_wiki(request, wikiurl):
655 """ Resolve an interwiki link. 624 """
625 Resolve an interwiki link.
656 626
657 *** DEPRECATED FUNCTION FOR OLD 1.5 SYNTAX - ONLY STILL HERE FOR THE 1.5 -> 1.6 MIGRATION *** 627 *** DEPRECATED FUNCTION FOR OLD 1.5 SYNTAX - ONLY STILL HERE FOR THE 1.5 -> 1.6 MIGRATION ***
658 Use resolve_interwiki(), see below. 628 Use resolve_interwiki(), see below.
659 629
660 @param request: the request object 630 @param request: the request object
661 @param wikiurl: the InterWiki:PageName link 631 @param wikiurl: the InterWiki:PageName link
662 @rtype: tuple 632 @rtype: tuple
663 @return: (wikitag, wikiurl, wikitail, err) 633 @return: (wikitag, wikiurl, wikitail, err)
664 """ 634 """
665 _interwiki_list = load_wikimap(request) 635 _interwiki_list = load_wikimap(request)
666 wikiname, pagename, linktext = split_wiki(wikiurl) 636 # split wiki url
637 wikiname, pagename = split_wiki(wikiurl)
638
639 # return resolved url
667 if wikiname in _interwiki_list: 640 if wikiname in _interwiki_list:
668 return (wikiname, _interwiki_list[wikiname], pagename, False) 641 return (wikiname, _interwiki_list[wikiname], pagename, False)
669 else: 642 else:
670 return (wikiname, request.getScriptname(), "/InterWiki", True) 643 return (wikiname, request.getScriptname(), "/InterWiki", True)
671 644