Index: ProofreadPage_body.php =================================================================== --- ProofreadPage_body.php (wersja 95619) +++ ProofreadPage_body.php (kopia robocza) @@ -357,29 +357,32 @@ return true; } + $fileName = null; + $filePage = null; + $image = wfFindFile( $imageTitle ); if ( $image && $image->exists() ) { + $fileName = $imageTitle->getPrefixedText(); + $width = $image->getWidth(); $height = $image->getHeight(); if ( $m[2] ) { - $thumbName = $image->thumbName( array( 'width' => '##WIDTH##', 'page' => $m[3] ) ); - $thumbURL = $image->getThumbUrl( $thumbName ); - $thumbURL = str_replace( '%23', '#', $thumbURL ); - $fullURL = str_replace( '##WIDTH##', "$width", $thumbURL ); + $filePage = $m[3]; + + $thumbName = $image->thumbName( array( 'width' => $width, 'page' => $filePage ) ); + $fullURL = $image->getThumbUrl( $thumbName ); } else { - $thumbName = $image->thumbName( array( 'width' => '##WIDTH##' ) ); - $thumbURL = $image->getThumbUrl( $thumbName ); - $thumbURL = str_replace( '%23', '#', $thumbURL ); - $fullURL = $image->getURL(); + $fullURL = $image->getViewURL(); } - $scan_link = Html::element( 'a', - array( 'href' => $fullURL, - 'title' => wfMsg( 'proofreadpage_image' ) ), + $scan_link = Html::element( 'a', + array( 'href' => $fullURL, + 'title' => wfMsg( 'proofreadpage_image' ) ), wfMsg( 'proofreadpage_image' ) ); } else { $width = 0; $height = 0; - $thumbURL = ''; $fullURL = ''; $scan_link = ''; } @@ -395,12 +398,12 @@ array( 'title' => wfMsg( 'proofreadpage_nextpage' ) ) ) : ''; $prev_link = $prev_title ? $sk->link( $prev_title, - Html::element( 'img', array( 'src' => $path . '/leftarrow.png', - 'alt' => wfMsg( 'proofreadpage_prevpage' ), 'width' => 15, 'height' => 15 ) ), + Html::element( 'img', array( 'src' => $path . '/leftarrow.png', + 'alt' => wfMsg( 'proofreadpage_prevpage' ), 'width' => 15, 'height' => 15 ) ), array( 'title' => wfMsg( 'proofreadpage_prevpage' ) ) ): ''; $index_link = $index_title ? $sk->link( $index_title, - Html::element( 'img', array( 'src' => $path . '/uparrow.png', + Html::element( 'img', array( 'src' => $path . '/uparrow.png', 'alt' => wfMsg( 'proofreadpage_index' ), 'width' => 15, 'height' => 15 ) ), array( 'title' => wfMsg( 'proofreadpage_index' ) ) ) : ''; @@ -408,8 +411,9 @@ 'proofreadPageWidth' => intval( $width ), 'proofreadPageHeight' => intval( $height ), 'proofreadPageEditWidth' => $edit_width, - 'proofreadPageThumbURL' => $thumbURL, 'proofreadPageURL' => $fullURL, + 'proofreadPageFileName' => $fileName, + 'proofreadPageFilePage' => $filePage, 'proofreadPageIsEdit' => intval( $isEdit ), 'proofreadPageIndexLink' => $index_link, 'proofreadPageNextLink' => $next_link, Index: proofread.js =================================================================== --- proofread.js (wersja 95619) +++ proofread.js (kopia robocza) @@ -7,24 +7,58 @@ $( '#ca-talk' ).after( '
  • ' + self.proofreadPageScanLink + '
  • ' ); } -function pr_image_url( requested_width ) { - if( self.proofreadPageExternalURL ) { - self.DisplayWidth = requested_width; - self.DisplayHeight = ''; - return self.proofreadPageExternalURL; +function pr_fetch_thumb_url( requestedWidth, callback ) { + var fullWidth = mw.config.get( 'proofreadPageWidth' ); + var fullHeight = mw.config.get( 'proofreadPageHeight' ); + + // enforce quantization: width must be multiple of 100px + var quantizedWidth = 100 * Math.round( requestedWidth / 100 ); + + // compare to the width of the image + if( quantizedWidth < fullWidth ) { + // Send request to fetch a thumbnail url + var request = { + action: 'query', + titles: mw.config.get( 'proofreadPageFileName' ), + prop: 'imageinfo', + iiprop: 'url|size', + iiurlwidth: quantizedWidth, + format: 'json' + }; + + // Check if this is multipaged document + if( mw.config.get( 'proofreadPageFilePage' ) != null ) { + request['iiurlparam'] = 'page' + mw.config.get( 'proofreadPageFilePage' ) + '-' + quantizedWidth + 'px'; + } + + $.getJSON( mw.util.wikiScript( 'api' ) ,request, function(data) { + if( data && data.query && data.query.pages ) { + for( var i in data.query.pages ) { + var page = data.query.pages[i]; + if( !page.imageinfo || page.imageinfo.length < 1 ) { + continue; + } + var imageinfo = page.imageinfo[0]; + + if( !imageinfo.thumburl ) { + // Unable to fetch a thumbnail, use the image without scaling and lie about its size + // This works only for non-paged files though + if ( mw.config.get( 'proofreadPageFilePage' ) == null ) { + height = ( quantizedWidth / fullWidth ) * fullHeight; + callback( imageinfo.url, quantizedWidth, height ); + } + } + else { + callback( imageinfo.thumburl, imageinfo.thumbwidth, imageinfo.thumbheight ); + } + + return; + } + } + }); } 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 ) { - self.DisplayWidth = width; - self.DisplayHeight = width * proofreadPageHeight / proofreadPageWidth; - return proofreadPageThumbURL.replace( '##WIDTH##', '' + width ); - } else { - self.DisplayWidth = proofreadPageWidth; - self.DisplayHeight = proofreadPageHeight; - return proofreadPageURL; - } + // Image without scaling + callback( mw.config.get( 'proofreadPageURL' ), fullWidth, fullHeight ); } } @@ -317,35 +351,32 @@ return false; } +//zoom using two images (magnification glass) +function pr_initzoom( width, height ) { + var maxWidth = 800; -//zoom using two images (magnification glass) -function pr_initzoom() { - if( proofreadPageIsEdit ) { + if( width > maxWidth ) { return; } - if( !self.proofreadPageThumbURL ) { + + zp = document.getElementById( 'pr_container' ); + if( !zp ) { return; } - if( self.DisplayWidth > 800 ) { - return; - } + pr_fetch_thumb_url( maxWidth, function( largeUrl, largeWidth, largeHeight ) { + self.objw = width; + self.objh = height; - zp = document.getElementById( 'pr_container' ); - if( zp ) { - var hires_url = pr_image_url( 800 ); - self.objw = zp.firstChild.width; - self.objh = zp.firstChild.height; - zp.onmouseup = zoom_mouseup; zp.onmousemove = zoom_move; zp_container = document.createElement( 'div' ); zp_container.style.cssText = 'position:absolute; width:0; height:0; overflow:hidden;'; zp_clip = document.createElement( 'img' ); - zp_clip.setAttribute( 'src', hires_url ); + zp_clip.setAttribute( 'src', largeUrl ); zp_clip.style.cssText = 'padding:0;margin:0;border:0;'; zp_container.appendChild( zp_clip ); zp.insertBefore( zp_container, zp.firstChild ); - } + } ); } /******************************** @@ -620,6 +651,7 @@ if( !pr_horiz ) { // use a table only here var t_table = document.createElement( 'table' ); + t_table.style.width = '100%'; var t_body = document.createElement( 'tbody' ); var cell_left = document.createElement( 'td' ); var cell_right = document.createElement( 'td' ); @@ -666,9 +698,9 @@ pr_zoom( 0 ); } -function pr_load_image( ) { +function pr_load_image( url ) { pr_container.innerHTML = ''; + escapeQuotesHTML( url ) + '" width="' + img_width + '" />'; pr_zoom( 0 ); } @@ -704,15 +736,16 @@ // fill the image container if( !proofreadPageIsEdit ) { - // this sets DisplayWidth and DisplayHeight - var thumb_url = pr_image_url( parseInt( pr_width / 2 - 70 ) ); - var image = document.createElement( 'img' ); - image.setAttribute( 'id', 'ProofReadImage' ); - image.setAttribute( 'src', thumb_url ); - image.setAttribute( 'width', self.DisplayWidth ); - image.style.cssText = 'padding:0;margin:0;border:0;'; - pr_container.appendChild( image ); - pr_container.style.cssText = 'overflow:hidden;width:' + self.DisplayWidth + 'px;'; + pr_fetch_thumb_url( parseInt( pr_width / 2 - 70 ), function( url, width, height ) { + var image = document.createElement( 'img' ); + image.setAttribute( 'id', 'ProofReadImage' ); + image.setAttribute( 'src', url ); + image.setAttribute( 'width', width ); + image.style.cssText = 'padding:0;margin:0;border:0;'; + pr_container.appendChild( image ); + pr_container.style.cssText = 'overflow:hidden;width:' + width + 'px;'; + pr_initzoom( width, height ); + } ); } else { var w = parseInt( self.proofreadPageEditWidth ); if( !w ) { @@ -721,17 +754,20 @@ if( !w ) { w = 1024; /* Default size in edit mode */ } - self.proofreadPageViewURL = 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; pr_container.onmousemove = pr_move; - if ( pr_container.addEventListener ) { + if( pr_container.addEventListener ) { pr_container.addEventListener( 'DOMMouseScroll', pr_zoom_wheel, false ); } pr_container.onmousewheel = pr_zoom_wheel; // IE, Opera. - /* Load the image after page setup, so that user-defined hooks do not have to wait for it. */ - hookEvent( 'load', pr_load_image ); + + pr_fetch_thumb_url( Math.min( w, self.proofreadPageWidth ), function( url, width, height ) { + // Load the image after page setup, so that user-defined hooks do not have to wait for it. + $( document ).ready( function() { pr_load_image( url ) } ); + } ); } table.setAttribute( 'id', 'textBoxTable' ); @@ -909,42 +945,20 @@ return; } - /* check if external URL is provided */ - if( !self.proofreadPageThumbURL ) { - var text = document.getElementById( 'wpTextbox1' ); - if ( text ) { - var proofreadPageIsEdit = true; - re = /\[http:\/\/(.*?)\]<\/span>/; - m = re.exec( text.value ); - if( m ) { - self.proofreadPageExternalURL = 'http://' + m[1]; - } - } else { - var proofreadPageIsEdit = false; - text = document.getElementById( 'bodyContent' ); - try { - var a = document.getElementById( 'pageURL' ); - var b = a.firstChild; - self.proofreadPageExternalURL = b.getAttribute( 'href' ); - } catch( err ) { - }; - } - // set to dummy values, not used - self.proofreadPageWidth = 400; - self.proofreadPageHeight = 400; - } - - if( !self.proofreadPageThumbURL ) { + if( mw.config.get( 'proofreadPageFileName' ) == null ) { + // File does not exist return; } if( self.proofreadpage_setup ) { + // Run site/user setup code proofreadpage_setup( proofreadPageWidth, proofreadPageHeight, proofreadPageIsEdit ); } else { + // Run extension setup code pr_setup(); } @@ -956,7 +970,6 @@ $(document).ready( pr_init ); $(document).ready( pr_init_tabs ); -$(document).ready( pr_initzoom ); /* Quality buttons */