[Mediawiki-l] Safely change upload directory path without breaking old links

Platonides Platonides at gmail.com
Mon Oct 11 22:59:05 UTC 2010

Tech Geek wrote:
> I am using MediaWiki 1.12 installed on Linux machine.

You should be using MediaWiki 1.16...

> We have been using MediaWiki for over a year with the file upload variables
> set to their default values.  Here is what the current mediawiki image
> folder looks like:
> wikiserver:~# ls /var/www/wiki/images
> 0  2  4  6  8  a        b  d        e  gnuplot  thumb
> 1  3  5  7  9  archive  c  deleted  f  temp
> Now we need to change upload directory path to something more generic like
> "uploads" with the hash strcture instead of "images" directory.
> Now I am thinking to have the following in my LocalSettings.php file:
> $wgUploadPath = "{$wgScriptPath}/uploads";
> $wgUploadDirectory = "{$IP}/uploads/";
> $wgHashedUploadDirectory = false;
> So far everything looks good and the new files uploaded will work just fine.
> Now my question (s):
> What about the links/path to the files that have been upload previously? I
> am guessing that those will break since they reside in
> /var/lib/mediawiki/images directory. Do I need to move them to the new
> upload directory /var/lib/mediawiki/uploads ? What about the existing
> articles that link to those files in the images directory? Is there a script
> which will do the automated image link building?
> Thanks

The articles know just the image name. The is generated from that so
just moving everything by it should fix it (if you uploaded into uploads
a new version of a file which existed in images you may need to manually
clean it).

As you also changed from $wgHashedUploadDirectory to false, you will
need to move the files from the childs to the uploads root. There's a
script for moving files into hashed folders if needed, too.

The cached pages may still contain pointers to the old location, but
changing LocalSettings.php by defaults updates $wgCacheEpoch forcing to
rerender them.
If someone manually linked to the old location (eg. where they should
have used Media:), well, that link will break. You can use
Special:LinkSearch for the wiki, and/or place a redirect from images to

More information about the MediaWiki-l mailing list