-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApiCalendar.php
More file actions
112 lines (100 loc) · 2.7 KB
/
ApiCalendar.php
File metadata and controls
112 lines (100 loc) · 2.7 KB
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
<?php
/**
* Calendar API module
*
* @file
* @ingroup API
* @author Jack Phoenix <jack@shoutwiki.com>
* @date 23 July 2013
* @see https://www.mediawiki.org/wiki/API:Extensions#ApiSampleApiExtension.php
*/
class ApiCalendar extends ApiBase {
/**
* Main entry point.
*/
public function execute() {
$user = $this->getUser();
// Get the request parameters
$params = $this->extractRequestParams();
$month = $params['month'];
$year = $params['year'];
$categoryName = $params['category'];
$showUpcomingEvents = $params['upcoming'];
// Ensure that we have all the parameters we need to proceed
if (
!$month || $month === null || !is_numeric( $month ) ||
!$year || $year === null || !is_numeric( $year )
)
{
$this->dieUsageMsg( 'missingparam' );
}
// Lack of the category parameter is not a fatal error as we have a
// fallback for that...
if ( !$categoryName || $categoryName === null ) {
$categoryName = wfMessage( 'events-categoryname' )->inContentLanguage()->plain();
}
$mwCalendar = new mwCalendar();
$mwCalendar->dateNow( $month, $year );
$mwCalendar->setCategoryName( $categoryName );
$mwCalendar->setAjaxPrevNext( true );
if (
!isset( $showUpcomingEvents ) ||
isset( $showUpcomingEvents ) && $showUpcomingEvents == 'off'
)
{
$mwCalendar->showUpcoming( false );
} else {
$mwCalendar->showUpcoming( true );
}
$mwCalendar->showCalendar( true );
// Top level
$this->getResult()->addValue( null, $this->getModuleName(),
array( 'result' => $mwCalendar->showThisMonth() )
);
return true;
}
/**
* @return string Human-readable module description
*/
public function getDescription() {
return 'Calendar API';
}
/**
* @return array
*/
public function getAllowedParams() {
return array(
'month' => array(
ApiBase::PARAM_TYPE => 'integer',
ApiBase::PARAM_REQUIRED => true,
ApiBase::PARAM_MIN => 1,
ApiBase::PARAM_MAX => 12,
),
'year' => array(
ApiBase::PARAM_TYPE => 'integer',
ApiBase::PARAM_REQUIRED => true,
),
'category' => array(
ApiBase::PARAM_TYPE => 'string',
),
'upcoming' => array(
ApiBase::PARAM_TYPE => 'boolean',
)
);
}
// Describe the parameters
public function getParamDescription() {
return array_merge( parent::getParamDescription(), array(
'month' => 'Month (1 = January; 12 = December)',
'year' => 'Year',
'category' => 'Category name',
'upcoming' => 'Whether to show upcoming events or not',
) );
}
// Get examples
public function getExamples() {
return array(
'api.php?action=calendar&year=2013&month=8&categoryName=Meetings&upcoming=off' => 'Shows events in August 2013 from the category "Meetings" without showing upcoming events',
);
}
}