How to change the values of the user options for the image and thumbnail sizes in MediaWiki
The first thing to make clear is that what's meant here by image size is the dimensions of the image, its width and height in pixels; this is not about the size of the file.
In the account options of registered users there are a couple of settings from which the users can change the dimensions with which images are displayed. One of the options is for selecting the dimensions with which the image is shown on its file description page, and the other is for the dimensions with which thumbnail images are shown in articles. Users can view and configure these by going to Preferences button>Appearance tab>Files section on the page that opens. For both options there are preconfigured values and users can select only from these values. In this article we'll examine how to change these values that can be selected from the two options.
For more details on the user preferences related to images check out the Appearance section in the tutorial on user preferences in MediaWiki. For detailed information on file uploads and on images check out the tutorial on how to manage file uploads and images in MediaWiki.
For each of the two frontend settings related to image size there's a corresponding option that can be added to the LocalSettings.php file of your MediaWiki, and this option can be used to set the allowed image sizes. The options are $wgImageLimits for the image sizes used to display images on file description pages, and $wgThumbLimits for the thumbnail format used in the content of articles.
Change the Available Image Sizes for File Description Pages
The variable $wgImageLimits sets the image sizes that can be selected for the resized image copies displayed on file description pages. As you know, each image that is uploaded has a file description page which displays a copy of the image and some additional information. The dimensions used for the resized copies shown on these pages depend on the image size that the user has selected from their account options. By default it's 800x600 pixels (width x height). The default available sizes from which users can select are 320x240, 640x480, 800x600, 1024x768, 1280x1024.
If you want to, you can change these dimensions. You can also increase or decrease the number of available options; for example, from the default five sizes to three. This is useful if you want to save disk space, for instance, since fewer sizes will be available and hence fewer resized copies will have to be created for each image. In some cases it may be useful to change the different dimensions for purposes related to the style of the skin.
So, for example, let's say that you want the available image sizes to be 640x480, 800x600 and 1024x768, then you have to add the following at the end of the LocalSettings.php file of your MediaWiki:$wgImageLimits = array( array( 640, 480 ), array( 800, 600 ), array( 1024, 768 ) );
After you make this change users will be able to choose only from these three sizes from the preferences of their accounts.
To use different dimensions, simply change the numbers in the brackets. You can add more array lines with sizes or remove existing ones. Just use the form in the above example.
After this you should also explicitly set a default size. That's the size which will be applied to all users by default. Registered users can then select one of the other available sizes from their user preferences. If you don't set a default size, some errors may appear on the site.
You can set a default image size by adding something like this on a new line at the end of LocalSettings.php:
$wgDefaultUserOptions['imagesize'] = 1;
You only have to change the number. It corresponds to a size that you have set with $wgImageLimits. Each size that you set is assigned a number. The top one is 0, the next is 1, and so on. In our example, we have set three sizes:640x480 - this is the top one and so it's 0 800x600 - 1 1024x768 - 2
The numbers are automatically assigned by MediaWiki. You don't have to put them in the actual code. So in our example the default image size is set to 1 which means that the image dimensions 800x600 will be used by default.
Change the Available Thumbnail Image Sizes
When an image is embedded in the content of articles, different formats can be used to display that image. If the thumbnail format is selected and no specific dimensions are set, then the image will be displayed to the user with the dimensions which the user has set for the thumbnail format from their user account preferences.
The default sizes (in pixels) that users can select from the account options are 120, 150, 180, 200, 250, 300. In MediaWiki version 1.24 and newer ones the user option for the thumbnail size is set to 300, while in older versions it's set to 180.
You can change the available thumbnail sizes from which users can choose with the variable $wgThumbLimits. You have to add it to the LocalSettings.php file of your MediaWiki together with a list of the sizes that you want to be available to users. For example, by adding the following at the end of LocalSettings.php:$wgThumbLimits = array( 160, 220 280, 340 );
the available sizes will be 160, 220, 280 and 340.
As with setting the image sizes, MediaWiki automatically assigns a number to each of the thumbnail sizes. The top one (in our examlpe it's 160) is 0, the next is 1, and so on. You can use these numbers to set the default thumbnail size to which the respective user option will be set.
To avoid any errors on the site, after changing the thumbnail sizes you should set a default size. This is done by adding a line with the following form at the end of LocalSettings.php:
$wgDefaultUserOptions['thumbsize'] = 1;
You only have to change the number to correspond to the size that you want. In our example 1 corresponds to the size 220 set with $wgThumbLimits.
Was this answer helpful?
- How to hide page titles in MediaWiki
- How to generate and update a sitemap in MediaWiki
- How to change the size of the search field in MediaWiki
- How to remove the Search block, the Navigation and Tools menus and menu links in MediaWiki
- How to set and change the minimal password length for user accounts in MediaWiki