http://www.mediawiki.org/wiki/Special:Code/MediaWiki/71149
Revision: 71149 Author: thomasv Date: 2010-08-15 20:45:49 +0000 (Sun, 15 Aug 2010) Log Message: ----------- make image width in edit mode configurable from the index page. Modified Paths: -------------- trunk/extensions/ProofreadPage/ProofreadPage.php trunk/extensions/ProofreadPage/proofread.js Modified: trunk/extensions/ProofreadPage/ProofreadPage.php =================================================================== --- trunk/extensions/ProofreadPage/ProofreadPage.php 2010-08-15 20:39:02 UTC (rev 71148) +++ trunk/extensions/ProofreadPage/ProofreadPage.php 2010-08-15 20:45:49 UTC (rev 71149) @@ -37,9 +37,6 @@ # Group allowed to modify pagequality $wgGroupPermissions['user']['pagequality'] = true; -# Max width of zoomable image -$wgProofreadPageMaxWidth = 2048; - $wgExtensionCredits['other'][] = array( 'path' => __FILE__, 'name' => 'ProofreadPage', @@ -232,8 +229,9 @@ $footer = str_replace( "{{{{$key}}}}", $val, $footer ); } $css = $attributes['css'] ? $attributes['css'] : ""; + $edit_width = $attributes['width'] ? $attributes['width'] : ""; - return array( $index_url, $prev_url, $next_url, $header, $footer, $css ); + return array( $index_url, $prev_url, $next_url, $header, $footer, $css, $edit_width ); } @@ -394,37 +392,27 @@ if ( $image && $image->exists() ) { $width = $image->getWidth(); $height = $image->getHeight(); - if( $width > $wgProofreadPageMaxWidth ) { - $width = $wgProofreadPageMaxWidth; - $height = $image->getHeight() * $wgProofreadPageMaxWidth / $image->getWidth(); - } if ( $m[2] ) { - $viewName = $image->thumbName( array( 'width' => $width, 'page' => $m[3] ) ); - $viewURL = $image->getThumbUrl( $viewName ); - $thumbName = $image->thumbName( array( 'width' => '##WIDTH##', 'page' => $m[3] ) ); - $thumbURL = $image->getThumbUrl( $thumbName ); } else { - $viewURL = $image->getViewURL(); $thumbName = $image->thumbName( array( 'width' => '##WIDTH##' ) ); - $thumbURL = $image->getThumbUrl( $thumbName ); } + $thumbURL = $image->getThumbUrl( $thumbName ); $thumbURL = str_replace( '%23', '#', $thumbURL ); } else { $width = 0; $height = 0; - $viewURL = ''; $thumbURL = ''; } - list( $index_url, $prev_url, $next_url, $header, $footer, $css ) = pr_navigation( $wgTitle ); + list( $index_url, $prev_url, $next_url, $header, $footer, $css, $edit_width ) = pr_navigation( $wgTitle ); $jsFile = htmlspecialchars( "$wgScriptPath/extensions/ProofreadPage/proofread.js?$wgProofreadPageVersion" ); $jsVars = array( 'proofreadPageWidth' => intval( $width ), 'proofreadPageHeight' => intval( $height ), - 'proofreadPageViewURL' => $viewURL, + 'proofreadPageEditWidth' => $edit_width, 'proofreadPageThumbURL' => $thumbURL, 'proofreadPageIsEdit' => intval( $isEdit ), 'proofreadPageIndexURL' => $index_url, @@ -893,7 +881,7 @@ $page_regexp = "/^<noinclude>(.*?)<\/noinclude>(.*?)<noinclude>(.*?)<\/noinclude>$/s"; if( !preg_match( $page_regexp, $text, $m ) ) { pr_load_index( $wgTitle ); - list( $index_url, $prev_url, $next_url, $header, $footer, $css ) = pr_navigation( $wgTitle ); + list( $index_url, $prev_url, $next_url, $header, $footer, $css, $edit_width ) = pr_navigation( $wgTitle ); $new_text = "<noinclude><pagequality level=\"1\" user=\"$username\" />" ."$header\n\n\n</noinclude>$text<noinclude>\n$footer</noinclude>"; return array( -1, null, $new_text ); Modified: trunk/extensions/ProofreadPage/proofread.js =================================================================== --- trunk/extensions/ProofreadPage/proofread.js 2010-08-15 20:39:02 UTC (rev 71148) +++ trunk/extensions/ProofreadPage/proofread.js 2010-08-15 20:45:49 UTC (rev 71149) @@ -1,6 +1,10 @@ // Author : ThomasV - License : GPL +/* Default size of the high resolution image in edit mode */ +self.proofreadPageDefaultEditWidth = 1024; + + function pr_init_tabs(){ var a = document.getElementById("p-namespaces"); if(!a) a = document.getElementById("p-cactions"); @@ -9,10 +13,11 @@ var b = a.getElementsByTagName("ul"); if (!b) return; - if(self.proofreadPageViewURL) { + if( self.proofreadPageThumbURL ) { + var view_url = self.proofreadPageThumbURL.replace('##WIDTH##',"" + self.proofreadPageWidth ); b[0].innerHTML = b[0].innerHTML + '<li id="ca-image">' - + '<a href="' + escapeQuotesHTML(proofreadPageViewURL) + '"><span>' + + '<a href="' + escapeQuotesHTML( view_url ) + '"><span>' + escapeQuotesHTML(proofreadPageMessageImage) + '</span></a></li>'; } @@ -53,29 +58,20 @@ function pr_image_url(requested_width){ - var thumb_url; - if(self.proofreadPageExternalURL) { - thumb_url = proofreadPageViewURL; self.DisplayWidth = requested_width; self.DisplayHeight = ""; + return self.proofreadPageExternalURL; } else { //enforce quantization: width must be multiple of 100px var width = 100 * Math.round( requested_width /100 ); //compare to the width of the image - if(width < proofreadPageWidth) { - thumb_url = proofreadPageThumbURL.replace('##WIDTH##',""+width); - self.DisplayWidth = requested_width; - self.DisplayHeight = requested_width*proofreadPageHeight/proofreadPageWidth; - } - else { - thumb_url = proofreadPageViewURL; - self.DisplayWidth = proofreadPageWidth; - self.DisplayHeight = proofreadPageHeight; - } + width = Math.min( width, proofreadPageWidth ); + self.DisplayWidth = width; + self.DisplayHeight = width*proofreadPageHeight/proofreadPageWidth; + return proofreadPageThumbURL.replace( '##WIDTH##', "" + width ); } - return thumb_url; } @@ -368,7 +364,7 @@ //zoom using two images (magnification glass) function pr_initzoom(){ if(proofreadPageIsEdit) return; - if(!self.proofreadPageViewURL) return; + if( !self.proofreadPageThumbURL ) return; if(self.DisplayWidth>800) return; zp = document.getElementById("pr_container"); @@ -661,9 +657,9 @@ -function pr_load_image() { +function pr_load_image( view_url ) { pr_container.innerHTML = "<img id=\"ProofReadImage\" src=\"" - + escapeQuotesHTML(proofreadPageViewURL) + + escapeQuotesHTML( view_url ) + "\" width=\"" + img_width + "\" />"; } @@ -710,6 +706,9 @@ pr_container.appendChild(image); pr_container.style.cssText = "overflow:hidden;width:"+self.DisplayWidth+"px;"; } else { + var w = parseInt(self.proofreadPageEditWidth); + if( !w ) w = self.proofreadPageDefaultEditWidth; + var view_url = pr_image_url( Math.min( w, self.proofreadPageWidth ) ); //prevent the container from being resized once the image is downloaded. img_width = pr_horiz?0:parseInt(pr_width/2-70)-20; pr_container.onmousedown = pr_grab; @@ -717,7 +716,7 @@ if (pr_container.addEventListener) pr_container.addEventListener('DOMMouseScroll', pr_zoom_wheel, false); pr_container.onmousewheel = pr_zoom_wheel;//IE,Opera. - hookEvent( 'load', pr_load_image ); + hookEvent( 'load', function() { pr_load_image(view_url); } ); } table.setAttribute("id", "textBoxTable"); @@ -839,15 +838,14 @@ if(document.URL.indexOf("action=history") > 0 ) return; /*check if external url is provided*/ - if(!self.proofreadPageViewURL) { + if( !self.proofreadPageThumbURL ) { var text = document.getElementById("wpTextbox1"); if (text) { var proofreadPageIsEdit = true; re = /<span class="hiddenStructure" id="pageURL">\[http:\/\/(.*?)\]<\/span>/; m = re.exec(text.value); if( m ) { - self.proofreadPageViewURL = "http://"+m[1]; - self.proofreadPageExternalURL = true; + self.proofreadPageExternalURL = "http://"+m[1]; } } else { @@ -856,8 +854,7 @@ try { var a = document.getElementById("pageURL"); var b = a.firstChild; - self.proofreadPageViewURL = b.getAttribute("href"); - self.proofreadPageExternalURL = true; + self.proofreadPageExternalURL = b.getAttribute("href"); } catch(err){}; } //set to dummy values, not used @@ -865,7 +862,7 @@ self.proofreadPageHeight = 400; } - if(!self.proofreadPageViewURL) return; + if( !self.proofreadPageThumbURL ) return; if( self.proofreadpage_setup ) { _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs