/** * @param $path array|string * @param $status string * @return array */ private function getStatusPath($path, $status) { $array = array(); $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select(array('code_paths', 'code_rev'), array('COUNT(*) AS revs', 'cr_author'), array('cr_repo_id' => $this->repo->getId(), 'cp_path' => $path, 'cr_status' => $status), __METHOD__, array('GROUP BY' => 'cr_author', 'ORDER BY' => 'revs DESC', 'LIMIT' => 500), array('code_rev' => array('INNER JOIN', 'cr_repo_id = cp_repo_id AND cr_id = cp_rev_id'))); foreach ($res as $row) { $array[$row->cr_author] = $row->revs; } return $array; }
function doBatchChange() { global $wgRequest, $wgUser, $wgOut; $revisions = $wgRequest->getArray('wpRevisionSelected'); $removeTags = $wgRequest->getVal('wpRemoveTag'); $addTags = $wgRequest->getVal('wpTag'); $status = $wgRequest->getVal('wpStatus'); // Grab data from the DB $dbr = wfGetDB(DB_SLAVE); $revObjects = array(); $res = $dbr->select('code_rev', '*', array('cr_id' => $revisions, 'cr_repo_id' => $this->mRepo->getId()), __METHOD__); foreach ($res as $row) { $revObjects[] = CodeRevision::newFromRow($this->mRepo, $row); } if ($wgUser->isAllowed('codereview-add-tag') && $addTags || $removeTags) { $addTags = array_map('trim', explode(",", $addTags)); $removeTags = array_map('trim', explode(",", $removeTags)); foreach ($revObjects as $rev) { $rev->changeTags($addTags, $removeTags, $wgUser); } } if ($wgUser->isAllowed('codereview-set-status') && $revObjects && CodeRevision::isValidStatus($status)) { foreach ($revObjects as $rev) { $rev->setStatus($status, $wgUser); } } // Automatically refresh // This way of getting GET parameters is horrible, but effective. $fields = $wgRequest->getValues(); foreach (array_keys($fields) as $key) { if (substr($key, 0, 2) == 'wp' || $key == 'title') { unset($fields[$key]); } } $wgOut->redirect($this->getPager()->getTitle()->getFullURL($fields)); }
/** * @static * @throws MWException * @param CodeRepository $repo * @param $row * @return CodeRevision */ public static function newFromRow(CodeRepository $repo, $row) { $rev = new CodeRevision(); $rev->repoId = intval($row->cr_repo_id); if ($rev->repoId != $repo->getId()) { throw new MWException("Invalid repo ID in " . __METHOD__); } $rev->repo = $repo; $rev->id = intval($row->cr_id); $rev->author = $row->cr_author; $rev->timestamp = wfTimestamp(TS_MW, $row->cr_timestamp); $rev->message = $row->cr_message; $rev->status = $row->cr_status; $rev->oldStatus = ''; $rev->commonPath = $row->cr_path; return $rev; }