Merge branch 'Wikidata' of ssh://review/mediawiki/core into Wikidata
authorjeroendedauw <jeroendedauw@gmail.com>
Mon, 14 May 2012 10:02:09 +0000 (12:02 +0200)
committerjeroendedauw <jeroendedauw@gmail.com>
Mon, 14 May 2012 10:02:09 +0000 (12:02 +0200)
1  2 
includes/Content.php
includes/WikiPage.php

diff --combined includes/Content.php
@@@ -12,9 -12,9 +12,9 @@@ abstract class Content 
         * Name of the content model this Content object represents.
         * Use with CONTENT_MODEL_XXX constants
         *
-        * @var String $model_name
+        * @var String $model_id
         */
-       protected $modelName;
+       protected $model_id;
  
        /**
         * @since WD.1
        public abstract function getSize( );
  
        /**
-        * @param $model_name
+        * @param int $model_id
         */
-       public function __construct( $modelName = null ) {
-               $this->modelName = $modelName;
+       public function __construct( $model_id = null ) {
+               $this->model_id = $model_id;
        }
  
        /**
-        * Returns the name of the content model used by this content objects.
+        * Returns the id of the content model used by this content objects.
         * Corresponds to the CONTENT_MODEL_XXX constants.
         *
         * @since WD.1
         *
-        * @return String the model name
+        * @return int the model id
         */
-       public function getModelName() {
-               return $this->modelName;
+       public function getModel() {
+               return $this->model_id;
        }
  
        /**
-        * Throws an MWException if $model_name is not the name of the content model
+        * Throws an MWException if $model_id is not the id of the content model
         * supported by this Content object.
         *
-        * @param String $modelName the model to check
+        * @param int $model_id the model to check
         */
-       protected function checkModelName( $modelName ) {
-               if ( $modelName !== $this->modelName ) {
-                       throw new MWException( "Bad content model: expected " . $this->modelName . " but got found " . $modelName );
+       protected function checkModelID( $model_id ) {
+               if ( $model_id !== $this->model_id ) {
+                       $model_name = ContentHandler::getContentModelName( $model_id );
+                       $own_model_name = ContentHandler::getContentModelName( $this->model_id );
+                       throw new MWException( "Bad content model: expected {$this->model_id} ($own_model_name) but got found $model_id ($model_name)." );
                }
        }
  
         */
        protected function checkFormat( $format ) {
                if ( !$this->isSupportedFormat( $format ) ) {
-                       throw new MWException( "Format $format is not supported for content model " . $this->getModelName() );
+                       throw new MWException( "Format $format is not supported for content model " . $this->getModel() );
                }
        }
  
                return $this->getSize() == 0;
        }
  
 +      /**
 +       * Returns if the content is valid.
 +       * It needs to be valid before it can be saved.
 +       *
 +       * @since WD.1
 +       *
 +       * @return boolean
 +       */
 +      public function isValid() {
 +              // TODO
 +              return true;
 +      }
 +
 +      /**
 +       * Diff the content object with what is currently stored in the database.
 +       * If it is not currently stored, it will be diffed with an empty object.
 +       *
 +       * @since WD.diff
 +       *
 +       * @return ContentDiff
 +       */
 +      public function diffToDatabase() {
 +              // TODO
 +      }
 +
        /**
         * Returns true if this Content objects is conceptually equivalent to the given Content object.
         *
         * Will returns false if $that is null.
         * Will return true if $that === $this.
-        * Will return false if $that->getModleName() != $this->getModelName().
+        * Will return false if $that->getModleName() != $this->getModel().
         * Will return false if $that->getNativeData() is not equal to $this->getNativeData(),
         * where the meaning of "equal" depends on the actual data model.
         *
                        return true;
                }
  
-               if ( $that->getModelName() !== $this->getModelName() ) {
+               if ( $that->getModel() !== $this->getModel() ) {
                        return false;
                }
  
         * if $copy = $original->copy()
         *
         * * get_class($original) === get_class($copy)
-        * * $original->getModelName() === $copy->getModelName()
+        * * $original->getModel() === $copy->getModel()
         * * $original->equals( $copy )
         *
         * If and only if the Content object is imutable, the copy() method can and should
   */
  abstract class TextContent extends Content {
  
-       public function __construct( $text, $model_name = null ) {
-               parent::__construct( $model_name );
+       public function __construct( $text, $model_id = null ) {
+               parent::__construct( $model_id );
  
                $this->mText = $text;
        }
@@@ -613,11 -591,15 +616,15 @@@ class WikitextContent extends TextConte
        public function replaceSection( $section, Content $with, $sectionTitle = '' ) {
                wfProfileIn( __METHOD__ );
  
-               $myModelName = $this->getModelName();
-               $sectionModelName = $with->getModelName();
+               $myModelId = $this->getModel();
+               $sectionModelId = $with->getModel();
+               if ( $sectionModelId != $myModelId  ) {
+                       $myModelName = ContentHandler::getContentModelName( $myModelId );
+                       $sectionModelName = ContentHandler::getContentModelName( $sectionModelId );
  
-               if ( $sectionModelName != $myModelName  ) {
-                       throw new MWException( "Incompatible content model for section: document uses $myModelName, section uses $sectionModelName." );
+                       throw new MWException( "Incompatible content model for section: document uses $myModelId ($myModelName), "
+                                                               . "section uses $sectionModelId ($sectionModelName)." );
                }
  
                $oldtext = $this->getNativeData();
diff --combined includes/WikiPage.php
@@@ -161,14 -161,14 +161,14 @@@ class WikiPage extends Page 
        /**
         * Returns the ContentHandler instance to be used to deal with the content of this WikiPage.
         *
-        * Shorthand for ContentHandler::getForModelName( $this->getContentModelName() );
+        * Shorthand for ContentHandler::getForModelID( $this->getContentModel() );
         *
         * @return ContentHandler
         *
         * @since 1.WD
         */
        public function getContentHandler() {
-               return ContentHandler::getForModelName( $this->getContentModelName() );
+               return ContentHandler::getForModelID( $this->getContentModel() );
        }
  
        /**
        }
  
        /**
-        * Returns the page's content model name. Will use the revisions actual content model if the page exists,
+        * Returns the page's content model id (see the CONTENT_MODEL_XXX constants).
+        *
+        * Will use the revisions actual content model if the page exists,
         * and the page's default if the page doesn't exist yet.
         *
         * @return int
         *
         * @since 1.WD
         */
-       public function getContentModelName() {
+       public function getContentModel() {
                if ( $this->exists() ) {
                        # look at the revision's actual content model
                        $rev = $this->getRevision();
  
                        if ( $rev !== null ) {
-                               return $rev->getContentModelName();
+                               return $rev->getContentModel();
                        } else {
                                wfWarn( "Page exists but has no revision!" );
                        }
                }
  
                # use the default model for this page
-               return $this->mTitle->getContentModelName();
+               return $this->mTitle->getContentModel();
        }
  
        /**
                );
  
                if ( $wgContentHandlerUseDB ) {
-                       $row[ 'page_content_model' ] = $revision->getContentModelName();
+                       $row[ 'page_content_model' ] = $revision->getContentModel();
                }
  
                $dbw->update( 'page',
                                'user'       => $user->getId(),
                                'user_text'  => $user->getName(),
                                'timestamp'  => $now,
-                               'content_model' => $content->getModelName(),
+                               'content_model' => $content->getModel(),
                                'content_format' => $serialisation_format,
                        ) );
  
                        $changed = !$content->equals( $old_content );
  
                        if ( $changed ) {
 +                              // TODO: validate!
 +                              if ( $content->isValid() ) {
 +
 +                              }
 +
                                $dbw->begin( __METHOD__ );
                                $revisionId = $revision->insertOn( $dbw );
  
                                return $status;
                        }
  
 +                      // TODO: create content diff to pass to update objects that might need it
 +
                        # Update links tables, site stats, etc.
 -                      $this->doEditUpdates( $revision, $user, array( 'changed' => $changed,
 -                              'oldcountable' => $oldcountable ) );
 +                      $this->doEditUpdates(
 +                              $revision,
 +                              $user,
 +                              array(
 +                                      'changed' => $changed,
 +                                      'oldcountable' => $oldcountable
 +                              )
 +                      );
  
                        if ( !$changed ) {
                                $status->warning( 'edit-no-change' );
                                'user'       => $user->getId(),
                                'user_text'  => $user->getName(),
                                'timestamp'  => $now,
-                               'content_model' => $content->getModelName(),
+                               'content_model' => $content->getModel(),
                                'content_format' => $serialisation_format,
                        ) );
                        $revisionId = $revision->insertOn( $dbw );
  
                wfDeprecated( __METHOD__, '1.WD' );
  
-               $handler = ContentHandler::getForModelName( CONTENT_MODEL_WIKITEXT );
+               $handler = ContentHandler::getForModelID( CONTENT_MODEL_WIKITEXT );
                $oldContent = is_null( $oldtext ) ? null : $handler->unserializeContent( $oldtext );
                $newContent = is_null( $newtext ) ? null : $handler->unserializeContent( $newtext );
  
@@@ -3077,9 -3066,9 +3079,9 @@@ class PoolWorkArticleView extends PoolC
         */
        function __construct( Page $page, ParserOptions $parserOptions, $revid, $useParserCache, $content = null, IContextSource $context = null ) {
                if ( is_string($content) ) { #BC: old style call
-                       $modelName = $page->getRevision()->getContentModelName();
+                       $modelId = $page->getRevision()->getContentModel();
                        $format = $page->getRevision()->getContentFormat();
-                       $content = ContentHandler::makeContent( $content, $page->getTitle(), $modelName, $format );
+                       $content = ContentHandler::makeContent( $content, $page->getTitle(), $modelId, $format );
                }
  
                if ( is_null( $context ) ) {