jenkins-bot has submitted this change and it was merged.

Change subject: Replace getImagePageHtml() with fileIsShared()
......................................................................


Replace getImagePageHtml() with fileIsShared()

ImagePage.getImagePageHtml() was used in the original 2007 checkimages
script to detect if a local page exists for the same name as a file on
the shared repository.  ImagePage now has a cheaper method fileIsShared()
which achieves the same goal.

Likewise getImagePageHtml() was used in the original 2007 unusedfiles
script to detect if the rendered page contained:
   <table id="mw_metadata" class="mw_metadata">
which indicated that it had an image linked to it.  Using fileUrl()
and fileIsShared() achieves the same goal.

Change-Id: I5fd3f34b9081fdbb20b853052fe1c4c30e360d93
---
M scripts/checkimages.py
M scripts/unusedfiles.py
2 files changed, 5 insertions(+), 11 deletions(-)

Approvals:
  Ladsgroup: Looks good to me, but someone else must approve
  Xqt: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/scripts/checkimages.py b/scripts/checkimages.py
index 5c63a33..41b0aac 100644
--- a/scripts/checkimages.py
+++ b/scripts/checkimages.py
@@ -912,9 +912,7 @@
                         return True  # continue with the check-part
 
             pywikibot.output(u'%s is on commons!' % self.imageName)
-            on_commons_text = self.image.getImagePageHtml()
-            if re.search(r"\<div class\=(?:'|\")sharedUploadNotice(?:'|\")\>",
-                         on_commons_text):
+            if self.image.fileIsShared():
                 pywikibot.output(
                     u"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/unusedfiles.py b/scripts/unusedfiles.py
index a4c7fd9..7307368 100644
--- a/scripts/unusedfiles.py
+++ b/scripts/unusedfiles.py
@@ -42,10 +42,6 @@
     'fa': u'\n\n{{جا:اخطار به کاربر برای تصاویر بدون 
استفاده|%(title)s}}--~~~~',
     'it': u'\n\n{{Utente:Filbot/Immagine orfana}}',
 }
-except_text = {
-    'en': u'<table id="mw_metadata" class="mw_metadata">',
-    'it': u'<table id="mw_metadata" class="mw_metadata">',
-}
 
 
 class UnusedFilesBot(Bot):
@@ -63,9 +59,8 @@
                                         template_to_the_image)
         template_user = i18n.translate(self.site,
                                        template_to_the_user)
-        except_text_translated = i18n.translate(self.site, except_text)
         summary = i18n.translate(self.site, comment, fallback=True)
-        if not all([template_image, template_user, except_text_translated, 
comment]):
+        if not all([template_image, template_user, comment]):
             raise pywikibot.Error(u'This script is not localized for %s site.'
                                   % self.site)
         self.summary = summary
@@ -76,8 +71,9 @@
                 pywikibot.output(u"File '%s' does not exist (see bug 69133)."
                                  % image.title())
                 continue
-            if (except_text_translated.encode('utf-8')
-                    not in image.getImagePageHtml() and
+            # Use fileUrl() and fileIsShared() 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() and
                     u'http://' not in image.text):
                 if template_image in image.text:
                     pywikibot.output(u"%s done already"

-- 
To view, visit https://gerrit.wikimedia.org/r/153293
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I5fd3f34b9081fdbb20b853052fe1c4c30e360d93
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jay...@gmail.com>
Gerrit-Reviewer: John Vandenberg <jay...@gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhall...@arctus.nl>
Gerrit-Reviewer: Ricordisamoa <ricordisa...@openmailbox.org>
Gerrit-Reviewer: Xqt <i...@gno.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
Pywikibot-commits mailing list
Pywikibot-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to