Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Wikipedia: Mediawiki

Dirty hack for MW-1.19.1 (fix upload images on some hosters)

 

 

Wikipedia mediawiki RSS feed   Index | Next | Previous | View Threaded


fossa-artem at mail

Jul 31, 2012, 11:01 AM

Post #1 of 5 (365 views)
Permalink
Dirty hack for MW-1.19.1 (fix upload images on some hosters)

Hi, mr. All!

When i installed MW-1.19.1 on my hosting i got error messages like

'rename() [function.rename
<http://fwiki.whitefossa.ru/index.php/function.rename>]: SAFE MODE
Restriction in effect. The script whose uid is 55398 is not allowed to
access /var/tmp owned by uid 0 in
*/home/u48601/whitefossaru/fwiki/includes/upload/UploadStash.php* on
line *173*'

when trying to upload any image.

Safe mode was turned OFF, but this error didn't disappear.

Investigations, made by me and Sir. Sheti <sheti [at] furtails> revealed, that my hoster is completely moron. He uses one tempdir /var/tmp for all users of server, and, this directory belongs to root:root. Because it any modification in this directory fails. And, hoster don't allow to change this directory.

So, here is dirty workaround by Sheti:

1) Create temp directory in filesystem, accessible by you, than chmod -R 777 it

2) Locate file <mediawiki_dir>/includes/GlobalFunctions.php

3) Find function named 'wfTempDir()' and comment it (this function determines temp directory):

//Hoster are idiot, we must make temp yourself
/*
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( function_exists( 'sys_get_temp_dir' ) ) {
return sys_get_temp_dir();
}
# Usual defaults
return wfIsWindows() ? 'C:\Windows\Temp' : '/tmp';
}
*/

Than add new version of function:

//BEGIN PATCH
function wfTempDir() {
return '/home/u48601/whitefossaru/fwiki/temp'; //!!!! << FULL PATH TO YOUR TEMP MUST GO HERE !!!!
}
//END PATCH

4) Save file and locate <mediawiki_dir>/includes/uploads/UploadStash.php
5) Find function 'stashFile' and lines

if ( ! preg_match( "/\\.\\Q$extension\\E$/", $path ) ) {
$pathWithGoodExtension = "$path.$extension";

in it.

Comment out this lines.

Place between commented lines and 'if ( ! rename( $path,
$pathWithGoodExtension ) ) {' next code:

//BEGIN PATCH
//For moron hosters, who do not allow to work with file in
tmp directory
if ( ! preg_match( "/\\.\\Q$extension\\E$/", $path ) ) {
$file_basename = basename($path);
$pathWithGoodExtension =
wfTempDir().'/'.$file_basename.$extension;
//END PATCH

This code will move uploaded file into our temp.

6) Enjoy. It's working, but it's very dirty!
7) Write you hoster testimonial email.

P.s. My hoster is Majordomo (Majordomo.ru, Russia).


_______________________________________________
MediaWiki-l mailing list
MediaWiki-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l


overlordq at gmail

Jul 31, 2012, 12:19 PM

Post #2 of 5 (342 views)
Permalink
Re: Dirty hack for MW-1.19.1 (fix upload images on some hosters) [In reply to]

On Tue, Jul 31, 2012 at 1:01 PM, Фосса <fossa-artem [at] mail> wrote:
> Hi, mr. All!
> foreach( array( 'TMPDIR', 'TMP', 'TEMP' ) as $var ) {
> $tmp = getenv( $var );
> if( $tmp && file_exists( $tmp ) && is_dir( $tmp ) &&
> is_writable( $tmp ) ) {
> return $tmp;
> }
> }


Did you try overriding these environment variables first?

_______________________________________________
MediaWiki-l mailing list
MediaWiki-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l


fossa-artem at mail

Jul 31, 2012, 12:19 PM

Post #3 of 5 (340 views)
Permalink
Re: Dirty hack for MW-1.19.1 (fix upload images on some hosters) [In reply to]

Didn't, but i'm in the firm belief that it will not help, because hoster
do not allow to change server-wide variables.

31.07.2012 23:19, OQ пишет:
> On Tue, Jul 31, 2012 at 1:01 PM, Фосса <fossa-artem [at] mail> wrote:
>> Hi, mr. All!
>> foreach( array( 'TMPDIR', 'TMP', 'TEMP' ) as $var ) {
>> $tmp = getenv( $var );
>> if( $tmp && file_exists( $tmp ) && is_dir( $tmp ) &&
>> is_writable( $tmp ) ) {
>> return $tmp;
>> }
>> }
>
> Did you try overriding these environment variables first?
>
> _______________________________________________
> MediaWiki-l mailing list
> MediaWiki-l [at] lists
> https://lists.wikimedia.org/mailman/listinfo/mediawiki-l



_______________________________________________
MediaWiki-l mailing list
MediaWiki-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l


Platonides at gmail

Jul 31, 2012, 4:59 PM

Post #4 of 5 (338 views)
Permalink
Re: Dirty hack for MW-1.19.1 (fix upload images on some hosters) [In reply to]

On 31/07/12 21:19, Фосса wrote:
> Didn't, but i'm in the firm belief that it will not help, because hoster
> do not allow to change server-wide variables.

This should work when set in LocalSettings.php:
putenv("TMPDIR=/home/u48601/whitefossaru/fwiki/temp");
(but safemode config could forbid you from doing so)



_______________________________________________
MediaWiki-l mailing list
MediaWiki-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l


mah at everybody

Aug 1, 2012, 8:59 AM

Post #5 of 5 (329 views)
Permalink
Re: Dirty hack for MW-1.19.1 (fix upload images on some hosters) [In reply to]

On 07/31/2012 02:01 PM, Фосса wrote:
> Hi, mr. All!
>
> When i installed MW-1.19.1 on my hosting i got error messages like
>
> 'rename() [function.rename SAFE MODE
> Restriction in effect. The script whose uid is 55398 is not allowed to
> access /var/tmp owned by uid 0 in *UploadStash.php* on
> line *173*'
>
> when trying to upload any image.
>
> Safe mode was turned OFF, but this error didn't disappear.

I think this is Bug 24985 which has been fixed by
https://gerrit.wikimedia.org/r/#/c/8996/ to use $wgTmpDirectory when
available. There was a lot of discussion on MW.o about this sort of
problem (see
http://www.mediawiki.org/wiki/Thread:Talk:MediaWiki_1.19/Thumbnails_didn%27t_work_since_Update_to_1.19,
shortened: http://hexm.de/ks)

If the patch in Gerrit fixes your problem then, it will be fixed in
1.20, at the latest (due out later this year).

Mark.

_______________________________________________
MediaWiki-l mailing list
MediaWiki-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l

Wikipedia mediawiki RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.