Ejemplo n.º 1
0
function wfTalkHereAjaxEditor( $page, $section, $returnto ) {
	global $wgRequest, $wgTitle, $wgOut;

	$title = Title::newFromText( $page );
	if ( !$title ) {
		return false;
	}

	//fake editor environment
	$args = array(
		'wpTalkHere' => '1',
		'wpReturnTo' => $returnto,
		'action' => 'edit',
		'section' => $section
	);

	$wgRequest = new FauxRequest( $args );
	$wgTitle = $title;

	$article = Article::newFromTitle( $title, RequestContext::getMain() );
	$editor = new TalkHereEditPage( $article );

	//generate form
	$editor->importFormData( $wgRequest );
	$editor->showEditForm();

	$response = new AjaxResponse();
	$response->addText( $wgOut->getHTML() );
	$response->setCacheDuration( false ); //don't cache, because of tokens etc

	return $response;
}
Ejemplo n.º 2
0
	public static function onCustomEditor( $article, $user ) {
		global $wgRequest, $wgOut;

		$action = $wgRequest->getVal( 'action' );
		$oldid = $wgRequest->getVal( 'oldid' );
		$returnto = $wgRequest->getVal( 'wpReturnTo' );
		$talkhere = $wgRequest->getVal( 'wpTalkHere' );
		if (!$talkhere || $action != 'submit' || !$returnto || $oldid) return true; //go on as normal

		$to = Title::newFromText($returnto);
		if (!$to) return true; //go on as normal

		//use a wrapper to override redirection target
		$editor = new TalkHereEditPage( $article );
		$editor->setReturnTo( $to );
		$editor->edit();
		$code = $editor->getCode();

		if ( $code == EditPage::AS_SUCCESS_NEW_ARTICLE ) {
			$wgOut->redirect( $to->getFullURL() . '#talkhere' );
		} elseif ( $code == EditPage::AS_SUCCESS_UPDATE ) {
			$wgOut->redirect( $to->getFullURL() . $editor->getAnchor() );
		}

		return false;
	}