PKLeÅ4wikirename/__init__.pyPKUAl5Cs$ $ wikirename/util.py#! /usr/bin/python from trac.core import * from trac.env import * import sys import sre import os import time import optparse import urllib __all__ = ['main', 'rename_page'] def pass_(*args): pass def print_(s, *args): print s%args def log_intercept(log): def out(s, *args): log('WikiRenamePlugin: '+s, *args) return out def rename_page(env, oldname, newname, user, ip, debug=False, db=None): """Rename a wiki page from oldname to newname, using env as the environment.""" handle_commit = False if not db: db = env.get_db_cnx() handle_commit = True cursor = db.cursor() if debug is False: debug = pass_ elif debug is True: debug = print_ else: debug = log_intercept(debug) sqlbase = ' FROM wiki w1, ' + \ '(SELECT name, MAX(version) AS max_version FROM wiki GROUP BY name) w2 ' + \ 'WHERE w1.version = w2.max_version AND w1.name = w2.name ' sql = 'SELECT w1.version,w1.text' + sqlbase + 'AND w1.name = \'%s\'' % oldname debug('Running query %r', sql) cursor.execute(sql) row = cursor.fetchone() if not row: raise TracError, 'Page not found' new_wiki_page = (newname,row[0]+1,int(time.time()),user,ip,row[1],'Name changed from %s to %s'%(oldname,newname),0) # Create a new page with the needed comment debug('Inserting new page %r', new_wiki_page) cursor.execute('INSERT INTO wiki (name,version,time,author,ipnr,text,comment,readonly) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)', new_wiki_page) # Move all the old versions of the page debug("Moving all old versions of page") cursor.execute('UPDATE wiki SET name=%s WHERE name=%s', (newname,oldname)) # Move any attachments that are on the page debug("Moving all attachments in database") cursor.execute('UPDATE attachment SET id=%s WHERE type=%s AND id=%s', (newname,'wiki',oldname)) debug("Found %s attachments on that page", cursor.rowcount) if cursor.rowcount > 0: # Change the directory where the attachments are stored, if there were any debug('Moving all attachments on file system') from_path = os.path.join(env.path, 'attachments', 'wiki', urllib.quote(oldname)) to_path = os.path.join(env.path, 'attachments', 'wiki', urllib.quote(newname)) debug('Moving from %r to %r', from_path, to_path) os.renames(from_path, to_path) # Get a list of all wiki pages containing links to the old page debug("Trying to fix links") sql = 'SELECT w1.version,w1.name,w1.text' + sqlbase + "AND w1.text like '%%[wiki:%s%%'" % oldname debug('Running query %r', sql) cursor.execute(sql) # Rewrite all links to the old page, such as to point to the new page for row in list(cursor): debug("Found a page with a backlink in it: %s (v%s)", row[1], row[0]) newtext = sre.sub('\[wiki:%s'%oldname,'[wiki:%s'%newname,row[2]) cursor.execute('UPDATE wiki SET text=%s WHERE name=%s AND version=%s', (newtext,row[1],row[0])) if handle_commit: db.commit() PKM†68%­¬3µµwikirename/script.pyc;ò ñ^„Dc@s…dkTdklZdkZdkZdkZdkZdkZdkl Z d„Z d„Z d„Z e djo e ƒndS((s*(s EnvironmentN(s rename_pagecCs-tidjotidSn tiƒSdS(sFind the current username.sntsUSERNAMEN(sossnamesenvironsgetlogin(((s5build/bdist.darwin-8.0.1-x86/egg/wikirename/script.pysusernamesc GsÍtiddddƒ}|iddddd d d tƒ|it|d ƒƒ\}}t |ƒd jo|i dƒn|d}|d }|d}t|ƒ}t|||tƒdd|iƒdS(Nsusages'Usage: %prog old-name new-name trac-envsversionsRenamePage 2.0s-ds--debugshelpsActivate debuggingsactions store_truesdefaultiisNot enough argumentsiis 127.0.0.1sdebug(soptparses OptionParsersparsers add_optionsFalses parse_argsslistsargvsoptionssargsslenserrorsoldnamesnewnamesenvpaths Environmentsenvs rename_pagesusernamesdebug(sargvsparsersargssnewnamesenvsenvpathsoptionssoldname((s5build/bdist.darwin-8.0.1-x86/egg/wikirename/script.pysmains"    cCsttiŒdS(N(smainssyssargv(((s5build/bdist.darwin-8.0.1-x86/egg/wikirename/script.pysrunss__main__(s trac.corestrac.envs Environmentssysssresosstimesoptparseswikirename.utils rename_pagesusernamesmainsruns__name__( susernamessyssrunssresoptparses rename_pages Environmentstimesmainsos((s5build/bdist.darwin-8.0.1-x86/egg/wikirename/script.pys?s -    PKM†68å:U?RRwikirename/web_ui.pyc;ò SWEc@s®dkTdklZdklZdklZdklZdk l Z dk Z eeegZ ydk lZe ieƒWnej onXdefd „ƒYZdS( (s*(sMarkup(sIPermissionRequestor(sITemplateProvider(sIAdminPageProvider(s rename_pageN(s ICtxtnavAddersWikiRenameModulecBsWtZdZeeŒd„Zd„Zd„Zd„Zd„Z d„Z d„Z RS(s8An evil module that adds a rename button to the wiki UI.cCs@|iidƒp|iidƒ}|iidƒo|SdS(Ns WIKI_RENAMEs WIKI_ADMINs/wiki(sreqspermshas_permissions path_infos startswith(sselfsreqsperm((s5build/bdist.darwin-8.0.1-x86/egg/wikirename/web_ui.pysmatch_ctxtnav_adds%ccs9|idpd}|iiddƒd|dfVdS(Nis WikiStartsgenerals wikirenames?redirect=1&src_page=s Rename page(sreqs path_infospageshrefsadmin(sselfsreqspage((s5build/bdist.darwin-8.0.1-x86/egg/wikirename/web_ui.pysget_ctxtnav_addsscCs dgSdS(Ns WIKI_RENAME((sself((s5build/bdist.darwin-8.0.1-x86/egg/wikirename/web_ui.pysget_permission_actions"sccs>|iidƒp|iidƒoddddfVndS(Ns WIKI_RENAMEs WIKI_ADMINsgeneralsGenerals wikirenames Wiki Rename(sreqspermshas_permission(sselfsreq((s5build/bdist.darwin-8.0.1-x86/egg/wikirename/web_ui.pysget_admin_pages&s&cCs*|iiddƒ}|iiddƒ}|iiddƒdj}ti|ƒ}ti|ƒ}d|iiƒjo|| p| o t d‚nt |i |||i |id|iiƒ|o|i|ii|ƒƒnd}d}n||id <||id <||id
Rename Page
PK!RÕ48Œ ¸¸(wikirename/templates/wikirename_admin.cs

Wiki Rename

Rename Page
PKO†68“×2EGG-INFO/zip-safe PKJ†68°ÿ[ CCEGG-INFO/SOURCES.txtsetup.py TracWikiRename.egg-info/PKG-INFO TracWikiRename.egg-info/SOURCES.txt TracWikiRename.egg-info/dependency_links.txt TracWikiRename.egg-info/entry_points.txt TracWikiRename.egg-info/requires.txt TracWikiRename.egg-info/top_level.txt wikirename/__init__.py wikirename/script.py wikirename/util.py wikirename/web_ui.py PKI†68\ßóqqEGG-INFO/entry_points.txt[trac.plugins] wikirename.web_ui = wikirename.web_ui [console_scripts] trac-wikirename = wikirename.script:run PKI†68“×2EGG-INFO/dependency_links.txt PKI†68Ü>´EGG-INFO/PKG-INFOMetadata-Version: 1.0 Name: TracWikiRename Version: 1.2 Summary: Add simple support for renaming/moving wiki pages Home-page: http://trac-hacks.org/wiki/WikiRenamePlugin Author: Noah Kantrowitz Author-email: coderanger@yahoo.com License: BSD Description: Adds basic support for renaming wiki pages. A console script is provided, as is a WebAdmin module. Please read the notice on the homepage for a list of known shortcomings. Keywords: trac plugin wiki page rename Platform: UNKNOWN Classifier: Framework :: Trac PKI†68“Î'ÈEGG-INFO/requires.txtTracWebAdmin TracCtxtnavAddPKI†68áUø¾ EGG-INFO/top_level.txtwikirename PKLeÅ4¤wikirename/__init__.pyPKUAl5Cs$ $ ¤4wikirename/util.pyPKM†68%­¬3µµ¤ˆ wikirename/script.pycPKM†68å:U?RR¤pwikirename/web_ui.pycPKLeÅ4®Âß<——¤õ$wikirename/script.pyPKM†68B5Žf¤¾(wikirename/util.pycPKM†68æg÷¤8wikirename/__init__.pycPKUAl5]ù̀à à ¤Ä8wikirename/web_ui.pyPKLeÅ43ë¡¡"¤¹Bwikirename/templates/wikirename.csPK!RÕ48Œ ¸¸(¤šEwikirename/templates/wikirename_admin.csPKO†68“×2¤˜HEGG-INFO/zip-safePKJ†68°ÿ[ CC¤ÈHEGG-INFO/SOURCES.txtPKI†68\ßóqq¤=JEGG-INFO/entry_points.txtPKI†68“×2¤åJEGG-INFO/dependency_links.txtPKI†68Ü>´¤!KEGG-INFO/PKG-INFOPKI†68“Î'ȤlMEGG-INFO/requires.txtPKI†68áUø¾ ¤ºMEGG-INFO/top_level.txtPK“ùM