+/**
+ * @package MediaWiki
+ * @subpackage SpecialPage
+ */
+
+/** @package MediaWiki */
+class contribs_finder {
+ var $username, $offset, $limit, $namespace;
+ var $dbr;
+
+ function contribs_finder($username) {
+ $this->username = $username;
+ $this->namespace = false;
+ $this->dbr =& wfGetDB(DB_SLAVE);
+ }
+
+ function set_namespace($ns) {
+ $this->namespace = $ns;
+ }
+
+ function set_limit($limit) {
+ $this->limit = $limit;
+ }
+
+ function set_offset($offset) {
+ $this->offset = $offset;
+ }
+
+ function get_edit_limit($dir) {
+ list($index, $usercond) = $this->get_user_cond();
+ $nscond = $this->get_namespace_cond();
+ $use_index = $this->dbr->useIndexClause($index);
+ extract($this->dbr->tableNames('revision', 'page'));
+ $sql = "SELECT rev_timestamp " .
+ " FROM $page,$revision $use_index " .
+ " WHERE rev_page=page_id AND $usercond $nscond" .
+ " ORDER BY rev_timestamp $dir LIMIT 1";
+
+ $res = $this->dbr->query($sql, "contribs_finder::get_edit_limit");
+ while ($o = $this->dbr->fetchObject($res))
+ $row = $o;
+ return $row->rev_timestamp;
+ }
+
+ function get_edit_limits() {
+ return array(
+ $this->get_edit_limit("ASC"),
+ $this->get_edit_limit("DESC")
+ );
+ }
+
+ function get_user_cond() {
+ $condition = '';
+
+ if ($this->username == 'newbies') {
+ $max = $this->dbr->selectField('user', 'max(user_id)', false, 'make_sql');
+ $condition = '>' . (int)($max - $max / 100);
+ }
+
+ if ($condition == '') {
+ $condition = ' rev_user_text=' . $this->dbr->addQuotes($this->username);
+ $index = 'usertext_timestamp';
+ } else {
+ $condition = ' rev_user '.$condition ;
+ $index = 'user_timestamp';
+ }
+ return array($index, $condition);
+ }
+
+ function get_namespace_cond() {
+ if ($this->namespace !== false)
+ return ' AND page_namespace = ' . (int)$this->namespace;
+ return '';
+ }