Index: trunk/extensions/RandomImage/README |
— | — | @@ -93,6 +93,8 @@ |
94 | 94 | Version 1.4 |
95 | 95 | Support automatic caption retrieval from image description pages |
96 | 96 | Limit database selections to files with "IMAGE" major MIME types |
| 97 | + Fix regression; "size" was ignored under most circumstances |
| 98 | + Force thumbnailing of images |
97 | 99 | |
98 | 100 | August 15, 2007 |
99 | 101 | Version 1.3 |
Index: trunk/extensions/RandomImage/RandomImage.class.php |
— | — | @@ -60,38 +60,49 @@ |
61 | 61 | */ |
62 | 62 | public function render() { |
63 | 63 | $title = $this->pickImage(); |
64 | | - if( $title instanceof Title ) { |
65 | | - $file = wfFindFile( $title ); |
66 | | - if( $file->exists() ) { |
67 | | - return $this->parser->parse( |
68 | | - $this->buildMarkup( $file ), |
69 | | - $this->parser->getTitle(), |
70 | | - $this->parser->getOptions(), |
71 | | - false, |
72 | | - false |
73 | | - )->getText(); |
74 | | - } |
| 64 | + if( $title instanceof Title && $this->imageExists( $title ) ) { |
| 65 | + return $this->parser->parse( |
| 66 | + $this->buildMarkup( $title ), |
| 67 | + $this->parser->getTitle(), |
| 68 | + $this->parser->getOptions(), |
| 69 | + false, |
| 70 | + false |
| 71 | + )->getText(); |
75 | 72 | } |
76 | 73 | return ''; |
77 | 74 | } |
78 | 75 | |
79 | 76 | /** |
| 77 | + * Does the specified image exist? |
| 78 | + * |
| 79 | + * This is a wrapper around the new File/FileRepo mechanism from |
| 80 | + * 1.10, to avoid breaking compatibility with older versions for |
| 81 | + * no good reason |
| 82 | + * |
| 83 | + * @param Title $title Title of the image |
| 84 | + * @return bool |
| 85 | + */ |
| 86 | + protected function imageExists( $title ) { |
| 87 | + $file = function_exists( 'wfFindFile' ) |
| 88 | + ? wfFindFile( $title ) |
| 89 | + : new Image( $title ); |
| 90 | + return is_object( $file ) && $file->exists(); |
| 91 | + } |
| 92 | + |
| 93 | + /** |
80 | 94 | * Prepare image markup for the given image |
81 | 95 | * |
82 | | - * @param File $image Image to render |
| 96 | + * @param Title $title Title of the image to render |
83 | 97 | * @return string |
84 | 98 | */ |
85 | | - protected function buildMarkup( $image ) { |
86 | | - $parts[] = $image->getTitle()->getPrefixedText(); |
87 | | - if( $this->width !== false ) { |
| 99 | + protected function buildMarkup( $title ) { |
| 100 | + $parts[] = $title->getPrefixedText(); |
| 101 | + $parts[] = 'thumb'; |
| 102 | + if( $this->width !== false ) |
88 | 103 | $parts[] = "{$this->width}px"; |
89 | | - $parts[] = 'frame'; |
90 | | - } else { |
91 | | - $parts[] = 'thumb'; |
92 | | - } |
93 | 104 | if( $this->float ) |
94 | 105 | $parts[] = $this->float; |
95 | | - $parts[] = $this->getCaption( $image->getTitle() ); |
| 106 | + $parts[] = $this->getCaption( $title ); |
96 | 107 | return '[[' . implode( '|', $parts ) . ']]'; |
97 | 108 | } |
98 | 109 | |