Topic on Project:Support desk

Jump to navigation Jump to search

How to understand the example at SkinAddFooterLinks?

3
49.230.3.204 (talkcontribs)

At Manual:Hooks/SkinAddFooterLinks I came accross the following code example to add a chat menu-link to the footer menu of a MediaWiki (>=1.35) website:

// Add a "Chat" tab with action=chat
public static function onSkinAddFooterLinks( Skin $skin, string $key, array &$footerlinks  ) {
	if ( $key === 'places' ) {
		$footerlinks['test'] = '<A href=#>test link</a>';
    }
}

The only place I read the word "chat" is in the code comment //.

So, how it is an example for adding a button with the term "chat"?

How to understand the example at SkinAddFooterLinks?

TiltedCerebellum (talkcontribs)

My understanding of hooks is that they are there to extend the functionality of the mediawiki software (to write an extension or some bit of code with to extend it). Manual:Hooks has an explanation and some examples of how hooks are called/invoked for extension writers or users who need to write functions for it. The examples provided there are just that, it doesn't mean it has all the code in it to do certain things. You'd have to write the code, create an extension using hooks, or find an extension that already uses the hooks mentioned.

As an example, we couldn't just take the BeforePageDisplay hook and use it's example as-is, we had to write the functions required to do what we wanted. So we use the following in our LocalSettings.php to hide some utilities for non-logged in users:


$wgHooks['BeforePageDisplay'][] = 'efCustomBeforePageDisplay';

/* Hide Utilities for non-logged in users */

function efAddSkinStyles(OutputPage &$out, Skin &$skin) {

    if(!$skin->getUser()->isLoggedIn()) {

if ($skin->getSkinName() == 'pivot') {

            $out->addInlineStyle('#p-Utilities, li#n-New-Page, li#n-Special-Pages, li#n-Multi-upload { display:none; }');

        }

    } else {

// Do nothing

    }

    return true;

}

$wgHooks['BeforePageDisplay'][] = 'efAddSkinStyles';

Bawolff (talkcontribs)

that example is confusing since its just adding a test link not a chat link.

Reply to "How to understand the example at SkinAddFooterLinks?"