Index: trunk/extensions/SlimboxThumbs/SlimboxThumbs.php |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | die( 'Not an entry point.' ); |
21 | 21 | } |
22 | 22 | |
23 | | -define( 'SlimboxThumbs_VERSION', '0.1' ); |
| 23 | +define( 'SlimboxThumbs_VERSION', '0.2' ); |
24 | 24 | |
25 | 25 | // Register the extension credits. |
26 | 26 | $wgExtensionCredits['other'][] = array( |
— | — | @@ -50,7 +50,7 @@ |
51 | 51 | */ |
52 | 52 | if ( $slimboxThumbsFilesDir ) { |
53 | 53 | $slimboxThumbsFilesDir = rtrim( trim( $slimboxThumbsFilesDir ), '/' ); // strip whitespace, then any trailing / |
54 | | - // $wgHooks['BeforeParserrenderImageGallery'][] = 'efSBTTestForGallery'; // this seems to fail on some pages :( |
| 54 | + $wgHooks['BeforeParserrenderImageGallery'][] = 'efSBTTestForGallery'; // this seems to fail on some pages :( |
55 | 55 | $hasGallery = true; // temporary fix |
56 | 56 | $wgHooks['BeforePageDisplay'][] = 'efSBTAddScripts'; |
57 | 57 | $wgHooks['BeforePageDisplay'][] = 'efSBTAddSlimboxCode'; |
— | — | @@ -58,19 +58,20 @@ |
59 | 59 | |
60 | 60 | function efSBTTestForGallery( $parser, $gallery ) { |
61 | 61 | global $hasGallery; |
62 | | - if ( $gallery instanceof ImageGallery ) |
63 | | - return $hasGallery = true; |
64 | | - return false; |
| 62 | + $hasGallery = $gallery instanceof ImageGallery; |
| 63 | + return $hasGallery; |
65 | 64 | } |
66 | 65 | |
67 | 66 | function efSBTDebugVar( $varName, $var ) { |
68 | 67 | return "\n\n<!--\n$varName: " . str_replace( '--', '__', print_r( $var, true ) ) . "\n-->\n\n"; |
69 | 68 | } |
70 | 69 | |
71 | | -// this is a callback function that gets called by efBeforePageDisplay() |
| 70 | +// This is a callback function that gets called by efBeforePageDisplay(). |
72 | 71 | function efRewriteThumbImage( $matches ) { |
73 | 72 | global $wgOut, $slimboxThumbsDebug; |
| 73 | + |
74 | 74 | if ( $slimboxThumbsDebug ) { global $wgContLang; } |
| 75 | + |
75 | 76 | $titleObj = Title::newFromText( rawurldecode( $matches[2] ) ); |
76 | 77 | $image = wfFindFile( $titleObj, false, false, true ); # # wfFindFile($titleObj,false,false,true) to bypass cache |
77 | 78 | $output = $matches[1] |
— | — | @@ -85,7 +86,7 @@ |
86 | 87 | return $output; |
87 | 88 | } |
88 | 89 | |
89 | | -// rewrite the gallery code |
| 90 | +// Rewrite the gallery code. |
90 | 91 | function efRewriteGalleryImage( $matches ) { |
91 | 92 | global $wgOut, $slimboxThumbsDebug, $slimboxDefaultWidth; |
92 | 93 | $titleObj = Title::newFromText( rawurldecode( $matches[2] ) ); |
— | — | @@ -134,9 +135,11 @@ |
135 | 136 | |
136 | 137 | function efSBTAddSlimboxCode( $out, $skin ) { |
137 | 138 | global $slimboxThumbsFilesDir, $wgContLang, $hasGallery; |
138 | | - |
| 139 | + |
139 | 140 | // We don't want to run regular expressions if there's no gallery here. |
140 | | - if ( !$hasGallery ) return false; |
| 141 | + if ( !$hasGallery ) { |
| 142 | + return false; |
| 143 | + } |
141 | 144 | |
142 | 145 | # # ideally we'd do this with XPath, but we'd need valid XML for that, so we'll do it with some ugly regexes |
143 | 146 | # # (could use a regex to pull out all div.thumb, maybe they're valid XML? ...probably not) |
— | — | @@ -166,7 +169,7 @@ |
167 | 170 | /sx'; |
168 | 171 | |
169 | 172 | $allDone = preg_replace_callback( $pattern, 'efRewriteGalleryImage', $thumbnailsDone ); |
170 | | - |
| 173 | + |
171 | 174 | $out->clearHTML(); |
172 | 175 | $out->addHTML( $allDone ); |
173 | 176 | |