UploadVariables-Talk

mwaychoffatmiceadotnet? July 25, 2019, at 09:09 PM

I have few thousand files from MediaWiki that are a part of a translation I am working on to pmWiki. Many of these files have underscores in filename...but links in MediaWiki have spaces as follows...

Filenames have underscores:
ACI_318_08.pdf

MediaWiki links have spaces:
[[Media:ACI 318 08.pdf|ACI 318-08 - Imperial]]

Right now this does not work in pmWiki:
[[Attach:ACI 318 08.pdf|ACI 318-08 - Imperial]]

Right now this does work in pmWiki:
[[Attach:ACI_318_08.pdf|ACI 318-08 - Imperial]]

Please advise efficient way to to resolve many thousands of broken links of this nature.

Much appreciated.

Place this code in config.php:

  $UploadNameChars = "-\\w. "; 
# $UploadNameChars = "-\\w\x80-\xfe. "; # If filenames may have international characters
  $MakeUploadNamePatterns = array(
    "/[^$UploadNameChars]/" => '',
    "/ /" => '_',
    '/(\\.[^.]*)$/' => 'cb_tolower',
    '/^[^[:alnum:]_]+/' => '',
#   "/^[^\\w\x80-\xfe]+/" => '', # If filenames may start with international characters
    '/[^[:alnum:]_]+$/' => ''
    );
  $LinkFunctions['Media:'] = $LinkFunctions['File:'] = $LinkFunctions['Image:'] = 'LinkUpload';
  $IMap['Media:'] = $IMap['File:'] = $IMap['Image:'] = '$1';

Notes:

  • $UploadNameChars defines which characters are allowed in a file name: by default only Roman letters a-zA-Z, digits 0-9, underscore _ dash - dot . and space are allowed, but if you may have files with international or accented characters use the commented-out line above.
  • On PmWiki files can only have lowercase extensions; if you might have files with uppercase extensions, either rename them or comment out the line with 'cb_tolower'.
  • PmWiki doesn't allow filenames to start or end with any special characters, only roman letters, digits and underscore; if your files may have such characters use the second commented-out line.
  • If you already have uploaded files with spaces, they will become invisible to PmWiki, you need to rename them to replace the spaces with underscores.
  • The lines with $LinkFunctions and $IMap will add Media:, File: and Image: prefixes to work exactly like Attach: so you don't need to rewrite your pages.
  • Note that PmWiki will not embed a picture with [[Attach:...]] or the others, but will create a link to it. You need to write without brackets, just Attach:image.jpg or the new ones like Image:image.jpg for the picture to be embedded. Also note that normally you cannot embed this way pictures with spaces in the file name, you need to write the underscores like Media:file_with_spaces.jpg.

If you have any difficulties tell us. --Petko July 26, 2019, at 12:01 PM


Cannot get rid of a Forced 2 Meg upload limit

I tried to set a large file limit to be able to upload larger files and pmwiki seems to restrict my upload anyways. Here is a sample of the code

$UploadMaxSize = 0;

$UploadExtSize['zip' ] = 10*1024*1024; // 10 meg

The goal is to allow to upload zip files which are less than 10 megs. But when I try to upload a 3 Megs, it gives me this error:

"file is larger than maximum allowed by webserver"

It seems to do that on all my sites whatever the config I use. There seems to always be a 2 meg limit. I was wondering if the problem was PMwiki or the webserver itself.

Nov 10th, 2012 by Larienna

It is likely a system limit of the webserver, see Cookbook:SystemLimits, about post_max_size and upload_max_filesize. --Petko November 10, 2012, at 10:50 AM


I have

$UploadNameChars = "-\w. !=+#"; # allow exclamations, equals, plus, and hash

but the example now given has \\w. In fact should not the expression then be

$UploadNameChars = "-\\w\. !=\+#"; # allow exclamations, equals, plus, and hash
simon April 17, 2016, at 05:08 AM

No, $UploadNameChars is used inside a character class (in brackets) so the dot and plus characters have no special meaning. The double backslash could also be single in this case for the exact same effect, but in regular expressions I usually escape (double) them. --Petko April 17, 2016, at 06:22 AM

This is a talk page for improving PmWiki.UploadVariables.