jenkins-bot submitted this change.

View Change

Approvals: JJMC89: Looks good to me, approved jenkins-bot: Verified
[cleanup] Use FutureWarning for methods deprecated 2012

- use FutureWarning for fileIsOnCommons in favour of file_is_shared
because this method was deprecated 8 years ago
- rename fileIsShared to file_is_shared
- deprecate the older fileIsShared due to naming convention
- replace all occurrences if fileIsShared
- use FutureWarning for the two randompages shortcuts
which where deprecated 7 years ago

Change-Id: I956b569b6976907049fe829aa6eb599450178d6b
---
M pywikibot/page/__init__.py
M pywikibot/site/__init__.py
M pywikibot/specialbots/_upload.py
M scripts/checkimages.py
M scripts/imagetransfer.py
M scripts/nowcommons.py
M scripts/unusedfiles.py
M tests/file_tests.py
8 files changed, 39 insertions(+), 27 deletions(-)

diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index 9085f15..fe6bf42 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -2612,17 +2612,26 @@
url_param=url_param)
return self.latest_file_info.thumburl

- @deprecated('fileIsShared', since='20121101')
+ @deprecated('file_is_shared', since='20121101', future_warning=True)
def fileIsOnCommons(self):
"""
DEPRECATED. Check if the image is stored on Wikimedia Commons.

@rtype: bool
"""
- return self.fileIsShared()
+ return self.file_is_shared()

+ @deprecated('file_is_shared', since='20200618')
def fileIsShared(self):
"""
+ DEPRECATED. Check if the image is stored on Wikimedia Commons.
+
+ @rtype: bool
+ """
+ return self.file_is_shared()
+
+ def file_is_shared(self):
+ """
Check if the file is stored on any known shared repository.

@rtype: bool
@@ -2631,12 +2640,13 @@
# TODO: put the URLs to family file
if not self.site.has_image_repository:
return False
- elif 'wikitravel_shared' in self.site.shared_image_repository():
+
+ if 'wikitravel_shared' in self.site.shared_image_repository():
return self.latest_file_info.url.startswith(
'https://wikitravel.org/upload/shared/')
- else:
- return self.latest_file_info.url.startswith(
- 'https://upload.wikimedia.org/wikipedia/commons/')
+ # default to commons
+ return self.latest_file_info.url.startswith(
+ 'https://upload.wikimedia.org/wikipedia/commons/')

@deprecated('FilePage.latest_file_info.sha1', since='20141106')
def getFileMd5Sum(self):
diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py
index 5ee61be..d61c5b5 100644
--- a/pywikibot/site/__init__.py
+++ b/pywikibot/site/__init__.py
@@ -5193,7 +5193,8 @@
'ususers': usernames, 'usprop': usprop})
return usgen

- @deprecated('Site.randompages(total=1)', since='20130828')
+ @deprecated('Site.randompages(total=1)', since='20130828',
+ future_warning=True)
def randompage(self, redirect=False):
"""
DEPRECATED.
@@ -5203,7 +5204,8 @@
"""
return self.randompages(total=1, redirects=redirect)

- @deprecated('Site.randompages(total=1, redirects=True)', since='20130828')
+ @deprecated('Site.randompages(total=1, redirects=True)', since='20130828',
+ future_warning=True)
def randomredirectpage(self):
"""
DEPRECATED: Use Site.randompages() instead.
diff --git a/pywikibot/specialbots/_upload.py b/pywikibot/specialbots/_upload.py
index eec04ad..b1da796 100644
--- a/pywikibot/specialbots/_upload.py
+++ b/pywikibot/specialbots/_upload.py
@@ -322,7 +322,7 @@
continue
else:
try:
- if potential_file_page.fileIsShared():
+ if potential_file_page.file_is_shared():
pywikibot.output(
'File with name %s already exists in shared '
'repository and cannot be overwritten.' % filename)
diff --git a/scripts/checkimages.py b/scripts/checkimages.py
index 668add6..f49b6ec 100755
--- a/scripts/checkimages.py
+++ b/scripts/checkimages.py
@@ -785,7 +785,7 @@
return True # continue with the check-part

pywikibot.output(self.imageName + ' is on commons!')
- if self.image.fileIsShared():
+ if self.image.file_is_shared():
pywikibot.output(
"But, the file doesn't exist on your project! Skip...")
# We have to skip the check part for that image because
diff --git a/scripts/imagetransfer.py b/scripts/imagetransfer.py
index ebbac0c..f421889 100755
--- a/scripts/imagetransfer.py
+++ b/scripts/imagetransfer.py
@@ -274,7 +274,7 @@
break
todo = int(todo)
if 0 <= todo < len(imagelist):
- if (imagelist[todo].fileIsShared()
+ if (imagelist[todo].file_is_shared()
and imagelist[todo].site.image_repository()
== self.targetSite.image_repository()):
pywikibot.output(
diff --git a/scripts/nowcommons.py b/scripts/nowcommons.py
index d704ebf..48f4a4a 100755
--- a/scripts/nowcommons.py
+++ b/scripts/nowcommons.py
@@ -268,7 +268,7 @@
self.current_page = page
try:
localImagePage = pywikibot.FilePage(self.site, page.title())
- if localImagePage.fileIsShared():
+ if localImagePage.file_is_shared():
pywikibot.output('File is already on Commons.')
continue
sha1 = localImagePage.latest_file_info.sha1
diff --git a/scripts/unusedfiles.py b/scripts/unusedfiles.py
index 2273d0a..d563a80 100755
--- a/scripts/unusedfiles.py
+++ b/scripts/unusedfiles.py
@@ -12,7 +12,7 @@
If not used, all pages are used.
"""
#
-# (C) Pywikibot team, 2007-2019
+# (C) Pywikibot team, 2007-2020
#
# Distributed under the terms of the MIT license.
#
@@ -64,9 +64,9 @@

def treat(self, image):
"""Process one image page."""
- # Use fileUrl() and fileIsShared() to confirm it is local media
+ # Use fileUrl() and file_is_shared() to confirm it is local media
# rather than a local page with the same name as shared media.
- if (image.fileUrl() and not image.fileIsShared()
+ if (image.fileUrl() and not image.file_is_shared()
and 'http://' not in image.text):
if self.template_image in image.text:
pywikibot.output('{0} done already'
diff --git a/tests/file_tests.py b/tests/file_tests.py
index 1e7b50b..c96cae1 100644
--- a/tests/file_tests.py
+++ b/tests/file_tests.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""FilePage tests."""
#
-# (C) Pywikibot team, 2014-2019
+# (C) Pywikibot team, 2014-2020
#
# Distributed under the terms of the MIT license.
#
@@ -21,7 +21,7 @@

class TestShareFiles(TestCase):

- """Test fileIsShared, exists and fileUrl/get_file_url with shared files."""
+ """Test file_is_shared, exists, fileUrl/get_file_url with shared files."""

sites = {
'enwiki': {
@@ -55,7 +55,7 @@
self.assertEqual(itwp_file.fileUrl(), itwp_file.get_file_url())

def testSharedOnly(self):
- """Test fileIsShared() on file page with shared file only."""
+ """Test file_is_shared() on file page with shared file only."""
title = 'File:Sepp Maier 1.JPG'

commons = self.get_site('commons')
@@ -69,8 +69,8 @@
self.assertFalse(itwp_file.exists())
self.assertTrue(commons_file.exists())

- self.assertTrue(itwp_file.fileIsShared())
- self.assertTrue(commons_file.fileIsShared())
+ self.assertTrue(itwp_file.file_is_shared())
+ self.assertTrue(commons_file.file_is_shared())
self.assertTrue(commons_file.get_file_url())

self.assertIn('/wikipedia/commons/', itwp_file.get_file_url())
@@ -80,7 +80,7 @@
itwp_file.get()

def testLocalOnly(self):
- """Test fileIsShared() on file page with local file only."""
+ """Test file_is_shared() on file page with local file only."""
title = 'File:Untitled (Three Forms), stainless steel sculpture by ' \
'--James Rosati--, 1975-1976, --Honolulu Academy of Arts--.JPG'

@@ -96,14 +96,14 @@
self.assertTrue(enwp_file.exists())
self.assertFalse(commons_file.exists())

- self.assertFalse(enwp_file.fileIsShared())
+ self.assertFalse(enwp_file.file_is_shared())

page_doesnt_exist_exc_regex = re.escape(
"Page [[commons:{}]] doesn't exist.".format(title))
with self.assertRaisesRegex(
pywikibot.NoPage,
page_doesnt_exist_exc_regex):
- commons_file.fileIsShared()
+ commons_file.file_is_shared()

with self.assertRaisesRegex(
pywikibot.NoPage,
@@ -116,7 +116,7 @@
commons_file.get()

def testOnBoth(self):
- """Test fileIsShared() on file page with local and shared file."""
+ """Test file_is_shared() on file page with local and shared file."""
title = 'File:Pulsante spam.png'

commons = self.get_site('commons')
@@ -131,8 +131,8 @@
self.assertTrue(itwp_file.exists())
self.assertTrue(commons_file.exists())

- self.assertFalse(itwp_file.fileIsShared())
- self.assertTrue(commons_file.fileIsShared())
+ self.assertFalse(itwp_file.file_is_shared())
+ self.assertTrue(commons_file.file_is_shared())

def testNonFileLocal(self):
"""Test file page, without local file, existing on the local wiki."""
@@ -144,7 +144,7 @@

self.assertTrue(testwp_file.latest_file_info.url)
self.assertTrue(testwp_file.exists())
- self.assertTrue(testwp_file.fileIsShared())
+ self.assertTrue(testwp_file.file_is_shared())

commons_file = pywikibot.FilePage(commons, title)
self.assertEqual(testwp_file.get_file_url(),

To view, visit change 606313. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I956b569b6976907049fe829aa6eb599450178d6b
Gerrit-Change-Number: 606313
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: JJMC89 <JJMC89.Wikimedia@gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged