* @todo document
*/
-/** */
-require_once( 'Database.php' );
-
/**
* @package MediaWiki
* @todo document
* Returns null if no such revision can be found.
*
* @param int $id
- * @static
* @access public
+ * @static
*/
- function newFromId( $id ) {
+ public static function newFromId( $id ) {
return Revision::newFromConds(
array( 'page_id=rev_page',
'rev_id' => intval( $id ) ) );
* @access public
* @static
*/
- function newFromTitle( &$title, $id = 0 ) {
+ public static function newFromTitle( &$title, $id = 0 ) {
if( $id ) {
$matchId = intval( $id );
} else {
'page_title' => $title->getDbkey() ) );
}
+ /**
+ * Load a page revision from a given revision ID number.
+ * Returns null if no such revision can be found.
+ *
+ * @param Database $db
+ * @param int $id
+ * @access public
+ * @static
+ */
+ public static function loadFromId( &$db, $id ) {
+ return Revision::loadFromConds( $db,
+ array( 'page_id=rev_page',
+ 'rev_id' => intval( $id ) ) );
+ }
+
/**
* Load either the current, or a specified, revision
* that's attached to a given page. If not attached
* @param int $id
* @return Revision
* @access public
+ * @static
*/
- function loadFromPageId( &$db, $pageid, $id = 0 ) {
+ public static function loadFromPageId( &$db, $pageid, $id = 0 ) {
$conds=array('page_id=rev_page','rev_page'=>intval( $pageid ), 'page_id'=>intval( $pageid ));
if( $id ) {
$conds['rev_id']=intval($id);
* @param int $id
* @return Revision
* @access public
+ * @static
*/
- function loadFromTitle( &$db, $title, $id = 0 ) {
+ public static function loadFromTitle( &$db, $title, $id = 0 ) {
if( $id ) {
$matchId = intval( $id );
} else {
* @access public
* @static
*/
- function loadFromTimestamp( &$db, &$title, $timestamp ) {
+ public static function loadFromTimestamp( &$db, &$title, $timestamp ) {
return Revision::loadFromConds(
$db,
array( 'rev_timestamp' => $db->timestamp( $timestamp ),
*
* @param array $conditions
* @return Revision
- * @static
* @access private
+ * @static
*/
- function newFromConds( $conditions ) {
+ private static function newFromConds( $conditions ) {
$db =& wfGetDB( DB_SLAVE );
$row = Revision::loadFromConds( $db, $conditions );
if( is_null( $row ) ) {
* @param Database $db
* @param array $conditions
* @return Revision
- * @static
* @access private
+ * @static
*/
- function loadFromConds( &$db, $conditions ) {
+ private static function loadFromConds( &$db, $conditions ) {
$res = Revision::fetchFromConds( $db, $conditions );
if( $res ) {
$row = $res->fetchObject();
*
* @param Title $title
* @return ResultWrapper
- * @static
* @access public
+ * @static
*/
- function fetchAllRevisions( &$title ) {
+ public static function fetchAllRevisions( &$title ) {
return Revision::fetchFromConds(
wfGetDB( DB_SLAVE ),
array( 'page_namespace' => $title->getNamespace(),
*
* @param Title $title
* @return ResultWrapper
- * @static
* @access public
+ * @static
*/
- function fetchRevision( &$title ) {
+ public static function fetchRevision( &$title ) {
return Revision::fetchFromConds(
wfGetDB( DB_SLAVE ),
array( 'rev_id=page_latest',
* @param Database $db
* @param array $conditions
* @return ResultWrapper
- * @static
* @access private
+ * @static
*/
- function fetchFromConds( &$db, $conditions ) {
+ private static function fetchFromConds( &$db, $conditions ) {
$res = $db->select(
array( 'page', 'revision' ),
array( 'page_namespace',
$this->mTitle = null;
}
+ // Lazy extraction...
+ $this->mText = null;
if( isset( $row->old_text ) ) {
- $this->mText = $this->getRevisionText( $row );
+ $this->mTextRow = $row;
} else {
- $this->mText = null;
+ // 'text' table row entry will be lazy-loaded
+ $this->mTextRow = null;
}
} elseif( is_array( $row ) ) {
// Build a new revision to be saved...
// Enforce spacing trimming on supplied text
$this->mComment = isset( $row['comment'] ) ? trim( strval( $row['comment'] ) ) : null;
$this->mText = isset( $row['text'] ) ? rtrim( strval( $row['text'] ) ) : null;
+ $this->mTextRow = null;
$this->mTitle = null; # Load on demand if needed
$this->mCurrent = false;
# Use external methods for external objects, text in table is URL-only then
if ( in_array( 'external', $flags ) ) {
$url=$text;
- @list($proto,$path)=explode('://',$url,2);
+ @list(/* $proto */,$path)=explode('://',$url,2);
if ($path=="") {
wfProfileOut( $fname );
return false;
}
- require_once('ExternalStore.php');
$text=ExternalStore::fetchFromURL($url);
}
} else {
$store = $wgDefaultExternalStore;
}
- require_once('ExternalStore.php');
// Store and get the URL
$data = ExternalStore::insert( $store, $data );
if ( !$data ) {
function loadText() {
$fname = 'Revision::loadText';
wfProfileIn( $fname );
-
- $dbr =& wfGetDB( DB_SLAVE );
- $row = $dbr->selectRow( 'text',
- array( 'old_text', 'old_flags' ),
- array( 'old_id' => $this->getTextId() ),
- $fname);
+
+ // Caching may be beneficial for massive use of external storage
+ global $wgRevisionCacheExpiry, $wgMemc;
+ $key = wfMemcKey( 'revisiontext', 'textid', $this->getTextId() );
+ if( $wgRevisionCacheExpiry ) {
+ $text = $wgMemc->get( $key );
+ if( is_string( $text ) ) {
+ wfProfileOut( $fname );
+ return $text;
+ }
+ }
+
+ // If we kept data for lazy extraction, use it now...
+ if ( isset( $this->mTextRow ) ) {
+ $row = $this->mTextRow;
+ $this->mTextRow = null;
+ } else {
+ $row = null;
+ }
+
+ if( !$row ) {
+ // Text data is immutable; check slaves first.
+ $dbr =& wfGetDB( DB_SLAVE );
+ $row = $dbr->selectRow( 'text',
+ array( 'old_text', 'old_flags' ),
+ array( 'old_id' => $this->getTextId() ),
+ $fname);
+ }
if( !$row ) {
+ // Possible slave lag!
$dbw =& wfGetDB( DB_MASTER );
$row = $dbw->selectRow( 'text',
array( 'old_text', 'old_flags' ),
}
$text = Revision::getRevisionText( $row );
+
+ if( $wgRevisionCacheExpiry ) {
+ $wgMemc->set( $key, $text, $wgRevisionCacheExpiry );
+ }
+
wfProfileOut( $fname );
return $text;
* @param integer $id
*/
static function getTimestampFromID( $id ) {
+ $dbr =& wfGetDB( DB_SLAVE );
$timestamp = $dbr->selectField( 'revision', 'rev_timestamp',
array( 'rev_id' => $id ), __METHOD__ );
if ( $timestamp === false ) {
}
return $timestamp;
}
+
+ static function countByPageId( $db, $id ) {
+ $row = $db->selectRow( 'revision', 'COUNT(*) AS revCount',
+ array( 'rev_page' => $id ), __METHOD__ );
+ if( $row ) {
+ return $row->revCount;
+ }
+ return 0;
+ }
+
+ static function countByTitle( $db, $title ) {
+ $id = $title->getArticleId();
+ if( $id ) {
+ return Revision::countByPageId( $db, $id );
+ }
+ return 0;
+ }
}
/**