Back to index

moin  1.9.0~rc2
Classes | Functions | Variables
MoinMoin.script.migration.wikiutil160a Namespace Reference

Classes

class  InvalidFileNameError
class  MetaDict
class  MimeType
class  PluginError
class  PluginMissingError
class  PluginAttributeError
class  ParameterParser

Functions

def decodeUnknownInput
 Getting data from user/Sending data to user.
def decodeUserInput
def url_quote
def url_quote_plus
def url_unquote
def parseQueryString
def makeQueryString
def quoteWikinameURL
def escape
def clean_comment
def make_breakable
def quoteWikinameFS
def unquoteWikiname
def timestamp2version
def version2timestamp
def quoteName
def unquoteName
def generate_file_list
def get_max_mtime
def load_wikimap
def split_wiki
def resolve_wiki
def join_wiki
def isSystemPage
 Page types (based on page names)
def isTemplatePage
def isGroupPage
def filterCategoryPages
def getLocalizedPage
def getFrontPage
def getHomePage
def getInterwikiHomePage
def AbsPageName
def pagelinkmarkup
def importPlugin
def importWikiPlugin
def importBuiltinPlugin
def importNameFromPlugin
def builtinPlugins
def wikiPlugins
def getPlugins
def searchAndImportPlugin
def getParserForExtension
 Parsers.
def parseAttributes
 Parameter parsing.
def taintfilename
def mapURL
def getUnicodeIndexGroup
def isStrictWikiname
def isPicture
def link_tag
def containsConflictMarker
def pagediff
def createTicket
 Tickets - used by RenamePage and DeletePage.
def checkTicket
def renderText
def getProcessingInstructions
def getParser

Variables

string PARENT_PREFIX = "../"
tuple PARENT_PREFIX_LEN = len(PARENT_PREFIX)
string CHILD_PREFIX = "/"
tuple CHILD_PREFIX_LEN = len(CHILD_PREFIX)
tuple UNSAFE = re.compile(r'[^a-zA-Z0-9_]+')
 Storage.
tuple QUOTED = re.compile(r'\(([a-fA-F0-9]+)\)')
list INTEGER_METAS
string QUOTE_CHARS = u"'\""
string INTERWIKI_PAGE = "InterWikiMap"
 InterWiki.
dictionary MIMETYPES_MORE
dictionary MIMETYPES_sanitize_mapping
dictionary MIMETYPES_spoil_mapping = {}

Class Documentation

class MoinMoin::script::migration::wikiutil160a::InvalidFileNameError
Called when we find an invalid file name 

Definition at line 21 of file wikiutil160a.py.


Function Documentation

def MoinMoin.script.migration.wikiutil160a.AbsPageName (   request,
  context,
  pagename 
)
Return the absolute pagename for a (possibly) relative pagename.

@param context: name of the page where "pagename" appears on
@param pagename: the (possibly relative) page name
@rtype: string
@return: the absolute page name

Definition at line 797 of file wikiutil160a.py.

00797 
00798 def AbsPageName(request, context, pagename):
00799     """
00800     Return the absolute pagename for a (possibly) relative pagename.
00801 
00802     @param context: name of the page where "pagename" appears on
00803     @param pagename: the (possibly relative) page name
00804     @rtype: string
00805     @return: the absolute page name
00806     """
00807     if pagename.startswith(PARENT_PREFIX):
00808         pagename = '/'.join(filter(None, context.split('/')[:-1] + [pagename[PARENT_PREFIX_LEN:]]))
00809     elif pagename.startswith(CHILD_PREFIX):
00810         pagename = context + '/' + pagename[CHILD_PREFIX_LEN:]
00811     return pagename

Gets a list of modules in MoinMoin.'kind'

@param kind: what kind of modules we look for
@rtype: list
@return: module names

Definition at line 1049 of file wikiutil160a.py.

01049 
01050 def builtinPlugins(kind):
01051     """ Gets a list of modules in MoinMoin.'kind'
01052 
01053     @param kind: what kind of modules we look for
01054     @rtype: list
01055     @return: module names
01056     """
01057     modulename = "MoinMoin." + kind
01058     return pysupport.importName(modulename, "modules")
01059 

Here is the caller graph for this function:

def MoinMoin.script.migration.wikiutil160a.checkTicket (   request,
  ticket 
)
Check validity of a previously created ticket

Definition at line 1597 of file wikiutil160a.py.

01597 
01598 def checkTicket(request, ticket):
01599     """Check validity of a previously created ticket"""
01600     try:
01601         timestamp_str = ticket.split('.')[0]
01602         timestamp = int(timestamp_str, 16)
01603     except ValueError:
01604         # invalid or empty ticket
01605         return False
01606     now = time.time()
01607     if timestamp < now - 10 * 3600:
01608         # we don't accept tickets older than 10h
01609         return False
01610     ourticket = createTicket(request, timestamp_str)
01611     return ticket == ourticket
01612 

Here is the call graph for this function:

Clean comment - replace CR, LF, TAB by whitespace, delete control chars
    TODO: move this to config, create on first call then return cached.

Definition at line 223 of file wikiutil160a.py.

00223 
00224 def clean_comment(comment):
00225     """ Clean comment - replace CR, LF, TAB by whitespace, delete control chars
00226         TODO: move this to config, create on first call then return cached.
00227     """
00228     # we only have input fields with max 200 chars, but spammers send us more
00229     if len(comment) > 201:
00230         comment = u''
00231     remap_chars = {
00232         ord(u'\t'): u' ',
00233         ord(u'\r'): u' ',
00234         ord(u'\n'): u' ',
00235     }
00236     control_chars = u'\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f' \
00237                     '\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f'
00238     for c in control_chars:
00239         remap_chars[c] = None
00240     comment = comment.translate(remap_chars)
00241     return comment

Returns true if there is a conflict marker in the text. 

Definition at line 1550 of file wikiutil160a.py.

01550 
01551 def containsConflictMarker(text):
01552     """ Returns true if there is a conflict marker in the text. """
01553     return "/!\\ '''Edit conflict" in text

def MoinMoin.script.migration.wikiutil160a.createTicket (   request,
  tm = None 
)

Tickets - used by RenamePage and DeletePage.

Create a ticket using a site-specific secret (the config)

Definition at line 1579 of file wikiutil160a.py.

01579 
01580 def createTicket(request, tm=None):
01581     """Create a ticket using a site-specific secret (the config)"""
01582     from MoinMoin.support.python_compatibility import hash_new
01583     ticket = tm or "%010x" % time.time()
01584     digest = hash_new('sha1', ticket)
01585 
01586     varnames = ['data_dir', 'data_underlay_dir', 'language_default',
01587                 'mail_smarthost', 'mail_from', 'page_front_page',
01588                 'theme_default', 'sitename', 'logo_string',
01589                 'interwikiname', 'user_homewiki', 'acl_rights_before', ]
01590     for varname in varnames:
01591         var = getattr(request.cfg, varname, None)
01592         if isinstance(var, (str, unicode)):
01593             digest.update(repr(var))
01594 
01595     return "%s.%s" % (ticket, digest.hexdigest())
01596 

Here is the caller graph for this function:

Getting data from user/Sending data to user.

Decode unknown input, like text attachments

First we try utf-8 because it has special format, and it will decode
only utf-8 files. Then we try config.charset, then iso-8859-1 using
'replace'. We will never raise an exception, but may return junk
data.

WARNING: Use this function only for data that you view, not for data
that you save in the wiki.

@param text: the text to decode, string
@rtype: unicode
@return: decoded text (maybe wrong)

Definition at line 35 of file wikiutil160a.py.

00035 
00036 def decodeUnknownInput(text):
00037     """ Decode unknown input, like text attachments
00038 
00039     First we try utf-8 because it has special format, and it will decode
00040     only utf-8 files. Then we try config.charset, then iso-8859-1 using
00041     'replace'. We will never raise an exception, but may return junk
00042     data.
00043 
00044     WARNING: Use this function only for data that you view, not for data
00045     that you save in the wiki.
00046 
00047     @param text: the text to decode, string
00048     @rtype: unicode
00049     @return: decoded text (maybe wrong)
00050     """
00051     # Shortcut for unicode input
00052     if isinstance(text, unicode):
00053         return text
00054 
00055     try:
00056         return unicode(text, 'utf-8')
00057     except UnicodeError:
00058         if config.charset not in ['utf-8', 'iso-8859-1']:
00059             try:
00060                 return unicode(text, config.charset)
00061             except UnicodeError:
00062                 pass
00063         return unicode(text, 'iso-8859-1', 'replace')
00064 

def MoinMoin.script.migration.wikiutil160a.decodeUserInput (   s,
  charsets = [config.charset] 
)
Decodes input from the user.

@param s: the string to unquote
@param charsets: list of charsets to assume the string is in
@rtype: unicode
@return: the unquoted string as unicode

Definition at line 65 of file wikiutil160a.py.

00065 
00066 def decodeUserInput(s, charsets=[config.charset]):
00067     """
00068     Decodes input from the user.
00069 
00070     @param s: the string to unquote
00071     @param charsets: list of charsets to assume the string is in
00072     @rtype: unicode
00073     @return: the unquoted string as unicode
00074     """
00075     for charset in charsets:
00076         try:
00077             return s.decode(charset)
00078         except UnicodeError:
00079             pass
00080     raise UnicodeError('The string %r cannot be decoded.' % s)
00081 
00082 
00083 # this is a thin wrapper around urllib (urllib only handles str, not unicode)
00084 # with py <= 2.4.1, it would give incorrect results with unicode
# with py == 2.4.2, it crashes with unicode, if it contains non-ASCII chars

Here is the caller graph for this function:

def MoinMoin.script.migration.wikiutil160a.escape (   s,
  quote = 0 
)
Escape possible html tags

Replace special characters '&', '<' and '>' by SGML entities.
(taken from cgi.escape so we don't have to include that, even if we
don't use cgi at all)

@param s: (unicode) string to escape
@param quote: bool, should transform '\"' to '&quot;'
@rtype: when called with a unicode object, return unicode object - otherwise return string object
@return: escaped version of s

Definition at line 198 of file wikiutil160a.py.

00198 
00199 def escape(s, quote=0):
00200     """ Escape possible html tags
00201 
00202     Replace special characters '&', '<' and '>' by SGML entities.
00203     (taken from cgi.escape so we don't have to include that, even if we
00204     don't use cgi at all)
00205 
00206     @param s: (unicode) string to escape
00207     @param quote: bool, should transform '\"' to '&quot;'
00208     @rtype: when called with a unicode object, return unicode object - otherwise return string object
00209     @return: escaped version of s
00210     """
00211     if not isinstance(s, (str, unicode)):
00212         s = str(s)
00213 
00214     # Must first replace &
00215     s = s.replace("&", "&amp;")
00216 
00217     # Then other...
00218     s = s.replace("<", "&lt;")
00219     s = s.replace(">", "&gt;")
00220     if quote:
00221         s = s.replace('"', "&quot;")
00222     return s

Here is the caller graph for this function:

Return category pages in pagelist

WARNING: DO NOT USE THIS TO FILTER THE FULL PAGE LIST! Use
getPageList with a filter function.

If you pass a list with a single pagename, either that is returned
or an empty list, thus you can use this function like a `isCategoryPage`
one.

@param pagelist: a list of pages
@rtype: list
@return: only the category pages of pagelist

Definition at line 675 of file wikiutil160a.py.

00675 
00676 def filterCategoryPages(request, pagelist):
00677     """ Return category pages in pagelist
00678 
00679     WARNING: DO NOT USE THIS TO FILTER THE FULL PAGE LIST! Use
00680     getPageList with a filter function.
00681 
00682     If you pass a list with a single pagename, either that is returned
00683     or an empty list, thus you can use this function like a `isCategoryPage`
00684     one.
00685 
00686     @param pagelist: a list of pages
00687     @rtype: list
00688     @return: only the category pages of pagelist
00689     """
00690     func = request.cfg.cache.page_category_regex.search
00691     return filter(func, pagelist)
00692 

generates a list of all files. for internal use. 

Definition at line 489 of file wikiutil160a.py.

00489 
00490 def generate_file_list(request):
00491     """ generates a list of all files. for internal use. """
00492 
00493     # order is important here, the local intermap file takes
00494     # precedence over the shared one, and is thus read AFTER
00495     # the shared one
00496     intermap_files = request.cfg.shared_intermap
00497     if not isinstance(intermap_files, list):
00498         intermap_files = [intermap_files]
00499     else:
00500         intermap_files = intermap_files[:]
00501     intermap_files.append(os.path.join(request.cfg.data_dir, "intermap.txt"))
00502     request.cfg.shared_intermap_files = [filename for filename in intermap_files
00503                                          if filename and os.path.isfile(filename)]
00504 

Here is the caller graph for this function:

Returns the highest modification time of the files in file_list and the
page page. 

Definition at line 505 of file wikiutil160a.py.

00505 
00506 def get_max_mtime(file_list, page):
00507     """ Returns the highest modification time of the files in file_list and the
00508     page page. """
00509     timestamps = [os.stat(filename).st_mtime for filename in file_list]
00510     if page.exists():
00511         # exists() is cached and thus cheaper than mtime_usecs()
00512         timestamps.append(version2timestamp(page.mtime_usecs()))
00513     return max(timestamps)
00514 

Here is the call graph for this function:

Here is the caller graph for this function:

Convenience function to get localized front page

@param request: current request
@rtype: Page object
@return localized page_front_page, if there is a translation

Definition at line 732 of file wikiutil160a.py.

00732 
00733 def getFrontPage(request):
00734     """ Convenience function to get localized front page
00735 
00736     @param request: current request
00737     @rtype: Page object
00738     @return localized page_front_page, if there is a translation
00739     """
00740     return getLocalizedPage(request, request.cfg.page_front_page)
00741 

Here is the call graph for this function:

def MoinMoin.script.migration.wikiutil160a.getHomePage (   request,
  username = None 
)
Get a user's homepage, or return None for anon users and
those who have not created a homepage.

DEPRECATED - try to use getInterwikiHomePage (see below)

@param request: the request object
@param username: the user's name
@rtype: Page
@return: user's homepage object - or None

Definition at line 742 of file wikiutil160a.py.

00742 
00743 def getHomePage(request, username=None):
00744     """
00745     Get a user's homepage, or return None for anon users and
00746     those who have not created a homepage.
00747 
00748     DEPRECATED - try to use getInterwikiHomePage (see below)
00749 
00750     @param request: the request object
00751     @param username: the user's name
00752     @rtype: Page
00753     @return: user's homepage object - or None
00754     """
00755     from MoinMoin.Page import Page
00756     # default to current user
00757     if username is None and request.user.valid:
00758         username = request.user.name
00759 
00760     # known user?
00761     if username:
00762         # Return home page
00763         page = Page(request, username)
00764         if page.exists():
00765             return page
00766 
00767     return None
00768 

def MoinMoin.script.migration.wikiutil160a.getInterwikiHomePage (   request,
  username = None 
)
Get a user's homepage.

cfg.user_homewiki influences behaviour of this:
'Self' does mean we store user homepage in THIS wiki.
When set to our own interwikiname, it behaves like with 'Self'.

'SomeOtherWiki' means we store user homepages in another wiki.

@param request: the request object
@param username: the user's name
@rtype: tuple (or None for anon users)
@return: (wikiname, pagename)

Definition at line 769 of file wikiutil160a.py.

00769 
00770 def getInterwikiHomePage(request, username=None):
00771     """
00772     Get a user's homepage.
00773 
00774     cfg.user_homewiki influences behaviour of this:
00775     'Self' does mean we store user homepage in THIS wiki.
00776     When set to our own interwikiname, it behaves like with 'Self'.
00777 
00778     'SomeOtherWiki' means we store user homepages in another wiki.
00779 
00780     @param request: the request object
00781     @param username: the user's name
00782     @rtype: tuple (or None for anon users)
00783     @return: (wikiname, pagename)
00784     """
00785     # default to current user
00786     if username is None and request.user.valid:
00787         username = request.user.name
00788     if not username:
00789         return None # anon user
00790 
00791     homewiki = request.cfg.user_homewiki
00792     if homewiki == request.cfg.interwikiname:
00793         homewiki = 'Self'
00794 
00795     return homewiki, username
00796 

Get a system page according to user settings and available translations.

We include some special treatment for the case that <pagename> is the
currently rendered page, as this is the case for some pages used very
often, like FrontPage, RecentChanges etc. - in that case we reuse the
already existing page object instead creating a new one.

@param request: the request object
@param pagename: the name of the page
@rtype: Page object
@return: the page object of that system page, using a translated page,
         if it exists

Definition at line 693 of file wikiutil160a.py.

00693 
00694 def getLocalizedPage(request, pagename): # was: getSysPage
00695     """ Get a system page according to user settings and available translations.
00696 
00697     We include some special treatment for the case that <pagename> is the
00698     currently rendered page, as this is the case for some pages used very
00699     often, like FrontPage, RecentChanges etc. - in that case we reuse the
00700     already existing page object instead creating a new one.
00701 
00702     @param request: the request object
00703     @param pagename: the name of the page
00704     @rtype: Page object
00705     @return: the page object of that system page, using a translated page,
00706              if it exists
00707     """
00708     from MoinMoin.Page import Page
00709     i18n_name = request.getText(pagename, formatted=False)
00710     pageobj = None
00711     if i18n_name != pagename:
00712         if request.page and i18n_name == request.page.page_name:
00713             # do not create new object for current page
00714             i18n_page = request.page
00715             if i18n_page.exists():
00716                 pageobj = i18n_page
00717         else:
00718             i18n_page = Page(request, i18n_name)
00719             if i18n_page.exists():
00720                 pageobj = i18n_page
00721 
00722     # if we failed getting a translated version of <pagename>,
00723     # we fall back to english
00724     if not pageobj:
00725         if request.page and pagename == request.page.page_name:
00726             # do not create new object for current page
00727             pageobj = request.page
00728         else:
00729             pageobj = Page(request, pagename)
00730     return pageobj
00731 

Here is the caller graph for this function:

def MoinMoin.script.migration.wikiutil160a.getParser (   request,
  text 
)
gets the parser from raw wiki murkup

Definition at line 1638 of file wikiutil160a.py.

01638 
01639 def getParser(request, text):
01640     """gets the parser from raw wiki murkup"""
01641     # check for XML content
01642     if text and text[:5] == '<?xml':
01643         pi_format = "xslt"
01644     else:
01645         # check processing instructions
01646         pi = getProcessingInstructions(text)
01647         pi_format = pi.get("format", request.cfg.default_markup or "wiki").lower()
01648 
01649     Parser = searchAndImportPlugin(request.cfg, "parser", pi_format)
01650     return Parser
01651 

Here is the call graph for this function:

Parsers.

Returns the Parser class of the parser fit to handle a file
with the given extension. The extension should be in the same
format as os.path.splitext returns it (i.e. with the dot).
Returns None if no parser willing to handle is found.
The dict of extensions is cached in the config object.

@param cfg: the Config instance for the wiki in question
@param extension: the filename extension including the dot
@rtype: class, None
@returns: the parser class or None

Definition at line 1116 of file wikiutil160a.py.

01116 
01117 def getParserForExtension(cfg, extension):
01118     """
01119     Returns the Parser class of the parser fit to handle a file
01120     with the given extension. The extension should be in the same
01121     format as os.path.splitext returns it (i.e. with the dot).
01122     Returns None if no parser willing to handle is found.
01123     The dict of extensions is cached in the config object.
01124 
01125     @param cfg: the Config instance for the wiki in question
01126     @param extension: the filename extension including the dot
01127     @rtype: class, None
01128     @returns: the parser class or None
01129     """
01130     if not hasattr(cfg.cache, 'EXT_TO_PARSER'):
01131         etp, etd = {}, None
01132         for pname in getPlugins('parser', cfg):
01133             try:
01134                 Parser = importPlugin(cfg, 'parser', pname, 'Parser')
01135             except PluginMissingError:
01136                 continue
01137             if hasattr(Parser, 'extensions'):
01138                 exts = Parser.extensions
01139                 if isinstance(exts, list):
01140                     for ext in Parser.extensions:
01141                         etp[ext] = Parser
01142                 elif str(exts) == '*':
01143                     etd = Parser
01144         cfg.cache.EXT_TO_PARSER = etp
01145         cfg.cache.EXT_TO_PARSER_DEFAULT = etd
01146 
01147     return cfg.cache.EXT_TO_PARSER.get(extension, cfg.cache.EXT_TO_PARSER_DEFAULT)
01148 

Here is the call graph for this function:

Gets a list of plugin names of kind

@param kind: what kind of modules we look for
@rtype: list
@return: module names

Definition at line 1075 of file wikiutil160a.py.

01075 
01076 def getPlugins(kind, cfg):
01077     """ Gets a list of plugin names of kind
01078 
01079     @param kind: what kind of modules we look for
01080     @rtype: list
01081     @return: module names
01082     """
01083     # Copy names from builtin plugins - so we dont destroy the value
01084     all_plugins = builtinPlugins(kind)[:]
01085 
01086     # Add extension plugins without duplicates
01087     for plugin in wikiPlugins(kind, cfg):
01088         if plugin not in all_plugins:
01089             all_plugins.append(plugin)
01090 
01091     return all_plugins
01092 

Here is the call graph for this function:

Here is the caller graph for this function:

creates dict of processing instructions from raw wiki markup

Definition at line 1626 of file wikiutil160a.py.

01626 
01627 def getProcessingInstructions(text):
01628     """creates dict of processing instructions from raw wiki markup"""
01629     kw = {}
01630     for line in text.split('\n'):
01631         if line.startswith('#'):
01632             for pi in ("format", "refresh", "redirect", "deprecated", "pragma", "form", "acl", "language"):
01633                 if line[1:].lower().startswith(pi):
01634                     kw[pi] = line[len(pi)+1:].strip()
01635                     break
01636     return kw
01637 

Here is the caller graph for this function:

Return a group letter for `name`, which must be a unicode string.
Currently supported: Hangul Syllables (U+AC00 - U+D7AF)

@param name: a string
@rtype: string
@return: group letter or None

Definition at line 1459 of file wikiutil160a.py.

01459 
01460 def getUnicodeIndexGroup(name):
01461     """
01462     Return a group letter for `name`, which must be a unicode string.
01463     Currently supported: Hangul Syllables (U+AC00 - U+D7AF)
01464 
01465     @param name: a string
01466     @rtype: string
01467     @return: group letter or None
01468     """
01469     c = name[0]
01470     if u'\uAC00' <= c <= u'\uD7AF': # Hangul Syllables
01471         return unichr(0xac00 + (int(ord(c) - 0xac00) / 588) * 588)
01472     else:
01473         return c.upper() # we put lower and upper case words into the same index group
01474 

def MoinMoin.script.migration.wikiutil160a.importBuiltinPlugin (   kind,
  name,
  function = "execute" 
)
Import builtin plugin from MoinMoin package

See importPlugin docstring.

Definition at line 1026 of file wikiutil160a.py.

01026 
01027 def importBuiltinPlugin(kind, name, function="execute"):
01028     """ Import builtin plugin from MoinMoin package
01029 
01030     See importPlugin docstring.
01031     """
01032     if not name in builtinPlugins(kind):
01033         raise PluginMissingError
01034     moduleName = 'MoinMoin.%s.%s' % (kind, name)
01035     return importNameFromPlugin(moduleName, function)
01036 

Here is the call graph for this function:

Return name from plugin module

Raise PluginAttributeError if name does not exists.

Definition at line 1037 of file wikiutil160a.py.

01037 
01038 def importNameFromPlugin(moduleName, name):
01039     """ Return name from plugin module
01040 
01041     Raise PluginAttributeError if name does not exists.
01042     """
01043     module = __import__(moduleName, globals(), {}, [name])
01044     try:
01045         return getattr(module, name)
01046     except AttributeError:
01047         raise PluginAttributeError
01048 

Here is the caller graph for this function:

def MoinMoin.script.migration.wikiutil160a.importPlugin (   cfg,
  kind,
  name,
  function = "execute" 
)
Import wiki or builtin plugin

Returns function from a plugin module name. If name can not be
imported, raise PluginMissingError. If function is missing, raise
PluginAttributeError.

kind may be one of 'action', 'formatter', 'macro', 'parser' or any other
directory that exist in MoinMoin or data/plugin.

Wiki plugins will always override builtin plugins. If you want
specific plugin, use either importWikiPlugin or importBuiltinPlugin
directly.

@param cfg: wiki config instance
@param kind: what kind of module we want to import
@param name: the name of the module
@param function: the function name
@rtype: any object
@return: "function" of module "name" of kind "kind", or None

Definition at line 988 of file wikiutil160a.py.

00988 
00989 def importPlugin(cfg, kind, name, function="execute"):
00990     """ Import wiki or builtin plugin
00991 
00992     Returns function from a plugin module name. If name can not be
00993     imported, raise PluginMissingError. If function is missing, raise
00994     PluginAttributeError.
00995 
00996     kind may be one of 'action', 'formatter', 'macro', 'parser' or any other
00997     directory that exist in MoinMoin or data/plugin.
00998 
00999     Wiki plugins will always override builtin plugins. If you want
01000     specific plugin, use either importWikiPlugin or importBuiltinPlugin
01001     directly.
01002 
01003     @param cfg: wiki config instance
01004     @param kind: what kind of module we want to import
01005     @param name: the name of the module
01006     @param function: the function name
01007     @rtype: any object
01008     @return: "function" of module "name" of kind "kind", or None
01009     """
01010     try:
01011         return importWikiPlugin(cfg, kind, name, function)
01012     except PluginMissingError:
01013         return importBuiltinPlugin(kind, name, function)
01014 

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.script.migration.wikiutil160a.importWikiPlugin (   cfg,
  kind,
  name,
  function = "execute" 
)
Import plugin from the wiki data directory

See importPlugin docstring.

Definition at line 1015 of file wikiutil160a.py.

01015 
01016 def importWikiPlugin(cfg, kind, name, function="execute"):
01017     """ Import plugin from the wiki data directory
01018 
01019     See importPlugin docstring.
01020     """
01021     if not name in wikiPlugins(kind, cfg):
01022         raise PluginMissingError
01023     moduleName = '%s.plugin.%s.%s' % (cfg.siteid, kind, name)
01024     return importNameFromPlugin(moduleName, function)
01025 

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.script.migration.wikiutil160a.isGroupPage (   request,
  pagename 
)
Is this a name of group page?

@param pagename: the page name
@rtype: bool
@return: true if page is a form page

Definition at line 665 of file wikiutil160a.py.

00665 
00666 def isGroupPage(request, pagename):
00667     """ Is this a name of group page?
00668 
00669     @param pagename: the page name
00670     @rtype: bool
00671     @return: true if page is a form page
00672     """
00673     return request.cfg.cache.page_group_regex.search(pagename) is not None
00674 

Is this a picture's url?

@param url: the url in question
@rtype: bool
@return: true if url points to a picture

Definition at line 1486 of file wikiutil160a.py.

01486 
01487 def isPicture(url):
01488     """
01489     Is this a picture's url?
01490 
01491     @param url: the url in question
01492     @rtype: bool
01493     @return: true if url points to a picture
01494     """
01495     extpos = url.rfind(".")
01496     return extpos > 0 and url[extpos:].lower() in ['.gif', '.jpg', '.jpeg', '.png', '.bmp', '.ico', ]
01497 

def MoinMoin.script.migration.wikiutil160a.isStrictWikiname (   name,
  word_re = re.compile(ur"^(?:[%(u)s][%(l)s]+){2,}$" % {'u': config.chars_upper,
  l 
)

Definition at line 1475 of file wikiutil160a.py.

01475 
01476 def isStrictWikiname(name, word_re=re.compile(ur"^(?:[%(u)s][%(l)s]+){2,}$" % {'u': config.chars_upper, 'l': config.chars_lower})):
01477     """
01478     Check whether this is NOT an extended name.
01479 
01480     @param name: the wikiname in question
01481     @rtype: bool
01482     @return: true if name matches the word_re
01483     """
01484     return word_re.match(name)
01485 

def MoinMoin.script.migration.wikiutil160a.isSystemPage (   request,
  pagename 
)

Page types (based on page names)

Is this a system page? Uses AllSystemPagesGroup internally.

@param request: the request object
@param pagename: the page name
@rtype: bool
@return: true if page is a system page

Definition at line 643 of file wikiutil160a.py.

00643 
00644 def isSystemPage(request, pagename):
00645     """ Is this a system page? Uses AllSystemPagesGroup internally.
00646 
00647     @param request: the request object
00648     @param pagename: the page name
00649     @rtype: bool
00650     @return: true if page is a system page
00651     """
00652     return (pagename in request.groups.get(u'SystemPagesGroup', []) or
00653         isTemplatePage(request, pagename))
00654 

Here is the call graph for this function:

def MoinMoin.script.migration.wikiutil160a.isTemplatePage (   request,
  pagename 
)
Is this a template page?

@param pagename: the page name
@rtype: bool
@return: true if page is a template page

Definition at line 655 of file wikiutil160a.py.

00655 
00656 def isTemplatePage(request, pagename):
00657     """ Is this a template page?
00658 
00659     @param pagename: the page name
00660     @rtype: bool
00661     @return: true if page is a template page
00662     """
00663     return request.cfg.cache.page_template_regex.search(pagename) is not None
00664 

Here is the caller graph for this function:

def MoinMoin.script.migration.wikiutil160a.join_wiki (   wikiurl,
  wikitail 
)
Add a (url_quoted) page name to an interwiki url.

Note: We can't know what kind of URL quoting a remote wiki expects.
      We just use a utf-8 encoded string with standard URL quoting.

@param wikiurl: wiki url, maybe including a $PAGE placeholder
@param wikitail: page name
@rtype: string
@return: generated URL of the page in the other wiki

Definition at line 620 of file wikiutil160a.py.

00620 
00621 def join_wiki(wikiurl, wikitail):
00622     """
00623     Add a (url_quoted) page name to an interwiki url.
00624 
00625     Note: We can't know what kind of URL quoting a remote wiki expects.
00626           We just use a utf-8 encoded string with standard URL quoting.
00627 
00628     @param wikiurl: wiki url, maybe including a $PAGE placeholder
00629     @param wikitail: page name
00630     @rtype: string
00631     @return: generated URL of the page in the other wiki
00632     """
00633     wikitail = url_quote(wikitail)
00634     if '$PAGE' in wikiurl:
00635         return wikiurl.replace('$PAGE', wikitail)
00636     else:
00637         return wikiurl + wikitail
00638 

Here is the call graph for this function:

def MoinMoin.script.migration.wikiutil160a.link_tag (   request,
  params,
  text = None,
  formatter = None,
  on = None,
  kw 
)
Create a link.

TODO: cleanup css_class

@param request: the request object
@param params: parameter string appended to the URL after the scriptname/
@param text: text / inner part of the <a>...</a> link - does NOT get
             escaped, so you can give HTML here and it will be used verbatim
@param formatter: the formatter object to use
@param on: opening/closing tag only
@keyword attrs: additional attrs (HTMLified string) (removed in 1.5.3)
@rtype: string
@return: formatted link tag

Definition at line 1498 of file wikiutil160a.py.

01498 
01499 def link_tag(request, params, text=None, formatter=None, on=None, **kw):
01500     """ Create a link.
01501 
01502     TODO: cleanup css_class
01503 
01504     @param request: the request object
01505     @param params: parameter string appended to the URL after the scriptname/
01506     @param text: text / inner part of the <a>...</a> link - does NOT get
01507                  escaped, so you can give HTML here and it will be used verbatim
01508     @param formatter: the formatter object to use
01509     @param on: opening/closing tag only
01510     @keyword attrs: additional attrs (HTMLified string) (removed in 1.5.3)
01511     @rtype: string
01512     @return: formatted link tag
01513     """
01514     if formatter is None:
01515         formatter = request.html_formatter
01516     if kw.has_key('css_class'):
01517         css_class = kw['css_class']
01518         del kw['css_class'] # one time is enough
01519     else:
01520         css_class = None
01521     id = kw.get('id', None)
01522     name = kw.get('name', None)
01523     if text is None:
01524         text = params # default
01525     if formatter:
01526         url = "%s/%s" % (request.script_root, params)
01527         # formatter.url will escape the url part
01528         if on is not None:
01529             tag = formatter.url(on, url, css_class, **kw)
01530         else:
01531             tag = (formatter.url(1, url, css_class, **kw) +
01532                 formatter.rawHTML(text) +
01533                 formatter.url(0))
01534     else: # this shouldn't be used any more:
01535         if on is not None and not on:
01536             tag = '</a>'
01537         else:
01538             attrs = ''
01539             if css_class:
01540                 attrs += ' class="%s"' % css_class
01541             if id:
01542                 attrs += ' id="%s"' % id
01543             if name:
01544                 attrs += ' name="%s"' % name
01545             tag = '<a%s href="%s/%s">' % (attrs, request.script_root, params)
01546             if not on:
01547                 tag = "%s%s</a>" % (tag, text)
01548         request.log("Warning: wikiutil.link_tag called without formatter and without request.html_formatter. tag=%r" % (tag, ))
01549     return tag

load interwiki map (once, and only on demand) 

Definition at line 515 of file wikiutil160a.py.

00515 
00516 def load_wikimap(request):
00517     """ load interwiki map (once, and only on demand) """
00518     from MoinMoin.Page import Page
00519 
00520     now = int(time.time())
00521     if getattr(request.cfg, "shared_intermap_files", None) is None:
00522         generate_file_list(request)
00523 
00524     try:
00525         _interwiki_list = request.cfg.cache.interwiki_list
00526         old_mtime = request.cfg.cache.interwiki_mtime
00527         if request.cfg.cache.interwiki_ts + (1*60) < now: # 1 minutes caching time
00528             max_mtime = get_max_mtime(request.cfg.shared_intermap_files, Page(request, INTERWIKI_PAGE))
00529             if max_mtime > old_mtime:
00530                 raise AttributeError # refresh cache
00531             else:
00532                 request.cfg.cache.interwiki_ts = now
00533     except AttributeError:
00534         _interwiki_list = {}
00535         lines = []
00536 
00537         for filename in request.cfg.shared_intermap_files:
00538             f = open(filename, "r")
00539             lines.extend(f.readlines())
00540             f.close()
00541 
00542         # add the contents of the InterWikiMap page
00543         lines += Page(request, INTERWIKI_PAGE).get_raw_body().splitlines()
00544 
00545         for line in lines:
00546             if not line or line[0] == '#': continue
00547             try:
00548                 line = "%s %s/InterWiki" % (line, request.script_root)
00549                 wikitag, urlprefix, dummy = line.split(None, 2)
00550             except ValueError:
00551                 pass
00552             else:
00553                 _interwiki_list[wikitag] = urlprefix
00554 
00555         del lines
00556 
00557         # add own wiki as "Self" and by its configured name
00558         _interwiki_list['Self'] = request.script_root + '/'
00559         if request.cfg.interwikiname:
00560             _interwiki_list[request.cfg.interwikiname] = request.script_root + '/'
00561 
00562         # save for later
00563         request.cfg.cache.interwiki_list = _interwiki_list
00564         request.cfg.cache.interwiki_ts = now
00565         request.cfg.cache.interwiki_mtime = get_max_mtime(request.cfg.shared_intermap_files, Page(request, INTERWIKI_PAGE))
00566 
00567     return _interwiki_list

Here is the call graph for this function:

Here is the caller graph for this function:

make a text breakable by inserting spaces into nonbreakable parts

Definition at line 242 of file wikiutil160a.py.

00242 
00243 def make_breakable(text, maxlen):
00244     """ make a text breakable by inserting spaces into nonbreakable parts
00245     """
00246     text = text.split(" ")
00247     newtext = []
00248     for part in text:
00249         if len(part) > maxlen:
00250             while part:
00251                 newtext.append(part[:maxlen])
00252                 part = part[maxlen:]
00253         else:
00254             newtext.append(part)
00255     return " ".join(newtext)

def MoinMoin.script.migration.wikiutil160a.makeQueryString (   qstr = None,
  want_unicode = False,
  kw 
)
Make a querystring from arguments.

kw arguments overide values in qstr.

If a string is passed in, it's returned verbatim and
keyword parameters are ignored.

@param qstr: dict to format as query string, using either ascii or unicode
@param kw: same as dict when using keywords, using ascii or unicode
@rtype: string
@return: query string ready to use in a url

Definition at line 160 of file wikiutil160a.py.

00160 
00161 def makeQueryString(qstr=None, want_unicode=False, **kw):
00162     """ Make a querystring from arguments.
00163 
00164     kw arguments overide values in qstr.
00165 
00166     If a string is passed in, it's returned verbatim and
00167     keyword parameters are ignored.
00168 
00169     @param qstr: dict to format as query string, using either ascii or unicode
00170     @param kw: same as dict when using keywords, using ascii or unicode
00171     @rtype: string
00172     @return: query string ready to use in a url
00173     """
00174     if qstr is None:
00175         qstr = {}
00176     if isinstance(qstr, dict):
00177         qstr.update(kw)
00178         items = ['%s=%s' % (url_quote_plus(key, want_unicode=want_unicode), url_quote_plus(value, want_unicode=want_unicode)) for key, value in qstr.items()]
00179         qstr = '&'.join(items)
00180     return qstr
00181 

Here is the call graph for this function:

def MoinMoin.script.migration.wikiutil160a.mapURL (   request,
  url 
)
Map URLs according to 'cfg.url_mappings'.

@param url: a URL
@rtype: string
@return: mapped URL

Definition at line 1439 of file wikiutil160a.py.

01439 
01440 def mapURL(request, url):
01441     """
01442     Map URLs according to 'cfg.url_mappings'.
01443 
01444     @param url: a URL
01445     @rtype: string
01446     @return: mapped URL
01447     """
01448     # check whether we have to map URLs
01449     if request.cfg.url_mappings:
01450         # check URL for the configured prefixes
01451         for prefix in request.cfg.url_mappings.keys():
01452             if url.startswith(prefix):
01453                 # substitute prefix with replacement value
01454                 return request.cfg.url_mappings[prefix] + url[len(prefix):]
01455 
01456     # return unchanged url
01457     return url
01458 

def MoinMoin.script.migration.wikiutil160a.pagediff (   request,
  pagename1,
  rev1,
  pagename2,
  rev2,
  kw 
)
Calculate the "diff" between two page contents.

@param pagename1: name of first page
@param rev1: revision of first page
@param pagename2: name of second page
@param rev2: revision of second page
@keyword ignorews: if 1: ignore pure-whitespace changes.
@rtype: list
@return: lines of diff output

Definition at line 1554 of file wikiutil160a.py.

01554 
01555 def pagediff(request, pagename1, rev1, pagename2, rev2, **kw):
01556     """
01557     Calculate the "diff" between two page contents.
01558 
01559     @param pagename1: name of first page
01560     @param rev1: revision of first page
01561     @param pagename2: name of second page
01562     @param rev2: revision of second page
01563     @keyword ignorews: if 1: ignore pure-whitespace changes.
01564     @rtype: list
01565     @return: lines of diff output
01566     """
01567     from MoinMoin.Page import Page
01568     from MoinMoin.util import diff_text
01569     lines1 = Page(request, pagename1, rev=rev1).getlines()
01570     lines2 = Page(request, pagename2, rev=rev2).getlines()
01571 
01572     lines = diff_text.diff(lines1, lines2, **kw)
01573     return lines
01574 

return markup that can be used as link to page <pagename> 

Definition at line 812 of file wikiutil160a.py.

00812 
00813 def pagelinkmarkup(pagename):
00814     """ return markup that can be used as link to page <pagename> """
00815     from MoinMoin.parser.text_moin_wiki import Parser
00816     if re.match(Parser.word_rule + "$", pagename):
00817         return pagename
00818     else:
00819         return u'["%s"]' % pagename # XXX use quoteName(pagename) later

def MoinMoin.script.migration.wikiutil160a.parseAttributes (   request,
  attrstring,
  endtoken = None,
  extension = None 
)

Parameter parsing.

Parse a list of attributes and return a dict plus a possible
error message.
If extension is passed, it has to be a callable that returns
a tuple (found_flag, msg). found_flag is whether it did find and process
something, msg is '' when all was OK or any other string to return an error
message.

@param request: the request object
@param attrstring: string containing the attributes to be parsed
@param endtoken: token terminating parsing
@param extension: extension function -
                  gets called with the current token, the parser and the dict
@rtype: dict, msg
@return: a dict plus a possible error message

Definition at line 1153 of file wikiutil160a.py.

01153 
01154 def parseAttributes(request, attrstring, endtoken=None, extension=None):
01155     """
01156     Parse a list of attributes and return a dict plus a possible
01157     error message.
01158     If extension is passed, it has to be a callable that returns
01159     a tuple (found_flag, msg). found_flag is whether it did find and process
01160     something, msg is '' when all was OK or any other string to return an error
01161     message.
01162 
01163     @param request: the request object
01164     @param attrstring: string containing the attributes to be parsed
01165     @param endtoken: token terminating parsing
01166     @param extension: extension function -
01167                       gets called with the current token, the parser and the dict
01168     @rtype: dict, msg
01169     @return: a dict plus a possible error message
01170     """
01171     import shlex, StringIO
01172 
01173     _ = request.getText
01174 
01175     parser = shlex.shlex(StringIO.StringIO(attrstring))
01176     parser.commenters = ''
01177     msg = None
01178     attrs = {}
01179 
01180     while not msg:
01181         try:
01182             key = parser.get_token()
01183         except ValueError, err:
01184             msg = str(err)
01185             break
01186         if not key: break
01187         if endtoken and key == endtoken: break
01188 
01189         # call extension function with the current token, the parser, and the dict
01190         if extension:
01191             found_flag, msg = extension(key, parser, attrs)
01192             #request.log("%r = extension(%r, parser, %r)" % (msg, key, attrs))
01193             if found_flag:
01194                 continue
01195             elif msg:
01196                 break
01197             #else (we found nothing, but also didn't have an error msg) we just continue below:
01198 
01199         try:
01200             eq = parser.get_token()
01201         except ValueError, err:
01202             msg = str(err)
01203             break
01204         if eq != "=":
01205             msg = _('Expected "=" to follow "%(token)s"') % {'token': key}
01206             break
01207 
01208         try:
01209             val = parser.get_token()
01210         except ValueError, err:
01211             msg = str(err)
01212             break
01213         if not val:
01214             msg = _('Expected a value for key "%(token)s"') % {'token': key}
01215             break
01216 
01217         key = escape(key) # make sure nobody cheats
01218 
01219         # safely escape and quote value
01220         if val[0] in ["'", '"']:
01221             val = escape(val)
01222         else:
01223             val = '"%s"' % escape(val, 1)
01224 
01225         attrs[key.lower()] = val
01226 
01227     return attrs, msg or ''
01228 

Here is the call graph for this function:

def MoinMoin.script.migration.wikiutil160a.parseQueryString (   qstr,
  want_unicode = True 
)
Parse a querystring "key=value&..." into a dict.

Definition at line 142 of file wikiutil160a.py.

00142 
00143 def parseQueryString(qstr, want_unicode=True):
00144     """ Parse a querystring "key=value&..." into a dict.
00145     """
00146     is_unicode = isinstance(qstr, unicode)
00147     if is_unicode:
00148         qstr = qstr.encode(config.charset)
00149     values = {}
00150     for key, value in cgi.parse_qs(qstr).items():
00151         if len(value) < 2:
00152             v = ''.join(value)
00153             if want_unicode:
00154                 try:
00155                     v = unicode(v, config.charset)
00156                 except UnicodeDecodeError:
00157                     v = unicode(v, 'iso-8859-1', 'replace')
00158             values[key] = v
00159     return values

put quotes around a given name 

Definition at line 468 of file wikiutil160a.py.

00468 
00469 def quoteName(name):
00470     """ put quotes around a given name """
00471     for quote_char in QUOTE_CHARS:
00472         if quote_char not in name:
00473             return u"%s%s%s" % (quote_char, name, quote_char)
00474     else:
00475         return name # XXX we need to be able to escape the quote char for worst case

def MoinMoin.script.migration.wikiutil160a.quoteWikinameFS (   wikiname,
  charset = config.charset 
)
Return file system representation of a Unicode WikiName.

Warning: will raise UnicodeError if wikiname can not be encoded using
charset. The default value of config.charset, 'utf-8' can encode any
character.

@param wikiname: Unicode string possibly containing non-ascii characters
@param charset: charset to encode string
@rtype: string
@return: quoted name, safe for any file system

Definition at line 265 of file wikiutil160a.py.

00265 
00266 def quoteWikinameFS(wikiname, charset=config.charset):
00267     """ Return file system representation of a Unicode WikiName.
00268 
00269     Warning: will raise UnicodeError if wikiname can not be encoded using
00270     charset. The default value of config.charset, 'utf-8' can encode any
00271     character.
00272 
00273     @param wikiname: Unicode string possibly containing non-ascii characters
00274     @param charset: charset to encode string
00275     @rtype: string
00276     @return: quoted name, safe for any file system
00277     """
00278     filename = wikiname.encode(charset)
00279 
00280     quoted = []
00281     location = 0
00282     for needle in UNSAFE.finditer(filename):
00283         # append leading safe stuff
00284         quoted.append(filename[location:needle.start()])
00285         location = needle.end()
00286         # Quote and append unsafe stuff
00287         quoted.append('(')
00288         for character in needle.group():
00289             quoted.append('%02x' % ord(character))
00290         quoted.append(')')
00291 
00292     # append rest of string
00293     quoted.append(filename[location:])
00294     return ''.join(quoted)
00295 

def MoinMoin.script.migration.wikiutil160a.quoteWikinameURL (   pagename,
  charset = config.charset 
)
Return a url encoding of filename in plain ascii

Use urllib.quote to quote any character that is not always safe.

@param pagename: the original pagename (unicode)
@param charset: url text encoding, 'utf-8' recommended. Other charset
                might not be able to encode the page name and raise
                UnicodeError. (default config.charset ('utf-8')).
@rtype: string
@return: the quoted filename, all unsafe characters encoded

Definition at line 182 of file wikiutil160a.py.

00182 
00183 def quoteWikinameURL(pagename, charset=config.charset):
00184     """ Return a url encoding of filename in plain ascii
00185 
00186     Use urllib.quote to quote any character that is not always safe.
00187 
00188     @param pagename: the original pagename (unicode)
00189     @param charset: url text encoding, 'utf-8' recommended. Other charset
00190                     might not be able to encode the page name and raise
00191                     UnicodeError. (default config.charset ('utf-8')).
00192     @rtype: string
00193     @return: the quoted filename, all unsafe characters encoded
00194     """
00195     pagename = pagename.encode(charset)
00196     return urllib.quote(pagename)
00197 

Here is the caller graph for this function:

def MoinMoin.script.migration.wikiutil160a.renderText (   request,
  Parser,
  text,
  line_anchors = False 
)
executes raw wiki markup with all page elements

Definition at line 1613 of file wikiutil160a.py.

01613 
01614 def renderText(request, Parser, text, line_anchors=False):
01615     """executes raw wiki markup with all page elements"""
01616     import StringIO
01617     out = StringIO.StringIO()
01618     request.redirect(out)
01619     wikiizer = Parser(text, request)
01620     wikiizer.format(request.formatter, inhibit_p=True)
01621     result = out.getvalue()
01622     request.redirect()
01623     del out
01624     return result
01625 

def MoinMoin.script.migration.wikiutil160a.resolve_wiki (   request,
  wikiurl 
)
Resolve an interwiki link.

@param request: the request object
@param wikiurl: the InterWiki:PageName link
@rtype: tuple
@return: (wikitag, wikiurl, wikitail, err)

Definition at line 605 of file wikiutil160a.py.

00605 
00606 def resolve_wiki(request, wikiurl):
00607     """ Resolve an interwiki link.
00608 
00609     @param request: the request object
00610     @param wikiurl: the InterWiki:PageName link
00611     @rtype: tuple
00612     @return: (wikitag, wikiurl, wikitail, err)
00613     """
00614     _interwiki_list = load_wikimap(request)
00615     wikiname, pagename, linktext = split_wiki(wikiurl)
00616     if _interwiki_list.has_key(wikiname):
00617         return (wikiname, _interwiki_list[wikiname], pagename, False)
00618     else:
00619         return (wikiname, request.script_root, "/InterWiki", True)

Here is the call graph for this function:

def MoinMoin.script.migration.wikiutil160a.searchAndImportPlugin (   cfg,
  type,
  name,
  what = None 
)

Definition at line 1093 of file wikiutil160a.py.

01093 
01094 def searchAndImportPlugin(cfg, type, name, what=None):
01095     type2classname = {"parser": "Parser",
01096                       "formatter": "Formatter",
01097     }
01098     if what is None:
01099         what = type2classname[type]
01100     mt = MimeType(name)
01101     plugin = None
01102     for module_name in mt.module_name():
01103         try:
01104             plugin = importPlugin(cfg, type, module_name, what)
01105             break
01106         except PluginMissingError:
01107             pass
01108     else:
01109         raise PluginMissingError("Plugin not found!")
01110     return plugin
01111 

Here is the call graph for this function:

Here is the caller graph for this function:

Split a wiki url, e.g:

'MoinMoin:FrontPage' -> "MoinMoin", "FrontPage", ""
'FrontPage' -> "Self", "FrontPage", ""
'MoinMoin:"Page with blanks" link title' -> "MoinMoin", "Page with blanks", "link title"

can also be used for:

'attachment:"filename with blanks.txt" other title' -> "attachment", "filename with blanks.txt", "other title"

@param wikiurl: the url to split
@rtype: tuple
@return: (wikiname, pagename, linktext)

Definition at line 568 of file wikiutil160a.py.

00568 
00569 def split_wiki(wikiurl):
00570     """ Split a wiki url, e.g:
00571 
00572     'MoinMoin:FrontPage' -> "MoinMoin", "FrontPage", ""
00573     'FrontPage' -> "Self", "FrontPage", ""
00574     'MoinMoin:"Page with blanks" link title' -> "MoinMoin", "Page with blanks", "link title"
00575 
00576     can also be used for:
00577 
00578     'attachment:"filename with blanks.txt" other title' -> "attachment", "filename with blanks.txt", "other title"
00579 
00580     @param wikiurl: the url to split
00581     @rtype: tuple
00582     @return: (wikiname, pagename, linktext)
00583     """
00584     try:
00585         wikiname, rest = wikiurl.split(":", 1) # e.g. MoinMoin:FrontPage
00586     except ValueError:
00587         try:
00588             wikiname, rest = wikiurl.split("/", 1) # for what is this used?
00589         except ValueError:
00590             wikiname, rest = 'Self', wikiurl
00591     if rest:
00592         first_char = rest[0]
00593         if first_char in QUOTE_CHARS: # quoted pagename
00594             pagename_linktext = rest[1:].split(first_char, 1)
00595         else: # not quoted, split on whitespace
00596             pagename_linktext = rest.split(None, 1)
00597     else:
00598         pagename_linktext = "", ""
00599     if len(pagename_linktext) == 1:
00600         pagename, linktext = pagename_linktext[0], ""
00601     else:
00602         pagename, linktext = pagename_linktext
00603     linktext = linktext.strip()
00604     return wikiname, pagename, linktext

Here is the caller graph for this function:

Make a filename that is supposed to be a plain name secure, i.e.
remove any possible path components that compromise our system.

@param basename: (possibly unsafe) filename
@rtype: string
@return: (safer) filename

Definition at line 1424 of file wikiutil160a.py.

01424 
01425 def taintfilename(basename):
01426     """
01427     Make a filename that is supposed to be a plain name secure, i.e.
01428     remove any possible path components that compromise our system.
01429 
01430     @param basename: (possibly unsafe) filename
01431     @rtype: string
01432     @return: (safer) filename
01433     """
01434     for x in (os.pardir, ':', '/', '\\', '<', '>'):
01435         basename = basename.replace(x, '_')
01436 
01437     return basename
01438 

Convert UNIX timestamp (may be float or int) to our version
    (long) int.
    We don't want to use floats, so we just scale by 1e6 to get
    an integer in usecs.

Definition at line 358 of file wikiutil160a.py.

00358 
00359 def timestamp2version(ts):
00360     """ Convert UNIX timestamp (may be float or int) to our version
00361         (long) int.
00362         We don't want to use floats, so we just scale by 1e6 to get
00363         an integer in usecs.
00364     """
00365     return long(ts*1000000L) # has to be long for py 2.2.x

if there are quotes around the name, strip them 

Definition at line 476 of file wikiutil160a.py.

00476 
00477 def unquoteName(name):
00478     """ if there are quotes around the name, strip them """
00479     for quote_char in QUOTE_CHARS:
00480         if quote_char == name[0] == name[-1]:
00481             return name[1:-1]
00482     else:
00483         return name

def MoinMoin.script.migration.wikiutil160a.unquoteWikiname (   filename,
  charsets = [config.charset] 
)
Return Unicode WikiName from quoted file name.

We raise an InvalidFileNameError if we find an invalid name, so the
wiki could alarm the admin or suggest the user to rename a page.
Invalid file names should never happen in normal use, but are rather
cheap to find.

This function should be used only to unquote file names, not page
names we receive from the user. These are handled in request by
urllib.unquote, decodePagename and normalizePagename.

Todo: search clients of unquoteWikiname and check for exceptions.

@param filename: string using charset and possibly quoted parts
@param charsets: list of charsets used by string
@rtype: Unicode String
@return: WikiName

Definition at line 296 of file wikiutil160a.py.

00296 
00297 def unquoteWikiname(filename, charsets=[config.charset]):
00298     """ Return Unicode WikiName from quoted file name.
00299 
00300     We raise an InvalidFileNameError if we find an invalid name, so the
00301     wiki could alarm the admin or suggest the user to rename a page.
00302     Invalid file names should never happen in normal use, but are rather
00303     cheap to find.
00304 
00305     This function should be used only to unquote file names, not page
00306     names we receive from the user. These are handled in request by
00307     urllib.unquote, decodePagename and normalizePagename.
00308 
00309     Todo: search clients of unquoteWikiname and check for exceptions.
00310 
00311     @param filename: string using charset and possibly quoted parts
00312     @param charsets: list of charsets used by string
00313     @rtype: Unicode String
00314     @return: WikiName
00315     """
00316     ### Temporary fix start ###
00317     # From some places we get called with Unicode strings
00318     if isinstance(filename, type(u'')):
00319         filename = filename.encode(config.charset)
00320     ### Temporary fix end ###
00321 
00322     parts = []
00323     start = 0
00324     for needle in QUOTED.finditer(filename):
00325         # append leading unquoted stuff
00326         parts.append(filename[start:needle.start()])
00327         start = needle.end()
00328         # Append quoted stuff
00329         group = needle.group(1)
00330         # Filter invalid filenames
00331         if (len(group) % 2 != 0):
00332             raise InvalidFileNameError(filename)
00333         try:
00334             for i in range(0, len(group), 2):
00335                 byte = group[i:i+2]
00336                 character = chr(int(byte, 16))
00337                 parts.append(character)
00338         except ValueError:
00339             # byte not in hex, e.g 'xy'
00340             raise InvalidFileNameError(filename)
00341 
00342     # append rest of string
00343     if start == 0:
00344         wikiname = filename
00345     else:
00346         parts.append(filename[start:len(filename)])
00347         wikiname = ''.join(parts)
00348 
00349     # FIXME: This looks wrong, because at this stage "()" can be both errors
00350     # like open "(" without close ")", or unquoted valid characters in the file name.
00351     # Filter invalid filenames. Any left (xx) must be invalid
00352     #if '(' in wikiname or ')' in wikiname:
00353     #    raise InvalidFileNameError(filename)
00354 
00355     wikiname = decodeUserInput(wikiname, charsets)
00356     return wikiname
00357 
# time scaling

Here is the call graph for this function:

def MoinMoin.script.migration.wikiutil160a.url_quote (   s,
  safe = '/',
  want_unicode = False 
)
Wrapper around urllib.quote doing the encoding/decoding as usually wanted:

@param s: the string to quote (can be str or unicode, if it is unicode,
          config.charset is used to encode it before calling urllib)
@param safe: just passed through to urllib
@param want_unicode: for the less usual case that you want to get back
                     unicode and not str, set this to True
                     Default is False.

Definition at line 85 of file wikiutil160a.py.

00085 
00086 def url_quote(s, safe='/', want_unicode=False):
00087     """
00088     Wrapper around urllib.quote doing the encoding/decoding as usually wanted:
00089 
00090     @param s: the string to quote (can be str or unicode, if it is unicode,
00091               config.charset is used to encode it before calling urllib)
00092     @param safe: just passed through to urllib
00093     @param want_unicode: for the less usual case that you want to get back
00094                          unicode and not str, set this to True
00095                          Default is False.
00096     """
00097     if isinstance(s, unicode):
00098         s = s.encode(config.charset)
00099     elif not isinstance(s, str):
00100         s = str(s)
00101     s = urllib.quote(s, safe)
00102     if want_unicode:
00103         s = s.decode(config.charset) # ascii would also work
00104     return s

Here is the caller graph for this function:

def MoinMoin.script.migration.wikiutil160a.url_quote_plus (   s,
  safe = '/',
  want_unicode = False 
)
Wrapper around urllib.quote_plus doing the encoding/decoding as usually wanted:

@param s: the string to quote (can be str or unicode, if it is unicode,
          config.charset is used to encode it before calling urllib)
@param safe: just passed through to urllib
@param want_unicode: for the less usual case that you want to get back
                     unicode and not str, set this to True
                     Default is False.

Definition at line 105 of file wikiutil160a.py.

00105 
00106 def url_quote_plus(s, safe='/', want_unicode=False):
00107     """
00108     Wrapper around urllib.quote_plus doing the encoding/decoding as usually wanted:
00109 
00110     @param s: the string to quote (can be str or unicode, if it is unicode,
00111               config.charset is used to encode it before calling urllib)
00112     @param safe: just passed through to urllib
00113     @param want_unicode: for the less usual case that you want to get back
00114                          unicode and not str, set this to True
00115                          Default is False.
00116     """
00117     if isinstance(s, unicode):
00118         s = s.encode(config.charset)
00119     elif not isinstance(s, str):
00120         s = str(s)
00121     s = urllib.quote_plus(s, safe)
00122     if want_unicode:
00123         s = s.decode(config.charset) # ascii would also work
00124     return s

Here is the caller graph for this function:

def MoinMoin.script.migration.wikiutil160a.url_unquote (   s,
  want_unicode = True 
)
Wrapper around urllib.unquote doing the encoding/decoding as usually wanted:

@param s: the string to unquote (can be str or unicode, if it is unicode,
          config.charset is used to encode it before calling urllib)
@param want_unicode: for the less usual case that you want to get back
                     str and not unicode, set this to False.
                     Default is True.

Definition at line 125 of file wikiutil160a.py.

00125 
00126 def url_unquote(s, want_unicode=True):
00127     """
00128     Wrapper around urllib.unquote doing the encoding/decoding as usually wanted:
00129 
00130     @param s: the string to unquote (can be str or unicode, if it is unicode,
00131               config.charset is used to encode it before calling urllib)
00132     @param want_unicode: for the less usual case that you want to get back
00133                          str and not unicode, set this to False.
00134                          Default is True.
00135     """
00136     if isinstance(s, unicode):
00137         s = s.encode(config.charset) # ascii would also work
00138     s = urllib.unquote(s)
00139     if want_unicode:
00140         s = s.decode(config.charset)
00141     return s

Convert version number to UNIX timestamp (float).
    This must ONLY be used for display purposes.

Definition at line 366 of file wikiutil160a.py.

00366 
00367 def version2timestamp(v):
00368     """ Convert version number to UNIX timestamp (float).
00369         This must ONLY be used for display purposes.
00370     """
00371     return v / 1000000.0
00372 
00373 
00374 # This is the list of meta attribute names to be treated as integers.
00375 # IMPORTANT: do not use any meta attribute names with "-" (or any other chars
# invalid in python attribute names), use e.g. _ instead.

Here is the caller graph for this function:

Gets a list of modules in data/plugin/'kind'

Require valid plugin directory. e.g missing 'parser' directory or
missing '__init__.py' file will raise errors.

@param kind: what kind of modules we look for
@rtype: list
@return: module names

Definition at line 1060 of file wikiutil160a.py.

01060 
01061 def wikiPlugins(kind, cfg):
01062     """ Gets a list of modules in data/plugin/'kind'
01063 
01064     Require valid plugin directory. e.g missing 'parser' directory or
01065     missing '__init__.py' file will raise errors.
01066 
01067     @param kind: what kind of modules we look for
01068     @rtype: list
01069     @return: module names
01070     """
01071     # Wiki plugins are located in wikiconfig.plugin module
01072     modulename = '%s.plugin.%s' % (cfg.siteid, kind)
01073     return pysupport.importName(modulename, "modules")
01074 

Here is the caller graph for this function:


Variable Documentation

Definition at line 28 of file wikiutil160a.py.

Definition at line 29 of file wikiutil160a.py.

Initial value:
00001 ['current', 'revision', # for page storage (moin 2.0)
00002                  'data_format_revision', # for data_dir format spec (use by mig scripts)
00003                 ]

Definition at line 376 of file wikiutil160a.py.

InterWiki.

Definition at line 487 of file wikiutil160a.py.

Initial value:
00001 {
00002  # OpenOffice 2.x & other open document stuff
00003  '.odt': 'application/vnd.oasis.opendocument.text',
00004  '.ods': 'application/vnd.oasis.opendocument.spreadsheet',
00005  '.odp': 'application/vnd.oasis.opendocument.presentation',
00006  '.odg': 'application/vnd.oasis.opendocument.graphics',
00007  '.odc': 'application/vnd.oasis.opendocument.chart',
00008  '.odf': 'application/vnd.oasis.opendocument.formula',
00009  '.odb': 'application/vnd.oasis.opendocument.database',
00010  '.odi': 'application/vnd.oasis.opendocument.image',
00011  '.odm': 'application/vnd.oasis.opendocument.text-master',
00012  '.ott': 'application/vnd.oasis.opendocument.text-template',
00013  '.ots': 'application/vnd.oasis.opendocument.spreadsheet-template',
00014  '.otp': 'application/vnd.oasis.opendocument.presentation-template',
00015  '.otg': 'application/vnd.oasis.opendocument.graphics-template',
00016 }

Definition at line 825 of file wikiutil160a.py.

Initial value:
00001 {
00002     # this stuff is text, but got application/* for unknown reasons
00003     ('application', 'docbook+xml'): ('text', 'docbook'),
00004     ('application', 'x-latex'): ('text', 'latex'),
00005     ('application', 'x-tex'): ('text', 'tex'),
00006     ('application', 'javascript'): ('text', 'javascript'),
00007 }

Definition at line 843 of file wikiutil160a.py.

Definition at line 851 of file wikiutil160a.py.

Definition at line 26 of file wikiutil160a.py.

Definition at line 27 of file wikiutil160a.py.

Definition at line 466 of file wikiutil160a.py.

tuple MoinMoin.script.migration.wikiutil160a.QUOTED = re.compile(r'\(([a-fA-F0-9]+)\)')

Definition at line 262 of file wikiutil160a.py.

tuple MoinMoin.script.migration.wikiutil160a.UNSAFE = re.compile(r'[^a-zA-Z0-9_]+')

Storage.

Definition at line 261 of file wikiutil160a.py.