Short description

WikiSync expects wiki authentication, and barfs with ProtocolError (Authorization Required) when the source wiki uses HTTP authentication. Many organisations I know of use HTTP authentication with MoinMoin, so I really needed this feature.

So, in short, this patch tries to implement HTTP authentication in wikisync.py. It works for me.

   1 *** wikisync.py.bak	2009-09-20 19:05:16.000000000 +0300
   2 --- wikisync.py	2009-09-20 21:34:12.000000000 +0300
   3 ***************
   4 *** 174,179 ****
   5 --- 174,182 ----
   6               self.connection = None
   7               return
   8   
   9 +         httpauth = False
  10 +         notallowed = _("Invalid username or password.")
  11 + 
  12           self.connection = self.createConnection()
  13   
  14           try:
  15 ***************
  16 *** 182,192 ****
  17 --- 185,231 ----
  18               raise UnsupportedWikiException(_("The wiki is currently not reachable."))
  19           except xmlrpclib.Fault, err:
  20               raise UnsupportedWikiException("xmlrpclib.Fault: %s" % str(err))
  21 +         except xmlrpclib.ProtocolError, err:
  22 +             if err.errmsg != "Authorization Required":
  23 +                 raise
  24 + 
  25 +             if user and password:
  26 +                 try:
  27 +                     import urlparse
  28 +                     import urllib
  29 + 
  30 +                     def urlQuote(string):
  31 +                         if isinstance(string, unicode):
  32 +                             string = string.encode("utf-8")
  33 +                         return urllib.quote(string, "/:")
  34 + 
  35 +                     scheme, netloc, path, a, b, c = \
  36 +                         urlparse.urlparse(self.wiki_url)
  37 +                     action = "action=xmlrpc2"
  38 + 
  39 +                     user, password = map(urlQuote, [user, password])
  40 +                     netloc = "%s:%s@%s" % (user, password, netloc)
  41 +                     self.xmlrpc_url = urlparse.urlunparse((scheme, netloc, 
  42 +                                                            path, "", 
  43 +                                                            action, ""))
  44 + 
  45 +                     self.connection = self.createConnection()
  46 +                     iw_list = self.connection.interwikiName()
  47 + 
  48 +                     httpauth = True
  49 +                 except:
  50 +                     raise NotAllowedException(notallowed)
  51 +             elif user:
  52 +                 return
  53 +             else:
  54 +                 raise NotAllowedException(notallowed)
  55   
  56           if user and password:
  57               token = self.connection.getAuthToken(user, password)
  58               if token:
  59                   self.token = token
  60 +             elif httpauth:
  61 +                 self.token = None
  62               else:
  63                   raise NotAllowedException(_("Invalid username or password."))
  64           else:

wikisync-http-auth.patch

-- JussiEronen (See GraphingWiki for other additions, some might be useful for Moin)

/!\ "except:" is rather evil. "Are you sure?" :)


CategoryFeatureRequest CategoryFeaturePatched

MoinMoin: FeatureRequests/WikiSyncWithHttpAuth (last edited 2009-09-20 19:50:05 by ThomasWaldmann)