r24962 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24961‎ | r24962 | r24963 >
Date:19:28, 20 August 2007
Author:robchurch
Status:old
Tags:
Comment:
* Fix complete breakage of the size option
* Simple wrapper for file existence check to avoid breaking things under 1.9 and below for no good reason
Modified paths:
  • /trunk/extensions/RandomImage/README (modified) (history)
  • /trunk/extensions/RandomImage/RandomImage.class.php (modified) (history)

Diff [purge]

Index: trunk/extensions/RandomImage/README
@@ -93,6 +93,8 @@
9494 Version 1.4
9595 Support automatic caption retrieval from image description pages
9696 Limit database selections to files with "IMAGE" major MIME types
 97+ Fix regression; "size" was ignored under most circumstances
 98+ Force thumbnailing of images
9799
98100 August 15, 2007
99101 Version 1.3
Index: trunk/extensions/RandomImage/RandomImage.class.php
@@ -60,38 +60,49 @@
6161 */
6262 public function render() {
6363 $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();
7572 }
7673 return '';
7774 }
7875
7976 /**
 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+ /**
8094 * Prepare image markup for the given image
8195 *
82 - * @param File $image Image to render
 96+ * @param Title $title Title of the image to render
8397 * @return string
8498 */
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 )
88103 $parts[] = "{$this->width}px";
89 - $parts[] = 'frame';
90 - } else {
91 - $parts[] = 'thumb';
92 - }
93104 if( $this->float )
94105 $parts[] = $this->float;
95 - $parts[] = $this->getCaption( $image->getTitle() );
 106+ $parts[] = $this->getCaption( $title );
96107 return '[[' . implode( '|', $parts ) . ']]';
97108 }
98109

Status & tagging log