Enabling and using file uploads with mediawiki

From Notes_Wiki
Revision as of 07:30, 25 March 2014 by Saurabh (talk | contribs)

<yambe:breadcrumb>Mediawiki configuration</yambe:breadcrumb>

Enabling and using file uploads with mediawiki

Configuring mediawiki

You can add following lines to LocalSettings.php file to enable uploads quicky

#Setting local directory for upload and its corresponding server URL
$wgUploadDirectory='/documents/room-documents/documents/databases/mysql/notes_wiki/upload';
$wgUploadPath='/notes/upload';

#Allow uploads from URL
$wgAllowCopyUploads=true;

#Enabling upload
$wgEnableUploads=true;

#Do not check for extensions too strictly
$wgStrictFileExtensions=false; 


Configuring apache

Make sure that webserver has alias like in appropriate virtual host for uploads and wiki to work properly

Alias /notes/upload /documents/room-documents/documents/databases/mysql/notes_wiki/upload
Alias /notes /usr/share/mediawiki-notes
<Directory "/usr/share/mediawiki-notes">
      Order deny,allow
      Deny from all
      Allow from 127.0.0.1
</Directory>
<Directory "/documents/room-documents/documents/databases/mysql/notes_wiki/upload">
      Order deny,allow
      Deny from all
      Allow from 127.0.0.1
</Directory>

Please note that Alias for /notes/upload should come before alias for /notes for things to work


Setting file system permissions

Also the folder "/documents/room-documents/documents/databases/mysql/notes_wiki/upload" in case of above examples should have 777 permissions on it so that webserver can write into the folder.


Linking to uploaded files

After uploading file using Upload File link from left panel you can link to it using

[[Media:Asa_5520-2009-10-06.txt|Asa_5520-2009-10-06.txt]]

where first 'Asa_5520-2009-10-06.txt' refers to name of uploaded file and second 'Asa_5520-2009-10-06.txt' is the text to displayed on wiki which would link to uploaded file.


Allowing extra extension

By default mediawiki may allow only upload of files with extensions such as .png, .jpg, etc. To allow additional extensions use:

 $wgFileExtensions[] = 'doc';

Even with this blacklist extensions will not be allowed. To remove an extension from blacklisting use:

$wgFileExtensions[] = 'py';
$wgFileBlacklist = array_diff( $wgFileBlacklist, array ('py') );


More information

For more details on file uploads read http://www.mediawiki.org/wiki/Manual:Configuring_file_uploads and http://www.mediawiki.org/wiki/Manual:Configuration_settings#Uploads



<yambe:breadcrumb>Mediawiki configuration</yambe:breadcrumb>