* @access public
*/
function loadFromPageId( &$db, $pageid, $id = 0 ) {
+ $conds=array('page_id=rev_page','rev_page'=>intval( $pageid ), 'page_id'=>intval( $pageid ));
if( $id ) {
- $matchId = intval( $id );
+ $conds['rev_id']=intval($id);
} else {
- $matchId = 'page_latest';
+ $conds[]='rev_id=page_latest';
}
- $ret = Revision::loadFromConds(
- $db,
- array( "rev_id=$matchId",
- 'rev_page' => intval( $pageid ),
- 'page_id=rev_page' ) );
- return $ret;
+ return Revision::loadFromConds( $db, $conds );
}
/**
*/
function getPrevious() {
$prev = $this->mTitle->getPreviousRevisionID( $this->mId );
- return Revision::newFromTitle( $this->mTitle, $prev );
+ if ( $prev ) {
+ return Revision::newFromTitle( $this->mTitle, $prev );
+ } else {
+ return null;
+ }
}
/**
*/
function getNext() {
$next = $this->mTitle->getNextRevisionID( $this->mId );
- return Revision::newFromTitle( $this->mTitle, $next );
+ if ( $next ) {
+ return Revision::newFromTitle( $this->mTitle, $next );
+ } else {
+ return null;
+ }
}
/**#@-*/
$text=ExternalStore::fetchFromURL($url);
}
- if( in_array( 'gzip', $flags ) ) {
- # Deal with optional compression of archived pages.
- # This can be done periodically via maintenance/compressOld.php, and
- # as pages are saved if $wgCompressRevisions is set.
- $text = gzinflate( $text );
- }
-
- if( in_array( 'object', $flags ) ) {
- # Generic compressed storage
- $obj = unserialize( $text );
-
- # Bugger, corrupted my test database by double-serializing
- if ( !is_object( $obj ) ) {
- $obj = unserialize( $obj );
+ // If the text was fetched without an error, convert it
+ if ( $text !== false ) {
+ if( in_array( 'gzip', $flags ) ) {
+ # Deal with optional compression of archived pages.
+ # This can be done periodically via maintenance/compressOld.php, and
+ # as pages are saved if $wgCompressRevisions is set.
+ $text = gzinflate( $text );
}
- $text = $obj->getText();
- }
+ if( in_array( 'object', $flags ) ) {
+ # Generic compressed storage
+ $obj = unserialize( $text );
+ $text = $obj->getText();
+ }
- global $wgLegacyEncoding;
- if( $wgLegacyEncoding && !in_array( 'utf-8', $flags ) ) {
- # Old revisions kept around in a legacy encoding?
- # Upconvert on demand.
- global $wgInputEncoding, $wgContLang;
- $text = $wgContLang->iconv( $wgLegacyEncoding, $wgInputEncoding, $text );
+ global $wgLegacyEncoding;
+ if( $wgLegacyEncoding && !in_array( 'utf-8', $flags ) ) {
+ # Old revisions kept around in a legacy encoding?
+ # Upconvert on demand.
+ global $wgInputEncoding, $wgContLang;
+ $text = $wgContLang->iconv( $wgLegacyEncoding, $wgInputEncoding . '//IGNORE', $text );
+ }
}
wfProfileOut( $fname );
return $text;
* @return int
*/
function insertOn( &$dbw ) {
+ global $wgDefaultExternalStore;
+
$fname = 'Revision::insertOn';
wfProfileIn( $fname );
- $mungedText = $this->mText;
- $flags = Revision::compressRevisionText( $mungedText );
+ $data = $this->mText;
+ $flags = Revision::compressRevisionText( $data );
+
+ # Write to external storage if required
+ if ( $wgDefaultExternalStore ) {
+ require_once('ExternalStore.php');
+ // Store and get the URL
+ $data = ExternalStore::insert( $wgDefaultExternalStore, $data );
+ if ( !$data ) {
+ # This should only happen in the case of a configuration error, where the external store is not valid
+ wfDebugDieBacktrace( "Unable to store text to external storage $wgDefaultExternalStore" );
+ }
+ if ( $flags ) {
+ $flags .= ',';
+ }
+ $flags .= 'external';
+ }
- # Record the text to the text table
+ # Record the text (or external storage URL) to the text table
if( !isset( $this->mTextId ) ) {
$old_id = $dbw->nextSequenceValue( 'text_old_id_val' );
$dbw->insert( 'text',
array(
'old_id' => $old_id,
- 'old_text' => $mungedText,
+ 'old_text' => $data,
'old_flags' => $flags,
), $fname
);