/
HuijiMiddleware.hooks.php
174 lines (158 loc) · 6.11 KB
/
HuijiMiddleware.hooks.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
/**
* Hooks for Example extension
*
* @file
* @ingroup Extensions
*/
class HuijiHooks {
public static function onSpecialSearchResultsPrepend( $specialSearch, $output, $term ) {
global $wgServer, $wgSitename;
$globalSearch = SpecialPage::getTitleFor('GlobalSearch');
$url = htmlspecialchars( $globalSearch->getFullURL("key={$term}") );
$link = "<a href=\"{$url}\">".wfMessage('global-search-link')->params($term)->text()."</a>";
$globalSearchNotice = wfMessage('global-search-notice')->params( $wgSitename, $link )->text();
$output->addHtml('<p class="global-search-notice">'.$globalSearchNotice.'</p>');
return true;
}
public static function addTables( $updater ) {
$dbt = $updater->getDB()->getType();
$file = __DIR__ . "/../VoteNY/vote.$dbt";
echo $file;
if ( file_exists( $file ) ) {
$updater->addExtensionUpdate( array( 'addTable', 'Vote', $file, true ) );
} else {
throw new MWException( "VoteNY does not support $dbt." );
}
$file = __DIR__ ."/../PollNY/poll.sql";
echo $file;
$updater->addExtensionUpdate( array( 'addTable', 'poll_choice', $file, true ) );
$updater->addExtensionUpdate( array( 'addTable', 'poll_question', $file, true ) );
$updater->addExtensionUpdate( array( 'addTable', 'poll_user_vote', $file, true ) );
return true;
}
public static function onGetDoubleUnderscoreIDs( &$doubleUnderscoreIDs ) {
$doubleUnderscoreIDs[] = 'norec';
$doubleUnderscoreIDs[] = 'rec';
return true;
}
public static function onOpenSearchUrls( &$urls ) {
global $wgHuijiPrefix;
if ($wgHuijiPrefix = 'www' || $wgHuijiPrefix = 'zs.test'){
$urls = array(array(
'type' => 'text/html',
'method' => 'get',
'template' => SpecialPage::getTitleFor('GlobalSearch')->getCanonicalURL( 'key={searchTerms}' )
));
}
}
public static function onRegisterMagicWords( &$magicWordsIds ) {
// Add the following to a wiki page to see how it works:
// {{MYWORD}}
$magicWordsIds[] = 'numberoffollowers';
$magicWordsIds[] = 'numberoffollowers:r';
$magicWordsIds[] = 'numberofalledits';
$magicWordsIds[] = 'numberofallarticles';
$magicWordsIds[] = 'numberofallactiveusers';
$magicWordsIds[] = 'numberofallfiles';
$magicWordsIds[] = 'numberofallsites';
$magicWordsIds[] = 'sitedescription';
return true;
}
public static function onParserGetVariableValueSwitch( &$parser, &$cache, &$magicWordId, &$ret ) {
global $wgHuijiPrefix;
// Return value and cache should match. Cache is used to save
// additional call when it is used multiple times on a page.
$huijiStats = Huiji::getInstance()->getStats();
if ( $magicWordId === 'numberofalledits' ) {
$ret = $cache['numberofalledits'] = $huijiStats['edits'];
}
if ( $magicWordId === 'numberofallarticles' ) {
$ret = $cache['numberofallarticles'] = $huijiStats['pages'];
}
if ( $magicWordId === 'numberofallactiveusers' ) {
$ret = $cache['numberofallactiveusers'] = $huijiStats['users'];
}
if ( $magicWordId === 'numberofallfiles' ) {
$ret = $cache['numberofallfiles'] = $huijiStats['files'];
}
if ( $magicWordId === 'numberofallsites' ) {
$ret = $cache['numberofallsites'] = $huijiStats['sites'];
}
if ( $magicWordId === 'numberoffollowers' ) {
$site = WikiSite::newFromPrefix($wgHuijiPrefix);
$stats = $site->getStats();
$ret = $cache['numberoffollowers'] = $stats['followers'];
}
if ( $magicWordId === 'numberoffollowers:r' ) {
$site = WikiSite::newFromPrefix($wgHuijiPrefix);
$stats = $site->getStats(false);
$ret = $cache['numberoffollowers'] = $stats['followers'];
}
if ( $magicWordId === 'sitedescription') {
$site = WikiSite::newFromPrefix($wgHuijiPrefix);
$ret = $cache['sitedescription'] = $site->getDescription();
}
return true;
}
public static function onSetupParserFunction( &$parser ){
$parser->setFunctionHook( 'css', 'HuijiHooks::renderObseleteParserFunction' );
}
public static function renderObseleteParserFunction($parser, $stuff){
return array( "<!-- #CSS is obselete and no longer supported, please remove it -->", 'noparse' => true, 'isHTML' => true );
}
public static function onAPIQuerySiteInfoGeneralInfo($api, &$data){
global $wgHuijiPrefix, $wgDefaultSiteProperty;
if (class_exists("TransSite")){
$site = TransSite::newFromPrefix($wgHuijiPrefix);
} else {
$site = WikiSite::newFromPrefix($wgHuijiPrefix);
}
$data['group'] = $site->getGroup();
$data['prefix'] = $site->getPrefix();
$data['avatar'] = array(
"l" => $site->getAvatar('l')->getAvatarUrlPath(),
"ml" => $site->getAvatar('ml')->getAvatarUrlPath(),
"m" => $site->getAvatar('m')->getAvatarUrlPath(),
"s" => $site->getAvatar('s')->getAvatarUrlPath(),
);
foreach($wgDefaultSiteProperty as $key => $property){
$data['property'][$key] = $site->getProperty($key);
}
}
public static function onAPIQuerySiteInfoStatisticsInfo(&$data){
global $wgHuijiPrefix;
$site = WikiSite::newFromPrefix($wgHuijiPrefix);
$stats = $site->getStats(false);
$data['followers'] = (int)$stats['followers'];
$data['rating'] = $site->getRating();
$data['score'] = (int)$site->getScore();
$data['donate'] = (int)$site->getDonationSum();
$month = date('Y-m', time());
$month -= 1;
$data['donategoalmet'] = (bool)($site->hasMetDonationGoal($month)==false)?"false":"true";
}
public static function onGetPreferences( $user, &$preferences ){
// $preferences['usecodemirror'] = array(
// 'type' => 'toggle',
// 'label-message' => 'usecodemirror-pref',
// 'section' => "editing/advancedediting"
// );
$preferences['showeditcss'] = array(
'type' => 'toggle',
'label-message' => 'showeditcss-pref',
'section' => "rendering/advancedrendering"
);
$preferences['showeditjs'] = array(
'type' => 'toggle',
'label-message' => 'showeditjs-pref',
'section' => "rendering/advancedrendering"
);
// $preferences['mypref'] = array(
// 'type' => 'toggle',
// 'label-message' => 'tog-mypref', // a system message
// 'section' => 'personal/info',
// );
return true;
}
}