Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

BUGFIX: upgrade module to fit 3.0 api.

  • Loading branch information...
commit dd84574b8da528e87582297aad6179ec88488ec4 1 parent 1e28e82
@wilr wilr authored
View
3  README.md
@@ -7,7 +7,7 @@
## Requirements
-* SilverStripe 2.4
+* SilverStripe 3.0
## Summary
@@ -20,4 +20,3 @@ For more documentation on how to use the module please read /docs/Writing-Docume
(or via this in /dev/docs/sapphiredocs/Writing-Documentation in your webbrowser)
**Note** This module assumes you are using numeric values for your versions.
-
View
4 _config.php
@@ -11,7 +11,9 @@
}
if(!defined('DOCSVIEWER_DIR')) {
- define('DOCSVIEWER_DIR', array_pop(explode(DIRECTORY_SEPARATOR, DOCSVIEWER_PATH)));
+ $dir = explode(DIRECTORY_SEPARATOR, DOCSVIEWER_PATH);
+
+ define('DOCSVIEWER_DIR', array_pop($dir));
}
View
44 code/DocumentationSearch.php
@@ -44,7 +44,7 @@ class DocumentationSearch {
static $boost_by_path = array();
/**
- * @var DataObjectSet - Results
+ * @var ArrayList - Results
*/
private $results;
@@ -117,13 +117,13 @@ public function setOutputController($controller) {
/**
* Generate an array of every single documentation page installed on the system.
*
- * @return DataObjectSet
+ * @return ArrayList
*/
public static function get_all_documentation_pages() {
DocumentationService::load_automatic_registration();
$modules = DocumentationService::get_registered_entities();
- $output = new DataObjectSet();
+ $output = new ArrayList();
if($modules) {
foreach($modules as $module) {
@@ -245,8 +245,8 @@ public function getSearchResults($request) {
$data = array(
'Results' => null,
'Query' => null,
- 'Versions' => DBField::create('Text', implode(',', $this->versions)),
- 'Modules' => DBField::create('Text', implode(',', $this->modules)),
+ 'Versions' => DBField::create_field('Text', implode(',', $this->versions)),
+ 'Modules' => DBField::create_field('Text', implode(',', $this->modules)),
'Title' => _t('DocumentationSearch.SEARCHRESULTS', 'Search Results'),
'TotalResults' => null,
'TotalPages' => null,
@@ -254,9 +254,9 @@ public function getSearchResults($request) {
'StartResult' => null,
'PageLength' => $pageLength,
'EndResult' => null,
- 'PrevUrl' => DBField::create('Text', 'false'),
- 'NextUrl' => DBField::create('Text', 'false'),
- 'SearchPages' => new DataObjectSet()
+ 'PrevUrl' => DBField::create_field('Text', 'false'),
+ 'NextUrl' => DBField::create_field('Text', 'false'),
+ 'SearchPages' => new ArrayList()
);
$start = ($request->requestVar('start')) ? (int)$request->requestVar('start') : 0;
@@ -269,7 +269,7 @@ public function getSearchResults($request) {
if ($totalPages == 0) $totalPages = 1;
if ($currentPage > $totalPages) $currentPage = $totalPages;
- $results = new DataObjectSet();
+ $results = new ArrayList();
if($this->results) {
foreach($this->results as $k => $hit) {
@@ -280,13 +280,13 @@ public function getSearchResults($request) {
$content = $hit->content;
$obj = new ArrayData(array(
- 'Title' => DBField::create('Varchar', $doc->getFieldValue('Title')),
- 'BreadcrumbTitle' => DBField::create('HTMLText', $doc->getFieldValue('BreadcrumbTitle')),
- 'Link' => DBField::create('Varchar',$doc->getFieldValue('Link')),
- 'Language' => DBField::create('Varchar',$doc->getFieldValue('Language')),
- 'Version' => DBField::create('Varchar',$doc->getFieldValue('Version')),
- 'Entity' => DBField::create('Varchar', $doc->getFieldValue('Entity')),
- 'Content' => DBField::create('HTMLText', $content),
+ 'Title' => DBField::create_field('Varchar', $doc->getFieldValue('Title')),
+ 'BreadcrumbTitle' => DBField::create_field('HTMLText', $doc->getFieldValue('BreadcrumbTitle')),
+ 'Link' => DBField::create_field('Varchar',$doc->getFieldValue('Link')),
+ 'Language' => DBField::create_field('Varchar',$doc->getFieldValue('Language')),
+ 'Version' => DBField::create_field('Varchar',$doc->getFieldValue('Version')),
+ 'Entity' => DBField::create_field('Varchar', $doc->getFieldValue('Entity')),
+ 'Content' => DBField::create_field('HTMLText', $content),
'Score' => $hit->score,
'Number' => $k + 1,
'ID' => md5($doc->getFieldValue('Link'))
@@ -297,22 +297,22 @@ public function getSearchResults($request) {
}
$data['Results'] = $results;
- $data['Query'] = DBField::create('Text', $query);
- $data['TotalResults'] = DBField::create('Text', count($this->results));
- $data['TotalPages'] = DBField::create('Text', $totalPages);
- $data['ThisPage'] = DBField::create('Text', $currentPage);
+ $data['Query'] = DBField::create_field('Text', $query);
+ $data['TotalResults'] = DBField::create_field('Text', count($this->results));
+ $data['TotalPages'] = DBField::create_field('Text', $totalPages);
+ $data['ThisPage'] = DBField::create_field('Text', $currentPage);
$data['StartResult'] = $start + 1;
$data['EndResult'] = $start + count($results);
// Pagination links
if($currentPage > 1) {
- $data['PrevUrl'] = DBField::create('Text',
+ $data['PrevUrl'] = DBField::create_field('Text',
$this->buildQueryUrl(array('start' => ($currentPage - 2) * $pageLength))
);
}
if($currentPage < $totalPages) {
- $data['NextUrl'] = DBField::create('Text',
+ $data['NextUrl'] = DBField::create_field('Text',
$this->buildQueryUrl(array('start' => $currentPage * $pageLength))
);
}
View
4 code/DocumentationService.php
@@ -455,10 +455,10 @@ public static function get_extension($name) {
* @param string - lang to use
*
* @throws Exception
- * @return DataObjectSet
+ * @return ArrayList
*/
public static function get_pages_from_folder($entity, $relativePath = false, $recursive = true, $version = 'trunk', $lang = 'en') {
- $output = new DataObjectSet();
+ $output = new ArrayList();
$pages = array();
if(!$entity instanceof DocumentationEntity)
View
45 code/controllers/DocumentationViewer.php
@@ -76,7 +76,6 @@ function init() {
Requirements::javascript(DOCSVIEWER_DIR .'/javascript/DocumentationViewer.js');
Requirements::css(DOCSVIEWER_DIR .'/css/shSilverStripeDocs.css');
-
Requirements::css(DOCSVIEWER_DIR .'/css/DocumentationViewer.css');
}
@@ -128,7 +127,7 @@ public function handleAction($request) {
*
* @return SS_HTTPResponse
*/
- public function handleRequest(SS_HTTPRequest $request) {
+ public function handleRequest(SS_HTTPRequest $request, DataModel $model = null) {
// if we submitted a form, let that pass
if(!$request->isGET() || isset($_GET['action_results']))
return parent::handleRequest($request);
@@ -148,7 +147,7 @@ public function handleRequest(SS_HTTPRequest $request) {
if($firstParam) {
// allow assets
if($firstParam == "assets") {
- return parent::handleRequest($request);
+ return parent::handleRequest($request, $model);
}
// check for permalinks
@@ -199,7 +198,7 @@ public function handleRequest(SS_HTTPRequest $request) {
}
- return parent::handleRequest($request);
+ return parent::handleRequest($request, $model);
}
return $this->throw404();
@@ -297,7 +296,7 @@ function getLanguages() {
* the filesystem then they are loaded under the 'Current' namespace.
*
* @param String $entity name of {@link Entity} to limit it to eg sapphire
- * @return DataObjectSet
+ * @return ArrayList
*/
function getVersions($entity = false) {
if(!$entity) $entity = $this->entity;
@@ -306,7 +305,7 @@ function getVersions($entity = false) {
if(!$entity) return false;
$versions = $entity->getVersions();
- $output = new DataObjectSet();
+ $output = new ArrayList();
if($versions) {
$lang = $this->getLang();
@@ -336,7 +335,7 @@ function getVersions($entity = false) {
*/
function getEntities($version = false, $lang = false) {
$entities = DocumentationService::get_registered_entities($version, $lang);
- $output = new DataObjectSet();
+ $output = new ArrayList();
$currentEntity = $this->getEntity();
@@ -349,7 +348,7 @@ function getEntities($version = false, $lang = false) {
$content = false;
if($page = $entity->getIndexPage($version, $lang)) {
- $content = DBField::create('HTMLText', DocumentationParser::parse($page, $link));
+ $content = DBField::create_field('HTMLText', DocumentationParser::parse($page, $link));
}
$output->push(new ArrayData(array(
@@ -457,7 +456,7 @@ function getPage() {
*
* @todo this only handles 2 levels. Could make it recursive
*
- * @return false|DataObjectSet
+ * @return false|ArrayList
*/
function getEntityPages() {
if($entity = $this->getEntity()) {
@@ -493,7 +492,7 @@ function getEntityPages() {
* @param DocumentationEntity
* @param int Depth of page in the tree
*
- * @return DataObjectSet|false
+ * @return ArrayList|false
*/
private function _getEntityPagesNested(&$page, $entity, $level = 0) {
if(isset($this->Remaining[$level])) {
@@ -556,7 +555,7 @@ function getContent() {
$page = $this->getPage();
if($page) {
- return DBField::create("HTMLText", $page->getHTML($this->getVersion(), $this->getLang()));
+ return DBField::create_field("HTMLText", $page->getHTML($this->getVersion(), $this->getLang()));
}
// If no page found then we may want to get the listing of the folder.
@@ -594,14 +593,14 @@ function getContent() {
* Generate a list of breadcrumbs for the user. Based off the remaining params
* in the url
*
- * @return DataObjectSet
+ * @return ArrayList
*/
function getBreadcrumbs() {
if(!$this->Remaining) $this->Remaining = array();
$pages = array_merge(array($this->entity), $this->Remaining);
- $output = new DataObjectSet();
+ $output = new ArrayList();
if($pages) {
$path = array();
@@ -690,7 +689,7 @@ public function Link($path = false, $entity = false, $version = false, $lang = f
function LanguageForm() {
$langs = $this->getLanguages();
- $fields = new FieldSet(
+ $fields = new FieldList(
$dropdown = new DropdownField(
'LangCode',
_t('DocumentationViewer.LANGUAGE', 'Language'),
@@ -699,7 +698,7 @@ function LanguageForm() {
)
);
- $actions = new FieldSet(
+ $actions = new FieldList(
new FormAction('doLanguageForm', _t('DocumentationViewer.CHANGE', 'Change'))
);
@@ -749,13 +748,13 @@ function DocumentationSearchForm() {
if(!DocumentationSearch::enabled()) return false;
$q = ($q = $this->getSearchQuery()) ? $q->NoHTML() : "";
- $fields = new FieldSet(
+ $fields = new FieldList(
new TextField('Search', _t('DocumentationViewer.SEARCH', 'Search'), $q),
new HiddenField('Entities', '', implode(',', array_keys($this->getSearchedEntities()))),
new HiddenField('Versions', '', implode(',', $this->getSearchedVersions()))
);
- $actions = new FieldSet(
+ $actions = new FieldList(
new FormAction('results', 'Search')
);
@@ -824,7 +823,7 @@ function getSearchedVersions() {
*/
function getSearchQuery() {
if(isset($_REQUEST['Search'])) {
- return DBField::create('HTMLText', $_REQUEST['Search']);
+ return DBField::create_field('HTMLText', $_REQUEST['Search']);
}
}
@@ -867,7 +866,7 @@ function AdvancedSearchForm() {
$q = ($q = $this->getSearchQuery()) ? $q->NoHTML() : "";
// klude to take an array of objects down to a simple map
- $entities = new DataObjectSet($entities);
+ $entities = new ArrayList($entities);
$entities = $entities->map('Folder', 'Title');
// if we haven't gone any search limit then we're searching everything
@@ -877,7 +876,7 @@ function AdvancedSearchForm() {
$searchedVersions = $this->getSearchedVersions();
if(count($searchedVersions) < 1) $searchedVersions = $uniqueVersions;
- $fields = new FieldSet(
+ $fields = new FieldList(
new TextField('Search', _t('DocumentationViewer.KEYWORDS', 'Keywords'), $q),
new CheckboxSetField('Entities', _t('DocumentationViewer.MODULES', 'Modules'), $entities, $searchedEntities),
new CheckboxSetField('Versions', _t('DocumentationViewer.VERSIONS', 'Versions'),
@@ -885,7 +884,7 @@ function AdvancedSearchForm() {
)
);
- $actions = new FieldSet(
+ $actions = new FieldList(
new FormAction('results', _t('DocumentationViewer.SEARCH', 'Search'))
);
$required = new RequiredFields(array('Search'));
@@ -920,13 +919,13 @@ function VersionWarning() {
if($version == "trunk" || $compare > 0) {
return $this->customise(new ArrayData(array(
'FutureRelease' => true,
- 'StableVersion' => DBField::create('HTMLText', $stable)
+ 'StableVersion' => DBField::create_field('HTMLText', $stable)
)));
}
else {
return $this->customise(new ArrayData(array(
'OutdatedRelease' => true,
- 'StableVersion' => DBField::create('HTMLText', $stable)
+ 'StableVersion' => DBField::create_field('HTMLText', $stable)
)));
}
}
View
17 code/models/DocumentationPage.php
@@ -113,8 +113,9 @@ function getPath($defaultFile = false) {
}
/**
- * @param String - has to be plain text for open search compatibility.
- * @return String
+ * @param string - has to be plain text for open search compatibility.
+ *
+ * @return string
*/
function getBreadcrumbTitle($divider = ' - ') {
$pathParts = explode('/', $this->getRelativePath());
@@ -128,11 +129,11 @@ function getBreadcrumbTitle($divider = ' - ') {
}
/**
- * Returns the link for the web browser
+ * Returns the public accessible link for this page.
*
* @return string
*/
- function Link() {
+ function getLink() {
if($entity = $this->getEntity()) {
$link = Controller::join_links($entity->Link($this->getVersion(), $this->lang), $this->getRelativeLink());
@@ -194,7 +195,7 @@ function getTitle() {
/**
* Set a variable from the metadata field on this class
*
- * @param String key
+ * @param string key
* @param mixed value
*/
public function setMetaData($key, $value) {
@@ -231,7 +232,7 @@ function getMarkdown() {
$ext = $this->getExtension();
if(DocumentationService::is_valid_extension($ext)) {
- return file_get_contents($path);
+ return file_get_contents($path);
}
}
}
@@ -243,9 +244,9 @@ function getMarkdown() {
/**
* Parse a file (with a lang and a version).
*
- * @param String $baselink
+ * @param string $baselink
*
- * @return String
+ * @return string
*/
function getHTML($version, $lang = 'en') {
return DocumentationParser::parse($this, $this->entity->getRelativeLink($version, $lang));
View
8 tests/DocumentationPageTest.php
@@ -15,21 +15,21 @@ function testGetLink() {
$page->setEntity($entity);
// single layer
- $this->assertStringEndsWith('testmodule/en/test', $page->Link(), 'The page link should have no extension and have a language');
+ $this->assertStringEndsWith('testmodule/en/test', $page->Link, 'The page link should have no extension and have a language');
$folder = new DocumentationPage();
$folder->setRelativePath('sort');
$folder->setEntity($entity);
// folder, should have a trailing slash
- $this->assertStringEndsWith('testmodule/en/sort/', $folder->Link());
+ $this->assertStringEndsWith('testmodule/en/sort/', $folder->Link);
// second
$nested = new DocumentationPage();
$nested->setRelativePath('subfolder/subpage.md');
$nested->setEntity($entity);
- $this->assertStringEndsWith('testmodule/en/subfolder/subpage', $nested->Link());
+ $this->assertStringEndsWith('testmodule/en/subfolder/subpage', $nested->Link);
// test with version.
$entity = DocumentationService::register("versionlinks", DOCSVIEWER_PATH ."/tests/docs-v2.4/", '1');
@@ -40,7 +40,7 @@ function testGetLink() {
$page->setRelativePath('test.md');
$page->setEntity($entity);
$page->setVersion('1');
- $this->assertStringEndsWith('versionlinks/en/1/test', $page->Link());
+ $this->assertStringEndsWith('versionlinks/en/1/test', $page->Link);
}
View
1  tests/DocumentationViewerTest.php
@@ -133,7 +133,6 @@ function testGetEntityPages() {
}
$links = $pages->column('Link');
-
$this->assertStringEndsWith('DocumentationViewerTests/en/2.3/sort/', $links[0]);
$this->assertStringEndsWith('DocumentationViewerTests/en/2.3/subfolder/', $links[1]);
$this->assertStringEndsWith('DocumentationViewerTests/en/2.3/test', $links[2]);
Please sign in to comment.
Something went wrong with that request. Please try again.