-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimelineHook.php
executable file
·88 lines (76 loc) · 3.38 KB
/
TimelineHook.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
86
87
88
<?php
if (!defined('MEDIAWIKI')) die();
class TimelineHook {
public static function init(Parser $parser) {
$parser->setHook('timeline', [self::class, 'timelineRender']);
}
public function timelineRender($input, array $args, Parser $parser, PPFrame $frame) {
$planetParam = (array_key_exists("planets", $args)) ? $args['planets'] : "";
$catParam = (array_key_exists("categories", $args)) ? $args['categories'] : "";
$showKey = (array_key_exists("key", $args)) ? $args['key'] : false;
$showAsList = false;
$height = "400px";
if (array_key_exists('list', $args) && strlen($args['list'])) {
$showAsList = (bool) $args['list'];
}
if (array_key_exists('height', $args) && strlen($args['height'])) {
$height = $args['height'];
}
if (strlen($planetParam)) $planetsList = "'".implode("','", explode(',', $planetParam))."'";
if (strlen($catParam)) $catList = "'".implode("','", explode(',', $catParam))."'";
if ($showKey || $showAsList) {
wfDebugLog('extensions', __METHOD__." List?: ".$list);
$db = wfGetDB(DB_SLAVE);
$results = TimelineLib::ursFetchTimelineData($db, $catList, $planetsList);
$html = '<h1><span class="mw-headline" id="Age_of_Colonization">Age of Colonization</span></h1>';
$curYear = 0;
global $wgParser, $wgUser, $wgTitle, $wgEnableParserCache;
$localParser = clone $wgParser;
$popts = new ParserOptions();
$popts->setTidy( true );
$popts->enableLimitReport(false);
while ($row = $results->fetchRow()) {
if ($row['start_year'] != $curYear) {
if ($row['start_year'] == "2210") {
$html .= '<h1><span class="mw-headline" id="Age_of_War">Age of War</span></h1>';
} else if ($row['start_year'] == "2361") {
$html .= '<h1><span class="mw-headline" id="Age_of_Betrayal">Age of Betrayal</span></h1>';
}
$html .= '</ul><h3><span class="mw-headline" id="'.$row['start_year'].'">'.$row['start_year'].'</span></h3><ul>';
$curYear = $row['start_year'];
}
$notes = $localParser->parse( $row['notes'], $wgTitle, $popts );
$hasMatched = preg_match("/<p>(.*)<\/p>/s", trim($notes->mText), $matches);
$html .= "<li> ".$matches[1]."</li>";
}
}
if ($showAsList) {
$html .= '</ul>';
return $html;
} else {
$planets = "";
if (strlen(trim($planetParam))) {
$planets = implode('|',explode(',', trim($planetParam)));
}
$categories = "";
if (strlen(trim($catParam))) {
$categories = implode('|',explode(',', trim($catParam)));
}
$output = '<div id="dynamic_timeline" class="timeline-default" style="height: '.$height.'; margin-top: 20px; margin-bottom: 50px;" data-planets="'.$planets.'" data-categories="'.$categories.'"></div>';
wfDebugLog('extensions', __METHOD__." Show Key?: ".$showKey);
if (strlen($showKey) && $showKey == "true") {
$output .= '<div id="timeline_view_key"><img src="/wiki/extensions/Timeline/timeline_js/images/icon-ship.png"/>Space Vehicles<br/>'.
'<img src="/wiki/extensions/Timeline/timeline_js/images/icon-un.png"/>UUHA<br/>'.
'<img src="/wiki/extensions/Timeline/timeline_js/images/icon-military.png"/>Military<br/>'.
'<img src="/wiki/extensions/Timeline/timeline_js/images/icon_baseball.png"/>Baseball</div>'.
'<div id="timeline_view_list">View as list</div>';
}
if ($showKey || $showAsList) {
$output .= '<noscript id="list_timeline">'.$html.'</noscript>';
}
return $output;
}
return "No Timeline available";
}
}
?>