r56553 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56552‎ | r56553 | r56554 >
Date:19:10, 17 September 2009
Author:aaron
Status:ok
Tags:
Comment:
bug 20690: use MakeGlobalVariablesScript hook
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.class.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -445,6 +445,7 @@
446446
447447 # Add CSS/JS as needed
448448 $wgHooks['BeforePageDisplay'][] = 'FlaggedRevsHooks::injectStyleAndJS';
 449+$wgHooks['MakeGlobalVariablesScript'][] = 'FlaggedRevsHooks::injectGlobalJSVars';
449450
450451 # Cache updates
451452 $wgHooks['HTMLCacheUpdate::doUpdate'][] = 'FlaggedRevsHooks::doCacheUpdate';
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
@@ -1286,7 +1286,7 @@
12871287 $tagsJS[$tag] = self::$minQL[$tag];
12881288 }
12891289 $params = array( 'tags' => (object)$tagsJS );
1290 - return Xml::encodeJsVar( (object)$params );
 1290+ return (object)$params;
12911291 }
12921292
12931293 /**
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.hooks.php
@@ -17,38 +17,42 @@
1818 return true;
1919 }
2020 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+ }
2140 # Load required messages
2241 wfLoadExtensionMessages( 'FlaggedRevs' );
23 -
24 - $stylePath = str_replace( '$wgScriptPath', $wgScriptPath, $wgFlaggedRevsStylePath );
 42+ # Get the review tags on this wiki
2543 $rTags = FlaggedRevs::getJSTagParams();
 44+ # Get page-specific meta-data
2645 $frev = $fa->getStableRev();
2746 $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(
3548 'sendingMsg' => wfMsgHtml('revreview-submitting'),
3649 'sentMsgOk' => wfMsgHtml('revreview-finished'),
3750 'sentMsgBad' => wfMsgHtml('revreview-failed'),
3851 'actioncomplete' => wfMsgHtml('actioncomplete'),
3952 'actionfailed' => wfMsgHtml('actionfailed')
40 - )
4153 );
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;
5357 return true;
5458 }
5559

Follow-up revisions

RevisionCommit summaryAuthorDate
r56555Merged r56553: script location fixaaron19:15, 17 September 2009

Status & tagging log