r54661 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54660‎ | r54661 | r54662 >
Date:14:23, 9 August 2009
Author:ialex
Status:deferred
Tags:
Comment:
* (bug 20145) Update Piwik Integration extension to work with Piwik 0.4
* deleted piwik-mw.js per request on the bug
Modified paths:
  • /trunk/extensions/Piwik/Piwik.php (modified) (history)
  • /trunk/extensions/Piwik/README (modified) (history)
  • /trunk/extensions/Piwik/piwik-mw.js (deleted) (history)

Diff [purge]

Index: trunk/extensions/Piwik/piwik-mw.js
@@ -1,220 +0,0 @@
2 -// Web analytics by Piwik - http://piwik.org
3 -// Copyleft 2007, All rights reversed.
4 -var _pk_use_title_as_name = 0;
5 -var _pk_install_tracker = 1;
6 -var _pk_tracker_pause = 500;
7 -var _pk_download_extensions = "7z|aac|avi|csv|doc|exe|flv|gif|gz|jpe?g|js|mp(3|4|e?g)|mov|pdf|phps|png|ppt|rar|sit|tar|torrent|txt|wma|wmv|xls|xml|zip";
8 -
9 -// Beginning script
10 -function _pk_plug_normal(_pk_pl) {
11 - if (_pk_tm.indexOf(_pk_pl) != -1 && (navigator.mimeTypes[_pk_pl].enabledPlugin != null))
12 - return '1';
13 - return '0';
14 -}
15 -
16 -function _pk_plug_ie(_pk_pl)
17 -{
18 - pk_found = false;
19 - document.write('<SCR' + 'IPT LANGUAGE=VBScript>\n on error resume next \n pk_found = IsObject(CreateObject("' + _pk_pl + '")) </SCR' + 'IPT>\n');
20 - if (pk_found) return '1';
21 - return '0';
22 -}
23 -
24 -var _pk_jav = '0'; if(navigator.javaEnabled()) _pk_jav='1';
25 -var _pk_agent = navigator.userAgent.toLowerCase();
26 -var _pk_moz = (navigator.appName.indexOf("Netscape") != -1);
27 -var _pk_ie = (_pk_agent.indexOf("msie") != -1);
28 -var _pk_win = ((_pk_agent.indexOf("win") != -1) || (_pk_agent.indexOf("32bit") != -1));
29 -var _pk_cookie = (navigator.cookieEnabled)? '1' : '0';
30 -if((typeof (navigator.cookieEnabled) == "undefined") && (_pk_cookie == '0')) {
31 - document.cookie="_pk_testcookie"
32 - _pk_cookie=(document.cookie.indexOf("_pk_testcookie")!=-1)? '1' : '0';
33 -}
34 -
35 -var _pk_dir='0',_pk_fla='0',_pk_pdf='0',_pk_qt = '0',_pk_rea = '0',_pk_wma='0';
36 -if (_pk_win && _pk_ie){
37 - _pk_dir = _pk_plug_ie("SWCtl.SWCtl.1");
38 - _pk_fla = _pk_plug_ie("ShockwaveFlash.ShockwaveFlash.1");
39 - if (_pk_plug_ie("PDF.PdfCtrl.1") == '1' || _pk_plug_ie('PDF.PdfCtrl.5') == '1' || _pk_plug_ie('PDF.PdfCtrl.6') == '1') _pk_pdf = '1';
40 - _pk_qt = _pk_plug_ie("Quicktime.Quicktime"); // Old : "QuickTimeCheckObject.QuickTimeCheck.1"
41 - _pk_rea = _pk_plug_ie("rmocx.RealPlayer G2 Control.1");
42 - _pk_wma = _pk_plug_ie("wmplayer.ocx"); // Old : "MediaPlayer.MediaPlayer.1"
43 -} else {
44 - var _pk_tm = '';
45 - for (var i=0; i < navigator.mimeTypes.length; i++)
46 - _pk_tm += navigator.mimeTypes[i].type.toLowerCase();
47 - _pk_dir = _pk_plug_normal("application/x-director");
48 - _pk_fla = _pk_plug_normal("application/x-shockwave-flash");
49 - _pk_pdf = _pk_plug_normal("application/pdf");
50 - _pk_qt = _pk_plug_normal("video/quicktime");
51 - _pk_rea = _pk_plug_normal("audio/x-pn-realaudio-plugin");
52 - _pk_wma = _pk_plug_normal("application/x-mplayer2");
53 -}
54 -
55 -var _pk_rtu = '';
56 -try {
57 - _pk_rtu = top.document.referrer;
58 -} catch(e1) {
59 - if(parent){
60 - try{ _pk_rtu = parent.document.referrer; } catch(e2) { _pk_rtu=''; }
61 - }
62 -}
63 -if(_pk_rtu == '') {
64 - _pk_rtu = document.referrer;
65 -}
66 -
67 -function _pk_escape(_pk_str){
68 - if(typeof(encodeURIComponent) == 'function') {
69 - return encodeURIComponent(_pk_str);
70 - } else {
71 - return escape(_pk_str);
72 - }
73 -}
74 -var _pk_title = '';
75 -if (document.title && document.title!="") _pk_title = _pk_escape(document.title);
76 -
77 -var _pk_called;
78 -
79 -function _pk_getUrlLog( _pk_action_name, _pk_site, _pk_pkurl, _pk_custom_vars )
80 -{
81 - var _pk_custom_vars_str = '';
82 - if(typeof _pk_custom_vars == "undefined"){
83 - _pk_custom_vars = false;
84 - }
85 - if (_pk_custom_vars) {
86 - for (var i in _pk_custom_vars){
87 - if (!Array.prototype[i]){
88 - _pk_custom_vars_str = _pk_custom_vars_str + '&vars['+ escape(i) + ']' + "=" + escape(_pk_custom_vars[i]);
89 - }
90 - }
91 - }
92 -
93 - var _pk_url = document.location.href;
94 - var _pk_da = new Date();
95 - var _pk_src = _pk_pkurl
96 - +'?url='+_pk_escape(document.location.href)
97 - +'&action_name='+_pk_escape(_pk_action_name)
98 - +'&idsite='+_pk_site
99 - +'&res='+screen.width+'x'+screen.height +'&col='+screen.colorDepth
100 - +'&h='+_pk_da.getHours()+'&m='+_pk_da.getMinutes()+'&s='+_pk_da.getSeconds()
101 - +'&fla='+_pk_fla+'&dir='+_pk_dir+'&qt='+_pk_qt+'&realp='+_pk_rea+'&pdf='+_pk_pdf
102 - +'&wma='+_pk_wma+'&java='+_pk_jav+'&cookie='+_pk_cookie
103 - +'&title='+_pk_title
104 - +'&urlref='+_pk_escape(_pk_rtu)
105 - +_pk_custom_vars_str;
106 - return _pk_src;
107 -}
108 -
109 -function piwik_log( _pk_action_name, _pk_site, _pk_pkurl, _pk_custom_vars )
110 -{
111 - if(_pk_called && (!_pk_action_name || _pk_action_name=="")) return;
112 - var _pk_src = _pk_getUrlLog(_pk_action_name, _pk_site, _pk_pkurl, _pk_custom_vars );
113 - document.writeln('<img src="'+_pk_src+'" alt="Piwik" style="border:0" />');
114 - if(!_pk_action_name || _pk_action_name=="") _pk_called=1;
115 -
116 - _pk_init_tracker(_pk_site, _pk_pkurl);
117 -}
118 -
119 -function _pk_add_event(elm, evType, fn, useCapture)
120 -{
121 - if (elm.addEventListener) {
122 - elm.addEventListener(evType, fn, useCapture);
123 - return true;
124 - } else if (elm.attachEvent) {
125 - var r = elm.attachEvent('on' + evType, fn);
126 - return r;
127 - } else {
128 - elm['on' + evType] = fn;
129 - }
130 -}
131 -
132 -var _pk_tracker_site, _pk_tracker_url;
133 -
134 -function _pk_init_tracker(_pk_site, _pk_pkurl)
135 -{
136 - if( typeof(piwik_install_tracker) != "undefined" )
137 - _pk_install_tracker = piwik_install_tracker;
138 - if( typeof(piwik_tracker_pause) != "undefined" )
139 - _pk_tracker_pause = piwik_tracker_pause;
140 - if( typeof(piwik_download_extensions) != "undefined" )
141 - _pk_download_extensions = piwik_download_extensions;
142 -
143 - _pk_hosts_alias = ( typeof(piwik_hosts_alias) != "undefined" ? piwik_hosts_alias : new Array())
144 - _pk_hosts_alias.push(window.location.hostname);
145 -
146 - if( !_pk_install_tracker )
147 - return;
148 -
149 - _pk_tracker_site = _pk_site;
150 - _pk_tracker_url = _pk_pkurl;
151 -
152 - if (document.getElementsByTagName) {
153 - linksElements = document.getElementsByTagName('a')
154 - for (var i = 0; i < linksElements.length; i++) {
155 - if( linksElements[i].className != 'piwik_ignore' )
156 - _pk_add_event(linksElements[i], 'mousedown', _pk_click, false);
157 - }
158 - }
159 -}
160 -
161 -function _pk_dummy() { return true; }
162 -
163 -function _pk_pause(_pk_time_msec) {
164 - var _pk_now = new Date();
165 - var _pk_expire = _pk_now.getTime() + _pk_time_msec;
166 - while(_pk_now.getTime() < _pk_expire)
167 - _pk_now = new Date();
168 -}
169 -
170 -// _pk_type only 'download' and 'link' types supported
171 -function piwik_track(url, _pk_site, _pk_url, _pk_type)
172 -{
173 - var _pk_image = new Image();
174 - _pk_image.onLoad = function() { _pk_dummy(); };
175 - _pk_image.src = _pk_url + '?idsite=' + _pk_site + '&' + _pk_type + '=' + escape(url) + '&rand=' + Math.random() + '&redirect=0';
176 - _pk_pause(_pk_tracker_pause);
177 -}
178 -
179 -function _pk_is_site_hostname(_pk_hostname) {
180 - for(i = 0; i < _pk_hosts_alias.length; i++)
181 - if( _pk_hostname == _pk_hosts_alias[i] )
182 - return true;
183 - return false;
184 -}
185 -
186 -function _pk_click(e)
187 -{
188 - var source;
189 -
190 - if (typeof e == 'undefined')
191 - var e = window.event;
192 -
193 - if (typeof e.target != 'undefined')
194 - source = e.target;
195 - else if (typeof e.srcElement != 'undefined')
196 - source = e.srcElement;
197 - else return true;
198 -
199 - while( source.tagName != "A" )
200 - source = source.parentNode;
201 -
202 - if( typeof source.href == 'undefined' )
203 - return true;
204 -
205 - var _pk_download = new RegExp('\\.(' + _pk_download_extensions + ')$', 'i');
206 - var _pk_link_type;
207 - var _pk_not_site_hostname = !_pk_is_site_hostname(source.hostname);
208 -
209 - if( source.className == "piwik_download" )
210 - _pk_link_type = 'download';
211 - else if( source.className == "image" ) {
212 - _pk_link_type = 'link';
213 - _pk_not_site_hostname = 0;
214 - }
215 - else _pk_link_type = (_pk_download.test(source.href) ? 'download' : 'link');
216 -
217 - if( _pk_not_site_hostname || _pk_link_type == 'download' )
218 - piwik_track(source.href, _pk_tracker_site, _pk_tracker_url, _pk_link_type);
219 -
220 - return true;
221 -}
Index: trunk/extensions/Piwik/Piwik.php
@@ -15,7 +15,7 @@
1616 $wgExtensionCredits['specialpage'][] = array(
1717 'path' => __FILE__,
1818 'name' => 'Piwik Integration',
19 - 'version' => '0.8-piwik0.2.26 (1.0-RC3)',
 19+ 'version' => '1.5-piwik0.4.2',
2020 'author' => 'Isb1009',
2121 'description' => 'Inserts Piwik script into MediaWiki pages for tracking and adds [[Special:Piwik|some stats]]. Based on Google Analytics Integration by Tim Laqua.',
2222 'descriptionmsg' => 'piwik-desc',
@@ -52,19 +52,24 @@
5353 }
5454 $funcOutput = <<<PIWIK
5555 <!-- Piwik -->
56 -<a href="http://piwik.org" title="Web analytics" onclick="window.open(this.href);return(false);">
57 -<script language="javascript" src="{$wgScriptPath}/extensions/piwik/piwik-mw.js" type="text/javascript"></script>
5856 <script type="text/javascript">
5957 /* <![CDATA[ */
60 -piwik_action_name = '{$wgPiwikFinalActionName}';
61 -piwik_idsite = {$wgPiwikIDSite};
62 -piwik_url = '{$wgPiwikURL}piwik.php';
63 -piwik_log(piwik_action_name, piwik_idsite, piwik_url);
 58+var pkBaseURL = (("https:" == document.location.protocol) ? "https://{$wgPiwikURL}" : "http://{$wgPiwikURL}");
 59+document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
 60+/* ]]> */
 61+</script>
 62+<script type="text/javascript">
 63+/* <![CDATA[ */
 64+try {
 65+var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", {$wgPiwikIDSite});
 66+piwikTracker.setDocumentTitle("{$wgPiwikFinalActionName}");
 67+piwikTracker.setIgnoreClasses("image");
6468 {$wgPiwikCustomJS}
 69+piwikTracker.trackPageView();
 70+piwikTracker.enableLinkTracking();
 71+} catch( err ) {}
6572 /* ]]> */
66 -</script><object>
67 -<noscript><p>Web analytics <img src="{$wgPiwikURL}/piwik.php" style="border:0" alt="piwik"/></p>
68 -</noscript></object></a>
 73+</script><noscript><p><img src="http://{$wgPiwikURL}piwik.php?idsite={$wgPiwikIDSite}" style="border:0" alt=""/></p></noscript>
6974 <!-- /Piwik -->
7075 PIWIK;
7176 } else {
Index: trunk/extensions/Piwik/README
@@ -1,7 +1,7 @@
22 MediaWiki Piwik Integration extension
33
4 -version 0.8-piwik0.2.26 (1.0-RC3)
5 -23 December 2008
 4+version 1.5-piwik0.4.2
 5+9 August 2009
66
77 This is the README file for the Piwik Integration extension for MediaWiki
88 software. The extension is only useful if you've got a MediaWiki
@@ -9,9 +9,9 @@
1010
1111 == Minimum requirements ==
1212
13 -* MediaWiki 1.11+
 13+* MediaWiki 1.14+
1414
15 -* A Piwik installation with the site configured
 15+* A Piwik (0.4+) installation with the site configured
1616
1717 == Installation instructions ==
1818
@@ -20,7 +20,7 @@
2121
2222 * Create a folder called "piwik" in your extensions directory
2323
24 -* Upload Piwik.php, Piwik.i18n.php, Piwik_specialpage.php and piwik-mw.js
 24+* Upload Piwik.php, Piwik.i18n.php, Piwik_specialpage.php and Piwik.alias.php
2525 to the "piwik" folder you've just created
2626
2727 * Edit your LocalSettings.php and, at the end of the file, add the
@@ -32,44 +32,42 @@
3333 * Then, you need to define where Piwik is installed and the "idsite".
3434 To do it, just add after the require_once:
3535
36 - $wgPiwikURL = "http://piwik/url/";
 36+ $wgPiwikURL = "piwik/url/"; //Don't include the protocol
3737 $wgPiwikIDSite = "piwik_idsite";
3838
39 - Note: Change the value of $wgPiwikURL with the URL where you installed
40 - Piwik. Remember to add the trailing slash!
 39+ Note: Change the value of $wgPiwikURL with the URL, without the protocol,
 40+ where you installed Piwik. Remember to add the trailing slash!
4141
42 - Change the value of $wgPiwikIDSite with the number inside
43 - "piwik_idsite" in your Piwik code. For example, in:
 42+ Change the value of $wgPiwikIDSite with your site ID.
 43+ For example, in:
4444
45 - <!-- Piwik -->
46 - <a href="http://piwik.org" title="Web analytics" onclick="window.open(this.href);return(false);">
47 - <script language="javascript" src="http://piwik/url/piwik.js" type="text/javascript"></script>
48 - <script type="text/javascript">
49 - <!--
50 - piwik_action_name = '';
51 - piwik_idsite = 1;
52 - piwik_url = 'http://piwik/url/piwik.php';
53 - piwik_log(piwik_action_name, piwik_idsite, piwik_url);
54 - //-->
55 - </script><object>
56 - <noscript><p>Web analytics <img src="http://stats.astronomipedia.es/piwik.php" style="border:0" alt="piwik"/></p>
57 - </noscript></object></a>
58 - <!-- /Piwik -->
 45+ <!-- Piwik -->
 46+ <script type="text/javascript">
 47+ var pkBaseURL = (("https:" == document.location.protocol) ? "https://piwik/url/" : "http://piwik/url/");
 48+ document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
 49+ </script><script type="text/javascript">
 50+ try {
 51+ var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 3);
 52+ piwikTracker.trackPageView();
 53+ piwikTracker.enableLinkTracking();
 54+ } catch( err ) {}
 55+ </script><noscript><p><img src="http://piwik/url/piwik.php?idsite=3" style="border:0" alt=""/></p></noscript>
 56+ <!-- End Piwik Tag -->
5957
60 - the $wgPiwikIDSite is 1
 58+ the $wgPiwikIDSite is 3
6159
6260
6361 * You can also set $wgPiwikCustomJS if you want to add custom javascript
64 - tags (see http://piwik.org/javascript-tag-documentation/ for further
 62+ tags (see http://piwik.org/docs/javascript-tracking/ for further
6563 information). For example:
6664
67 - $wgPiwikCustomJS = "piwik_hosts_alias = ["hostname1.com", "hostname2.com"]; // the current tracked website is added to this array anyway
68 - piwik_install_tracker = 0;"
 65+ $wgPiwikCustomJS = "piwikTracker.trackGoal(1); // logs a conversion for goal 1
 66+ piwikTracker.setDownloadExtensions( \"jpg|png|gif\" ); // we now only track clicks on images";
6967
70 -* If you want to change piwik_action_name, you can set $wgPiwikActionName
71 - inside your LocalSettings.php file.
 68+* If you want to change the title of your pages inside the Piwik tracker,
 69+ you can set $wgPiwikActionName inside your LocalSettings.php file.
7270
73 -** In case you want to include the piwik_action_name as, for example,
 71+** In case you want to include the title as, for example,
7472 "wiki/Title of the page", you can set $wgPiwikUsePageTitle to
7573 true and set $wgPiwikActionName to "wiki/". The extension will print
7674

Status & tagging log