Knowledgebase

How to disable and enable the renaming of files in MediaWiki

In MediaWiki files can be renamed. It's the equivalent of moving a file; both terms are used for the same thing. This is done from the description page of the file and the process is the same as moving any regular page. For more information on how to do this check the section on how to move and rename pages in MediaWiki in the tutorial on managing pages.

You can manage whether it's allowed to rename files with an option that's specifically intended for that. The option is labeled $wgAllowImageMoving. There's also a user permission labeled movefile that allows users who belong to a user group with that permission to rename/move files. By default, the option for renaming files is enabled and all registered users have the permission to rename files.

Disable and Enable File Renaming for the Whole Site

The option that enables and disables the renaming of files for the whole site is $wgAllowImageMoving. It's enabled by default and so all users who have the user right to rename files can do it. You can disable the option by adding it to the LocalSettings.php file of your MediaWiki and setting it to false. For example, by adding the following on a new line at the end of LocalSettings.php:

$wgAllowImageMoving = false;

you'll disable file renaming/moving for the whole site and for every user, regardless of whether they have the permission to rename files.

In case you want to enable the option again either delete the line or set it to true.

If you haven't edited the LocalSettings.php file, you can find it in the root MediaWiki folder on your MediaWiki hosting account. If the application is installed directly in the public_html directory on the account, then the path to the file will be public_html/LocalSettings.php. HostKnox customers can view and edit files with the file manager of the Pixie control panel. An alternative way to do it is to download the file on your local computer, edit it with a text editor (e.g. Notepad ++) and upload it back overwriting the old file.

Disable and Enable File Renaming per User Group

When the option $wgAllowImageMoving is enabled only users who belong to a user group that has the movefile permission will be able to rename files. So using the permission you can configure which user groups can rename files. By default, the permission is added to the group user (that's the group of all registered users) and it's also explicitly added to the sysop group (the group of the administrators). In this way if you remove the permission from the group of the registered users, administrators will still be able to rename files, unless you remove the permission from the sysop group too.

You can add the right to existing users groups, revoke it, and you can also create a new group with that permission specifically added. You can do this in the same way as changing any other user permission. It's done by adding some code to the LocalSettings.php file. For example, by adding the following:

$wgGroupPermissions['user']['movefile'] = false;

you'll revoke the permission for the group user. This will have the effect of disabling the renaming option for all registered users except administrators. To add the permission to a group replace false with true; you can change the name of the group in the first pair of brackets. For instance, by adding the following to LocalSettings.php:

$wgGroupPermissions['file-managers']['movefile'] = true;

you'll create the group file-managers that will have the right to rename files. You can then assign users to that group from the frontend of the site. For more information on users and rights check out the tutorial on how to manage users, user groups and permissions in MediaWiki (or the shorter article version).

You may also find useful the following articles in our knowledge base related to file uploads and images:

Was this answer helpful?

 Print this Article

Also Read