-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpecialEvents.page.php
More file actions
125 lines (108 loc) · 3.96 KB
/
SpecialEvents.page.php
File metadata and controls
125 lines (108 loc) · 3.96 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
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* Special page to display events.
* Events must be stored in articles with [[Category:Events]] and a category
* for the date, e.g. [[Category:2006/07/12]].
* The article can use any name, for example using subpages "Events/2006/07/12/Party at my house".
* Only the last part of the name is shown when displaying the title.
* This special page also uses my calendar extension to display a calendar.
*
* @file
* @ingroup Extensions
* @author Barrylb -- original code
* @author Jack Phoenix <jack@shoutwiki.com>
* @author Misza <misza@shoutwiki.com>
* @author Ryan Schmidt <skizzerz@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 SpecialEvents extends IncludableSpecialPage {
/**
* Constructor -- set up the new special page
*/
public function __construct() {
parent::__construct( 'Events' );
}
/**
* Show the special page
*
* @param mixed|null $par Parameter passed to the page, if any
*/
public function execute( $par ) {
global $wgParser;
$out = $this->getOutput();
$request = $this->getRequest();
$user = $this->getUser();
$year = $request->getInt( 'year' );
$month = $request->getInt( 'month' );
$month = ( $month < 10 ? '0' . $month : $month );
$day = $request->getInt( 'day' );
wfSuppressWarnings();
if ( $year == '' ) {
$year = date( 'Y' );
}
if ( $month == '' || $month == '00' ) {
$month = date( 'm' );
}
wfRestoreWarnings();
if ( $request->getVal( 'category' ) ) {
$catname = $request->getVal( 'category' );
} else {
$catname = $this->msg( 'events-categoryname' )->inContentLanguage()->plain();
}
# Don't show the navigation if we're including the page
if ( !$this->mIncluding ) {
$this->setHeaders();
$out->addModules( 'ext.calendar' );
$out->addWikiMsg( 'events-header' );
}
if ( $day == '' ) {
$mwCalendar = new mwCalendar();
$mwCalendar->dateNow( $month, $year );
$mwCalendar->showUpcoming( false );
$mwCalendar->setAjaxPrevNext( false );
$mwCalendar->setCategoryName( htmlspecialchars( $catname ) );
$out->addHTML( $mwCalendar->showThisMonth() );
$day = '__';
}
// Build the SQL query
$dbr = wfGetDB( DB_SLAVE );
$sPageTable = $dbr->tableName( 'page' );
$categorylinks = $dbr->tableName( 'categorylinks' );
$catname_safe = $dbr->strencode( $catname );
$year = intval( $year );
$month = intval( $month );
$day = intval( $day );
// @todo FIXME: query almost identical to mwCalendar::getUpcomingEvents()!
$sSqlSelect = "SELECT page_namespace, page_title, page_id, clike1.cl_to AS catlike1 ";
$sSqlSelectFrom = "FROM $sPageTable INNER JOIN $categorylinks AS c1 ON page_id = c1.cl_from AND c1.cl_to='$catname_safe' INNER JOIN $categorylinks " .
"AS clike1 ON page_id = clike1.cl_from AND clike1.cl_to LIKE '$year/$month/$day'";
$sSqlWhere = ' WHERE page_is_redirect = 0 ';
$sSqlOrderby = ' ORDER BY catlike1 ASC';
$res = $dbr->query(
$sSqlSelect . $sSqlSelectFrom . $sSqlWhere . $sSqlOrderby,
__METHOD__
);
// Informational message when there are no upcoming events (the SQL query
// above returned zero results)
if ( $dbr->numRows( $res ) == 0 ) {
$out->addHTML( $this->msg( 'events-no-upcoming-events' )->parse() );
return;
}
foreach ( $res as $row ) {
$title = Title::makeTitle( $row->page_namespace, $row->page_title );
$out->addHTML( '<div class="eventsblock">' );
$title_text = $title->getSubpageText();
$out->addHTML( '<b>' . Linker::linkKnown( $title, $title_text ) . '</b><br />' );
$wl_article = new Article( $title );
$wl = $wl_article->getContent();
$parserOptions = ParserOptions::newFromUser( $user );
$parserOptions->setEditSection( false );
$parserOptions->setTidy( true );
$parserOutput = $wgParser->parse( $wl, $title, $parserOptions );
$previewHTML = $parserOutput->getText();
$out->addHTML( $previewHTML );
$out->addHTML( '</div>' );
}
}
}