r95613 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95612‎ | r95613 | r95614 >
Date:02:05, 28 August 2011
Author:johnduhart
Status:ok
Tags:
Comment:
Reverting r95602 per CR
Modified paths:
  • /trunk/extensions/ProofreadPage/ProofreadPage_body.php (modified) (history)
  • /trunk/extensions/ProofreadPage/proofread.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ProofreadPage/ProofreadPage_body.php
@@ -75,7 +75,7 @@
7676
7777 /**
7878 * Set up our custom parser hooks when initializing parser.
79 - *
 79+ *
8080 * @param Parser $parser
8181 * @return boolean hook return value
8282 */
@@ -324,7 +324,7 @@
325325 return true;
326326 }
327327
328 - if ( $isEdit && $out->getTitle()->getNamespace() == self::getIndexNamespaceId() ) {
 328+ if ( $isEdit && ( preg_match( "/^$index_namespace:(.*?)(\/([0-9]*)|)$/", $out->getTitle()->getPrefixedText(), $m ) ) ) {
329329 self::prepareIndex( $out );
330330 return true;
331331 }
@@ -339,13 +339,10 @@
340340
341341 private static function prepareIndex( $out ) {
342342 $out->addModules( 'ext.proofreadpage.index' );
343 -
344 - $jsVars = array(
345 - 'prp_index_attributes' => wfMsgForContent( 'proofreadpage_index_attributes' ),
346 - 'prp_default_header' => wfMsgForContentNoTrans( 'proofreadpage_default_header' ),
347 - 'prp_default_footer' => wfMsgForContentNoTrans( 'proofreadpage_default_footer' ),
348 - );
349 - $out->addInlineScript( ResourceLoader::makeConfigSetScript( $jsVars ) );
 343+ $out->addInlineScript("
 344+var prp_index_attributes = \"" . Xml::escapeJsString( wfMsgForContent( 'proofreadpage_index_attributes' ) ) . "\";
 345+var prp_default_header = \"" . Xml::escapeJsString( wfMsgForContentNoTrans( 'proofreadpage_default_header' ) ) . "\";
 346+var prp_default_footer = \"" . Xml::escapeJsString( wfMsgForContentNoTrans( 'proofreadpage_default_footer' ) ) . "\";" );
350347 }
351348
352349 private static function preparePage( $out, $m, $isEdit ) {
@@ -360,32 +357,31 @@
361358 return true;
362359 }
363360
364 - $fileName = null;
365 - $filePage = null;
366 - $fileWidth = 0;
367 - $fileHeight = 0;
368 - $fileFullUrl = null;
369 - $scanLink = null;
370 -
371361 $image = wfFindFile( $imageTitle );
372 -
373362 if ( $image && $image->exists() ) {
374 - $fileName = $imageTitle->getPrefixedText();
375 - $fileWidth = $image->getWidth();
376 - $fileHeight = $image->getHeight();
377 -
 363+ $width = $image->getWidth();
 364+ $height = $image->getHeight();
378365 if ( $m[2] ) {
379 - $filePage = $m[3];
380 -
381 - $thumbName = $image->thumbName( array( 'width' => $fileWidth, 'page' => $filePage ) );
382 - $fileFullUrl = $image->getThumbUrl( $thumbName );
 366+ $thumbName = $image->thumbName( array( 'width' => '##WIDTH##', 'page' => $m[3] ) );
 367+ $thumbURL = $image->getThumbUrl( $thumbName );
 368+ $thumbURL = str_replace( '%23', '#', $thumbURL );
 369+ $fullURL = str_replace( '##WIDTH##', "$width", $thumbURL );
383370 } else {
384 - $fileFullUrl = $image->getViewURL();
 371+ $thumbName = $image->thumbName( array( 'width' => '##WIDTH##' ) );
 372+ $thumbURL = $image->getThumbUrl( $thumbName );
 373+ $thumbURL = str_replace( '%23', '#', $thumbURL );
 374+ $fullURL = $image->getURL();
385375 }
386 - $scanLink = Html::element( 'a',
387 - array( 'href' => $fileFullUrl,
388 - 'title' => wfMsg( 'proofreadpage_image' ) ),
 376+ $scan_link = Html::element( 'a',
 377+ array( 'href' => $fullURL,
 378+ 'title' => wfMsg( 'proofreadpage_image' ) ),
389379 wfMsg( 'proofreadpage_image' ) );
 380+ } else {
 381+ $width = 0;
 382+ $height = 0;
 383+ $thumbURL = '';
 384+ $fullURL = '';
 385+ $scan_link = '';
390386 }
391387
392388 list( $index_title, $prev_title, $next_title, $header, $footer, $css, $edit_width ) = self::navigation( $out->getTitle() );
@@ -393,33 +389,32 @@
394390 $sk = $wgUser->getSkin();
395391 $path = $wgExtensionAssetsPath . '/ProofreadPage';
396392
397 - $nextLink = $next_title ? $sk->link( $next_title,
 393+ $next_link = $next_title ? $sk->link( $next_title,
398394 Html::element( 'img', array( 'src' => $path . '/rightarrow.png',
399395 'alt' => wfMsg( 'proofreadpage_nextpage' ), 'width' => 15, 'height' => 15 ) ),
400 - array( 'title' => wfMsg( 'proofreadpage_nextpage' ) ) ) : null;
 396+ array( 'title' => wfMsg( 'proofreadpage_nextpage' ) ) ) : '';
401397
402 - $prevLink = $prev_title ? $sk->link( $prev_title,
403 - Html::element( 'img', array( 'src' => $path . '/leftarrow.png',
404 - 'alt' => wfMsg( 'proofreadpage_prevpage' ), 'width' => 15, 'height' => 15 ) ),
405 - array( 'title' => wfMsg( 'proofreadpage_prevpage' ) ) ): null;
 398+ $prev_link = $prev_title ? $sk->link( $prev_title,
 399+ Html::element( 'img', array( 'src' => $path . '/leftarrow.png',
 400+ 'alt' => wfMsg( 'proofreadpage_prevpage' ), 'width' => 15, 'height' => 15 ) ),
 401+ array( 'title' => wfMsg( 'proofreadpage_prevpage' ) ) ): '';
406402
407 - $indexLink = $index_title ? $sk->link( $index_title,
408 - Html::element( 'img', array( 'src' => $path . '/uparrow.png',
 403+ $index_link = $index_title ? $sk->link( $index_title,
 404+ Html::element( 'img', array( 'src' => $path . '/uparrow.png',
409405 'alt' => wfMsg( 'proofreadpage_index' ), 'width' => 15, 'height' => 15 ) ),
410 - array( 'title' => wfMsg( 'proofreadpage_index' ) ) ) : null;
 406+ array( 'title' => wfMsg( 'proofreadpage_index' ) ) ) : '';
411407
412408 $jsVars = array(
413 - 'proofreadPageWidth' => intval( $fileWidth ),
414 - 'proofreadPageHeight' => intval( $fileHeight ),
 409+ 'proofreadPageWidth' => intval( $width ),
 410+ 'proofreadPageHeight' => intval( $height ),
415411 'proofreadPageEditWidth' => $edit_width,
416 - 'proofreadPageURL' => $fileFullUrl,
417 - 'proofreadPageFileName' => $fileName,
418 - 'proofreadPageFilePage' => $filePage,
 412+ 'proofreadPageThumbURL' => $thumbURL,
 413+ 'proofreadPageURL' => $fullURL,
419414 'proofreadPageIsEdit' => intval( $isEdit ),
420 - 'proofreadPageIndexLink' => $indexLink,
421 - 'proofreadPageNextLink' => $nextLink,
422 - 'proofreadPagePrevLink' => $prevLink,
423 - 'proofreadPageScanLink' => $scanLink,
 415+ 'proofreadPageIndexLink' => $index_link,
 416+ 'proofreadPageNextLink' => $next_link,
 417+ 'proofreadPagePrevLink' => $prev_link,
 418+ 'proofreadPageScanLink' => $scan_link,
424419 'proofreadPageHeader' => $header,
425420 'proofreadPageFooter' => $footer,
426421 'proofreadPageAddButtons' => $wgUser->isAllowed( 'pagequality' ),
@@ -857,7 +852,7 @@
858853 null,
859854 array( 'categorylinks' => array( 'LEFT JOIN', 'cl_from=page_id' ) )
860855 );
861 -
 856+
862857 if( $res ) {
863858 foreach ( $res as $o ) {
864859 array_push( $q0_pages, $o->page_title );
@@ -1549,7 +1544,7 @@
15501545 if( $indextitle ) {
15511546 $sk = $wgUser->getSkin();
15521547 $nt = Title::makeTitleSafe( $index_ns_index, $indextitle );
1553 - $indexlink = $sk->link( $nt, wfMsg( 'proofreadpage_source' ),
 1548+ $indexlink = $sk->link( $nt, wfMsg( 'proofreadpage_source' ),
15541549 array( 'title' => wfMsg( 'proofreadpage_source_message' ) ) );
15551550 $out->addInlineScript( ResourceLoader::makeConfigSetScript( array( 'proofreadpage_source_href' => $indexlink ) ) );
15561551 $out->addModules( 'ext.proofreadpage.article' );
Index: trunk/extensions/ProofreadPage/proofread.js
@@ -1,70 +1,30 @@
22 // Author : ThomasV - License : GPL
33
44 function pr_init_tabs() {
5 - if( mw.config.get( 'proofreadPagePrevLink' ) != null ) {
6 - $( '#ca-talk' ).prev().before( '<li id="ca-prev"><span>' + mw.config.get( 'proofreadPagePrevLink' ) + '</span></li>' );
7 - }
8 - if( mw.config.get( 'proofreadPageNextLink' ) != null ) {
9 - $( '#ca-talk' ).prev().before( '<li id="ca-next"><span>' + mw.config.get( 'proofreadPageNextLink' ) + '</span></li>' );
10 - }
11 - if( mw.config.get( 'proofreadPageIndexLink' ) != null ) {
12 - $( '#ca-talk' ).after( '<li id="ca-index"><span>' + mw.config.get( 'proofreadPageIndexLink' ) + '</span></li>' );
13 - }
14 - if( mw.config.get( 'proofreadPageScanLink' ) != null ) {
15 - $( '#ca-talk' ).after( '<li id="ca-image"><span>' + mw.config.get( 'proofreadPageScanLink' ) + '</span></li>' );
16 - }
 5+ $( '#ca-talk' ).prev().before( '<li id="ca-prev"><span>' + self.proofreadPagePrevLink + '</span></li>' );
 6+ $( '#ca-talk' ).prev().before( '<li id="ca-next"><span>' + self.proofreadPageNextLink + '</span></li>' );
 7+ $( '#ca-talk' ).after( '<li id="ca-index"><span>' + self.proofreadPageIndexLink + '</span></li>' );
 8+ $( '#ca-talk' ).after( '<li id="ca-image"><span>' + self.proofreadPageScanLink + '</span></li>' );
179 }
1810
19 -function pr_fetch_thumb_url( requestedWidth, callback ) {
20 - var fullWidth = mw.config.get( 'proofreadPageWidth' );
21 - var fullHeight = mw.config.get( 'proofreadPageHeight' );
22 -
23 - // enforce quantization: width must be multiple of 100px
24 - var quantizedWidth = 100 * Math.round( requestedWidth / 100 );
25 -
26 - // compare to the width of the image
27 - if( quantizedWidth < fullWidth ) {
28 - // Send request to fetch thumbnail url
29 - var request = {
30 - action: 'query',
31 - titles: mw.config.get( 'proofreadPageFileName' ),
32 - prop: 'imageinfo',
33 - iiprop: 'url|size',
34 - iiurlwidth: quantizedWidth,
35 - format: 'json'
36 - };
37 -
38 - if( mw.config.get( 'proofreadPageFilePage' ) != null ) {
39 - request['iiurlparam'] = 'page' + mw.config.get( 'proofreadPageFilePage' ) + '-' + quantizedWidth + 'px';
40 - }
41 -
42 - $.getJSON( mw.util.wikiScript( 'api' ) ,request, function(data) {
43 - if( data && data.query && data.query.pages ) {
44 - for( var i in data.query.pages ) {
45 - var page = data.query.pages[i];
46 - if( !page.imageinfo || page.imageinfo.length < 1 ) {
47 - continue;
48 - }
49 - var imageinfo = page.imageinfo[0];
50 -
51 - if( !imageinfo.thumburl ) {
52 - // Unable to fetch thumbnail, use image without scaling
53 - // This works only for non-paged files and may mess up the layout of the page
54 - if ( mw.config.get( 'proofreadPageFilePage' ) == null ) {
55 - callback( imageinfo.url, imageinfo.width, imageinfo.height );
56 - }
57 - }
58 - else {
59 - callback( imageinfo.thumburl, imageinfo.thumbwidth, imageinfo.thumbheight );
60 - }
61 -
62 - return;
63 - }
64 - }
65 - });
 11+function pr_image_url( requested_width ) {
 12+ if( self.proofreadPageExternalURL ) {
 13+ self.DisplayWidth = requested_width;
 14+ self.DisplayHeight = '';
 15+ return self.proofreadPageExternalURL;
6616 } else {
67 - // Image without scaling
68 - callback( mw.config.get( 'proofreadPageURL' ), fullWidth, fullHeight );
 17+ // enforce quantization: width must be multiple of 100px
 18+ var width = 100 * Math.round( requested_width / 100 );
 19+ // compare to the width of the image
 20+ if( width < proofreadPageWidth ) {
 21+ self.DisplayWidth = width;
 22+ self.DisplayHeight = width * proofreadPageHeight / proofreadPageWidth;
 23+ return proofreadPageThumbURL.replace( '##WIDTH##', '' + width );
 24+ } else {
 25+ self.DisplayWidth = proofreadPageWidth;
 26+ self.DisplayHeight = proofreadPageHeight;
 27+ return proofreadPageURL;
 28+ }
6929 }
7030 }
7131
@@ -130,7 +90,7 @@
13191 }
13292 self.proofreadpage_username = m4[2];
13393 pageHeader = pageHeader.replace( reg, '' );
134 - } else if( old_m4 ) {
 94+ } else if ( old_m4 ) {
13595 switch( old_m4[1] ) {
13696 case '0':
13797 self.proofreadpage_quality = 0;
@@ -182,7 +142,6 @@
183143 var box = document.getElementById( 'wpTextbox1' );
184144 var h = document.getElementById( 'prp_header' );
185145 var f = document.getElementById( 'prp_footer' );
186 -
187146 if( h.style.cssText == 'display:none;' ) {
188147 box.style.cssText = 'height:' + ( self.DisplayHeight - 6 ) + 'px';
189148 } else {
@@ -358,32 +317,35 @@
359318 return false;
360319 }
361320
362 -//zoom using two images (magnification glass)
363 -function pr_initzoom( width, height ) {
364 - var maxWidth = 800;
365321
366 - if( width > maxWidth ) {
 322+//zoom using two images (magnification glass)
 323+function pr_initzoom() {
 324+ if( proofreadPageIsEdit ) {
367325 return;
368326 }
369 -
370 - zp = document.getElementById( 'pr_container' );
371 - if( !zp ) {
 327+ if( !self.proofreadPageThumbURL ) {
372328 return;
373329 }
374 - pr_fetch_thumb_url( maxWidth, function( largeUrl, largeWidth, largeHeight ) {
375 - self.objw = width;
376 - self.objh = height;
 330+ if( self.DisplayWidth > 800 ) {
 331+ return;
 332+ }
377333
 334+ zp = document.getElementById( 'pr_container' );
 335+ if( zp ) {
 336+ var hires_url = pr_image_url( 800 );
 337+ self.objw = zp.firstChild.width;
 338+ self.objh = zp.firstChild.height;
 339+
378340 zp.onmouseup = zoom_mouseup;
379341 zp.onmousemove = zoom_move;
380342 zp_container = document.createElement( 'div' );
381343 zp_container.style.cssText = 'position:absolute; width:0; height:0; overflow:hidden;';
382344 zp_clip = document.createElement( 'img' );
383 - zp_clip.setAttribute( 'src', largeUrl );
 345+ zp_clip.setAttribute( 'src', hires_url );
384346 zp_clip.style.cssText = 'padding:0;margin:0;border:0;';
385347 zp_container.appendChild( zp_clip );
386348 zp.insertBefore( zp_container, zp.firstChild );
387 - } );
 349+ }
388350 }
389351
390352 /********************************
@@ -570,7 +532,7 @@
571533 boxHeight + 'px;background:#000000;';
572534 }
573535 }
574 - if( evt.preventDefault ) {
 536+ if ( evt.preventDefault ) {
575537 evt.preventDefault();
576538 }
577539 evt.returnValue = false;
@@ -594,7 +556,7 @@
595557 }
596558
597559 self.pr_zoom = function( delta ) {
598 - if( delta == 0 ) {
 560+ if ( delta == 0 ) {
599561 // reduce width by 20 pixels in order to prevent horizontal scrollbar
600562 // from showing up
601563 pr_set_margins( 0, 0, pr_container.offsetWidth - 20 );
@@ -625,10 +587,10 @@
626588 return false;
627589 }
628590 var delta = 0;
629 - if( evt.wheelDelta ) {
 591+ if ( evt.wheelDelta ) {
630592 /* IE/Opera. */
631593 delta = evt.wheelDelta / 120;
632 - } else if( evt.detail ) {
 594+ } else if ( evt.detail ) {
633595 /**
634596 * Mozilla case.
635597 * In Mozilla, sign of delta is different than in IE.
@@ -704,9 +666,9 @@
705667 pr_zoom( 0 );
706668 }
707669
708 -function pr_load_image( url ) {
 670+function pr_load_image( ) {
709671 pr_container.innerHTML = '<img id="ProofReadImage" src="' +
710 - escapeQuotesHTML( url ) + '" width="' + img_width + '" />';
 672+ escapeQuotesHTML( self.proofreadPageViewURL ) + '" width="' + img_width + '" />';
711673 pr_zoom( 0 );
712674 }
713675
@@ -742,16 +704,15 @@
743705
744706 // fill the image container
745707 if( !proofreadPageIsEdit ) {
746 - pr_fetch_thumb_url( parseInt( pr_width / 2 - 70 ), function( url, width, height ) {
747 - var image = document.createElement( 'img' );
748 - image.setAttribute( 'id', 'ProofReadImage' );
749 - image.setAttribute( 'src', url );
750 - image.setAttribute( 'width', width );
751 - image.style.cssText = 'padding:0;margin:0;border:0;';
752 - pr_container.appendChild( image );
753 - pr_container.style.cssText = 'overflow:hidden;width:' + width + 'px;';
754 - pr_initzoom( width, height );
755 - } );
 708+ // this sets DisplayWidth and DisplayHeight
 709+ var thumb_url = pr_image_url( parseInt( pr_width / 2 - 70 ) );
 710+ var image = document.createElement( 'img' );
 711+ image.setAttribute( 'id', 'ProofReadImage' );
 712+ image.setAttribute( 'src', thumb_url );
 713+ image.setAttribute( 'width', self.DisplayWidth );
 714+ image.style.cssText = 'padding:0;margin:0;border:0;';
 715+ pr_container.appendChild( image );
 716+ pr_container.style.cssText = 'overflow:hidden;width:' + self.DisplayWidth + 'px;';
756717 } else {
757718 var w = parseInt( self.proofreadPageEditWidth );
758719 if( !w ) {
@@ -760,20 +721,17 @@
761722 if( !w ) {
762723 w = 1024; /* Default size in edit mode */
763724 }
764 -
 725+ self.proofreadPageViewURL = pr_image_url( Math.min( w, self.proofreadPageWidth ) );
765726 // prevent the container from being resized once the image is downloaded.
766727 img_width = pr_horiz ? 0 : parseInt( pr_width / 2 - 70 ) - 20;
767728 pr_container.onmousedown = pr_grab;
768729 pr_container.onmousemove = pr_move;
769 - if( pr_container.addEventListener ) {
 730+ if ( pr_container.addEventListener ) {
770731 pr_container.addEventListener( 'DOMMouseScroll', pr_zoom_wheel, false );
771732 }
772733 pr_container.onmousewheel = pr_zoom_wheel; // IE, Opera.
773 -
774 - pr_fetch_thumb_url( Math.min( w, self.proofreadPageWidth ), function( url, width, height ) {
775 - // Load the image after page setup, so that user-defined hooks do not have to wait for it.
776 - $( function() { pr_load_image( url ) } );
777 - } );
 734+ /* Load the image after page setup, so that user-defined hooks do not have to wait for it. */
 735+ hookEvent( 'load', pr_load_image );
778736 }
779737
780738 table.setAttribute( 'id', 'textBoxTable' );
@@ -797,7 +755,7 @@
798756 pr_make_edit_area( self.text_container, new_text.value );
799757 var copywarn = document.getElementById( 'editpage-copywarn' );
800758 f.insertBefore( table, copywarn );
801 - if( !self.proofreadpage_show_headers ) {
 759+ if ( !self.proofreadpage_show_headers ) {
802760 hookEvent( 'load', pr_toggle_visibility );
803761 } else {
804762 hookEvent( 'load', pr_reset_size );
@@ -938,36 +896,69 @@
939897 return;
940898 }
941899
942 - if( $.inArray( mw.util.getParamValue( 'action' ), ['protect', 'unprotect', 'delete', 'undelete', 'watch', 'unwatch', 'history'] ) > -1 ) {
 900+ if( document.URL.indexOf( 'action=protect' ) > 0 || document.URL.indexOf( 'action=unprotect' ) > 0 ) {
943901 return;
944902 }
 903+ if( document.URL.indexOf( 'action=delete' ) > 0 || document.URL.indexOf( 'action=undelete' ) > 0 ) {
 904+ return;
 905+ }
 906+ if( document.URL.indexOf( 'action=watch' ) > 0 || document.URL.indexOf( 'action=unwatch' ) > 0 ) {
 907+ return;
 908+ }
 909+ if( document.URL.indexOf( 'action=history' ) > 0 ) {
 910+ return;
 911+ }
945912
946 - if( mw.config.get( 'proofreadPageFileName' ) == null ) {
947 - // File does not exist
 913+ /* check if external URL is provided */
 914+ if( !self.proofreadPageThumbURL ) {
 915+ var text = document.getElementById( 'wpTextbox1' );
 916+ if ( text ) {
 917+ var proofreadPageIsEdit = true;
 918+ re = /<span class="hiddenStructure" id="pageURL">\[http:\/\/(.*?)\]<\/span>/;
 919+ m = re.exec( text.value );
 920+ if( m ) {
 921+ self.proofreadPageExternalURL = 'http://' + m[1];
 922+ }
 923+ } else {
 924+ var proofreadPageIsEdit = false;
 925+ text = document.getElementById( 'bodyContent' );
 926+ try {
 927+ var a = document.getElementById( 'pageURL' );
 928+ var b = a.firstChild;
 929+ self.proofreadPageExternalURL = b.getAttribute( 'href' );
 930+ } catch( err ) {
 931+ };
 932+ }
 933+ // set to dummy values, not used
 934+ self.proofreadPageWidth = 400;
 935+ self.proofreadPageHeight = 400;
 936+ }
 937+
 938+ if( !self.proofreadPageThumbURL ) {
948939 return;
949940 }
950941
951942 if( self.proofreadpage_setup ) {
952 - // Run site/user setup code
953943 proofreadpage_setup(
954 - mw.config.get( 'proofreadPageWidth' ),
955 - mw.config.get( 'proofreadPageHeight' ),
956 - mw.config.get( 'proofreadPageIsEdit' )
 944+ proofreadPageWidth,
 945+ proofreadPageHeight,
 946+ proofreadPageIsEdit
957947 );
958948 } else {
959 - // Run extension setup code
960949 pr_setup();
961950 }
962951
963952 // add CSS classes to the container div
964 - if( mw.config.get( 'proofreadPageCss' ) != null ) {
965 - $( 'div.pagetext' ).addClass( mw.config.get( 'proofreadPageCss' ) );
 953+ if( self.proofreadPageCss) {
 954+ $( 'div.pagetext' ).addClass( self.proofreadPageCss );
966955 }
967956 }
968957
969958 $(document).ready( pr_init );
970959 $(document).ready( pr_init_tabs );
 960+$(document).ready( pr_initzoom );
971961
 962+
972963 /* Quality buttons */
973964 self.pr_add_quality = function( form, value ) {
974965 self.proofreadpage_quality = value;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r95602(bug 17791) ProofreadPage broken for GIF images due to assuming it can always...johnduhart17:40, 27 August 2011

Status & tagging log