/**
  * {@inheritdoc}
  */
 public function getCodeByCode($codeString)
 {
     if (!($code = $this->repository->findOneByCode($codeId))) {
         throw new CodeNotFoundException('code', $codeId);
     }
     return $code;
 }
Esempio n. 2
0
 /**
  * @param $matches array
  */
 function messageRevLink($matches)
 {
     $text = $matches[0];
     $rev = intval($matches[1]);
     $repo = $this->mRepo->getName();
     $title = SpecialPage::getTitleFor('Code', "{$repo}/{$rev}");
     return $this->makeInternalLink($title, $text);
 }
 public function execute()
 {
     global $wgUser;
     // Before doing anything at all, let's check permissions
     if (!$wgUser->isAllowed('codereview-use')) {
         $this->dieUsage('You don\'t have permission to view code paths', 'permissiondenied');
     }
     $params = $this->extractRequestParams();
     $repo = CodeRepository::newFromName($params['repo']);
     if (!$repo instanceof CodeRepository) {
         $this->dieUsage("Invalid repo ``{$params['repo']}''", 'invalidrepo');
     }
     $this->addTables('code_paths');
     $this->addFields('DISTINCT cp_path');
     $this->addWhere(array('cp_repo_id' => $repo->getId()));
     $db = $this->getDB();
     $this->addWhere('cp_path ' . $db->buildLike($params['path'], $db->anyString()));
     $this->addOption('USE INDEX', 'repo_path');
     $this->addOption('LIMIT', 10);
     $res = $this->select(__METHOD__);
     $result = $this->getResult();
     $data = array();
     foreach ($res as $row) {
         $item = array();
         ApiResult::setContent($item, $row->cp_path);
         $data[] = $item;
     }
     $result->setIndexedTagName($data, 'paths');
     $result->addValue('query', $this->getModuleName(), $data);
 }
Esempio n. 4
0
 public function execute()
 {
     global $wgUser, $wgCodeReviewMaxDiffSize;
     // Before doing anything at all, let's check permissions
     if (!$wgUser->isAllowed('codereview-use')) {
         $this->dieUsage('You don\'t have permission to view code diffs', 'permissiondenied');
     }
     $params = $this->extractRequestParams();
     $repo = CodeRepository::newFromName($params['repo']);
     if (!$repo) {
         $this->dieUsage("Invalid repo ``{$params['repo']}''", 'invalidrepo');
     }
     $lastStoredRev = $repo->getLastStoredRev();
     if ($params['rev'] > $lastStoredRev) {
         $this->dieUsage("There is no revision with ID {$params['rev']}", 'nosuchrev');
     }
     $diff = $repo->getDiff($params['rev']);
     if (!is_string($diff)) {
         // FIXME: Are we sure we don't want to throw an error here?
         $html = 'Failed to load diff. Error message: ' . CodeRepository::getDiffErrorMessage($diff);
     } elseif (strlen($diff) > $wgCodeReviewMaxDiffSize) {
         $html = 'Diff too large.';
     } else {
         $hilite = new CodeDiffHighlighter();
         $html = $hilite->render($diff);
     }
     $data = array('repo' => $params['repo'], 'id' => $params['rev'], 'diff' => $html);
     $this->getResult()->addValue('code', 'rev', $data);
 }
Esempio n. 5
0
 public function execute()
 {
     $repoName = $this->getArg(0);
     if ($repoName == "all") {
         $this->error("Cannot use the 'all' repo", true);
     }
     $repo = CodeRepository::newFromName($repoName);
     if (!$repo) {
         $this->error("Repo '{$repoName}' is not a valid Repository", true);
     }
     $revisions = $this->getArg(1);
     if (strpos($revisions, ':') !== false) {
         $revisionVals = explode(':', $revisions, 2);
     } else {
         $this->error("Invalid revision range", true);
     }
     $start = intval($revisionVals[0]);
     $end = intval($revisionVals[1]);
     $revisions = range($start, $end);
     $dbr = wfGetDB(DB_SLAVE);
     $res = $dbr->select('code_paths', '*', array('cp_rev_id' => $revisions, 'cp_repo_id' => $repo->getId()), __METHOD__);
     $dbw = wfGetDB(DB_MASTER);
     $dbw->begin();
     foreach ($res as $row) {
         $fragments = CodeRevision::getPathFragments(array(array('path' => $row->cp_path, 'action' => $row->cp_action)));
         CodeRevision::insertPaths($dbw, $fragments, $repo->getId(), $row->cp_rev_id);
         $this->output("r{$row->cp_rev_id}, path: " . $row->cp_path . " Fragments: " . count($fragments) . "\n");
     }
     $dbw->commit();
     $this->output("Done!\n");
 }
 function __construct($path, $request)
 {
     parent::__construct($path, $request);
     $parts = explode('/', $path, 2);
     $this->mRepoName = $parts[0];
     $this->mBasePath = '/' . @$parts[1];
     $this->mRepository = CodeRepository::newFromName($this->mRepoName);
 }
Esempio n. 7
0
 /**
  * @param $status string
  * @param $oldStatus string
  */
 protected function sendStatusToUDP($status, $oldStatus)
 {
     global $wgCodeReviewUDPAddress, $wgCodeReviewUDPPort, $wgCodeReviewUDPPrefix, $wgUser;
     if ($wgCodeReviewUDPAddress) {
         $url = $this->getCanonicalUrl();
         $line = wfMsg('code-rev-status') . " 14(" . $this->repo->getName() . ")03 " . RecentChange::cleanupForIRC($wgUser->getName()) . " " . str_replace("'''", '', wfMsg('code-change-status', "7" . $this->getIdString() . "")) . ": 15" . wfMsg('code-status-' . $oldStatus) . " -> 10" . wfMsg('code-status-' . $status) . " " . $url;
         RecentChange::sendToUDP($line, $wgCodeReviewUDPAddress, $wgCodeReviewUDPPrefix, $wgCodeReviewUDPPort);
     }
 }
Esempio n. 8
0
 /**
  * @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;
 }
Esempio n. 9
0
 private function createRepo()
 {
     $row = new stdClass();
     $row->repo_id = 1;
     $row->repo_name = 'Test';
     $row->repo_path = 'somewhere';
     $row->repo_viewvc = 'http://example.com/view/';
     $row->repo_bugzilla = 'http://example.com/$1';
     return CodeRepository::newFromRow($row);
 }
Esempio n. 10
0
 public function execute()
 {
     global $wgUser;
     $this->getMain()->setCacheMode('anon-public-user-private');
     // Before doing anything at all, let's check permissions
     if (!$wgUser->isAllowed('codereview-use')) {
         $this->dieUsage('You don\'t have permission to view code revisions', 'permissiondenied');
     }
     $params = $this->extractRequestParams();
     $this->props = array_flip($params['prop']);
     $repo = CodeRepository::newFromName($params['repo']);
     if (!$repo) {
         $this->dieUsage("Invalid repo ``{$params['repo']}''", 'invalidrepo');
     }
     $data = array();
     $listview = new CodeRevisionListView($repo);
     if (isset($params['path']) && $params['path'] !== '') {
         $listview->mPath = CodeRevisionListView::pathsToArray($params['path']);
     }
     $pager = $listview->getPager();
     $revsSet = count($params['revs']);
     if ($revsSet) {
         $db = wfGetDB(DB_SLAVE);
         $query = $pager->getQueryInfo();
         $query['conds']['cr_id'] = $params['revs'];
         $revisions = $db->select($query['tables'], $query['fields'], $query['conds'], __METHOD__, $query['options'], $query['join_conds']);
     } else {
         if (!is_null($params['start'])) {
             $pager->setOffset($params['start']);
         }
         $limit = $params['limit'];
         $pager->setLimit($limit);
         $pager->doQuery();
         $revisions = $pager->getResult();
     }
     $count = 0;
     $start = 0;
     $defaultSort = $pager->getDefaultSort();
     $result = $this->getResult();
     foreach ($revisions as $row) {
         if (!$revsSet && $count == $limit) {
             $this->setContinueEnumParameter('start', $start);
             break;
         }
         $data[] = $this->formatRow($row, $repo, $result);
         $start = $row->{$defaultSort};
         $count++;
     }
     $result->setIndexedTagName($data, 'revision');
     $result->addValue('query', $this->getModuleName(), $data);
 }
Esempio n. 11
0
 /**
  * @param $pager SvnTablePager
  *
  * @return string
  */
 function showForm($pager)
 {
     global $wgScript, $wgRequest;
     $states = CodeRevision::getPossibleStates();
     $name = $this->mRepo->getName();
     $title = SpecialPage::getTitleFor('Code', $name);
     $options = array(Xml::option('', $title->getPrefixedText(), $this->mStatus == ''));
     foreach ($states as $key => $state) {
         $title = SpecialPage::getTitleFor('Code', $name . "/status/{$state}");
         $options[] = Xml::option(wfMsgHtml("code-status-{$state}"), $title->getPrefixedText(), $this->mStatus == $state);
     }
     $ret = "<fieldset><legend>" . wfMsgHtml('code-pathsearch-legend') . "</legend>" . '<table width="100%"><tr><td>' . Xml::openElement('form', array('action' => $wgScript, 'method' => 'get')) . Xml::inputlabel(wfMsg("code-pathsearch-path"), 'path', 'path', 55, $this->getPathsAsString(), array('dir' => 'ltr')) . '&#160;' . Xml::label(wfMsg('code-pathsearch-filter'), 'code-status-filter') . '&#160;' . Xml::openElement('select', array('id' => 'code-status-filter', 'name' => 'title')) . "\n" . implode("\n", $options) . "\n" . Xml::closeElement('select') . '&#160;' . Xml::submitButton(wfMsg('allpagessubmit')) . $pager->getHiddenFields(array('path', 'title')) . Xml::closeElement('form') . '</td></tr></table></fieldset>';
     return $ret;
 }
Esempio n. 12
0
 public function execute()
 {
     global $wgUser;
     // Before doing anything at all, let's check permissions
     if (!$wgUser->isAllowed('codereview-use')) {
         $this->dieUsage('You don\'t have permission to update code', 'permissiondenied');
     }
     $params = $this->extractRequestParams();
     $repo = CodeRepository::newFromName($params['repo']);
     if (!$repo) {
         $this->dieUsage("Invalid repo ``{$params['repo']}''", 'invalidrepo');
     }
     $svn = SubversionAdaptor::newFromRepo($repo->getPath());
     $lastStoredRev = $repo->getLastStoredRev();
     if ($lastStoredRev >= $params['rev']) {
         // Nothing to do, we're up to date.
         // Return an empty result
         $this->getResult()->addValue(null, $this->getModuleName(), array());
         return;
     }
     // FIXME: this could be a lot?
     $log = $svn->getLog('', $lastStoredRev + 1, $params['rev']);
     if (!$log) {
         // FIXME: When and how often does this happen?
         // Should we use dieUsage() here instead?
         ApiBase::dieDebug(__METHOD__, 'Something awry...');
     }
     $result = array();
     $revs = array();
     foreach ($log as $data) {
         $codeRev = CodeRevision::newFromSvn($repo, $data);
         $codeRev->save();
         $result[] = array('id' => $codeRev->getId(), 'author' => $codeRev->getAuthor(), 'timestamp' => wfTimestamp(TS_ISO_8601, $codeRev->getTimestamp()), 'message' => $codeRev->getMessage());
         $revs[] = $codeRev;
     }
     // Cache the diffs if there are a only a few.
     // Mainly for WMF post-commit ping hook...
     if (count($revs) <= 2) {
         foreach ($revs as $codeRev) {
             $repo->setDiffCache($codeRev);
             // trigger caching
         }
     }
     $this->getResult()->setIndexedTagName($result, 'rev');
     $this->getResult()->addValue(null, $this->getModuleName(), $result);
 }
Esempio n. 13
0
 private function createRepo()
 {
     $dbw = wfGetDB(DB_MASTER);
     $dbw->insert('code_repo', array('repo_name' => 'Test', 'repo_path' => 'somewhere', 'repo_viewvc' => 'http://example.com/view/', 'repo_bugzilla' => 'http://www.example.com/$1'), __METHOD__);
     $id = $dbw->insertId();
     $this->repo = CodeRepository::newFromId($id);
     # Now insert a revision
     $row = new StdClass();
     $row->cr_repo_id = $this->repo->getId();
     $row->cr_id = 777;
     $row->cr_author = 'hashar';
     $row->cr_timestamp = '20110731063300';
     $row->cr_message = 'I am the very first revision of this life';
     $row->cr_status = '';
     $row->cr_path = '/trunk/';
     $rev = CodeRevision::newFromRow($this->repo, $row);
     $rev->save();
 }
Esempio n. 14
0
 public function execute()
 {
     $repoName = $this->getArg(0);
     if ($repoName == "all") {
         $this->error("Cannot use the 'all' repo", true);
     }
     $repo = CodeRepository::newFromName($repoName);
     if (!$repo) {
         $this->error("Repo '{$repoName}' is not a valid Repository", true);
     }
     $revisions = $this->getArg(1);
     if (strpos($revisions, ':') !== false) {
         $revisionVals = explode(':', $revisions, 2);
     } else {
         $this->error("Invalid revision range", true);
     }
     $start = intval($revisionVals[0]);
     $end = intval($revisionVals[1]);
     $revisions = range($start, $end);
     $status = $this->getArg(2);
     if (!CodeRevision::isValidStatus($status)) {
         $this->error("'{$status}' is not a valid status", true);
     }
     $username = $this->getArg(3);
     $user = User::newFromName($username);
     if (!$user) {
         $this->error("'{$username}' is not a valid username ", true);
     }
     if (!$user->isAllowed('codereview-set-status')) {
         $this->error("'{$username}' does not have the 'codereview-set-status' right", true);
     }
     $dbr = wfGetDB(DB_SLAVE);
     $res = $dbr->select('code_rev', '*', array('cr_id' => $revisions, 'cr_repo_id' => $repo->getId()), __METHOD__);
     foreach ($res as $row) {
         $rev = CodeRevision::newFromRow($repo, $row);
         if ($rev && $rev->setStatus($status, $user)) {
             $this->output("r{$row->cr_id} updated\n");
         } else {
             $this->output("r{$row->cr_id} not updated\n");
         }
     }
     $this->output("Done!\n");
 }
Esempio n. 15
0
 public function execute()
 {
     global $wgUser;
     // Before doing anything at all, let's check permissions
     if (!$wgUser->isAllowed('codereview-use')) {
         $this->dieUsage('You don\'t have permission to view code tags', 'permissiondenied');
     }
     $params = $this->extractRequestParams();
     $repo = CodeRepository::newFromName($params['repo']);
     if (!$repo instanceof CodeRepository) {
         $this->dieUsage("Invalid repo ``{$params['repo']}''", 'invalidrepo');
     }
     $data = array();
     foreach ($repo->getTagList(true) as $tag => $count) {
         $data[] = array('name' => $tag, 'revcount' => $count);
     }
     $result = $this->getResult();
     $result->setIndexedTagName($data, 'tag');
     $result->addValue('query', $this->getModuleName(), $data);
 }
 static function reallyGetContent()
 {
     $repos = CodeRepository::getRepoList();
     if (!count($repos)) {
         return wfMsg('code-no-repo');
     }
     $text = '';
     foreach ($repos as $repo) {
         global $wgLang;
         $name = $repo->getName();
         $text .= "* '''[[Special:CodeBrowse/{$name}|{$name}]]''' (";
         $links[] = "[[Special:Code/{$name}|" . wfMsgHtml('code-log') . "]]";
         $links[] = "[[Special:Code/{$name}/comments|" . wfMsgHtml('code-notes') . "]]";
         $links[] = "[[Special:Code/{$name}/tag|" . wfMsgHtml('code-tags') . "]]";
         $links[] = "[[Special:Code/{$name}/author|" . wfMsgHtml('code-authors') . "]]";
         $text .= $wgLang->pipeList($links);
         $text .= ")\n";
     }
     return $text;
 }
Esempio n. 17
0
 public function execute()
 {
     global $wgOut;
     $repos = CodeRepository::getRepoList();
     if (!count($repos)) {
         global $wgUser;
         $wgOut->addWikiMsg('code-no-repo');
         if ($wgUser->isAllowed('repoadmin')) {
             $wgOut->addWikiMsg('code-create-repo');
         } else {
             $wgOut->addWikiMsg('code-need-repoadmin-rights');
             if (!count(User::getGroupsWithPermission('repoadmin'))) {
                 $wgOut->addWikiMsg('code-need-group-with-rights');
             }
         }
         return;
     }
     $text = '';
     foreach ($repos as $repo) {
         $text .= "* " . self::getNavItem($repo) . "\n";
     }
     $wgOut->addWikiText($text);
 }
Esempio n. 18
0
 public function execute()
 {
     global $wgUser;
     // Before doing anything at all, let's check permissions
     if (!$wgUser->isAllowed('codereview-use')) {
         $this->dieUsage('You don\'t have permission to update code', 'permissiondenied');
     }
     $params = $this->extractRequestParams();
     if ($params['comment'] && !$wgUser->isAllowed('codereview-post-comment')) {
         $this->dieUsage('You do not have permission to post comment', 'permissiondenied');
     }
     global $wgCodeReviewInlineComments;
     if (!$wgCodeReviewInlineComments && isset($params['patchline'])) {
         $this->dieUsageMsg("Can not attach a comment to a diff when inline commenting is disabled (\$wgCodeReviewInlineComments is false).");
     }
     $repo = CodeRepository::newFromName($params['repo']);
     if (!$repo) {
         $this->dieUsage("Invalid repo ``{$params['repo']}''", 'invalidrepo');
     }
     $rev = $repo->getRevision($params['rev']);
     if (!$rev) {
         $this->dieUsage("There is no revision with ID {$params['rev']}", 'nosuchrev');
     }
     $revisionCommitter = new CodeRevisionCommitterApi($repo, $rev);
     $commentID = $revisionCommitter->revisionUpdate($params['status'], $params['addtags'], $params['removetags'], $params['addflags'], $params['removeflags'], $params['addreferences'], $params['removereferences'], $params['comment'], $params['addreferenced'], $params['removereferenced']);
     // Forge a response object
     $r = array('result' => 'Success');
     if ($commentID !== 0) {
         // id inserted
         $r['commentid'] = intval($commentID);
         // HTML Formatted comment
         $view = new CodeRevisionView($repo, $rev);
         $comment = CodeComment::newFromID($commentID, $rev);
         $r['HTML'] = $view->formatComment($comment);
     }
     $this->getResult()->addValue(null, $this->getModuleName(), $r);
 }
 public function execute()
 {
     $repoName = $this->getArg(0);
     if ($repoName == "all") {
         $this->error("Cannot use the 'all' repo", true);
     }
     $repo = CodeRepository::newFromName($repoName);
     if (!$repo) {
         $this->error("Repo '{$repoName}' is not a valid Repository", true);
     }
     $revisions = $this->getArg(1);
     if (strpos($revisions, ':') !== false) {
         $revisionVals = explode(':', $revisions, 2);
     } else {
         $this->error("Invalid revision range", true);
     }
     $start = intval($revisionVals[0]);
     $end = intval($revisionVals[1]);
     $revisions = range($start, $end);
     $dryrun = $this->hasOption('dry-run');
     $dbr = wfGetDB(DB_SLAVE);
     $res = $dbr->select('code_rev', '*', array('cr_id' => $revisions, 'cr_repo_id' => $repo->getId()), __METHOD__);
     foreach ($res as $row) {
         $rev = CodeRevision::newFromRow($repo, $row);
         $affectedRevs = $rev->getUniqueAffectedRevs();
         $this->output("r{$row->cr_id}: ");
         if (count($affectedRevs)) {
             $this->output("associating revs " . implode(',', $affectedRevs) . "\n");
             if (!$dryrun) {
                 $rev->addReferencesTo($affectedRevs);
             }
         } else {
             $this->output("no revisions followed up\n");
         }
     }
     $this->output("Done!\n");
 }
Esempio n. 20
0
 /**
  * Import a repository in the local database.
  * @param $repoName String Local name of repository
  * @param $start Int Revision to begin the import from (Default: null, means last stored revision);
  */
 private function importRepo($repoName, $start = null, $cacheSize = 0)
 {
     global $wgCodeReviewImportBatchSize;
     static $adaptorReported = false;
     $repo = CodeRepository::newFromName($repoName);
     if (!$repo) {
         $this->error("Invalid repo {$repoName}");
         return;
     }
     $svn = SubversionAdaptor::newFromRepo($repo->getPath());
     if (!$adaptorReported) {
         $this->output("Using " . get_class($svn) . " adaptor\n");
         $adaptorReported = true;
     }
     $this->output("IMPORT FROM REPO: {$repoName}\n");
     $lastStoredRev = $repo->getLastStoredRev();
     $this->output("Last stored revision: {$lastStoredRev}\n");
     $chunkSize = $wgCodeReviewImportBatchSize;
     $startTime = microtime(true);
     $revCount = 0;
     $start = $start !== null ? intval($start) : $lastStoredRev + 1;
     /*
      * FIXME: when importing only a part of a repository, the given path
      * might not have been created with revision 1. For example, the
      * mediawiki '/trunk/phase3' got created with r1284.
      */
     if ($start > $lastStoredRev + 1) {
         $this->error("Invalid starting point. r{$start} is beyond last stored revision: r" . ($lastStoredRev + 1));
         return;
     }
     $this->output("Syncing from r{$start} to HEAD...\n");
     if (!$svn->canConnect()) {
         $this->error("Unable to connect to repository.");
         return;
     }
     while (true) {
         $log = $svn->getLog('', $start, $start + $chunkSize - 1);
         if (empty($log)) {
             # Repo seems to give a blank when max rev is invalid, which
             # stops new revisions from being added. Try to avoid this
             # by trying less at a time from the last point.
             if ($chunkSize <= 1) {
                 break;
                 // done!
             }
             $chunkSize = max(1, floor($chunkSize / 4));
             continue;
         } else {
             $start += $chunkSize;
         }
         if (!is_array($log)) {
             var_dump($log);
             // @TODO: cleanup :)
             $this->error('Log entry is not an array! See content above.', true);
         }
         foreach ($log as $data) {
             $revCount++;
             $delta = microtime(true) - $startTime;
             $revSpeed = $revCount / $delta;
             $codeRev = CodeRevision::newFromSvn($repo, $data);
             $codeRev->save();
             $this->output(sprintf("%d %s %s (%0.1f revs/sec)\n", $codeRev->getId(), wfTimestamp(TS_DB, $codeRev->getTimestamp()), $codeRev->getAuthor(), $revSpeed));
         }
         wfWaitForSlaves();
     }
     if ($cacheSize !== 0) {
         $dbw = wfGetDB(DB_MASTER);
         $options = array('ORDER BY' => 'cr_id DESC');
         if ($cacheSize == "all") {
             $this->output("Pre-caching all uncached diffs...\n");
         } else {
             if ($cacheSize == 1) {
                 $this->output("Pre-caching the latest diff...\n");
             } else {
                 $this->output("Pre-caching the latest {$cacheSize} diffs...\n");
             }
             $options['LIMIT'] = $cacheSize;
         }
         // Get all rows for this repository that don't already have a diff filled in.
         // This is LIMITed according to the $cacheSize setting, above, so only the
         // rows that we plan to pre-cache are returned.
         // TODO: This was optimised in order to skip rows that already have a diff,
         //		 which is mostly what is required, but there may be situations where
         //		 you want to re-calculate diffs (e.g. if $wgCodeReviewMaxDiffPaths
         //		 changes).  If these situations arise we will either want to revert
         //		 this behaviour, or add a --force flag or something.
         $res = $dbw->select('code_rev', 'cr_id', array('cr_repo_id' => $repo->getId(), 'cr_diff IS NULL OR cr_diff = ""'), __METHOD__, $options);
         foreach ($res as $row) {
             $repo->getRevision($row->cr_id);
             $diff = $repo->getDiff($row->cr_id);
             // trigger caching
             $msg = "Diff r{$row->cr_id} ";
             if (is_integer($diff)) {
                 $msg .= "Skipped: " . CodeRepository::getDiffErrorMessage($diff);
             } else {
                 $msg .= "done";
             }
             $this->output($msg . "\n");
         }
     } else {
         $this->output("Pre-caching skipped.\n");
     }
     $this->output("Done!\n");
 }
Esempio n. 21
0
 /**
  * Like getRevIdString(), but if more than one repository is defined
  * on the wiki then it includes the repo name as a prefix to the revision ID
  * (separated with a period).
  * This ensures you get a unique reference, as the revision ID alone can be
  * confusing (e.g. in e-mails, page titles etc.).  If only one repository is
  * defined then this returns the same as getRevIdString() as there
  * is no ambiguity.
  *
  * @param $id string
  * @return string
  */
 public function getRevIdStringUnique($id)
 {
     $id = wfMsg('code-rev-id', $id);
     // If there is more than one repo, use the repo name as well.
     $repos = CodeRepository::getRepoList();
     if (count($repos) > 1) {
         $id = $this->getName() . "." . $id;
     }
     return $id;
 }
Esempio n. 22
0
 /**
  * Get a view object from a sub page path.
  * @return CodeView object or null if no valid action could be found
  */
 private function getViewFrom($subpage)
 {
     global $wgRequest;
     // Defines the classes to use for each view type.
     // The first class name is used if no additional parameters are provided.
     // The second, if defined, is used if there is an additional parameter.  If
     // there is no second class defined, then the first class is used in both
     // cases.
     static $paramClasses = array('tag' => array("CodeTagListView", "CodeRevisionTagView"), 'author' => array("CodeAuthorListView", "CodeRevisionAuthorView"), 'status' => array("CodeStatusListView", "CodeRevisionStatusView"), 'comments' => array("CodeCommentsListView"), 'statuschanges' => array("CodeStatusChangeListView"), 'releasenotes' => array("CodeReleaseNotes"), 'stats' => array("CodeRepoStatsView"));
     # Remove stray slashes
     $subpage = preg_replace('/\\/$/', '', $subpage);
     if ($subpage == '') {
         $view = new CodeRepoListView();
     } else {
         $params = explode('/', $subpage);
         $repo = CodeRepository::newFromName($params[0]);
         // If a repository was specified, but it does not exist, redirect to the
         // repository list with an appropriate message.
         if (!$repo) {
             $view = new CodeRepoListView();
             global $wgOut;
             $wgOut->addWikiMsg('code-repo-not-found', wfEscapeWikiText($params[0]));
             return $view;
         }
         switch (count($params)) {
             case 1:
                 $view = new CodeRevisionListView($repo);
                 break;
             case 2:
                 // drop through...
             // drop through...
             case 3:
                 if (isset($paramClasses[$params[1]])) {
                     $row = $paramClasses[$params[1]];
                     if (isset($params[2]) && isset($row[1])) {
                         $view = new $row[1]($repo, $params[2]);
                     } else {
                         $view = new $row[0]($repo);
                     }
                 } elseif ($wgRequest->wasPosted() && !$wgRequest->getCheck('wpPreview')) {
                     # This is not really a view, but we return it nonetheless.
                     # Add any tags, Set status, Adds comments
                     $view = new CodeRevisionCommitter($repo, $params[1]);
                 } elseif (empty($params[1])) {
                     $view = new CodeRevisionListView($repo);
                 } else {
                     $view = new CodeRevisionView($repo, $params[1]);
                 }
                 break;
             case 4:
                 if ($params[1] === 'author' && $params[3] === 'link') {
                     $view = new CodeRevisionAuthorLink($repo, $params[2]);
                     break;
                 } elseif ($params[1] === 'comments') {
                     $view = new CodeCommentsAuthorListView($repo, $params[3]);
                     break;
                 } elseif ($params[1] === 'statuschanges') {
                     $view = new CodeStatusChangeAuthorListView($repo, $params[3]);
                     break;
                 }
             default:
                 if ($params[2] == 'reply') {
                     $view = new CodeRevisionView($repo, $params[1], $params[3]);
                     break;
                 }
                 return null;
         }
     }
     return $view;
 }
Esempio n. 23
0
 /**
  * @
  * @param $page Title Special page title (with repo subpage)
  * @param $repo
  */
 public function __construct(Title $t, $repo)
 {
     $this->title = $t;
     $this->repoName = $repo;
     $this->repo = CodeRepository::newFromName($repo);
 }
Esempio n. 24
0
 function authorLink($author, $extraParams = array())
 {
     $repo = $this->mRepo->getName();
     $special = SpecialPage::getTitleFor('Code', "{$repo}/author/{$author}");
     return $this->skin->link($special, htmlspecialchars($author), array(), $extraParams);
 }