Revision: 7851
Author: xqt
Date: 2010-01-04 09:16:51 +0000 (Mon, 04 Jan 2010)
Log Message:
-----------
Skip empty pages if they are not categories (fix for #2905091)
Modified Paths:
--------------
trunk/pywikipedia/interwiki.py
Modified: trunk/pywikipedia/interwiki.py
===================================================================
--- trunk/pywikipedia/interwiki.py 2010-01-02 12:59:20 UTC (rev 7850)
+++ trunk/pywikipedia/interwiki.py 2010-01-04 09:16:51 UTC (rev 7851)
@@ -1233,11 +1233,13 @@
# Register this fact at the todo-counter.
counter.minus(page.site())
+
# Now check whether any interwiki links should be added to the
# todo list.
if not page.exists():
- pywikibot.output(u"NOTE: %s does not exist" % page.aslink(True))
+ if not globalvar.quiet or pywikibot.verbose:
+ pywikibot.output(u"NOTE: %s does not exist. Skipping." % page.aslink(True))
if page == self.originPage:
# The page we are working on is the page that does not exist.
# No use in doing any work on it in that case.
@@ -1254,9 +1256,11 @@
except pywikibot.InvalidTitle:
# MW considers #redirect [[en:#foo]] as a redirect page,
# but we can't do anything useful with such pages
- pywikibot.output(u"NOTE: %s redirects to an invalid title" % page.aslink(True))
+ if not globalvar.quiet or pywikibot.verbose:
+ pywikibot.output(u"NOTE: %s redirects to an invalid title" % page.aslink(True))
continue
- pywikibot.output(u"NOTE: %s is redirect to %s" % (page.aslink(True), redirectTargetPage.aslink(True)))
+ if not globalvar.quiet or pywikibot.verbose:
+ pywikibot.output(u"NOTE: %s is redirect to %s" % (page.aslink(True), redirectTargetPage.aslink(True)))
if page == self.originPage:
if globalvar.initialredirect:
if globalvar.contentsondisk:
@@ -1274,25 +1278,38 @@
counter.minus(site, count)
self.todo = PageTree()
elif not globalvar.followredirect:
- pywikibot.output(u"NOTE: not following redirects.")
+ if not globalvar.quiet or pywikibot.verbose:
+ pywikibot.output(u"NOTE: not following redirects.")
elif page.site().family == redirectTargetPage.site().family \
and not self.skipPage(page, redirectTargetPage, counter):
if self.addIfNew(redirectTargetPage, counter, page):
if config.interwiki_shownew or pywikibot.verbose:
pywikibot.output(u"%s: %s gives new redirect %s" % (self.originPage.aslink(), page.aslink(True), redirectTargetPage.aslink(True)))
-
continue
+
+ # must be behind the page.isRedirectPage() part
+ # otherwise a redirect error would be raised
+ if page.isEmpty() and not page.isCategory():
+ if not globalvar.quiet or pywikibot.verbose:
+ pywikibot.output(u"NOTE: %s is empty. Skipping." % page.aslink(True))
+ if page == self.originPage:
+ for site, count in self.todo.siteCounts():
+ counter.minus(site, count)
+ self.todo = PageTree()
+ self.done = PageTree()
+ continue
elif page.section():
+ if not globalvar.quiet or pywikibot.verbose:
+ pywikibot.output(u"NOTE: %s is a page section. Skipping." % page.aslink(True))
continue
-
# Page exists, isnt a redirect, and is a plain link (no section)
-
try:
iw = page.interwiki()
except pywikibot.NoSuchSite:
- pywikibot.output(u"NOTE: site %s does not exist" % page.site())
+ if not globalvar.quiet or pywikibot.verbose:
+ pywikibot.output(u"NOTE: site %s does not exist" % page.site())
continue
(skip, alternativePage) = self.disambigMismatch(page, counter)
@@ -1347,7 +1364,8 @@
sys.exit()
iw = ()
elif page.isEmpty() and not page.isCategory():
- pywikibot.output(u"NOTE: %s is empty; ignoring it and its interwiki links" % page.aslink(True))
+ if not globalvar.quiet or pywikibot.verbose:
+ pywikibot.output(u"NOTE: %s is empty; ignoring it and its interwiki links" % page.aslink(True))
# Ignore the interwiki links
self.done.remove(page)
iw = ()
Revision: 7850
Author: xqt
Date: 2010-01-02 12:59:20 +0000 (Sat, 02 Jan 2010)
Log Message:
-----------
empty list/dict is not None
Modified Paths:
--------------
trunk/pywikipedia/cosmetic_changes.py
Modified: trunk/pywikipedia/cosmetic_changes.py
===================================================================
--- trunk/pywikipedia/cosmetic_changes.py 2009-12-31 17:56:33 UTC (rev 7849)
+++ trunk/pywikipedia/cosmetic_changes.py 2010-01-02 12:59:20 UTC (rev 7850)
@@ -318,20 +318,20 @@
if self.site.language()=='nn':
regex = re.compile('(<!-- ?interwiki \(no(/nb)?, ?sv, ?da first; then other languages alphabetically by name\) ?-->)')
found = regex.findall(text)
- if found != []:
+ if found:
if pywikibot.verbose:
print found
hasCommentLine = True
text = regex.sub('', text)
# Adding categories
- if categories != None:
+ if categories:
text = pywikibot.replaceCategoryLinks(text, categories, site = self.site)
# Put the nn iw message back
- if self.site.language()=='nn' and not self.talkpage and (interwikiLinks != None or hasCommentLine):
+ if self.site.language()=='nn' and not self.talkpage and (interwikiLinks or hasCommentLine):
text = text + '\r\n\r\n' + nn_iw_msg
# Adding stars templates
- if allstars != []:
+ if allstars:
text = text.strip()+self.site.family.interwiki_text_separator
allstars.sort()
for element in allstars:
@@ -339,7 +339,7 @@
if pywikibot.verbose:
pywikibot.output(u'%s' %element.strip())
# Adding the interwiki
- if interwikiLinks != None:
+ if interwikiLinks:
text = pywikibot.replaceLanguageLinks(text, interwikiLinks, site = self.site, template = self.template, template_subpage = subpage)
return text