doc: Use `chapterId' instead of `chapterTitle' in URLs
Manually given chapter IDs are meant to not change while a chapter's title could change. refs #4820
This commit is contained in:
parent
f9e8ad3d0b
commit
289aed8420
|
@ -19,18 +19,18 @@ class Doc_IcingawebController extends DocController
|
|||
/**
|
||||
* View a chapter of Icinga Web 2's documentation
|
||||
*
|
||||
* @throws Zend_Controller_Action_Exception
|
||||
* @throws Zend_Controller_Action_Exception If the required parameter 'chapterId' is missing
|
||||
*/
|
||||
public function chapterAction()
|
||||
{
|
||||
$chapterTitle = $this->getParam('chapterTitle');
|
||||
if ($chapterTitle === null) {
|
||||
$chapterId = $this->getParam('chapterId');
|
||||
if ($chapterId === null) {
|
||||
throw new Zend_Controller_Action_Exception(
|
||||
$this->translate('Missing parameter \'chapterTitle\''),
|
||||
$this->translate('Missing parameter \'chapterId\''),
|
||||
404
|
||||
);
|
||||
}
|
||||
$this->renderChapter(Icinga::app()->getApplicationDir('/../doc'), $chapterTitle, 'doc/icingaweb/chapter');
|
||||
$this->renderChapter(Icinga::app()->getApplicationDir('/../doc'), $chapterId, 'doc/icingaweb/chapter');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -82,7 +82,7 @@ class Doc_ModuleController extends DocController
|
|||
/**
|
||||
* View a chapter of a module's documentation
|
||||
*
|
||||
* @throws Zend_Controller_Action_Exception If the required parameter 'chapterTitle' is missing or if an error in
|
||||
* @throws Zend_Controller_Action_Exception If the required parameter 'chapterId' is missing or if an error in
|
||||
* the documentation module's library occurs
|
||||
* @see assertModuleEnabled()
|
||||
*/
|
||||
|
@ -90,10 +90,10 @@ class Doc_ModuleController extends DocController
|
|||
{
|
||||
$moduleName = $this->getParam('moduleName');
|
||||
$this->assertModuleEnabled($moduleName);
|
||||
$chapterTitle = $this->getParam('chapterTitle');
|
||||
if ($chapterTitle === null) {
|
||||
$chapterId = $this->getParam('chapterId');
|
||||
if ($chapterId === null) {
|
||||
throw new Zend_Controller_Action_Exception(
|
||||
$this->translate('Missing parameter \'chapterTitle\''),
|
||||
$this->translate('Missing parameter \'chapterId\''),
|
||||
404
|
||||
);
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ class Doc_ModuleController extends DocController
|
|||
try {
|
||||
$this->renderChapter(
|
||||
$moduleManager->getModuleDir($moduleName, '/doc'),
|
||||
$chapterTitle,
|
||||
$chapterId,
|
||||
'doc/module/chapter',
|
||||
array('moduleName' => $moduleName)
|
||||
);
|
||||
|
|
|
@ -12,16 +12,16 @@ class DocController extends ModuleActionController
|
|||
* Render a chapter
|
||||
*
|
||||
* @param string $path Path to the documentation
|
||||
* @param string $chapterTitle Title of the chapter
|
||||
* @param string $chapterId ID of the chapter
|
||||
* @param string $url
|
||||
* @param array $urlParams
|
||||
*/
|
||||
protected function renderChapter($path, $chapterTitle, $url, array $urlParams = array())
|
||||
protected function renderChapter($path, $chapterId, $url, array $urlParams = array())
|
||||
{
|
||||
$parser = new DocParser($path);
|
||||
$this->view->sectionRenderer = new SectionRenderer(
|
||||
$parser->getDocTree(),
|
||||
SectionRenderer::decodeUrlParam($chapterTitle),
|
||||
SectionRenderer::decodeUrlParam($chapterId),
|
||||
$url,
|
||||
$urlParams
|
||||
);
|
||||
|
|
|
@ -148,12 +148,12 @@ class DocParser
|
|||
$nofollow = false;
|
||||
}
|
||||
if ($stack->isEmpty()) {
|
||||
$chapterTitle = $title;
|
||||
$section = new Section($id, $title, $level, $nofollow, $chapterTitle);
|
||||
$chapterId = $id;
|
||||
$section = new Section($id, $title, $level, $nofollow, $chapterId);
|
||||
$tree->addRoot($section);
|
||||
} else {
|
||||
$chapterTitle = $stack->bottom()->getTitle();
|
||||
$section = new Section($id, $title, $level, $nofollow, $chapterTitle);
|
||||
$chapterId = $stack->bottom()->getId();
|
||||
$section = new Section($id, $title, $level, $nofollow, $chapterId);
|
||||
$tree->addChild($section, $stack->top());
|
||||
}
|
||||
$stack->push($section);
|
||||
|
|
|
@ -40,11 +40,11 @@ class Section implements Identifiable
|
|||
protected $nofollow;
|
||||
|
||||
/**
|
||||
* The title of the chapter the section is part of
|
||||
* The ID of the chapter the section is part of
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $chapterTitle;
|
||||
protected $chapterId;
|
||||
|
||||
/**
|
||||
* The content of the section
|
||||
|
@ -60,15 +60,15 @@ class Section implements Identifiable
|
|||
* @param string $title The title of the section
|
||||
* @param int $level The header level
|
||||
* @param bool $nofollow Whether to instruct search engines to not index the link to the section
|
||||
* @param string $chapterTitle The title of the chapter the section is part of
|
||||
* @param string $chapterId The ID of the chapter the section is part of
|
||||
*/
|
||||
public function __construct($id, $title, $level, $nofollow, $chapterTitle)
|
||||
public function __construct($id, $title, $level, $nofollow, $chapterId)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->title = $title;
|
||||
$this->level = $level;
|
||||
$this->nofollow = $nofollow;
|
||||
$this->chapterTitle= $chapterTitle;
|
||||
$this->chapterId= $chapterId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,13 +112,13 @@ class Section implements Identifiable
|
|||
}
|
||||
|
||||
/**
|
||||
* The title of the chapter the section is part of
|
||||
* The ID of the chapter the section is part of
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getChapterTitle()
|
||||
public function getChapterId()
|
||||
{
|
||||
return $this->chapterTitle;
|
||||
return $this->chapterId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,22 +14,22 @@ use Icinga\Data\Tree\NodeInterface;
|
|||
class SectionFilterIterator extends RecursiveFilterIterator implements Countable
|
||||
{
|
||||
/**
|
||||
* The chapter title to filter for
|
||||
* The chapter ID to filter for
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $chapterTitle;
|
||||
protected $chapterId;
|
||||
|
||||
/**
|
||||
* Create a new SectionFilterIterator
|
||||
*
|
||||
* @param NodeInterface $node Node
|
||||
* @param string $chapterTitle The chapter title to filter for
|
||||
* @param string $chapterId The chapter ID to filter for
|
||||
*/
|
||||
public function __construct(NodeInterface $node, $chapterTitle)
|
||||
public function __construct(NodeInterface $node, $chapterId)
|
||||
{
|
||||
parent::__construct($node);
|
||||
$this->chapterTitle = $chapterTitle;
|
||||
$this->chapterId = $chapterId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -42,7 +42,7 @@ class SectionFilterIterator extends RecursiveFilterIterator implements Countable
|
|||
{
|
||||
$section = $this->getInnerIterator()->current()->getValue();
|
||||
/* @var $section \Icinga\Module\Doc\Section */
|
||||
if ($section->getChapterTitle() === $this->chapterTitle) {
|
||||
if ($section->getChapterId() === $this->chapterId) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -54,7 +54,7 @@ class SectionFilterIterator extends RecursiveFilterIterator implements Countable
|
|||
*/
|
||||
public function getChildren()
|
||||
{
|
||||
return new static($this->getInnerIterator()->getChildren(), $this->chapterTitle);
|
||||
return new static($this->getInnerIterator()->getChildren(), $this->chapterId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -57,7 +57,7 @@ class Callback
|
|||
array_merge(
|
||||
$this->urlParams,
|
||||
array(
|
||||
'chapterTitle' => SectionRenderer::encodeUrlParam($section->getChapterTitle())
|
||||
'chapterId' => SectionRenderer::encodeUrlParam($section->getChapterId())
|
||||
)
|
||||
),
|
||||
$this->url,
|
||||
|
@ -119,19 +119,19 @@ class SectionRenderer extends Renderer
|
|||
* Create a new section renderer
|
||||
*
|
||||
* @param DocTree $docTree The documentation tree
|
||||
* @param string|null $chapterTitle If not null, the chapter title to filter for
|
||||
* @param string|null $chapterId If not null, the chapter ID to filter for
|
||||
* @param string $url The URL to replace links with
|
||||
* @param array $urlParams Additional URL parameters
|
||||
*
|
||||
* @throws ChapterNotFoundException If the chapter to filter for was not found
|
||||
*/
|
||||
public function __construct(DocTree $docTree, $chapterTitle, $url, array $urlParams)
|
||||
public function __construct(DocTree $docTree, $chapterId, $url, array $urlParams)
|
||||
{
|
||||
if ($chapterTitle !== null) {
|
||||
$filter = new SectionFilterIterator($docTree, $chapterTitle);
|
||||
if ($chapterId !== null) {
|
||||
$filter = new SectionFilterIterator($docTree, $chapterId);
|
||||
if ($filter->count() === 0) {
|
||||
throw new ChapterNotFoundException(
|
||||
mt('doc', 'Chapter') . ' \'' . $chapterTitle . '\' ' . mt('doc', 'not found')
|
||||
mt('doc', 'Chapter') . ' \'' . $chapterId . '\' ' . mt('doc', 'not found')
|
||||
);
|
||||
}
|
||||
parent::__construct(
|
||||
|
|
|
@ -85,7 +85,7 @@ class TocRenderer extends Renderer
|
|||
array_merge(
|
||||
$this->urlParams,
|
||||
array(
|
||||
'chapterTitle' => $this->encodeUrlParam($section->getChapterTitle())
|
||||
'chapterId' => $this->encodeUrlParam($section->getChapterId())
|
||||
)
|
||||
),
|
||||
$this->url,
|
||||
|
|
|
@ -8,7 +8,7 @@ if (Icinga::app()->isCli()) {
|
|||
}
|
||||
|
||||
$docModuleChapter = new Zend_Controller_Router_Route(
|
||||
'doc/module/:moduleName/chapter/:chapterTitle',
|
||||
'doc/module/:moduleName/chapter/:chapterId',
|
||||
array(
|
||||
'controller' => 'module',
|
||||
'action' => 'chapter',
|
||||
|
@ -17,7 +17,7 @@ $docModuleChapter = new Zend_Controller_Router_Route(
|
|||
);
|
||||
|
||||
$docIcingaWebChapter = new Zend_Controller_Router_Route(
|
||||
'doc/icingaweb/chapter/:chapterTitle',
|
||||
'doc/icingaweb/chapter/:chapterId',
|
||||
array(
|
||||
'controller' => 'icingaweb',
|
||||
'action' => 'chapter',
|
||||
|
|
Loading…
Reference in New Issue