/**
* Get the RC object belonging to the current revision, if there's one
*
+ * @param int $flags (optional) $flags include:
+ * Revision::READ_LATEST : Select the data from the master
+ *
* @since 1.22
* @return RecentChange|null
*/
- public function getRecentChange() {
+ public function getRecentChange( $flags = 0 ) {
$dbr = wfGetDB( DB_SLAVE );
+
+ list( $dbType, ) = DBAccessObjectUtils::getDBOptions( $flags );
+
return RecentChange::newFromConds(
array(
'rc_user_text' => $this->getUserText( Revision::RAW ),
'rc_timestamp' => $dbr->timestamp( $this->getTimestamp() ),
'rc_this_oldid' => $this->getId()
),
- __METHOD__
+ __METHOD__,
+ $dbType
);
}
# If no revision is given, the change was probably triggered by parser functions
if ( $revision !== null ) {
- // TODO if no RC try again from the master DB?
$correspondingRc = $this->revision->getRecentChange();
+ if ( $correspondingRc === null ) {
+ $correspondingRc = $this->revision->getRecentChange( Revision::READ_LATEST );
+ }
if ( $correspondingRc !== null ) {
$bot = $correspondingRc->getAttribute( 'rc_bot' ) ?: 0;
$ip = $correspondingRc->getAttribute( 'rc_ip' ) ?: '';
*
* @param array $conds Array of conditions
* @param mixed $fname Override the method name in profiling/logs
+ * @param int $dbType DB_* constant
+ *
* @return RecentChange|null
*/
- public static function newFromConds( $conds, $fname = __METHOD__ ) {
- $dbr = wfGetDB( DB_SLAVE );
- $row = $dbr->selectRow( 'recentchanges', self::selectFields(), $conds, $fname );
+ public static function newFromConds(
+ $conds,
+ $fname = __METHOD__,
+ $dbType = DB_SLAVE
+ ) {
+ $db = wfGetDB( $dbType );
+ $row = $db->selectRow( 'recentchanges', self::selectFields(), $conds, $fname );
if ( $row !== false ) {
return self::newFromRow( $row );
} else {