Index: trunk/extensions/WikiForum/WikiForum.php |
— | — | @@ -6,7 +6,7 @@ |
7 | 7 | * @ingroup Extensions |
8 | 8 | * @author Michael Chlebek |
9 | 9 | * @author Jack Phoenix <jack@countervandalism.net> |
10 | | - * @date 23 December 2010 (date of this build: 22 January 2011) |
| 10 | + * @date 6 October 2011 |
11 | 11 | * @version 1.2-SW |
12 | 12 | * @copyright Copyright © 2010 Unidentify Studios |
13 | 13 | * @copyright Copyright © 2010-2011 Jack Phoenix <jack@countervandalism.net> |
— | — | @@ -44,6 +44,7 @@ |
45 | 45 | $dir = dirname( __FILE__ ) . '/'; |
46 | 46 | $wgExtensionMessagesFiles['WikiForum'] = $dir . 'WikiForum.i18n.php'; |
47 | 47 | $wgExtensionAliasesFiles['WikiForum'] = $dir . 'WikiForum.alias.php'; |
| 48 | +$wgAutoloadClasses['WikiForumHooks'] = $dir . 'WikiForumHooks.php'; |
48 | 49 | $wgAutoloadClasses['WikiForumGui'] = $dir . 'WikiForumGui.php'; |
49 | 50 | $wgAutoloadClasses['WikiForumClass'] = $dir . 'WikiForumClass.php'; |
50 | 51 | $wgAutoloadClasses['WikiForum'] = $dir . 'SpecialWikiForum.php'; |
— | — | @@ -81,294 +82,7 @@ |
82 | 83 | ); |
83 | 84 | |
84 | 85 | // Hooked functions |
85 | | -$wgHooks['ParserFirstCallInit'][] = 'wfWikiForumTags'; |
86 | | -$wgHooks['SkinTemplateBuildNavUrlsNav_urlsAfterPermalink'][] = 'wfSpecialWikiForumNav'; |
87 | | -$wgHooks['SkinTemplateToolboxEnd'][] = 'wfSpecialWikiForumToolbox'; |
88 | | - |
89 | | -// @todo FIXME: Move hook methods to a hook class. |
90 | | - |
91 | | -/** |
92 | | - * Set up the two new parser hooks: <WikiForumList> and <WikiForumThread> |
93 | | - * |
94 | | - * @param $parser Object: instance of Parser |
95 | | - * @return Boolean: true |
96 | | - */ |
97 | | -function wfWikiForumTags( &$parser ) { |
98 | | - $parser->setHook( 'WikiForumList', 'renderWikiForumList' ); |
99 | | - $parser->setHook( 'WikiForumThread', 'renderWikiForumThread' ); |
100 | | - return true; |
101 | | -} |
102 | | - |
103 | | -/** |
104 | | - * Adds a link to Special:WikiForum to the toolbox, after permalink. |
105 | | - * Both this and the function below are required to render the link in the |
106 | | - * toolbox. |
107 | | - * |
108 | | - * @param $skinTemplate Object: SkinTemplate instance |
109 | | - * @param $nav_urls Array: existing navigation URLs |
110 | | - * @param $oldid Integer |
111 | | - * @param $revid Integer: revision ID number of the current revision |
112 | | - * @return Boolean: true |
113 | | - */ |
114 | | -function wfSpecialWikiForumNav( &$skinTemplate, &$nav_urls, &$oldid, &$revid ) { |
115 | | - $nav_urls['wikiforum'] = array( |
116 | | - 'text' => wfMsg( 'wikiforum' ), |
117 | | - 'href' => $skinTemplate->makeSpecialUrl( 'WikiForum' ) |
118 | | - ); |
119 | | - return true; |
120 | | -} |
121 | | - |
122 | | -/** |
123 | | - * Adds a link to Special:WikiForum to the toolbox, after permalink. |
124 | | - * Both this and the function above are required to render the link in the |
125 | | - * toolbox. |
126 | | - * |
127 | | - * @param $skinTemplate Object: instance of SkinTemplate class |
128 | | - * @return Boolean: true |
129 | | - */ |
130 | | -function wfSpecialWikiForumToolbox( &$skinTemplate ) { |
131 | | - if ( isset( $skinTemplate->data['nav_urls']['wikiforum'] ) ) { |
132 | | - if ( $skinTemplate->data['nav_urls']['wikiforum']['href'] == '' ) { |
133 | | - echo '<li id="t-iswikiforum">' . wfMsg( 'wikiforum' ) . '</li>'; |
134 | | - } else { |
135 | | - $url = $skinTemplate->data['nav_urls']['wikiforum']['href']; |
136 | | - echo '<li id="t-wikiforum"><a href="' . htmlspecialchars( $url ) . '">'; |
137 | | - echo wfMsg( 'wikiforum' ); |
138 | | - echo '</a></li>'; |
139 | | - } |
140 | | - } |
141 | | - return true; |
142 | | -} |
143 | | - |
144 | | -/** |
145 | | - * Callback for <WikiForumList> tag. |
146 | | - * Takes only the following argument: num (used as the LIMIT for the SQL query) |
147 | | - */ |
148 | | -function renderWikiForumList( $input, $args, $parser, $frame ) { |
149 | | - global $wgUser, $wgLang, $wgScriptPath; |
150 | | - |
151 | | - if ( !isset( $args['num'] ) ) { |
152 | | - $args['num'] = 5; |
153 | | - } |
154 | | - |
155 | | - $dbr = wfGetDB( DB_SLAVE ); |
156 | | - $sqlThreads = $dbr->select( |
157 | | - array( |
158 | | - 'wikiforum_forums', 'wikiforum_category', 'wikiforum_threads', |
159 | | - 'user' |
160 | | - ), |
161 | | - array( |
162 | | - '*', 'wff_forum', 'wff_forum_name', 'wfc_category', |
163 | | - 'wfc_category_name', 'user_name' |
164 | | - ), |
165 | | - array( |
166 | | - 'wff_deleted' => 0, |
167 | | - 'wfc_deleted' => 0, |
168 | | - 'wft_deleted' => 0, |
169 | | - 'wff_category = wfc_category', |
170 | | - 'wff_forum = wft_forum' |
171 | | - ), |
172 | | - __METHOD__, |
173 | | - // it's either wff or wft, I'm not 100% sure which one so I just picked |
174 | | - // one of them... |
175 | | - array( |
176 | | - 'ORDER BY' => 'wff_last_post_timestamp DESC', |
177 | | - 'LIMIT' => intval( $args['num'] ) |
178 | | - ), |
179 | | - array( 'user' => array( 'LEFT JOIN', 'user_id = wft_user' ) ) |
180 | | - ); |
181 | | - |
182 | | - $output = WikiForumGui::getMainPageHeader( |
183 | | - wfMsg( 'wikiforum-updates' ), |
184 | | - wfMsg( 'wikiforum-replies' ), |
185 | | - wfMsg( 'wikiforum-views' ), |
186 | | - wfMsg( 'wikiforum-latest-reply' ) |
187 | | - ); |
188 | | - |
189 | | - foreach ( $sqlThreads as $thread ) { |
190 | | - $icon = WikiForumClass::getThreadIcon( |
191 | | - $thread->wft_posted_timestamp, |
192 | | - $thread->wft_closed, |
193 | | - $thread->wft_sticky |
194 | | - ); |
195 | | - |
196 | | - $lastpost = ''; |
197 | | - // If there are some replies, then we can obviously figure out who was |
198 | | - // the last user who posted something on the topic... |
199 | | - if ( $thread->wft_reply_count > 0 ) { |
200 | | - $lastpost = wfMsg( |
201 | | - 'wikiforum-by', |
202 | | - $wgLang->timeanddate( $thread->wft_last_post_timestamp ), |
203 | | - WikiForumClass::getUserLinkById( $thread->wft_last_post_user ) |
204 | | - ); |
205 | | - } |
206 | | - |
207 | | - $specialPageObj = SpecialPage::getTitleFor( 'WikiForum' ); |
208 | | - $sk = $wgUser->getSkin(); |
209 | | - // Build the links to the category and forum pages by using Linker |
210 | | - $categoryLink = $sk->link( |
211 | | - $specialPageObj, |
212 | | - $thread->wfc_category_name, |
213 | | - array(), |
214 | | - array( 'category' => $thread->wfc_category ) |
215 | | - ); |
216 | | - $forumLink = $sk->link( |
217 | | - $specialPageObj, |
218 | | - $thread->wff_forum_name, |
219 | | - array(), |
220 | | - array( 'forum' => $thread->wff_forum ) |
221 | | - ); |
222 | | - $threadLink = $sk->link( |
223 | | - $specialPageObj, |
224 | | - $thread->wft_thread_name, |
225 | | - array(), |
226 | | - array( 'thread' => $thread->wft_thread ) |
227 | | - ); |
228 | | - |
229 | | - $output .= WikiForumGui::getMainBody( |
230 | | - '<p class="mw-wikiforum-thread">' . $icon . $threadLink . |
231 | | - '<p class="mw-wikiforum-descr" style="border-top: 0;">' . |
232 | | - wfMsg( |
233 | | - 'wikiforum-posted', |
234 | | - $wgLang->timeanddate( $thread->wft_posted_timestamp ), |
235 | | - WikiForumClass::getUserLink( $thread->user_name ) |
236 | | - ) . '<br />' . |
237 | | - wfMsgHtml( 'wikiforum-forum', $categoryLink, $forumLink ) . |
238 | | - '</p></p>', |
239 | | - $thread->wft_reply_count, |
240 | | - $thread->wft_view_count, |
241 | | - $lastpost, |
242 | | - false, |
243 | | - false |
244 | | - ); |
245 | | - } |
246 | | - $output .= WikiForumGui::getMainPageFooter(); |
247 | | - |
248 | | - return $output; |
249 | | -} |
250 | | - |
251 | | -/** |
252 | | - * Callback for the <WikiForumThread> hook. |
253 | | - * Takes the following arguments: id (ID number of the thread, used in SQL |
254 | | - * query), replies (whether to display replies) |
255 | | - */ |
256 | | -function renderWikiForumThread( $input, $args, $parser, $frame ) { |
257 | | - global $wgOut, $wgLang, $wgScriptPath; |
258 | | - |
259 | | - if ( isset( $args['id'] ) && $args['id'] > 0 ) { |
260 | | - $dbr = wfGetDB( DB_SLAVE ); |
261 | | - $sqlThreads = $dbr->select( |
262 | | - array( 'wikiforum_forums', 'wikiforum_category', 'wikiforum_threads', 'user' ), |
263 | | - array( |
264 | | - 'wft_thread', 'wft_thread_name', 'wft_text', 'wff_forum', |
265 | | - 'wff_forum_name', 'wfc_category', 'wfc_category_name', |
266 | | - 'user_name', 'user_id', 'wft_edit_timestamp', 'wft_edit_user', |
267 | | - 'wft_posted_timestamp', 'wft_user', 'wft_closed', |
268 | | - 'wft_closed_user' |
269 | | - ), |
270 | | - array( |
271 | | - 'wff_deleted' => 0, |
272 | | - 'wfc_deleted' => 0, |
273 | | - 'wft_deleted' => 0, |
274 | | - 'wff_category = wfc_category', |
275 | | - 'wff_forum = wft_forum', |
276 | | - 'wft_thread' => intval( $args['id'] ) |
277 | | - ), |
278 | | - __METHOD__, |
279 | | - array(), |
280 | | - array( 'user' => array( 'LEFT JOIN', 'user_id = wft_user' ) ) |
281 | | - ); |
282 | | - $overview = $dbr->fetchObject( $sqlThreads ); |
283 | | - |
284 | | - if ( $overview ) { |
285 | | - $posted = wfMsg( |
286 | | - 'wikiforum-posted', |
287 | | - $wgLang->timeanddate( $overview->wft_posted_timestamp ), |
288 | | - WikiForumClass::getUserLink( $overview->user_name ) |
289 | | - ); |
290 | | - if ( $overview->wft_edit_timestamp > 0 ) { |
291 | | - $posted .= '<br /><i>' . |
292 | | - wfMsg( |
293 | | - 'wikiforum-edited', |
294 | | - $wgLang->timeanddate( $overview->wft_edit_timestamp ), |
295 | | - WikiForumClass::getUserLinkById( $overview->wft_edit_user ) |
296 | | - ) . '</i>'; |
297 | | - } |
298 | | - |
299 | | - $output = WikiForumGui::getHeaderRow( |
300 | | - $overview->wfc_category, |
301 | | - $overview->wfc_category_name, |
302 | | - $overview->wff_forum, |
303 | | - $overview->wff_forum_name, |
304 | | - false |
305 | | - ); |
306 | | - |
307 | | - $specialPageObj = SpecialPage::getTitleFor( 'WikiForum' ); |
308 | | - $link = $specialPageObj->escapeFullURL( 'thread=' . $overview->wft_thread ); |
309 | | - |
310 | | - $output .= WikiForumGui::getThreadHeader( |
311 | | - '<a href="' . $link . '">' . $overview->wft_thread_name . '</a>', |
312 | | - $parser->recursiveTagParse( $overview->wft_text, $frame ), |
313 | | - $posted, |
314 | | - '', |
315 | | - $overview->wft_thread, |
316 | | - $overview->user_id |
317 | | - ); |
318 | | - |
319 | | - if ( isset( $args['replies'] ) && $args['replies'] ) { |
320 | | - $replies = $dbr->select( |
321 | | - array( 'wikiforum_replies', 'user' ), |
322 | | - array( '*', 'user_name' ), |
323 | | - array( 'wfr_deleted' => 0, 'wfr_thread' => $overview->pkThread ), |
324 | | - __METHOD__, |
325 | | - array( 'ORDER BY' => 'wfr_posted_timestamp ASC' ), |
326 | | - array( 'user' => array( 'LEFT JOIN', 'user_id = wfr_user' ) ) |
327 | | - ); |
328 | | - |
329 | | - foreach ( $replies as $reply ) { |
330 | | - $posted = wfMsg( |
331 | | - 'wikiforum-posted', |
332 | | - $wgLang->timeanddate( $reply->wfr_posted_timestamp ), |
333 | | - WikiForumClass::getUserLink( $reply->user_name ) |
334 | | - ); |
335 | | - if ( $reply->wfr_edit > 0 ) { |
336 | | - $posted .= '<br /><i>' . |
337 | | - wfMsg( |
338 | | - 'wikiforum-edited', |
339 | | - $wgLang->timeanddate( $reply->wfr_edit ), |
340 | | - WikiForumClass::getUserLinkById( $reply->wfr_edit_user ) |
341 | | - ) . '</i>'; |
342 | | - } |
343 | | - $output .= WikiForumGui::getReply( |
344 | | - $wgOut->parse( WikiForum::deleteTags( $reply->wfr_reply_text ) ), |
345 | | - $posted, |
346 | | - '', |
347 | | - $reply->wfr_reply_id |
348 | | - ); |
349 | | - } |
350 | | - } |
351 | | - |
352 | | - $output .= WikiForumGui::getThreadFooter(); |
353 | | - return $output; |
354 | | - } |
355 | | - } else { |
356 | | - return ''; |
357 | | - } |
358 | | -} |
359 | | - |
360 | | -$wgHooks['BeforePageDisplay'][] = 'wfWikiForumAddStyles'; |
361 | | -/** |
362 | | - * Add the CSS file to the output, but only once. |
363 | | - * |
364 | | - * @param $out Object: OutputPage instance |
365 | | - * @param $sk Object: Skin (or descendant class) instance |
366 | | - */ |
367 | | -function wfWikiForumAddStyles( &$out, &$sk ) { |
368 | | - static $cssDone = false; |
369 | | - if ( !$cssDone ) { |
370 | | - global $wgScriptPath; |
371 | | - $out->addExtensionStyle( $wgScriptPath . '/extensions/WikiForum/styles.css' ); |
372 | | - $cssDone = true; |
373 | | - } |
374 | | - return true; |
375 | | -} |
\ No newline at end of file |
| 86 | +$wgHooks['ParserFirstCallInit'][] = 'WikiForumHooks::registerParserHooks'; |
| 87 | +$wgHooks['SkinTemplateBuildNavUrlsNav_urlsAfterPermalink'][] = 'WikiForumHooks::addNavigationLink'; |
| 88 | +$wgHooks['SkinTemplateToolboxEnd'][] = 'WikiForumHooks::addNavigationLinkToToolbox'; |
| 89 | +$wgHooks['BeforePageDisplay'][] = 'WikiForumHooks::addStyles'; |
\ No newline at end of file |
Index: trunk/extensions/WikiForum/WikiForumHooks.php |
— | — | @@ -0,0 +1,294 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Static class containing all the hooked functions used by WikiForum. |
| 5 | + * |
| 6 | + * @file |
| 7 | + */ |
| 8 | +class WikiForumHooks { |
| 9 | + |
| 10 | + /** |
| 11 | + * Set up the two new parser hooks: <WikiForumList> and <WikiForumThread> |
| 12 | + * |
| 13 | + * @param $parser Object: instance of Parser |
| 14 | + * @return Boolean: true |
| 15 | + */ |
| 16 | + public static function registerParserHooks( &$parser ) { |
| 17 | + $parser->setHook( 'WikiForumList', 'WikiForumHooks::renderWikiForumList' ); |
| 18 | + $parser->setHook( 'WikiForumThread', 'WikiForumHooks::renderWikiForumThread' ); |
| 19 | + return true; |
| 20 | + } |
| 21 | + |
| 22 | + /** |
| 23 | + * Adds a link to Special:WikiForum to the toolbox, after permalink. |
| 24 | + * Both this and the function below are required to render the link in the |
| 25 | + * toolbox. |
| 26 | + * |
| 27 | + * @param $skinTemplate Object: SkinTemplate instance |
| 28 | + * @param $nav_urls Array: existing navigation URLs |
| 29 | + * @param $oldid Integer |
| 30 | + * @param $revid Integer: revision ID number of the current revision |
| 31 | + * @return Boolean: true |
| 32 | + */ |
| 33 | + public static function addNavigationLink( &$skinTemplate, &$nav_urls, &$oldid, &$revid ) { |
| 34 | + $nav_urls['wikiforum'] = array( |
| 35 | + 'text' => wfMsg( 'wikiforum' ), |
| 36 | + 'href' => $skinTemplate->makeSpecialUrl( 'WikiForum' ) |
| 37 | + ); |
| 38 | + return true; |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Adds a link to Special:WikiForum to the toolbox, after permalink. |
| 43 | + * Both this and the function above are required to render the link in the |
| 44 | + * toolbox. |
| 45 | + * |
| 46 | + * @param $skinTemplate Object: instance of SkinTemplate class |
| 47 | + * @return Boolean: true |
| 48 | + */ |
| 49 | + public static function addNavigationLinkToToolbox( &$skinTemplate ) { |
| 50 | + if ( isset( $skinTemplate->data['nav_urls']['wikiforum'] ) ) { |
| 51 | + if ( $skinTemplate->data['nav_urls']['wikiforum']['href'] == '' ) { |
| 52 | + echo '<li id="t-iswikiforum">' . wfMsg( 'wikiforum' ) . '</li>'; |
| 53 | + } else { |
| 54 | + $url = $skinTemplate->data['nav_urls']['wikiforum']['href']; |
| 55 | + echo '<li id="t-wikiforum"><a href="' . htmlspecialchars( $url ) . '">'; |
| 56 | + echo wfMsg( 'wikiforum' ); |
| 57 | + echo '</a></li>'; |
| 58 | + } |
| 59 | + } |
| 60 | + return true; |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * Callback for <WikiForumList> tag. |
| 65 | + * Takes only the following argument: num (used as the LIMIT for the SQL query) |
| 66 | + */ |
| 67 | + public static function renderWikiForumList( $input, $args, $parser, $frame ) { |
| 68 | + global $wgUser, $wgLang, $wgScriptPath; |
| 69 | + |
| 70 | + if ( !isset( $args['num'] ) ) { |
| 71 | + $args['num'] = 5; |
| 72 | + } |
| 73 | + |
| 74 | + $dbr = wfGetDB( DB_SLAVE ); |
| 75 | + $sqlThreads = $dbr->select( |
| 76 | + array( |
| 77 | + 'wikiforum_forums', 'wikiforum_category', 'wikiforum_threads', |
| 78 | + 'user' |
| 79 | + ), |
| 80 | + array( |
| 81 | + '*', 'wff_forum', 'wff_forum_name', 'wfc_category', |
| 82 | + 'wfc_category_name', 'user_name' |
| 83 | + ), |
| 84 | + array( |
| 85 | + 'wff_deleted' => 0, |
| 86 | + 'wfc_deleted' => 0, |
| 87 | + 'wft_deleted' => 0, |
| 88 | + 'wff_category = wfc_category', |
| 89 | + 'wff_forum = wft_forum' |
| 90 | + ), |
| 91 | + __METHOD__, |
| 92 | + // it's either wff or wft, I'm not 100% sure which one so I just |
| 93 | + // picked one of them... |
| 94 | + array( |
| 95 | + 'ORDER BY' => 'wff_last_post_timestamp DESC', |
| 96 | + 'LIMIT' => intval( $args['num'] ) |
| 97 | + ), |
| 98 | + array( 'user' => array( 'LEFT JOIN', 'user_id = wft_user' ) ) |
| 99 | + ); |
| 100 | + |
| 101 | + $output = WikiForumGui::getMainPageHeader( |
| 102 | + wfMsg( 'wikiforum-updates' ), |
| 103 | + wfMsg( 'wikiforum-replies' ), |
| 104 | + wfMsg( 'wikiforum-views' ), |
| 105 | + wfMsg( 'wikiforum-latest-reply' ) |
| 106 | + ); |
| 107 | + |
| 108 | + foreach ( $sqlThreads as $thread ) { |
| 109 | + $icon = WikiForumClass::getThreadIcon( |
| 110 | + $thread->wft_posted_timestamp, |
| 111 | + $thread->wft_closed, |
| 112 | + $thread->wft_sticky |
| 113 | + ); |
| 114 | + |
| 115 | + $lastpost = ''; |
| 116 | + // If there are some replies, then we can obviously figure out who was |
| 117 | + // the last user who posted something on the topic... |
| 118 | + if ( $thread->wft_reply_count > 0 ) { |
| 119 | + $lastpost = wfMsg( |
| 120 | + 'wikiforum-by', |
| 121 | + $wgLang->timeanddate( $thread->wft_last_post_timestamp ), |
| 122 | + WikiForumClass::getUserLinkById( $thread->wft_last_post_user ) |
| 123 | + ); |
| 124 | + } |
| 125 | + |
| 126 | + $specialPageObj = SpecialPage::getTitleFor( 'WikiForum' ); |
| 127 | + $sk = $wgUser->getSkin(); |
| 128 | + // Build the links to the category and forum pages by using Linker |
| 129 | + $categoryLink = $sk->link( |
| 130 | + $specialPageObj, |
| 131 | + $thread->wfc_category_name, |
| 132 | + array(), |
| 133 | + array( 'category' => $thread->wfc_category ) |
| 134 | + ); |
| 135 | + $forumLink = $sk->link( |
| 136 | + $specialPageObj, |
| 137 | + $thread->wff_forum_name, |
| 138 | + array(), |
| 139 | + array( 'forum' => $thread->wff_forum ) |
| 140 | + ); |
| 141 | + $threadLink = $sk->link( |
| 142 | + $specialPageObj, |
| 143 | + $thread->wft_thread_name, |
| 144 | + array(), |
| 145 | + array( 'thread' => $thread->wft_thread ) |
| 146 | + ); |
| 147 | + |
| 148 | + $output .= WikiForumGui::getMainBody( |
| 149 | + '<p class="mw-wikiforum-thread">' . $icon . $threadLink . |
| 150 | + '<p class="mw-wikiforum-descr" style="border-top: 0;">' . |
| 151 | + wfMsg( |
| 152 | + 'wikiforum-posted', |
| 153 | + $wgLang->timeanddate( $thread->wft_posted_timestamp ), |
| 154 | + WikiForumClass::getUserLink( $thread->user_name ) |
| 155 | + ) . '<br />' . |
| 156 | + wfMsgHtml( 'wikiforum-forum', $categoryLink, $forumLink ) . |
| 157 | + '</p></p>', |
| 158 | + $thread->wft_reply_count, |
| 159 | + $thread->wft_view_count, |
| 160 | + $lastpost, |
| 161 | + false, |
| 162 | + false |
| 163 | + ); |
| 164 | + } |
| 165 | + $output .= WikiForumGui::getMainPageFooter(); |
| 166 | + |
| 167 | + return $output; |
| 168 | + } |
| 169 | + |
| 170 | + /** |
| 171 | + * Callback for the <WikiForumThread> hook. |
| 172 | + * Takes the following arguments: id (ID number of the thread, used in SQL |
| 173 | + * query), replies (whether to display replies) |
| 174 | + */ |
| 175 | + public static function renderWikiForumThread( $input, $args, $parser, $frame ) { |
| 176 | + global $wgOut, $wgLang, $wgScriptPath; |
| 177 | + |
| 178 | + if ( isset( $args['id'] ) && $args['id'] > 0 ) { |
| 179 | + $dbr = wfGetDB( DB_SLAVE ); |
| 180 | + $sqlThreads = $dbr->select( |
| 181 | + array( 'wikiforum_forums', 'wikiforum_category', 'wikiforum_threads', 'user' ), |
| 182 | + array( |
| 183 | + 'wft_thread', 'wft_thread_name', 'wft_text', 'wff_forum', |
| 184 | + 'wff_forum_name', 'wfc_category', 'wfc_category_name', |
| 185 | + 'user_name', 'user_id', 'wft_edit_timestamp', 'wft_edit_user', |
| 186 | + 'wft_posted_timestamp', 'wft_user', 'wft_closed', |
| 187 | + 'wft_closed_user' |
| 188 | + ), |
| 189 | + array( |
| 190 | + 'wff_deleted' => 0, |
| 191 | + 'wfc_deleted' => 0, |
| 192 | + 'wft_deleted' => 0, |
| 193 | + 'wff_category = wfc_category', |
| 194 | + 'wff_forum = wft_forum', |
| 195 | + 'wft_thread' => intval( $args['id'] ) |
| 196 | + ), |
| 197 | + __METHOD__, |
| 198 | + array(), |
| 199 | + array( 'user' => array( 'LEFT JOIN', 'user_id = wft_user' ) ) |
| 200 | + ); |
| 201 | + $overview = $dbr->fetchObject( $sqlThreads ); |
| 202 | + |
| 203 | + if ( $overview ) { |
| 204 | + $posted = wfMsg( |
| 205 | + 'wikiforum-posted', |
| 206 | + $wgLang->timeanddate( $overview->wft_posted_timestamp ), |
| 207 | + WikiForumClass::getUserLink( $overview->user_name ) |
| 208 | + ); |
| 209 | + if ( $overview->wft_edit_timestamp > 0 ) { |
| 210 | + $posted .= '<br /><i>' . |
| 211 | + wfMsg( |
| 212 | + 'wikiforum-edited', |
| 213 | + $wgLang->timeanddate( $overview->wft_edit_timestamp ), |
| 214 | + WikiForumClass::getUserLinkById( $overview->wft_edit_user ) |
| 215 | + ) . '</i>'; |
| 216 | + } |
| 217 | + |
| 218 | + $output = WikiForumGui::getHeaderRow( |
| 219 | + $overview->wfc_category, |
| 220 | + $overview->wfc_category_name, |
| 221 | + $overview->wff_forum, |
| 222 | + $overview->wff_forum_name, |
| 223 | + false |
| 224 | + ); |
| 225 | + |
| 226 | + $specialPageObj = SpecialPage::getTitleFor( 'WikiForum' ); |
| 227 | + $link = $specialPageObj->escapeFullURL( 'thread=' . $overview->wft_thread ); |
| 228 | + |
| 229 | + $output .= WikiForumGui::getThreadHeader( |
| 230 | + '<a href="' . $link . '">' . $overview->wft_thread_name . '</a>', |
| 231 | + $parser->recursiveTagParse( $overview->wft_text, $frame ), |
| 232 | + $posted, |
| 233 | + '', |
| 234 | + $overview->wft_thread, |
| 235 | + $overview->user_id |
| 236 | + ); |
| 237 | + |
| 238 | + if ( isset( $args['replies'] ) && $args['replies'] ) { |
| 239 | + $replies = $dbr->select( |
| 240 | + array( 'wikiforum_replies', 'user' ), |
| 241 | + array( '*', 'user_name' ), |
| 242 | + array( 'wfr_deleted' => 0, 'wfr_thread' => $overview->pkThread ), |
| 243 | + __METHOD__, |
| 244 | + array( 'ORDER BY' => 'wfr_posted_timestamp ASC' ), |
| 245 | + array( 'user' => array( 'LEFT JOIN', 'user_id = wfr_user' ) ) |
| 246 | + ); |
| 247 | + |
| 248 | + foreach ( $replies as $reply ) { |
| 249 | + $posted = wfMsg( |
| 250 | + 'wikiforum-posted', |
| 251 | + $wgLang->timeanddate( $reply->wfr_posted_timestamp ), |
| 252 | + WikiForumClass::getUserLink( $reply->user_name ) |
| 253 | + ); |
| 254 | + if ( $reply->wfr_edit > 0 ) { |
| 255 | + $posted .= '<br /><i>' . |
| 256 | + wfMsg( |
| 257 | + 'wikiforum-edited', |
| 258 | + $wgLang->timeanddate( $reply->wfr_edit ), |
| 259 | + WikiForumClass::getUserLinkById( $reply->wfr_edit_user ) |
| 260 | + ) . '</i>'; |
| 261 | + } |
| 262 | + $output .= WikiForumGui::getReply( |
| 263 | + $wgOut->parse( WikiForum::deleteTags( $reply->wfr_reply_text ) ), |
| 264 | + $posted, |
| 265 | + '', |
| 266 | + $reply->wfr_reply_id |
| 267 | + ); |
| 268 | + } |
| 269 | + } |
| 270 | + |
| 271 | + $output .= WikiForumGui::getThreadFooter(); |
| 272 | + return $output; |
| 273 | + } |
| 274 | + } else { |
| 275 | + return ''; |
| 276 | + } |
| 277 | + } |
| 278 | + |
| 279 | + /** |
| 280 | + * Add the CSS file to the output, but only once. |
| 281 | + * |
| 282 | + * @param $out Object: OutputPage instance |
| 283 | + * @param $sk Object: Skin (or descendant class) instance |
| 284 | + */ |
| 285 | + public static function addStyles( &$out, &$sk ) { |
| 286 | + static $cssDone = false; |
| 287 | + if ( !$cssDone ) { |
| 288 | + global $wgScriptPath; |
| 289 | + $out->addExtensionStyle( $wgScriptPath . '/extensions/WikiForum/styles.css' ); |
| 290 | + $cssDone = true; |
| 291 | + } |
| 292 | + return true; |
| 293 | + } |
| 294 | + |
| 295 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/WikiForum/WikiForumHooks.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 296 | + native |