Enabling and using file uploads with mediawiki

From Notes_Wiki
Revision as of 13:13, 28 July 2022 by Saurabh (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Home > CentOS > CentOS 6.x > Web based tools or applications > Mediawiki configuration > 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') );


Allow upload of .xlsx extension

By default uploading .xlsx may show error that detected mime type is application/zip. To solve it use:

  1. Edit includes/libs/mime/mime.types in wiki as follows
    #application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx
    application/zip zip jar xpi sxc stc sxd std sxi sti sxm stm sxw stw xlsx
  2. Edit LocalSettings.php as follows
    $wgStrictFileExtensions=false;
    $wgFileExtensions = array_merge( $wgFileExtensions,
    array( 'doc', 'xls', 'mpp', 'pdf', 'ppt', 'xlsx', 'jpg',
    'tiff', 'odt', 'odg', 'ods', 'odp'
    )
    );
    $wgVerifyMimeType= "false";

Refer:


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


Home > CentOS > CentOS 6.x > Web based tools or applications > Mediawiki configuration > Enabling and using file uploads with mediawiki