var $textbox1 = '', $textbox2 = '', $summary = '', $nosummary = false;
var $edittime = '', $section = '', $sectiontitle = '', $starttime = '';
var $oldid = 0, $editintro = '', $scrolltop = null, $bot = true;
- var $content_model = null, $content_format = null;
+ var $contentModel = null, $contentFormat = null;
# Placeholders for text injection by hooks (must be HTML)
# extensions should take care to _append_ to the present value
$this->mArticle = $article;
$this->mTitle = $article->getTitle();
- $this->content_model = $this->mTitle->getContentModel();
+ $this->contentModel = $this->mTitle->getContentModel();
- $handler = ContentHandler::getForModelID( $this->content_model );
- $this->content_format = $handler->getDefaultFormat(); #NOTE: should be overridden by format of actual revision
+ $handler = ContentHandler::getForModelID( $this->contentModel );
+ $this->contentFormat = $handler->getDefaultFormat();
}
/**
/**
* Get the context title object.
- * If not set, $wgTitle will be returned. This behavior might changed in
+ * If not set, $wgTitle will be returned. This behavior might change in
* the future to return $this->mTitle instead.
*
* @return Title object
$this->isCssSubpage = $this->mTitle->isCssSubpage();
$this->isJsSubpage = $this->mTitle->isJsSubpage();
$this->isWrongCaseCssJsPage = $this->isWrongCaseCssJsPage();
- $this->isNew = !$this->mTitle->exists() || $this->section == 'new';
# Show applicable editing introductions
if ( $this->formtype == 'initial' || $this->firsttime ) {
* @since 1.19
* @param $permErrors Array of permissions errors, as returned by
* Title::getUserPermissionsErrors().
+ * @throws PermissionsError
*/
protected function displayPermissionsError( array $permErrors ) {
global $wgRequest, $wgOut;
throw new PermissionsError( $action, $permErrors );
}
+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
$wgOut->setPageTitle( wfMessage( 'viewsource-title', $this->getContextTitle()->getPrefixedText() ) );
$wgOut->addBacklinkSubtitle( $this->getContextTitle() );
$wgOut->addWikiText( $wgOut->formatPermissionsErrorMessage( $permErrors, 'edit' ) );
* @param $request WebRequest
*/
function importFormData( &$request ) {
- global $wgLang, $wgUser;
+ global $wgContLang, $wgUser;
wfProfileIn( __METHOD__ );
# Section edit can come from either the form or a link
$this->section = $request->getVal( 'wpSection', $request->getVal( 'section' ) );
+ $this->isNew = !$this->mTitle->exists() || $this->section == 'new';
if ( $request->wasPosted() ) {
# These fields need to be checked for encoding.
}
# Truncate for whole multibyte characters
- $this->summary = $wgLang->truncate( $request->getText( 'wpSummary' ), 255 );
+ $this->summary = $wgContLang->truncate( $request->getText( 'wpSummary' ), 255 );
# If the summary consists of a heading, e.g. '==Foobar==', extract the title from the
# header syntax, e.g. 'Foobar'. This is mainly an issue when we are using wpSummary for
# currently doing double duty as both edit summary and section title. Right now this
# is just to allow API edits to work around this limitation, but this should be
# incorporated into the actual edit form when EditPage is rewritten (Bugs 18654, 26312).
- $this->sectiontitle = $wgLang->truncate( $request->getText( 'wpSectionTitle' ), 255 );
+ $this->sectiontitle = $wgContLang->truncate( $request->getText( 'wpSectionTitle' ), 255 );
$this->sectiontitle = preg_replace( '/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->sectiontitle );
$this->edittime = $request->getVal( 'wpEdittime' );
$this->nosummary = $request->getBool( 'nosummary' );
$content_handler = ContentHandler::getForTitle( $this->mTitle );
- $this->content_model = $request->getText( 'model', $content_handler->getModelID() ); #may be overridden by revision
- $this->content_format = $request->getText( 'format', $content_handler->getDefaultFormat() ); #may be overridden by revision
+ $this->contentModel = $request->getText( 'model', $content_handler->getModelID() ); #may be overridden by revision
+ $this->contentFormat = $request->getText( 'format', $content_handler->getDefaultFormat() ); #may be overridden by revision
#TODO: check if the desired model is allowed in this namespace, and if a transition from the page's current model to the new model is allowed
#TODO: check if the desired content model supports the given content format!
* @param $def_text string
* @return mixed string on success, $def_text for invalid sections
* @private
- * @deprecated since 1.21
- * @todo: deprecated, replace usage everywhere
+ * @deprecated since 1.21, get WikiPage::getContent() instead.
*/
function getContent( $def_text = false ) {
- wfDeprecated( __METHOD__, '1.21' );
+ ContentHandler::deprecated( __METHOD__, '1.21' );
if ( $def_text !== null && $def_text !== false && $def_text !== '' ) {
$def_content = $this->toEditContent( $def_text );
return $this->toEditText( $content );
}
- private function getContentObject( $def_content = null ) {
+ /**
+ * @param Content|false $def_content The default value to return
+ *
+ * @return mixed Content on success, $def_content for invalid sections
+ *
+ * @since 1.21
+ */
+ protected function getContentObject( $def_content = null ) {
global $wgOut, $wgRequest;
wfProfileIn( __METHOD__ );
}
$revision = $this->mArticle->getRevisionFetched();
if ( $revision === null ) {
- if ( !$this->content_model ) $this->content_model = $this->getTitle()->getContentModel();
- $handler = ContentHandler::getForModelID( $this->content_model );
+ if ( !$this->contentModel ) $this->contentModel = $this->getTitle()->getContentModel();
+ $handler = ContentHandler::getForModelID( $this->contentModel );
return $handler->makeEmptyContent();
}
* content object is returned instead of null.
*
* @since 1.21
- * @return string
+ * @return Content
*/
- private function getCurrentContent() {
+ protected function getCurrentContent() {
$rev = $this->mArticle->getRevision();
$content = $rev ? $rev->getContent( Revision::RAW ) : null;
if ( $content === false || $content === null ) {
- if ( !$this->content_model ) $this->content_model = $this->getTitle()->getContentModel();
- $handler = ContentHandler::getForModelID( $this->content_model );
+ if ( !$this->contentModel ) $this->contentModel = $this->getTitle()->getContentModel();
+ $handler = ContentHandler::getForModelID( $this->contentModel );
return $handler->makeEmptyContent();
} else {
# nasty side-effect, but needed for consistency
- $this->content_model = $rev->getContentModel();
- $this->content_format = $rev->getContentFormat();
+ $this->contentModel = $rev->getContentModel();
+ $this->contentFormat = $rev->getContentFormat();
return $content;
}
* Use this method before edit() to preload some text into the edit box
*
* @param $text string
- * @deprecated since 1.21
+ * @deprecated since 1.21, use setPreloadedContent() instead.
*/
public function setPreloadedText( $text ) {
- wfDeprecated( __METHOD__, "1.21" );
+ ContentHandler::deprecated( __METHOD__, "1.21" );
$content = $this->toEditContent( $text );
* @since 1.21
*/
public function setPreloadedContent( Content $content ) {
- $this->mPreloadedContent = $content;
+ $this->mPreloadContent = $content;
}
/**
*
* @deprecated since 1.21, use getPreloadedContent() instead
*/
- protected function getPreloadedText( $preload ) { #NOTE: B/C only, replace usage!
- wfDeprecated( __METHOD__, "1.21" );
+ protected function getPreloadedText( $preload ) {
+ ContentHandler::deprecated( __METHOD__, "1.21" );
$content = $this->getPreloadedContent( $preload );
$text = $this->toEditText( $content );
*
* @since 1.21
*/
- protected function getPreloadedContent( $preload ) { #@todo: use this!
+ protected function getPreloadedContent( $preload ) {
global $wgUser;
if ( !empty( $this->mPreloadContent ) ) {
/**
* Attempt submission
+ * @throws UserBlockedError|ReadOnlyError|ThrottledError|PermissionsError
* @return bool false if output is done, true if the rest of the form should be displayed
*/
function attemptSave() {
# Construct Content object
$textbox_content = $this->toEditContent( $this->textbox1 );
} catch (MWContentSerializationException $ex) {
- $status->fatal( 'content-failed-to-parse', $this->content_model, $this->content_format, $ex->getMessage() );
+ $status->fatal( 'content-failed-to-parse', $this->contentModel, $this->contentFormat, $ex->getMessage() );
$status->value = self::AS_PARSE_ERROR;
wfProfileOut( __METHOD__ );
return $status;
$this->isConflict = false;
wfDebug( __METHOD__ . ": conflict suppressed; new section\n" );
}
- } elseif ( $this->section == '' && Revision::userWasLastToEdit( DB_MASTER, $this->mTitle->getArticleID(), $wgUser->getId(), $this->edittime ) ) {
+ } elseif ( $this->section == '' && Revision::userWasLastToEdit( DB_MASTER, $this->mTitle->getArticleID(),
+ $wgUser->getId(), $this->edittime ) ) {
# Suppress edit conflict with self, except for section edits where merging is required.
wfDebug( __METHOD__ . ": Suppressing edit conflict, same user.\n" );
$this->isConflict = false;
wfDebug( __METHOD__ . ": conflict! getting section '{$this->section}' for time '{$this->edittime}'"
. " (article time '{$timestamp}')\n" );
- $content = $this->mArticle->replaceSectionContent( $this->section, $textbox_content,
- $sectionTitle, $this->edittime );
+ $content = $this->mArticle->replaceSectionContent( $this->section, $textbox_content, $sectionTitle, $this->edittime );
} else {
wfDebug( __METHOD__ . ": getting section '{$this->section}'\n" );
$content = $this->mArticle->replaceSectionContent( $this->section, $textbox_content, $sectionTitle );
( $bot ? EDIT_FORCE_BOT : 0 );
$doEditStatus = $this->mArticle->doEditContent( $content, $this->summary, $flags,
- false, null, $this->content_format );
+ false, null, $this->contentFormat );
if ( $doEditStatus->isOK() ) {
$result['redirect'] = $content->isRedirect();
* @deprecated since 1.21, use mergeChangesIntoContent() instead
*/
function mergeChangesInto( &$editText ){
- wfDebug( __METHOD__, "1.21" );
+ ContentHandler::deprecated( __METHOD__, "1.21" );
$editContent = $this->toEditContent( $editText );
* @parma $editText string
*
* @return bool
- * @since since 1.21
+ * @since since 1.WD
*/
private function mergeChangesIntoContent( &$editContent ){
wfProfileIn( __METHOD__ );
. ContentHandler::getLocalizedName( $content->getModel() ) );
}
- return $content->serialize( $this->content_format );
+ return $content->serialize( $this->contentFormat );
}
/**
* an exception will be raised. Set $this->allowNonTextContent to true to allow editing of non-textual
* content.
*
- * @param String $text Text to unserialize
- * @return Content the content object created from $text
+ * @param String|null|false $text Text to unserialize
+ * @return Content The content object created from $text. If $text was false or null, false resp. null will be
+ * returned instead.
*
* @throws MWException if unserializing the text results in a Content object that is not an instance of TextContent
* and $this->allowNonTextContent is not true.
*/
protected function toEditContent( $text ) {
+ if ( $text === false || $text === null ) {
+ return $text;
+ }
+
$content = ContentHandler::makeContent( $text, $this->getTitle(),
- $this->content_model, $this->content_format );
+ $this->contentModel, $this->contentFormat );
if ( !$this->allowNonTextContent && !( $content instanceof TextContent ) ) {
throw new MWException( "This content model can not be edited as text: "
$wgOut->addHTML( Html::hidden( 'oldid', $this->oldid ) );
- $wgOut->addHTML( Html::hidden( 'format', $this->content_format ) );
- $wgOut->addHTML( Html::hidden( 'model', $this->content_model ) );
+ $wgOut->addHTML( Html::hidden( 'format', $this->contentFormat ) );
+ $wgOut->addHTML( Html::hidden( 'model', $this->contentModel ) );
if ( $this->section == 'new' ) {
$this->showSummaryInput( true, $this->summary );
$this->showConflict();
} catch ( MWContentSerializationException $ex ) {
// this can't really happen, but be nice if it does.
- $msg = wfMessage( 'content-failed-to-parse', $this->content_model, $this->content_format, $ex->getMessage() );
+ $msg = wfMessage( 'content-failed-to-parse', $this->contentModel, $this->contentFormat, $ex->getMessage() );
$wgOut->addWikiText( '<div class="error">' . $msg->text() . '</div>');
}
}
try {
$this->showDiff();
} catch ( MWContentSerializationException $ex ) {
- $msg = wfMessage( 'content-failed-to-parse', $this->content_model, $this->content_format, $ex->getMessage() );
+ $msg = wfMessage( 'content-failed-to-parse', $this->contentModel, $this->contentFormat, $ex->getMessage() );
$wgOut->addWikiText( '<div class="error">' . $msg->text() . '</div>');
}
}
$textboxContent = $this->toEditContent( $this->textbox1 );
$newContent = $this->mArticle->replaceSectionContent(
- $this->section, $textboxContent,
- $this->summary, $this->edittime );
+ $this->section, $textboxContent,
+ $this->summary, $this->edittime );
ContentHandler::runLegacyHooks( 'EditPageGetDiffText', array( $this, &$newContent ) );
wfRunHooks( 'EditPageGetDiffContent', array( $this, &$newContent ) );
$content1 = $this->toEditContent( $this->textbox1 );
$content2 = $this->toEditContent( $this->textbox2 );
- $handler = ContentHandler::getForModelID( $this->content_model );
+ $handler = ContentHandler::getForModelID( $this->contentModel );
$de = $handler->createDifferenceEngine( $this->mArticle->getContext() );
$de->setContent( $content2, $content1 );
- $de->showDiff(
+ $de->showDiff(
wfMessage( 'yourtext' )->parse(),
wfMessage( 'storedversion' )->text()
);
/**
* Get the rendered text for previewing.
+ * @throws MWException
* @return string
*/
function getPreviewText() {
$parserOptions = $this->mArticle->makeParserOptions( $this->mArticle->getContext() );
$parserOptions->setEditSection( false );
- $parserOptions->setTidy( true );
$parserOptions->setIsPreview( true );
$parserOptions->setIsSectionPreview( !is_null($this->section) && $this->section !== '' );
# If we're adding a comment, we need to show the
# summary as the headline
- if ( $this->section == "new" && $this->summary != "" ) {
+ if ( $this->section === "new" && $this->summary !== "" ) {
$content = $content->addSectionHeader( $this->summary );
}
$note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
}
}
- } catch (MWContentSerializationException $ex) {
- $m = wfMessage('content-failed-to-parse', $this->content_model, $this->content_format, $ex->getMessage() );
+ } catch ( MWContentSerializationException $ex ) {
+ $m = wfMessage('content-failed-to-parse', $this->contentModel, $this->contentFormat, $ex->getMessage() );
$note .= "\n\n" . $m->parse();
$previewHTML = '';
}