r82057 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82056‎ | r82057 | r82058 >
Date:15:36, 13 February 2011
Author:kwisatz
Status:deferred
Tags:
Comment:
resolved bug where all urls in a gallery were being selected for replacement
Modified paths:
  • /trunk/extensions/GeeQuBox/GeeQuBox.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GeeQuBox/GeeQuBox.php
@@ -27,6 +27,9 @@
2828 'descriptionmsg' => 'geequbox-desc'
2929 );
3030
 31+// defaults
 32+$wgGqbDefaultWidth = 640;
 33+
3134 $wgExtensionMessagesFiles['GeeQuBox'] = dirname(__FILE__) .'/GeeQuBox.i18n.php';
3235 $wgHooks['LanguageGetMagic'][] = 'wfGeeQuBoxLanguageGetMagic';
3336
@@ -89,8 +92,17 @@
9093 imageBtnClose: "'. $eDir .'images/lightbox-btn-close.gif",
9194 imageBtnPrev: "'. $eDir .'images/lightbox-btn-prev.gif",
9295 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+ */
95107 return true;
96108 }
97109
@@ -102,7 +114,7 @@
103115 */
104116 private function _gqbReplaceHref() {
105117 $page = $this->_page->getHTML();
106 - $pattern = '~href="https://www.mediawiki.org/wiki/([^"]+)"~';
 118+ $pattern = '~href="https://www.mediawiki.org/wiki/([^"]+)"\s*class="image"~';
107119 $replaced = preg_replace_callback($pattern,'self::_gqbReplaceMatches',$page);
108120
109121 $this->_page->clearHTML();
@@ -110,12 +122,14 @@
111123 }
112124
113125 private static function _gqbReplaceMatches( $matches ) {
 126+ global $wgGqbDefaultWidth;
114127 $titleObj = Title::newFromText( rawurldecode( $matches[1] ) );
115128 $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()
120134 }
121135
122136 /*
@@ -123,14 +137,6 @@
124138 * This can only be done in js where the window.width is known.
125139 $out->addInlineScript( $jQ.'(document).ready(function(){
126140 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 - }
135141 })' );
136142
137143 */

Status & tagging log