Meza/Ensuring users get the latest file

From mediawiki.org

The problem[edit]

after you "Upload a new version of this file" for a file .. other pages in the wiki that link to that file do not automatically result in the latest version without some manual per-page coercing by the users .. how can admins guarantee that users will always see the "current version" of an image after it has been updated?

Possible Solutions[edit]

Which of these options and how to configure them is still a topic of discussion. If you have any specific solution that works for you.. please contribute to this page.

tools and solutions listed so far include;

MW update[edit]

https://gerrit.wikimedia.org/r/#/c/mediawiki/core/+/496705/

apache solution[edit]

https://httpd.apache.org/docs/current/mod/mod_expires.html

Stashbot[edit]

https://wikitech.wikimedia.org/wiki/Tool:Stashbot

Hack img_auth.php[edit]

Resolve Bug[edit]

https://phabricator.wikimedia.org/T19577

Header Modules[edit]

configure a <location> for images, and use the headers module to add headers http://httpd.apache.org/docs/current/mod/mod_headers.html#header

Other[edit]

https://developer.mozilla.org/docs/Web/HTTP/Headers/Cache-Control has other caching possibilities

Extension:WikiDexFileRepository[edit]

using: https://github.com/ciencia/mediawiki-extensions-WikiDexFileRepository In Localsettings:

wfLoadExtension( 'WikiDexFileRepository' );
$wgLocalFileRepo = [
	'class' => 'LocalWikiDexRepo',
	'name' => 'local',
	'directory' => $wgUploadDirectory,
	'url' => $wgUploadBaseUrl ? $wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
	'hashLevels' => 2,
	'thumbScriptUrl' => $wgThumbnailScriptPath,
	'transformVia404' => true,
	'deletedDir' => $wgDeletedDirectory,
	'deletedHashLevels' => 3
];

this extension adds extra "/latest/<timestamp>" to the image/file path before the filename, which must be stripped out by rewrite rules in .htaccess

Such as the following for NGINX

map $mwuploads_longcache $mwuploads_expire {
	default 5m;
	1 30d;
}

map $uri $images_thumbfallback {
        default @404;
        "~/mwuploads/wikidex/" @thumb;
}

map $uri $images_mwinstallpath {
        default "/dev/null";
        "~/mwuploads/wikidex/" "/home/www/www.wikidex.net/mediawiki-1.30";
}

map $request_uri $thumbfile {
        default "xx";
        "~/mwuploads/[a-z0-9]+/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/latest/[0-9]+/(?<xthumbfile>[^/]+)/[0-9]+px-.*$" "$xthumbfile";
        "~/mwuploads/[a-z0-9]+/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/(?<xthumbfile>[^/]+)/[0-9]+px-.*$" "$xthumbfile";
        "~/mwuploads/[a-z0-9]+/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/(?<xthumbfile>[^/]+)/[0-9]+px-.*$" "$xthumbfile";
}
	
server {


	location /mwuploads/ {
		alias /data/mwuploads/public/;
		expires $mwuploads_expire;

		# Imagen con /latest/timestamp/, se reescribe, expires largo
		location ~ "^/mwuploads/[a-z0-9]+/(?:thumb/)?[0-9a-f]/[0-9a-f][0-9a-f]/latest/[0-9]+/.*$" {
				set $mwuploads_longcache 1;
				expires $mwuploads_expire;
				rewrite "^/mwuploads/(?<startpath>[a-z0-9]+/(?:thumb/)?[0-9a-f]/[0-9a-f][0-9a-f]/)latest/[0-9]+/(?<endpath>.*)$" "/mwuploads/$startpath$endpath";
		}

		# Imagen directa en /archive, expires largo
		location ~ "^/mwuploads/[a-z0-9]+/archive" {
				set $mwuploads_longcache 1;
				expires $mwuploads_expire;
		}
		# Imagen thumb
		# Ojo, las variables del regexp se usan en @thumb
		location ~ "^/mwuploads/[a-z0-9]+/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/[^/]+/(?<thumbwidth>[0-9]+)px-.*$" {
				set $thumbarchived 0;
				expires $mwuploads_expire;
				try_files $uri $images_thumbfallback;
		}
		# Imagen thumb de archive
		location ~ "^/mwuploads/[a-z0-9]+/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/[^/]+/(?<thumbwidth>[0-9]+)px-.*$" {
				set $mwuploads_longcache 1;
				set $thumbarchived 1;
				expires $mwuploads_expire;
				try_files $uri $images_thumbfallback;
		}
	}

	location @thumb {
			expires $mwuploads_expire;
			# Run the thumb.php script
			include /etc/nginx/fastcgi_params;
			fastcgi_param SCRIPT_FILENAME $images_mwinstallpath/thumb.php;
			fastcgi_param QUERY_STRING f=$thumbfile&width=$thumbwidth&archived=$thumbarchived;
			fastcgi_pass unix:/run/php/php-fpm-wikidex-images.sock;
	}

	location @404 {
		return 404;
	}

	location / {
		return 404;
	}
}