Skip to content

Instantly share code, notes, and snippets.

@Glorfindel83
Last active August 19, 2023 14:08
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Glorfindel83/9d954d34385d2ac2597bbe864466259f to your computer and use it in GitHub Desktop.
Save Glorfindel83/9d954d34385d2ac2597bbe864466259f to your computer and use it in GitHub Desktop.
Broken Image Repairer

Broken Image Repairer

What is the problem?

A long time ago, it was possible to inline images from all kinds of external sources. Since the switch from HTTP to HTTPS, this is no longer possible; only HTTPS sources are allowed. This leads to ugly blurbs like

alt text http://example.com/image.png

instead of a nicely formatted page with images. Sometimes, the links don't even work anymore, even with HTTPS images, which will show like this: ... Luckily, we have the Wayback Machine which is able to rescue some of the lost images. Since a picture often says more than a thousand words, it's important to bring back the post into its original state; important enough to justify the occasional bump of an old post (see below).

What does it do?

'It' is a program which automatically attempts to repair these broken images. You can think of it as a paintings conservator. It will upload the images to Stack Exchange's imgur channel, which makes sure they'll live as long as the posts they appear in, and not get broken again in the future. If the image isn't hosted on one of the popular image hosting sites like ImageShack or TinyPic, it will attempt to add attribution if it isn't present already. It will edit posts (under my own account) if I have edit privileges on a site; if not, it will suggest an edit.

How much does it do?

The program runs approximately once every 36 hours. Edits are limited to one suggested edit at the time, and up to three autonomous edits to e.g. Community Wiki posts; this both limits the effects on the front page, and does not increase the burden on reviewers too much. (I'll run the program more often on Stack Overflow because of the vast number of posts to fix there; flooding the front page is rather hard there.) If the previous suggested edit is still pending review, the program will skip that site. I'm an avid reviewer myself and wouldn't like to review hundreds of the same type of edits. Also, whenever I'm able to, I'm trying to manually review the edits to correct typos and improve formatting. Reviewing by other people helps finding bugs like this one where the program attempted to replace images in code. Hats off to the reviewers there!

Questions?

I'm always happy to discuss automation of moderating tasks. Just ping me in chat, in Charcoal HQ, Ask Different Chat, SOCVR, Tavern on the Meta or invite me into a separate room. A post on your local Meta is fine as well, as long as I'm somehow notified about this (either via a ping in chat or a comment reply - those also work on the posts I've edited, even though my username isn't autocompleted). FWIW, I also examine all rejected edits made by the program. Leaving a comment below works, but since I don't get notified of any new comments, it could take a while before I react.

The bot will detect error/placeholder images like this one, but only if it knows how they look like. Some of these have been hardcoded into the source code, but please let me know if you encounter a situation where this happens again.

@x-yuri
Copy link

x-yuri commented May 7, 2020

@Glorfindel83 I should've probably just approved the edit, but it says, "broken image fixed." And there's no broken image. So what it does is replaces the image with an identical one from imgur. Is that correct?

This one is probably primarily to myself. I'm thinking of adding a link to the original article.

@Glorfindel83
Copy link
Author

@x-yuri that's a surprise. I guess that while the script was running, the Docker website (or at least the part hosting that image) was temporarily down, so that the script thought is was broken. One more reason to host it on Stack Exchange's own Imgur channel...

@timtjtim
Copy link

It probably shouldn’t be replacing Valuable Flair with imgur links. It would be better to update these to https. See https://lifehacks.meta.stackexchange.com/revisions/1272/5

There’s an argument that nominations like that should be “frozen” in time when they’re posted, but it’s a bit late for that now.

@Glorfindel83
Copy link
Author

Thanks @timtjtim, that makes sense indeed. Strange that this situation never occurred before...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment