summaryrefslogtreecommitdiff
blob: 88db0e55bbe515094b3006c7d8005d457b9c00e0 (plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php

class SpecialAnalytics extends SpecialPage {
	function __construct() {
		parent::__construct( 'Analytics' );
	}

	function execute( $par ) {
		$this->setHeaders();
		$this->outputHeader();

		$out = $this->getOutput();

		$out->addWikiMsg( 'matomoanalytics-header' );

		$options = [
			'browser' => 'Browser Usage',
			'devices' => 'Device Usage',
			'referrer' => 'Site Referrers',
			'search' => 'Search Engine Keywords',
			'social' => 'Social Network Referrals',
			'website' => 'Website Referrals',
			'continent' => 'Visits By Continent',
			'country' => 'Visits By Country',
			'visitday' => 'Visits By Day',
			'visithour' => 'Visits By Hour',
			'visitpages' => 'Number of Pages Accessed',
			'visitduration' => 'Length of Visits',
			'visitpass' => 'Time Between Visits',
			'visitcount' => 'Visits By User',
		];

		$optionDescriptor = [
			'statistic1' => [
				'type' => 'select',
				'name' => 'stat1',
				'label-message' => 'matomoanalytics-form-stat1',
				'options' => array_flip( $options ),
			],
			'statistic2' => [
				'type' => 'select',
				'name' => 'stat2',
				'label-message' => 'matomoanalytics-form-stat2',
				'options' => array_flip( $options ),
			],
		];

		$optionForm = HTMLForm::factory( 'ooui', $optionDescriptor, $this->getContext() );
		$optionForm->setSubmitCallback( [ $this, 'dummyHandler' ] )->setMethod( 'get' )->setFormIdentifier( 'optionForm' )->prepareForm()->show();

		$stat1 = $this->getRequest()->getText( 'stat1' );
		$stat2 = $this->getRequest()->getText( 'stat2' );

		if ( !in_array( '', array( $stat1, $stat2 ) ) ) {
			$statDescriptor = [];

			$stat1out = self::statisticReturn( $stat1 );
			foreach ( $stat1out as $label => $value ) {
				$statDescriptor[$label] = [
					'type' => 'info',
					'label' => $label,
					'default' => (string)$value,
					'section' => 'form-stat1',
				];
			}


			$stat2out = self::statisticReturn( $stat2 );
			foreach ( $stat2out as $label => $value ) {
				$statDescriptor[$label] = [
					'type' => 'info',
					'label' => $label,
					'default' => (string)$value,
					'section' => 'form-stat2',
				];
			}

			$statForm = HTMLForm::factory( 'ooui', $statDescriptor, $this->getContext(), 'matomoanalytics' );
			$statForm->setSubmitCallback( [ $this, 'dummyHandler' ] )->setMethod( 'get' )->setFormIdentifier( 'statForm' )->suppressDefaultSubmit()->prepareForm()->show();
		}

	}

	function dummyHandler( $formData ) {
		return false;
	}

	private function statisticReturn( $stat ) {
		global $wgDBname;

		switch ( $stat ) {
			case 'browser':
				$statarray = MatomoAnalytics::getBrowserTypes( $wgDBname );
				break;
			case 'devices':
				$statarray = MatomoAnalytics::getDeviceTypes( $wgDBname );
				break;
			case 'referrer':
				$statarray = MatomoAnalytics::getReferrerType( $wgDBname );
				break;
			case 'search':
				$statarray = MatomoAnalytics::getSearchKeywords( $wgDBname );
				break;
			case 'social':
				$statarray = MatomoAnalytics::getSocialReferrals( $wgDBname );
				break;
			case 'website':
				$statarray = MatomoAnalytics::getWebsiteReferrals( $wgDBname );
				break;
			case 'continent':
				$statarray = MatomoAnalytics::getUsersContinent( $wgDBname );
				break;
			case 'country':
				$statarray = MatomoAnalytics::getUsersCountry( $wgDBname );
				break;
			case 'visitday':
				$statarray = MatomoAnalytics::getVisitsByDay( $wgDBname );
				break;
			case 'visithour':
				$statarray = MatomoAnalytics::getVisitsPerServerHour( $wgDBname );
				break;
			case 'visitpages':
				$statarray = MatomoAnalytics::getVisitPages( $wgDBname );
				break;
			case 'visitduration':
				$statarray = MatomoAnalytics::getVisitDurations( $wgDBname );
				break;
			case 'visitpass':
				$statarray = MatomoAnalytics::getVisitDaysPassed( $wgDBname );
				break;
			case 'visitcount':
				$statarray = MatomoAnalytics::getVisitsCount( $wgDBname );
				break;
		}

		return $statarray;
	}
}