-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalendarHooks.php
85 lines (74 loc) · 2.21 KB
/
CalendarHooks.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
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
<?php
/**
* Calendar hooks wrapper class
* All functions are public and static.
*
* @file
* @ingroup Extensions
* @author Jack Phoenix <jack@shoutwiki.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
* @link https://www.mediawiki.org/wiki/Extension:Calendar_(Barrylb) Documentation
*/
class CalendarHooks {
/**
* Set up the new <calendar/> parser hook
*
* @param Parser $parser
* @return bool
*/
public static function registerTag( &$parser ) {
$parser->setHook( 'calendar', array( 'CalendarHooks', 'createCalendar' ) );
return true;
}
# The callback function for converting the input text to HTML output
public static function createCalendar( $input, $args, $parser ) {
global $wgRequest;
/**
* Check if the date was supplied in $_GET parameter
* fallback on default this month
*/
$year = $wgRequest->getInt( 'year' );
$month = $wgRequest->getInt( 'month' );
if ( $month && ( isset( $year ) ) ) {
$month = ( $month < 10 ? '0' . $month : $month );
$year = $wgRequest->getInt( 'year' );
} else {
wfSuppressWarnings();
$month = date( 'm' );
$year = date( 'Y' );
wfRestoreWarnings();
}
// Add CSS & JS
$parser->getOutput()->addModules( 'ext.calendar' );
$mwCalendar = new mwCalendar();
$mwCalendar->dateNow( $month, $year );
$categoryName = ( isset( $args['category'] ) ? $args['category'] : false );
if ( $categoryName ) {
$mwCalendar->setCategoryName( $categoryName ); //CATNAME NEVER GETS VALIDATED SO BE SURE TO ESCAPE IT UPON USE!!!!!
}
if (
isset( $args['ajaxprevnext'] ) &&
( $args['ajaxprevnext'] !== false || $args['ajaxprevnext'] == 'on' )
)
{
$mwCalendar->setAjaxPrevNext( true );
} else {
$mwCalendar->setAjaxPrevNext( false );
}
if (
isset( $args['upcoming'] ) &&
( $args['upcoming'] !== false || $args['upcoming'] == 'on' )
)
{
$mwCalendar->showUpcoming( true );
} else {
$mwCalendar->showUpcoming( false );
}
// Show calendar by default unless explicitly requested not to
$mwCalendar->showCalendar( true );
if ( isset( $args['calendar'] ) && $args['calendar'] == 'off' ) {
$mwCalendar->showCalendar( false );
}
return $mwCalendar->showThisMonth();
}
}