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:
Eric Lippmann 2014-08-19 09:45:53 +02:00
parent f9e8ad3d0b
commit 289aed8420
9 changed files with 41 additions and 41 deletions

View File

@ -19,18 +19,18 @@ class Doc_IcingawebController extends DocController
/** /**
* View a chapter of Icinga Web 2's documentation * 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() public function chapterAction()
{ {
$chapterTitle = $this->getParam('chapterTitle'); $chapterId = $this->getParam('chapterId');
if ($chapterTitle === null) { if ($chapterId === null) {
throw new Zend_Controller_Action_Exception( throw new Zend_Controller_Action_Exception(
$this->translate('Missing parameter \'chapterTitle\''), $this->translate('Missing parameter \'chapterId\''),
404 404
); );
} }
$this->renderChapter(Icinga::app()->getApplicationDir('/../doc'), $chapterTitle, 'doc/icingaweb/chapter'); $this->renderChapter(Icinga::app()->getApplicationDir('/../doc'), $chapterId, 'doc/icingaweb/chapter');
} }
/** /**

View File

@ -82,7 +82,7 @@ class Doc_ModuleController extends DocController
/** /**
* View a chapter of a module's documentation * 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 * the documentation module's library occurs
* @see assertModuleEnabled() * @see assertModuleEnabled()
*/ */
@ -90,10 +90,10 @@ class Doc_ModuleController extends DocController
{ {
$moduleName = $this->getParam('moduleName'); $moduleName = $this->getParam('moduleName');
$this->assertModuleEnabled($moduleName); $this->assertModuleEnabled($moduleName);
$chapterTitle = $this->getParam('chapterTitle'); $chapterId = $this->getParam('chapterId');
if ($chapterTitle === null) { if ($chapterId === null) {
throw new Zend_Controller_Action_Exception( throw new Zend_Controller_Action_Exception(
$this->translate('Missing parameter \'chapterTitle\''), $this->translate('Missing parameter \'chapterId\''),
404 404
); );
} }
@ -101,7 +101,7 @@ class Doc_ModuleController extends DocController
try { try {
$this->renderChapter( $this->renderChapter(
$moduleManager->getModuleDir($moduleName, '/doc'), $moduleManager->getModuleDir($moduleName, '/doc'),
$chapterTitle, $chapterId,
'doc/module/chapter', 'doc/module/chapter',
array('moduleName' => $moduleName) array('moduleName' => $moduleName)
); );

View File

@ -12,16 +12,16 @@ class DocController extends ModuleActionController
* Render a chapter * Render a chapter
* *
* @param string $path Path to the documentation * @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 string $url
* @param array $urlParams * @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); $parser = new DocParser($path);
$this->view->sectionRenderer = new SectionRenderer( $this->view->sectionRenderer = new SectionRenderer(
$parser->getDocTree(), $parser->getDocTree(),
SectionRenderer::decodeUrlParam($chapterTitle), SectionRenderer::decodeUrlParam($chapterId),
$url, $url,
$urlParams $urlParams
); );

View File

@ -148,12 +148,12 @@ class DocParser
$nofollow = false; $nofollow = false;
} }
if ($stack->isEmpty()) { if ($stack->isEmpty()) {
$chapterTitle = $title; $chapterId = $id;
$section = new Section($id, $title, $level, $nofollow, $chapterTitle); $section = new Section($id, $title, $level, $nofollow, $chapterId);
$tree->addRoot($section); $tree->addRoot($section);
} else { } else {
$chapterTitle = $stack->bottom()->getTitle(); $chapterId = $stack->bottom()->getId();
$section = new Section($id, $title, $level, $nofollow, $chapterTitle); $section = new Section($id, $title, $level, $nofollow, $chapterId);
$tree->addChild($section, $stack->top()); $tree->addChild($section, $stack->top());
} }
$stack->push($section); $stack->push($section);

View File

@ -40,11 +40,11 @@ class Section implements Identifiable
protected $nofollow; protected $nofollow;
/** /**
* The title of the chapter the section is part of * The ID of the chapter the section is part of
* *
* @var string * @var string
*/ */
protected $chapterTitle; protected $chapterId;
/** /**
* The content of the section * The content of the section
@ -60,15 +60,15 @@ class Section implements Identifiable
* @param string $title The title of the section * @param string $title The title of the section
* @param int $level The header level * @param int $level The header level
* @param bool $nofollow Whether to instruct search engines to not index the link to the section * @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->id = $id;
$this->title = $title; $this->title = $title;
$this->level = $level; $this->level = $level;
$this->nofollow = $nofollow; $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 * @return string
*/ */
public function getChapterTitle() public function getChapterId()
{ {
return $this->chapterTitle; return $this->chapterId;
} }
/** /**

View File

@ -14,22 +14,22 @@ use Icinga\Data\Tree\NodeInterface;
class SectionFilterIterator extends RecursiveFilterIterator implements Countable class SectionFilterIterator extends RecursiveFilterIterator implements Countable
{ {
/** /**
* The chapter title to filter for * The chapter ID to filter for
* *
* @var string * @var string
*/ */
protected $chapterTitle; protected $chapterId;
/** /**
* Create a new SectionFilterIterator * Create a new SectionFilterIterator
* *
* @param NodeInterface $node Node * @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); parent::__construct($node);
$this->chapterTitle = $chapterTitle; $this->chapterId = $chapterId;
} }
/** /**
@ -42,7 +42,7 @@ class SectionFilterIterator extends RecursiveFilterIterator implements Countable
{ {
$section = $this->getInnerIterator()->current()->getValue(); $section = $this->getInnerIterator()->current()->getValue();
/* @var $section \Icinga\Module\Doc\Section */ /* @var $section \Icinga\Module\Doc\Section */
if ($section->getChapterTitle() === $this->chapterTitle) { if ($section->getChapterId() === $this->chapterId) {
return true; return true;
} }
return false; return false;
@ -54,7 +54,7 @@ class SectionFilterIterator extends RecursiveFilterIterator implements Countable
*/ */
public function getChildren() public function getChildren()
{ {
return new static($this->getInnerIterator()->getChildren(), $this->chapterTitle); return new static($this->getInnerIterator()->getChildren(), $this->chapterId);
} }
/** /**

View File

@ -57,7 +57,7 @@ class Callback
array_merge( array_merge(
$this->urlParams, $this->urlParams,
array( array(
'chapterTitle' => SectionRenderer::encodeUrlParam($section->getChapterTitle()) 'chapterId' => SectionRenderer::encodeUrlParam($section->getChapterId())
) )
), ),
$this->url, $this->url,
@ -119,19 +119,19 @@ class SectionRenderer extends Renderer
* Create a new section renderer * Create a new section renderer
* *
* @param DocTree $docTree The documentation tree * @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 string $url The URL to replace links with
* @param array $urlParams Additional URL parameters * @param array $urlParams Additional URL parameters
* *
* @throws ChapterNotFoundException If the chapter to filter for was not found * @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) { if ($chapterId !== null) {
$filter = new SectionFilterIterator($docTree, $chapterTitle); $filter = new SectionFilterIterator($docTree, $chapterId);
if ($filter->count() === 0) { if ($filter->count() === 0) {
throw new ChapterNotFoundException( throw new ChapterNotFoundException(
mt('doc', 'Chapter') . ' \'' . $chapterTitle . '\' ' . mt('doc', 'not found') mt('doc', 'Chapter') . ' \'' . $chapterId . '\' ' . mt('doc', 'not found')
); );
} }
parent::__construct( parent::__construct(

View File

@ -85,7 +85,7 @@ class TocRenderer extends Renderer
array_merge( array_merge(
$this->urlParams, $this->urlParams,
array( array(
'chapterTitle' => $this->encodeUrlParam($section->getChapterTitle()) 'chapterId' => $this->encodeUrlParam($section->getChapterId())
) )
), ),
$this->url, $this->url,

View File

@ -8,7 +8,7 @@ if (Icinga::app()->isCli()) {
} }
$docModuleChapter = new Zend_Controller_Router_Route( $docModuleChapter = new Zend_Controller_Router_Route(
'doc/module/:moduleName/chapter/:chapterTitle', 'doc/module/:moduleName/chapter/:chapterId',
array( array(
'controller' => 'module', 'controller' => 'module',
'action' => 'chapter', 'action' => 'chapter',
@ -17,7 +17,7 @@ $docModuleChapter = new Zend_Controller_Router_Route(
); );
$docIcingaWebChapter = new Zend_Controller_Router_Route( $docIcingaWebChapter = new Zend_Controller_Router_Route(
'doc/icingaweb/chapter/:chapterTitle', 'doc/icingaweb/chapter/:chapterId',
array( array(
'controller' => 'icingaweb', 'controller' => 'icingaweb',
'action' => 'chapter', 'action' => 'chapter',