From f95913ec47c9dc935f5f30e702072f71f294267b Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 11 Jul 2011 08:54:22 -0700 Subject: [PATCH] Phriction basics Summary: Basically a copy/paste of parts of D636, but with two changes: - Fully separate the index table ("document") from the content table ("content"). I think this will be a cleaner solution in the long run. - Build slugs into the document structure. This doesn't do anything useful, it just normalizes slugs and lays some groundwork. Test Plan: - Visited various /w/ pages and saw them normalize correctly. - Verified the DAO works by inserting dummy rows. Reviewed By: codeblock Reviewers: hsb, codeblock, jungejason, aran, tuomaspelkonen CC: aran, codeblock, epriestley Differential Revision: 638 --- resources/sql/patches/060.phriction.sql | 12 ++++ src/__phutil_library_map__.php | 8 +++ ...AphrontDefaultApplicationConfiguration.php | 5 ++ .../constants/PhabricatorPHIDConstants.php | 1 + .../controller/base/PhrictionController.php | 35 ++++++++++ .../phriction/controller/base/__init__.php | 15 +++++ .../document/PhrictionDocumentController.php | 47 +++++++++++++ .../controller/document/__init__.php | 17 +++++ .../phriction/storage/base/PhrictionDAO.php | 25 +++++++ .../phriction/storage/base/__init__.php | 12 ++++ .../storage/document/PhrictionDocument.php | 67 +++++++++++++++++++ .../phriction/storage/document/__init__.php | 14 ++++ 12 files changed, 258 insertions(+) create mode 100644 resources/sql/patches/060.phriction.sql create mode 100644 src/applications/phriction/controller/base/PhrictionController.php create mode 100644 src/applications/phriction/controller/base/__init__.php create mode 100644 src/applications/phriction/controller/document/PhrictionDocumentController.php create mode 100644 src/applications/phriction/controller/document/__init__.php create mode 100644 src/applications/phriction/storage/base/PhrictionDAO.php create mode 100644 src/applications/phriction/storage/base/__init__.php create mode 100644 src/applications/phriction/storage/document/PhrictionDocument.php create mode 100644 src/applications/phriction/storage/document/__init__.php diff --git a/resources/sql/patches/060.phriction.sql b/resources/sql/patches/060.phriction.sql new file mode 100644 index 0000000000..d09752e840 --- /dev/null +++ b/resources/sql/patches/060.phriction.sql @@ -0,0 +1,12 @@ +CREATE DATABASE phabricator_phriction; + +CREATE TABLE phabricator_phriction.phriction_document ( + id INT UNSIGNED NOT NULL, + phid VARCHAR(64) BINARY NOT NULL, + UNIQUE KEY (phid), + slug VARCHAR(512) NOT NULL, + UNIQUE KEY (slug), + depth INT UNSIGNED NOT NULL, + UNIQUE KEY (depth, slug), + contentID INT UNSIGNED NOT NULL +) ENGINE=InnoDB; \ No newline at end of file diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 6f1284e26f..976c022083 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -578,6 +578,10 @@ phutil_register_library_map(array( 'PhabricatorXHProfProfileController' => 'applications/xhprof/controller/profile', 'PhabricatorXHProfProfileSymbolView' => 'applications/xhprof/view/symbol', 'PhabricatorXHProfProfileTopLevelView' => 'applications/xhprof/view/toplevel', + 'PhrictionController' => 'applications/phriction/controller/base', + 'PhrictionDAO' => 'applications/phriction/storage/base', + 'PhrictionDocument' => 'applications/phriction/storage/document', + 'PhrictionDocumentController' => 'applications/phriction/controller/document', ), 'function' => array( @@ -1066,6 +1070,10 @@ phutil_register_library_map(array( 'PhabricatorXHProfProfileController' => 'PhabricatorXHProfController', 'PhabricatorXHProfProfileSymbolView' => 'AphrontView', 'PhabricatorXHProfProfileTopLevelView' => 'AphrontView', + 'PhrictionController' => 'PhabricatorController', + 'PhrictionDAO' => 'PhabricatorLiskDAO', + 'PhrictionDocument' => 'PhrictionDAO', + 'PhrictionDocumentController' => 'PhrictionController', ), 'requires_interface' => array( diff --git a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php index 7bc7808c14..b2c8d29ac3 100644 --- a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php +++ b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php @@ -339,6 +339,11 @@ class AphrontDefaultApplicationConfiguration '(?:view/(?P\w+)/)?$' => 'PhabricatorSlowvoteListController', 'create/' => 'PhabricatorSlowvoteCreateController', ), + + // Match "/w/" with slug "/". + '/w(?P/)$' => 'PhrictionDocumentController', + // Match "/w/x/y/z/" with slug "x/y/z/". + '/w/(?P.+/)$' => 'PhrictionDocumentController', ); } diff --git a/src/applications/phid/constants/PhabricatorPHIDConstants.php b/src/applications/phid/constants/PhabricatorPHIDConstants.php index 7f0d237a54..2b603059ff 100644 --- a/src/applications/phid/constants/PhabricatorPHIDConstants.php +++ b/src/applications/phid/constants/PhabricatorPHIDConstants.php @@ -32,5 +32,6 @@ final class PhabricatorPHIDConstants { const PHID_TYPE_PSTE = 'PSTE'; const PHID_TYPE_STRY = 'STRY'; const PHID_TYPE_POLL = 'POLL'; + const PHID_TYPE_WIKI = 'WIKI'; } diff --git a/src/applications/phriction/controller/base/PhrictionController.php b/src/applications/phriction/controller/base/PhrictionController.php new file mode 100644 index 0000000000..6f2761d507 --- /dev/null +++ b/src/applications/phriction/controller/base/PhrictionController.php @@ -0,0 +1,35 @@ +buildStandardPageView(); + + $page->setApplicationName('Phriction'); + $page->setBaseURI('/phriction/'); + $page->setTitle(idx($data, 'title')); + $page->setGlyph("\xE2\x9A\xA1"); + + $page->appendChild($view); + + $response = new AphrontWebpageResponse(); + return $response->setContent($page->render()); + } +} diff --git a/src/applications/phriction/controller/base/__init__.php b/src/applications/phriction/controller/base/__init__.php new file mode 100644 index 0000000000..40bf3fcdf8 --- /dev/null +++ b/src/applications/phriction/controller/base/__init__.php @@ -0,0 +1,15 @@ +slug = $data['slug']; + } + + public function processRequest() { + + $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); + } + + $slug_info = 'Phriction page for '.phutil_escape_html($this->slug); + + return $this->buildStandardPageResponse( + $slug_info, + array( + 'title' => 'Phriction', + )); + + } + +} diff --git a/src/applications/phriction/controller/document/__init__.php b/src/applications/phriction/controller/document/__init__.php new file mode 100644 index 0000000000..3bccce34b6 --- /dev/null +++ b/src/applications/phriction/controller/document/__init__.php @@ -0,0 +1,17 @@ + true, + self::CONFIG_TIMESTAMPS => false, + ) + parent::getConfiguration(); + } + + public function generatePHID() { + return PhabricatorPHID::generateNewPHID( + PhabricatorPHIDConstants::PHID_TYPE_WIKI); + } + + public static function getSlugURI($slug) { + if ($slug == '/') { + return '/w/'; + } else { + return '/w/'.$slug; + } + } + + public static function normalizeSlug($slug) { + + // TODO: We need to deal with unicode at some point, this is just a very + // basic proof-of-concept implementation. + + $slug = strtolower($slug); + $slug = preg_replace('@/+@', '/', $slug); + $slug = trim($slug, '/'); + $slug = preg_replace('@[^a-z0-9/]+@', '_', $slug); + $slug = trim($slug, '_'); + + return $slug.'/'; + } + + public function setSlug($slug) { + $this->slug = self::normalizeSlug($slug); + $this->depth = substr_count($this->slug, '/'); + return $this; + } + +} diff --git a/src/applications/phriction/storage/document/__init__.php b/src/applications/phriction/storage/document/__init__.php new file mode 100644 index 0000000000..bf16f121cd --- /dev/null +++ b/src/applications/phriction/storage/document/__init__.php @@ -0,0 +1,14 @@ +