/** * Render the contributions of user to page * @param ResultWrapper $res */ protected function showContributions(ResultWrapper $res) { $numRows = $res->numRows(); $rev = null; $out = $this->getOutput(); $revs = array(); $prevRevs = array(); foreach ($res as $row) { $rev = new Revision($row); $revs[] = $rev; if ($res->key() <= self::LIMIT + 1 && $rev->getParentId()) { $prevRevs[] = $rev->getParentId(); } } $this->prevLengths = Revision::getParentLengths(wfGetDB(DB_SLAVE), $prevRevs); if ($numRows > 0) { $count = 0; foreach ($revs as $rev) { if ($count++ < self::LIMIT) { $this->showContributionsRow($rev); } } $out->addHtml('</ul>'); // Captured 1 more than we should have done so if the number of // results is greater than the limit there are more to show. if ($numRows > self::LIMIT) { $out->addHtml($this->getMoreButton($rev->getTimestamp())); } } else { // For users who exist but have not made any edits $out->addHtml(MobileUI::warningBox($this->msg('mobile-frontend-history-no-results'))); } }
function doBatchLookups() { # Do a link batch query $this->mResult->seek(0); $batch = new LinkBatch(); $revIds = array(); foreach ($this->mResult as $row) { if ($row->rev_parent_id) { $revIds[] = $row->rev_parent_id; } if (!is_null($row->user_name)) { $batch->add(NS_USER, $row->user_name); $batch->add(NS_USER_TALK, $row->user_name); } else { # for anons or usernames of imported revisions $batch->add(NS_USER, $row->rev_user_text); $batch->add(NS_USER_TALK, $row->rev_user_text); } } $this->parentLens = Revision::getParentLengths($this->mDb, $revIds); $batch->execute(); $this->mResult->seek(0); }
function doBatchLookups() { # Do a link batch query $this->mResult->seek(0); $revIds = array(); $batch = new LinkBatch(); # Give some pointers to make (last) links foreach ($this->mResult as $row) { if (isset($row->rev_parent_id) && $row->rev_parent_id) { $revIds[] = $row->rev_parent_id; } if (isset($row->rev_id)) { if ($this->contribs === 'newbie') { // multiple users $batch->add(NS_USER, $row->user_name); $batch->add(NS_USER_TALK, $row->user_name); } $batch->add($row->page_namespace, $row->page_title); } } $this->mParentLens = Revision::getParentLengths($this->getDatabase(), $revIds); $batch->execute(); $this->mResult->seek(0); }
function doBatchLookups() { # Do a link batch query $this->mResult->seek(0); $parentRevIds = []; $this->mParentLens = []; $batch = new LinkBatch(); # Give some pointers to make (last) links foreach ($this->mResult as $row) { if (isset($row->rev_parent_id) && $row->rev_parent_id) { $parentRevIds[] = $row->rev_parent_id; } if (isset($row->rev_id)) { $this->mParentLens[$row->rev_id] = $row->rev_len; if ($this->contribs === 'newbie') { // multiple users $batch->add(NS_USER, $row->user_name); $batch->add(NS_USER_TALK, $row->user_name); } $batch->add($row->page_namespace, $row->page_title); } } # Fetch rev_len for revisions not already scanned above $this->mParentLens += Revision::getParentLengths($this->mDbSecondary, array_diff($parentRevIds, array_keys($this->mParentLens))); $batch->execute(); $this->mResult->seek(0); }
public function execute() { // Parse some parameters $this->params = $this->extractRequestParams(); $prop = array_flip($this->params['prop']); $this->fld_ids = isset($prop['ids']); $this->fld_title = isset($prop['title']); $this->fld_comment = isset($prop['comment']); $this->fld_parsedcomment = isset($prop['parsedcomment']); $this->fld_size = isset($prop['size']); $this->fld_sizediff = isset($prop['sizediff']); $this->fld_flags = isset($prop['flags']); $this->fld_timestamp = isset($prop['timestamp']); $this->fld_patrolled = isset($prop['patrolled']); $this->fld_tags = isset($prop['tags']); // TODO: if the query is going only against the revision table, should this be done? $this->selectNamedDB('contributions', DB_SLAVE, 'contributions'); if (isset($this->params['userprefix'])) { $this->prefixMode = true; $this->multiUserMode = true; $this->userprefix = $this->params['userprefix']; } else { $this->usernames = array(); if (!is_array($this->params['user'])) { $this->params['user'] = array($this->params['user']); } if (!count($this->params['user'])) { $this->dieUsage('User parameter may not be empty.', 'param_user'); } foreach ($this->params['user'] as $u) { $this->prepareUsername($u); } $this->prefixMode = false; $this->multiUserMode = count($this->params['user']) > 1; } $this->prepareQuery(); // Do the actual query. $res = $this->select(__METHOD__); if ($this->fld_sizediff) { $revIds = array(); foreach ($res as $row) { if ($row->rev_parent_id) { $revIds[] = $row->rev_parent_id; } } $this->parentLens = Revision::getParentLengths($this->getDB(), $revIds); $res->rewind(); // reset } // Initialise some variables $count = 0; $limit = $this->params['limit']; // Fetch each row foreach ($res as $row) { if (++$count > $limit) { // We've reached the one extra which shows that there are // additional pages to be had. Stop here... if ($this->multiUserMode) { $this->setContinueEnumParameter('continue', $this->continueStr($row)); } else { $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->rev_timestamp)); } break; } $vals = $this->extractRowInfo($row); $fit = $this->getResult()->addValue(array('query', $this->getModuleName()), null, $vals); if (!$fit) { if ($this->multiUserMode) { $this->setContinueEnumParameter('continue', $this->continueStr($row)); } else { $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->rev_timestamp)); } break; } } $this->getResult()->setIndexedTagName_internal(array('query', $this->getModuleName()), 'item'); }
public function execute() { // Parse some parameters $this->params = $this->extractRequestParams(); $prop = array_flip($this->params['prop']); $this->fld_ids = isset($prop['ids']); $this->fld_title = isset($prop['title']); $this->fld_comment = isset($prop['comment']); $this->fld_parsedcomment = isset($prop['parsedcomment']); $this->fld_size = isset($prop['size']); $this->fld_sizediff = isset($prop['sizediff']); $this->fld_flags = isset($prop['flags']); $this->fld_timestamp = isset($prop['timestamp']); $this->fld_patrolled = isset($prop['patrolled']); $this->fld_tags = isset($prop['tags']); // Most of this code will use the 'contributions' group DB, which can map to replica DBs // with extra user based indexes or partioning by user. The additional metadata // queries should use a regular replica DB since the lookup pattern is not all by user. $dbSecondary = $this->getDB(); // any random replica DB // TODO: if the query is going only against the revision table, should this be done? $this->selectNamedDB('contributions', DB_REPLICA, 'contributions'); $this->idMode = false; if (isset($this->params['userprefix'])) { $this->prefixMode = true; $this->multiUserMode = true; $this->userprefix = $this->params['userprefix']; } else { $anyIPs = false; $this->userids = []; $this->usernames = []; if (!is_array($this->params['user'])) { $this->params['user'] = [$this->params['user']]; } if (!count($this->params['user'])) { $this->dieUsage('User parameter may not be empty.', 'param_user'); } foreach ($this->params['user'] as $u) { if (is_null($u) || $u === '') { $this->dieUsage('User parameter may not be empty', 'param_user'); } if (User::isIP($u)) { $anyIPs = true; $this->usernames[] = $u; } else { $name = User::getCanonicalName($u, 'valid'); if ($name === false) { $this->dieUsage("User name {$u} is not valid", 'param_user'); } $this->usernames[] = $name; } } $this->prefixMode = false; $this->multiUserMode = count($this->params['user']) > 1; if (!$anyIPs) { $dbr = $this->getDB(); $res = $dbr->select('user', 'user_id', ['user_name' => $this->usernames], __METHOD__); foreach ($res as $row) { $this->userids[] = $row->user_id; } $this->idMode = count($this->userids) === count($this->usernames); } } $this->prepareQuery(); $hookData = []; // Do the actual query. $res = $this->select(__METHOD__, [], $hookData); if ($this->fld_sizediff) { $revIds = []; foreach ($res as $row) { if ($row->rev_parent_id) { $revIds[] = $row->rev_parent_id; } } $this->parentLens = Revision::getParentLengths($dbSecondary, $revIds); $res->rewind(); // reset } // Initialise some variables $count = 0; $limit = $this->params['limit']; // Fetch each row foreach ($res as $row) { if (++$count > $limit) { // We've reached the one extra which shows that there are // additional pages to be had. Stop here... $this->setContinueEnumParameter('continue', $this->continueStr($row)); break; } $vals = $this->extractRowInfo($row); $fit = $this->processRow($row, $vals, $hookData) && $this->getResult()->addValue(['query', $this->getModuleName()], null, $vals); if (!$fit) { $this->setContinueEnumParameter('continue', $this->continueStr($row)); break; } } $this->getResult()->addIndexedTagName(['query', $this->getModuleName()], 'item'); }