[MediaWiki-l] help with hook in localsettings

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[MediaWiki-l] help with hook in localsettings

rkevans
I am trying to write my first hook for localsettings.php

I'm trying to write a hook that will place a tiny html div with some linked text at the top left corner of every page (over top the site logo if need be).

Here is what I have so far:

$wgHooks['OutputPageBeforeHTML'][] = 'MyExtensionHook4topleft';
function MyExtensionHook4topleft( &$out ) {
                ....tbd... = "<div style="position:fixed;left:0px;top:0px"><a href="https://somelink.com">test</a></div>";
        return true;
}

Is this right so far?

Can anyone help me determine what needs to go in place of the ...tbd...

-Rich

_______________________________________________
MediaWiki-l mailing list
To unsubscribe, go to:
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|

Re: help with hook in localsettings

Greg Rundlett (freephile)
Hi Rich,

I'm not a hook expert, so not sure about this. But, the
https://www.mediawiki.org/wiki/Manual:Hooks/OutputPageBeforeHTML manual
shows that it acts on both $out and $text.  Furthermore, the talk page says
that using the first could lead to an infinite loop, so I'd suggest using
$text for the '...tbd...

There's also an example in the talk page.
https://www.mediawiki.org/wiki/Manual_talk:Hooks/OutputPageBeforeHTML

Greg Rundlett
https://eQuality-Tech.com
https://freephile.org
_______________________________________________
MediaWiki-l mailing list
To unsubscribe, go to:
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|

Re: help with hook in localsettings

rkevans
Thanks Greg,

I think I understand.
Can you take a peek at this and tell me if you see any glaring issues:

$wgMyDivHTML = "<div class=MyTopLeftDiv><a id=MyTopLeftDivLink>text</div>";
$wgMyTopLeftDivFn = new MyTopLeftDivFn();
$wgHooks['OutputPageBeforeHTML'][] = $wgMyTopLeftDivFn;
class MyTopLeftDivFn {
        public function onOutputPageBeforeHTML( OutputPage &$out, &$text ) {
                global $wgMyDIvHTML;
                $text = strtr( $text, $wgMyDivHTML );
                return $out;
        }
}

_______________________________________
From: MediaWiki-l [[hidden email]] on behalf of Greg Rundlett (freephile) [[hidden email]]
Sent: Tuesday, April 24, 2018 2:21 PM
To: MediaWiki announcements and site admin list
Subject: Re: [MediaWiki-l] help with hook in localsettings

Hi Rich,

I'm not a hook expert, so not sure about this. But, the
https://www.mediawiki.org/wiki/Manual:Hooks/OutputPageBeforeHTML manual
shows that it acts on both $out and $text.  Furthermore, the talk page says
that using the first could lead to an infinite loop, so I'd suggest using
$text for the '...tbd...

There's also an example in the talk page.
https://www.mediawiki.org/wiki/Manual_talk:Hooks/OutputPageBeforeHTML

Greg Rundlett
https://eQuality-Tech.com
https://freephile.org
_______________________________________________
MediaWiki-l mailing list
To unsubscribe, go to:
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l

_______________________________________________
MediaWiki-l mailing list
To unsubscribe, go to:
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|

Re: help with hook in localsettings

rkevans
I'm using the following hook based extension in my localsettings to add a small <span> tag to every page with a link back to the domain root:

$wgHooks['BeforePageDisplay'][] = 'lfMyTopLeftDiv';
function lfMyTopLeftDiv( OutputPage &$out, Skin &$skin ) {
$out->addHTML( "<span style='position:fixed;top:0px;left:0px; z-index:100;'><a href='https://mydomain.org' style='z-index:100;'>X</a></span>" );  
return $out;
}

It positions just fine in the top left of the page, but I can't the link to be on top of the logo. The logo div is on top and my hook span is hidden behind it. Z-index does not seem to help.

How can I get this <span> tag to be on top of the logo/menu?

-Rich
_______________________________________________
MediaWiki-l mailing list
To unsubscribe, go to:
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l