$title = Title::newFromText( $preload );
# Check for existence to avoid getting MediaWiki:Noarticletext
if ( $title === null || !$title->exists() || !$title->userCan( 'read', $wgUser ) ) {
+ //TODO: somehow show a warning to the user!
return $handler->makeEmptyContent();
}
$title = $page->getRedirectTarget();
# Same as before
if ( $title === null || !$title->exists() || !$title->userCan( 'read', $wgUser ) ) {
+ //TODO: somehow show a warning to the user!
return $handler->makeEmptyContent();
}
$page = WikiPage::factory( $title );
$content = $page->getContent( Revision::RAW );
if ( !$content ) {
+ //TODO: somehow show a warning to the user!
return $handler->makeEmptyContent();
}
+ if ( $content->getModel() !== $handler->getModelID() ) {
+ $converted = $content->convert( $handler->getModelID() );
+
+ if ( !$converted ) {
+ //TODO: somehow show a warning to the user!
+ wfDebug( "Attempt to preload incompatible content: "
+ . "can't convert " . $content->getModel()
+ . " to " . $handler->getModelID() );
+
+ return $handler->makeEmptyContent();
+ }
+
+ $content = $converted;
+ }
+
return $content->preloadTransform( $title, $parserOptions );
}
$this->isConflict = true;
$content = $textbox_content; // do not try to merge here!
} elseif ( $this->isConflict ) {
- $contentObj = $content;
# Attempt merge
- if ( $this->mergeChangesInto( $content ) ) {
+ if ( $this->mergeChangesIntoContent( $content ) ) {
// Successful merge! Maybe we should tell the user the good news?
$this->isConflict = false;
- $content = $this->toEditContent( $content );
wfDebug( __METHOD__ . ": Suppressing edit conflict, successful merge.\n" );
} else {
$this->section = '';
- $this->textbox1 = ContentHandler::getContentText( $contentObj );
+ $this->textbox1 = ContentHandler::getContentText( $content );
wfDebug( __METHOD__ . ": Keeping edit conflict, failed merge.\n" );
}
}
function mergeChangesInto( &$editText ){
ContentHandler::deprecated( __METHOD__, "1.21" );
- wfProfileIn( __METHOD__ );
+ $editContent = $this->toEditContent( $editText );
- $db = wfGetDB( DB_MASTER );
+ $ok = $this->mergeChangesIntoContent( $editContent );
- // This is the revision the editor started from
- $baseRevision = $this->getBaseRevision();
- if ( is_null( $baseRevision ) ) {
- wfProfileOut( __METHOD__ );
- return false;
- }
- $baseText = $baseRevision->getText();
-
- // The current state, we want to merge updates into it
- $currentRevision = Revision::loadFromTitle( $db, $this->mTitle );
- if ( is_null( $currentRevision ) ) {
- wfProfileOut( __METHOD__ );
- return false;
- }
- $currentText = $currentRevision->getText();
-
- $result = '';
- $editText = $this->toEditText( $editText );
-
- if ( wfMerge( $baseText, $editText, $currentText, $result ) ) {
- $editText = $result;
- wfProfileOut( __METHOD__ );
+ if ( $ok ) {
+ $editText = $this->toEditText( $editContent );
return true;
- } else {
- wfProfileOut( __METHOD__ );
- return false;
}
+ return false;
}
/**
* an exception will be raised. Set $this->allowNonTextContent to true to allow editing of non-textual
* content.
*
- * @param Content|null|false|string $content
+ * @param Content|null|bool|string $content
* @return String the editable text form of the content.
*
* @throws MWException if $content is not an instance of TextContent and $this->allowNonTextContent is not true.