Adding new getCreator and getOldestRevision methods to WikiPage class.

Patch 2: Adding getOldest method per comments
Patch 3: whitespace fix
Patch 4: renaming getOldest to getOldestRevision
Patch 5: separating into 3 methods: getOldestRevisionId, getOldestRevision, getCreator
Patch 6: more concise, fixing whitespace
Patch 7: return user object instead of user id
Patch 8: consolidating revision methods per discussion
Patch 9: whitespace
Patch 11: better commit summary
Patch 12: Typo, sigh
Patch 13: switching to use Revision::newFromRow per comment
Patch 14: using Revision::selectFields()
Patch 15: moving outside of while loop
Change-Id: I140e17a95b89c9263978942fd642d6a236a5cc4f
This commit is contained in:
Kaldari 2012-05-07 13:39:02 -07:00
parent f1a37c1618
commit 57975e257f

View file

@ -494,6 +494,49 @@ class WikiPage extends Page {
return (int)$this->mLatest;
}
/**
* Get the Revision object of the oldest revision
* @return Revision|null
*/
public function getOldestRevision() {
wfProfileIn( __METHOD__ );
// Try using the slave database first, then try the master
$continue = 2;
$db = wfGetDB( DB_SLAVE );
$revSelectFields = Revision::selectFields();
while ( $continue ) {
$row = $db->selectRow(
array( 'page', 'revision' ),
$revSelectFields,
array(
'page_namespace' => $this->mTitle->getNamespace(),
'page_title' => $this->mTitle->getDBkey(),
'rev_page = page_id'
),
__METHOD__,
array(
'ORDER BY' => 'rev_timestamp ASC'
)
);
if ( $row ) {
$continue = 0;
} else {
$db = wfGetDB( DB_MASTER );
$continue--;
}
}
wfProfileOut( __METHOD__ );
if ( $row ) {
return Revision::newFromRow( $row );
} else {
return null;
}
}
/**
* Loads everything except the text
* This isn't necessary for all uses, so it's only done if needed.
@ -601,6 +644,24 @@ class WikiPage extends Page {
}
}
/**
* Get the User object of the user who created the page
* @param $audience Integer: one of:
* Revision::FOR_PUBLIC to be displayed to all users
* Revision::FOR_THIS_USER to be displayed to $wgUser
* Revision::RAW get the text regardless of permissions
* @return User|null
*/
public function getCreator( $audience = Revision::FOR_PUBLIC ) {
$revision = $this->getOldestRevision();
if ( $revision ) {
$userName = $revision->getUserText( $audience );
return User::newFromName( $userName, false );
} else {
return null;
}
}
/**
* @param $audience Integer: one of:
* Revision::FOR_PUBLIC to be displayed to all users