jenkins-bot has submitted this change and it was merged.
Change subject: Added UntaggedPageGenerator
......................................................................
Added UntaggedPageGenerator
Change-Id: Ib7e8a545334d11b73e93a740b39690520ef209f6
---
M pywikibot/pagegenerators.py
1 file changed, 38 insertions(+), 4 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index 1970294..4033f68 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -20,14 +20,16 @@
__version__ = '$Id$'
#
-import re
import codecs
-import itertools
-import pywikibot
-import time
import date
+import itertools
+import re
+import time
+
+import pywikibot
from pywikibot import config
from pywikibot import deprecate_arg, i18n
+from pywikibot.comms import http
# ported from version 1 for backwards-compatibility
@@ -151,6 +153,11 @@
[[Special:RandomRedirect]]. Can also be given as
"-randomredirect:n" where n is the number of pages to be
returned, else 10 pages are returned.
+
+-untagged Work on image pages that don't have any license template on a
+ site given in the format "<language>.<project>.org, e.g.
+ "ja.wikipedia.org" or "commons.wikimedia.org".
+ Using an external Toolserver tool.
-google Work on all pages that are found in a Google search.
You need a Google Web API license key. Note that Google
@@ -480,6 +487,8 @@
self.articlefilter = arg[6:]
elif arg.startswith('-yahoo'):
gen = YahooSearchPageGenerator(arg[7:])
+ elif arg.startswith('-untagged'):
+ gen = UntaggedPageGenerator(arg[10:])
else:
pass
if gen:
@@ -1028,6 +1037,31 @@
for page in site.search(query, step=step, total=total, namespaces=namespaces):
yield page
+
+def UntaggedPageGenerator(untaggedProject, limit=500):
+ """ Function to get the pages returned by this tool:
+ http://toolserver.org/~daniel/WikiSense/UntaggedImages.php
+ """
+ URL = "http://toolserver.org/~daniel/WikiSense/UntaggedImages.php?"
+ REGEXP = r"<td valign='top' title='Name'><a href='http://.*?" \
+ "\.org/w/index\.php\?title=(.*?)'>.*?</a></td>"
+ lang, project = untaggedProject.split('.', 1)
+ if lang == 'commons':
+ wiki = 'wikifam=commons.wikimedia.org'
+ else:
+ wiki = 'wikilang=%s&wikifam=.%s' % (lang, project)
+ link = '%s&%s&max=%d&order=img_timestamp' % (URL, wiki, limit)
+ results = re.findall(REGEXP, http.request(site=None, uri=link))
+ if not results:
+ print link
+ raise pywikibot.Error(
+ 'Nothing found! Try to use the tool by yourself to be sure that it '
+ 'works!')
+ else:
+ for result in results:
+ yield pywikibot.Page(pywikibot.getSite(), result)
+
+
# following classes just ported from version 1 without revision; not tested
--
To view, visit https://gerrit.wikimedia.org/r/95209
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib7e8a545334d11b73e93a740b39690520ef209f6
Gerrit-PatchSet: 5
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Pyfisch <pyfisch(a)googlemail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change and it was merged.
Change subject: Extended comms/http.py so that it can also be used for non wiki site requests
......................................................................
Extended comms/http.py so that it can also be used for non wiki site requests
Original-Change-Id: Ib7e8a545334d11b73e93a740b39690520ef209f6
Change-Id: Ifc9e29ce43cce63eff305b956da40b4e41f273f9
---
M pywikibot/comms/http.py
1 file changed, 14 insertions(+), 7 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index 1dee9ec..a4ad829 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -95,20 +95,27 @@
All parameters not listed below are the same as
L{httplib2.Http.request}, but the uri is relative
+ If the site argument is None the uri has to be absolute and is
+ taken. In this case ssl is ignored. Used for requests to non wiki
+ pages.
+
@param site: The Site to connect to
@param uri: the URI to retrieve (relative to the site's scriptpath)
@param ssl: Use https connection
@return: The received data (a unicode string).
"""
- if ssl:
- proto = "https"
- host = site.ssl_hostname()
- uri = site.ssl_pathprefix() + uri
+ if site:
+ if ssl:
+ proto = "https"
+ host = site.ssl_hostname()
+ uri = site.ssl_pathprefix() + uri
+ else:
+ proto = site.protocol()
+ host = site.hostname()
+ baseuri = urlparse.urljoin("%(proto)s://%(host)s" % locals(), uri)
else:
- proto = site.protocol()
- host = site.hostname()
- baseuri = urlparse.urljoin("%(proto)s://%(host)s" % locals(), uri)
+ baseuri = uri
# set default user-agent string
kwargs.setdefault("headers", {})
--
To view, visit https://gerrit.wikimedia.org/r/97996
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ifc9e29ce43cce63eff305b956da40b4e41f273f9
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Pyfisch <pyfisch(a)googlemail.com>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change and it was merged.
Change subject: Improvements to listpages.py
......................................................................
Improvements to listpages.py
1. Structure of listpages.py now like in other scripts.
2. Removed uneeded except part which caused bad output.
3. Fixed typing error. parameterd -> parameters
Change-Id: Iacc0e929482b4baac12a078bdc9faf813f773444
---
M scripts/listpages.py
1 file changed, 17 insertions(+), 19 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/listpages.py b/scripts/listpages.py
index 2cb668b..96bc235 100644
--- a/scripts/listpages.py
+++ b/scripts/listpages.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
"""
-Print a list of pages, as defined by page generator parameterd
+Print a list of pages, as defined by page generator parameters
These parameters are supported to specify which pages titles to print:
@@ -20,23 +20,21 @@
def main(*args):
- try:
- gen = None
- genFactory = GeneratorFactory()
- for arg in pywikibot.handleArgs(*args):
- genFactory.handleArg(arg)
- gen = genFactory.getCombinedGenerator()
- if gen:
- i = 0
- for page in gen:
- i += 1
- pywikibot.stdout("%4d: %s" % (i, page.title()))
- else:
- pywikibot.showHelp()
- except Exception:
- pywikibot.error("Fatal error", exc_info=True)
- finally:
- pywikibot.stopme()
+ gen = None
+ genFactory = GeneratorFactory()
+ for arg in pywikibot.handleArgs(*args):
+ genFactory.handleArg(arg)
+ gen = genFactory.getCombinedGenerator()
+ if gen:
+ i = 0
+ for page in gen:
+ i += 1
+ pywikibot.stdout("%4d: %s" % (i, page.title()))
+ else:
+ pywikibot.showHelp()
if __name__ == "__main__":
- main()
+ try:
+ main()
+ finally:
+ pywikibot.stopme()
--
To view, visit https://gerrit.wikimedia.org/r/94605
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iacc0e929482b4baac12a078bdc9faf813f773444
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Pyfisch <pyfisch(a)googlemail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Pyfisch <pyfisch(a)googlemail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change and it was merged.
Change subject: Use new octal syntax
......................................................................
Use new octal syntax
Change-Id: I9f6fbfef1c2cb7ea453a25b8a8c36990950f8000
---
M pywikibot/config2.py
1 file changed, 2 insertions(+), 2 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index c758295..25df6d2 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -139,7 +139,7 @@
else:
base_dir = os.path.join(home, "." + NAME)
if not os.path.isdir(base_dir):
- os.makedirs(base_dir, mode=0700)
+ os.makedirs(base_dir, mode=0o700)
if not os.path.isabs(base_dir):
base_dir = os.path.normpath(os.path.join(os.getcwd(), base_dir))
# make sure this path is valid and that it contains user-config file
@@ -671,7 +671,7 @@
_filemode = _filestatus[0]
_fileuid = _filestatus[4]
if __sys.platform == 'win32' or _fileuid in [os.getuid(), 0]:
- if __sys.platform == 'win32' or _filemode & 002 == 0 or True:
+ if __sys.platform == 'win32' or _filemode & 0o02 == 0 or True:
execfile(_filename)
else:
print "WARNING: Skipped '%(fn)s': writeable by others." \
--
To view, visit https://gerrit.wikimedia.org/r/97879
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9f6fbfef1c2cb7ea453a25b8a8c36990950f8000
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Aaron1011 <aa1ronham(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change and it was merged.
Change subject: Porting protect.py from compat to core.
......................................................................
Porting protect.py from compat to core.
Change-Id: I085c1a271e91324e8641f405fccec297f5533703
---
A scripts/protect.py
1 file changed, 288 insertions(+), 0 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/protect.py b/scripts/protect.py
new file mode 100644
index 0000000..681fe6f
--- /dev/null
+++ b/scripts/protect.py
@@ -0,0 +1,288 @@
+# -*- coding: utf-8 -*-
+"""
+This script can be used to protect and unprotect pages en masse.
+Of course, you will need an admin account on the relevant wiki.
+
+Syntax: python protect.py OPTION...
+
+Command line options:
+
+-page: Protect specified page
+-cat: Protect all pages in the given category.
+-nosubcats: Don't protect pages in the subcategories.
+-links: Protect all pages linked from a given page.
+-file: Protect all pages listed in a text file.
+-ref: Protect all pages referring from a given page.
+-images: Protect all images used on a given page.
+-always: Don't prompt to protect pages, just do it.
+-summary: Supply a custom edit summary.
+-unprotect: Actually unprotect pages instead of protecting
+-edit:PROTECTION_LEVEL Set edit protection level to PROTECTION_LEVEL
+-move:PROTECTION_LEVEL Set move protection level to PROTECTION_LEVEL
+
+## Without support ##
+## -create:PROTECTION_LEVEL Set move protection level to PROTECTION_LEVEL ##
+
+Values for PROTECTION_LEVEL are: sysop, autoconfirmed, none.
+If an operation parameter (edit, move or create) is not specified, default
+protection level is 'sysop' (or 'none' if -unprotect).
+
+Examples:
+
+Protect everything in the category "To protect" prompting.
+ python protect.py -cat:"To protect" -always
+
+Unprotect all pages listed in text file "unprotect.txt" without prompting.
+ python protect.py -file:unprotect.txt -unprotect
+"""
+
+#
+# Written by http://it.wikisource.org/wiki/Utente:Qualc1
+# Created by modifying delete.py
+#
+# (C) Pywikipedia bot team, 2008-2012
+#
+# Distributed under the terms of the MIT license.
+#
+__version__ = '$Id$'
+#
+
+import pywikibot
+from pywikibot import catlib
+from pywikibot import pagegenerators
+
+# Summary messages for protecting from a category.
+msg_simple_protect = {
+ 'ar': u'بوت: حماية قائمة من الملفات.',
+ 'en': u'Robot: Protecting a list of files.',
+ 'it': u'Bot: Protezione di una lista di pagine.',
+ 'fa': u'ربات:حفاظت فهرستی از صفحهها',
+ 'nl': u'Bot: lijst met bestanden beveiligd',
+ 'pt': u'Bot: Protegendo uma lista de artigos.',
+ 'zh': u'機器人:保護清單中的所有檔案',
+}
+
+msg_protect_category = {
+ 'ar': u'روبوت - حماية كل الصفحات من التصنيف %s',
+ 'en': u'Robot: Protecting all pages from category %s',
+ 'it': u'Bot: Protezione di tutte le pagine nella categoria %s.',
+ 'fa': u'ربات:حفاظت تمام صفحههای رده %s',
+ 'nl': u'Bot: alle pagina\'s uit categorie %s beveiligd',
+ 'pt': u'Bot: Protegendo todos os artigos da categoria %s',
+ 'zh': u'機器人: 保護目錄 %s 的所有頁面',
+}
+
+msg_protect_links = {
+ 'ar': u'روبوت - حماية كل الصفحات الموصولة من %s',
+ 'en': u'Robot: Protecting all pages linked from %s',
+ 'it': u'Bot: Protezione di tutte le pagine linkate da %s.',
+ 'fa': u'ربات:حفاظت تمام صفحههایی که در %s پیوند شدهاند.',
+ 'nl': u'Bot: alle pagina\'s met verwijzingen vanaf %s beveiligd',
+ 'pt': u'Bot: Protegendo todos os artigos ligados a %s',
+ 'zh': u'機器人: 保護所有從 %s 連結的頁面',
+}
+
+msg_protect_ref = {
+ 'ar': u'روبوت - حماية كل الصفحات الراجعة من %s',
+ 'en': u'Robot: Protecting all pages referring from %s',
+ 'it': u'Bot: Protezione di tutte le pagine con link verso %s.',
+ 'fa': u'ربات:حفاظت تمام صفحههایی که به %s پیوند دادهاند',
+ 'nl': u'Bot: alle pagina\'s met een verwijzing op beveiligd',
+ 'pt': u'Bot: Protegendo todos os artigos afluentes a %s',
+ 'zh': u'機器人: 保護所有連至 %s 的頁面',
+}
+
+msg_protect_images = {
+ 'ar': u'روبوت - حماية كل الصور في الصفحة %s',
+ 'en': u'Robot: Protecting all images on page %s',
+ 'it': u'Bot: Protezione di tutte le immagini presenti in %s.',
+ 'fa': u'ربات:حفاظت تمام تصاویر به کار رفته در %s',
+ 'nl': u'Bot: alle bestanden gebruikt op %s beveiligd',
+ 'pt': u'Bot: Protegendo todas as imagens do artigo %s',
+ 'zh': u'機器人: 保護頁面 %s 中的所有圖條',
+}
+
+
+class ProtectionRobot:
+ """
+ This robot allows protection of pages en masse.
+ """
+
+ def __init__(self, generator, summary, always=False, unprotect=False,
+ edit='sysop', move='sysop', create='sysop'):
+ """
+ Arguments:
+ * generator - A page generator.
+ * always - Protect without prompting?
+ * edit, move, create - protection level for these operations
+ * unprotect - unprotect pages (and ignore edit, move, create params)
+ """
+ self.generator = generator
+ self.summary = summary
+ self.prompt = not always
+ self.unprotect = unprotect
+ self.edit = edit
+ self.move = move
+
+ def run(self):
+ """
+ Starts the robot's action.
+ """
+ #Loop through everything in the page generator and (un)protect it.
+ for page in self.generator:
+ pywikibot.output(u'Processing page %s' % page.title())
+ #print self.edit, self.move#, self.create
+ page.protect(unprotect=self.unprotect, reason=self.summary,
+ prompt=self.prompt, edit=self.edit,
+ move=self.move)
+
+
+# Asks a valid protection level for "operation".
+# Returns the protection level chosen by user.
+def choiceProtectionLevel(operation, default):
+ default = default[0]
+ firstChar = map(lambda level: level[0], protectionLevels)
+ choiceChar = pywikibot.inputChoice('Choice a protection level to %s:'
+ % operation,
+ protectionLevels, firstChar,
+ default=default)
+ for level in protectionLevels:
+ if level.startswith(choiceChar):
+ return level
+
+
+def main():
+ global protectionLevels
+ protectionLevels = ['sysop', 'autoconfirmed', 'none']
+
+ pageName = ''
+ summary = ''
+ always = False
+ doSinglePage = False
+ doCategory = False
+ protectSubcategories = True
+ doRef = False
+ doLinks = False
+ doImages = False
+ fileName = ''
+ gen = None
+ edit = ''
+ move = ''
+ defaultProtection = 'sysop'
+
+ # read command line parameters
+ for arg in pywikibot.handleArgs():
+ if arg == '-always':
+ always = True
+ elif arg.startswith('-file'):
+ if len(arg) == len('-file'):
+ fileName = pywikibot.input(u'Enter name of file to protect pages from:')
+ else:
+ fileName = arg[len('-file:'):]
+ elif arg.startswith('-summary'):
+ if len(arg) == len('-summary'):
+ summary = pywikibot.input(u'Enter a reason for the protection:')
+ else:
+ summary = arg[len('-summary:'):]
+ elif arg.startswith('-cat'):
+ doCategory = True
+ if len(arg) == len('-cat'):
+ pageName = pywikibot.input(u'Enter the category to protect from:')
+ else:
+ pageName = arg[len('-cat:'):]
+ elif arg.startswith('-nosubcats'):
+ protectSubcategories = False
+ elif arg.startswith('-links'):
+ doLinks = True
+ if len(arg) == len('-links'):
+ pageName = pywikibot.input(u'Enter the page to protect from:')
+ else:
+ pageName = arg[len('-links:'):]
+ elif arg.startswith('-ref'):
+ doRef = True
+ if len(arg) == len('-ref'):
+ pageName = pywikibot.input(u'Enter the page to protect from:')
+ else:
+ pageName = arg[len('-ref:'):]
+ elif arg.startswith('-page'):
+ doSinglePage = True
+ if len(arg) == len('-page'):
+ pageName = pywikibot.input(u'Enter the page to protect:')
+ else:
+ pageName = arg[len('-page:'):]
+ elif arg.startswith('-images'):
+ doImages = True
+ if len(arg) == len('-images'):
+ pageName = pywikibot.input(u'Enter the page with the images to protect:')
+ else:
+ pageName = arg[len('-images:'):]
+ elif arg.startswith('-unprotect'):
+ defaultProtection = 'none'
+ elif arg.startswith('-edit'):
+ edit = arg[len('-edit:'):]
+ if edit not in protectionLevels:
+ edit = choiceProtectionLevel('edit', defaultProtection)
+ elif arg.startswith('-move'):
+ move = arg[len('-move:'):]
+ if move not in protectionLevels:
+ move = choiceProtectionLevel('move', defaultProtection)
+ elif arg.startswith('-create'):
+ create = arg[len('-create:'):]
+ if create not in protectionLevels:
+ create = choiceProtectionLevel('create', defaultProtection)
+
+ mysite = pywikibot.getSite()
+
+ if doSinglePage:
+ if not summary:
+ summary = pywikibot.input(u'Enter a reason for the protection:')
+ page = pywikibot.Page(mysite, pageName)
+ gen = iter([page])
+ elif doCategory:
+ if not summary:
+ summary = pywikibot.translate(mysite,
+ msg_protect_category) % pageName
+ ns = mysite.category_namespace()
+ categoryPage = catlib.Category(mysite, ns + ':' + pageName)
+ gen = pagegenerators.CategorizedPageGenerator(categoryPage,
+ recurse=protectSubcategories)
+ elif doLinks:
+ if not summary:
+ summary = pywikibot.translate(mysite,
+ msg_protect_links) % pageName
+ linksPage = pywikibot.Page(mysite, pageName)
+ gen = pagegenerators.LinkedPageGenerator(linksPage)
+ elif doRef:
+ if not summary:
+ summary = pywikibot.translate(mysite, msg_protect_ref) % pageName
+ refPage = pywikibot.Page(mysite, pageName)
+ gen = pagegenerators.ReferringPageGenerator(refPage)
+ elif fileName:
+ if not summary:
+ summary = pywikibot.translate(mysite, msg_simple_protect)
+ gen = pagegenerators.TextfilePageGenerator(fileName)
+ elif doImages:
+ if not summary:
+ summary = pywikibot.translate(mysite, msg_protect_images) % pageName
+ gen = pagegenerators.ImagesPageGenerator(pywikibot.Page(mysite,
+ pageName))
+
+ if gen:
+ pywikibot.setAction(summary)
+ # We are just protecting pages, so we have no need of using a preloading
+ # page generator
+ # to actually get the text of those pages.
+ if not edit:
+ edit = defaultProtection
+ if not move:
+ move = defaultProtection
+ bot = ProtectionRobot(gen, summary, always, edit=edit, move=move)
+ bot.run()
+ else:
+ pywikibot.showHelp(u'protect')
+
+if __name__ == "__main__":
+ try:
+ main()
+ finally:
+ pywikibot.stopme()
--
To view, visit https://gerrit.wikimedia.org/r/97749
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I085c1a271e91324e8641f405fccec297f5533703
Gerrit-PatchSet: 10
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Gerrit Patch Uploader <gerritpatchuploader(a)gmail.com>
Gerrit-Reviewer: Gerrit Patch Uploader <gerritpatchuploader(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Sn1per <geofbot(a)gmail.com>
Gerrit-Reviewer: jenkins-bot