Merge "Use SidebarBeforeOutput hook instead of echo'ing HTML"

This commit is contained in:
jenkins-bot 2016-08-05 00:39:56 +00:00 committed by Gerrit Code Review
commit d2ccf02a81
2 changed files with 4 additions and 56 deletions

View file

@ -31,11 +31,8 @@
"RelatedArticles\\Hooks::onOutputPageParserOutput"
],
"@SkinBuildSidebar": [
"RelatedArticles\\SidebarHooks::onSkinBuildSidebar"
],
"SkinTemplateToolboxEnd": [
"RelatedArticles\\SidebarHooks::onSkinTemplateToolboxEnd"
"SidebarBeforeOutput": [
"RelatedArticles\\SidebarHooks::onSidebarBeforeOutput"
],
"GetBetaFeaturePreferences": [

View file

@ -13,7 +13,7 @@ use User;
class SidebarHooks {
/**
* Handler for the <code>SkinBuildSidebar</code> hook.
* Handler for the <code>SidebarBeforeOutput</code> hook.
*
* Retrieves the list of related pages
* and adds its HTML representation to the sidebar if the ReadMore feature
@ -23,7 +23,7 @@ class SidebarHooks {
* @param array $bar
* @return boolean Always <code>true</code>
*/
public static function onSkinBuildSidebar( Skin $skin, &$bar ) {
public static function onSidebarBeforeOutput( Skin $skin, &$bar ) {
$out = $skin->getOutput();
$relatedPages = $out->getProperty( 'RelatedArticles' );
@ -53,55 +53,6 @@ class SidebarHooks {
return true;
}
/**
* Handler for the <code>SkinTemplateToolboxEnd</code> hook.
*
* Retrieves the list of related pages from the template and
* <code>echo</code>s its HTML representation to the sidebar if the
* ReadMore feature is disabled and the beta feature is enabled by the user.
*
* @param SkinTemplate $skinTpl
* @return boolean Always <code>true</code>
*/
public static function onSkinTemplateToolboxEnd( BaseTemplate &$skinTpl ) {
$out = $skinTpl->getSkin()->getOutput();
$relatedPages = $out->getProperty( 'RelatedArticles' );
if ( !self::isInSidebar( $relatedPages, $out->getUser() ) ) {
return true;
}
$relatedPagesUrls = self::getRelatedPagesUrls( $relatedPages );
// build relatedarticles <li>'s
$relatedPages = [];
foreach ( (array) $relatedPagesUrls as $url ) {
$relatedPages[] =
Html::rawElement( 'li', [ 'class' => htmlspecialchars( $url['class'] ) ],
Html::element( 'a', [ 'href' => htmlspecialchars( $url['href'] ) ],
$url['text']
)
);
}
// build complete html
echo
Html::closeElement( 'ul' ) .
Html::closeElement( 'div' ) .
Html::closeElement( 'div' ) .
Html::openElement( 'div', [
'class' => 'portal',
'role' => 'navigation',
'id' => 'p-relatedarticles',
] ) .
Html::element( 'h3', [], wfMessage( 'relatedarticles-title' )->text() ) .
Html::openElement( 'div', [ 'class' => 'body' ] ) .
Html::openElement( 'ul' ) .
implode( '', $relatedPages );
return true;
}
/**
* Generates anchor element attributes for each entry in list of pages.
*