コード例 #1
0
	/**
	 * Callback for <WikiForumList> tag.
	 * Takes only the following argument: num (used as the LIMIT for the SQL query)
	 */
	public static function renderWikiForumList( $input, $args, $parser, $frame ) {
		global $wgLang;

		if ( !isset( $args['num'] ) ) {
			$args['num'] = 5;
		}

		$dbr = wfGetDB( DB_SLAVE );
		$sqlThreads = $dbr->select(
			array(
				'wikiforum_forums', 'wikiforum_category', 'wikiforum_threads',
				'user'
			),
			array(
				'*', 'wff_forum', 'wff_forum_name', 'wfc_category',
				'wfc_category_name', 'user_name'
			),
			array(
				'wff_deleted' => 0,
				'wfc_deleted' => 0,
				'wft_deleted' => 0,
				'wff_category = wfc_category',
				'wff_forum = wft_forum'
			),
			__METHOD__,
			array(
				'ORDER BY' => 'wft_last_post_timestamp DESC',
				'LIMIT' => intval( $args['num'] )
			),
			array( 'user' => array( 'LEFT JOIN', 'user_id = wft_user' ) )
		);

		$output = WikiForumGui::getMainPageHeader(
			wfMsg( 'wikiforum-updates' ),
			wfMsg( 'wikiforum-replies' ),
			wfMsg( 'wikiforum-views' ),
			wfMsg( 'wikiforum-latest-reply' )
		);

		foreach ( $sqlThreads as $thread ) {
			$icon = WikiForumClass::getThreadIcon(
				$thread->wft_posted_timestamp,
				$thread->wft_closed,
				$thread->wft_sticky
			);

			$lastpost = '';
			// If there are some replies, then we can obviously figure out who was
			// the last user who posted something on the topic...
			if ( $thread->wft_reply_count > 0 ) {
				$lastpost = wfMsg(
					'wikiforum-by',
					$wgLang->timeanddate( $thread->wft_last_post_timestamp ),
					WikiForumClass::getUserLinkById( $thread->wft_last_post_user )
				);
			}

			$specialPageObj = SpecialPage::getTitleFor( 'WikiForum' );
			// Build the links to the category and forum pages by using Linker
			$categoryLink = Linker::link(
				$specialPageObj,
				$thread->wfc_category_name,
				array(),
				array( 'category' => $thread->wfc_category )
			);
			$forumLink = Linker::link(
				$specialPageObj,
				$thread->wff_forum_name,
				array(),
				array( 'forum' => $thread->wff_forum )
			);
			$threadLink = Linker::link(
				$specialPageObj,
				$thread->wft_thread_name,
				array(),
				array( 'thread' => $thread->wft_thread )
			);

			$output .= WikiForumGui::getMainBody(
				'<p class="mw-wikiforum-thread">' . $icon . $threadLink .
				'<p class="mw-wikiforum-descr" style="border-top: 0;">' .
				wfMsg(
					'wikiforum-posted',
					$wgLang->timeanddate( $thread->wft_posted_timestamp ),
					WikiForumClass::getUserLink( $thread->user_name )
				) . '<br />' .
				wfMsgHtml( 'wikiforum-forum', $categoryLink, $forumLink ) .
				'</p></p>',
				$thread->wft_reply_count,
				$thread->wft_view_count,
				$lastpost,
				false,
				false
			);
		}
		$output .= WikiForumGui::getMainPageFooter();

		return $output;
	}