Extension talk:RandomImage
From MediaWiki.org
[edit] Method renderHook not loading
An email was sent to Rob Church, this is just to document the bug and provide a fix.
When installed and tested on MediaWiki 1.10.0, and 1.11.0, the extension would not render an imagebox and provided the following warning:
Warning: call_user_func_array() [<a href='function.call-user-func-array'>function.call-user-func-array</a>]: Unable to call RandomImage::renderHook() in ${IP}/mediawiki-1.11.1/includes/Parser.php on line 626
The fault appears to be in the declaration of the renderHook method on line 48 of
If you modify;
$wgparser->setHook( 'randomimage', 'RandomImage::renderHook' );
to;
$wgParser->setHook( 'randomimage', array('RandomImage', 'renderHook'));
the method becomes accessible and the extension works. --Zven 01:55, 12 February 2008 (UTC)
[edit] Empty captions
If the <randomcaption> is not used and there is no starting paragraph the image rendering will screw up the page. This seems to be because a caption defined as an empty character or spaces will get stripped out by the method removeMagnifier when it removes the div tags <div class="magnify">, in the process creating a div tag that looks like this;
<div class="thumbcaption"/>
This tag is malformed and depending on the content can cause the left side bar to screw up. Caption content is defined in the method getCaption in RandomImage.class.php;
protected function getCaption( $title ) { if( !$this->caption ) { if( $title->exists() ) { $text = Revision::newFromTitle( $title )->getText(); if( preg_match( '!<randomcaption>(.*?)</randomcaption>!i', $text, $matches ) ) { $this->caption = $matches[1]; } elseif( preg_match( "!^(.*?)\n!i", $text, $matches ) ) { $this->caption = $matches[1]; } else { $this->caption = $text; } } else { $this->caption = ' '; } } return $this->caption; }
Instead of defining spaces as ' ', a UTF-8 character ' ' seems to work. I modified this function to
protected function getCaption( $title ) { if( !$this->caption ) { if( $title->exists() ) { $text = Revision::newFromTitle( $title )->getText(); if( preg_match( '!<randomcaption>(.*?)</randomcaption>!i', $text, $matches ) ) { $this->caption = $matches[1]; } elseif( preg_match( "!^(.*?)\n!i", $text, $matches ) ) { $this->caption = $matches[1]; } else { if($text) { $this->caption = $text; } else { $this->caption=' '; } } } else { $this->caption = ' '; } } return $this->caption; }
which checks that the $text is not empty and sends the UTF-8 character instead of empty or spaces that get stripped forming a div tag like this;
<div class="thumbcaption"> </div>
--Zven 11:13, 12 February 2008 (UTC)
[edit] Incorrectly used <randomimage> causes fatal errors
If someone puts <randomimage> in an article then that particular article/page can throw fatal errors, only revertable by manipulating the query string to provide &action=edit in a long form url request for that page. The problem seems to be in the method removeMagnifier in the file RandomImage.class.php when entities such as are present in the variable $html. A hack seems to be to use the DOMDocument::LoadHTML static method rather than DOMDocument::LoadXML at about line 118. This hack stops the fatal error, but the malformed tag does not work properly unless you close it by specifying <randomimage />--Zven 02:05, 19 February 2008 (UTC)
[edit] Float='center' does not work
In README you mention 'center' as valid value for float. That's not right, it should be 'centre'.
RandomImage.class.php: if( in_array( $float, array( 'left', 'right', 'centre' ) ) )
-- Landa
[edit] Center contra centre
I think it must be center in the source since it sets the <class=tcenter>.
The README is correct but there is a bug in RandomImage.class.php.
So line 47 'centre' must be replaced by 'center'.
--Tomas 21:26, 29 April 2008 (UTC)
[edit] Category Possible?
How it is possible to use only pictures from category: XYZ? The Command <randomimage choices="category:Titelscreen"></randomimage> Did not work.
[edit] No captions?
Is there a way to omit any caption and just have the image? 71.170.103.181 06:42, 15 December 2008 (UTC)
[edit] DOCTYPE/ Invalid HTML output
For some reason, this extension is adding its own doctype declaration, wrapping itself into a html/body tag and exporting unneeded comment data. I've tried to remove this but can't find where it's coming from - most likely the parse function. I just want it to output the div and image code. --75.158.70.23 10:33, 15 March 2009 (UTC)
- I confirm this bug! --66.131.178.187 13:15, 4 May 2009 (UTC)
- In use here, I confirm this bug. --Jlhenry 13:26, 4 May 2009 (UTC)
- Here is the answer I received from the developer of this extension:
- In use here, I confirm this bug. --Jlhenry 13:26, 4 May 2009 (UTC)
Hmm. Well, I'm not really involved with MediaWiki development any more, and that includes extensions; I've no idea what changes have been made since I last committed to RandomImage.
From the sound of it, it's possible that something's altered with respect to the parser, or whatever other mechanism I was using to get the damn thumbnail - I do recall that, at the time, the Linker::makeImageLink() or whatever you're *supposed* to use to produce images didn't work as it should have, and I resorted to using a hack involving the parser and some manipulation of the resulting DOM to extract the bits I was after - a hack pilfered from one of Tim Starling's extensions, I think. If the output (and thus the DOM) have changed in any way, or if some other detail of the XML library or whatever have changed, then that would explain why it's now broken.
Honestly, I probably won't end up doing anything about it - I'm aware that that's a bit of a cop-out, but as I say, I'm no longer involved in the project in any meaningful way, and from what I can gather after a bit of quick reading around, it seems as though that's not a real problem; plenty of people appear to be submitting patches, and those appear to be making it into the source code repository.
If you get really, really stuck, then I might take a look in more detail, but I'm unlikely to be able to come up with a decent solution if no-one else can - I haven't written anything in PHP for a while, and I'm rusty. ;)
Hope this helps explain things, even if all it does is fill you with the impression that I'm somewhat reluctant to rip off that band-aid and get stuck in again.
Rob Church
-
-
- I hope that this could help someone to find a fix. --Jlhenry 14:27, 4 May 2009 (UTC)
-
[edit] False russian encoding with MW 1.12
The string of the description of a picture in Russian, writes Extension in the spoilt kind. For example, Russian word "Ошибка" is written so: "Ошибка " --80.93.116.233 10:38, 12 April 2009 (UTC)
- Problem in French too. --66.131.178.187 21:00, 3 May 2009 (UTC)
[edit] RandomImage in a category?
Could I use <randomimage> in order to show a random image taken from a defined category? --Airon90 15:25, 5 May 2009 (UTC)
[edit] Possible article links?
Needing to see if it is possible to create a "link" for the random images when the choice option is utilized. For instance, I am needing anytime THIS choice is shown, it links to THIS page? Any information on process or even info on if this is possible (or in future versions) would be appreciated. --M1shawhan 22:36, 30 June 2009 (UTC)
[edit] For russian encoding
public function render() {
$title = $this->pickImage();
if( $title instanceof Title && $this->imageExists( $title ) ) {
return //$this->removeMagnifier(
$this->parser->recursiveTagParse(
base64_decode ($this->buildMarkup( $title ))
//)
);
}
return '';
}
protected function buildMarkup ( $title ) {
$parts[] = $title->getPrefixedText();
$parts[] = 'thumb';
if( $this->width !== false )
$parts[] = "{$this->width}px";
if( $this->float )
$parts[] = $this->float;
$parts[] = $this->getCaption( $title );
return ( base64_encode ('[[' . implode( '|', $parts ) . ']]'));
}
Can anybody put this in svn?