Task #13127

MediaWiki hook: Select the header to show for TYPO3 CMS/Flow exceptions

Added by Daniel Brüßler over 8 years ago. Updated over 6 years ago.

Status:
Resolved
Priority:
Must have
Assignee:
Start date:
2011-02-18
Due date:
% Done:

100%


Description

Select the header to show for TYPO3 CMS v4/v6 exceptions and the header to show for Flow exceptions.


Related issues

Related to wiki.typo3.org - Task #13128: Flow exception texts: Clean up meta info Resolved 2011-02-18
Related to wiki.typo3.org - Task #12841: FLOW3 Exceptions Collection: Collect requirements Closed 2011-02-07

History

#1 Updated by Daniel Brüßler over 8 years ago

  • Category set to 887

#2 Updated by Francois Suter about 8 years ago

  • Project changed from Documentation to wiki.typo3.org
  • Category deleted (887)
  • Assignee deleted (Daniel Brüßler)
  • Target version deleted (843)

#3 Updated by Chris topher almost 7 years ago

  • Subject changed from mediawiki hook: select the header to show for V4/V5-Exceptions to MediaWiki hook: Select the header to show for TYPO3 CMS/Flow exceptions

#4 Updated by Chris topher almost 7 years ago

If I understand that issue correctly, the idea is to show a certain header on certain pages. Currently this header is shown only, when it has been inserted manually (e.g. as {{Exception|1234567890}}).

So the header consists of the signs "{{Exception|", the exception number (which is part of the page name), the signs "}}" and a newline.

Adding the header could be automated by using a hook, e.g. the hook ArticleSave. This hook is executed, when someone tries to save a page.
With this hook it should be possible to do the following:
  • If the page is in the main namespace (and not a talk page or so) and
  • has a certain name (e.g. starting with "Exception") and
  • if the text, which should be saved, does not already start with the header which we want to add, then
  • prepend that header to the text.

Question: What if the user did not edit the whole page, but only a section, maybe one in the middle? Does $text then contain the whole page or only the edited section? I guess the whole page (arg.: the complete page is saved as a new revision, not only the changed section).

#5 Updated by Chris topher over 6 years ago

Maybe adding text to the page text is not ideal: Users could start fiddling around with the code, maybe removing it. Or they could change it. If they changed it, our hook would add it again and we would have multiple versions of the header on the pages. That would not be ideal.

Possibly a better option might be not to add the text to the pages themselves, but to display it, when the user is on these pages. The display should then be above the actual content area.
Possible hooks might be

#6 Updated by Chris topher over 6 years ago

I took the hook ArticleViewHeader. This hook is shown when the according pages are viewed; also when they have not yet been created.

First draft:

<?php // Add a header for TYPO3 CMS/Flow exception pages $wgHooks['ArticleViewHeader'][] = 'addHeader'; /** * Add a header prior to outputting the page content, * but after the usual header content (page title, site sub-title, redirect message, etc.) have been output * * @param $article The article (object) * @param $outputDone If there is no more output to output, set $outputDone to true. * @param $pcache If you want the parser cache to try retrieving cached results, set $pcache to done. * @return bool true Continue processing. */ function addHeader(&$article, &$outputDone, &$pcache) { global $wgOut; // Use the Title object to get the number of the namespace; main namespace has number "0". $namespace = $article->getTitle()->getNamespace(); // Only add header for pages inside the main namespace if ($namespace == '0') { // Get the page name inside the namespace; name with spaces, not with underscores, first letter in uppercase. $title = $article->getTitle()->getText(); // Add header if the title starts with "Exception" $needle = 'Exception'; // Check, if the page name starts with $needle if (!strncmp($title, $needle, strlen($needle))) { $isExceptionPage = true; } else { $isExceptionPage = false; } // This is one of the Exception pages. // This page should get the special header! if ($isExceptionPage === true) { $element = 'p'; $attribs = array('class' => 'exception-header'); $contents = 'This is the page header. Please login to edit.'; $wgOut->addElement($element, $attribs, $contents); // Alternatively add raw HTML: //$wgOut->addHTML('<p class="exception-header">This is the page header.</p>'); } } return true; } These page names are used. Whether it's a TYPO3 CMS or a Flow exception can be told based on the page names:
  • TYPO3 exceptions are those whose title starts with "Exception/CMS/",
  • Flow exceptions then are those whose name starts with "Exception" ("Exception<number>), but not with "Exception/CMS/"

#7 Updated by Chris topher over 6 years ago

With this hook the header is not shown, when someone edits the page. Wikipedia does show headers during editing for certain pages
  • when editing the page
  • when creating something new (uses a link with these arguments in the page "Wikipedia:Auskunft").
=> How do they do that? (Maybe we can include it the same way not only when editing, but also on page view.)
  • They created a page named MediaWiki:editnotice-4 (The 4 is the number of the namespace.) The text on this page is automatically included in the editing view of all pages of that namespace.
    • The inclusion can be restricted to certain pages of the namespace by putting an "#ifexist" followed by some variables behind it. This needs the extension ParserFunctions.
    • A language label makes translation easy; good idea for us as well, German label as ".../de" then.
  • This label itself includes the text from "Wikipedia:Fragen_zur_Wikipedia/Editnotice".

=> Not nice: Might work for the editing view, but we still need to do the same for page view. And that does not work that way. Better use two hooks.

#8 Updated by Chris topher over 6 years ago

  • Assignee set to Chris topher

Showing a text in the editing view works with the hook EditPage::showEditForm:initial. It is called when editing a page.

Current code:

// Add a header when _viewing_ TYPO3 CMS/Flow exception pages $wgHooks['ArticleViewHeader'][] = 'addHeaderOnArticleView'; /** * Add a header prior to outputting the page content, * but after the usual header content (page title, site sub-title, redirect message, etc.) have been output * * @param $article The article (object) * @param $outputDone If there is no more output to output, set $outputDone to true. * @param $pcache If you want the parser cache to try retrieving cached results, set $pcache to done. * @return bool true Continue processing. */ function addHeaderOnArticleView(&$article, &$outputDone, &$pcache) { global $wgOut; // Contains the logic to decide, if the header should be shown, // and adds it, when it is needed. addHeaderToOutputPage($article, $wgOut); return true; } /** * Add a header when _editing_ TYPO3 CMS/Flow exception pages * * This hook is called when editing a new or an existing page, * also when showing the edit preview and the edit diff * (called at the beginning, when the edit page is initialising, therefore the "initial"). */ $wgHooks['EditPage::showEditForm:initial'][] = 'addHeaderOnEdit'; /** * $editPage The current EditPage object * $output The OutputPage object * @return bool true Continue processing. */ function addHeaderOnEdit($editPage, $output) { // Get the Article object $article = $editPage->getArticle(); // Contains the logic to decide, if the header should be shown, // and adds it, when it is needed. addHeaderToOutputPage($article, $output); return true; } /** * Used to add the "Exception header" to the page; on page view and on edit. * * @param $article The article (object) * @param $wgOut The OutputPage object * @return void */ function addHeaderToOutputPage(&$article, $wgOut) { // Use the Title object to get the number of the namespace; main namespace has number "0". $namespace = $article->getTitle()->getNamespace(); // Only add header for pages inside the main namespace; using "===" does not work here. if ($namespace == '0') { // Get the page name inside the namespace; name with spaces, not with underscores, first letter in uppercase. $title = $article->getTitle()->getText(); // Check, if the page name starts with "Exception" $needle = 'Exception'; if (!strncmp($title, $needle, strlen($needle))) { // This is one of the Exception pages. // This page should get a special header! // Page with the Flow-specific header; might be overwritten by a TYPO3-specific header below. $headerTitleName = 'Template:Exception/Header/Flow'; $needle = 'Exception/CMS'; // Check, if the page is one with an exception for TYPO3 CMS // Choose a different header there. if (!strncmp($title, $needle, strlen($needle))) { // Page with the TYPO3-specific header $headerTitleName = 'Template:Exception/Header/TYPO3CMS'; } // Add the according header! $wgOut->addWikiText('{{' . $headerTitleName . '}}'); } } }
  • The header for Flow can more or less be extracted from one of the templates we already have (and be removed there; or the inclusion of the template itself can be removed).
  • For TYPO3 CMS such a header still needs to be created.
  • It might make sense to protect these pages then.
  • Maybe the whole logic could be put into an extension, as ultimate bonus maybe with configuration variables instead of hardcoding the namespace and page names; this would keep LocalSettings.php clean and prevent bloating.

#9 Updated by Chris topher over 6 years ago

  • Status changed from Accepted to Resolved
  • % Done changed from 0 to 100

Done. I created the extension ExceptionHeader for this and installed it in the wiki.

I have created the pages Template:Exception/Header/TYPO3CMS‎ and Template:Exception/Header/Flow. The extension includes these pages; I put an according note on the pages themselves.

Also available in: Atom PDF