Skip to content

Commit

Permalink
FeaturedFeeds: Use SidebarBeforeOutput hook
Browse files Browse the repository at this point in the history
SkinTemplateOutputPageBeforeExec is deprecated

Bug: T255380
Change-Id: Ib4cc9d104bae07fd78ee10c3aa5596734a7924b9
  • Loading branch information
Ammarpad committed Jun 14, 2020
1 parent a7498a8 commit 3ee517c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
2 changes: 1 addition & 1 deletion extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"Hooks": {
"PageContentSaveComplete": "FeaturedFeeds::pageContentSaveComplete",
"BeforePageDisplay": "FeaturedFeeds::beforePageDisplay",
"SkinTemplateOutputPageBeforeExec": "FeaturedFeeds::skinTemplateOutputPageBeforeExec"
"SidebarBeforeOutput": "FeaturedFeeds::onSidebarBeforeOutput"
},
"MessagesDirs": {
"FeaturedFeeds": [
Expand Down
59 changes: 32 additions & 27 deletions includes/FeaturedFeeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,37 +116,42 @@ public static function beforePageDisplay( OutputPage &$out ) {
}

/**
* SkinTemplateOutputPageBeforeExec hook handler
* @param Skin &$sk
* @param QuickTemplate &$tpl
* @return bool
* SidebarBeforeOutput hook handler
*
* @param Skin $skin
* @param array &$sidebar
*/
public static function skinTemplateOutputPageBeforeExec( &$sk, &$tpl ) {
public static function onSidebarBeforeOutput( Skin $skin, &$sidebar ) {
global $wgDisplayFeedsInSidebar, $wgAdvertisedFeedTypes;

if ( ( $wgDisplayFeedsInSidebar
|| !wfMessage( 'ffeed-enable-sidebar-links' )->inContentLanguage()->isDisabled()
) && $sk->getContext()->getTitle()->isMainPage()
) {
$feeds = self::getFeeds(
$sk->getContext()->getLanguage()->getCode(),
$sk->getUser()
);
$links = [];
$format = $wgAdvertisedFeedTypes[0]; // @fixme:
/** @var FeaturedFeedChannel $feed */
foreach ( $feeds as $feed ) {
$links[] = [
'href' => $feed->getURL( $format ),
'title' => $feed->title,
'text' => $feed->shortTitle,
];
}
if ( count( $links ) ) {
$tpl->data['sidebar']['ffeed-sidebar-section'] = $links;
}
if ( !$skin->getTitle()->isMainPage() ) {
return;
}

$msgDisabled = $skin->msg( 'ffeed-enable-sidebar-links' )->inContentLanguage()->isDisabled();

if ( !$wgDisplayFeedsInSidebar || $msgDisabled ) {
return;
}

$feeds = self::getFeeds(
$skin->getLanguage()->getCode(),
$skin->getUser()
);
$links = [];
$format = $wgAdvertisedFeedTypes[0]; // @fixme:
/** @var FeaturedFeedChannel $feed */
foreach ( $feeds as $feed ) {
$links[] = [
'href' => $feed->getURL( $format ),
'title' => $feed->title,
'text' => $feed->shortTitle,
];
}

if ( count( $links ) ) {
$sidebar['ffeed-sidebar-section'] = $links;
}
return true;
}

/**
Expand Down

0 comments on commit 3ee517c

Please sign in to comment.