Xqt has submitted this change and it was merged.
Change subject: Page.data_item() function to get a Wikibase item of a page
......................................................................
Page.data_item() function to get a Wikibase item of a page
Change-Id: I10e5b4162b0ee4ec479c312acbdd833640e488aa
---
M pywikibot/page.py
1 file changed, 7 insertions(+), 0 deletions(-)
Approvals:
Xqt: Looks good to me, approved
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 6203459..86be801 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -998,6 +998,13 @@
# iterated upon.
return self.site.pagelanglinks(self, step=step, total=total)
+ def data_item(self):
+ """
+ Convinience function to get the Wikibase item of a page
+ @return: ItemPage
+ """
+ return ItemPage.fromPage(self)
+
def templates(self, content=False):
"""Return a list of Page objects for templates used on this Page.
--
To view, visit https://gerrit.wikimedia.org/r/85181
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I10e5b4162b0ee4ec479c312acbdd833640e488aa
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Xqt has submitted this change and it was merged.
Change subject: update from core (86343, 86344)
......................................................................
update from core (86343, 86344)
Change-Id: I0e419629c2121b51bbb39bfa6663703015280069
---
M cfd.py
1 file changed, 31 insertions(+), 26 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
jenkins-bot: Verified
diff --git a/cfd.py b/cfd.py
index 8c21afb..8da3657 100644
--- a/cfd.py
+++ b/cfd.py
@@ -9,7 +9,7 @@
"""
#
# (C) Ben McIlwain, 2008
-# (C) Pywikipedia bot team, 2009-2010
+# (C) Pywikipedia bot team, 2009-2013
#
# Distributed under the terms of the MIT license.
@@ -28,27 +28,31 @@
# See the en-wiki CFD working page at [[Wikipedia:Categories for discussion/Working]]
# to see how these work in context. To get this bot working on other wikis you will
# need to adjust these regular expressions at the very least.
-nobots = re.compile(r"NO\s*BOTS", re.IGNORECASE);
-example = re.compile(r"\[\[\:Category\:(.)\1\1\1\1\]\]", re.IGNORECASE);
-speedymode = re.compile(r"^===*\s*Speedy Moves\s*===*\s*$", re.IGNORECASE);
-movemode = re.compile(r"^===*\s*Move\/Merge then delete\s*===*\s*$", re.IGNORECASE);
+nobots = re.compile(r"NO\s*BOTS", re.IGNORECASE)
+example = re.compile(r"\[\[\:Category\:(.)\1\1\1\1\]\]", re.IGNORECASE)
+speedymode = re.compile(r"^===*\s*Speedy Moves\s*===*\s*$", re.IGNORECASE)
+movemode = re.compile(r"^===*\s*Move\/Merge then delete\s*===*\s*$", re.IGNORECASE)
emptymode = re.compile(r"^===*\s*Empty then delete\s*===*\s*$", re.IGNORECASE)
deletemode = re.compile(r"^===*\s*Ready for deletion\s*===*\s*$", re.IGNORECASE)
maintenance = re.compile(r"^===*\s*Old by month categories with entries\s*===*\s*$", re.IGNORECASE)
-dateheader = re.compile(r"(\[\[Wikipedia\:Categories[_ ]for[_ ](?:discussion|deletion)\/Log\/([^\]]*?)\]\])", re.IGNORECASE)
+dateheader = re.compile(r"(\[\[Wikipedia\:Categories[_ ]for[_ ](?:discussion|deletion)\/Log\/([^\]]*?)\]\])",
+ re.IGNORECASE)
movecat = re.compile(r"\[\[\:Category\:([^\]]*?)\]\][^\]]*?\[\[\:Category\:([^\]]*?)\]\]", re.IGNORECASE)
deletecat = re.compile(r"\[\[\:Category\:([^\]]*?)\]\]", re.IGNORECASE)
findday = re.compile(r"\[\[(Wikipedia\:Categories for (?:discussion|deletion)\/Log\/\d{4} \w+ \d+)#", re.IGNORECASE)
+
class ReCheck:
def __init__(self):
self.result = None
+
def check(self, pattern, text):
self.result = pattern.search(text)
return self.result
+
def main():
- pywikibot.handleArgs();
+ pywikibot.handleArgs()
page = pywikibot.Page(pywikibot.getSite(), cfdPage)
@@ -63,38 +67,38 @@
m = ReCheck()
for line in page.get().split("\n"):
- if (nobots.search(line)):
+ if nobots.search(line):
# NO BOTS!!!
pass
- elif (example.search(line)):
+ elif example.search(line):
# Example line
pass
- elif (speedymode.search(line)):
+ elif speedymode.search(line):
mode = "Speedy"
day = "None"
- elif (movemode.search(line)):
+ elif movemode.search(line):
mode = "Move"
day = "None"
- elif (emptymode.search(line)):
+ elif emptymode.search(line):
mode = "Empty"
day = "None"
- elif (deletemode.search(line)):
+ elif deletemode.search(line):
mode = "Delete"
day = "None"
- elif (maintenance.search(line)):
+ elif maintenance.search(line):
# It's probably best not to try to handle these in an automated fashion.
mode = "None"
day = "None"
- elif (m.check(dateheader, line)):
+ elif m.check(dateheader, line):
day = m.result.group(1)
pywikibot.output("Found day header: %s" % day)
- elif (m.check(movecat, line)):
+ elif m.check(movecat, line):
src = m.result.group(1)
dest = m.result.group(2)
thisDay = findDay(src, day)
- if (mode == "Move" and thisDay != "None"):
+ if mode == "Move" and thisDay != "None":
summary = "Robot - Moving category " + src + " to [[:Category:" + dest + "]] per [[WP:CFD|CFD]] at " + thisDay + "."
- elif (mode == "Speedy"):
+ elif mode == "Speedy":
summary = "Robot - Speedily moving category " + src + " to [[:Category:" + dest + "]] per [[WP:CFDS|CFDS]]."
else:
continue
@@ -111,13 +115,13 @@
robot = category.CategoryMoveRobot(oldCatTitle=src, newCatTitle=dest, batchMode=True,
editSummary=summary, inPlace=True, moveCatPage=True,
deleteEmptySourceCat=True, useSummaryForDeletion=True)
- elif (m.check(deletecat, line)):
+ elif m.check(deletecat, line):
src = m.result.group(1)
# I currently don't see any reason to handle these two cases separately, though
# if are guaranteed that the category in the "Delete" case is empty, it might be
# easier to call delete.py on it.
thisDay = findDay(src, day)
- if ((mode == "Empty" or mode == "Delete") and thisDay != "None"):
+ if (mode == "Empty" or mode == "Delete") and thisDay != "None":
summary = "Robot - Removing category " + src + " per [[WP:CFD|CFD]] at " + thisDay + "."
else:
continue
@@ -126,12 +130,13 @@
else:
# This line does not fit any of our regular expressions, so ignore it.
pass
- if (summary != "" and robot != None):
+ if summary != "" and robot is not None:
pywikibot.output(summary, toStdout=True)
# Run, robot, run!
robot.run()
summary = ""
robot = None
+
# This function grabs the wiki source of a category page and attempts to
# extract a link to the CFD per-day discussion page from the CFD template.
@@ -146,7 +151,7 @@
except pywikibot.NoPage:
m = None
- if (m != None):
+ if m is not None:
return "[[" + m.group(1) + "]]"
else:
# Try to parse day link from CFD template parameters.
@@ -157,13 +162,13 @@
(day, month, year) = [None, None, None]
for param in params:
(paramName, paramVal) = param.split('=', 1)
- if (paramName == 'day'):
+ if paramName == 'day':
day = paramVal
- elif (paramName == 'month'):
+ elif paramName == 'month':
month = paramVal
- elif (paramName == 'year'):
+ elif paramName == 'year':
year = paramVal
- if (day and month and year):
+ if day and month and year:
return "[[Wikipedia:Categories for discussion/Log/%s %s %s]]" % (year, month, day)
return oldDay
--
To view, visit https://gerrit.wikimedia.org/r/86365
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0e419629c2121b51bbb39bfa6663703015280069
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Xqt has submitted this change and it was merged.
Change subject: Port cfd.py from compat
......................................................................
Port cfd.py from compat
Change-Id: Ie0221f95ccbb2048a03bce74421c25e5a51a294a
---
A scripts/cfd.py
1 file changed, 172 insertions(+), 0 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/cfd.py b/scripts/cfd.py
new file mode 100644
index 0000000..64296a4
--- /dev/null
+++ b/scripts/cfd.py
@@ -0,0 +1,172 @@
+# -*- coding: utf-8 -*-
+"""
+This script processes the Categories for discussion working page. It parses
+out the actions that need to be taken as a result of CFD discussions (as posted
+to the working page by an administrator) and performs them.
+
+Syntax: python cfd.py
+
+"""
+#
+# (C) Ben McIlwain, 2008
+# (C) Pywikipedia bot team, 2009-2013
+#
+# Distributed under the terms of the MIT license.
+
+import pywikibot
+import re
+import category
+
+# The location of the CFD working page.
+cfdPage = 'Wikipedia:Categories for discussion/Working'
+
+# A list of templates that are used on category pages as part of the CFD
+# process that contain information such as the link to the per-day discussion page.
+cfdTemplates = ['Cfd full', 'Cfr full']
+
+# Regular expression declarations
+# See the en-wiki CFD working page at [[Wikipedia:Categories for discussion/Working]]
+# to see how these work in context. To get this bot working on other wikis you will
+# need to adjust these regular expressions at the very least.
+nobots = re.compile(r"NO\s*BOTS", re.IGNORECASE)
+example = re.compile(r"\[\[\:Category\:(.)\1\1\1\1\]\]", re.IGNORECASE)
+speedymode = re.compile(r"^===*\s*Speedy Moves\s*===*\s*$", re.IGNORECASE)
+movemode = re.compile(r"^===*\s*Move\/Merge then delete\s*===*\s*$", re.IGNORECASE)
+emptymode = re.compile(r"^===*\s*Empty then delete\s*===*\s*$", re.IGNORECASE)
+deletemode = re.compile(r"^===*\s*Ready for deletion\s*===*\s*$", re.IGNORECASE)
+maintenance = re.compile(r"^===*\s*Old by month categories with entries\s*===*\s*$", re.IGNORECASE)
+dateheader = re.compile(r"(\[\[Wikipedia\:Categories[_ ]for[_ ](?:discussion|deletion)\/Log\/([^\]]*?)\]\])", re.IGNORECASE)
+movecat = re.compile(r"\[\[\:Category\:([^\]]*?)\]\][^\]]*?\[\[\:Category\:([^\]]*?)\]\]", re.IGNORECASE)
+deletecat = re.compile(r"\[\[\:Category\:([^\]]*?)\]\]", re.IGNORECASE)
+findday = re.compile(r"\[\[(Wikipedia\:Categories for (?:discussion|deletion)\/Log\/\d{4} \w+ \d+)#", re.IGNORECASE)
+
+class ReCheck:
+ def __init__(self):
+ self.result = None
+ def check(self, pattern, text):
+ self.result = pattern.search(text)
+ return self.result
+
+def main():
+ pywikibot.handleArgs()
+
+ page = pywikibot.Page(pywikibot.Site(), cfdPage)
+
+ # Variable declarations
+ day = "None"
+ mode = "None"
+ src = "None"
+ dest = "None"
+ line = ""
+ summary = ""
+ robot = None
+
+ m = ReCheck()
+ for line in page.get().split("\n"):
+ if (nobots.search(line)):
+ # NO BOTS!!!
+ pass
+ elif (example.search(line)):
+ # Example line
+ pass
+ elif (speedymode.search(line)):
+ mode = "Speedy"
+ day = "None"
+ elif (movemode.search(line)):
+ mode = "Move"
+ day = "None"
+ elif (emptymode.search(line)):
+ mode = "Empty"
+ day = "None"
+ elif (deletemode.search(line)):
+ mode = "Delete"
+ day = "None"
+ elif (maintenance.search(line)):
+ # It's probably best not to try to handle these in an automated fashion.
+ mode = "None"
+ day = "None"
+ elif (m.check(dateheader, line)):
+ day = m.result.group(1)
+ pywikibot.output("Found day header: %s" % day)
+ elif (m.check(movecat, line)):
+ src = m.result.group(1)
+ dest = m.result.group(2)
+ thisDay = findDay(src, day)
+ if (mode == "Move" and thisDay != "None"):
+ summary = "Robot - Moving category " + src + " to [[:Category:" + dest + "]] per [[WP:CFD|CFD]] at " + thisDay + "."
+ elif (mode == "Speedy"):
+ summary = "Robot - Speedily moving category " + src + " to [[:Category:" + dest + "]] per [[WP:CFDS|CFDS]]."
+ else:
+ continue
+ # If the category is redirect, we do NOT want to move articles to
+ # it. The safest thing to do here is abort and wait for human
+ # intervention.
+ destpage = pywikibot.Page(
+ pywikibot.Site(), dest, ns=14)
+ if destpage.isCategoryRedirect():
+ summary = 'CANCELED. Destination is redirect: ' + summary
+ pywikibot.output(summary, toStdout=True)
+ robot = None
+ else:
+ robot = category.CategoryMoveRobot(oldCatTitle=src, newCatTitle=dest, batchMode=True,
+ editSummary=summary, inPlace=True, moveCatPage=True,
+ deleteEmptySourceCat=True, useSummaryForDeletion=True)
+ elif (m.check(deletecat, line)):
+ src = m.result.group(1)
+ # I currently don't see any reason to handle these two cases separately, though
+ # if are guaranteed that the category in the "Delete" case is empty, it might be
+ # easier to call delete.py on it.
+ thisDay = findDay(src, day)
+ if ((mode == "Empty" or mode == "Delete") and thisDay != "None"):
+ summary = "Robot - Removing category " + src + " per [[WP:CFD|CFD]] at " + thisDay + "."
+ else:
+ continue
+ robot = category.CategoryRemoveRobot(catTitle=src, batchMode=True, editSummary=summary,
+ useSummaryForDeletion=True, inPlace=True)
+ else:
+ # This line does not fit any of our regular expressions, so ignore it.
+ pass
+ if (summary != "" and robot != None):
+ pywikibot.output(summary, toStdout=True)
+ # Run, robot, run!
+ robot.run()
+ summary = ""
+ robot = None
+
+# This function grabs the wiki source of a category page and attempts to
+# extract a link to the CFD per-day discussion page from the CFD template.
+# If the CFD template is not there, it will return the value of the second
+# parameter, which is essentially a fallback that is extracted from the
+# per-day subheadings on the working page.
+def findDay(pageTitle, oldDay):
+ page = pywikibot.Page(pywikibot.Site(), "Category:" + pageTitle)
+ try:
+ pageSrc = page.get()
+ m = findday.search(pageSrc)
+ except pywikibot.NoPage:
+ m = None
+
+ if (m != None):
+ return "[[" + m.group(1) + "]]"
+ else:
+ # Try to parse day link from CFD template parameters.
+ templates = page.templatesWithParams()
+ for template in templates:
+ if template[0] in cfdTemplates:
+ params = template[1]
+ (day, month, year) = [None, None, None]
+ for param in params:
+ (paramName, paramVal) = param.split('=', 1)
+ if (paramName == 'day'):
+ day = paramVal
+ elif (paramName == 'month'):
+ month = paramVal
+ elif (paramName == 'year'):
+ year = paramVal
+ if (day and month and year):
+ return "[[Wikipedia:Categories for discussion/Log/%s %s %s]]" % (year, month, day)
+ return oldDay
+
+if __name__ == "__main__":
+ main()
+
--
To view, visit https://gerrit.wikimedia.org/r/86343
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie0221f95ccbb2048a03bce74421c25e5a51a294a
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Xqt has submitted this change and it was merged.
Change subject: Use unicode base path; fixes https://sourceforge.net/p/pywikipediabot/bugs/1648/
......................................................................
Use unicode base path; fixes https://sourceforge.net/p/pywikipediabot/bugs/1648/
execfile does not accept unicode paths, so a manual exec open(...).read()
will have to take its job.
Change-Id: I9741c9f97e5a66f0d1af012a82f933f493c64066
---
M config.py
M fixes.py
M wikipediatools.py
3 files changed, 3 insertions(+), 3 deletions(-)
Approvals:
Xqt: Looks good to me, approved
diff --git a/config.py b/config.py
index ef495ca..cc44c66 100644
--- a/config.py
+++ b/config.py
@@ -603,7 +603,7 @@
_fileuid = _filestatus[4]
if __sys.platform == 'win32' or _fileuid in [os.getuid(), 0]:
if __sys.platform == 'win32' or _filemode & 002 == 0:
- execfile(_filename)
+ exec open(_filename, 'r').read()
else:
print "WARNING: Skipped '%s': writeable by others."%_filename
else:
diff --git a/fixes.py b/fixes.py
index 4923410..58cbcfa 100644
--- a/fixes.py
+++ b/fixes.py
@@ -669,6 +669,6 @@
import config
try:
- execfile(config.datafilepath(config.base_dir, "user-fixes.py"))
+ exec open(config.datafilepath(config.base_dir, "user-fixes.py"), 'r').read()
except IOError:
pass
diff --git a/wikipediatools.py b/wikipediatools.py
index 7af8cb7..baefa51 100644
--- a/wikipediatools.py
+++ b/wikipediatools.py
@@ -41,7 +41,7 @@
print sys.modules
base_dir = '.'
if not os.path.isabs(base_dir):
- base_dir = os.path.normpath(os.path.join(os.getcwd(), base_dir))
+ base_dir = os.path.normpath(os.path.join(os.getcwdu(), base_dir))
# make sure this path is valid and that it contains user-config file
if not os.path.isdir(base_dir):
raise RuntimeError("Directory '%s' does not exist." % base_dir)
--
To view, visit https://gerrit.wikimedia.org/r/85029
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9741c9f97e5a66f0d1af012a82f933f493c64066
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot