2012-10-16 18:20:43 +00:00
|
|
|
<?php
|
2012-11-18 14:34:00 +00:00
|
|
|
/**
|
2012-12-20 19:44:47 +00:00
|
|
|
* Base content handler class for flat text contents.
|
|
|
|
|
*
|
2012-11-18 14:34:00 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2012-12-20 19:44:47 +00:00
|
|
|
* @since 1.21
|
|
|
|
|
*
|
2012-11-18 14:34:00 +00:00
|
|
|
* @file
|
2012-12-20 19:44:47 +00:00
|
|
|
* @ingroup Content
|
2012-11-18 14:34:00 +00:00
|
|
|
*/
|
2012-10-16 18:20:43 +00:00
|
|
|
|
|
|
|
|
/**
|
2012-12-20 19:44:47 +00:00
|
|
|
* Base content handler implementation for flat text contents.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Content
|
2012-10-16 18:20:43 +00:00
|
|
|
*/
|
|
|
|
|
class TextContentHandler extends ContentHandler {
|
2014-03-03 17:08:05 +00:00
|
|
|
|
2013-12-03 13:31:04 +00:00
|
|
|
// @codingStandardsIgnoreStart bug 57585
|
2013-11-20 04:49:59 +00:00
|
|
|
public function __construct( $modelId = CONTENT_MODEL_TEXT,
|
2014-03-03 17:08:05 +00:00
|
|
|
$formats = array( CONTENT_FORMAT_TEXT ) ) {
|
2012-10-16 18:20:43 +00:00
|
|
|
parent::__construct( $modelId, $formats );
|
|
|
|
|
}
|
2013-12-03 13:31:04 +00:00
|
|
|
// @codingStandardsIgnoreEnd
|
2012-10-16 18:20:43 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the content's text as-is.
|
|
|
|
|
*
|
2014-03-03 17:08:05 +00:00
|
|
|
* @param Content $content
|
|
|
|
|
* @param string $format The serialization format to check
|
|
|
|
|
*
|
2012-10-16 18:20:43 +00:00
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function serializeContent( Content $content, $format = null ) {
|
|
|
|
|
$this->checkFormat( $format );
|
2013-11-19 21:26:16 +00:00
|
|
|
|
2012-10-16 18:20:43 +00:00
|
|
|
return $content->getNativeData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Attempts to merge differences between three versions. Returns a new
|
|
|
|
|
* Content object for a clean merge and false for failure or a conflict.
|
|
|
|
|
*
|
|
|
|
|
* All three Content objects passed as parameters must have the same
|
|
|
|
|
* content model.
|
|
|
|
|
*
|
|
|
|
|
* This text-based implementation uses wfMerge().
|
|
|
|
|
*
|
2014-03-03 17:08:05 +00:00
|
|
|
* @param Content|string $oldContent The page's previous content.
|
|
|
|
|
* @param Content|string $myContent One of the page's conflicting contents.
|
|
|
|
|
* @param Content|string $yourContent One of the page's conflicting contents.
|
2012-10-16 18:20:43 +00:00
|
|
|
*
|
2014-03-03 17:08:05 +00:00
|
|
|
* @return Content|bool
|
2012-10-16 18:20:43 +00:00
|
|
|
*/
|
|
|
|
|
public function merge3( Content $oldContent, Content $myContent, Content $yourContent ) {
|
|
|
|
|
$this->checkModelID( $oldContent->getModel() );
|
|
|
|
|
$this->checkModelID( $myContent->getModel() );
|
|
|
|
|
$this->checkModelID( $yourContent->getModel() );
|
|
|
|
|
|
|
|
|
|
$format = $this->getDefaultFormat();
|
|
|
|
|
|
|
|
|
|
$old = $this->serializeContent( $oldContent, $format );
|
|
|
|
|
$mine = $this->serializeContent( $myContent, $format );
|
|
|
|
|
$yours = $this->serializeContent( $yourContent, $format );
|
|
|
|
|
|
|
|
|
|
$ok = wfMerge( $old, $mine, $yours, $result );
|
|
|
|
|
|
|
|
|
|
if ( !$ok ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !$result ) {
|
|
|
|
|
return $this->makeEmptyContent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$mergedContent = $this->unserializeContent( $result, $format );
|
2013-11-19 21:26:16 +00:00
|
|
|
|
2012-10-16 18:20:43 +00:00
|
|
|
return $mergedContent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Unserializes a Content object of the type supported by this ContentHandler.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.21
|
|
|
|
|
*
|
2014-03-03 17:08:05 +00:00
|
|
|
* @param string $text Serialized form of the content
|
|
|
|
|
* @param string $format The format used for serialization
|
2012-10-16 18:20:43 +00:00
|
|
|
*
|
2014-03-03 17:08:05 +00:00
|
|
|
* @return Content The TextContent object wrapping $text
|
2012-10-16 18:20:43 +00:00
|
|
|
*/
|
|
|
|
|
public function unserializeContent( $text, $format = null ) {
|
|
|
|
|
$this->checkFormat( $format );
|
|
|
|
|
|
|
|
|
|
return new TextContent( $text );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates an empty TextContent object.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.21
|
|
|
|
|
*
|
2014-03-03 17:08:05 +00:00
|
|
|
* @return Content A new TextContent object with empty text.
|
2012-10-16 18:20:43 +00:00
|
|
|
*/
|
|
|
|
|
public function makeEmptyContent() {
|
|
|
|
|
return new TextContent( '' );
|
|
|
|
|
}
|
2014-03-03 17:08:05 +00:00
|
|
|
|
2012-10-22 10:29:52 +00:00
|
|
|
}
|