r61029 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61028‎ | r61029 | r61030 >
Date:22:02, 13 January 2010
Author:aaron
Status:ok
Tags:
Comment:
Refactored JS output to use MakeGlobalVariablesScript hook
Modified paths:
  • /trunk/extensions/ReaderFeedback/ReaderFeedback.class.php (modified) (history)
  • /trunk/extensions/ReaderFeedback/ReaderFeedback.hooks.php (modified) (history)
  • /trunk/extensions/ReaderFeedback/ReaderFeedback.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ReaderFeedback/ReaderFeedback.hooks.php
@@ -20,28 +20,25 @@
2121 wfLoadExtensionMessages( 'ReaderFeedback' );
2222
2323 $stylePath = str_replace( '$wgScriptPath', $wgScriptPath, $wgFeedbackStylePath );
24 - $fTags = ReaderFeedback::getJSFeedbackParams();
2524
2625 $encCssFile = htmlspecialchars( "$stylePath/readerfeedback.css?$wgFeedbackStyleVersion" );
2726 $encJsFile = htmlspecialchars( "$stylePath/readerfeedback.js?$wgFeedbackStyleVersion" );
28 -
 27+ // Add CSS
2928 $wgOut->addExtensionStyle( $encCssFile );
 29+ // Add JS
 30+ $head = "<script type=\"$wgJsMimeType\" src=\"$encJsFile\"></script>\n";
 31+ $wgOut->addHeadItem( 'ReaderFeedback', $head );
3032
31 - $ajaxFeedback = Xml::encodeJsVar( (object) array(
 33+ return true;
 34+ }
 35+
 36+ public static function injectJSVars( &$globalVars ) {
 37+ global $wgUser;
 38+ $globalVars['wgFeedbackParams'] = ReaderFeedback::getJSFeedbackParams();
 39+ $globalVars['wgAjaxFeedback'] = (object) array(
3240 'sendingMsg' => wfMsgHtml('readerfeedback-submitting'),
3341 'sentMsg' => wfMsgHtml('readerfeedback-finished')
34 - )
3542 );
36 -
37 - $head = <<<EOT
38 -<script type="$wgJsMimeType">
39 -var wgFeedbackParams = $fTags;
40 -var wgAjaxFeedback = $ajaxFeedback
41 -</script>
42 -<script type="$wgJsMimeType" src="$encJsFile"></script>
43 -
44 -EOT;
45 - $wgOut->addHeadItem( 'ReaderFeedback', $head );
4643 return true;
4744 }
4845
Index: trunk/extensions/ReaderFeedback/ReaderFeedback.class.php
@@ -265,7 +265,7 @@
266266 # Param to pass to JS function to know if tags are at quality level
267267 global $wgFeedbackTags;
268268 $params = array( 'tags' => (object)$wgFeedbackTags );
269 - return Xml::encodeJsVar( (object)$params );
 269+ return (object)$params;
270270 }
271271
272272 }
Index: trunk/extensions/ReaderFeedback/ReaderFeedback.php
@@ -110,6 +110,7 @@
111111
112112 # Add CSS/JS as needed
113113 $wgHooks['BeforePageDisplay'][] = 'ReaderFeedbackHooks::injectStyleAndJS';
 114+$wgHooks['MakeGlobalVariablesScript'][] = 'ReaderFeedbackHooks::injectJSVars';
114115
115116 # Duplicate flagged* tables in parserTests.php
116117 $wgHooks['ParserTestTables'][] = 'ReaderFeedbackHooks::onParserTestTables';

Status & tagging log