/** * Callback for the <WikiForumThread> hook. * Takes the following arguments: id (ID number of the thread, used in SQL * query), replies (whether to display replies) */ public static function renderWikiForumThread( $input, $args, $parser, $frame ) { global $wgOut, $wgLang; if ( isset( $args['id'] ) && $args['id'] > 0 ) { $dbr = wfGetDB( DB_SLAVE ); $sqlThreads = $dbr->select( array( 'wikiforum_forums', 'wikiforum_category', 'wikiforum_threads', 'user' ), array( 'wft_thread', 'wft_thread_name', 'wft_text', 'wff_forum', 'wff_forum_name', 'wfc_category', 'wfc_category_name', 'user_name', 'user_id', 'wft_edit_timestamp', 'wft_edit_user', 'wft_posted_timestamp', 'wft_user', 'wft_closed', 'wft_closed_user' ), array( 'wff_deleted' => 0, 'wfc_deleted' => 0, 'wft_deleted' => 0, 'wff_category = wfc_category', 'wff_forum = wft_forum', 'wft_thread' => intval( $args['id'] ) ), __METHOD__, array(), array( 'user' => array( 'LEFT JOIN', 'user_id = wft_user' ) ) ); $overview = $dbr->fetchObject( $sqlThreads ); if ( $overview ) { $posted = wfMsg( 'wikiforum-posted', $wgLang->timeanddate( $overview->wft_posted_timestamp ), WikiForumClass::getUserLink( $overview->user_name ) ); if ( $overview->wft_edit_timestamp > 0 ) { $posted .= '<br /><i>' . wfMsg( 'wikiforum-edited', $wgLang->timeanddate( $overview->wft_edit_timestamp ), WikiForumClass::getUserLinkById( $overview->wft_edit_user ) ) . '</i>'; } $output = WikiForumGui::getHeaderRow( $overview->wfc_category, $overview->wfc_category_name, $overview->wff_forum, $overview->wff_forum_name, false ); $specialPageObj = SpecialPage::getTitleFor( 'WikiForum' ); $link = $specialPageObj->escapeFullURL( 'thread=' . $overview->wft_thread ); $output .= WikiForumGui::getThreadHeader( '<a href="' . $link . '">' . $overview->wft_thread_name . '</a>', $parser->recursiveTagParse( $overview->wft_text, $frame ), $posted, '', $overview->wft_thread, $overview->user_id ); if ( isset( $args['replies'] ) && $args['replies'] ) { $replies = $dbr->select( array( 'wikiforum_replies', 'user' ), array( '*', 'user_name' ), array( 'wfr_deleted' => 0, 'wfr_thread' => $overview->pkThread ), __METHOD__, array( 'ORDER BY' => 'wfr_posted_timestamp ASC' ), array( 'user' => array( 'LEFT JOIN', 'user_id = wfr_user' ) ) ); foreach ( $replies as $reply ) { $posted = wfMsg( 'wikiforum-posted', $wgLang->timeanddate( $reply->wfr_posted_timestamp ), WikiForumClass::getUserLink( $reply->user_name ) ); if ( $reply->wfr_edit > 0 ) { $posted .= '<br /><i>' . wfMsg( 'wikiforum-edited', $wgLang->timeanddate( $reply->wfr_edit ), WikiForumClass::getUserLinkById( $reply->wfr_edit_user ) ) . '</i>'; } $output .= WikiForumGui::getReply( $wgOut->parse( WikiForum::deleteTags( $reply->wfr_reply_text ) ), $posted, '', $reply->wfr_reply_id ); } } $output .= WikiForumGui::getThreadFooter(); return $output; } } else { return ''; } }
/** * Show the special page * * @param $par Mixed: parameter passed to the page or null */ public function execute( $par ) { global $wgOut, $wgUser, $wgRequest, $wgScriptPath; // If user is blocked, s/he doesn't need to access this page if ( $wgUser->isBlocked() ) { $wgOut->blockedPage(); return; } // Checking for wfReadOnly() is done in the individual functions // in WikiForumClass.php; besides, we should be able to browse the // forum even when the DB is in read-only mode $this->setHeaders(); $forum = new WikiForumClass; $values = array(); // Add CSS $wgOut->addModuleStyles( 'ext.wikiForum' ); // If a parameter to the special page is specified, check its type // and either display a forum (if parameter is a number) or a thread // (if it's the title of a topic) if ( $par ) { // Let search spiders index our content $wgOut->setRobotPolicy( 'index,follow' ); if ( is_numeric( $par ) ) { $wgOut->addHTML( $forum->showForum( $par ) ); } else { $threadId = WikiForumClass::findThreadIDByTitle( $par ); $wgOut->addHTML( $forum->showThread( $threadId ) ); } } else { // That's...a lot of variables. No kidding. $mod_category = $wgRequest->getInt( 'category' ); $mod_forum = $wgRequest->getInt( 'forum' ); $mod_thread = $wgRequest->getInt( 'thread' ); $mod_writethread = $wgRequest->getInt( 'writethread' ); $mod_addcomment = $wgRequest->getInt( 'addcomment' ); $mod_addthread = $wgRequest->getInt( 'addthread' ); $mod_editcomment = $wgRequest->getInt( 'editcomment' ); $mod_editthread = $wgRequest->getInt( 'editthread' ); $mod_deletecomment = $wgRequest->getInt( 'deletecomment' ); $mod_deletethread = $wgRequest->getInt( 'deletethread' ); $mod_closethread = $wgRequest->getInt( 'closethread' ); $mod_reopenthread = $wgRequest->getInt( 'reopenthread' ); $mod_addcategory = $wgRequest->getBool( 'addcategory' ); $mod_addforum = $wgRequest->getInt( 'addforum' ); $mod_editcategory = $wgRequest->getInt( 'editcategory' ); $mod_editforum = $wgRequest->getInt( 'editforum' ); $mod_deletecategory = $wgRequest->getInt( 'deletecategory' ); $mod_deleteforum = $wgRequest->getInt( 'deleteforum' ); $mod_makesticky = $wgRequest->getInt( 'makesticky' ); $mod_removesticky = $wgRequest->getInt( 'removesticky' ); $mod_categoryup = $wgRequest->getInt( 'categoryup' ); $mod_categorydown = $wgRequest->getInt( 'categorydown' ); $mod_forumup = $wgRequest->getInt( 'forumup' ); $mod_forumdown = $wgRequest->getInt( 'forumdown' ); $mod_search = $wgRequest->getVal( 'txtSearch' ); $mod_submit = $wgRequest->getBool( 'butSubmit' ); $mod_pastethread = $wgRequest->getInt( 'pastethread' ); // Define this variable to prevent E_NOTICEs about undefined variable $mod_none = false; // Figure out what we're going to do here...post a reply, a new thread, // edit a reply, edit a thread...and so on. if ( isset( $mod_addcomment ) && $mod_addcomment > 0 ) { $data_text = $wgRequest->getVal( 'frmText' ); $data_preview = $wgRequest->getBool( 'butPreview' ); $data_save = $wgRequest->getBool( 'butSave' ); if ( $data_save == true ) { $result = $forum->addReply( $mod_addcomment, $data_text ); $mod_thread = $mod_addcomment; } elseif ( $data_preview == true ) { $result = $wgOut->addHTML( $forum->previewIssue( 'addcomment', $mod_addcomment, false, $data_text ) ); $mod_none = true; } } elseif ( isset( $mod_addthread ) && $mod_addthread > 0 ) { $data_title = $wgRequest->getVal( 'frmTitle' ); $data_text = $wgRequest->getVal( 'frmText' ); $data_preview = $wgRequest->getBool( 'butPreview' ); $data_save = $wgRequest->getBool( 'butSave' ); if ( $data_save == true ) { $result = $forum->addThread( $mod_addthread, $data_title, $data_text ); $mod_forum = $mod_addthread; } elseif ( $data_preview == true ) { $result = $wgOut->addHTML( $forum->previewIssue( 'addthread', $mod_addthread, $data_title, $data_text ) ); $mod_none = true; } else { $mod_writethread = $mod_addthread; } } elseif ( isset( $mod_editcomment ) && $mod_editcomment > 0 ) { $data_text = $wgRequest->getVal( 'frmText' ); $data_preview = $wgRequest->getBool( 'butPreview' ); $data_save = $wgRequest->getBool( 'butSave' ); if ( $data_save == true ) { $result = $forum->editReply( $mod_editcomment, $data_text ); $mod_thread = $mod_thread; } elseif ( $data_preview == true ) { $result = $wgOut->addHTML( $forum->previewIssue( 'editcomment', $mod_editcomment, false, $data_text ) ); $mod_none = true; } } elseif ( isset( $mod_editthread ) && $mod_editthread > 0 ) { $data_title = $wgRequest->getVal( 'frmTitle' ); $data_text = $wgRequest->getVal( 'frmText' ); $data_preview = $wgRequest->getBool( 'butPreview' ); $data_save = $wgRequest->getBool( 'butSave' ); if ( $data_save == true ) { $result = $forum->editThread( $mod_editthread, $data_title, $data_text ); $mod_thread = $mod_editthread; } elseif ( $data_preview == true ) { $result = $wgOut->addHTML( $forum->previewIssue( 'editthread', $mod_editthread, $data_title, $data_text ) ); $mod_none = true; } else { $mod_writethread = $mod_editthread; } } elseif ( isset( $mod_deletecomment ) && $mod_deletecomment > 0 ) { $result = $forum->deleteReply( $mod_deletecomment ); } elseif ( isset( $mod_deletethread ) && $mod_deletethread > 0 ) { $result = $forum->deleteThread( $mod_deletethread ); } elseif ( isset( $mod_deletecategory ) && $mod_deletecategory > 0 ) { $result = $forum->deleteCategory( $mod_deletecategory ); } elseif ( isset( $mod_deleteforum ) && $mod_deleteforum > 0 ) { $result = $forum->deleteForum( $mod_deleteforum ); } elseif ( isset( $mod_categoryup ) && $mod_categoryup > 0 ) { $result = $forum->sortKeys( $mod_categoryup, 'category', true ); } elseif ( isset( $mod_categorydown ) && $mod_categorydown > 0 ) { $result = $forum->sortKeys( $mod_categorydown, 'category', false ); } elseif ( isset( $mod_forumup ) && $mod_forumup > 0 ) { $result = $forum->sortKeys( $mod_forumup, 'forum', true ); } elseif ( isset( $mod_forumdown ) && $mod_forumdown > 0 ) { $result = $forum->sortKeys( $mod_forumdown, 'forum', false ); } elseif ( isset( $mod_closethread ) && $mod_closethread > 0 ) { $result = $forum->closeThread( $mod_closethread ); $mod_thread = $mod_closethread; } elseif ( isset( $mod_reopenthread ) && $mod_reopenthread > 0 ) { $result = $forum->reopenThread( $mod_reopenthread ); $mod_thread = $mod_reopenthread; } elseif ( isset( $mod_makesticky ) && $mod_makesticky > 0 ) { $result = $forum->makeSticky( $mod_makesticky, true ); $mod_thread = $mod_makesticky; } elseif ( isset( $mod_removesticky ) && $mod_removesticky > 0 ) { $result = $forum->makeSticky( $mod_removesticky, false ); $mod_thread = $mod_removesticky; } elseif ( isset( $mod_pastethread ) && $mod_pastethread > 0 ) { $result = $forum->pasteThread( $mod_pastethread, $mod_forum ); } elseif ( isset( $mod_addcategory ) && $mod_addcategory == true && $wgUser->isAllowed( 'wikiforum-admin' ) ) { if ( $mod_submit == true ) { $values['title'] = $wgRequest->getVal( 'frmTitle' ); $mod_submit = $forum->addCategory( $values['title'] ); } if ( $mod_submit == false ) { $mod_showform = true; $type = 'addcategory'; $id = $mod_addcategory; } } elseif ( isset( $mod_addforum ) && $mod_addforum > 0 && $wgUser->isAllowed( 'wikiforum-admin' ) ) { if ( $mod_submit == true ) { $values['title'] = $wgRequest->getVal( 'frmTitle' ); $values['text'] = $wgRequest->getVal( 'frmText' ); if ( $wgRequest->getBool( 'chkAnnouncement' ) == true ) { $values['announce'] = '1'; } else { $values['announce'] = '0'; } $mod_submit = $forum->addForum( $mod_addforum, $values['title'], $values['text'], $values['announce'] ); } if ( $mod_submit == false ) { $mod_showform = true; $type = 'addforum'; $id = $mod_addforum; } } elseif ( isset( $mod_editcategory ) && $mod_editcategory > 0 && $wgUser->isAllowed( 'wikiforum-admin' ) ) { if ( $mod_submit == true ) { $values['title'] = $wgRequest->getVal( 'frmTitle' ); $mod_submit = $forum->editCategory( $mod_editcategory, $values['title'] ); } if ( $mod_submit == false ) { $mod_showform = true; $type = 'editcategory'; $id = $mod_editcategory; } } elseif ( isset( $mod_editforum ) && $mod_editforum > 0 && $wgUser->isAllowed( 'wikiforum-admin' ) ) { if ( $mod_submit == true ) { $values['title'] = $wgRequest->getVal( 'frmTitle' ); $values['text'] = $wgRequest->getVal( 'frmText' ); if ( $wgRequest->getBool( 'chkAnnouncement' ) == true ) { $values['announce'] = '1'; } else { $values['announce'] = '0'; } $mod_submit = $forum->editForum( $mod_editforum, $values['title'], $values['text'], $values['announce'] ); } if ( $mod_submit == false ) { $mod_showform = true; $type = 'editforum'; $id = $mod_editforum; } } // Only in certain cases we want search spiders to index our content // and follow links. These are overview (Special:WikiForum), individual // threads, forums and categories. if ( isset( $mod_search ) && $mod_search == true ) { $wgOut->addHTML( $forum->showSearchResults( $mod_search ) ); } elseif ( $mod_none == true ) { // no data } elseif ( isset( $mod_category ) && $mod_category > 0 ) { // Let search spiders index our content $wgOut->setRobotPolicy( 'index,follow' ); $wgOut->addHTML( $forum->showCategory( $mod_category ) ); } elseif ( isset( $mod_forum ) && $mod_forum > 0 ) { // Let search spiders index our content $wgOut->setRobotPolicy( 'index,follow' ); $wgOut->addHTML( $forum->showForum( $mod_forum ) ); } elseif ( isset( $mod_thread ) && $mod_thread > 0 ) { // Let search spiders index our content $wgOut->setRobotPolicy( 'index,follow' ); $wgOut->addHTML( $forum->showThread( $mod_thread ) ); } elseif ( isset( $mod_writethread ) && $mod_writethread > 0 ) { $wgOut->addHTML( $forum->writeThread( $mod_writethread ) ); } elseif ( isset( $mod_showform ) && $mod_showform ) { $wgOut->addHTML( $forum->showEditorCatForum( $id, $type, $values ) ); } else { // Let search spiders index our content $wgOut->setRobotPolicy( 'index,follow' ); $wgOut->addHTML( $forum->showOverview() ); } } // else from line 55 (the if $par is not specified one) } // execute()
function showThread( $threadId ) { global $wgOut, $wgRequest, $wgUser, $wgLang, $wgScriptPath; $output = $this->showFailure(); $dbr = wfGetDB( DB_SLAVE ); $sqlData = $dbr->select( array( 'wikiforum_forums', 'wikiforum_category', 'wikiforum_threads', 'user' ), array( 'wft_thread', 'wft_thread_name', 'wft_text', 'wff_forum', 'wff_forum_name', 'wfc_category', 'wfc_category_name', 'user_name', 'user_id', 'wft_sticky', 'wft_edit_timestamp', 'wft_edit_user', 'wft_posted_timestamp', 'wft_user', 'wft_closed', 'wft_closed_user', ), array( 'wff_deleted' => 0, 'wfc_deleted' => 0, 'wft_deleted' => 0, 'wff_category = wfc_category', 'wff_forum = wft_forum', 'wft_thread' => intval( $threadId ) ), __METHOD__, array(), array( 'user' => array( 'LEFT JOIN', 'user_id = wft_user' ) ) ); $data_overview = $dbr->fetchObject( $sqlData ); $maxRepliesPerPage = intval( wfMsgForContent( 'wikiforum-max-replies-per-page' ) ); // limiting if ( $maxRepliesPerPage && $wgRequest->getVal( 'lc' ) > 0 ) { $limit_count = $wgRequest->getVal( 'lc' ); } elseif ( $maxRepliesPerPage > 0 ) { $limit_count = $maxRepliesPerPage; } if ( is_numeric( $wgRequest->getVal( 'lp' ) ) ) { $limit_page = $wgRequest->getVal( 'lp' ) - 1; } else { $limit_page = 0; } // end limiting $specialPage = SpecialPage::getTitleFor( 'WikiForum' ); if ( $data_overview ) { $queryOptions['ORDER BY'] = 'wfr_posted_timestamp ASC'; if ( $limit_count > 0 ) { $queryOptions['LIMIT'] = $limit_count; $queryOptions['OFFSET'] = $limit_page * $limit_count; } $replies = $dbr->select( array( 'wikiforum_replies', 'user' ), array( '*', 'user_name', 'user_id' ), array( 'wfr_deleted' => 0, 'wfr_thread' => $data_overview->wft_thread ), __METHOD__, $queryOptions, array( 'user' => array( 'LEFT JOIN', 'user_id = wfr_user' ) ) ); if ( !wfReadOnly() ) { $dbw = wfGetDB( DB_MASTER ); $dbw->update( 'wikiforum_threads', array( 'wft_view_count = wft_view_count + 1' ), array( 'wft_thread' => intval( $data_overview->wft_thread ) ), __METHOD__ ); } $editButtons = $this->showThreadButtons( $data_overview->wft_user, $data_overview->wft_closed, $data_overview->wft_thread, $data_overview->wff_forum ); $menuLink = ''; if ( $wgUser->isAllowed( 'wikiforum-admin' ) ) { if ( $data_overview->wft_sticky == 1 ) { $icon = '<img src="' . $wgScriptPath . '/extensions/WikiForum/icons/tag_blue_delete.png" title="' . wfMsg( 'wikiforum-remove-sticky' ) . '" /> '; $menuLink = $icon . '<a href="' . $specialPage->escapeFullURL( array( 'removesticky' => $data_overview->wft_thread ) ) . '">' . wfMsg( 'wikiforum-remove-sticky' ) . '</a> '; } else { $icon = '<img src="' . $wgScriptPath . '/extensions/WikiForum/icons/tag_blue_add.png" title="' . wfMsg( 'wikiforum-make-sticky' ) . '" /> '; $menuLink = $icon . '<a href="' . $specialPage->escapeFullURL( array( 'makesticky' => $data_overview->wft_thread ) ) . '">' . wfMsg( 'wikiforum-make-sticky' ) . '</a> '; } } $icon = '<img src="' . $wgScriptPath . '/extensions/WikiForum/icons/comment_add.png" title="' . wfMsg( 'wikiforum-write-reply' ) . '" /> '; // Replying is only possible to open threads if ( $data_overview->wft_closed == 0 ) { $menuLink .= $icon . '<a href="#writereply">' . wfMsg( 'wikiforum-write-reply' ) . '</a>'; } $posted = wfMsg( 'wikiforum-posted', $wgLang->timeanddate( $data_overview->wft_posted_timestamp ), WikiForumClass::getUserLink( $data_overview->user_name ) ); if ( $data_overview->wft_edit_timestamp > 0 ) { $posted .= '<br /><i>' . wfMsg( 'wikiforum-edited', $wgLang->timeanddate( $data_overview->wft_edit_timestamp ), WikiForumClass::getUserLinkById( $data_overview->wft_edit_user ) ) . '</i>'; } $output .= WikiForumGui::getSearchbox(); $output .= WikiForumGui::getHeaderRow( $data_overview->wfc_category, $data_overview->wfc_category_name, $data_overview->wff_forum, $data_overview->wff_forum_name, $menuLink ); // Add topic name to the title // @todo FIXME: this is lame and doesn't apply to the <title> attribute $wgOut->setPageTitle( wfMsg( 'wikiforum-topic-name', $data_overview->wft_thread_name ) ); $output .= WikiForumGui::getThreadHeader( htmlspecialchars( $data_overview->wft_thread_name ), $this->parseIt( $data_overview->wft_text ),// $wgOut->parse( $data_overview->wft_text ), $posted, $editButtons, $data_overview->wft_thread, $data_overview->user_id ); foreach ( $replies as $reply ) { $editButtons = $this->showReplyButtons( $reply->wfr_user, $reply->wfr_reply_id, $data_overview->wft_thread, $data_overview->wft_closed ); $posted = wfMsg( 'wikiforum-posted', $wgLang->timeanddate( $reply->wfr_posted_timestamp ), WikiForumClass::getUserLink( $reply->user_name ) ); if ( $reply->wfr_edit_timestamp > 0 ) { $posted .= '<br /><i>' . wfMsg( 'wikiforum-edited', $wgLang->timeanddate( $reply->wfr_edit_timestamp ), WikiForumClass::getUserLinkById( $reply->wfr_edit_user ) ) . '</i>'; } $output .= WikiForumGui::getReply( $this->parseIt( $reply->wfr_reply_text ),// $wgOut->parse( $reply->wfr_reply_text ), $posted, $editButtons, $reply->wfr_reply_id, $reply->user_id ); } $output .= WikiForumGui::getThreadFooter(); if ( $limit_count > 0 ) { $countReplies = $dbr->selectRow( 'wikiforum_replies', 'COUNT(*) AS count', array( 'wfr_deleted' => 0, 'wfr_thread' => $data_overview->wft_thread ), __METHOD__ ); $output .= WikiForumGui::getFooterRow( $limit_page, $countReplies->count, $limit_count, $data_overview->wff_forum, intval( $threadId ) ); } $mod_editcomment = $wgRequest->getInt( 'editcomment' ); $mod_form = $wgRequest->getBool( 'form' ); if ( $data_overview->wft_closed == 0 || ( isset( $mod_editcomment ) && $mod_editcomment > 0 && $mod_form != true && $wgUser->isAllowed( 'wikiforum-moderator' ) ) ) { $output .= $this->showEditor( $data_overview->wft_thread, 'addcomment' ); } else { $this->errorTitle = wfMsg( 'wikiforum-thread-closed' ); $this->errorMessage = wfMsg( 'wikiforum-error-thread-closed' ); $this->errorIcon = 'lock.png';// 'icon_thread_closed'; } } else { $this->errorTitle = wfMsg( 'wikiforum-thread-not-found' ); $this->errorMessage = wfMsg( 'wikiforum-thread-not-found-text', '<a href="' . $specialPage->escapeFullURL() . '">' . wfMsg( 'wikiforum-overview' ) . '</a>' ); } $movethread_link = ''; if ( $wgUser->isAllowed( 'wikiforum-moderator' ) ) { $icon = '<img src="' . $wgScriptPath . '/extensions/WikiForum/icons/note_go.png" title="' . wfMsg( 'wikiforum-move-thread' ) . '" /> '; $movethread_link = $icon . '<a href="' . $specialPage->escapeFullURL( array( 'movethread' => $data_overview->wft_thread ) ) . '">' . wfMsg( 'wikiforum-move-thread' ) . '</a> '; $output .= WikiForumGui::getHeaderRow( 0, '', 0, '', $movethread_link ); } $output .= $this->showFailure(); return $output; }