merged master
[lhc/web/wiklou.git] / includes / WikiPage.php
index 64cc51a..e5edd2e 100644 (file)
@@ -257,11 +257,20 @@ class WikiPage extends Page {
 
        /**
         * Clear the object
+        * @return void
         */
        public function clear() {
                $this->mDataLoaded = false;
                $this->mDataLoadedFrom = self::DATA_NOT_LOADED;
 
+               $this->clearCacheFields();
+       }
+
+       /**
+        * Clear the object cache fields
+        * @return void
+        */
+       protected function clearCacheFields() {
                $this->mCounter = null;
                $this->mRedirectTarget = null; # Title object if set
                $this->mLastRevision = null; # Latest revision
@@ -418,10 +427,18 @@ class WikiPage extends Page {
                        $this->mTouched     = wfTimestamp( TS_MW, $data->page_touched );
                        $this->mIsRedirect  = intval( $data->page_is_redirect );
                        $this->mLatest      = intval( $data->page_latest );
+                       // Bug 37225: $latest may no longer match the cached latest Revision object.
+                       // Double-check the ID of any cached latest Revision object for consistency.
+                       if ( $this->mLastRevision && $this->mLastRevision->getId() != $this->mLatest ) {
+                               $this->mLastRevision = null;
+                               $this->mTimestamp = '';
+                       }
                } else {
                        $lc->addBadLinkObj( $this->mTitle );
 
                        $this->mTitle->loadFromRow( false );
+
+                       $this->clearCacheFields();
                }
 
                $this->mDataLoaded = true;
@@ -1279,7 +1296,7 @@ class WikiPage extends Page {
                        $this->mLatest = $revision->getId();
                        $this->mIsRedirect = (bool)$rt;
                        # Update the LinkCache.
-                       LinkCache::singleton()->addGoodLinkObj( $this->getId(), $this->mTitle, $len, $this->mIsRedirect, $this->mLatest );
+                       LinkCache::singleton()->addGoodLinkObj( $this->getId(), $this->mTitle, $len, $this->mIsRedirect, $this->mLatest, $revision->getContentModel() );
                }
 
                wfProfileOut( __METHOD__ );
@@ -1406,13 +1423,15 @@ class WikiPage extends Page {
        public function replaceSection( $section, $text, $sectionTitle = '', $edittime = null ) {
                wfDeprecated( __METHOD__, '1.WD' );
 
-               $sectionContent = ContentHandler::makeContent( $text, $this->getTitle() ); #XXX: could make section title, but that's not required.
+               if ( !$this->supportsSections() ) {
+                       return null;
+               }
+
+               $sectionContent = ContentHandler::makeContent( $text, $this->getTitle() ); # could even make section title, but that's not required.
 
-               #TODO: check ContentHandler::supportsSections(). throw exception??
                $newContent = $this->replaceSectionContent( $section, $sectionContent, $sectionTitle, $edittime );
-               #TODO: check $newContent == false. throw exception??
 
-               return ContentHandler::getContentText( $newContent ); #XXX: unclear what will happen for non-wikitext!
+               return ContentHandler::getContentText( $newContent );
        }
 
        /**
@@ -1421,6 +1440,7 @@ class WikiPage extends Page {
         * @return boolean whether sections are supported.
         *
         * @todo: the skin should check this and not offer section functionality if sections are not supported.
+        * @todo: the EditPage should check this and not offer section functionality if sections are not supported.
         */
        public function supportsSections() {
                return $this->getContentHandler()->supportsSections();
@@ -1439,6 +1459,11 @@ class WikiPage extends Page {
        public function replaceSectionContent( $section, Content $sectionContent, $sectionTitle = '', $edittime = null ) {
                wfProfileIn( __METHOD__ );
 
+               if ( !$this->supportsSections() ) {
+                       #XXX: log this?
+                       return null;
+               }
+
                if ( strval( $section ) == '' ) {
                        // Whole-page edit; let the whole text through
                        $newContent = $sectionContent;
@@ -1617,7 +1642,7 @@ class WikiPage extends Page {
                $hook_ok = wfRunHooks( 'ArticleContentSave', array( &$this, &$user, &$content, &$summary,
                        $flags & EDIT_MINOR, null, null, &$flags, &$status ) );
 
-               if ( $hook_ok && !empty( $wgHooks['ArticleSave'] ) ) { #FIXME: use wfHasHook or whatever. # avoid serialization overhead if the hook isn't present
+               if ( $hook_ok && Hooks::isRegistered( 'ArticleSave' ) ) { # avoid serialization overhead if the hook isn't present
                        $content_text = $content->serialize();
                        $txt = $content_text; # clone
 
@@ -1704,9 +1729,8 @@ class WikiPage extends Page {
                        $changed = !$content->equals( $old_content );
 
                        if ( $changed ) {
-                               // TODO: validate!
-                               if ( $content->isValid() ) {
-                                       #XXX: do it! throw exception??
+                               if ( !$content->isValid() ) {
+                                       throw new MWException( "New content failed validity check!" );
                                }
 
                                $dbw->begin( __METHOD__ );
@@ -1950,8 +1974,9 @@ class WikiPage extends Page {
                $edit->newContent = $content;
                $edit->oldContent = $this->getContent( Revision::RAW );
 
-               $edit->newText = ContentHandler::getContentText( $edit->newContent ); #FIXME: B/C only! don't use this field!
-               $edit->oldText = $edit->oldContent ? ContentHandler::getContentText( $edit->oldContent ) : ''; #FIXME: B/C only! don't use this field!
+               #NOTE: B/C for hooks! don't use these fields!
+               $edit->newText = ContentHandler::getContentText( $edit->newContent );
+               $edit->oldText = $edit->oldContent ? ContentHandler::getContentText( $edit->oldContent ) : '';
 
                $this->mPreparedEdit = $edit;
 
@@ -2071,7 +2096,7 @@ class WikiPage extends Page {
                }
 
                if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
-                       $msgtext = ContentHandler::getContentText( $content ); #XXX: could skip pseudo-messages like js/css here, based on content model.
+                       $msgtext = $content->getWikitextForTransclusion(); #XXX: could skip pseudo-messages like js/css here, based on content model.
                        if ( $msgtext === false || $msgtext === null ) $msgtext = '';
 
                        MessageCache::singleton()->replace( $shortTitle, $msgtext );
@@ -2128,7 +2153,7 @@ class WikiPage extends Page {
                        'length'     => $content->getSize(),
                        'comment'    => $comment,
                        'minor_edit' => $minor ? 1 : 0,
-               ) ); #XXX: set the content object
+               ) ); #XXX: set the content object?
                $revision->insertOn( $dbw );
                $this->updateRevisionOn( $dbw, $revision );
 
@@ -2861,6 +2886,7 @@ class WikiPage extends Page {
        * @param $newtext String|null: The submitted text of the page.
        * @param $flags Int bitmask: a bitmask of flags submitted for the edit.
        * @return string An appropriate autosummary, or an empty string.
+       *
        * @deprecated since 1.WD, use ContentHandler::getAutosummary() instead
        */
        public static function getAutosummary( $oldtext, $newtext, $flags ) {
@@ -2881,15 +2907,9 @@ class WikiPage extends Page {
         * @param &$hasHistory Boolean: whether the page has a history
         * @return mixed String containing deletion reason or empty string, or boolean false
         *    if no revision occurred
-        * @deprecated since 1.WD, use ContentHandler::getAutoDeleteReason() instead
         */
        public function getAutoDeleteReason( &$hasHistory ) {
-               #NOTE: stub for backwards-compatibility.
-
-               wfDeprecated( __METHOD__, '1.WD' );
-
-               $handler = ContentHandler::getForTitle( $this->getTitle() );
-               return $handler->getAutoDeleteReason( $this->getTitle(), $hasHistory );
+               return $this->getContentHandler()->getAutoDeleteReason( $this->getTitle(), $hasHistory );
        }
 
        /**
@@ -3109,7 +3129,7 @@ class WikiPage extends Page {
        public function quickEdit( $text, $comment = '', $minor = 0 ) {
                wfDeprecated( __METHOD__, '1.18' );
                global $wgUser;
-               return $this->doQuickEdit( $text, $wgUser, $comment, $minor );
+               $this->doQuickEdit( $text, $wgUser, $comment, $minor );
        }
 
        /**
@@ -3270,7 +3290,6 @@ class PoolWorkArticleView extends PoolCounterWork {
                }
 
                $time = - microtime( true );
-               // TODO: page might not have this method? Hard to tell what page is supposed to be here...
                $this->parserOutput = $content->getParserOutput( $this->page->getTitle(), $this->revid, $this->parserOptions );
                $time += microtime( true );