From 37704c66610dfc7b9729b32e4d1f61bb952d3c31 Mon Sep 17 00:00:00 2001 From: Jonathan Golder Date: Sat, 11 Mar 2017 10:39:31 +0100 Subject: [PATCH] Replace pywikibot.showDiff with patched version Pywikibot.bot.userPut does not support setting the value of diff context so it is always zero. Therefore we need to patch either userPut or showDiff to get some context. Related Task: [https://fs.golderweb.de/index.php?do=details&task_id=113 FS#113] --- bots/markpages.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bots/markpages.py b/bots/markpages.py index bdf4034..23a6aa2 100644 --- a/bots/markpages.py +++ b/bots/markpages.py @@ -28,8 +28,10 @@ with templates from datetime import datetime +import pywikibot from pywikibot import pagegenerators from pywikibot.bot import CurrentPageBot +from pywikibot.diff import PatchManager import mwparserfromhell as mwparser @@ -280,6 +282,10 @@ class MarkPagesBot( CurrentPageBot ): # sets 'current_page' on each treat() @param kwargs: Additional parameters directly given to L{Bot.userPut}. @type kwargs: dict """ + + # Monkey patch pywikibot.showDiff + pywikibot.showDiff = showDiff + if ignore_save_related_errors is None: ignore_save_related_errors = self.ignore_save_related_errors if ignore_server_errors is None: @@ -289,3 +295,15 @@ class MarkPagesBot( CurrentPageBot ): # sets 'current_page' on each treat() ignore_save_related_errors=ignore_save_related_errors, ignore_server_errors=ignore_server_errors, **kwargs) + + +# We need to have a patched version to set context param to value greater 0 as +# pywikibot.bot.userPut() currently does not support this value +def showDiff(oldtext, newtext, context=3): + """ + Output a string showing the differences between oldtext and newtext. + + The differences are highlighted (only on compatible systems) to show which + changes were made. + """ + PatchManager(oldtext, newtext, context=context).print_hunks()