public function render() { $drequest = $this->getDiffusionRequest(); $commit = $drequest->getCommit(); $callsign = $drequest->getRepository()->getCallsign(); if ($commit) { $commit = "r{$callsign}{$commit}"; } else { $commit = 'HEAD'; } switch ($this->browseQuery->getReasonForEmptyResultSet()) { case DiffusionBrowseQuery::REASON_IS_NONEXISTENT: $title = 'Path Does Not Exist'; // TODO: Under git, this error message should be more specific. It // may exist on some other branch. $body = "This path does not exist anywhere."; $severity = AphrontErrorView::SEVERITY_ERROR; break; case DiffusionBrowseQuery::REASON_IS_EMPTY: $title = 'Empty Directory'; $body = "This path was an empty directory at {$commit}.\n"; $severity = AphrontErrorView::SEVERITY_NOTICE; break; case DiffusionBrowseQuery::REASON_IS_DELETED: $deleted = $this->browseQuery->getDeletedAtCommit(); $existed = $this->browseQuery->getExistedAtCommit(); $deleted = self::linkCommit($drequest->getRepository(), $deleted); $browse = $this->linkBrowse($drequest->getPath(), array('text' => 'existed', 'commit' => $existed, 'params' => array('view' => $this->view))); $existed = "r{$callsign}{$existed}"; $title = 'Path Was Deleted'; $body = "This path does not exist at {$commit}. It was deleted in " . "{$deleted} and last {$browse} at {$existed}."; $severity = AphrontErrorView::SEVERITY_WARNING; break; case DiffusionBrowseQuery::REASON_IS_UNTRACKED_PARENT: $subdir = $drequest->getRepository()->getDetail('svn-subpath'); $title = 'Directory Not Tracked'; $body = "This repository is configured to track only one subdirectory " . "of the entire repository ('" . phutil_escape_html($subdir) . "'), " . "but you aren't looking at something in that subdirectory, so no " . "information is available."; $severity = AphrontErrorView::SEVERITY_WARNING; break; default: throw new Exception("Unknown failure reason!"); } $error_view = new AphrontErrorView(); $error_view->setSeverity($severity); $error_view->setTitle($title); $error_view->appendChild('<p>' . $body . '</p>'); return $error_view->render(); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $slug = PhrictionDocument::normalizeSlug($this->slug); if ($slug != $this->slug) { $uri = PhrictionDocument::getSlugURI($slug); // Canonicalize pages to their one true URI. return id(new AphrontRedirectResponse())->setURI($uri); } require_celerity_resource('phriction-document-css'); $document = id(new PhrictionDocument())->loadOneWhere('slug = %s', $slug); $breadcrumbs = $this->renderBreadcrumbs($slug); $version_note = null; if (!$document) { $create_uri = '/phriction/edit/?slug=' . $slug; $page_content = '<div class="phriction-content">' . '<em>No content here!</em><br />' . 'No document found at <tt>' . phutil_escape_html($slug) . '</tt>. ' . 'You can <strong>' . phutil_render_tag('a', array('href' => $create_uri), 'create a new document') . '</strong>.' . '</div>'; $page_title = 'Page Not Found'; $button = phutil_render_tag('a', array('href' => $create_uri, 'class' => 'green button'), 'Create Page'); $buttons = $button; } else { $version = $request->getInt('v'); if ($version) { $content = id(new PhrictionContent())->loadOneWhere('documentID = %d AND version = %d', $document->getID(), $version); if (!$content) { return new Aphront404Response(); } if ($content->getID() != $document->getContentID()) { $version_note = new AphrontErrorView(); $version_note->setSeverity(AphrontErrorView::SEVERITY_NOTICE); $version_note->setTitle('Older Version'); $version_note->appendChild('You are viewing an older version of this document, as it ' . 'appeared on ' . phabricator_datetime($content->getDateCreated(), $user) . '.'); } } else { $content = id(new PhrictionContent())->load($document->getContentID()); } $page_title = $content->getTitle(); $project_phid = null; if (PhrictionDocument::isProjectSlug($slug)) { $project = id(new PhabricatorProject())->loadOneWhere('phrictionSlug = %s', PhrictionDocument::getProjectSlugIdentifier($slug)); $project_phid = $project->getPHID(); } $phids = array_filter(array($content->getAuthorPHID(), $project_phid)); $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); $age = time() - $content->getDateCreated(); $age = floor($age / (60 * 60 * 24)); if ($age < 1) { $when = 'today'; } else { if ($age == 1) { $when = 'yesterday'; } else { $when = "{$age} days ago"; } } $project_info = null; if ($project_phid) { $project_info = '<br />This document is about the project ' . $handles[$project_phid]->renderLink() . '.'; } $byline = '<div class="phriction-byline">' . "Last updated {$when} by " . $handles[$content->getAuthorPHID()]->renderLink() . '.' . $project_info . '</div>'; $doc_status = $document->getStatus(); if ($doc_status == PhrictionDocumentStatus::STATUS_EXISTS) { $core_content = $content->renderContent(); } else { if ($doc_status == PhrictionDocumentStatus::STATUS_DELETED) { $notice = new AphrontErrorView(); $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE); $notice->setTitle('Document Deleted'); $notice->appendChild('This document has been deleted. You can edit it to put new content ' . 'here, or use history to revert to an earlier version.'); $core_content = $notice->render(); } else { throw new Exception("Unknown document status '{$doc_status}'!"); } } $page_content = '<div class="phriction-content">' . $byline . $core_content . '</div>'; $edit_button = phutil_render_tag('a', array('href' => '/phriction/edit/' . $document->getID() . '/', 'class' => 'button'), 'Edit Document'); $history_button = phutil_render_tag('a', array('href' => PhrictionDocument::getSlugURI($slug, 'history'), 'class' => 'button grey'), 'View History'); // these float right so history_button which is right most goes first $buttons = $history_button . $edit_button; } if ($version_note) { $version_note = $version_note->render(); } $children = $this->renderChildren($slug); $page = '<div class="phriction-header">' . $buttons . '<h1>' . phutil_escape_html($page_title) . '</h1>' . $breadcrumbs . '</div>' . $version_note . $page_content . $children; return $this->buildStandardPageResponse($page, array('title' => 'Phriction - ' . $page_title)); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $slug = PhabricatorSlug::normalize($this->slug); if ($slug != $this->slug) { $uri = PhrictionDocument::getSlugURI($slug); // Canonicalize pages to their one true URI. return id(new AphrontRedirectResponse())->setURI($uri); } require_celerity_resource('phriction-document-css'); $document = id(new PhrictionDocumentQuery())->setViewer($user)->withSlugs(array($slug))->executeOne(); $version_note = null; $core_content = ''; $move_notice = ''; $properties = null; if (!$document) { $document = new PhrictionDocument(); if (PhrictionDocument::isProjectSlug($slug)) { $project = id(new PhabricatorProjectQuery())->setViewer($user)->withPhrictionSlugs(array(PhrictionDocument::getProjectSlugIdentifier($slug)))->executeOne(); if (!$project) { return new Aphront404Response(); } } $create_uri = '/phriction/edit/?slug=' . $slug; $notice = new AphrontErrorView(); $notice->setSeverity(AphrontErrorView::SEVERITY_NODATA); $notice->setTitle(pht('No content here!')); $notice->appendChild(pht('No document found at %s. You can <strong>' . '<a href="%s">create a new document here</a></strong>.', phutil_tag('tt', array(), $slug), $create_uri)); $core_content = $notice; $page_title = pht('Page Not Found'); } else { $version = $request->getInt('v'); if ($version) { $content = id(new PhrictionContent())->loadOneWhere('documentID = %d AND version = %d', $document->getID(), $version); if (!$content) { return new Aphront404Response(); } if ($content->getID() != $document->getContentID()) { $vdate = phabricator_datetime($content->getDateCreated(), $user); $version_note = new AphrontErrorView(); $version_note->setSeverity(AphrontErrorView::SEVERITY_NOTICE); $version_note->appendChild(pht('You are viewing an older version of this document, as it ' . 'appeared on %s.', $vdate)); } } else { $content = id(new PhrictionContent())->load($document->getContentID()); } $page_title = $content->getTitle(); $properties = $this->buildPropertyListView($document, $content, $slug); $doc_status = $document->getStatus(); $current_status = $content->getChangeType(); if ($current_status == PhrictionChangeType::CHANGE_EDIT || $current_status == PhrictionChangeType::CHANGE_MOVE_HERE) { $core_content = $content->renderContent($user); } else { if ($current_status == PhrictionChangeType::CHANGE_DELETE) { $notice = new AphrontErrorView(); $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE); $notice->setTitle(pht('Document Deleted')); $notice->appendChild(pht('This document has been deleted. You can edit it to put new ' . 'content here, or use history to revert to an earlier version.')); $core_content = $notice->render(); } else { if ($current_status == PhrictionChangeType::CHANGE_STUB) { $notice = new AphrontErrorView(); $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE); $notice->setTitle(pht('Empty Document')); $notice->appendChild(pht('This document is empty. You can edit it to put some proper ' . 'content here.')); $core_content = $notice->render(); } else { if ($current_status == PhrictionChangeType::CHANGE_MOVE_AWAY) { $new_doc_id = $content->getChangeRef(); $slug_uri = null; // If the new document exists and the viewer can see it, provide a link // to it. Otherwise, render a generic message. $new_docs = id(new PhrictionDocumentQuery())->setViewer($user)->withIDs(array($new_doc_id))->execute(); if ($new_docs) { $new_doc = head($new_docs); $slug_uri = PhrictionDocument::getSlugURI($new_doc->getSlug()); } $notice = id(new AphrontErrorView())->setSeverity(AphrontErrorView::SEVERITY_NOTICE); if ($slug_uri) { $notice->appendChild(phutil_tag('p', array(), pht('This document has been moved to %s. You can edit it to put ' . 'new content here, or use history to revert to an earlier ' . 'version.', phutil_tag('a', array('href' => $slug_uri), $slug_uri)))); } else { $notice->appendChild(phutil_tag('p', array(), pht('This document has been moved. You can edit it to put new ' . 'contne here, or use history to revert to an earlier ' . 'version.'))); } $core_content = $notice->render(); } else { throw new Exception("Unknown document status '{$doc_status}'!"); } } } } $move_notice = null; if ($current_status == PhrictionChangeType::CHANGE_MOVE_HERE) { $from_doc_id = $content->getChangeRef(); $slug_uri = null; // If the old document exists and is visible, provide a link to it. $from_docs = id(new PhrictionDocumentQuery())->setViewer($user)->withIDs(array($from_doc_id))->execute(); if ($from_docs) { $from_doc = head($from_docs); $slug_uri = PhrictionDocument::getSlugURI($from_doc->getSlug()); } $move_notice = id(new AphrontErrorView())->setSeverity(AphrontErrorView::SEVERITY_NOTICE); if ($slug_uri) { $move_notice->appendChild(pht('This document was moved from %s.', phutil_tag('a', array('href' => $slug_uri), $slug_uri))); } else { // Render this for consistency, even though it's a bit silly. $move_notice->appendChild(pht('This document was moved from elsewhere.')); } } } $children = $this->renderDocumentChildren($slug); $actions = $this->buildActionView($user, $document); $crumbs = $this->buildApplicationCrumbs(); $crumbs->setActionList($actions); $crumb_views = $this->renderBreadcrumbs($slug); foreach ($crumb_views as $view) { $crumbs->addCrumb($view); } $header = id(new PHUIHeaderView())->setHeader($page_title); $prop_list = null; if ($properties) { $prop_list = new PHUIPropertyGroupView(); $prop_list->addPropertyList($properties); } $page_content = id(new PHUIDocumentView())->setOffset(true)->setFontKit(PHUIDocumentView::FONT_SOURCE_SANS)->setHeader($header)->appendChild(array($actions, $prop_list, $version_note, $move_notice, $core_content)); $core_page = phutil_tag('div', array('class' => 'phriction-offset'), array($page_content, $children)); return $this->buildApplicationPage(array($crumbs->render(), $core_page), array('pageObjects' => array($document->getPHID()), 'title' => $page_title)); }