/**
	 * Constructor.
	 *
	 * @param $title Title of the page.
	 * @param $wi WikilogInfo object with information about the wikilog and
	 *   the item.
	 */
	function __construct( Title &$title, WikilogInfo &$wi ) {
		global $wgUser, $wgRequest;

		parent::__construct( $title );

		# Check if user can post.
		$this->mUserCanPost = $wgUser->isAllowed( 'wl-postcomment' ) ||
			( $wgUser->isAllowed( 'edit' ) && $wgUser->isAllowed( 'createtalk' ) );
		$this->mUserCanModerate = $wgUser->isAllowed( 'wl-moderation' );

		# Prepare the skin and the comment formatter.
		$this->mSkin = $wgUser->getSkin();
		$this->mFormatter = new WikilogCommentFormatter( $this->mSkin, $this->mUserCanPost );

		# Get item object relative to this comments page.
		$this->mItem = WikilogItem::newFromInfo( $wi );

		# Form options.
		$this->mFormOptions = new FormOptions();
		$this->mFormOptions->add( 'wlAnonName', '' );
		$this->mFormOptions->add( 'wlComment', '' );
		$this->mFormOptions->fetchValuesFromRequest( $wgRequest,
			array( 'wlAnonName', 'wlComment' ) );

		# This flags if we are viewing a single comment (subpage).
		$this->mTrailing = $wi->getTrailing();
		$this->mTalkTitle = $wi->getItemTalkTitle();
		if ( $this->mItem && $this->mTrailing ) {
			$this->mSingleComment =
				WikilogComment::newFromPageID( $this->mItem, $this->getID() );
		}
	}
	/**
	 * Constructor from a page ID.
	 * @param $id Int article ID to load.
	 */
	public static function newFromID( $id ) {
		$t = Title::newFromID( $id );
		$i = WikilogItem::newFromID( $id );
		return $t == null ? null : new self( $t, $i );
	}
예제 #3
0
	/**
	 * Formats a comments page link.
	 *
	 * @param $item WikilogItem object.
	 * @return Wikitext-formatted comments link.
	 */
	public static function getCommentsWikiText( WikilogItem &$item ) {
		$commentsNum = $item->getNumComments();
		$commentsMsg = ( $commentsNum ? 'wikilog-has-comments' : 'wikilog-no-comments' );
		$commentsUrl = $item->mTitle->getTalkPage()->getPrefixedURL();
		$commentsTxt = wfMsgExt( $commentsMsg, array( 'parsemag', 'content' ), $commentsNum );
		return "[[{$commentsUrl}|{$commentsTxt}]]";
	}
예제 #4
0
	/**
	 * Generates and returns a single feed entry.
	 * @param $row The wikilog comment database entry.
	 * @return A new WlSyndicationEntry object.
	 */
	function formatFeedEntry( $row ) {
		global $wgMimeType;

		# Create comment object.
		$item = $this->mSingleItem ? $this->mSingleItem : WikilogItem::newFromRow( $row );
		$comment = WikilogComment::newFromRow( $item, $row );

		# Prepare some strings.
		if ( $comment->mUserID ) {
			$usertext = $comment->mUserText;
		} else {
			$usertext = wfMsgForContent( 'wikilog-comment-anonsig',
				$comment->mUserText, ''/*talk*/, $comment->mAnonName
			);
		}
		if ( $this->mSingleItem ) {
			$title = wfMsgForContent( 'wikilog-comment-feed-title1',
				$comment->mID, $usertext
			);
		} else {
			$title = wfMsgForContent( 'wikilog-comment-feed-title2',
				$comment->mID, $usertext, $comment->mItem->mName
			);
		}

		# Create new syndication entry.
		$entry = new WlSyndicationEntry(
			self::makeEntryId( $comment ),
			$title,
			$comment->mUpdated,
			$comment->getCommentArticleTitle()->getFullUrl()
		);

		# Comment text.
		if ( $comment->mCommentRev ) {
			list( $article, $parserOutput ) = WikilogUtils::parsedArticle( $comment->mCommentTitle, true );
			$content = Sanitizer::removeHTMLcomments( $parserOutput->getText() );
			if ( $content ) {
				$entry->setContent( new WlTextConstruct( 'html', $content ) );
			}
		}

		# Author.
		$usertitle = Title::makeTitle( NS_USER, $comment->mUserText );
		$useruri = $usertitle->exists() ? $usertitle->getFullUrl() : null;
		$entry->addAuthor( $usertext, $useruri );

		# Timestamp
		$entry->setPublished( $comment->mTimestamp );

		return $entry;
	}
	function formatRow( $row ) {
		$attribs = array();
		$columns = array();
		$this->mCurrentRow = $row;
		$this->mCurrentItem = WikilogItem::newFromRow( $row );
		if ( !$this->mCurrentItem->getIsPublished() ) {
			$attribs['class'] = 'wl-draft';
		}
		foreach ( $this->getFieldNames() as $field => $name ) {
			$value = isset( $row->$field ) ? $row->$field : null;
			$formatted = strval( $this->formatValue( $field, $value ) );
			if ( $formatted == '' ) {
				$formatted = WL_NBSP;
			}
			$class = 'TablePager_col_' . htmlspecialchars( $field );
			$columns[] = "<td class=\"$class\">$formatted</td>";
		}
		return Xml::tags( 'tr', $attribs, implode( "\n", $columns ) ) . "\n";
	}
예제 #6
0
	/**
	 * ArticleFromTitle hook handler function.
	 * Detects if the article is a wikilog article (self::getWikilogInfo
	 * returns an instance of WikilogInfo) and returns the proper class
	 * instance for the article.
	 */
	static function ArticleFromTitle( &$title, &$article ) {
		global $wgWikilogEnableComments;

		if ( ( $wi = self::getWikilogInfo( $title ) ) ) {
			if ( $title->isTalkPage() ) {
				if ( $wgWikilogEnableComments && $wi->isItem() ) {
					$article = new WikilogCommentsPage( $title, $wi );
				} else {
					return true;
				}
			} elseif ( $wi->isItem() ) {
				$item = WikilogItem::newFromInfo( $wi );
				$article = new WikilogItemPage( $title, $item );
			} else {
				$article = new WikilogMainPage( $title, $wi );
			}
			return false;	// stop processing
		}
		return true;
	}
예제 #7
0
	/**
	 * Organizes all the query information and constructs the table and
	 * field lists that will later form the SQL SELECT statement.
	 * @param $db Database object.
	 * @param $opts Array with query options. Keys are option names, values
	 *   are option values.
	 * @return Array with tables, fields, conditions, options and join
	 *   conditions, to be used in a call to $db->select(...).
	 */
	public function getQueryInfo( $db, $opts = array() ) {
		$this->setOptions( $opts );

		$join_wlp = false;

		# Basic defaults.
		$wlc_tables = WikilogComment::selectTables( $db );
		$q_tables = $wlc_tables['tables'];
		$q_fields = WikilogComment::selectFields();
		$q_conds = array();
		$q_options = array();
		$q_joins = $wlc_tables['join_conds'];

		# Invalid filter.
		if ( $this->mEmpty ) {
			$q_conds[] = '0=1';
		}

		# Filter by moderation status.
		if ( $this->mModStatus == self::MS_ACCEPTED ) {
			$q_conds['wlc_status'] = 'OK';
		} elseif ( $this->mModStatus == self::MS_PENDING ) {
			$q_conds['wlc_status'] = 'PENDING';
		} elseif ( $this->mModStatus == self::MS_NOTDELETED ) {
			$q_conds[] = "wlc_status <> " . $db->addQuotes( 'DELETED' );
		} elseif ( $this->mModStatus == self::MS_NOTPENDING ) {
			$q_conds[] = "wlc_status <> " . $db->addQuotes( 'PENDING' );
		}

		# Filter by article or wikilog.
		if ( $this->mItem !== null ) {
			$q_conds['wlc_post'] = $this->mItem->getID();
			if ( $this->mThread ) {
				$q_conds[] = "wlc_thread " . $db->buildLike( $this->mThread . '/', $db->anyString() );
			}
		} elseif ( $this->mWikilog !== null ) {
			$join_wlp = true;
			$q_conds['wlp_parent'] = $this->mWikilog->getArticleId();
		} elseif ( $this->mNamespace !== false ) {
			$q_conds['c.page_namespace'] = $this->mNamespace;
		}

		# Filter by author.
		if ( $this->mAuthor ) {
			$q_conds['wlc_user_text'] = $this->mAuthor;
		}

		# Filter by date.
		if ( $this->mDate ) {
			$q_conds[] = 'wlc_timestamp >= ' . $db->addQuotes( $this->mDate->start );
			$q_conds[] = 'wlc_timestamp < ' . $db->addQuotes( $this->mDate->end );
		}

		# Additional data.
		if ( $this->getOption( 'include-item' ) ) {
			$wlp_tables = WikilogItem::selectTables( $db );
			$q_tables = array_merge( $q_tables, $wlp_tables['tables'] );
			$q_joins['wikilog_posts'] = array( 'JOIN', 'wlp_page = wlc_post' );
			$q_joins += $wlp_tables['join_conds'];
			$q_fields = array_merge( $q_fields, WikilogItem::selectFields() );
		} elseif ( $join_wlp ) {
			$q_tables[] = 'wikilog_posts';
			$q_joins['wikilog_posts'] = array( 'JOIN', 'wlp_page = wlc_post' );
		}

		return array(
			'tables' => $q_tables,
			'fields' => $q_fields,
			'conds' => $q_conds,
			'options' => $q_options,
			'join_conds' => $q_joins
		);
	}
예제 #8
0
	/**
	 * EditPage::showEditForm:fields hook handler function.
	 * Adds wikilog article options to edit pages.
	 */
	static function EditPageEditFormFields( &$editpage, &$output ) {
		$wi = Wikilog::getWikilogInfo( $editpage->mTitle );
		if ( $wi && $wi->isItem() && !$wi->isTalk() ) {
			global $wgUser, $wgWikilogSignAndPublishDefault;
			$fields = array();
			$item = WikilogItem::newFromInfo( $wi );

			# [x] Sign and publish this wikilog article.
			if ( !$item || !$item->getIsPublished() ) {
				if ( isset( $editpage->wlSignpub ) ) {
					$checked = $editpage->wlSignpub;
				} else {
					$checked = !$item && $wgWikilogSignAndPublishDefault;
				}
				$label = wfMsgExt( 'wikilog-edit-signpub', array( 'parseinline' ) );
				$tooltip = wfMsgExt( 'wikilog-edit-signpub-tooltip', array( 'parseinline' ) );
				$fields['wlSignpub'] =
					Xml::check( 'wlSignpub', $checked, array(
						'id' => 'wl-signpub',
						'tabindex' => 1, // after text, before summary
					) ) . WL_NBSP .
					Xml::element( 'label', array(
						'for' => 'wl-signpub',
						'title' => $tooltip,
					), $label );
			}

			$fields = implode( $fields, "\n" );
			$html = Xml::fieldset(
				wfMsgExt( 'wikilog-edit-fieldset-legend', array( 'parseinline' ) ),
				$fields
			);
			$editpage->editFormTextAfterWarn .= $html;
		}
		return true;
	}
	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;
	}