# HG changeset patch # User Paul Boddie # Date 1374272194 -7200 # Node ID 06c639688ec14836109aa52202792a75bee11a42 # Parent 465cae9a8a2b83cc0eba40e250ce923b2fcf0ae3 Added redirect page revisions where pages have been renamed. diff -r 465cae9a8a2b -r 06c639688ec1 TO_DO.txt --- a/TO_DO.txt Fri Jul 19 19:56:39 2013 +0200 +++ b/TO_DO.txt Sat Jul 20 00:16:34 2013 +0200 @@ -31,7 +31,7 @@ Consider incorporating activity information for each user using a macro placed on user home pages -Redirects +Identifier-to-page redirects Maybe redirect to specific revisions rather than to pages; thus the mapping would be from identifiers to page names plus revision numbers @@ -52,11 +52,6 @@ that would cause conflicts in the generated Moin markup should be translated with spaces separating them -Handle page renaming (add redirects, perhaps support comments on old revisions): - - DOC/Making Sure Your Lists Are Private (10715350) renamed from - DOC/Making Sure Your List Is Private - DOC/I've set up Mailman%2C created a list%2C and added myself to the list%2C but I don't get any messages! (4030512) @ in the text causes mailto: auto-linking diff -r 465cae9a8a2b -r 06c639688ec1 convert.py --- a/convert.py Fri Jul 19 19:56:39 2013 +0200 +++ b/convert.py Sat Jul 20 00:16:34 2013 +0200 @@ -355,7 +355,7 @@ f = codecs.open(manifest, "r", encoding="utf-8") try: - lines = [x.split("|") for x in f.readlines()] + lines = [x.rstrip("\n").split("|") for x in f.readlines()] lines.sort(cmp=lambda x, y: cmp(int(x[0]), int(y[0]))) # Reconstruct the lines, optionally changing the titles. @@ -395,7 +395,7 @@ if action == "AddRevision": columns = list(columns) del columns[1] - result.append("|".join(columns)) + result.append("|".join(columns) + "\n") return "".join(result) @@ -449,14 +449,34 @@ # Modify the content to include child pages and comments. - for _action, _archive_filename, filename, new_title, username, comment in result: - text = read(filename) + last_title = None + final_result = [] + + for details in result: + _action, _archive_filename, filename, new_title, username, comment = details + + # Detect renamed pages and add a redirect revision. + + if last_title and last_title != new_title and _action == "AddRevision": + renaming_versionfile = filename + ".rename" + final_result.append((_action, "_", renaming_versionfile, last_title, username, "Page renamed to %s" % new_title)) + write(renaming_versionfile, "#REDIRECT %s" % new_title) + + last_title = new_title + + # Add this revision to the manifest. + + final_result.append(details) + + # Obtain the text only if modifications are to be made. + + text = None # Add an ACL to comment pages so that people cannot change other # people's comments. if type == "Comment": - text = "#acl %s:read,write,delete,revert All:read\n%s" % (username, text) + text = "#acl %s:read,write,delete,revert All:read\n%s" % (username, text or read(filename)) # Add child page information to the content. @@ -476,25 +496,26 @@ child_pages.append(" * [[%s|%s]]" % (child_page_name, child_page_label)) - text += child_page_section % "\n".join(child_pages) + text = (text or read(filename)) + child_page_section % "\n".join(child_pages) # Add comments to the content. if exists(comments) and title and not no_translate: - text += comment_section % title + text = (text or read(filename)) + comment_section - # Rewrite the file. + # Rewrite the file if necessary. - write(filename, text) + if text: + write(filename, text) # Add the attachments to the manifest. if exists(attachments): - result += _sort_manifest(attachments, title) + final_result += _sort_manifest(attachments, title) # Serialise the manifest. - s = serialise_manifest(result) + s = serialise_manifest(final_result) if output is None: write(manifest, s)