Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php |
— | — | @@ -445,6 +445,7 @@ |
446 | 446 | |
447 | 447 | # Add CSS/JS as needed |
448 | 448 | $wgHooks['BeforePageDisplay'][] = 'FlaggedRevsHooks::injectStyleAndJS'; |
| 449 | +$wgHooks['MakeGlobalVariablesScript'][] = 'FlaggedRevsHooks::injectGlobalJSVars'; |
449 | 450 | |
450 | 451 | # Cache updates |
451 | 452 | $wgHooks['HTMLCacheUpdate::doUpdate'][] = 'FlaggedRevsHooks::doCacheUpdate'; |
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php |
— | — | @@ -1286,7 +1286,7 @@ |
1287 | 1287 | $tagsJS[$tag] = self::$minQL[$tag]; |
1288 | 1288 | } |
1289 | 1289 | $params = array( 'tags' => (object)$tagsJS ); |
1290 | | - return Xml::encodeJsVar( (object)$params ); |
| 1290 | + return (object)$params; |
1291 | 1291 | } |
1292 | 1292 | |
1293 | 1293 | /** |
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php |
— | — | @@ -17,38 +17,42 @@ |
18 | 18 | return true; |
19 | 19 | } |
20 | 20 | global $wgScriptPath, $wgJsMimeType, $wgFlaggedRevsStylePath, $wgFlaggedRevStyleVersion; |
| 21 | + $stylePath = str_replace( '$wgScriptPath', $wgScriptPath, $wgFlaggedRevsStylePath ); |
| 22 | + # Get JS/CSS file locations |
| 23 | + $encCssFile = htmlspecialchars( "$stylePath/flaggedrevs.css?$wgFlaggedRevStyleVersion" ); |
| 24 | + $encJsFile = htmlspecialchars( "$stylePath/flaggedrevs.js?$wgFlaggedRevStyleVersion" ); |
| 25 | + # Add CSS file |
| 26 | + $wgOut->addExtensionStyle( $encCssFile ); |
| 27 | + # Add JS file |
| 28 | + $head = "<script type=\"{$wgJsMimeType}\" src=\"{$encJsFile}\"></script>"; |
| 29 | + $wgOut->addHeadItem( 'FlaggedRevs', $head ); |
| 30 | + return true; |
| 31 | + } |
| 32 | + |
| 33 | + public static function injectGlobalJSVars( &$globalVars ) { |
| 34 | + global $wgJsMimeType; |
| 35 | + $fa = FlaggedArticle::getGlobalInstance(); |
| 36 | + # Try to only add to relevant pages |
| 37 | + if( !$fa || !$fa->isReviewable(true) ) { |
| 38 | + return true; |
| 39 | + } |
21 | 40 | # Load required messages |
22 | 41 | wfLoadExtensionMessages( 'FlaggedRevs' ); |
23 | | - |
24 | | - $stylePath = str_replace( '$wgScriptPath', $wgScriptPath, $wgFlaggedRevsStylePath ); |
| 42 | + # Get the review tags on this wiki |
25 | 43 | $rTags = FlaggedRevs::getJSTagParams(); |
| 44 | + # Get page-specific meta-data |
26 | 45 | $frev = $fa->getStableRev(); |
27 | 46 | $stableId = $frev ? $frev->getRevId() : 0; |
28 | | - |
29 | | - $encCssFile = htmlspecialchars( "$stylePath/flaggedrevs.css?$wgFlaggedRevStyleVersion" ); |
30 | | - $encJsFile = htmlspecialchars( "$stylePath/flaggedrevs.js?$wgFlaggedRevStyleVersion" ); |
31 | | - |
32 | | - $wgOut->addExtensionStyle( $encCssFile ); |
33 | | - |
34 | | - $ajaxReview = Xml::encodeJsVar( (object) array( |
| 47 | + $ajaxReview = (object) array( |
35 | 48 | 'sendingMsg' => wfMsgHtml('revreview-submitting'), |
36 | 49 | 'sentMsgOk' => wfMsgHtml('revreview-finished'), |
37 | 50 | 'sentMsgBad' => wfMsgHtml('revreview-failed'), |
38 | 51 | 'actioncomplete' => wfMsgHtml('actioncomplete'), |
39 | 52 | 'actionfailed' => wfMsgHtml('actionfailed') |
40 | | - ) |
41 | 53 | ); |
42 | | - |
43 | | - $head = <<<EOT |
44 | | -<script type="$wgJsMimeType"> |
45 | | -var wgFlaggedRevsParams = $rTags; |
46 | | -var wgStableRevisionId = $stableId; |
47 | | -var wgAjaxReview = $ajaxReview |
48 | | -</script> |
49 | | -<script type="$wgJsMimeType" src="$encJsFile"></script> |
50 | | - |
51 | | -EOT; |
52 | | - $wgOut->addHeadItem( 'FlaggedRevs', $head ); |
| 54 | + $globalVars['wgFlaggedRevsParams'] = $rTags; |
| 55 | + $globalVars['wgStableRevisionId'] = $stableId; |
| 56 | + $globalVars['wgAjaxReview'] = $ajaxReview; |
53 | 57 | return true; |
54 | 58 | } |
55 | 59 | |