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()