From 53ab861a2fcba98d876e5a2be5af7bc7186b880c Mon Sep 17 00:00:00 2001 From: aude Date: Mon, 16 Dec 2013 18:26:30 +0100 Subject: [PATCH] Add BaseTemplateAfterPortlet hook to add html after portlets Allows extensions to move away from using (or abusing) the SkinTemplateOutputPageBeforeExec hook to add things in places such as after the list of language links. Also explicitly check that $template->data['language_urls'] is not false. Extensions can set it to an empty array to have the language links header be displayed. Bug: 57094 Change-Id: I099fb2ff48e02a2e3564a484aea906263e40bb53 --- RELEASE-NOTES-1.23 | 1 + docs/hooks.txt | 6 ++++++ includes/SkinTemplate.php | 13 +++++++++++++ skins/CologneBlue.php | 36 +++++++++++++++++++++++++++--------- skins/MonoBook.php | 11 ++++++++++- skins/Vector.php | 11 +++++++---- skins/cologneblue/screen.css | 5 +++++ skins/monobook/main.css | 6 ++++++ 8 files changed, 75 insertions(+), 14 deletions(-) diff --git a/RELEASE-NOTES-1.23 b/RELEASE-NOTES-1.23 index 38302f80eb..3a809d3d77 100644 --- a/RELEASE-NOTES-1.23 +++ b/RELEASE-NOTES-1.23 @@ -125,6 +125,7 @@ production. buttons. * Special:UserLogin/signup now does AJAX checks for invalid and taken usernames, displaying the error live. +* Added BaseTemplateAfterPortlet hook to allow injecting html after portlets in skins. === Bug fixes in 1.23 === * (bug 41759) The "updated since last visit" markers (on history pages, recent diff --git a/docs/hooks.txt b/docs/hooks.txt index e7fa89bae4..a8334848fe 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -709,6 +709,12 @@ pages or galleries in category pages. $name: Image name being checked &$bad: Whether or not the image is "bad" +'BaseTemplateAfterPortlet': After output of portlets, allow injecting +custom HTML after the section. Any uses of the hook need to handle escaping. +$template BaseTemplate +$portlet: string portlet name +&$html: string + 'BeforeDisplayNoArticleText': Before displaying message key "noarticletext" or "noarticletext-nopermission" at Article::showMissingArticle(). $article: article object diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 780b228e32..bf572d05b5 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -1738,6 +1738,19 @@ abstract class BaseTemplate extends QuickTemplate { return $boxes; } + /** + * @param string $name + */ + protected function renderAfterPortlet( $name ) { + $content = ''; + wfRunHooks( 'BaseTemplateAfterPortlet', array( $this, $name, &$content ) ); + + if ( $content !== '' ) { + echo "
$content
"; + } + + } + /** * Makes a link, usually used by makeListItem to generate a link for an item * in a list used in navigation lists, portlets, portals, sidebars, etc... diff --git a/skins/CologneBlue.php b/skins/CologneBlue.php index a7c62b317d..9344febf22 100644 --- a/skins/CologneBlue.php +++ b/skins/CologneBlue.php @@ -90,21 +90,37 @@ class CologneBlueTemplate extends BaseTemplate { return ""; } + $html = ''; + // We override SkinTemplate->formatLanguageName() in SkinCologneBlue // not to capitalize the language names. $language_urls = $this->data['language_urls']; - if ( empty( $language_urls ) ) { - return ""; - } + if ( !empty( $language_urls ) ) { + $s = array(); + foreach ( $language_urls as $key => $data ) { + $s[] = $this->makeListItem( $key, $data, array( 'tag' => 'span' ) ); + } - $s = array(); - foreach ( $language_urls as $key => $data ) { - $s[] = $this->makeListItem( $key, $data, array( 'tag' => 'span' ) ); + $html = wfMessage( 'otherlanguages' )->text() + . wfMessage( 'colon-separator' )->text() + . $this->getSkin()->getLanguage()->pipeList( $s ); } - return wfMessage( 'otherlanguages' )->text() - . wfMessage( 'colon-separator' )->text() - . $this->getSkin()->getLanguage()->pipeList( $s ); + $html .= $this->renderAfterPortlet( 'lang' ); + + return $html; + } + + /** + * @param string $name + */ + protected function renderAfterPortlet( $name ) { + $content = ''; + wfRunHooks( 'BaseTemplateAfterPortlet', array( $this, $name, &$content ) ); + + $html = $content !== '' ? "
$content
" : ''; + + return $html; } function pageTitleLinks() { @@ -517,6 +533,8 @@ class CologneBlueTemplate extends BaseTemplate { $role = ( $heading == 'search' ) ? 'search' : 'navigation'; $s .= "
\n$headingHTML\n$listHTML\n
\n"; } + + $s .= $this->renderAfterPortlet( $heading ); } $s .= "\n"; diff --git a/skins/MonoBook.php b/skins/MonoBook.php index bd914ceaa6..34f59655b7 100644 --- a/skins/MonoBook.php +++ b/skins/MonoBook.php @@ -221,6 +221,8 @@ echo $footerEnd; } ?> + + renderAfterPortlet( 'search' ); ?> +renderAfterPortlet( 'cactions' ); ?> +renderAfterPortlet( 'tb' ); ?> data['language_urls'] ) { + if ( $this->data['language_urls'] !== false ) { ?> renderAfterPortlet( $bar ); ?> renderPortal( 'tb', $this->getToolbox(), 'toolbox', 'SkinTemplateToolboxEnd' ); break; case 'LANGUAGES': - if ( $this->data['language_urls'] ) { + if ( $this->data['language_urls'] !== false ) { $this->renderPortal( 'lang', $this->data['language_urls'], 'otherlanguages' ); } break; @@ -316,9 +316,12 @@ class VectorTemplate extends BaseTemplate { - - + renderAfterPortlet( $name ); + ?>