Use SidebarBeforeOutput hook instead of echo'ing HTML

Ewwwww. This also fixes display in MonoBook.

Change-Id: I5c50722285a0dcf8af09674e3dd80e37128b279a
This commit is contained in:
Kunal Mehta 2016-07-29 20:34:40 -07:00
parent a4c4f6700f
commit ac5448adcc
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.
*