Jump to content

Topic on Talk:MediaWiki 1.19

Thumbnails didn't work since Update to 1.19

57
Summary by Nemo bis

bugzilla:42730. «I suspect one of the environment (TMPDIR, TMP or TEMP) is set to a directory which is NOT writable by your webserver. In such a case, you have to set $wgTmpDirectory in your LocalSettings.php to a directory writable by your webserver.»

212.21.161.88 (talkcontribs)

Hey there, since I have updated my 1.18.3 release of mediawiki to 1.19.0 I can't get new thumbnails created. If I upload a new picture I get the following error:

Error creating thumbnail: Unable to save thumbnail to destination

in my LocalSettings.php there is the following:

## To enable image uploads, make sure the 'images' directory
## is writable, then set this to true:
$wgEnableUploads  = true;
$wgUseImageMagick = true;
$wgImageMagickConvertCommand = "/usr/bin/convert";
#$wgUseImageResize = true;
$wgImageMagickTempDir = "/srv/httpd/vhosts/wiki.laub-home.de/htdocs/images/imtmp";
#$wgCustomConvertCommand = "/usr/bin/convert -resize %wx%h %s %d";

ImageMagick 6.6.0-4 is installed on a debian squeeze system. I can't see any errors in the apache logfiles and I didn't change the rights on my image folder. Anyone has the same problem? Greeting Andreas

Sumanah (talkcontribs)
91.89.83.212 (talkcontribs)

No, I test the patcht, but still didn't work. If it's an open_base_dir thing, I should see something in the apache logs.

91.89.83.212 (talkcontribs)

I made a mistake adding the patch. Forgot to delete the line

return sys_get_temp_dir();

Now it works fine! Thanks for the Patch and thanks for your help!

91.89.83.212 (talkcontribs)

Hi Sumana,

I found a problem in the patch for open_base_dir. I changed the upload_tmp_dir to /srv/php-tmp/ in my php.ini. This is a security thing. So the patcht checks first for /tmp which is the system tmp directory and this drops out an open_basedir error in apache log. Then it goes to the php.ini upload_tmp_dir, which works. I think the order of the patch schould changed to first look at php and then the system temp dir to avoid the error in apache log.

Greetings Andreas

Sumanah (talkcontribs)

Andreas, can you go ahead and just submit a corrected patch either via Developer access or via the bug in Bugzilla?

212.21.161.88 (talkcontribs)

Hi, I don't have access to Bugzilla, so here is my Patch, the whole function wfTempDir() looks like that on my Mediawiki:

function wfTempDir() {
        foreach( array( 'TMPDIR', 'TMP', 'TEMP' ) as $var ) {
                $tmp = getenv( $var );
                if( $tmp && file_exists( $tmp ) && is_dir( $tmp ) && is_writable( $tmp ) ) {
                        return $tmp;
                }
        }
        if (ini_get('upload_tmp_dir')!==false) {
                $tmp = ini_get('upload_tmp_dir');
                if( $tmp && file_exists( $tmp ) && is_dir( $tmp ) && is_writable( $tmp ) ) {
                        return $tmp;
                }
 
        }
        if( function_exists( 'sys_get_temp_dir' ) ) {
                $tmp = sys_get_temp_dir();
                if( $tmp && file_exists( $tmp ) && is_dir( $tmp ) && is_writable( $tmp ) ) {
                        return $tmp;
                }
        }
        # Usual defaults
        return wfIsWindows() ? 'C:\Windows\Temp' : '/tmp';
}
212.21.161.88 (talkcontribs)

Hi, I don't have access to Bugzilla, so here is my Patch, the whole function wfTempDir() looks like that on my Mediawiki:

function wfTempDir() {
        foreach( array( 'TMPDIR', 'TMP', 'TEMP' ) as $var ) {
                $tmp = getenv( $var );
                if( $tmp && file_exists( $tmp ) && is_dir( $tmp ) && is_writable( $tmp ) ) {
                        return $tmp;
                }
        }
        if (ini_get('upload_tmp_dir')!==false) {
                $tmp = ini_get('upload_tmp_dir');
                if( $tmp && file_exists( $tmp ) && is_dir( $tmp ) && is_writable( $tmp ) ) {
                        return $tmp;
                }
 
        }
        if( function_exists( 'sys_get_temp_dir' ) ) {
                $tmp = sys_get_temp_dir();
                if( $tmp && file_exists( $tmp ) && is_dir( $tmp ) && is_writable( $tmp ) ) {
                        return $tmp;
                }
        }
        # Usual defaults
        return wfIsWindows() ? 'C:\Windows\Temp' : '/tmp';
}
Sumanah (talkcontribs)
Nemo bis (talkcontribs)
Sephirothindra (talkcontribs)

I can save file, but cannot create thumbnail. It say Error creating thumbnail: Which my Setting was:
$wgAllowTitlesInSVG = True;
$wgFileExtensions = array('pdf', 'png', 'gif', 'jpg', 'flv', 'swf', 'mp3','doc','xls','pdf', 'svg');
$wgFileExtensions[] = 'svg';
$wgSVGConverter = 'ImageMagick';
$wgMaxImageArea = 100 * 1000 * 1000;
$wgMaxShellMemory = 202400;
If i change $wgSVGConverter into 'rsvg' it say error Error creating thumbnail: env: python: No such file or directory So there is any suggestions?

Nemo bis (talkcontribs)

Have you checked where rsvg is located on your machine?

Anderssl (talkcontribs)

Hey, I seem to be having the same problem, but the patch doesn't help: No matter what I do, I get the same error message.

It's a brand new MW installation, 1.19.0, in a shared hosting environment. I have php 5.3.10 (apache2handler) and GD library enabled. My "upload_tmp_dir" in phpinfo.php says "/tmp", and the /tmp directory on my server has rights drwxrwxrwt.

This is what I have in LocalSettings.php - uncommenting the ImageMagick variables has no effect:

$wgEnableUploads = true;

  1. $wgUseImageMagick = true;
  2. $wgImageMagickConvertCommand = "/usr/bin/convert";

I have tried to get some more error messages out of the php, using:

error_reporting( E_ALL ); ini_set( 'display_errors', 1 ); $wgShowExceptionDetails = true;

in LocalSettings.php, but that doesn't produce anything either.

Any ideas???

Anderssl (talkcontribs)

Forgot to say, but the images directory in the MW installation has rights 777, as do all the subfolders.

MarkAHershberger (talkcontribs)

Are you able to write to /tmp from your web process? Could you write a test script to verify this? If you don't know how, could you install a test I write to verify it?

Anderssl (talkcontribs)

Good question. Sure, pass me the script if you have one! (I think I could figure it out myself, but not without some effort...)

Anderssl (talkcontribs)

Some more info that I guess is relevant: I have another, older mediawiki installation running on the same server, where file uploads work fine. That is MW 1.15.1 though. I also just realized that php safe mode is enabled on our server. Is that a likely cause for trouble?

CORRECTION: I just realized that, although file uploading has worked fine for the purposes I have had till now, *thumbnailing* does not seem to work in any of the MW installations on our server. (Haven't had the need for thumbnailing until now.) So I guess this issue is not related strictly to version 19 of MW, but is a general issue with either MW or our server. Sorry about that.

Still, if anyone has any idea about how to diagnose this problem, I'd be thankful!

Anderssl (talkcontribs)

I tried the following:

<?php
$handle = fopen("/tmp/test.txt", "x");
if ($handle) echo "Success!";
else print_r(error_get_last());
?>

...which returns "failed to open stream: No such file or directory". According to php.net the 'x' flag should cause the file to be created if it doesn't exist, so I guess there is something wrong somewhere? I have allow_url_fopen=off in phpinfo, but that shouldn't matter, right?

Anderssl (talkcontribs)

Sorry for spamming the thread - I'm a noob. I changed the above script to point to the images directory, and then i get success. Could this be a php bug? (Or at least a very misleading error message...)

My open_basedir has "no value".

MarkAHershberger (talkcontribs)

Excellent work on reproducing the problem since I took too long to get back to you. Could you try this script?

<?php


function dirTest( $label, $dir ) {
    echo "Test for $label: $dir\n";

    if( file_exists( $dir ) ) {
        echo "Dir exists\n";
        $s = @stat( $dir );
        if( $s === false ) {
            echo "Stat failed: $php_errormsg\n";
        } else {
            echo "Permissions: ". decoct( $s[2] ) ."\n";
            echo "Is dir: ". ( is_dir( $dir ) ? "true" : "false" ) ."\n";
            echo "Is writable: ". ( is_writable( $dir ) ? "true" : "false" )  ."\n";

            $file = tempnam( $dir, "test" );
            echo "Attempting to create: $file\n";
            $fh = fopen( $file, "w" );
            if( $fh !== false ) {
                $written = fwrite( $fh, "stuff" );
                if( $written === false ) {
                    echo "Error when writing: $php_errormsg\n";
                } else {
                    echo "Wrote $written bytes.\n";
                    if( fclose($fh) === false ) {
                        echo "Error when closing: $php_errormsg\n";
                    }
                }
                if( unlink( $file ) === false ) {
                    echo "Error removing $file: $php_errormsg\n";
                } else {
                    echo "Sucessfully removed $file\n";
                }
            } else {
                echo "Error opening for writing: $php_errormsg\n";
            }
        }
    } else {
        echo "Directory does not exist!\n";
    }
    echo "\n";
}

dirTest( "Unix tmp dir", "/tmp" );
dirTest( "Window temp dir", "c:/windows/temp" );
dirTest( "sys_get_temp_dir", sys_get_temp_dir() );
dirTest( "upload_tmp_dir", ini_get( 'upload_tmp_dir' ) );
MarkAHershberger (talkcontribs)

btw, on my laptop this gives:

Test for Unix tmp dir: /tmp
Dir exists
Permissions: 41777
Is dir: true
Is writable: true
Attempting to create: /tmp/testjmWbDE
Wrote 5 bytes.
Sucessfully removed /tmp/testjmWbDE

Test for Window temp dir: c:/windows/temp
Directory does not exist!

Test for sys_get_temp_dir: /tmp
Dir exists
Permissions: 41777
Is dir: true
Is writable: true
Attempting to create: /tmp/test6nrzCk
Wrote 5 bytes.
Sucessfully removed /tmp/test6nrzCk

Test for upload_tmp_dir: 
Directory does not exist!
Anderssl (talkcontribs)

Thanks for getting back to me! The above script returns:

Test for Unix tmp dir: /tmp
Directory does not exist!

Test for Window temp dir: c:/windows/temp
Directory does not exist!

Test for sys_get_temp_dir: /tmp
Directory does not exist!

Test for upload_tmp_dir: /tmp
Directory does not exist!

For the record, there IS a directory that appears to me as '/tmp' in my command line. But I posted this question on stackoverflow, and a commenter suggested the problem could have to do with 'chroot'. This server is part of a large university network, so I am sure the setup is fairly complex.

It seems odd though, given that the user 'nobody' - which I am almost certain is the user running php scripts - is able to write to /tmp.

Is there any way to have the thumbnailing process use some other tmp folder, for instance one under the images folder - where I know i can write?

Anderssl (talkcontribs)

To be more precise: the reason I believe the php user can write to /tmp is that I find lots of files in that directory which have "nobody" as their owner, which is the same owner as I saw on the subfolders that the mediawiki system created under the images folder. The files I see in the /tmp folder all start with "sess_" followed by something that look like a hash, I assume they are some kind of temporary files created by the webserver. Unfortunately I do not at the moment have access to the apache error logs.

MarkAHershberger (talkcontribs)

Interesting. There is $wgTmpDirectory, but wfTempDir() ignores it. Instead of trying to track this down further, go to your includes/GlobalFunctions.php and replace the body of wfTempDir() with:

function wfTempDir() {
  global $wfTmpDirectory;
  return $wfTmpDirectory;
}

I'll investigate why wfTempDir() ignores this. I'm sure there is a good reason, I just don't know it.

Anderssl (talkcontribs)

I assume that's a typo, the variable name should have a 'g' as in $wgTmpDirectory, right? That doesn't quite fix the problem, though. There is a small change: Before the image that I'm trying to upload didn't show up at all on the File:Filename.jpg page (the one that comes up after you click upload) - even though the full version of the image did get uploaded, where it should show on the page was just the error message. Now the full version of the picture is shown, but in the "File History" table below the same error message is shown under "thumbnail". so I guess this modification made the script crash a little later in the process?

Looking in the "thumb" directory there are now empty directories, which each have the same filename as an image I have tried to upload. (E.g. 'images/thumb/PICT0157.jpg/').

If I switch over to using ImageMagick, I get a different error message, saying something about safe mode preventing an external program to be called. Which I guess supports the hypothesis that this fix removed one problem, but the script still crashes later on.

Thank you very much for taking an interest in my problem - will still be grateful if you have any other ideas for a solution...

MarkAHershberger (talkcontribs)

Sorry, yes, a typo.

> where it should show on the page was just the error message

What is the error message?

> so I guess this modification made the script crash a little later in the process?

I don't think so. I think you just need to regenerate the thumbnail. Try adding "?action=purge" to the File:Filename.jpg url. New files should upload with no problem.

Anderssl (talkcontribs)

> What is the error message?

I was referring to the same error message as we've been talking about all the time: "Error creating thumbnail" etc. Before it showed up two places: Where the picture should come, and in the "File history" table. Now it only comes in the table.

> New files should upload with no problem.

Nope. I always test with new files - the errors I am reporting apply to new files that I have not previously tried to upload.

MarkAHershberger (talkcontribs)

Thanks for the explanation. At least we've moved it a bit.

MarkAHershberger (talkcontribs)
Anderssl (talkcontribs)

I'd love to try it, but I don't know how to get it in a format so I can apply it to my installation. I can't use the command that comes up if I click on "patch", because my environment doesn't let me run git (two of my machines say "command not found", the third says "not a git repository").

MarkAHershberger (talkcontribs)

I emailed a patch to you. Let me know if it doesn't work.

Britpoper (talkcontribs)

I'm facing the same problem with a brandnew MediaWiki 1.19.1.

I tried the first proposed patch. The thumbs in my articles were not shown. However thumbnails were shown in the list of uploaded files. But at the same time I got dozens of error messages: "Warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(/tmp) is not within the allowed path(s): (/var/www/web1388/html/:/var/www/web1388/phptmp/:/var/www/web1388/files/:/var/www/web1388/atd/:/usr/share/php/) in /var/www/web1388/html/mediawiki_test/mediawiki/includes/GlobalFunctions.php on line 2495"

I saw that there is another patch. Is it also available as a patch file for Tortoise SVN? I'm not familiar with git.

Will this bug be fixed in 1.19.2?

BTW: I run another wiki on the same shared hosting with MediaWiki 1.16.2 and all thumbnailing works fine on this installation. I don't use ImageMagick on any of my wikis.
My PHP version: 5.3.13-1~dotdeb.0 (cgi-fcgi)
MySQL version: 5.5.25-1

Thanks for your help!

This post was posted by Britpoper, but signed as Stefahn.

MarkAHershberger (talkcontribs)
Stefahn (talkcontribs)

Mark, thanks for your excellent support (also via mail)!

Just for the record:
I managed to apply the patch to my 1.19.1 version.
Then I created a temp folder in the images folder (with chmod 775).
Then I added the following line to localsettings.php:

# Make sure this directory exists and is writable by the webserver!
$wgTmpDirectory = "$IP/images/temp";

Now thumbnails work fine again :)

87.53.152.254 (talkcontribs)

Thank you, Stefahn! Was confronted with the same problem, then the patch + your temp folder solution made my day!

176.199.75.50 (talkcontribs)

Hi,

I experience the same problem, but not able to use patch. What else can I do to get it back to work?

Cheers Yogie

MarkAHershberger (talkcontribs)

Why can't you use the patch?

176.199.75.50 (talkcontribs)

I'm on a shared host and do not have ssh or bash access I need to upload my files via FTP.

MarkAHershberger (talkcontribs)
94.100.245.126 (talkcontribs)

Thank you so much, with these files I got it back to work! Yay! Outstanding support!

188.23.151.3 (talkcontribs)

how do i update those without git? i only have ftp...

Stefahn (talkcontribs)

You can directly download the updated files - see the post by Mark on 4th of July (two posts above this).

91.66.112.206 (talkcontribs)

After i install its working Fine i have the problem showing me after username exm. admin? end the colors have cheng to i dont know what to do please help any one P.S. Sorry for my bad English

Thziege (talkcontribs)

Hey,

indeed, the patch did not work with my Wiki. I noticed that some thumbnails worked, others did not, independently of their file type (jpg, gif, ...). The only effect of the patch was that links to non-existent pages where not underlined red anymore, but black with a red question mark right next to it.

--Thorsten (talk)

95.91.80.199 (talkcontribs)

hi

i have done all steps, but after it comes a white page when i do check and when im save my work its allways the same ->thumbnails do not work for me, the image couldnt save on the right place...sry for my bad english. my version is 1.19.1 . can you help me please....

best regards Barberman

94.183.174.28 (talkcontribs)

Many thanks to Mark(for patch) and Stefahn(for code)

Nakohdo (talkcontribs)

Replacing these files does solve the thumbnail problem, thanks. However, somehow my Common.css and Common.js pages won't show up anymore.

MarkAHershberger (talkcontribs)

Can you link to your wiki so I can see what you're talking about? Or send me an email.

Nakohdo (talkcontribs)
Carchaias (talkcontribs)
Carchaias (talkcontribs)

Ok I inserted all the files from the post of 4.Jul.2012. But now I get an MWException. With $wgShowExceptionDetails = true; it results in:


Preprocessor_DOM::preprocessToObj: generated node count limit exceeded

Backtrace:

  1. 0 /users/blechschaden/www/wiki/includes/parser/Parser.php(2979): Preprocessor_DOM->preprocessToObj('$1 ??? {{SITENA...', 0)
  2. 1 /users/blechschaden/www/wiki/includes/parser/Parser.php(3036): Parser->preprocessToDom('$1 ??? {{SITENA...')
  3. 2 /users/blechschaden/www/wiki/includes/parser/Parser.php(540): Parser->replaceVariables('$1 ??? {{SITENA...')
  4. 3 /users/blechschaden/www/wiki/includes/parser/Parser.php(4636): Parser->preprocess('$1 ??? {{SITENA...', Object(Title), Object(ParserOptions))
  5. 4 /users/blechschaden/www/wiki/includes/cache/MessageCache.php(815): Parser->transformMsg('$1 ??? {{SITENA...', Object(ParserOptions), Object(Title))
  6. 5 /users/blechschaden/www/wiki/includes/Message.php(618): MessageCache->transform('$1 ??? {{SITENA...', true, Object(Language), Object(Title))
  7. 6 /users/blechschaden/www/wiki/includes/Message.php(436): Message->transformText('$1 ??? {{SITENA...')
  8. 7 /users/blechschaden/www/wiki/includes/Message.php(476): Message->toString()
  9. 8 /users/blechschaden/www/wiki/includes/OutputPage.php(790): Message->text()
  10. 9 /users/blechschaden/www/wiki/includes/OutputPage.php(833): OutputPage->setHTMLTitle(Object(Message))
  11. 10 /users/blechschaden/www/wiki/includes/Article.php(485): OutputPage->setPageTitle('Kategorie:Villo...')
  12. 11 /users/blechschaden/www/wiki/includes/CategoryPage.php(73): Article->view()
  13. 12 /users/blechschaden/www/wiki/includes/actions/ViewAction.php(37): CategoryPage->view()
  14. 13 /users/blechschaden/www/wiki/includes/Wiki.php(427): ViewAction->show()
  15. 14 /users/blechschaden/www/wiki/includes/Wiki.php(304): MediaWiki->performAction(Object(CategoryPage))
  16. 15 /users/blechschaden/www/wiki/includes/Wiki.php(536): MediaWiki->performRequest()
  17. 16 /users/blechschaden/www/wiki/includes/Wiki.php(446): MediaWiki->main()
  18. 17 /users/blechschaden/www/wiki/index.php(59): MediaWiki->run()
  19. 18 {main}
MarkAHershberger (talkcontribs)

Since this is a 1.20 issue, I've copied your question here and replied there.

Actiuinformatica (talkcontribs)

My solution for MediaWiki 1.20.3 has been to add the following line to LocalSettings.php

$wgTmpDirectory = ini_get('upload_tmp_dir');
Armin2208 (talkcontribs)

Thanks man!

92.195.122.92 (talkcontribs)

I could solve the problem in version 1.30.0 with changing the temp path setting:

I had:

$wgTmpDirectory     = "{$wgUploadDirectory}/tmp";

but it should be with "e":

$wgTmpDirectory     = "{$wgUploadDirectory}/temp";

even creating a tmp folder with full access right did not help, the path seems to be hard wired to 'temp' anywhere else..

Reply to "Thumbnails didn't work since Update to 1.19"