r71149 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71148‎ | r71149 | r71150 >
Date:20:45, 15 August 2010
Author:thomasv
Status:ok
Tags:
Comment:
make image width in edit mode configurable from the index page.
Modified paths:
  • /trunk/extensions/ProofreadPage/ProofreadPage.php (modified) (history)
  • /trunk/extensions/ProofreadPage/proofread.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ProofreadPage/ProofreadPage.php
@@ -37,9 +37,6 @@
3838 # Group allowed to modify pagequality
3939 $wgGroupPermissions['user']['pagequality'] = true;
4040
41 -# Max width of zoomable image
42 -$wgProofreadPageMaxWidth = 2048;
43 -
4441 $wgExtensionCredits['other'][] = array(
4542 'path' => __FILE__,
4643 'name' => 'ProofreadPage',
@@ -232,8 +229,9 @@
233230 $footer = str_replace( "{{{{$key}}}}", $val, $footer );
234231 }
235232 $css = $attributes['css'] ? $attributes['css'] : "";
 233+ $edit_width = $attributes['width'] ? $attributes['width'] : "";
236234
237 - return array( $index_url, $prev_url, $next_url, $header, $footer, $css );
 235+ return array( $index_url, $prev_url, $next_url, $header, $footer, $css, $edit_width );
238236
239237 }
240238
@@ -394,37 +392,27 @@
395393 if ( $image && $image->exists() ) {
396394 $width = $image->getWidth();
397395 $height = $image->getHeight();
398 - if( $width > $wgProofreadPageMaxWidth ) {
399 - $width = $wgProofreadPageMaxWidth;
400 - $height = $image->getHeight() * $wgProofreadPageMaxWidth / $image->getWidth();
401 - }
402396 if ( $m[2] ) {
403 - $viewName = $image->thumbName( array( 'width' => $width, 'page' => $m[3] ) );
404 - $viewURL = $image->getThumbUrl( $viewName );
405 -
406397 $thumbName = $image->thumbName( array( 'width' => '##WIDTH##', 'page' => $m[3] ) );
407 - $thumbURL = $image->getThumbUrl( $thumbName );
408398 } else {
409 - $viewURL = $image->getViewURL();
410399 $thumbName = $image->thumbName( array( 'width' => '##WIDTH##' ) );
411 - $thumbURL = $image->getThumbUrl( $thumbName );
412400 }
 401+ $thumbURL = $image->getThumbUrl( $thumbName );
413402 $thumbURL = str_replace( '%23', '#', $thumbURL );
414403 } else {
415404 $width = 0;
416405 $height = 0;
417 - $viewURL = '';
418406 $thumbURL = '';
419407 }
420408
421 - list( $index_url, $prev_url, $next_url, $header, $footer, $css ) = pr_navigation( $wgTitle );
 409+ list( $index_url, $prev_url, $next_url, $header, $footer, $css, $edit_width ) = pr_navigation( $wgTitle );
422410
423411 $jsFile = htmlspecialchars( "$wgScriptPath/extensions/ProofreadPage/proofread.js?$wgProofreadPageVersion" );
424412
425413 $jsVars = array(
426414 'proofreadPageWidth' => intval( $width ),
427415 'proofreadPageHeight' => intval( $height ),
428 - 'proofreadPageViewURL' => $viewURL,
 416+ 'proofreadPageEditWidth' => $edit_width,
429417 'proofreadPageThumbURL' => $thumbURL,
430418 'proofreadPageIsEdit' => intval( $isEdit ),
431419 'proofreadPageIndexURL' => $index_url,
@@ -893,7 +881,7 @@
894882 $page_regexp = "/^<noinclude>(.*?)<\/noinclude>(.*?)<noinclude>(.*?)<\/noinclude>$/s";
895883 if( !preg_match( $page_regexp, $text, $m ) ) {
896884 pr_load_index( $wgTitle );
897 - list( $index_url, $prev_url, $next_url, $header, $footer, $css ) = pr_navigation( $wgTitle );
 885+ list( $index_url, $prev_url, $next_url, $header, $footer, $css, $edit_width ) = pr_navigation( $wgTitle );
898886 $new_text = "<noinclude><pagequality level=\"1\" user=\"$username\" />"
899887 ."$header\n\n\n</noinclude>$text<noinclude>\n$footer</noinclude>";
900888 return array( -1, null, $new_text );
Index: trunk/extensions/ProofreadPage/proofread.js
@@ -1,6 +1,10 @@
22 // Author : ThomasV - License : GPL
33
44
 5+/* Default size of the high resolution image in edit mode */
 6+self.proofreadPageDefaultEditWidth = 1024;
 7+
 8+
59 function pr_init_tabs(){
610 var a = document.getElementById("p-namespaces");
711 if(!a) a = document.getElementById("p-cactions");
@@ -9,10 +13,11 @@
1014 var b = a.getElementsByTagName("ul");
1115 if (!b) return;
1216
13 - if(self.proofreadPageViewURL) {
 17+ if( self.proofreadPageThumbURL ) {
 18+ var view_url = self.proofreadPageThumbURL.replace('##WIDTH##',"" + self.proofreadPageWidth );
1419 b[0].innerHTML = b[0].innerHTML
1520 + '<li id="ca-image">'
16 - + '<a href="' + escapeQuotesHTML(proofreadPageViewURL) + '"><span>'
 21+ + '<a href="' + escapeQuotesHTML( view_url ) + '"><span>'
1722 + escapeQuotesHTML(proofreadPageMessageImage) + '</span></a></li>';
1823 }
1924
@@ -53,29 +58,20 @@
5459
5560
5661 function pr_image_url(requested_width){
57 - var thumb_url;
58 -
5962 if(self.proofreadPageExternalURL) {
60 - thumb_url = proofreadPageViewURL;
6163 self.DisplayWidth = requested_width;
6264 self.DisplayHeight = "";
 65+ return self.proofreadPageExternalURL;
6366 }
6467 else {
6568 //enforce quantization: width must be multiple of 100px
6669 var width = 100 * Math.round( requested_width /100 );
6770 //compare to the width of the image
68 - if(width < proofreadPageWidth) {
69 - thumb_url = proofreadPageThumbURL.replace('##WIDTH##',""+width);
70 - self.DisplayWidth = requested_width;
71 - self.DisplayHeight = requested_width*proofreadPageHeight/proofreadPageWidth;
72 - }
73 - else {
74 - thumb_url = proofreadPageViewURL;
75 - self.DisplayWidth = proofreadPageWidth;
76 - self.DisplayHeight = proofreadPageHeight;
77 - }
 71+ width = Math.min( width, proofreadPageWidth );
 72+ self.DisplayWidth = width;
 73+ self.DisplayHeight = width*proofreadPageHeight/proofreadPageWidth;
 74+ return proofreadPageThumbURL.replace( '##WIDTH##', "" + width );
7875 }
79 - return thumb_url;
8076 }
8177
8278
@@ -368,7 +364,7 @@
369365 //zoom using two images (magnification glass)
370366 function pr_initzoom(){
371367 if(proofreadPageIsEdit) return;
372 - if(!self.proofreadPageViewURL) return;
 368+ if( !self.proofreadPageThumbURL ) return;
373369 if(self.DisplayWidth>800) return;
374370
375371 zp = document.getElementById("pr_container");
@@ -661,9 +657,9 @@
662658
663659
664660
665 -function pr_load_image() {
 661+function pr_load_image( view_url ) {
666662 pr_container.innerHTML = "<img id=\"ProofReadImage\" src=\""
667 - + escapeQuotesHTML(proofreadPageViewURL)
 663+ + escapeQuotesHTML( view_url )
668664 + "\" width=\"" + img_width + "\" />";
669665 }
670666
@@ -710,6 +706,9 @@
711707 pr_container.appendChild(image);
712708 pr_container.style.cssText = "overflow:hidden;width:"+self.DisplayWidth+"px;";
713709 } else {
 710+ var w = parseInt(self.proofreadPageEditWidth);
 711+ if( !w ) w = self.proofreadPageDefaultEditWidth;
 712+ var view_url = pr_image_url( Math.min( w, self.proofreadPageWidth ) );
714713 //prevent the container from being resized once the image is downloaded.
715714 img_width = pr_horiz?0:parseInt(pr_width/2-70)-20;
716715 pr_container.onmousedown = pr_grab;
@@ -717,7 +716,7 @@
718717 if (pr_container.addEventListener)
719718 pr_container.addEventListener('DOMMouseScroll', pr_zoom_wheel, false);
720719 pr_container.onmousewheel = pr_zoom_wheel;//IE,Opera.
721 - hookEvent( 'load', pr_load_image );
 720+ hookEvent( 'load', function() { pr_load_image(view_url); } );
722721 }
723722
724723 table.setAttribute("id", "textBoxTable");
@@ -839,15 +838,14 @@
840839 if(document.URL.indexOf("action=history") > 0 ) return;
841840
842841 /*check if external url is provided*/
843 - if(!self.proofreadPageViewURL) {
 842+ if( !self.proofreadPageThumbURL ) {
844843 var text = document.getElementById("wpTextbox1");
845844 if (text) {
846845 var proofreadPageIsEdit = true;
847846 re = /<span class="hiddenStructure" id="pageURL">\[http:\/\/(.*?)\]<\/span>/;
848847 m = re.exec(text.value);
849848 if( m ) {
850 - self.proofreadPageViewURL = "http://"+m[1];
851 - self.proofreadPageExternalURL = true;
 849+ self.proofreadPageExternalURL = "http://"+m[1];
852850 }
853851 }
854852 else {
@@ -856,8 +854,7 @@
857855 try {
858856 var a = document.getElementById("pageURL");
859857 var b = a.firstChild;
860 - self.proofreadPageViewURL = b.getAttribute("href");
861 - self.proofreadPageExternalURL = true;
 858+ self.proofreadPageExternalURL = b.getAttribute("href");
862859 } catch(err){};
863860 }
864861 //set to dummy values, not used
@@ -865,7 +862,7 @@
866863 self.proofreadPageHeight = 400;
867864 }
868865
869 - if(!self.proofreadPageViewURL) return;
 866+ if( !self.proofreadPageThumbURL ) return;
870867
871868 if( self.proofreadpage_setup ) {
872869

Status & tagging log