-
Notifications
You must be signed in to change notification settings - Fork 5
/
TrackMainPage.php
58 lines (52 loc) · 1.81 KB
/
TrackMainPage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* Track MainPage Extension - track link clicks on the Main Page
*
* @file
* @ingroup Extensions
* @version 1.0 (r22337)
* @author Przemek Piotrowski (Nef) <[email protected]>
*/
if ( !defined( 'MEDIAWIKI' ) ) {
die( 'This file is an extension to the MediaWiki software and cannot be used standalone.' );
}
// Extension credits that will show up on Special:Version
$wgExtensionCredits['other'][] = array(
'name' => 'TrackMainPage',
'version' => '1.0',
'author' => 'Przemek Piotrowski (Nef)',
'description' => 'Track link clicks on the Main Page',
'svn-date' => '$LastChangedDate: 2010-06-07 12:08:27 +0000 (Mon, 07 Jun 2010) $',
'svn-revision' => '$LastChangedRevision: 22337 $',
);
$wgHooks['SkinAfterBottomScripts'][] = 'wfTrackMainPageHook';
function wfTrackMainPageHook( $skin, &$text ) {
global $wgRequest;
if (
( Title::newMainPage()->getArticleId() == $skin->getTitle()->getArticleId() ) &&
( $wgRequest->getVal( 'action', 'view' ) == 'view' )
)
{
$text .= "<script type=\"text/javascript\">/*<![CDATA[*/
var wgServerRE = new RegExp( '^' + wgServer.replace( /\\\\/, '\\\\' ) );
var wgArticlePathRE = new RegExp( '^' + wgArticlePath.replace( /\\$1/, '' ).replace( /\\\\/, '\\\\' ) );
$( '#bodyContent a[href]' ).each( function( e ) {
//$( this ).css( 'background-color', 'yellow' );
if ( $( this ).parent().attr( 'class' ) == 'usermessage' ) {
// skip 'you have new mesages on wiki foo' box
} else {
var tracker = $( this ).attr( 'href' )
.replace( wgServerRE, '' )
.replace( wgArticlePathRE, '' )
.replace( /[\\/?&]/g, '_' );
$( this ).bind( 'click',
function( e ) {
WET.byStr( 'mainpage/' + tracker );
}
);
}
});
/*]]>*/</script>\n";
}
return true;
}