/**
* 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
$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;
}
/**
- * Tests if the article text represents a redirect
+ * Tests if the article content represents a redirect
*
- * @param $text mixed string containing article contents, or boolean
* @return bool
*/
- public function isRedirect( $text = false ) { #TODO: investiage whether we need the text param
- if ( $text === false ) $content = $this->getContent();
- else $content = ContentHandler::makeContent( $text, $this->mTitle ); # TODO: allow model and format to be provided; or better, expect a Content object
-
+ public function isRedirect( ) {
+ $content = $this->getContent();
+ if ( !$content ) return false;
- if ( empty( $content ) ) return false;
- else return $content->isRedirect();
+ return $content->isRedirect();
}
/**
}
wfProfileOut( __METHOD__ );
- if ( $row ) {
- return Revision::newFromRow( $row );
- } else {
- return null;
- }
+ return $row ? Revision::newFromRow( $row ) : null;
}
/**
* @return String|bool The text of the current revision. False on failure
* @deprecated as of 1.WD, getContent() should be used instead.
*/
- public function getRawText() { #@todo: deprecated, replace usage!
+ public function getRawText() {
wfDeprecated( __METHOD__, '1.WD' );
return $this->getText( Revision::RAW );
}
if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
+ //@todo: move this logic to MessageCache
+
if ( $this->mTitle->exists() ) {
- $text = ContentHandler::getContentText( $this->getContent() ); #XXX: get native data directly?
+ // NOTE: use transclusion text for messages.
+ // This is consistent with MessageCache::getMsgFromNamespace()
+
+ $content = $this->getContent();
+ $text = $content === null ? null : $content->getWikitextForTransclusion();
+
+ if ( $text === null ) $text = false;
} else {
$text = false;
}
$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__ );
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.
$newContent = $this->replaceSectionContent( $section, $sectionContent, $sectionTitle, $edittime );
- #TODO: check $newContent == false. throw exception??
- #TODO: add ContentHandler::supportsSections()
- return ContentHandler::getContentText( $newContent ); #XXX: unclear what will happen for non-wikitext!
+ return ContentHandler::getContentText( $newContent );
+ }
+
+ /**
+ * Returns true iff this page's content model supports sections.
+ *
+ * @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();
}
/**
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;
$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
$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__ );
$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;
}
# Update the links tables and other secondary data
- $updates = $editInfo->output->getSecondaryDataUpdates( $this->getTitle() ); #FIXME: call ContentHandler::getSecondaryLinkUpdates. Don't parse iuf not needed! But don't parse too early either, only after saving, so we have an article ID!
+ $contentHandler = $revision->getContentHandler();
+ $updates = $contentHandler->getSecondaryDataUpdates( $content, $this->getTitle(), null, true, $editInfo->output );
DataUpdate::runUpdates( $updates );
wfRunHooks( 'ArticleEditUpdates', array( &$this, &$editInfo, $options['changed'] ) );
}
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 );
'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 );
* @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 ) {
* @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 );
}
/**
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 );
}
/**
wfRunHooks( 'WikiPageDeletionUpdates', array( $this, &$updates ) );
return $updates;
}
+
}
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 );