r51440 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51439‎ | r51440 | r51441 >
Date:23:55, 3 June 2009
Author:laner
Status:deferred
Tags:
Comment:
* Fix image descriptions
Modified paths:
  • /trunk/extensions/SmoothGallery/SmoothGallery.php (modified) (history)
  • /trunk/extensions/SmoothGallery/SmoothGalleryParser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SmoothGallery/SmoothGallery.php
@@ -35,7 +35,7 @@
3636 $wgExtensionCredits['other'][] = array(
3737 'path' => __FILE__,
3838 'name' => 'SmoothGallery parser extension',
39 - 'version' => '1.1d',
 39+ 'version' => '1.1e',
4040 'author' => 'Ryan Lane',
4141 'description' => 'Allows users to create galleries with images that have been uploaded. Allows most options of SmoothGallery',
4242 'descriptionmsg' => 'smoothgallery-desc',
Index: trunk/extensions/SmoothGallery/SmoothGalleryParser.php
@@ -22,70 +22,53 @@
2323
2424 function parseArguments( $argv ) {
2525 // Parse arguments, set defaults, and do sanity checks
 26+ $this->argumentArray = array( "height" => "300px", "width" => "400px", "carousel" => true, "timed" => false,
 27+ "delay" => "9000", "showarrows" => true, "showinfopane" => true,
 28+ "slideinfozoneslide" => true, "slideinfozoneopacity" => "0.7", "fallback" => "gallery",
 29+ "nolink" => false );
 30+
2631 if ( isset( $argv["height"] ) && is_numeric( $argv["height"] ) ) {
2732 $this->argumentArray["height"] = $argv["height"] . "px";
28 - } else {
29 - $this->argumentArray["height"] = "300px";
3033 }
3134
3235 if ( isset( $argv["width"] ) && is_numeric( $argv["width"] ) ) {
3336 $this->argumentArray["width"] = $argv["width"] . "px";
34 - } else {
35 - $this->argumentArray["width"] = "400px";
3637 }
3738
3839 if ( isset( $argv["showcarousel"] ) && $argv["showcarousel"] == "false" ) {
3940 $this->argumentArray["carousel"] = false;
40 - } else {
41 - $this->argumentArray["carousel"] = true;
4241 }
4342
4443 if ( isset( $argv["timed"] ) && $argv["timed"] == "true" ) {
4544 $this->argumentArray["timed"] = true;
46 - } else {
47 - $this->argumentArray["timed"] = false;
4845 }
4946
5047 if ( isset( $argv["delay"] ) && is_numeric( $argv["delay"] ) ) {
5148 $this->argumentArray["delay"] = $argv["delay"];
52 - } else {
53 - $this->argumentArray["delay"] = "9000";
5449 }
5550
5651 if ( isset( $argv["showarrows"] ) && $argv["showarrows"] == "false" ) {
5752 $this->argumentArray["showarrows"] = false;
58 - } else {
59 - $this->argumentArray["showarrows"] = true;
6053 }
6154
6255 if ( isset( $argv["showinfopane"] ) && $argv["showinfopane"] == "false" ) {
6356 $this->argumentArray["showinfopane"] = false;
64 - } else {
65 - $this->argumentArray["showinfopane"] = true;
6657 }
6758
6859 if ( isset( $argv["slideinfozoneslide"] ) && $argv["slideinfozoneslide"] == "false" ) {
6960 $this->argumentArray["slideinfozoneslide"] = false;
70 - } else {
71 - $this->argumentArray["slideinfozoneslide"] = true;
7261 }
7362
7463 if ( isset( $argv["slideinfozoneopacity"] ) && is_numeric( $argv["slideinfozoneopacity"] ) ) {
7564 $this->argumentArray["slideinfozoneopacity"] = $argv["slideinfozoneopacity"];
76 - } else {
77 - $this->argumentArray["slideinfozoneopacity"] = "0.7";
7865 }
7966
8067 if ( isset( $argv["fallback"] ) ) {
8168 $this->argumentArray["fallback"] = htmlspecialchars( $argv["fallback"] );
82 - } else {
83 - $this->argumentArray["fallback"] = "gallery";
8469 }
8570
8671 if ( isset( $argv["nolink"] ) && $argv["nolink"] == "true" ) {
8772 $this->argumentArray["nolink"] = true;
88 - } else {
89 - $this->argumentArray["nolink"] = false;
9073 }
9174 }
9275
@@ -143,10 +126,12 @@
144127 $img_arr = explode( "|", $line, 2 );
145128 $img = $img_arr[0];
146129 if ( count( $img_arr ) > 1 ) {
 130+ SmoothGallery::debug( 'sgallery line has description: ' . $img_arr[1] );
147131 $img_desc = $img_arr[1];
148132 } else {
149133 $img_desc = '';
150134 }
 135+ SmoothGallery::debug( 'sgallery line as img_arr: ', $img_arr );
151136
152137 if ( $wgSmoothGalleryAllowExternal &&
153138 ( ( strlen( $img ) >= 7 && substr( $img, 0, 7 ) == "http://" ) ||
@@ -178,20 +163,13 @@
179164 $ns = $title->getNamespace();
180165
181166 if ( $ns == NS_IMAGE ) {
182 - if ( $img_desc != '' ) {
183 - $galleryArray = $this->parseImage( $title, $parser, $galleryArray, true );
184 - if ( isset( $galleryArray["descriptions"]["$title"] ) ) {
185 - $galleryArray["descriptions"]["$title"] = $img_desc;
186 - }
187 - } else {
188 - $galleryArray = $this->parseImage( $title, $parser, $galleryArray );
189 - }
 167+ $galleryArray = $this->parseImage( $title, $parser, $galleryArray, $img_desc );
190168 } else if ( $ns == NS_CATEGORY ) {
191169 // list images in category
192170 $cat_images = $this->smoothGalleryImagesByCat( $title );
193171 if ( $cat_images ) {
194172 foreach ( $cat_images as $title ) {
195 - $galleryArray = $this->parseImage( $title, $parser, $galleryArray );
 173+ $galleryArray = $this->parseImage( $title, $parser, $galleryArray, '' );
196174 }
197175 }
198176 }
@@ -200,7 +178,7 @@
201179 return $galleryArray;
202180 }
203181
204 - function parseImage( $title, $parser, $galleryArray, $getDescription = false ) {
 182+ function parseImage( $title, $parser, $galleryArray, $description ) {
205183 global $wgUser;
206184 global $wgSmoothGalleryThumbHeight, $wgSmoothGalleryThumbWidth;
207185
@@ -258,27 +236,25 @@
259237 }
260238 }
261239
262 - $fulldesc = '';
263 -
264240 if ( $this->argumentArray["showinfopane"] ) {
265 - if ( $getDescription ) {
 241+ if ( $description == '' ) {
266242 // Load the image page from the database with the provided title from
267243 // the image object
268244 $db = wfGetDB( DB_SLAVE );
269245 $img_rev = Revision::loadFromTitle( $db, $title );
270246
271247 // Get the text from the image page's description
272 - $fulldesc = $img_rev->getText();
 248+ $description = $img_rev->getText();
273249 }
274250
275251 // convert wikitext to HTML
276252 // TODO: find out why this doesn't work with special pages
277253 if ( $parser ) {
278 - $pout = $parser->recursiveTagParse( $fulldesc, $title, $parser->mOptions, true );
279 - $fulldesc = strip_tags( $pout );
 254+ $pout = $parser->recursiveTagParse( $description, $title, $parser->mOptions, true );
 255+ $description = strip_tags( $pout );
280256 # $fulldesc = strip_tags( $pout->getText() );
281257 } else { // fall back to HTML-escaping
282 - $fulldesc = htmlspecialchars( $fulldesc );
 258+ $description = htmlspecialchars( $description );
283259 }
284260 }
285261
@@ -289,7 +265,7 @@
290266
291267 # We need the following for the image's div
292268 $imageArray["heading"] = $skin->makeKnownLinkObj( $img_obj->getTitle(), $img_obj->getName() );
293 - $imageArray["description"] = $fulldesc;
 269+ $imageArray["description"] = $description;
294270 $imageArray["full_url"] = $title->getFullURL();
295271 $imageArray["view_url"] = $img_obj->getViewURL();
296272 $imageArray["full_thumb_url"] = $full_thumb;

Status & tagging log