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 |
1 | 68 | + native |
Index: trunk/extensions/ArticleCreationWorkflow/modules/ext.articleCreation.user/ext.articleCreation.user.js |
— | — | @@ -72,6 +72,10 @@ |
73 | 73 | return; |
74 | 74 | } |
75 | 75 | |
| 76 | + if ( ac.config['tracking-turned-on'] ) { |
| 77 | + jQuery.trackAction( ac.config['tracking-code-prefix'] + $(this).data('ac-button' ) + '-tooltip' ); |
| 78 | + } |
| 79 | + |
76 | 80 | $( this ) |
77 | 81 | //make it green |
78 | 82 | .addClass('ac-button-green') |
— | — | @@ -133,7 +137,11 @@ |
134 | 138 | urlTemplate = urlTemplate.replace( '{{PAGE}}', encodeURIComponent( article ) ); |
135 | 139 | urlTemplate = urlTemplate.replace( '{{USER}}', encodeURIComponent( wgUserName ) ); |
136 | 140 | 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 | + |
138 | 146 | window.location.href = urlTemplate; |
139 | 147 | }, |
140 | 148 | |
Index: trunk/extensions/ArticleCreationWorkflow/ArticleCreationWorkflow.php |
— | — | @@ -16,6 +16,7 @@ |
17 | 17 | |
18 | 18 | /* Object model */ |
19 | 19 | $wgAutoloadClasses['ArticleCreationTemplates'] = $articleCreationDir . 'includes/ArticleCreationTemplates.php'; |
| 20 | +$wgAutoloadClasses['ArticleCreationUtil'] = $articleCreationDir . 'includes/ArticleCreationUtil.php'; |
20 | 21 | |
21 | 22 | /* Special Pages */ |
22 | 23 | $wgAutoloadClasses['SpecialArticleCreationLanding'] = $articleCreationDir . 'SpecialArticleCreationLanding.php'; |
— | — | @@ -162,8 +163,8 @@ |
163 | 164 | 'action-url' => array( |
164 | 165 | 'draft' => '{{SCRIPT}}?title=User:{{USER}}/{{PAGE}}&action=edit', |
165 | 166 | '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' ), |
168 | 169 | 'request' => 'http://google.com/?q={{PAGE}}' |
169 | 170 | ), |
170 | 171 | 'buttons' => $wgArticleCreationButtons, |
Index: trunk/extensions/ArticleCreationWorkflow/ArticleCreationWorkflow.hooks.php |
— | — | @@ -62,8 +62,11 @@ |
63 | 63 | public static function resourceLoaderGetConfigVars( &$vars ) { |
64 | 64 | global $wgArticleCreationConfig; |
65 | 65 | |
66 | | - $vars['acConfig'] = $wgArticleCreationConfig; |
| 66 | + $vars['acConfig'] = $wgArticleCreationConfig + |
| 67 | + array('tracking-turned-on' => ArticleCreationUtil::trackingEnabled(), |
| 68 | + 'tracking-code-prefix' => ArticleCreationUtil::trackingCodePrefix() ); |
67 | 69 | |
68 | 70 | return true; |
69 | 71 | } |
| 72 | + |
70 | 73 | } |
Index: trunk/extensions/ArticleCreationWorkflow/SpecialArticleCreationLanding.php |
— | — | @@ -14,7 +14,7 @@ |
15 | 15 | } |
16 | 16 | |
17 | 17 | public function execute( $par ) { |
18 | | - global $wgOut, $wgUser, $wgGroupPermissions; |
| 18 | + global $wgOut, $wgUser, $wgRequest; |
19 | 19 | |
20 | 20 | $title = Title::newFromText( $par ); |
21 | 21 | |
— | — | @@ -33,6 +33,8 @@ |
34 | 34 | $wgOut->addModules( 'ext.articleCreation.core' ); |
35 | 35 | $wgOut->addModules( 'ext.articleCreation.user' ); |
36 | 36 | $wgOut->addHtml( ArticleCreationTemplates::getLandingPage($par) ); |
| 37 | + |
| 38 | + ArticleCreationUtil::TrackSpecialLandingPage( $wgRequest, $wgUser ); |
37 | 39 | } |
38 | 40 | |
39 | 41 | } |