From 289aed84205924a57753a4fa527f1742f9e82b40 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 19 Aug 2014 09:45:53 +0200 Subject: [PATCH] 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 --- .../controllers/IcingawebController.php | 10 +++++----- .../application/controllers/ModuleController.php | 10 +++++----- modules/doc/library/Doc/DocController.php | 6 +++--- modules/doc/library/Doc/DocParser.php | 8 ++++---- modules/doc/library/Doc/Section.php | 16 ++++++++-------- .../doc/library/Doc/SectionFilterIterator.php | 14 +++++++------- modules/doc/library/Doc/SectionRenderer.php | 12 ++++++------ modules/doc/library/Doc/TocRenderer.php | 2 +- modules/doc/run.php | 4 ++-- 9 files changed, 41 insertions(+), 41 deletions(-) diff --git a/modules/doc/application/controllers/IcingawebController.php b/modules/doc/application/controllers/IcingawebController.php index 55f60d36e..117d6eb0e 100644 --- a/modules/doc/application/controllers/IcingawebController.php +++ b/modules/doc/application/controllers/IcingawebController.php @@ -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'); } /** diff --git a/modules/doc/application/controllers/ModuleController.php b/modules/doc/application/controllers/ModuleController.php index 3a8bfc6af..7429dbdf2 100644 --- a/modules/doc/application/controllers/ModuleController.php +++ b/modules/doc/application/controllers/ModuleController.php @@ -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) ); diff --git a/modules/doc/library/Doc/DocController.php b/modules/doc/library/Doc/DocController.php index de2a7bac9..16824ce0c 100644 --- a/modules/doc/library/Doc/DocController.php +++ b/modules/doc/library/Doc/DocController.php @@ -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 ); diff --git a/modules/doc/library/Doc/DocParser.php b/modules/doc/library/Doc/DocParser.php index d543f9f91..559a9a7d3 100644 --- a/modules/doc/library/Doc/DocParser.php +++ b/modules/doc/library/Doc/DocParser.php @@ -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); diff --git a/modules/doc/library/Doc/Section.php b/modules/doc/library/Doc/Section.php index 57419dc0a..ac458b6fe 100644 --- a/modules/doc/library/Doc/Section.php +++ b/modules/doc/library/Doc/Section.php @@ -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; } /** diff --git a/modules/doc/library/Doc/SectionFilterIterator.php b/modules/doc/library/Doc/SectionFilterIterator.php index 9b5d2c013..e20d80359 100644 --- a/modules/doc/library/Doc/SectionFilterIterator.php +++ b/modules/doc/library/Doc/SectionFilterIterator.php @@ -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); } /** diff --git a/modules/doc/library/Doc/SectionRenderer.php b/modules/doc/library/Doc/SectionRenderer.php index 31143e3c8..1b7c68f1b 100644 --- a/modules/doc/library/Doc/SectionRenderer.php +++ b/modules/doc/library/Doc/SectionRenderer.php @@ -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( diff --git a/modules/doc/library/Doc/TocRenderer.php b/modules/doc/library/Doc/TocRenderer.php index f018c556d..4b9d96a05 100644 --- a/modules/doc/library/Doc/TocRenderer.php +++ b/modules/doc/library/Doc/TocRenderer.php @@ -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, diff --git a/modules/doc/run.php b/modules/doc/run.php index 959b56095..7392e4c22 100644 --- a/modules/doc/run.php +++ b/modules/doc/run.php @@ -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',