Index: trunk/extensions/GeeQuBox/GeeQuBox.php |
— | — | @@ -27,6 +27,9 @@ |
28 | 28 | 'descriptionmsg' => 'geequbox-desc' |
29 | 29 | ); |
30 | 30 | |
| 31 | +// defaults |
| 32 | +$wgGqbDefaultWidth = 640; |
| 33 | + |
31 | 34 | $wgExtensionMessagesFiles['GeeQuBox'] = dirname(__FILE__) .'/GeeQuBox.i18n.php'; |
32 | 35 | $wgHooks['LanguageGetMagic'][] = 'wfGeeQuBoxLanguageGetMagic'; |
33 | 36 | |
— | — | @@ -89,8 +92,17 @@ |
90 | 93 | imageBtnClose: "'. $eDir .'images/lightbox-btn-close.gif", |
91 | 94 | imageBtnPrev: "'. $eDir .'images/lightbox-btn-prev.gif", |
92 | 95 | imageBtnNext: "'. $eDir .'images/lightbox-btn-next.gif" |
93 | | - }); |
94 | | - })'); |
| 96 | + }); |
| 97 | + })'); |
| 98 | + /* See _gqbreplaceHref() |
| 99 | + var boxWidth = ($j(window).width() - 20); |
| 100 | + var rxp = new RegExp(/([0-9]{2,})$/); |
| 101 | + $j("div.gallerybox a.image").each(function(el){ |
| 102 | + if(boxWidth < Number(this.search.match(rxp)[0])){ |
| 103 | + this.href = this.pathname+this.search.replace(rxp,boxWidth); |
| 104 | + } |
| 105 | + }); |
| 106 | + */ |
95 | 107 | return true; |
96 | 108 | } |
97 | 109 | |
— | — | @@ -102,7 +114,7 @@ |
103 | 115 | */ |
104 | 116 | private function _gqbReplaceHref() { |
105 | 117 | $page = $this->_page->getHTML(); |
106 | | - $pattern = '~href="https://www.mediawiki.org/wiki/([^"]+)"~'; |
| 118 | + $pattern = '~href="https://www.mediawiki.org/wiki/([^"]+)"\s*class="image"~'; |
107 | 119 | $replaced = preg_replace_callback($pattern,'self::_gqbReplaceMatches',$page); |
108 | 120 | |
109 | 121 | $this->_page->clearHTML(); |
— | — | @@ -110,12 +122,14 @@ |
111 | 123 | } |
112 | 124 | |
113 | 125 | private static function _gqbReplaceMatches( $matches ) { |
| 126 | + global $wgGqbDefaultWidth; |
114 | 127 | $titleObj = Title::newFromText( rawurldecode( $matches[1] ) ); |
115 | 128 | $image = wfFindFile( $titleObj, false, false, true ); |
116 | | - //$realwidth = (Integer) $image->getWidth(); |
117 | | - //$width = ( $realwidth > $defaultWidth ) ? $defaultWidth : $realwidth -1; |
118 | | - //$image->createThumb($width) |
119 | | - return 'href="'.$image->getURL().'"'; |
| 129 | + $realwidth = (Integer) $image->getWidth(); |
| 130 | + $width = ( $realwidth > $wgGqbDefaultWidth ) ? $wgGqbDefaultWidth : $realwidth; |
| 131 | + // do not create a thumbnail when the image is smaller than the default width requested |
| 132 | + $iPath = ( $realwidth < $wgGqbDefaultWidth ) ? $image->getURL() : $image->createThumb($width); |
| 133 | + return 'href="'. $iPath .'" class="image"'; // $image->getURL() |
120 | 134 | } |
121 | 135 | |
122 | 136 | /* |
— | — | @@ -123,14 +137,6 @@ |
124 | 138 | * This can only be done in js where the window.width is known. |
125 | 139 | $out->addInlineScript( $jQ.'(document).ready(function(){ |
126 | 140 | if('.$jQ.'("table.gallery").val() != undefined){ |
127 | | - var boxWidth = ('.$jQ.'(window).width() - 20); |
128 | | - var rxp = new RegExp(/([0-9]{2,})$/); |
129 | | - '.$jQ.'("a[rel=\'lightbox[gallery]\']").each(function(el){ |
130 | | - if(boxWidth < Number(this.search.match(rxp)[0])){ |
131 | | - this.href = this.pathname+this.search.replace(rxp,boxWidth); |
132 | | - } |
133 | | - }); |
134 | | - } |
135 | 141 | })' ); |
136 | 142 | |
137 | 143 | */ |