r110989 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110988‎ | r110989 | r110990 >
Date:00:17, 9 February 2012
Author:bsitu
Status:ok
Tags:
Comment:
Adding ClickTracking to Article Creation
Modified paths:
  • /trunk/extensions/ArticleCreationWorkflow/ArticleCreationWorkflow.hooks.php (modified) (history)
  • /trunk/extensions/ArticleCreationWorkflow/ArticleCreationWorkflow.php (modified) (history)
  • /trunk/extensions/ArticleCreationWorkflow/SpecialArticleCreationLanding.php (modified) (history)
  • /trunk/extensions/ArticleCreationWorkflow/includes/ArticleCreationUtil.php (added) (history)
  • /trunk/extensions/ArticleCreationWorkflow/modules/ext.articleCreation.user/ext.articleCreation.user.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleCreationWorkflow/includes/ArticleCreationUtil.php
@@ -0,0 +1,66 @@
 2+<?php
 3+
 4+/**
 5+ * Utility class for Article Creation
 6+ */
 7+class ArticleCreationUtil {
 8+
 9+ /**
 10+ * Check if tracking is enabled
 11+ */
 12+ public static function trackingEnabled() {
 13+ return class_exists( 'ApiClickTracking' );
 14+ }
 15+
 16+ /**
 17+ * Generate tracking code prefix
 18+ */
 19+ public static function trackingCodePrefix() {
 20+ global $wgExtensionCredits;
 21+ return 'ext.articlecreationworkflow@' . $wgExtensionCredits['other'][0]['version'] . '-';
 22+ }
 23+
 24+ /**
 25+ * Track the page stats to the special article creation landing page
 26+ * @param $request Object
 27+ * @param $user Object
 28+ */
 29+ public static function TrackSpecialLandingPage( $request, $user ) {
 30+ if ( $user->isAnon() ) {
 31+ $event = 'landingpage-anonymous';
 32+ } else {
 33+ $event = 'landingpage-loggedin';
 34+
 35+ if ( $request->getBool( 'fromlogin' ) ) {
 36+ $event .= '-fromlogin';
 37+ } elseif ( $request->getBool( 'fromsignup' ) ) {
 38+ $event .= '-fromsignup';
 39+ }
 40+ }
 41+
 42+ self::clickTracking( $event, SpecialPage::getTitleFor( 'ArticleCreationLanding' ) );
 43+ }
 44+
 45+ /**
 46+ * Tracking code that calls ClickTracking
 47+ * @param $event string the event name
 48+ * @param $title Object
 49+ */
 50+ private static function clickTracking( $event, $title ) {
 51+ // check if ClickTracking API is enabled
 52+ if ( !self::trackingEnabled() ) {
 53+ return;
 54+ }
 55+
 56+ $params = new FauxRequest( array(
 57+ 'action' => 'clicktracking',
 58+ 'eventid' => self::trackingCodePrefix() . $event,
 59+ 'token' => wfGenerateToken(),
 60+ 'namespacenumber' => $title->getNamespace()
 61+ ) );
 62+ $api = new ApiMain( $params, true );
 63+ $api->execute();
 64+ }
 65+
 66+}
 67+
Property changes on: trunk/extensions/ArticleCreationWorkflow/includes/ArticleCreationUtil.php
___________________________________________________________________
Added: svn:eol-style
168 + native
Index: trunk/extensions/ArticleCreationWorkflow/modules/ext.articleCreation.user/ext.articleCreation.user.js
@@ -72,6 +72,10 @@
7373 return;
7474 }
7575
 76+ if ( ac.config['tracking-turned-on'] ) {
 77+ jQuery.trackAction( ac.config['tracking-code-prefix'] + $(this).data('ac-button' ) + '-tooltip' );
 78+ }
 79+
7680 $( this )
7781 //make it green
7882 .addClass('ac-button-green')
@@ -133,7 +137,11 @@
134138 urlTemplate = urlTemplate.replace( '{{PAGE}}', encodeURIComponent( article ) );
135139 urlTemplate = urlTemplate.replace( '{{USER}}', encodeURIComponent( wgUserName ) );
136140 urlTemplate = urlTemplate.replace( '{{SCRIPT}}', wgScript );
137 -
 141+
 142+ if ( ac.config['tracking-turned-on'] ) {
 143+ jQuery.trackAction( ac.config['tracking-code-prefix'] + action );
 144+ }
 145+
138146 window.location.href = urlTemplate;
139147 },
140148
Index: trunk/extensions/ArticleCreationWorkflow/ArticleCreationWorkflow.php
@@ -16,6 +16,7 @@
1717
1818 /* Object model */
1919 $wgAutoloadClasses['ArticleCreationTemplates'] = $articleCreationDir . 'includes/ArticleCreationTemplates.php';
 20+$wgAutoloadClasses['ArticleCreationUtil'] = $articleCreationDir . 'includes/ArticleCreationUtil.php';
2021
2122 /* Special Pages */
2223 $wgAutoloadClasses['SpecialArticleCreationLanding'] = $articleCreationDir . 'SpecialArticleCreationLanding.php';
@@ -162,8 +163,8 @@
163164 'action-url' => array(
164165 'draft' => '{{SCRIPT}}?title=User:{{USER}}/{{PAGE}}&action=edit',
165166 'create' => '{{SCRIPT}}?title={{PAGE}}&action=edit',
166 - 'login' => '{{SCRIPT}}?title=Special:Userlogin&returnto=Special:ArticleCreationLanding/{{PAGE}}',
167 - 'signup' => '{{SCRIPT}}?title=Special:Userlogin/signup&returnto=Special:ArticleCreationLanding/{{PAGE}}',
 167+ 'login' => '{{SCRIPT}}?title=Special:Userlogin&returnto=Special:ArticleCreationLanding/{{PAGE}}&returntoquery=' . urlencode( 'fromlogin=1' ),
 168+ 'signup' => '{{SCRIPT}}?title=Special:Userlogin/signup&returnto=Special:ArticleCreationLanding/{{PAGE}}&returntoquery=' . urlencode( 'fromsignup=1' ),
168169 'request' => 'http://google.com/?q={{PAGE}}'
169170 ),
170171 'buttons' => $wgArticleCreationButtons,
Index: trunk/extensions/ArticleCreationWorkflow/ArticleCreationWorkflow.hooks.php
@@ -62,8 +62,11 @@
6363 public static function resourceLoaderGetConfigVars( &$vars ) {
6464 global $wgArticleCreationConfig;
6565
66 - $vars['acConfig'] = $wgArticleCreationConfig;
 66+ $vars['acConfig'] = $wgArticleCreationConfig +
 67+ array('tracking-turned-on' => ArticleCreationUtil::trackingEnabled(),
 68+ 'tracking-code-prefix' => ArticleCreationUtil::trackingCodePrefix() );
6769
6870 return true;
6971 }
 72+
7073 }
Index: trunk/extensions/ArticleCreationWorkflow/SpecialArticleCreationLanding.php
@@ -14,7 +14,7 @@
1515 }
1616
1717 public function execute( $par ) {
18 - global $wgOut, $wgUser, $wgGroupPermissions;
 18+ global $wgOut, $wgUser, $wgRequest;
1919
2020 $title = Title::newFromText( $par );
2121
@@ -33,6 +33,8 @@
3434 $wgOut->addModules( 'ext.articleCreation.core' );
3535 $wgOut->addModules( 'ext.articleCreation.user' );
3636 $wgOut->addHtml( ArticleCreationTemplates::getLandingPage($par) );
 37+
 38+ ArticleCreationUtil::TrackSpecialLandingPage( $wgRequest, $wgUser );
3739 }
3840
3941 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r111136ArticleCreationWorkflow: Remove the $info parameter to ArticleCreationUtils::...werdna00:51, 10 February 2012

Status & tagging log