Index: trunk/extensions/ContributionTracking/ContributionTracking.sql |
— | — | @@ -1,4 +1,4 @@ |
2 | | -CREATE TABLE `contribution_tracking` ( |
| 2 | +CREATE TABLE IF NOT EXISTS /*_*/`contribution_tracking` ( |
3 | 3 | `id` int(10) unsigned NOT NULL auto_increment, |
4 | 4 | `contribution_id` int(10) unsigned default NULL, |
5 | 5 | `note` text, |
Index: trunk/extensions/ContributionTracking/ContributionTracking_body.php |
— | — | @@ -5,6 +5,28 @@ |
6 | 6 | parent::__construct( 'ContributionTracking' ); |
7 | 7 | } |
8 | 8 | |
| 9 | + function get_owa_ref_id($ref){ |
| 10 | + // Replication lag means sometimes a new event will not exist in the table yet |
| 11 | + $dbw = wfGetDB( DB_MASTER ); |
| 12 | + $id_num = $dbw->selectField( |
| 13 | + 'contribution_tracking_owa_ref', |
| 14 | + 'id', |
| 15 | + array( 'url' => $ref ), |
| 16 | + __METHOD__ |
| 17 | + ); |
| 18 | + // Once we're on mysql 5, we can use replace() instead of this selectField --> insert or update hooey |
| 19 | + if ( $id_num === false ) { |
| 20 | + $dbw->insert( |
| 21 | + 'contribution_tracking_owa_ref', |
| 22 | + array( 'url' => (string) $event_name ), |
| 23 | + __METHOD__ |
| 24 | + ); |
| 25 | + $id_num = $dbw->insertId(); |
| 26 | + } |
| 27 | + return $id_num === false ? 0 : $id_num; |
| 28 | + } |
| 29 | + |
| 30 | + |
9 | 31 | function execute( $language ) { |
10 | 32 | global $wgRequest, $wgOut; |
11 | 33 | wfLoadExtensionMessages( 'ContributionTracking' ); |
— | — | @@ -28,6 +50,11 @@ |
29 | 51 | |
30 | 52 | $ts = $db->timestamp(); |
31 | 53 | |
| 54 | + $owa_ref = $wgRequest->getText('owa_ref', null); |
| 55 | + if($owa_ref != null && !is_numeric($owa_ref)){ |
| 56 | + $owa_ref = $this->get_owa_ref_id($owa_ref); |
| 57 | + } |
| 58 | + |
32 | 59 | $tracked_contribution = array( |
33 | 60 | 'note' => $wgRequest->getText('comment', null), |
34 | 61 | 'referrer' => $wgRequest->getText('referrer', null), |
— | — | @@ -38,7 +65,7 @@ |
39 | 66 | 'optout' => ($wgRequest->getCheck('email-opt', 0) ? 0 : 1), |
40 | 67 | 'language' => $wgRequest->getText('language', null), |
41 | 68 | 'owa_session' => $wgRequest->getText('owa_session', null), |
42 | | - 'owa_ref' => $wgRequest->getText('owa_ref', null), |
| 69 | + 'owa_ref' => $owa_ref, |
43 | 70 | 'ts' => $ts, |
44 | 71 | ); |
45 | 72 | |
— | — | @@ -141,6 +168,7 @@ |
142 | 169 | return wfMsgExt( $key, array( 'escape', 'language' => $this->lang ) ); |
143 | 170 | } |
144 | 171 | |
| 172 | + |
145 | 173 | function msgWiki( $key ) { |
146 | 174 | return wfMsgExt( $key, array( 'parse', 'language' => $this->lang ) ); |
147 | 175 | } |
Index: trunk/extensions/ContributionTracking/ContributionTracking.php |
— | — | @@ -46,6 +46,28 @@ |
47 | 47 | |
48 | 48 | } |
49 | 49 | |
| 50 | + //convert a referrer URL to an index in the owa_ref table |
| 51 | +function ef_contribution_tracking_owa_get_ref_id($ref){ |
| 52 | + // Replication lag means sometimes a new event will not exist in the table yet |
| 53 | + $dbw = wfGetDB( DB_MASTER ); |
| 54 | + $id_num = $dbw->selectField( |
| 55 | + 'contribution_tracking_owa_ref', |
| 56 | + 'id', |
| 57 | + array( 'url' => $ref ), |
| 58 | + __METHOD__ |
| 59 | + ); |
| 60 | + // Once we're on mysql 5, we can use replace() instead of this selectField --> insert or update hooey |
| 61 | + if ( $id_num === false ) { |
| 62 | + $dbw->insert( |
| 63 | + 'contribution_tracking_owa_ref', |
| 64 | + array( 'url' => (string) $event_name ), |
| 65 | + __METHOD__ |
| 66 | + ); |
| 67 | + $id_num = $dbw->insertId(); |
| 68 | + } |
| 69 | + return $id_num === false ? 0 : $id_num; |
| 70 | + } |
| 71 | + |
50 | 72 | function contributionTrackingConnection() { |
51 | 73 | global $wgContributionTrackingDBserver, $wgContributionTrackingDBname; |
52 | 74 | global $wgContributionTrackingDBuser, $wgContributionTrackingDBpassword; |