Пример #1
0
	/**
	 * 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." );
		}
	}
	/**
	 * ParserBeforeStrip hook handler function.
	 */
	public static function BeforeStrip( &$parser, &$text, &$stripState ) {
		global $wgUser;

		# Do nothing if a title is not set.
		if ( ! ( $title = $parser->getTitle() )  )
			return true;

		# Do nothing if it is not a wikilog article.
		if ( ! ( $parser->mExtWikilogInfo = Wikilog::getWikilogInfo( $title ) ) )
			return true;

		if ( $parser->mExtWikilogInfo->isItem() ) {
			# By default, use the item name as the default sort in categories.
			# This can be overriden by {{DEFAULTSORT:...}} if the user wants.
			$parser->setDefaultSort( $parser->mExtWikilogInfo->getItemName() );
		}

		return true;
	}
Пример #3
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;
	}