/**
	 * 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() );
		}
	}
	/**
	 * Handy method to set either the wikilog or the item to query for.
	 * @param $from Title, WikilogInfo or WikilogItem object.
	 */
	public function setWikilogOrItem( $from ) {
		if ( $from instanceof Title ) {
			$from = Wikilog::getWikilogInfo( $from );
		}
		if ( $from instanceof WikilogInfo ) {
			if ( $from->isItem() ) {
				$from = WikilogItem::newFromInfo( $from );
			} else {
				$this->setWikilog( $from->getTitle() );
				return;
			}
		}
		if ( $from instanceof WikilogItem ) {
			$this->setItem( $from );
			return;
		} else {
			throw new MWException( "Not a valid wikilog object." );
		}
	}
Esempio n. 3
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;
	}
	/**
	 * 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;
	}