Commit 6404e4bc by murtaugh

added back phpuploader option

parent 79913288
......@@ -12,13 +12,13 @@ def filetest (p):
return False
return True
def fixurlfilelinks (src, wiki, timestamp=None):
def fixurlfilelinks (src, wiki, timestamp=None, phpuploader=None, user=None):
if timestamp == None:
timestamp ="%Y/%m/%d")
def linksub (m):
print ("linksub",, file=sys.stderr)
url =
page = upload_url_to_wiki(url, wiki, "{{{{Provenance web|URL={0}|Date={1}]}}}}".format(url, timestamp))
page = upload_url_to_wiki(url, wiki, "{{{{Provenance web|URL={0}|Date={1}]}}}}".format(url, timestamp), phpuploader=phpuploader, user=user)
if page == None:
print ("URL failed {0} removing link: {1}".format(,, file=sys.stderr)
return ""
......@@ -27,11 +27,11 @@ def fixurlfilelinks (src, wiki, timestamp=None):
return re.sub(r"\[\[(?:File|Image)\:(https?\://.+?)(\|.+)?\]\]", linksub, src)
def fixlinks (page, wiki):
def fixlinks (page, wiki, phpuploader=None, user=None):
print ("fixlinks {0}".format(, file=sys.stderr)
src = page.text()
print ("src", src, file=sys.stderr)
newsrc = fixurlfilelinks(src, wiki)
newsrc = fixurlfilelinks(src, wiki, phpuploader=phpuploader, user=user)
if newsrc != src:
print ("[fixlinks] {0} saving updated page...".format(, file=sys.stderr), description="fix broken file links bot")
......@@ -48,12 +48,14 @@ if __name__ == "__main__":
ap.add_argument("--user", default="Michael Murtaugh@bot")
ap.add_argument("--password", default="3ap1p11k33snual7hr2m9nldvg1jo0si")
ap.add_argument("--page", default=None, help="fix just the page with the given name (otherwise default is to use Category:Pages with broken file links)")
ap.add_argument("--phpimportimages", default=None, help="optional: path to mw/maintenance/importImages.php. Default is to upload via the API")
args = ap.parse_args()
wiki = Site((args.wikiprotocol, args.wikihost), path=args.wikipath)
if args.user:
wiki.login(args.user, args.password)
fixlinks(wiki.pages[], wiki)
fixlinks(wiki.pages[], wiki, phpuploader=args.phpimportimages, user=args.user)
for page in wiki.categories["Pages with broken file links"]:
fixlinks(page, wiki)
fixlinks(page, wiki, phpuploader=args.phpimportimages, user=args.user)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment