/**
	 * View page action handler.
	 */
	public function view() {
		global $wgOut, $wgUser, $wgContLang, $wgFeed, $wgWikilogFeedClasses;

		# Get skin
		$skin = $wgUser->getSkin();

		if ( $this->mItem ) {
			$params = $this->mItem->getMsgParams( true );

			# Set page subtitle
			$subtitleTxt = wfMsgExt( 'wikilog-entry-sub',
				array( 'parsemag', 'content' ),
				$params
			);
			if ( !empty( $subtitleTxt ) ) {
				$wgOut->setSubtitle( $wgOut->parse( $subtitleTxt ) );
			}

			# Display draft notice.
			if ( !$this->mItem->getIsPublished() ) {
				$wgOut->wrapWikiMsg( '<div class="mw-warning">$1</div>', array( 'wikilog-reading-draft' ) );
			}

			# Item page header.
			$headerTxt = wfMsgExt( 'wikilog-entry-header',
				array( 'parse', 'content' ),
				$params
			);
			if ( !empty( $headerTxt ) ) {
				$wgOut->addHtml( WikilogUtils::wrapDiv( 'wl-entry-header', $headerTxt ) );
			}

			# Display article.
			parent::view();

			# Override page title.
			# NOTE (MW1.16+): Must come after parent::view().
			$fullPageTitle = wfMsg( 'wikilog-title-item-full',
					$this->mItem->mName,
					$this->mItem->mParentTitle->getPrefixedText()
			);
			$wgOut->setPageTitle( Sanitizer::escapeHtmlAllowEntities( $this->mItem->mName ) );
			$wgOut->setHTMLTitle( wfMsg( 'pagetitle', $fullPageTitle ) );

			# Item page footer.
			$footerTxt = wfMsgExt( 'wikilog-entry-footer',
				array( 'parse', 'content' ),
				$params
			);
			if ( !empty( $footerTxt ) ) {
				$wgOut->addHtml( WikilogUtils::wrapDiv( 'wl-entry-footer', $footerTxt ) );
			}

			# Add feed links.
			$links = array();
			if ( $wgFeed ) {
				foreach ( $wgWikilogFeedClasses as $format => $class ) {
					$wgOut->addLink( array(
						'rel' => 'alternate',
						'type' => "application/{$format}+xml",
						'title' => wfMsgExt(
							"page-{$format}-feed",
							array( 'content', 'parsemag' ),
							$this->mItem->mParentTitle->getPrefixedText()
						),
						'href' => $this->mItem->mParentTitle->getLocalUrl( "feed={$format}" )
					) );
				}
			}
		} else {
			# Display article.
			parent::view();
		}
	}
	/**
	 * Format and return the navigation bar.
	 * @param $limit integer  Number of itens being displayed.
	 * @return string  HTML-formatted navigation bar.
	 */
	public function getNavigationBar( $limit ) {
		global $wgLang;

		$limit = $wgLang->formatNum( $limit );
		$opts = array( 'parsemag', 'escapenoentities' );
		$linkTexts = $disabledTexts = array();
		foreach ( self::$linkTextMsgs[$this->mType] as $type => $msg ) {
			$label = wfMsgExt( $msg, $opts, $limit );
			$linkTexts[$type] = wfMsgReplaceArgs( self::$pagingLabels[$type], array( $label ) );
			$disabledTexts[$type] = Xml::wrapClass( $linkTexts[$type], 'disabled' );
		}

		$pagingLinks = $this->mPager->getPagingLinks( $linkTexts, $disabledTexts );
// 		$limitLinks = $this->mPager->getLimitLinks(); // XXX: Not used yet.
		$ellipsis = wfMsg( 'ellipsis' );
		$html = "{$pagingLinks['first']} {$pagingLinks['prev']} {$ellipsis} {$pagingLinks['next']} {$pagingLinks['last']}";
		$html = WikilogUtils::wrapDiv( 'wl-pagination', $html );

		$dir = $wgLang->getDir();

		return Xml::tags( 'div',
			array(
				'class' => 'wl-navbar',
				'dir' => $dir
			),
			$html
		);
	}
	/**
	 * Start a new comment thread. Should be called before formatComment()
	 * when formatting comments in threads. Comments must be displayed in
	 * correct thread sequence when using this function, which means that
	 * the 'wlc_thread' column should be used to sort the query results from
	 * the 'wikilog_comments' table. After the last comment,
	 * closeCommentThreads() must be called.
	 *
	 * @param $comment Comment to be formatted.
	 * @return Generated HTML.
	 */
	public function startCommentThread( $comment ) {
		$top = count( $this->mThreadStack );
		$thread = count( $comment->mThread );

		# Find common ancestors.
		$common = min( $top, $thread );
		for ( $i = 0; $i < $common; $i++ ) {
			if ( $this->mThreadStack[$i] != $comment->mThread[$i] )
				break;
		}

		# Close previous threads.
		$html = str_repeat( "</div>", $top - $i );
		array_splice( $this->mThreadStack, $i );

		# Create omitted comment thread(s).
		for ( ; $i < $thread-1; $i++ ) {
			$msg = wfMsgExt( 'wikilog-comment-omitted-x', array( 'parseinline' ), $comment->mThread[$i] );
			$msg = WikilogUtils::wrapDiv( 'wl-comment-placeholder', $msg );
			$msg = WikilogUtils::wrapDiv( 'wl-comment wl-comment-omitted', $msg );
			$html .= '<div class="wl-thread">' . $msg;
			array_push( $this->mThreadStack, $comment->mThread[$i] );
		}

		# Open the new comment thread.
		$html .= '<div class="wl-thread">';
		array_push( $this->mThreadStack, $comment->mThread[$i] );
		return $html;
	}
	function formatRow( $row ) {
		global $wgWikilogExtSummaries;
		$skin = $this->getSkin();
		$header = $footer = '';

		# Retrieve article parser output and other data.
		$item = WikilogItem::newFromRow( $row );
		list( $article, $parserOutput ) = WikilogUtils::parsedArticle( $item->mTitle );
		list( $summary, $content ) = WikilogUtils::splitSummaryContent( $parserOutput );

		# Retrieve the common header and footer parameters.
		$params = $item->getMsgParams( $wgWikilogExtSummaries, $parserOutput );

		# Article title heading, with direct link article page and optional
		# edit link (if user can edit the article).
		$titleText = Sanitizer::escapeHtmlAllowEntities( $item->mName );
		if ( !$item->getIsPublished() )
			$titleText .= wfMsgForContent( 'wikilog-draft-title-mark' );
		$heading = $skin->link( $item->mTitle, $titleText, array(), array(),
			array( 'known', 'noclasses' )
		);
		if ( $this->mShowEditLink && $item->mTitle->quickUserCan( 'edit' ) ) {
			$heading = $this->doEditLink( $item->mTitle, $item->mName ) . $heading;
		}
		$heading = Xml::tags( 'h2', null, $heading );

		# Sumary entry header.
		$key = $this->mQuery->isSingleWikilog()
			? 'wikilog-summary-header-single'
			: 'wikilog-summary-header';
		$msg = wfMsgExt( $key, array( 'content', 'parsemag' ), $params );
		if ( !empty( $msg ) ) {
			$header = WikilogUtils::wrapDiv( 'wl-summary-header', $this->parse( $msg ) );
		}

		# Summary entry text.
		if ( $summary ) {
			$more = $this->parse( wfMsgForContentNoTrans( 'wikilog-summary-more', $params ) );
			$summary = WikilogUtils::wrapDiv( 'wl-summary', $summary . $more );
		} else {
			$summary = WikilogUtils::wrapDiv( 'wl-summary', $content );
		}

		# Summary entry footer.
		$key = $this->mQuery->isSingleWikilog()
			? 'wikilog-summary-footer-single'
			: 'wikilog-summary-footer';
		$msg = wfMsgExt( $key, array( 'content', 'parsemag' ), $params );
		if ( !empty( $msg ) ) {
			$footer = WikilogUtils::wrapDiv( 'wl-summary-footer', $this->parse( $msg ) );
		}

		# Assembly the entry div.
		$divclass = array( 'wl-entry', 'visualClear' );
		if ( !$item->getIsPublished() )
			$divclass[] = 'wl-draft';
		$entry = WikilogUtils::wrapDiv(
			implode( ' ', $divclass ),
			$heading . $header . $summary . $footer
		);
		return $entry;
	}
	/**
	 * Wikilog action handler.
	 */
	public function wikilog() {
		global $wgUser, $wgOut, $wgRequest;

		if ( $this->mTitle->exists() && $wgRequest->getBool( 'wlActionNewItem' ) )
			return $this->actionNewItem();

		$wgOut->setPageTitle( wfMsg( 'wikilog-tab-title' ) );
		$wgOut->setRobotpolicy( 'noindex,nofollow' );

		if ( $this->mTitle->exists() ) {
			$skin = $wgUser->getSkin();
			$wgOut->addHTML( $this->formatWikilogDescription( $skin ) );
			$wgOut->addHTML( $this->formatWikilogInformation( $skin ) );
			if ( $this->mTitle->quickUserCan( 'edit' ) ) {
				$wgOut->addHTML( $this->formNewItem() );
			}
		} elseif ( $this->mTitle->userCan( 'create' ) ) {
			$text = wfMsgExt( 'wikilog-missing-wikilog', 'parse' );
			$text = WikilogUtils::wrapDiv( 'noarticletext', $text );
			$wgOut->addHTML( $text );
		} else {
			$this->showMissingArticle();
		}
	}
	public function formatRow( $row ) {
		# Retrieve comment data.
		$item = $this->mSingleItem ? $this->mSingleItem : WikilogItem::newFromRow( $row );
		$comment = WikilogComment::newFromRow( $item, $row );
		$comment->loadText();

		$doReply = $this->mReplyTrigger && $comment->mID == $this->mReplyTrigger;

		$html = $this->mFormatter->startCommentThread( $comment );
		$html .= $this->mFormatter->formatComment( $comment, $doReply );

		if ( $doReply && is_callable( $this->mReplyCallback ) ) {
			if ( ( $res = call_user_func( $this->mReplyCallback, $comment ) ) ) {
				$html .= WikilogUtils::wrapDiv( 'wl-indent', $res );
			}
		}
		return $html;
	}