r55758 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55757‎ | r55758 | r55759 >
Date:17:26, 2 September 2009
Author:nimishg
Status:deferred
Tags:
Comment:
Fixed JS global variable string escaping, added Special:ClickTracking page
Modified paths:
  • /trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.alias.php (added) (history)
  • /trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.i18n.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/ClickTracking/SpecialClickTracking.php (added) (history)
  • /trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -13,6 +13,7 @@
1414 private static $doOutput = false;
1515 private static $messages = array();
1616 private static $variables = array();
 17+ private static $literalVariables = array();
1718 private static $styles = array();
1819 private static $styleFiles = array(
1920 'base_sets' => array(
@@ -128,6 +129,14 @@
129130 self::$variables[$key] =
130131 "var {$escapedVariableKey} = '{$escapedVariableValue}';";
131132 }
 133+
 134+ //literal variables, ie ones we do not want escaped as strings
 135+ foreach( self::$literalVariables as $key => $value){
 136+ $escapedVariableValue = Xml::escapeJsString( $value );
 137+ $escapedVariableKey = Xml::escapeJsString( $key );
 138+ self::$variables[$key] =
 139+ "var {$escapedVariableKey} = {$escapedVariableValue};";
 140+ }
132141 if ( count( self::$variables ) > 0 ) {
133142 $out->addScript(
134143 Xml::tags(
@@ -216,11 +225,19 @@
217226 }
218227
219228 /**
220 - * Adds internationalized message definitions to the document for access
221 - * via javascript using the gM() function
222 - * @param array $messages Key names of messages to load
 229+ * Adds variables that will be turned into global variables in JS
 230+ * @param $variables array of "name" => "value"
223231 */
224232 public static function addVariables( $variables ) {
225233 self::$variables = array_merge( self::$variables, $variables );
226234 }
 235+
 236+ /**
 237+ * Adds variables that will be turned into global variables in JS, but not escaped as strings
 238+ * @param $variables array of "name" => "value"
 239+ */
 240+ public static function addLiteralVariables( $variables ) {
 241+ self::$literalVariables = array_merge( self::$literalVariables, $variables );
 242+ }
 243+
227244 }
Index: trunk/extensions/UsabilityInitiative/ClickTracking/SpecialClickTracking.php
@@ -0,0 +1,24 @@
 2+<?php
 3+/**
 4+ * Special:ClickTracking
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
 9+
 10+class SpecialClickTracking extends SpecialPage {
 11+ function __construct() {
 12+ parent::__construct( 'ClickTracking' );
 13+ wfLoadExtensionMessages( 'ClickTracking' );
 14+ }
 15+
 16+ function execute( $par ) {
 17+ global $wgOut;
 18+ $this->setHeaders();
 19+ $wgOut->setPageTitle( wfMsg( 'clicktracking-title' ) );
 20+
 21+ }
 22+
 23+
 24+
 25+}
\ No newline at end of file
Property changes on: trunk/extensions/UsabilityInitiative/ClickTracking/SpecialClickTracking.php
___________________________________________________________________
Name: svn:eol-style
126 + native
Index: trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.hooks.php
@@ -59,7 +59,11 @@
6060 UsabilityInitiativeHooks::addScript( 'ClickTracking/ClickTracking.js' );
6161 UsabilityInitiativeHooks::addVariables(
6262 array(
63 - 'wgTrackingToken' => ClickTrackingHooks::get_session_id(),
 63+ 'wgTrackingToken' => ClickTrackingHooks::get_session_id()
 64+ )
 65+ );
 66+ UsabilityInitiativeHooks::addLiteralVariables(
 67+ array(
6468 'wgClickTrackingIsThrottled' => ClickTrackingHooks::isUserThrottled()
6569 )
6670 );
Index: trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.js
@@ -1,6 +1,6 @@
22 (function($) {
33
4 - if(wgClickTrackingIsThrottled == 'false'){
 4+ if(!wgClickTrackingIsThrottled){
55 // creates 'track action' function to call the clicktracking API and send the ID
66 $.trackAction = function ( id ){
77 $j.post( wgScriptPath + '/api.php', { 'action': 'clicktracking', 'eventid': id, 'token': wgTrackingToken } );
Index: trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.alias.php
@@ -0,0 +1,13 @@
 2+<?php
 3+/**
 4+ * Special page aliases for Usability Initiative ClickTracking extension
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
 9+
 10+$aliases = array();
 11+
 12+$aliases['en'] = array(
 13+ 'ClickTracking' => array( 'ClickTracking' ),
 14+);
Property changes on: trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.alias.php
___________________________________________________________________
Name: svn:eol-style
115 + native
Index: trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.i18n.php
@@ -13,7 +13,8 @@
1414 */
1515 $messages['en'] = array(
1616 'clicktracking' => 'Usability Initiative click tracking',
17 - 'clicktracking-desc' => 'Click tracking, intended for tracking events that do not cause a page refresh'
 17+ 'clicktracking-desc' => 'Click tracking, intended for tracking events that do not cause a page refresh',
 18+ 'clicktracking-title' => 'Aggregated user clicks'
1819 );
1920
2021 /** Message documentation (Message documentation)
Index: trunk/extensions/UsabilityInitiative/ClickTracking/ClickTracking.php
@@ -47,11 +47,22 @@
4848 $dir = dirname( __FILE__ ) . '/';
4949 $wgAutoloadClasses['ClickTrackingHooks'] = $dir . 'ClickTracking.hooks.php';
5050 $wgAutoloadClasses['ApiClickTracking'] = $dir . 'ApiClickTracking.php';
 51+$wgAutoloadClasses['SpecialClickTracking'] = $dir . 'SpecialClickTracking.php';
5152
 53+
5254 // Hooked functions
5355 $wgHooks['LoadExtensionSchemaUpdates'][] = 'ClickTrackingHooks::schema';
5456 $wgHooks['ArticleSaveComplete'][] = 'ClickTrackingHooks::storeNewContrib';
5557 $wgHooks['EditPage::showEditForm:initial'][] = 'ClickTrackingHooks::addJS';
5658
5759 // Set up the new API module
58 -$wgAPIModules['clicktracking'] = 'ApiClickTracking';
\ No newline at end of file
 60+$wgAPIModules['clicktracking'] = 'ApiClickTracking';
 61+
 62+//Special page setup
 63+$wgSpecialPages['ClickTracking'] = 'SpecialClickTracking';
 64+
 65+
 66+
 67+// Adds Internationalized Messages
 68+$wgExtensionMessagesFiles['ClickTracking'] = $dir . 'ClickTracking.i18n.php';
 69+$wgExtensionAliasesFiles['ClickTracking'] = $dir . 'ClickTracking.alias.php';
\ No newline at end of file

Follow-up revisions

RevisionCommit summaryAuthorDate
r55759Add support for aliases for ClickTracking (r55758)siebrand18:23, 2 September 2009

Status & tagging log