-
Notifications
You must be signed in to change notification settings - Fork 0
/
BooksOnlineOcdla.php
executable file
·125 lines (87 loc) · 3.4 KB
/
BooksOnlineOcdla.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
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
if ( !defined( 'MEDIAWIKI' ) )
die();
/**
* General extension information.
*/
$wgExtensionCredits['specialpage'][] = array(
'path' => __FILE__,
'name' => 'BooksOnlineOcdla',
'version' => '0.0.0.1',
'author' => 'José Bernal'
);
$dir = dirname( __FILE__ );
class BooksOnlineOcdla {
public static function isBonNamespace($ns) {
global $wgOcdlaBooksOnlineNamespaces;
return in_array($ns,$wgOcdlaBooksOnlineNamespaces);
}
public static function onParserSetup( Parser $parser ) {
// When the parser sees the <sample> tag, it executes renderTagSample (see below)
$parser->setHook( 'bon-update', 'BooksOnlineOcdla::renderTagBonUpdate' );
return true;
}
// Render <bon-update>
public static function renderTagBonUpdate( $input, array $args, Parser $parser, PPFrame $frame ) {
// Nothing exciting here, just escape the user-provided input and throw it back out again (as example)
// return htmlspecialchars( $input );
$month = $args['month'];
$year = $args['year'];
$deprecated = $args['deprecated'];
$output = $parser->recursiveTagParse( $input, $frame );
$title_parts = array($month, $year, "update");
$title_parts = array_filter($title_parts, function($part){ return !empty($part); });
$title_parts = array_map(function($part){ return ucwords($part); }, $title_parts);
$classes = array("bon-update");
if(!empty($year)) {
$classes []= sprintf("bon-update-%s", $year);
}
if(!empty($deprecated) && $deprecated === "true") {
$classes []= "bon-update-deprecated";
$title_parts []= "(deprecated)";
}
if(!empty($month) && !empty($year)) {
$classes []= sprintf("bon-update-%s-%s", $year, $month);
}
$classes = implode(" ", $classes);
$title = implode(" ", $title_parts);
return "<div class='{$classes}'><span class='bon-update-title'>{$title}</span>".$output."</div>";
}
public static function SetupBooksOnlineOcdla() {
global $wgHooks, $wgResourceModules, $wgOcdlaShowBooksOnlineDrawer;
// $wgHooks['SpecialSearchCreateLink'][] = 'SetupBooksOnlineOcdla::onSpecialSearchCreateLink';
$wgHooks['BeforePageDisplay'][] = 'BooksOnlineOcdla::onBeforePageDisplay';
$wgHooks['ParserFirstCallInit'][] = 'BooksOnlineOcdla::onParserSetup';
/*
$wgResourceModules['ext.booksOnlineOcdla.search'] = array(
'scripts' => array('js/books-online-view.js','js/books-online-loader.js','js/search.controller.js'),
'dependencies' => array('clickpdx.framework.js'),
'position' => 'top',
'remoteBasePath' => '/extensions/BooksOnlineOcdla',
'localBasePath' => 'extensions/BooksOnlineOcdla'
);
*/
$wgResourceModules['ext.booksOnlineOcdla.styles'] = array(
'styles' => array(
'css/bon.css'
),
'position' => 'top',
'remoteBasePath' => '/extensions/BooksOnlineOcdla',
'localBasePath' => 'extensions/BooksOnlineOcdla'
);
}
public static function onBeforePageDisplay(OutputPage &$out, Skin &$skin ) {
global $wgOcdlaShowBooksOnlineDrawer, $wgOcdlaShowBooksOnlineNs;
$checkNamespace = isset($wgOcdlaShowBooksOnlineNs) && $wgOcdlaShowBooksOnlineNs != NS_ALL;
$skin->customElements = array();
$title = $out->getTitle();
$ns = $title->getNamespace();
if(self::isBonNamespace($ns)) {
$out->addModules('ext.booksOnlineOcdla.styles');
} else {
// $out->addModules('ext.booksOnlineOcdla.banner');
}
// $out->addModules('ext.booksOnlineOcdla.search');
return true;
}
}