1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-18 21:02:41 +01:00

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
This commit is contained in:
epriestley 2011-07-11 08:54:22 -07:00
parent 467308dd12
commit f95913ec47
12 changed files with 258 additions and 0 deletions

View file

@ -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;

View file

@ -578,6 +578,10 @@ phutil_register_library_map(array(
'PhabricatorXHProfProfileController' => 'applications/xhprof/controller/profile', 'PhabricatorXHProfProfileController' => 'applications/xhprof/controller/profile',
'PhabricatorXHProfProfileSymbolView' => 'applications/xhprof/view/symbol', 'PhabricatorXHProfProfileSymbolView' => 'applications/xhprof/view/symbol',
'PhabricatorXHProfProfileTopLevelView' => 'applications/xhprof/view/toplevel', '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' => 'function' =>
array( array(
@ -1066,6 +1070,10 @@ phutil_register_library_map(array(
'PhabricatorXHProfProfileController' => 'PhabricatorXHProfController', 'PhabricatorXHProfProfileController' => 'PhabricatorXHProfController',
'PhabricatorXHProfProfileSymbolView' => 'AphrontView', 'PhabricatorXHProfProfileSymbolView' => 'AphrontView',
'PhabricatorXHProfProfileTopLevelView' => 'AphrontView', 'PhabricatorXHProfProfileTopLevelView' => 'AphrontView',
'PhrictionController' => 'PhabricatorController',
'PhrictionDAO' => 'PhabricatorLiskDAO',
'PhrictionDocument' => 'PhrictionDAO',
'PhrictionDocumentController' => 'PhrictionController',
), ),
'requires_interface' => 'requires_interface' =>
array( array(

View file

@ -339,6 +339,11 @@ class AphrontDefaultApplicationConfiguration
'(?:view/(?P<view>\w+)/)?$' => 'PhabricatorSlowvoteListController', '(?:view/(?P<view>\w+)/)?$' => 'PhabricatorSlowvoteListController',
'create/' => 'PhabricatorSlowvoteCreateController', 'create/' => 'PhabricatorSlowvoteCreateController',
), ),
// Match "/w/" with slug "/".
'/w(?P<slug>/)$' => 'PhrictionDocumentController',
// Match "/w/x/y/z/" with slug "x/y/z/".
'/w/(?P<slug>.+/)$' => 'PhrictionDocumentController',
); );
} }

View file

@ -32,5 +32,6 @@ final class PhabricatorPHIDConstants {
const PHID_TYPE_PSTE = 'PSTE'; const PHID_TYPE_PSTE = 'PSTE';
const PHID_TYPE_STRY = 'STRY'; const PHID_TYPE_STRY = 'STRY';
const PHID_TYPE_POLL = 'POLL'; const PHID_TYPE_POLL = 'POLL';
const PHID_TYPE_WIKI = 'WIKI';
} }

View file

@ -0,0 +1,35 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
abstract class PhrictionController extends PhabricatorController {
public function buildStandardPageResponse($view, array $data) {
$page = $this->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());
}
}

View file

@ -0,0 +1,15 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'aphront/response/webpage');
phutil_require_module('phabricator', 'applications/base/controller/base');
phutil_require_module('phutil', 'utils');
phutil_require_source('PhrictionController.php');

View file

@ -0,0 +1,47 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class PhrictionDocumentController
extends PhrictionController {
private $slug;
public function willProcessRequest(array $data) {
$this->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',
));
}
}

View file

@ -0,0 +1,17 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'aphront/response/redirect');
phutil_require_module('phabricator', 'applications/phriction/controller/base');
phutil_require_module('phabricator', 'applications/phriction/storage/document');
phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils');
phutil_require_source('PhrictionDocumentController.php');

View file

@ -0,0 +1,25 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
abstract class PhrictionDAO extends PhabricatorLiskDAO {
public function getApplicationName() {
return 'phriction';
}
}

View file

@ -0,0 +1,12 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'applications/base/storage/lisk');
phutil_require_source('PhrictionDAO.php');

View file

@ -0,0 +1,67 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class PhrictionDocument extends PhrictionDAO {
protected $id;
protected $phid;
protected $slug;
protected $depth;
protected $contentID;
public function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => 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;
}
}

View file

@ -0,0 +1,14 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'applications/phid/constants');
phutil_require_module('phabricator', 'applications/phid/storage/phid');
phutil_require_module('phabricator', 'applications/phriction/storage/base');
phutil_require_source('PhrictionDocument.php');