jenkins-bot has submitted this change and it was merged.
Change subject: code improvements found by compat2core scripts/add_text.py
......................................................................
code improvements found by compat2core scripts/add_text.py
- replace site.lang by site.code because family method is code based
- use page.title() method instead of deprecated one
Change-Id: I9ba6e8f461532efc1b41a013f6fd56308b30a45a
---
M scripts/add_text.py
1 file changed, 2 insertions(+), 2 deletions(-)
Approvals:
Ladsgroup: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/add_text.py b/scripts/add_text.py
index 90c0e22..11e63c8 100644
--- a/scripts/add_text.py
+++ b/scripts/add_text.py
@@ -136,7 +136,7 @@
errorCount = 0
site = pywikibot.Site()
- pathWiki = site.family.nicepath(site.lang)
+ pathWiki = site.family.nicepath(site.code)
if putText:
pywikibot.output(u'Loading %s...' % page.title())
@@ -159,7 +159,7 @@
# Understand if the bot has to skip the page or not
# In this way you can use both -except and -excepturl
if regexSkipUrl is not None:
- url = '%s%s' % (pathWiki, page.urlname())
+ url = '%s%s' % (pathWiki, page.title(asUrl=True))
result = re.findall(regexSkipUrl, site.getUrl(url))
if result != []:
pywikibot.output(
--
To view, visit https://gerrit.wikimedia.org/r/135274
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9ba6e8f461532efc1b41a013f6fd56308b30a45a
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
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: L10N update for de-wiki
......................................................................
L10N update for de-wiki
Change-Id: If1c7150df6b90977f2e7b35d418b8eeba1accb53
---
M scripts/clean_sandbox.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/clean_sandbox.py b/scripts/clean_sandbox.py
index 936b86d..cc763ab 100755
--- a/scripts/clean_sandbox.py
+++ b/scripts/clean_sandbox.py
@@ -64,7 +64,7 @@
'bar': u'{{Bitte erst NACH dieser Zeile schreiben! (Begrüßungskasten)}}\r\n',
'cs': u'{{subst:/uhrabat}}',
'da': u'{{subst:Sandkasse tekst}}',
- 'de': u'{{Bitte erst NACH dieser Zeile schreiben! (Begrüßungskasten)}}\r\n',
+ 'de': u'{{subst:Wikipedia:Spielwiese/Vorlage}}',
'en': u'{{Sandbox heading}}\n<!-- Hello! Feel free to try your formatting and editing skills below this line. As this page is for editing experiments, this page will automatically be cleaned every 12 hours. -->',
'fa': u'{{subst:User:Amirobot/sandbox}}',
'fi': u'{{subst:Hiekka}}',
--
To view, visit https://gerrit.wikimedia.org/r/135180
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If1c7150df6b90977f2e7b35d418b8eeba1accb53
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
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 <>
jenkins-bot has submitted this change and it was merged.
Change subject: Ported unlink.py for Core branch, not using mwparserfromhell anymore Change-Id: Ic533bc9b9e1921b8ff0bcd07235492160b08a6b2
......................................................................
Ported unlink.py for Core branch,
not using mwparserfromhell anymore
Change-Id: Ic533bc9b9e1921b8ff0bcd07235492160b08a6b2
---
A scripts/unlink.py
1 file changed, 201 insertions(+), 0 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/unlink.py b/scripts/unlink.py
new file mode 100755
index 0000000..43f6723
--- /dev/null
+++ b/scripts/unlink.py
@@ -0,0 +1,201 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+"""
+This bot unlinks a page on every page that links to it.
+
+This script understands this command-line argument:
+
+ -namespace:n - Number of namespace to process. The parameter can be used
+ multiple times. It works in combination with all other
+ parameters, except for the -start parameter. If you e.g.
+ want to iterate over all user pages starting at User:M, use
+ -start:User:M.
+
+All other parameters will be regarded as part of the title of the page that
+should be unlinked.
+
+Example:
+
+python unlink.py Foo bar -namespace:0 -namespace:6
+
+ Removes links to the page [[Foo bar]] in articles and image descriptions.
+"""
+#
+# (C) Pywikibot team, 2007-2014
+#
+# Distributed under the terms of the MIT license.
+#
+__version__ = '$Id$'
+#
+
+import re
+import pywikibot
+from pywikibot import pagegenerators
+from pywikibot.editor import TextEditor
+from pywikibot import i18n
+from pywikibot import config
+
+
+class UnlinkBot:
+
+ def __init__(self, pageToUnlink, namespaces, always):
+ self.pageToUnlink = pageToUnlink
+ gen = pagegenerators.ReferringPageGenerator(pageToUnlink)
+ if namespaces != []:
+ gen = pagegenerators.NamespaceFilterPageGenerator(gen, namespaces)
+ self.generator = pagegenerators.PreloadingGenerator(gen)
+ linktrail = pywikibot.getSite().linktrail()
+ # The regular expression which finds links. Results consist of four
+ # groups:
+ #
+ # group title is the target page title, that is, everything
+ # before | or ].
+ #
+ # group section is the page section.
+ # It'll include the # to make life easier for us.
+ #
+ # group label is the alternative link title, that's everything
+ # between | and ].
+ #
+ # group linktrail is the link trail, that's letters after ]] which are
+ # part of the word.
+ # note that the definition of 'letter' varies from language to language.
+ self.linkR = re.compile(r'\[\[(?P<title>[^\]\|#]*)(?P<section>#[^\]\|]*)?(\|(?P<label>[^\]]*))?\]\](?P<linktrail>%s)'
+ % linktrail)
+ self.always = always
+ self.done = False
+ self.comment = i18n.twtranslate(pywikibot.getSite(), 'unlink-unlinking',
+ self.pageToUnlink.title())
+
+ def handleNextLink(self, text, match, context=100):
+ """
+ Returns a tuple (text, jumpToBeginning).
+
+ text is the unicode string after the current link has been processed.
+ jumpToBeginning is a boolean which specifies if the cursor position
+ should be reset to 0. This is required after the user has edited the
+ article.
+ """
+ # ignore interwiki links and links to sections of the same page as well
+ # as section links
+ if not match.group('title') \
+ or self.pageToUnlink.site.isInterwikiLink(match.group('title')) \
+ or match.group('section'):
+ return text, False
+ linkedPage = pywikibot.Page(self.pageToUnlink.site,
+ match.group('title'))
+ # Check whether the link found is to the current page itself.
+ if linkedPage != self.pageToUnlink:
+ # not a self-link
+ return text, False
+ else:
+ # at the beginning of the link, start red color.
+ # at the end of the link, reset the color to default
+ if self.always:
+ choice = 'a'
+ else:
+ pywikibot.output(
+ text[max(0, match.start() - context):match.start()]
+ + '\03{lightred}' + text[match.start():match.end()]
+ + '\03{default}' + text[match.end():match.end() + context])
+ choice = pywikibot.inputChoice(
+ u'\nWhat shall be done with this link?\n',
+ ['unlink', 'skip', 'edit', 'more context',
+ 'unlink all', 'quit'],
+ ['U', 's', 'e', 'm', 'a', 'q'], 'u')
+ pywikibot.output(u'')
+
+ if choice == 's':
+ # skip this link
+ return text, False
+ elif choice == 'e':
+ editor = TextEditor()
+ newText = editor.edit(text, jumpIndex=match.start())
+ # if user didn't press Cancel
+ if newText:
+ return newText, True
+ else:
+ return text, True
+ elif choice == 'm':
+ # show more context by recursive self-call
+ return self.handleNextLink(text, match,
+ context=context + 100)
+ elif choice == 'a':
+ self.always = True
+ elif choice == 'q':
+ self.done = True
+ return text, False
+ new = match.group('label') or match.group('title')
+ new += match.group('linktrail')
+ return text[:match.start()] + new + text[match.end():], False
+
+ def treat(self, page):
+ # Show the title of the page we're working on.
+ # Highlight the title in purple.
+ pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
+ % page.title())
+ try:
+ oldText = page.get()
+ text = oldText
+ curpos = 0
+ while curpos < len(text):
+ match = self.linkR.search(text, pos=curpos)
+ if not match:
+ break
+ # Make sure that next time around we will not find this same
+ # hit.
+ curpos = match.start() + 1
+ text, jumpToBeginning = self.handleNextLink(text, match)
+ if jumpToBeginning:
+ curpos = 0
+ if oldText == text:
+ pywikibot.output(u'No changes necessary.')
+ else:
+ pywikibot.showDiff(oldText, text)
+ page.put(text, self.comment)
+ except pywikibot.NoPage:
+ pywikibot.output(u"Page %s does not exist?!"
+ % page.title(asLink=True))
+ except pywikibot.IsRedirectPage:
+ pywikibot.output(u"Page %s is a redirect; skipping."
+ % page.title(asLink=True))
+ except pywikibot.LockedPage:
+ pywikibot.output(u"Page %s is locked?!" % page.title(asLink=True))
+
+ def run(self):
+ for page in self.generator:
+ if self.done:
+ break
+ self.treat(page)
+
+
+def main():
+ # This temporary array is used to read the page title if one single
+ # page that should be unlinked.
+ pageTitle = []
+ # Which namespaces should be processed?
+ # default to [] which means all namespaces will be processed
+ namespaces = []
+ always = False
+
+ for arg in pywikibot.handleArgs():
+ if arg.startswith('-namespace:'):
+ try:
+ namespaces.append(int(arg[11:]))
+ except ValueError:
+ namespaces.append(arg[11:])
+ elif arg == '-always':
+ always = True
+ else:
+ pageTitle.append(arg)
+
+ if pageTitle:
+ page = pywikibot.Page(pywikibot.getSite(), ' '.join(pageTitle))
+ bot = UnlinkBot(page, namespaces, always)
+ bot.run()
+ else:
+ pywikibot.showHelp('unlink')
+
+if __name__ == "__main__":
+ main()
--
To view, visit https://gerrit.wikimedia.org/r/132910
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic533bc9b9e1921b8ff0bcd07235492160b08a6b2
Gerrit-PatchSet: 5
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Maximilianklein <isalix(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Maximilianklein <isalix(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: update package name and links to documentation on MediaWiki.org
......................................................................
update package name and links to documentation on MediaWiki.org
using HTTPS/Special:MyLanguage for security/i18n purposes;
also fixed some typos
Change-Id: I244b45c6b86853f477b0965bec63391e9a75645a
---
M .gitignore
M README.rst
M generate_user_files.py
M pwb.py
M pywikibot/comms/http.py
M pywikibot/config2.py
M pywikibot/data/wikidataquery.py
M pywikibot/epydoc.cfg
M pywikibot/textlib.py
M pywikibot/version.py
M scripts/checkimages.py
M scripts/template.py
M scripts/version.py
M scripts/welcome.py
M setup.py
15 files changed, 31 insertions(+), 31 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/.gitignore b/.gitignore
index 90d2199..72bcafa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,4 +9,4 @@
logs*
*cache*
.idea
-Pywikipediabot.egg-info/
+pywikibot.egg-info/
diff --git a/README.rst b/README.rst
index e19cdc5..0d2a900 100644
--- a/README.rst
+++ b/README.rst
@@ -2,7 +2,7 @@
===================
The pywikibot framework is a Python library that interfaces with the
-`MediaWiki API <https://www.mediawiki.org/wiki/API>`_. Also included are
+`MediaWiki API <https://www.mediawiki.org/wiki/Special:MyLanguage/API:Main_page>`_. Also included are
various general function scripts that can be adapted for different
tasks.
@@ -17,7 +17,7 @@
python pwb.py script_name
Our `installation
-guide <https://www.mediawiki.org/wiki/Manual:Pywikipediabot/Installation>`_
+guide <https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Pywikibot/Installa…>`_
has more details for advanced usage.
Usage
@@ -37,7 +37,7 @@
------------
Our code is maintained on Wikimedia's `Gerrit installation <https://gerrit.wikimedia.org/>`_,
-`learn <https://www.mediawiki.org/wiki/Developer_access>`_ how to get
+`learn <https://www.mediawiki.org/wiki/Special:MyLanguage/Developer_access>`_ how to get
started.
.. image:: https://secure.travis-ci.org/wikimedia/pywikibot-core.png?branch=master
diff --git a/generate_user_files.py b/generate_user_files.py
index 3f7fba5..c9cefb1 100644
--- a/generate_user_files.py
+++ b/generate_user_files.py
@@ -333,7 +333,7 @@
if os.path.exists(os.path.join(base_dir, "user-config.py")):
break
do_copy = raw_input("Do you want to copy user files from an existing "
- "pywikipedia installation? ").upper().strip()
+ "pywikibot installation? ").upper().strip()
if do_copy and "YES".startswith(do_copy):
oldpath = raw_input("Path to existing wikipedia.py? ")
if not os.path.exists(oldpath):
diff --git a/pwb.py b/pwb.py
index 14178a8..2fba1d3 100644
--- a/pwb.py
+++ b/pwb.py
@@ -84,7 +84,7 @@
"or higher")
else:
if sys.version_info[0] not in (2, 3):
- raise RuntimeError("ERROR: Pywikipediabot only runs under Python 2 "
+ raise RuntimeError("ERROR: Pywikibot only runs under Python 2 "
"or Python 3")
version = tuple(sys.version_info)[:3]
if version < (2, 6, 5):
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index fc2dcea..affc571 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -13,7 +13,7 @@
"""
#
-# (C) Pywikipedia bot team, 2007-2014
+# (C) Pywikibot team, 2007-2014
#
# Distributed under the terms of the MIT license.
#
@@ -55,9 +55,9 @@
SSL_CERT_VERIFY_FAILED = ":14090086:"
# the User-agent: header. The default is
-# '<script>/<revision> Pywikipediabot/2.0', where '<script>' is the currently
-# executing script and version is the SVN revision of Pywikipediabot.
-USER_AGENT_FORMAT = '{script}/r{version[rev]} Pywikipediabot/2.0'
+# '<script>/<revision> Pywikibot/2.0', where '<script>' is the currently
+# executing script and version is the Git revision of Pywikibot.
+USER_AGENT_FORMAT = '{script}/r{version[rev]} Pywikibot/2.0'
useragent = USER_AGENT_FORMAT.format(script=pywikibot.calledModuleName(),
version=pywikibot.version.getversiondict())
numthreads = 1
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index 24966b3..757905f 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -196,7 +196,7 @@
try:
console_encoding = __sys.stdout.encoding
except:
- # When using pywikipedia inside a daemonized twisted application,
+ # When using pywikibot inside a daemonized twisted application,
# we get "StdioOnnaStick instance has no attribute 'encoding'"
console_encoding = None
@@ -738,7 +738,7 @@
print("WARNING: Running on Windows and transliteration_target is not "
"set.")
print("Please see "
- "http://www.mediawiki.org/wiki/Manual:Pywikipediabot/Windows")
+ "https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Pywikibot/Windows")
else:
transliteration_target = None
elif transliteration_target in ('None', 'none'):
diff --git a/pywikibot/data/wikidataquery.py b/pywikibot/data/wikidataquery.py
index 12e5d35..c606a18 100644
--- a/pywikibot/data/wikidataquery.py
+++ b/pywikibot/data/wikidataquery.py
@@ -3,7 +3,7 @@
Objects representing WikidataQuery query syntax and API
"""
#
-# (C) Pywikipedia bot team, 2013
+# (C) Pywikibot team, 2013
#
# Distributed under the terms of the MIT license.
@@ -396,7 +396,7 @@
class WikidataQuery():
"""
- An interface to the WikidatQuery API. Default host is
+ An interface to the WikidataQuery API. Default host is
http://wdq.wmflabs.org, but you can substitute
a different one.
@@ -423,7 +423,7 @@
def getQueryString(self, q, labels=[], props=[]):
"""
Get the query string for a given query or queryset
- @return query string including lables and props
+ @return query string including labels and props
"""
qStr = "q=%s" % quote(str(q))
diff --git a/pywikibot/epydoc.cfg b/pywikibot/epydoc.cfg
index 7ada205..8dbe58f 100644
--- a/pywikibot/epydoc.cfg
+++ b/pywikibot/epydoc.cfg
@@ -26,7 +26,7 @@
# url
# The documented project's URL.
-url: http://pywikipediabot.sourceforge.net
+url: https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Pywikibot
# frames
# Whether or not to include a frames-based table of contents.
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index 410af7b..70839ac 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -1163,7 +1163,7 @@
class TimeStripper(object):
"""
- Find timetstamp in page text and returns it as timezone aware datetime object
+ Find timestamp in page text and returns it as timezone aware datetime object
"""
def __init__(self, site=None):
diff --git a/pywikibot/version.py b/pywikibot/version.py
index d2be01d..6d0d30d 100644
--- a/pywikibot/version.py
+++ b/pywikibot/version.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-""" Module to determine the pywikipedia version (tag, revision and date) """
+""" Module to determine the pywikibot version (tag, revision and date) """
#
# (C) Merlijn 'valhallasw' van Deen, 2007-2014
# (C) xqt, 2010-2014
diff --git a/scripts/checkimages.py b/scripts/checkimages.py
index c26f4e4..64a90d5 100644
--- a/scripts/checkimages.py
+++ b/scripts/checkimages.py
@@ -6,7 +6,7 @@
description.
This script will have to be configured for each language. Please submit
-translations as addition to the pywikipediabot framework.
+translations as addition to the pywikibot framework.
Everything that needs customisation is indicated by comments.
@@ -84,7 +84,7 @@
# (C) Kyle/Orgullomoore, 2006-2007 (newimage.py)
# (C) Siebrand Mazeland, 2007-2010
# (C) Filnik, 2007-2011
-# (C) Pywikipedia team, 2007-2014
+# (C) Pywikibot team, 2007-2014
#
# Distributed under the terms of the MIT license.
#
diff --git a/scripts/template.py b/scripts/template.py
index 2298759..eda65eb 100755
--- a/scripts/template.py
+++ b/scripts/template.py
@@ -69,12 +69,12 @@
python template.py test -subst -namespace:2 -namespace:3
-Note that -namespace: is a global pywikipedia parameter
+Note that -namespace: is a global pywikibot parameter
This next example substitutes the template lived with a supplied edit summary.
It only performs substitutions in main article namespace and doesn't prompt to
-start replacing. Note that -putthrottle: is a global pywikipedia parameter.
+start replacing. Note that -putthrottle: is a global pywikibot parameter.
python template.py -putthrottle:30 -namespace:0 lived -subst -always
-summary:"BOT: Substituting {{lived}}, see [[WP:SUBST]]."
diff --git a/scripts/version.py b/scripts/version.py
index 24c8327..f341332 100755
--- a/scripts/version.py
+++ b/scripts/version.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-""" Script to determine the pywikipedia version (tag, revision and date) """
+""" Script to determine the pywikibot version (tag, revision and date) """
#
# (C) Merlijn 'valhallasw' van Deen, 2007-2008
# (C) xqt, 2010-2014
diff --git a/scripts/welcome.py b/scripts/welcome.py
index 0b91f6e..4ee4bc8 100644
--- a/scripts/welcome.py
+++ b/scripts/welcome.py
@@ -109,9 +109,9 @@
* dio is a badword
* Claudio is a normal name
* The username is "Claudio90 fuck!"
- * The Bot find dio and set "warning"
- * The Bot find Claudio and set "ok"
- * The Bot find fuck at the end and set "warning"
+ * The Bot finds dio and sets "warning"
+ * The Bot finds Claudio and sets "ok"
+ * The Bot finds fuck at the end and sets "warning"
* Result: The username is reported.
4) When a user is reported you have to check him and do:
* If he's ok, put the {{welcome}}
@@ -174,7 +174,7 @@
# (C) Daniel Herding, 2007
# (C) Alex Shih-Han Lin, 2009-2010
# (C) xqt, 2009-2011
-# (C) Pywikipedia bot team, 2008-2010
+# (C) Pywikibot team, 2008-2010
#
# Distributed under the terms of the MIT license.
#
@@ -942,7 +942,7 @@
elif arg == '-quick':
globalvar.quick = True
- # Filename and pywikipedia path
+ # Filename and pywikibot path
# file where is stored the random signature index
filename = pywikibot.config.datafilepath('welcome-%s-%s.data'
% (pywikibot.Site().family.name,
diff --git a/setup.py b/setup.py
index 207fa25..5752e0b 100644
--- a/setup.py
+++ b/setup.py
@@ -24,7 +24,7 @@
if sys.version_info[0] == 2:
if sys.version_info < (2, 6, 5):
- raise RuntimeError("ERROR: Pywikipediabot only runs under Python 2.6.5 or higher")
+ raise RuntimeError("ERROR: Pywikibot only runs under Python 2.6.5 or higher")
elif sys.version_info[1] == 6:
test_deps = ['unittest2']
testcollector = "tests.utils.collector"
@@ -32,7 +32,7 @@
if sys.version_info[0] == 3:
if not os.environ.get('PY3', False):
# use setup.py test --python3ok to run tests
- print("ERROR: Pywikipediabot only runs under Python 2")
+ print("ERROR: Pywikibot only runs under Python 2")
sys.exit(1)
if sys.version_info[1] < 3:
print("ERROR: Python 3.3 or higher is required!")
@@ -56,7 +56,7 @@
setup(
name='pywikibot',
version='2.0b1',
- description='Python Wikipedia Bot Framework',
+ description='Python MediaWiki Bot Framework',
long_description=open('README.rst').read(),
maintainer='The pywikibot team',
maintainer_email='pywikipedia-l(a)lists.wikimedia.org',
--
To view, visit https://gerrit.wikimedia.org/r/135156
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I244b45c6b86853f477b0965bec63391e9a75645a
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisamoa(a)live.it>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)live.it>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: (bugfix) bugfixes, script synchronized with compat
......................................................................
(bugfix) bugfixes, script synchronized with compat
- import re fom python library
- fix for language codes
- use Page.text instead of get()/put()
- bugfix for isRedirectPage exception
- continue outer loop if inner loop was completed i.e. nothing found
- indentation for always hotkey
- simplify inputChoice()
Change-Id: I710cc965a196799c5fe21980b08014416ebc4dd6
---
M scripts/lonelypages.py
1 file changed, 53 insertions(+), 62 deletions(-)
Approvals:
Ladsgroup: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/lonelypages.py b/scripts/lonelypages.py
index 265159f..820aab0 100644
--- a/scripts/lonelypages.py
+++ b/scripts/lonelypages.py
@@ -19,22 +19,15 @@
Furthermore, the following command line parameters are supported:
--enable: - Enable or disable the bot via a Wiki Page.
+-enable: Enable or disable the bot via a Wiki Page.
--disambig: - Set a page where the bot save the name of the disambig
- pages found (default: skip the pages)
+-disambig: Set a page where the bot save the name of the disambig
+ pages found (default: skip the pages)
--limit: - Set how many pages check.
+-limit: Set how many pages check.
--always - Always say yes, won't ask
+-always Always say yes, won't ask
---- FixMes ---
-* Check that all the code hasn't bugs
-
---- Credit and Help ---
-This Script has been developed by Pietrodn and Filnik on botwiki. If you want
-to help us improving our script archive and pywikipediabot's archive or you
-simply need help you can find us here: http://botwiki.sno.cc
--- Examples ---
python lonelypages.py -enable:User:Bot/CheckBot -always
@@ -49,10 +42,11 @@
__version__ = '$Id$'
#
+import re
+
import pywikibot
from pywikibot import i18n
from pywikibot import pagegenerators
-from pywikibot import re
# This is required for the text that is shown when you run this script
# with the parameter -help.
@@ -65,55 +59,54 @@
'ca': u'{{Orfe|date={{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}}}',
'en': u'{{Orphan|date={{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}}}',
'it': u'{{O||mese={{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}}}',
- 'jh': u'{{孤立|{{subst:DATE}}}}',
- 'za': u'{{subst:Orphan/auto}}',
+ 'ja': u'{{孤立|{{subst:DATE}}}}',
+ 'zh': u'{{subst:Orphan/auto}}',
}
+# Use regex to prevent to put the same template twice!
exception_regex = {
'ar': [ur'\{\{(?:قالب:|)(يتيمة)[\|\}]'],
'ca': [r'\{\{(?:template:|)(orfe)[\|\}]'],
- 'en': [r'\{\{(?:template:|)(orphan)[\|\}]', r'\{\{(?:template:|)(wi)[\|\}]'],
+ 'en': [r'\{\{(?:template:|)(orphan)[\|\}]',
+ r'\{\{(?:template:|)(wi)[\|\}]'],
'it': [r'\{\{(?:template:|)(o|a)[\|\}]'],
- 'jh': [ur'\{\{(?:template:|)(孤立)[\|\}]'],
- 'za': [r'\{\{(?:template:|)(orphan)[\|\}]'],
+ 'ja': [ur'\{\{(?:template:|)(孤立)[\|\}]'],
+ 'zh': [r'\{\{(?:template:|)(orphan)[\|\}]'],
}
-#####################################################
-# Here you have to put the config for your Project. #
-#####################################################
def main():
- enablePage = None # Check if someone set an enablePage or not
+ enablePage = None # Check if someone set an enablePage or not
limit = 50000 # Hope that there aren't so many lonely pages in a project
- generator = None # Check if bot should use default generator or not
+ generator = None # Check if bot should use default generator or not
# Load all default generators!
genFactory = pagegenerators.GeneratorFactory()
- nwpages = False # Check variable for newpages
- always = False # Check variable for always
- disambigPage = None # If no disambigPage given, not use it.
+ nwpages = False # Check variable for newpages
+ always = False # Check variable for always
+ disambigPage = None # If no disambigPage given, not use it.
# Arguments!
for arg in pywikibot.handleArgs():
if arg.startswith('-enable'):
if len(arg) == 7:
- enablePage = pywikibot.input(u'Would you like to check if the \
- bot should run or not?')
+ enablePage = pywikibot.input(
+ u'Would you like to check if the bot should run or not?')
else:
enablePage = arg[8:]
if arg.startswith('-disambig'):
if len(arg) == 9:
- disambigPage = pywikibot.input(u'In which page should the bot \
- save the disambig pages?')
+ disambigPage = pywikibot.input(
+ u'In which page should the bot save the disambig pages?')
else:
disambigPage = arg[10:]
elif arg.startswith('-limit'):
if len(arg) == 6:
- limit = int(pywikibot.input(u'How many pages do you want to \
- check?'))
+ limit = int(pywikibot.input(
+ u'How many pages do you want to check?'))
else:
limit = int(arg[7:])
elif arg.startswith('-newpages'):
if len(arg) == 9:
- nwlimit = 50 # Default: 50 pages
+ nwlimit = 50 # Default: 50 pages
else:
nwlimit = int(arg[10:])
generator = pywikibot.Site().newpages(number=nwlimit)
@@ -144,12 +137,13 @@
enable = pywikibot.Page(wikiSite, enablePage)
# Loading the page's data
try:
- getenable = enable.get()
+ getenable = enable.text
except pywikibot.NoPage:
- pywikibot.output(u"%s doesn't esist, I use the page as if it was \
- blank!" % enable.title())
+ pywikibot.output(
+ u"%s doesn't esist, I use the page as if it was blank!"
+ % enable.title())
getenable = ''
- except wikiepedia.IsRedirect:
+ except pywikibot.IsRedirectPage:
pywikibot.output(u"%s is a redirect, skip!" % enable.title())
getenable = ''
# If the enable page is set to disable, turn off the bot
@@ -165,17 +159,17 @@
except pywikibot.NoPage:
pywikibot.output(u"%s doesn't esist, skip!" % disambigpage.title())
disambigtext = ''
- except wikiepedia.IsRedirect:
- pywikibot.output(
- u"%s is a redirect, don't use it!" % disambigpage.title())
+ except pywikibot.IsRedirectPage:
+ pywikibot.output(u"%s is a redirect, don't use it!"
+ % disambigpage.title())
disambigPage = None
# Main Loop
for page in generator:
- if nwpages is True:
+ if nwpages:
# The newpages generator returns a tuple, not a Page object.
page = page[0]
pywikibot.output(u"Checking %s..." % page.title())
- if page.isRedirectPage(): # If redirect, skip!
+ if page.isRedirectPage(): # If redirect, skip!
pywikibot.output(u'%s is a redirect! Skip...' % page.title())
continue
# refs is not a list, it's a generator while resList... is a list, yes.
@@ -209,49 +203,46 @@
# I've used a loop in a loop. If I use continue in the second loop,
# it won't do anything in the first. So let's create a variable to
# avoid this problem.
- Find = False
for regexp in exception:
res = re.findall(regexp, oldtxt.lower())
# Found a template! Let's skip the page!
if res != []:
- pywikibot.output(u'Your regex has found something in %s, \
- skipping...' % page.title())
- Find = True
+ pywikibot.output(
+ u'Your regex has found something in %s, skipping...'
+ % page.title())
break
- # Skip the page..
- if Find:
+ else:
continue
- # Is the page a disambig?
if page.isDisambig() and disambigPage is not None:
- pywikibot.output(
- u'%s is a disambig page, report..' % page.title())
+ pywikibot.output(u'%s is a disambig page, report..'
+ % page.title())
if not page.title().lower() in disambigtext.lower():
disambigtext = u"%s\n*[[%s]]" % (disambigtext, page.title())
disambigpage.put(disambigtext, commentdisambig)
continue
# Is the page a disambig but there's not disambigPage? Skip!
elif page.isDisambig():
- pywikibot.output(
- u'%s is a disambig page, skip...' % page.title())
+ pywikibot.output(u'%s is a disambig page, skip...'
+ % page.title())
continue
else:
# Ok, the page need the template. Let's put it there!
# Adding the template in the text
newtxt = u"%s\n%s" % (template, oldtxt)
- # Showing the title
pywikibot.output(u"\t\t>>> %s <<<" % page.title())
- # Showing the changes
pywikibot.showDiff(oldtxt, newtxt)
- choice = 'y' # Default answer
+ choice = 'y'
if not always:
- choice = pywikibot.inputChoice(u'Orphan page found, add \
- template?', ['Yes', 'No', 'All'], ['y', 'n', 'a'])
- if choice == 'a':
- always = True
- choice = 'y'
+ choice = pywikibot.inputChoice(
+ u'Orphan page found, add template?',
+ ['Yes', 'No', 'All'], 'yna')
+ if choice == 'a':
+ always = True
+ choice = 'y'
if choice == 'y':
+ page.text = newtext
try:
- page.put(newtxt, comment)
+ page.save(comment)
except pywikibot.EditConflict:
pywikibot.output(u'Edit Conflict! Skip...')
continue
--
To view, visit https://gerrit.wikimedia.org/r/134303
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I710cc965a196799c5fe21980b08014416ebc4dd6
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: DrTrigon <dr.trigon(a)surfeu.ch>
Gerrit-Reviewer: Huji <huji.huji(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Siebrand <siebrand(a)kitano.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: (bugfix) compare the default key in the right order
......................................................................
(bugfix) compare the default key in the right order
if default key exist and answer is an empty string, the default
value must be returned. Return the choice if it is in hotkeys.
Otherwise try again.
With this patch the keys may be given as list or tuple or also
as string which simplifies the code. Because '' in 'anystring'
is always True the old order didn't work for hotkeys string.
Change-Id: I2caddf213818de231a3258b3a00cca0f6e51b268
---
M pywikibot/userinterfaces/terminal_interface_base.py
1 file changed, 3 insertions(+), 3 deletions(-)
Approvals:
Ladsgroup: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/userinterfaces/terminal_interface_base.py b/pywikibot/userinterfaces/terminal_interface_base.py
index 927ec13..745aa26 100755
--- a/pywikibot/userinterfaces/terminal_interface_base.py
+++ b/pywikibot/userinterfaces/terminal_interface_base.py
@@ -217,10 +217,10 @@
while True:
prompt = '%s (%s)' % (question, ', '.join(options))
answer = self.input(prompt)
- if answer.lower() in hotkeys or answer.upper() in hotkeys:
- return answer
- elif default and answer == '': # empty string entered
+ if default and answer == '': # empty string entered
return default
+ elif answer.lower() in hotkeys or answer.upper() in hotkeys:
+ return answer
def editText(self, text, jumpIndex=None, highlight=None):
"""Return the text as edited by the user.
--
To view, visit https://gerrit.wikimedia.org/r/134609
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I2caddf213818de231a3258b3a00cca0f6e51b268
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Russell Blau <russblau(a)imapmail.org>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Add summary, page and text options for clean_sandbox
......................................................................
Add summary, page and text options for clean_sandbox
Bug 55073
Change-Id: Iffe5e5c09e9952a8bbc71579f5efeb784bf84133
---
M scripts/clean_sandbox.py
1 file changed, 44 insertions(+), 7 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/clean_sandbox.py b/scripts/clean_sandbox.py
index 78b3272..936b86d 100755
--- a/scripts/clean_sandbox.py
+++ b/scripts/clean_sandbox.py
@@ -26,6 +26,14 @@
Please be also aware that the rules when to clean the
user sandbox differ from those for project sandbox.
+ -page Run the bot on specific page, you can use this when
+ you haven't configured clean_candbox for your wiki.
+
+ -text The text that substitutes in the sandbox, you can use this
+ when you haven't configured clean_candbox for your wiki.
+
+ -summary Summary of the edit made by bot.
+
"""
#
# (C) Leonardo Gregianin, 2006
@@ -135,6 +143,9 @@
'delay': None,
'delay_td': None,
'user': False,
+ 'text': "",
+ 'page': None,
+ 'summary': "",
}
def __init__(self, **kwargs):
@@ -160,8 +171,8 @@
content[self.site.code] = None
pywikibot.output(
u'Not properly set-up to run in user namespace!')
- if sandboxTitle.get(self.site.code) is None or content.get(
- self.site.code) is None:
+ if (not sandboxTitle.get(self.site.code) and not self.getOption('page')) or (not content.get(
+ self.site.code) and not self.getOption('text')):
pywikibot.output(u'This bot is not configured for the given site '
u'(%s), exiting.' % self.site)
sys.exit(0)
@@ -170,8 +181,11 @@
while True:
wait = False
now = time.strftime("%d %b %Y %H:%M:%S (UTC)", time.gmtime())
- localSandboxTitle = pywikibot.translate(self.site, sandboxTitle)
- if type(localSandboxTitle) is list:
+ if self.getOption('page'):
+ localSandboxTitle = self.getOption('page')
+ else:
+ localSandboxTitle = pywikibot.translate(self.site, sandboxTitle)
+ if isinstance(localSandboxTitle, list):
titles = localSandboxTitle
else:
titles = [localSandboxTitle]
@@ -181,9 +195,15 @@
% sandboxPage.title(asLink=True))
try:
text = sandboxPage.get()
- translatedContent = pywikibot.translate(self.site, content)
- translatedMsg = i18n.twtranslate(self.site,
- 'clean_sandbox-cleaned')
+ if not self.getOption('text'):
+ translatedContent = pywikibot.translate(self.site, content)
+ else:
+ translatedContent = self.getOption('text')
+ if self.getOption('summary'):
+ translatedMsg = self.getOption('summary')
+ else:
+ translatedMsg = i18n.twtranslate(
+ self.site, 'clean_sandbox-cleaned')
subst = 'subst:' in translatedContent
pos = text.find(translatedContent.strip())
if text.strip() == translatedContent.strip():
@@ -256,8 +276,25 @@
opts['no_repeat'] = False
elif arg.startswith('-delay:'):
opts['delay'] = int(arg[7:])
+ elif arg.startswith('-page'):
+ if len(arg) == 5:
+ opts['page'] = pywikibot.input(
+ u'Which page do you want to change?')
+ else:
+ opts['page'] = arg[6:]
+ elif arg.startswith('-text'):
+ if len(arg) == 5:
+ opts['text'] = pywikibot.input(
+ u'What text do you want to substitute?')
+ else:
+ opts['text'] = arg[6:]
elif arg == '-user':
opts['user'] = True
+ elif arg.startswith('-summary'):
+ if len(arg) == len('-summary'):
+ opts['summary'] = pywikibot.input(u'Enter the summary:')
+ else:
+ opts['summary'] = arg[9:]
else:
pywikibot.showHelp('clean_sandbox')
return
--
To view, visit https://gerrit.wikimedia.org/r/135159
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iffe5e5c09e9952a8bbc71579f5efeb784bf84133
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: 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 <>