r73811 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73810‎ | r73811 | r73812 >
Date:15:08, 27 September 2010
Author:thomasv
Status:ok (Comments)
Tags:
Comment:
use Resource loader ; adapt scripts
Modified paths:
  • /trunk/extensions/ProofreadPage/ProofreadPage.php (modified) (history)
  • /trunk/extensions/ProofreadPage/ProofreadPage_body.php (modified) (history)
  • /trunk/extensions/ProofreadPage/proofread.js (modified) (history)
  • /trunk/extensions/ProofreadPage/proofread_article.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ProofreadPage/ProofreadPage_body.php
@@ -51,11 +51,49 @@
5252 $wgHooks['LoadExtensionSchemaUpdates'][] = array( &$this, 'schema_update' );
5353 $wgHooks['EditPage::importFormData'][] = array( &$this, 'importFormData' );
5454 $wgHooks['OutputPageParserOutput'][] = array( &$this, 'OutputPageParserOutput' );
 55+ $wgHooks['ResourceLoaderRegisterModules'][] = array( &$this, 'resourceLoaderRegisterModules' );
5556 wfLoadExtensionMessages( 'ProofreadPage' );
5657 $this->page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' );
5758 $this->index_namespace = preg_quote( wfMsgForContent( 'proofreadpage_index_namespace' ), '/' );
5859 }
5960
 61+
 62+ public static function resourceLoaderRegisterModules() {
 63+
 64+ ResourceLoader::register( 'proofreadpage.page',
 65+ new ResourceLoaderFileModule(
 66+ array( 'scripts' => 'extensions/ProofreadPage/proofread.js',
 67+ 'messages' => array( 'proofreadpage_index',
 68+ 'proofreadpage_nextpage',
 69+ 'proofreadpage_prevpage',
 70+ 'proofreadpage_image',
 71+ 'proofreadpage_header',
 72+ 'proofreadpage_body',
 73+ 'proofreadpage_footer',
 74+ 'proofreadpage_toggleheaders',
 75+ 'proofreadpage_page_status',
 76+ 'proofreadpage_quality0_category',
 77+ 'proofreadpage_quality1_category',
 78+ 'proofreadpage_quality2_category',
 79+ 'proofreadpage_quality3_category',
 80+ 'proofreadpage_quality4_category',
 81+ )
 82+ ) ) );
 83+
 84+ ResourceLoader::register( 'proofreadpage.article',
 85+ new ResourceLoaderFileModule(
 86+ array( 'scripts' => 'extensions/ProofreadPage/proofread_article.js',
 87+ 'messages'=> array( 'proofreadpage_source', 'proofreadpage_source_message' )
 88+ ) ) );
 89+
 90+ ResourceLoader::register( 'proofreadpage.index',
 91+ new ResourceLoaderFileModule( array( 'scripts' => 'extensions/ProofreadPage/proofread_index.js' ) ) );
 92+
 93+ return true;
 94+ }
 95+
 96+
 97+
6098 function schema_update() {
6199 global $wgExtNewTables;
62100 $base = dirname(__FILE__);
@@ -306,42 +344,20 @@
307345 return true;
308346 }
309347
310 -
311348 function prepareArticle( $out ) {
312 - global $wgJsMimeType, $wgScriptPath, $wgRequest, $wgProofreadPageVersion;
313 - $jsFile = htmlspecialchars( "$wgScriptPath/extensions/ProofreadPage/proofread_article.js?$wgProofreadPageVersion" );
314 - $out->addScript( <<<EOT
315 -<script type="$wgJsMimeType" src="$jsFile"></script>
316 -EOT
317 - );
318 - $out->addScript( "<script type=\"{$wgJsMimeType}\">
319 -var prp_source = \"" . Xml::escapeJsString( wfMsg( 'proofreadpage_source' ) ) . "\";
320 -var prp_source_message = \"" . Xml::escapeJsString( wfMsg( 'proofreadpage_source_message' ) ) . "\";
321 -</script>\n"
322 - );
 349+ $out->addModules( 'proofreadpage.article' );
323350 $this->displayProofreadingStatus( $out );
324351 }
325352
326353 function prepareIndex( $out ) {
327 - global $wgJsMimeType, $wgScriptPath, $wgRequest, $wgProofreadPageVersion;
328 - $jsFile = htmlspecialchars( "$wgScriptPath/extensions/ProofreadPage/proofread_index.js?$wgProofreadPageVersion" );
329 -
330 - $out->addScript( <<<EOT
331 -<script type="$wgJsMimeType" src="$jsFile"></script>
332 -
333 -EOT
334 - );
335 - $out->addScript( "<script type=\"{$wgJsMimeType}\">
 354+ $out->addModules( 'proofreadpage.index' );
 355+ $out->addInlineScript("
336356 var prp_index_attributes = \"" . Xml::escapeJsString( wfMsgForContent( 'proofreadpage_index_attributes' ) ) . "\";
337357 var prp_default_header = \"" . Xml::escapeJsString( wfMsgGetKey( 'proofreadpage_default_header', true, true, false ) ) . "\";
338 -var prp_default_footer = \"" . Xml::escapeJsString( wfMsgGetKey( 'proofreadpage_default_footer', true, true, false ) ) . "\";
339 -</script>\n"
340 - );
 358+var prp_default_footer = \"" . Xml::escapeJsString( wfMsgGetKey( 'proofreadpage_default_footer', true, true, false ) ) . "\";" );
341359 }
342360
343 -
344361 function preparePage( $out, $m, $isEdit ) {
345 - global $wgJsMimeType, $wgScriptPath, $wgRequest, $wgProofreadPageVersion, $wgProofreadPageMaxWidth;
346362 global $wgTitle, $wgUser;
347363
348364 if ( !isset( $wgTitle->pr_index_title ) ) {
@@ -372,8 +388,6 @@
373389
374390 list( $index_url, $prev_url, $next_url, $header, $footer, $css, $edit_width ) = $this->navigation( $wgTitle );
375391
376 - $jsFile = htmlspecialchars( "$wgScriptPath/extensions/ProofreadPage/proofread.js?$wgProofreadPageVersion" );
377 -
378392 $jsVars = array(
379393 'proofreadPageWidth' => intval( $width ),
380394 'proofreadPageHeight' => intval( $height ),
@@ -389,32 +403,10 @@
390404 'proofreadPageUserName' => $wgUser->getName(),
391405 'proofreadPageCss' => $css,
392406 );
393 - $varScript = Skin::makeVariablesScript( $jsVars );
 407+ $out->addInlineScript( ResourceLoader::makeConfigSetScript( $jsVars ) );
394408
395 - $out->addScript( <<<EOT
396 -$varScript
397 -<script type="$wgJsMimeType" src="$jsFile"></script>
 409+ $out->addModules( 'proofreadpage.page' );
398410
399 -EOT
400 - );
401 -
402 - // Add messages from i18n
403 - $out->addScript( "<script type=\"{$wgJsMimeType}\">
404 -var proofreadPageMessageIndex = \"" . Xml::escapeJsString( wfMsg( 'proofreadpage_index' ) ) . "\";
405 -var proofreadPageMessageNextPage = \"" . Xml::escapeJsString( wfMsg( 'proofreadpage_nextpage' ) ) . "\";
406 -var proofreadPageMessagePrevPage = \"" . Xml::escapeJsString( wfMsg( 'proofreadpage_prevpage' ) ) . "\";
407 -var proofreadPageMessageImage = \"" . Xml::escapeJsString( wfMsg( 'proofreadpage_image' ) ) . "\";
408 -var proofreadPageMessageHeader = \"" . Xml::escapeJsString( wfMsg( 'proofreadpage_header' ) ) . "\";
409 -var proofreadPageMessagePageBody = \"" . Xml::escapeJsString( wfMsg( 'proofreadpage_body' ) ) . "\";
410 -var proofreadPageMessageFooter = \"" . Xml::escapeJsString( wfMsg( 'proofreadpage_footer' ) ) . "\";
411 -var proofreadPageMessageToggleHeaders = \"" . Xml::escapeJsString( wfMsg( 'proofreadpage_toggleheaders' ) ) . "\";
412 -var proofreadPageMessageStatus = \"" . Xml::escapeJsString( wfMsg( 'proofreadpage_page_status' ) ) . "\";
413 -var proofreadPageMessageQuality0 = \"" . Xml::escapeJsString( wfMsgForContent( 'proofreadpage_quality0_category' ) ) . "\";
414 -var proofreadPageMessageQuality1 = \"" . Xml::escapeJsString( wfMsgForContent( 'proofreadpage_quality1_category' ) ) . "\";
415 -var proofreadPageMessageQuality2 = \"" . Xml::escapeJsString( wfMsgForContent( 'proofreadpage_quality2_category' ) ) . "\";
416 -var proofreadPageMessageQuality3 = \"" . Xml::escapeJsString( wfMsgForContent( 'proofreadpage_quality3_category' ) ) . "\";
417 -var proofreadPageMessageQuality4 = \"" . Xml::escapeJsString( wfMsgForContent( 'proofreadpage_quality4_category' ) ) . "\";
418 -</script>\n" );
419411 return true;
420412 }
421413
Index: trunk/extensions/ProofreadPage/proofread.js
@@ -18,7 +18,7 @@
1919 var view_url = self.proofreadPageThumbURL.replace( '##WIDTH##', '' + self.proofreadPageWidth );
2020 b[0].innerHTML = b[0].innerHTML + '<li id="ca-image">' +
2121 '<span><a href="' + escapeQuotesHTML( view_url ) + '">' +
22 - escapeQuotesHTML( proofreadPageMessageImage ) + '</a></span></li>';
 22+ escapeQuotesHTML( mediaWiki.msg.get( 'proofreadpage_image' ) ) + '</a></span></li>';
2323 }
2424
2525 if( self.proofreadPageIndexURL ) {
@@ -26,16 +26,16 @@
2727 '<span><a href="' + escapeQuotesHTML( proofreadPageIndexURL ) +
2828 '" title="' + escapeQuotesHTML( proofreadPageMessageIndex ) + '">' +
2929 '<img src="' + wgScriptPath + '/extensions/ProofreadPage/uparrow.png" alt="' +
30 - escapeQuotesHTML( proofreadPageMessageIndex ) +
 30+ escapeQuotesHTML( mediaWiki.msg.get( 'proofreadpage_index' ) ) +
3131 '" width="15" height="15" /></a></span></li>';
3232 }
3333
3434 if( self.proofreadPageNextURL ) {
3535 b[0].innerHTML = '<li id="ca-next">' +
3636 '<span><a href="' + escapeQuotesHTML( self.proofreadPageNextURL ) +
37 - '" title="' + escapeQuotesHTML( proofreadPageMessageNextPage ) + '">' +
 37+ '" title="' + escapeQuotesHTML( mediaWiki.msg.get( 'proofreadpage_nextpage' ) ) + '">' +
3838 '<img src="' + wgScriptPath + '/extensions/ProofreadPage/rightarrow.png" alt="' +
39 - escapeQuotesHTML( proofreadPageMessageNextPage ) +
 39+ escapeQuotesHTML( mediaWiki.msg.get( 'proofreadpage_nextpage' ) ) +
4040 '" width="15" height="15" /></a></span></li>' +
4141 b[0].innerHTML;
4242 }
@@ -43,9 +43,9 @@
4444 if( self.proofreadPagePrevURL ) {
4545 b[0].innerHTML = '<li id="ca-prev">' +
4646 '<span><a href="' + escapeQuotesHTML( self.proofreadPagePrevURL ) +
47 - '" title="' + escapeQuotesHTML( proofreadPageMessagePrevPage ) + '">' +
 47+ '" title="' + escapeQuotesHTML( mediaWiki.msg.get( 'proofreadpage_prevpage' ) ) + '">' +
4848 '<img src="' + wgScriptPath + '/extensions/ProofreadPage/leftarrow.png" alt="' +
49 - escapeQuotesHTML( proofreadPageMessagePrevPage ) +
 49+ escapeQuotesHTML( mediaWiki.msg.get( 'proofreadpage_prevpage' ) ) +
5050 '" width="15" height="15" /></a></span></li>' +
5151 b[0].innerHTML;
5252 }
@@ -95,7 +95,7 @@
9696 pageBody = text;
9797 pageFooter = proofreadPageFooter;
9898 if( document.editform ) {
99 - document.editform.elements['wpSummary'].value = '/* ' + proofreadPageMessageQuality1 + ' */ ';
 99+ document.editform.elements['wpSummary'].value = "/* " + mediaWiki.msg.get( 'proofreadpage_quality1_category' ) + " */ ";
100100 }
101101 }
102102 }
@@ -166,18 +166,20 @@
167167 pageHeader = pageHeader.split( '&' ).join( '&amp;' );
168168 pageFooter = pageFooter.split( '&' ).join( '&amp;' );
169169
 170+ if ( ! self.proofreadpage_show_headers ) headers_style = 'display:none'; else headers_style='';
 171+
170172 container.innerHTML = '' +
171 - '<div id="prp_header" style="">' +
 173+ '<div id="prp_header" style="' + headers_style + '">' +
172174 '<span style="color:gray;font-size:80%;line-height:100%;">' +
173 - escapeQuotesHTML( proofreadPageMessageHeader ) + '</span>' +
 175+ escapeQuotesHTML( mediaWiki.msg.get( 'proofreadpage_header' ) ) + '</span>' +
174176 '<textarea name="wpHeaderTextbox" rows="2" cols="80" tabindex=1>' + pageHeader + '</textarea><br />' +
175177 '<span style="color:gray;font-size:80%;line-height:100%;">' +
176 - escapeQuotesHTML( proofreadPageMessagePageBody ) + '</span></div>' +
 178+ escapeQuotesHTML( mediaWiki.msg.get( 'proofreadpage_body' ) ) + '</span></div>' +
177179 '<textarea name="wpTextbox1" id="wpTextbox1" tabindex=1 style="height:' + ( self.DisplayHeight - 6 ) + 'px;">' +
178180 pageBody + '</textarea>' +
179 - '<div id="prp_footer" style="">' +
 181+ '<div id="prp_footer" style="' + headers_style + '">' +
180182 '<span style="color:gray;font-size:80%;line-height:100%;">' +
181 - escapeQuotesHTML( proofreadPageMessageFooter ) + '</span><br />' +
 183+ escapeQuotesHTML( mediaWiki.msg.get( 'proofreadpage_footer' ) ) + '</span><br />' +
182184 '<textarea name="wpFooterTextbox" rows="2" cols="80" tabindex=1>' +
183185 pageFooter + '</textarea></div>';
184186 }
@@ -599,7 +601,7 @@
600602 }
601603 }
602604
603 -function pr_zoom( delta ) {
 605+self.pr_zoom = function(delta) {
604606 if ( delta == 0 ) {
605607 // reduce width by 20 pixels in order to prevent horizontal scrollbar
606608 // from showing up
@@ -774,7 +776,7 @@
775777 pr_container.addEventListener( 'DOMMouseScroll', pr_zoom_wheel, false );
776778 }
777779 pr_container.onmousewheel = pr_zoom_wheel; // IE, Opera.
778 - hookEvent( 'load', function() { pr_load_image( view_url ); } );
 780+ pr_load_image(view_url);
779781 }
780782
781783 table.setAttribute( 'id', 'textBoxTable' );
@@ -798,9 +800,6 @@
799801 pr_make_edit_area( self.text_container, new_text.value );
800802 var copywarn = document.getElementById( 'editpage-copywarn' );
801803 f.insertBefore( table, copywarn );
802 - if ( !self.proofreadpage_show_headers ) {
803 - hookEvent( 'load', pr_toggle_visibility );
804 - }
805804 } else {
806805 self.text_container.appendChild( new_text );
807806 f.appendChild( self.table );
@@ -816,8 +815,8 @@
817816 image.className = 'mw-toolbar-editbutton';
818817 image.src = wgScriptPath + '/extensions/ProofreadPage/button_category_plus.png';
819818 image.border = 0;
820 - image.alt = proofreadPageMessageToggleHeaders;
821 - image.title = proofreadPageMessageToggleHeaders;
 819+ image.alt = mediaWiki.msg.get( 'proofreadpage_toggleheaders' );
 820+ image.title = mediaWiki.msg.get( 'proofreadpage_toggleheaders' );
822821 image.style.cursor = 'pointer';
823822 image.onclick = pr_toggle_visibility;
824823
@@ -954,25 +953,25 @@
955954 hookEvent( 'load', pr_initzoom );
956955
957956 /* Quality buttons */
958 -function pr_add_quality( form, value ) {
 957+self.pr_add_quality = function( form, value ) {
959958 self.proofreadpage_quality = value;
960959 self.proofreadpage_username = proofreadPageUserName;
961960 var text = '';
962961 switch( value ) {
963962 case 0:
964 - text = proofreadPageMessageQuality0;
 963+ text = mediaWiki.msg.get( 'proofreadpage_quality0_category' );
965964 break;
966965 case 1:
967 - text = proofreadPageMessageQuality1;
 966+ text = mediaWiki.msg.get( 'proofreadpage_quality1_category' );
968967 break;
969968 case 2:
970 - text = proofreadPageMessageQuality2;
 969+ text = mediaWiki.msg.get( 'proofreadpage_quality2_category' );
971970 break;
972971 case 3:
973 - text = proofreadPageMessageQuality3;
 972+ text = mediaWiki.msg.get( 'proofreadpage_quality3_category' );
974973 break;
975974 case 4:
976 - text = proofreadPageMessageQuality4;
 975+ text = mediaWiki.msg.get( 'proofreadpage_quality4_category' );
977976 break;
978977 }
979978 form.elements['wpSummary'].value = '/* ' + text + ' */ ';
@@ -1004,7 +1003,7 @@
10051004 +'<span class="quality1"> <input type="radio" name="quality" value=1 onclick="pr_add_quality(this.form,1)" tabindex=4> </span>'
10061005 +'<span class="quality3"> <input type="radio" name="quality" value=3 onclick="pr_add_quality(this.form,3)" tabindex=4> </span>'
10071006 +'<span class="quality4"> <input type="radio" name="quality" value=4 onclick="pr_add_quality(this.form,4)" tabindex=4> </span>';
1008 - f.innerHTML = f.innerHTML + '&nbsp;' + escapeQuotesHTML( proofreadPageMessageStatus );
 1007+ f.innerHTML = f.innerHTML + '&nbsp;' + escapeQuotesHTML( mediaWiki.msg.get( 'proofreadpage_page_status' ) );
10091008
10101009 if( !( ( self.proofreadpage_quality == 4 ) || ( ( self.proofreadpage_quality == 3 ) && ( self.proofreadpage_username != proofreadPageUserName ) ) ) ) {
10111010 document.editform.quality[4].parentNode.style.cssText = 'display:none';
Index: trunk/extensions/ProofreadPage/proofread_article.js
@@ -13,8 +13,8 @@
1414 return;
1515 }
1616 q.removeChild( href );
17 - href.innerHTML = prp_source;
18 - href.setAttribute( 'title', prp_source_message );
 17+ href.innerHTML = mediaWiki.msg.get( 'proofreadpage_source' );
 18+ href.setAttribute( 'title', mediaWiki.msg.get( 'proofreadpage_source_message' ) );
1919 var new_li = document.createElement( 'li' );
2020 new_li.appendChild( href );
2121 var new_span = document.createElement( 'span' );
Index: trunk/extensions/ProofreadPage/ProofreadPage.php
@@ -53,9 +53,6 @@
5454 $wgSpecialPages['PagesWithoutScans'] = 'PagesWithoutScans';
5555 $wgSpecialPageGroups['PagesWithoutScans'] = 'maintenance';
5656
57 -# Bump the version number every time you change proofread.js
58 -$wgProofreadPageVersion = 27;
59 -
6057 # Group allowed to modify pagequality
6158 $wgGroupPermissions['user']['pagequality'] = true;
6259

Follow-up revisions

RevisionCommit summaryAuthorDate
r73812ProofreadPage: follow-up to r73811 - tweak coding styleashley15:14, 27 September 2010
r73877follow up to r73811thomasv09:37, 28 September 2010

Comments

#Comment by Catrope (talk | contribs)   15:23, 27 September 2010
+		ResourceLoader::register( 'proofreadpage.page', 

The convention (which we should document, oops) is to prefix extension modules with ext., so that would make this ext.proofreadpage.page.

You can also register multiple modules with one call, like this:

ResourceLoader::register( array( 'module1' => array( 'scripts' => 'foo.js', ... ), 'module2' => array( 'scripts' => 'bar.js', ... ) );
+		$out->addInlineScript("
 var prp_index_attributes = \"" . Xml::escapeJsString( wfMsgForContent( 'proofreadpage_index_attributes' ) ) . "\";
 var prp_default_header = \"" . Xml::escapeJsString( wfMsgGetKey( 'proofreadpage_default_header', true, true, false ) ) . "\";
-var prp_default_footer = \"" . Xml::escapeJsString( wfMsgGetKey( 'proofreadpage_default_footer', true, true, false ) ) . "\";
-</script>\n"
-				 );
+var prp_default_footer = \"" . Xml::escapeJsString( wfMsgGetKey( 'proofreadpage_default_footer', true, true, false ) ) . "\";" );

What do you still need this for?

+		$out->addInlineScript( ResourceLoader::makeConfigSetScript( $jsVars ) );

Hmm. I think the resource loader should have nicer support for this.

#Comment by ThomasV (talk | contribs)   20:43, 27 September 2010

These 3 variables are not callled with wfMsg(), but with wfMsgForContent() and wfMsgGetKey() ; these are configuration messages, and they should not be translated. I do not know if resource loader has support for that.

#Comment by Catrope (talk | contribs)   11:49, 28 September 2010

Not yet, no, but it should. Filed as bug 25349

#Comment by ThomasV (talk | contribs)   09:51, 28 September 2010

I tried to prefix module names with "ext." as you suggest, but the result is that they are no longer loaded. did I miss something ?

#Comment by Catrope (talk | contribs)   11:39, 28 September 2010

Did you change the name everywhere it's being used? Did you action=purge the page you were looking at?

#Comment by ThomasV (talk | contribs)   14:16, 28 September 2010

all right, I fixed it with $document.ready(), see r73889

Status & tagging log