Thumbnails didn't work since Update to 1.19

Jump to: navigation, search

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

212.21.161.8812:30, 4 May 2012

Is this your issue?

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.21216:47, 4 May 2012

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.21222:35, 4 May 2012
 

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

91.89.83.21216:40, 5 May 2012

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

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.8809:44, 9 May 2012

You do have access to Bugzilla: https://bugzilla.wikimedia.org/

MarkAHershberger(talk)12:18, 9 May 2012
 

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.8809:44, 9 May 2012
 
 
 

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 (talk)13:04, 24 May 2012

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

Anderssl (talk)13:05, 24 May 2012
 

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?

MarkAHershberger(talk)13:26, 24 May 2012

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 (talk)19:27, 24 May 2012

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 (talk)08:32, 25 May 2012
 
Edited by another user.
Last edit: 12:39, 25 May 2012

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 (talk)08:56, 25 May 2012

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".

Anderssl (talk)09:51, 25 May 2012
 

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(talk)13:29, 25 May 2012

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!
MarkAHershberger(talk)13:40, 25 May 2012
 
Edited by another user.
Last edit: 14:36, 25 May 2012

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 (talk)13:42, 25 May 2012

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.

Anderssl (talk)13:54, 25 May 2012
 

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.

MarkAHershberger(talk)14:54, 25 May 2012

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...

Anderssl (talk)15:48, 25 May 2012

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.

MarkAHershberger(talk)18:16, 25 May 2012

> 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.

Anderssl (talk)23:01, 25 May 2012

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

MarkAHershberger(talk)23:09, 25 May 2012
 

Could you try this patch?

MarkAHershberger(talk)17:16, 26 May 2012

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").

Anderssl (talk)07:32, 28 May 2012

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

MarkAHershberger(talk)13:10, 28 May 2012
 
 
 
 
 
 
 
 
 
 
 

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!

Stefahn (talk)11:43, 16 June 2012

If you are sitting in the root of your MediaWiki installation and have access to patch, then this patch should be able to be applied like so:

 $ curl https://gerrit.wikimedia.org/r/gitweb?p=mediawiki/core.git;a=patch;h=99fdc6e838d4c7f6a7135a06b58d0bb232ca611c | patch -p1
MarkAHershberger(talk)11:32, 19 June 2012

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 :)

Stefahn (talk)20:51, 19 June 2012

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

87.53.152.25419:34, 29 August 2012
 

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

176.199.75.5020:50, 3 July 2012

Why can't you use the patch?

MarkAHershberger(talk)20:56, 3 July 2012

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

176.199.75.5004:24, 4 July 2012

You can get the files to upload from here: includes/DefaultSettings.php, includes/GlobalFunctions.php, includes/Setup.php, includes/diff/DifferenceEngine.php, includes/filerepo/backend/TempFSFile.php, includes/objectcache/DBABagOStuff.php, maintenance/storage/checkStorage.php

MarkAHershberger(talk)04:51, 4 July 2012
Edited by another user.
Last edit: 07:57, 4 July 2012

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

94.100.245.12607:48, 4 July 2012
 

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

188.23.151.317:52, 21 July 2012

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

Stefahn (talk)18:07, 21 July 2012
 

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

91.66.112.20618:31, 30 August 2012

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)

Thorsten (talk)18:21, 12 September 2012
 

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

95.91.80.19912:28, 13 September 2012

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

94.183.174.2810:59, 16 October 2012
 

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

Nakohdo (talk)20:48, 30 October 2012

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

MarkAHershberger(talk)21:17, 30 October 2012

Thanks for your reply. Unfortunately the wiki is on our intranet so I can't send you the link.

I reverted to MW 1.19.2 and finally solved the problem using an environment variable for pointing to the temp dir as suggested as the second solution at http://jehy.ru/articles/2012/09/17/mediawiki-1-19-unable-to-save-thumbnail-to-destination/

I also used the temp dir path provided by my hosting provider instead of an MW internal path.

hth

Nakohdo (talk)18:29, 31 October 2012
 
 
 
 
 
 

I did a fresh Install of 1.20.2 today with no modification to the uploadpath or so and now I'm facing the same problem. How can I use the patch (if its suitable for the current version) on a host with no shell access. example ist at

http://blechschaden.bplaced.net/wiki/index.php?action=Test

while an 1.18 works on the same host out of the box

http://wiki.fivefivezero.bplaced.net

Carchaias (talk)23:32, 29 December 2012

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}
Carchaias (talk)00:12, 30 December 2012
 

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

MarkAHershberger(talk)00:28, 2 January 2013
 
 
 

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

$wgTmpDirectory = ini_get('upload_tmp_dir');
Actiuinformatica (talk)16:42, 16 March 2013