UploadVariables-Talk
Problem with cyrillic filenames
1) In fresh clean PmWiki v2.2.129 when I try to upload file "Screenshot_2020-05-25 Синтаксис [Attach file].png" I get the message "Screenshot_2020-05-25 105710801085109010721082108910801089 Attach file.png: successfully uploaded". Why? By default "only Roman letters a-zA-Z, digits 0-9, underscore _ dash - dot . and space are allowed", so "Синтаксис" should be deleted?
Finar May 26, 2020, at 05:00 PM
A clean fresh PmWiki with UTF-8 enabled renames the file to "Screenshot_2020-05-25 Attach file.png". When the webpage encoding doesn't contain Cyrillic characters (eg Latin-1, not UTF-8 and not CP1251 or KOI8-R), then those are converted by the browser to HTML entities like Синтаксис
(same with wikitext) which then for a filename are stripped of characters &, # and ; not allowed in $UploadNameChars
and it becomes 105710801085109010721082108910801089. --Petko May 26, 2020, at 06:37 PM
This is my config.php:
$EnableUpload = 1; $DefaultPasswords['edit'] = pmcrypt('fe89e8ge0'); $DefaultPasswords['admin'] = pmcrypt('fe89e8ge0'); $UploadMaxSize = 20971520; include_once("$FarmD/scripts/xlpage-utf-8.php"); $EnableDiag = true;
Test site is 129.pmwiki.ru and it does not rename file (I use FireFox) :( Did I forgot something? You can try yourself, the password is actual. Finar
Well, it works on my own systems -- I tried before I wrote my reply. I'm guessing that either your server software (Nginx or Apache) somehow rewrites the file names, or the filesystem on the server doesn't support UTF-8 file names, or there may be something else. --Petko May 28, 2020, at 01:32 PM
2) Can you help me to add the following filenames converts:
- convert " " (space) to "_" (underscore);
- convert all cyrillic to transliterated text, like "Синтаксис" -> "sintaksis" (I have transliteration function already)
Finar May 26, 2020, at 05:00 PM
To add your own functions that rewrite the file names, you need to define both $UploadNameChars
and $MakeUploadNamePatterns
, something like this below. --Petko May 26, 2020, at 06:37 PM
$UploadNameChars = "-a-zA-Z0-9_. "; $MakeUploadNamePatterns = array( '/^.*$/' => 'cyr2ascii', # your custom function '/ +/' => '_', # space(s) to underscore "/[^$UploadNameChars]/" => '', # same as in scripts/upload.php '/(\\.[^.]*)$/' => 'cb_tolower', '/^[^[:alnum:]_]+/' => '', '/[^[:alnum:]_]+$/' => '' ); function cyr2ascii($m) { # the filename is $m[0] $cyr = [ 'а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п', 'р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','я', 'А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','М','Н','О','П', 'Р','С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ъ','Ы','Ь','Э','Ю','Я' ]; $lat = [ 'a','b','v','g','d','e','io','zh','z','i','y','k','l','m','n','o','p', 'r','s','t','u','f','h','ts','ch','sh','sht','a','i','y','e','yu','ya', 'A','B','V','G','D','E','Io','Zh','Z','I','Y','K','L','M','N','O','P', 'R','S','T','U','F','H','Ts','Ch','Sh','Sht','A','I','Y','E','Yu','Ya' ]; return str_replace($cyr, $lat, $m[0]); }
MediaWiki links adaptation
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, justAttach:image.jpg
or the new ones likeImage: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 likeMedia: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
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.