MediaWiki  REL1_24
TextContentHandler.php
Go to the documentation of this file.
00001 <?php
00031 class TextContentHandler extends ContentHandler {
00032 
00033     // @codingStandardsIgnoreStart bug 57585
00034     public function __construct( $modelId = CONTENT_MODEL_TEXT,
00035         $formats = array( CONTENT_FORMAT_TEXT ) ) {
00036         parent::__construct( $modelId, $formats );
00037     }
00038     // @codingStandardsIgnoreEnd
00039 
00048     public function serializeContent( Content $content, $format = null ) {
00049         $this->checkFormat( $format );
00050 
00051         return $content->getNativeData();
00052     }
00053 
00069     public function merge3( Content $oldContent, Content $myContent, Content $yourContent ) {
00070         $this->checkModelID( $oldContent->getModel() );
00071         $this->checkModelID( $myContent->getModel() );
00072         $this->checkModelID( $yourContent->getModel() );
00073 
00074         $format = $this->getDefaultFormat();
00075 
00076         $old = $this->serializeContent( $oldContent, $format );
00077         $mine = $this->serializeContent( $myContent, $format );
00078         $yours = $this->serializeContent( $yourContent, $format );
00079 
00080         $ok = wfMerge( $old, $mine, $yours, $result );
00081 
00082         if ( !$ok ) {
00083             return false;
00084         }
00085 
00086         if ( !$result ) {
00087             return $this->makeEmptyContent();
00088         }
00089 
00090         $mergedContent = $this->unserializeContent( $result, $format );
00091 
00092         return $mergedContent;
00093     }
00094 
00104     protected function getContentClass() {
00105         return 'TextContent';
00106     }
00107 
00118     public function unserializeContent( $text, $format = null ) {
00119         $this->checkFormat( $format );
00120 
00121         $class = $this->getContentClass();
00122         return new $class( $text );
00123     }
00124 
00132     public function makeEmptyContent() {
00133         $class = $this->getContentClass();
00134         return new $class( '' );
00135     }
00136 
00137 }