$outputDone = true;
} else {
$content = $this->getContentObject();
- $rt = $content->getRedirectChain();
+ $rt = $content ? $content->getRedirectChain() : null;
if ( $rt ) {
wfDebug( __METHOD__ . ": showing redirect=no page\n" );
# Viewing a redirect page (e.g. with parameter redirect=no)
'clearyourcache' );
}
- // Give hooks a chance to customise the output
- if ( ContentHandler::runLegacyHooks( 'ShowRawCssJs', array( $this->fetchContentObject(), $this->getTitle(), $outputPage ) ) ) {
- $po = $this->mContentObject->getParserOutput( $this->getTitle() );
- $outputPage->addHTML( $po->getText() );
+ $this->fetchContentObject();
+
+ if ( $this->mContentObject ) {
+ // Give hooks a chance to customise the output
+ if ( ContentHandler::runLegacyHooks( 'ShowRawCssJs', array( $this->mContentObject, $this->getTitle(), $outputPage ) ) ) {
+ $po = $this->mContentObject->getParserOutput( $this->getTitle() );
+ $outputPage->addHTML( $po->getText() );
+ }
}
}
$this->mText = $this->loadText();
}
- $this->mContent = is_null( $this->mText ) ? null : $handler->unserializeContent( $this->mText, $format );
+ $this->mContent = ( $this->mText === null || $this->mText === false ) ? null
+ : $handler->unserializeContent( $this->mText, $format );
}
return $this->mContent->copy(); // NOTE: copy() will return $this for immutable content objects
$content = $this->getContent( Revision::RAW );
- if ( !$content->isValid() ) {
+ if ( !$content || !$content->isValid() ) {
$t = $title->getPrefixedDBkey();
throw new MWException( "Content of $t is not valid! Content model is $model" );
* Lazy-load the revision's text.
* Currently hardcoded to the 'text' table storage engine.
*
- * @return String
+ * @return String|boolean the revision text, or false on failure
*/
protected function loadText() {
wfProfileIn( __METHOD__ );
$content = $rev->getContent();
# Does the redirect point to the source?
# Or is it a broken self-redirect, usually caused by namespace collisions?
- $redirTitle = $content->getRedirectTarget();
+ $redirTitle = $content ? $content->getRedirectTarget() : null;
if ( $redirTitle ) {
if ( $redirTitle->getPrefixedDBkey() != $this->getPrefixedDBkey() &&
wfProfileIn( __METHOD__ );
$content = $revision->getContent();
- $len = $content->getSize();
- $rt = $content->getUltimateRedirectTarget();
+ $len = $content ? $content->getSize() : 0;
+ $rt = $content ? $content->getUltimateRedirectTarget() : null;
$conditions = array( 'page_id' => $this->getId() );
// Bug 30711: always use current version when adding a new section
if ( is_null( $edittime ) || $section == 'new' ) {
$oldContent = $this->getContent();
- if ( ! $oldContent ) {
- wfDebug( __METHOD__ . ": no page text\n" );
- wfProfileOut( __METHOD__ );
- return null;
- }
} else {
$dbw = wfGetDB( DB_MASTER );
$rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime );
$oldContent = $rev->getContent();
}
+ if ( ! $oldContent ) {
+ wfDebug( __METHOD__ . ": no page text\n" );
+ wfProfileOut( __METHOD__ );
+ return null;
+ }
+
+ //FIXME: $oldContent might be null?
$newContent = $oldContent->replaceSection( $section, $sectionContent, $sectionTitle );
}
# Bug 37225: use accessor to get the text as Revision may trim it
$content = $revision->getContent(); // sanity; get normalized version
+ if ( $content ) {
+ $newsize = $content->getSize();
+ }
+
# Update the page record with revision data
$this->updateRevisionOn( $dbw, $revision, 0 );
$this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) );
# Add RC row to the DB
$rc = RecentChange::notifyNew( $now, $this->mTitle, $isminor, $user, $summary, $bot,
- '', $content->getSize(), $revisionId, $patrolled );
+ '', $newsize, $revisionId, $patrolled );
# Log auto-patrolled edits
if ( $patrolled ) {
* @since 1.21
*/
public function prepareContentForEdit( Content $content, $revid = null, User $user = null, $serialization_format = null ) {
- global $wgParser, $wgContLang, $wgUser;
+ global $wgContLang, $wgUser;
$user = is_null( $user ) ? $wgUser : $user;
//XXX: check $user->getId() here???
$edit = (object)array();
$edit->revid = $revid;
- $edit->pstContent = $content->preSaveTransform( $this->mTitle, $user, $popts );
- $edit->pst = $edit->pstContent->serialize( $serialization_format ); #XXX: do we need this??
- $edit->format = $serialization_format;
+ $edit->pstContent = $content ? $content->preSaveTransform( $this->mTitle, $user, $popts ) : null;
+ $edit->format = $serialization_format;
$edit->popts = $this->makeParserOptions( 'canonical' );
-
- $edit->output = $edit->pstContent->getParserOutput( $this->mTitle, $revid, $edit->popts );
+ $edit->output = $edit->pstContent ? $edit->pstContent->getParserOutput( $this->mTitle, $revid, $edit->popts ) : null;
$edit->newContent = $content;
$edit->oldContent = $this->getContent( Revision::RAW );
#NOTE: B/C for hooks! don't use these fields!
- $edit->newText = ContentHandler::getContentText( $edit->newContent );
+ $edit->newText = $edit->newContent ? ContentHandler::getContentText( $edit->newContent ) : '';
$edit->oldText = $edit->oldContent ? ContentHandler::getContentText( $edit->oldContent ) : '';
+ $edit->pst = $edit->pstContent ? $edit->pstContent->serialize( $serialization_format ) : '';
$this->mPreparedEdit = $edit;
-
return $edit;
}
}
# Update the links tables and other secondary data
- $updates = $content->getSecondaryDataUpdates( $this->getTitle(), null, true, $editInfo->output );
- DataUpdate::runUpdates( $updates );
+ if ( $content ) {
+ $updates = $content->getSecondaryDataUpdates( $this->getTitle(), null, true, $editInfo->output );
+ DataUpdate::runUpdates( $updates );
+ }
wfRunHooks( 'ArticleEditUpdates', array( &$this, &$editInfo, $options['changed'] ) );
if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
#XXX: could skip pseudo-messages like js/css here, based on content model.
- $msgtext = $content->getWikitextForTransclusion();
+ $msgtext = $content ? $content->getWikitextForTransclusion() : null;
if ( $msgtext === false || $msgtext === null ) $msgtext = '';
MessageCache::singleton()->replace( $shortTitle, $msgtext );
if ( ContentHandler::runLegacyHooks( 'ShowRawCssJs', array( $this->mNewContent, $this->mNewPage, $out ) ) ) {
// NOTE: deprecated hook, B/C only
// use the content object's own rendering
- $po = $this->mNewRev->getContent()->getParserOutput( $this->mNewRev->getTitle(), $this->mNewRev->getId() );
- $out->addHTML( $po->getText() );
+ $cnt = $this->mNewRev->getContent();
+ $po = $cnt ? $cnt->getParserOutput( $this->mNewRev->getTitle(), $this->mNewRev->getId() ) : null;
+ $txt = $po ? $po->getText() : '';
+ $out->addHTML( $txt );
}
} elseif( !wfRunHooks( 'ArticleContentViewCustom', array( $this->mNewContent, $this->mNewPage, $out ) ) ) {
// Handled by extension
$parserOutput = $this->getParserOutput( $wikiPage, $this->mNewRev );
# Also try to load it as a redirect
- $rt = $this->mNewContent->getRedirectTarget();
+ $rt = $this->mNewContent ? $this->mNewContent->getRedirectTarget() : null;
if ( $rt ) {
$article = Article::newFromTitle( $this->mNewPage, $this->getContext() );
}
if ( $this->mOldRev ) {
$this->mOldContent = $this->mOldRev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
- if ( $this->mOldContent === false ) {
+ if ( $this->mOldContent === null ) {
return false;
}
}
if ( $this->mNewRev ) {
$this->mNewContent = $this->mNewRev->getContent( Revision::FOR_THIS_USER, $this->getUser() );
- if ( $this->mNewContent === false ) {
+ if ( $this->mNewContent === null ) {
return false;
}
}
return true;
}
$content = $targetRev->getContent();
- $currentDest = $content->getRedirectTarget();
+ $currentDest = $content ? $content->getRedirectTarget() : null;
if ( !$currentDest || !$currentDest->equals( $this->redirTitle ) ) {
wfDebug( __METHOD__.": Redirect has changed since the job was queued\n" );
return true;
}
public static function runForTitleInternal( Title $title, Revision $revision, $fname ) {
- global $wgContLang;
+ wfProfileIn( $fname );
+ $content = $revision->getContent( Revision::RAW );
- wfProfileIn( $fname . '-parse' );
- $options = ParserOptions::newFromUserAndLang( new User, $wgContLang );
- $content = $revision->getContent();
- $parserOutput = $content->getParserOutput( $title, $revision->getId(), $options, false );
- wfProfileOut( $fname . '-parse' );
+ if ( !$content ) {
+ // if there is no content, pretend the content is empty
+ $content = $revision->getContentHandler()->makeEmptyContent();
+ }
- wfProfileIn( $fname . '-update' );
- $updates = $content->getSecondaryDataUpdates( $title, null, false, $parserOutput );
+ $updates = $content->getSecondaryDataUpdates( $title, null, false );
DataUpdate::runUpdates( $updates );
- wfProfileOut( $fname . '-update' );
+ wfProfileOut( $fname );
}
}
if ( $rev ) {
$content = $rev->getContent();
- $text = $content->getWikitextForTransclusion();
+ $text = $content ? $content->getWikitextForTransclusion() : null;
if ( $text === false || $text === null ) {
$text = false;
}
$content = $revision->getContent( Revision::RAW );
+
+ if ( !$content ) {
+ wfDebug( __METHOD__ . "failed to load content of JS/CSS page!\n" );
+ return null;
+ }
+
$model = $content->getModel();
if ( $model !== CONTENT_MODEL_CSS && $model !== CONTENT_MODEL_JAVASCRIPT ) {
- wfDebug( __METHOD__ . "bad content model #$model for JS/CSS page!\n" );
+ wfDebug( __METHOD__ . "bad content model $model for JS/CSS page!\n" );
return null;
}
//TODO: if we could plug in some code that knows about special content models *and* about
// special features of the search engine, the search could benefit.
$content = $this->mRevision->getContent();
- $this->mText = $content->getTextForSearchIndex();
+ $this->mText = $content ? $content->getTextForSearchIndex() : '';
} else { // TODO: can we fetch raw wikitext for commons images?
$this->mText = '';
}