Mediawiki in safe mode: images, deleted, thumbnails, etc.
It’ really hard to set up wiki for safe mode. Not because it’s too complicated - but because of the lack of normal documentation. You can find separate pieces there and here - but not the whole manual.
So.
Image uploads
Allow image uploads
$wgEnableUploads=true;
in your LocalSettings.php file.Set up for all uploaded images not to use hash directory (two level md5 split) - but to use three common directories:
“archive”, “deleted”, “temp”, thumb. You do so by specifying
$wgHashedUploadDirectory = false;
in your LocalSettings.php file.
- Chmod
777
on these directories.
Deleted files in wiki
There are two options:Do not save them at all
$wgSaveDeletedFiles = false;
(possibly, doesn’t work in new versions of wiki)Save them in the root of the “deleted” folder:
1
2
3
4$wgSaveDeletedFiles = true;
$wgFileStore['deleted']['directory'] = false;// Defaults to $wgUploadDirectory/deleted
$wgFileStore['deleted']['url'] = null; // Private, so set to null
$wgFileStore['deleted']['hash'] = 0; // 0-level subdirectory split
Thumbnails
Are you sure you really need them? :)) It's the beginning of the fun. There are also several options.1 ) Generate thumbnails on EVERY client request, instead of generating and writing them to thumbs directory
$wgThumbnailScriptPath = "{$wgScriptPath}/thumb.php";
If you don’t have many images in your wiki, then you can really use this option. If not - just think, how hard it will be on your server :(
Have pity.
2 ) Use browser resizing instead of graphic library’s. It’s fast, it doesn’t require any server power… But it’s pretty stupid, yeah?
And also - it happened to me several times quite accidentially during my experiments… I don’t think that anyone will try to use this thing, so I don’t want to explore how to repeat it.
3 ) And now - the only pretty way for working with images in wiki. Please read carefully. This way requires that you have the ability to change server safe mode configuration. So…
- In php.ini set
safe_mode_gid=1
What it does?
PHP manual: By default, Safe Mode does a UID compare check when opening files. If you want to relax this to a GID compare, then turn on safe_mode_gid. Whether to use UID (FALSE) or GID (TRUE) checking upon file access.
- Move your user to “apache” group
- Set
$wgDirectoryMode=0777;
- No #4. It will all JUST WORK!!! Now, web server will compare not user_id of the files’s owner, but group_id. And it will be the same! By the way, now you can set up all normal settings:
1
2
3
4
5
6
7
8$wgEnableUploads = true;
$wgHashedUploadDirectory = true;
$wgSaveDeletedFiles = true;
$wgFileStore['deleted']['directory'] = false;// Defaults to $wgUploadDirectory/deleted
$wgFileStore['deleted']['url'] = null; // Private, so set to null
$wgFileStore['deleted']['hash'] = 3; // 3-level subdirectory split
$wgAllowCopyUploads=true;
$wgDirectoryMode=0777;
Hey-hey… Now, you’ll need to move your images to the hashed upload directory, right? Unfortunately, wiki doesn’t have an option for it. But you can do it manually - just upload to your images dir and execute the following script:
1 |
|
And all your images will be moved to their hashed directories! By the way, slightly modifying the script, you can move your thumbnails (not neccesary, they are recreated automatically from original files) and deleted files to theit hashed directories.
Some notes:
1) Sometimes you can see errors that put_env function can't run properly because of safe mode. It doesn't affect any functionality but looks rather bad for user. To remove errors, you can either- comment lines in wiki source code (NOT RECOMMENDED)
- Disable error reporting in php
- Use ErrorHandler extension for hiding errors.
- Disable error reporting in PHP locally by setting the following at the top of your LocalSettings.php file
error_reporting(0); #Disable the reporting of errors
2)Setting time zone
In safe mode, things like
1 | $wgLocaltimezone = "America/New_York"; |
Won’t work. Instead, you should use
1 | $wgLocaltimezone = 'CET'; |
It is the only possible solution.
It will make the bloody wiki engine use server time (it MUST use it by default - but WTF?!) and set time offset +4 for all new users. It’s the only workaround for safe mode in wiki.
LATER:
I added this articles to mediawiki development pages:
http://www.mediawiki.org/wiki/Safe_mode - there possibly can be something new now.