Revision: 6330
Author: kim
Date: 2009-02-05 23:08:58 +0000 (Thu, 05 Feb 2009)
Log Message:
-----------
Add an example on how to use pywikipedia as a library.
Added Paths:
-----------
trunk/pywikipedia/logindata.py
trunk/pywikipedia/simple_family.py
Added: trunk/pywikipedia/logindata.py
===================================================================
--- trunk/pywikipedia/logindata.py (rev 0)
+++ trunk/pywikipedia/logindata.py 2009-02-05 23:08:58 UTC (rev 6330)
@@ -0,0 +1,100 @@
+# -*- coding: utf-8 -*-
+
+#Usable example module: Use of pywikipedia as a
+# library.
+#
+# Looks up the path to pywikipedia (pywikipedia_path)
+# in a settings.py file. You'll need to provide that,
+# and/or refactor.
+
+# (C) Kim Bruning for Wikiation, sponsored by Kennisnet, 2009
+#
+# Distributed under the terms of the MIT license.
+#
+
+import sys, os
+import settings
+if settings.pywikipedia_path not in sys.path:
+ sys.path.append(settings.pywikipedia_path)
+
+# pywikipedia can only set itself up if everything is
+# done in its own directory. This needs fixing sometime.
+# for now, we live with it.
+cwd=os.getcwd()
+os.chdir(settings.pywikipedia_path)
+import wikipedia, login
+from simple_family import Family
+os.chdir(cwd)
+
+class LoginData:
+ """An example class that uses pywikipedia as a library.
+ usage example:
+
+ from logindata import LoginData, wikipedia
+ target_wiki=LoginData( ... ) # for example, fill in from a settings file, or use code to generate, or ...
+ site=target_wiki.login()
+ page=wikipedia.Page(site,"Main Page")
+ """
+
+
+ def __init__(
+ """
+ paramaters:
+ name: arbitrary name. Pick something easy to remember
+ protocol: http|https
+ server: dns address or ip address
+ scriptpath: path on server itself
+ (ie: protocol:server/scriptpath http://6.wikiation.nl/revisions/REL1.13.2)
+ version: mediawiki version of the target mediawiki instance
+ lang: default language, as configured on target mediawiki instance
+ encoding: should (almost) always be utf-8
+ api_supported: Does this mediawiki instance support the mediawiki api?
+ RversionTab: Magic. See superclass for information.
+ user: Username on wiki
+ password: password for this user
+ """
+
+
+ self,
+ name='MY_NAME_FOR_THIS_SERVER',
+ protocol='http',
+ server='www.my_server.com',
+ scriptpath='/my/script/path/',
+ version='1.13.2',
+ lang='en',
+ encoding='utf-8',
+ user='MY_BOT_USER',
+ password='MY_SECRET_PASSWORD',
+ RversionTab=None,
+ api_supported=False
+ ):
+ self.lang=lang
+ self.user=user
+ self.password=password
+ self.family=base_family.Family(
+ name=name,
+ protocol=protocol,
+ server=server,
+ scriptpath=scriptpath,
+ version=version,
+ lang=lang,
+ encoding=encoding,
+ RversionTab=RversionTab,
+ api_supported=api_supported)
+ self.site=None
+
+ def login(self):
+ """Attempt to log in on the site described
+ by this class. Returns a pywikipedia site object"""
+ self.site=wikipedia.Site(
+ code=self.lang,
+ fam=self.family,
+ user=self.user
+ )
+ loginManager=login.LoginManager(
+ password=self.password,
+ site=self.site,
+ username=self.user
+ )
+ loginManager.login()
+ return self.site
Added: trunk/pywikipedia/simple_family.py
===================================================================
--- trunk/pywikipedia/simple_family.py (rev 0)
+++ trunk/pywikipedia/simple_family.py 2009-02-05 23:08:58 UTC (rev 6330)
@@ -0,0 +1,98 @@
+# -*- coding: utf-8 -*-
+
+# ============================================
+# NOTE FOR USERS: Unlike the Family files in
+# the family # directory, you do not need to
+# edit this file to configure anything.
+# ============================================
+
+# (C) Kim Bruning for Wikiation, sponsored by Kennisnet, 2009
+#
+# Distributed under the terms of the MIT license.
+#
+
+import sys, settings
+if settings.pywikipedia_path not in sys.path:
+ sys.path.append(settings.pywikipedia_path)
+
+import config, family, urllib
+class Family(family.Family):
+ """Friendlier version of the pywikipedia family class.
+ We can use this in conjunction with none-pywikipedia
+ config files.
+
+ Note that this just handles most common cases.
+ If you run into a special case, you'll have to fall back
+ to your regular pywikipedia.
+ """
+
+ def __init__(self,
+ """name: arbitrary name. Pick something easy to remember
+ protocol: http|https
+ server: dns address or ip address
+ scriptpath: path on server itself
+ (ie: protocol:server/scriptpath http://6.wikiation.nl/revisions/REL1.13.2)
+ version: mediawiki version of the target mediawiki instance
+ lang: default language, as configured on target mediawiki instance
+ encoding: should (almost) always be utf-8
+ api_supported: Does this mediawiki instance support the mediawiki api?
+ RversionTab: Magic. See superclass for information.
+ """
+ name='MY_NAME_FOR_THIS_SERVER',
+ protocol='http',
+ server='www.my_server.com',
+ scriptpath='/my/script/path',
+ version='1.13.2',
+ lang='en',
+ encoding='utf-8',
+ api_supported=False,
+ RversionTab=None # very rare beast, you probably won't need it.
+ ):
+
+ family.Family.__init__(self)
+ self.name = name # REQUIRED; replace with actual name
+
+ self.langs = { # REQUIRED
+ lang: server, # Include one line for each wiki in family
+ }
+ self._protocol=protocol
+ self._scriptpath=scriptpath
+ self._version=version
+ self._encoding=encoding
+ # may as well add these here, so we can have a 1 stop shop
+ self._lang=lang
+ self._server=server
+ self._api_supported=api_supported
+ self._RversionTab=RversionTab
+
+ def protocol(self, code):
+ """
+ returns "http" or "https"
+ """
+ return self._protocol
+
+ def scriptpath(self, code):
+ """returns the prefix used to locate scripts on this wiki.
+ """
+ return self._scriptpath
+
+ def apipath(self, code):
+ """returns whether or not this wiki
+ if self._api_supported:
+ return '%s/api.php' % self.scriptpath(code)
+ else:
+ raise NotImplementedError, "%s wiki family does not support api.php" % self.name
+
+ # Which version of MediaWiki is used?
+ def version(self, code):
+ # Replace with the actual version being run on your wiki
+ return self._version
+
+ def code2encoding(self, code):
+ """Return the encoding for a specific language wiki"""
+ # Most wikis nowadays use UTF-8, but change this if yours uses
+ # a different encoding
+ return self._encoding
+
+ def RversionTab(self, code):
+ return self._RversionTab
Revision: 6329
Author: kim
Date: 2009-02-05 22:28:51 +0000 (Thu, 05 Feb 2009)
Log Message:
-----------
(null edit)
Modified login.py slightly, so that it can be used as a module
in programs external to pywikipedia
Modified Paths:
--------------
trunk/pywikipedia/login.py
Modified: trunk/pywikipedia/login.py
===================================================================
--- trunk/pywikipedia/login.py 2009-02-05 22:27:26 UTC (rev 6328)
+++ trunk/pywikipedia/login.py 2009-02-05 22:28:51 UTC (rev 6329)
@@ -1,5 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
+
"""
Script to log the robot in to a wiki account.
Revision: 6328
Author: kim
Date: 2009-02-05 22:27:26 +0000 (Thu, 05 Feb 2009)
Log Message:
-----------
Provide a marginally more useful Exception message.
(Message was very misleading. This took me ages to figure out)
Modified Paths:
--------------
trunk/pywikipedia/login.py
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/login.py
===================================================================
--- trunk/pywikipedia/login.py 2009-02-05 22:22:41 UTC (rev 6327)
+++ trunk/pywikipedia/login.py 2009-02-05 22:27:26 UTC (rev 6328)
@@ -64,18 +64,25 @@
class LoginManager:
- def __init__(self, password = None, sysop = False, site = None):
+ def __init__(self, password = None, sysop = False, site = None, username=None):
self.site = site or wikipedia.getSite()
- if sysop:
- try:
- self.username = config.sysopnames[self.site.family.name][self.site.lang]
- except:
- raise wikipedia.NoUsername(u'ERROR: Sysop username for %s:%s is undefined.\nIf you have a sysop account for that site, please add such a line to user-config.py:\n\nsysopnames[\'%s\'][\'%s\'] = \'myUsername\'' % (self.site.family.name, self.site.lang, self.site.family.name, self.site.lang))
- else:
- try:
- self.username = config.usernames[self.site.family.name][self.site.lang]
- except:
- raise wikipedia.NoUsername(u'ERROR: Username for %s:%s is undefined.\nIf you have an account for that site, please add such a line to user-config.py:\n\nusernames[\'%s\'][\'%s\'] = \'myUsername\'' % (self.site.family.name, self.site.lang, self.site.family.name, self.site.lang))
+ if username:
+ self.username=username
+ # perform writeback.
+ if site.family.name not in config.usernames:
+ config.usernames[site.family.name]={}
+ config.usernames[site.family.name][self.site.lang]=username
+ else:
+ if sysop:
+ try:
+ self.username = config.sysopnames[self.site.family.name][self.site.lang]
+ except:
+ raise wikipedia.NoUsername(u'ERROR: Sysop username for %s:%s is undefined.\nIf you have a sysop account for that site, please add such a line to user-config.py:\n\nsysopnames[\'%s\'][\'%s\'] = \'myUsername\'' % (self.site.family.name, self.site.lang, self.site.family.name, self.site.lang))
+ else:
+ try:
+ self.username = config.usernames[self.site.family.name][self.site.lang]
+ except:
+ raise wikipedia.NoUsername(u'ERROR: Username for %s:%s is undefined.\nIf you have an account for that site, please add such a line to user-config.py:\n\nusernames[\'%s\'][\'%s\'] = \'myUsername\'' % (self.site.family.name, self.site.lang, self.site.family.name, self.site.lang))
self.password = password
if getattr(config, 'password_file', ''):
self.readPassword()
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2009-02-05 22:22:41 UTC (rev 6327)
+++ trunk/pywikipedia/wikipedia.py 2009-02-05 22:27:26 UTC (rev 6328)
@@ -809,7 +809,7 @@
RversionTab = re.compile(r'<li id="ca-history"><a href=".*?title=.*?&action=history".*?>.*?</a></li>', re.DOTALL)
matchVersionTab = RversionTab.search(text)
if not matchVersionTab:
- raise NoPage(self.site(), self.aslink(forceInterwiki = True))
+ raise NoPage(self.site(), self.aslink(forceInterwiki = True),"Page does not exist. In rare cases, if you are certain the page does exist, look into overriding family.RversionTab" )
# Look if the page is on our watchlist
matchWatching = Rwatchlist.search(text)
if matchWatching:
Revision: 6325
Author: russblau
Date: 2009-02-05 13:59:48 +0000 (Thu, 05 Feb 2009)
Log Message:
-----------
port category redirect methods from trunk
Modified Paths:
--------------
branches/rewrite/pywikibot/page.py
Modified: branches/rewrite/pywikibot/page.py
===================================================================
--- branches/rewrite/pywikibot/page.py 2009-02-04 17:20:55 UTC (rev 6324)
+++ branches/rewrite/pywikibot/page.py 2009-02-05 13:59:48 UTC (rev 6325)
@@ -408,6 +408,29 @@
"""Return True if this is a redirect, False if not or not existing."""
return self.site().page_isredirect(self)
+ def isCategoryRedirect(self):
+ """Return True if this is a category redirect page, False otherwise."""
+
+ if not self.isCategory():
+ return False
+ if not hasattr(self, "_catredirect"):
+ catredirs = self.site().category_redirects()
+ for (template, args) in self.templatesWithParams():
+ if template.title(withNamespace=False) in catredirs:
+ # Get target (first template argument)
+ self._catredirect = self.site().namespace(14) \
+ + ":" + args[0]
+ break
+ else:
+ self._catredirect = False
+ return bool(self._catredirect)
+
+ def getCategoryRedirectTarget(self):
+ """If this is a category redirect, return the target category title."""
+ if self.isCategoryRedirect():
+ return Category(self.site(), self._catredirect)
+ raise pywikibot.ErrorIsNotRedirectPage
+
def isEmpty(self):
"""Return True if the page text has less than 4 characters.
@@ -793,7 +816,8 @@
for name in named:
positional.append("%s=%s" % (name, named[name]))
result.append((pywikibot.Page(
- pywikibot.Link(template[0], self.site())),
+ pywikibot.Link(template[0], self.site(),
+ defaultNamespace=10)),
positional))
return result
@@ -1305,7 +1329,7 @@
"""All parameters are the same as for Page() constructor.
"""
- Page.__init__(self, source, title, 14)
+ Page.__init__(self, source, title, ns=14)
if self.namespace() != 14:
raise ValueError(u"'%s' is not in the category namespace!"
% title)
Bugs item #2567357, was opened at 2009-02-05 08:21
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=2567357&group_…
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: outdated family files on dv and sa-wiki
Initial Comment:
Some namespace family files on dv- and sa-wiki has to be updated.
[w:De:user:Xqt]
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=2567357&group_…
Bugs item #2564757, was opened at 2009-02-04 17:47
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=2564757&group_…
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: redirect.py edits twice
Initial Comment:
If redirect-bot detects a self loop in method fix_double_redirects, it edits twice if sd_template and sd_tagging_sum is defined for the processed language. One for putting the template and one fixing the redirect which is wrong. Of cause it removes the linefeed behind the template the second edit will be done. This diff-link gives an example for that: [http://en.wikipedia.org/w/index.php?title=Talk:Vitamin_K_reactions&diff=pre…]
A quick and dirty fix would be changing the line
else:
break # TODO Better implement loop redirect
to
break # TODO Better implement loop redirect
(delete else: and reduce 1 indention)
but there are no tests or exception handling. I think this is meant by "# TODO Better implement loop redirect"
[w:de:User:Xqt]
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=2564757&group_…