}
/**
- * FIXME: this does what?
- * @param $limit Integer: default 0.
- * @param $offset Integer: default 0.
- * @return UserArrayFromResult object with User objects of article contributors for requested range
+ * Get a list of users who have edited this article, not including the user who made
+ * the most recent revision, which you can get from $article->getUser() if you want it
+ * @return UserArray
*/
- public function getContributors( $limit = 0, $offset = 0 ) {
+ public function getContributors() {
# FIXME: this is expensive; cache this info somewhere.
$dbr = wfGetDB( DB_SLAVE );
- $revTable = $dbr->tableName( 'revision' );
$userTable = $dbr->tableName( 'user' );
- $pageId = $this->getId();
+ $tables = array( 'revision', 'user' );
- $user = $this->getUser();
+ $fields = array(
+ "$userTable.*",
+ 'rev_user_text AS user_name',
+ 'MAX(rev_timestamp) AS timestamp',
+ );
+ $conds = array( 'rev_page' => $this->getId() );
+
+ // The user who made the top revision gets credited as "this page was last edited by
+ // John, based on contributions by Tom, Dick and Harry", so don't include them twice.
+ $user = $this->getUser();
if ( $user ) {
- $excludeCond = "AND rev_user != $user";
+ $conds[] = "rev_user != $user";
} else {
- $userText = $dbr->addQuotes( $this->getUserText() );
- $excludeCond = "AND rev_user_text != $userText";
+ $conds[] = "rev_user_text != {$dbr->addQuotes( $this->getUserText() )}";
}
- $deletedBit = $dbr->bitAnd( 'rev_deleted', Revision::DELETED_USER ); // username hidden?
-
- $sql = "SELECT {$userTable}.*, rev_user_text as user_name, MAX(rev_timestamp) as timestamp
- FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
- WHERE rev_page = $pageId
- $excludeCond
- AND $deletedBit = 0
- GROUP BY rev_user, rev_user_text
- ORDER BY timestamp DESC";
+ $conds[] = "{$dbr->bitAnd( 'rev_deleted', Revision::DELETED_USER )} = 0"; // username hidden?
- if ( $limit > 0 ) {
- $sql = $dbr->limitResult( $sql, $limit, $offset );
- }
-
- $sql .= ' ' . $this->getSelectOptions();
- $res = $dbr->query( $sql, __METHOD__ );
+ $jconds = array(
+ 'user' => array( 'LEFT JOIN', 'rev_user = user_id' ),
+ );
+ $options = array(
+ 'GROUP BY' => array( 'rev_user', 'rev_user_text' ),
+ 'ORDER BY' => 'timestamp DESC',
+ );
+
+ $res = $dbr->select( $tables, $fields, $conds, __METHOD__, $options, $jconds );
return new UserArrayFromResult( $res );
}
$dbw = wfGetDB( DB_MASTER );
$cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
- $recentchanges = $dbw->tableName( 'recentchanges' );
- $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
-
- $dbw->query( $sql );
+ $dbw->delete(
+ 'recentchanges',
+ array( "rc_timestamp < '$cutoff'" ),
+ __METHOD__
+ );
}
}
# Generates the distinct list of authors of an article
# Not called by default (depends on $this->list_authors)
# Can be set by Special:Export when not exporting whole history
- protected function do_list_authors( $page , $revision , $cond ) {
+ protected function do_list_authors( $cond ) {
wfProfileIn( __METHOD__ );
$this->author_list = "<contributors>";
// rev_deleted
- $nothidden = '(' . $this->db->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ') = 0';
- $sql = "SELECT DISTINCT rev_user_text,rev_user FROM {$page},{$revision}
- WHERE page_id=rev_page AND $nothidden AND " . $cond ;
- $result = $this->db->query( $sql, __METHOD__ );
- $resultset = $this->db->resultObject( $result );
- foreach ( $resultset as $row ) {
+ $res = $this->db->select(
+ array( 'page', 'revision' ),
+ array( 'DISTINCT rev_user_text', 'rev_user' ),
+ array(
+ $this->db->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0',
+ $cond,
+ 'page_id = rev_id',
+ ),
+ __METHOD__
+ );
+
+ foreach ( $res as $row ) {
$this->author_list .= "<contributor>" .
"<username>" .
htmlentities( $row->rev_user_text ) .
} elseif ( $this->history & WikiExporter::CURRENT ) {
# Latest revision dumps...
if ( $this->list_authors && $cond != '' ) { // List authors, if so desired
- list( $page, $revision ) = $this->db->tableNamesN( 'page', 'revision' );
- $this->do_list_authors( $page, $revision, $cond );
+ $this->do_list_authors( $cond );
}
$join['revision'] = array( 'INNER JOIN', 'page_id=rev_page AND page_latest=rev_id' );
} elseif ( $this->history & WikiExporter::STABLE ) {
# Generate query
$query = false;
$current = null;
+ $queries = array();
foreach ( $this->internals as $ns => $entries ) {
foreach ( $entries as $entry ) {
$title = $entry['title'];
$colours[$pdbk] = 'new';
} else {
# Not in the link cache, add it to the query
- if ( !isset( $current ) ) {
- $current = $ns;
- $query = "SELECT page_id, page_namespace, page_title, page_is_redirect, page_len, page_latest";
- $query .= " FROM $page WHERE (page_namespace=$ns AND page_title IN(";
- } elseif ( $current != $ns ) {
- $current = $ns;
- $query .= ")) OR (page_namespace=$ns AND page_title IN(";
- } else {
- $query .= ', ';
- }
-
- $query .= $dbr->addQuotes( $title->getDBkey() );
+ $queries[$ns][] = $title->getDBkey();
}
}
}
- if ( $query ) {
- $query .= '))';
+ if ( $queries ) {
+ $where = array();
+ foreach( $queries as $ns => $pages ){
+ $where[] = $dbr->makeList(
+ array(
+ 'page_namespace' => $ns,
+ 'page_title' => $pages,
+ ),
+ LIST_AND
+ );
+ }
- $res = $dbr->query( $query, __METHOD__ );
+ $res = $dbr->select(
+ 'page',
+ array( 'page_id', 'page_namespace', 'page_title', 'page_is_redirect', 'page_len', 'page_latest' ),
+ $dbr->makeList( $where, LIST_OR ),
+ __METHOD__
+ );
# Fetch data and form into an associative array
# non-existent = broken