just reading through and one issue that stands out with (e.g.: [[file:foo.png|thumb|no-viewer|…]]). format is that many of the small image files are embedded within infoboxes, templates and tables would it be more efficient to restrict media viewer to only images that use the syntax [[File:foo.jpg|thumb|....]] within an article body ignoring images embedded with in {{.....}} and encourage editors to shift flags, small icons, maps etc into templates.
Alternatively just use the [[file:Foo.jpg|
thumb |....]] as the key for media viewer to display otherwise it just ignores the file