Topic on Project:Support desk

Ads defined in LocalSettings.php - means to limit them to NS_MAIN only?

5
Balerion300 (talkcontribs)

As the title says! I'm trying to figure out if there's a way, within Localsettings.php, to wrap ad tags/scripts with code that indicates they should only execute on pages within the Main namespace. Any suggestions that doesn't require an extension?

Ciencia Al Poder (talkcontribs)

You should tell us more details about what code/extension are you using for this. If you're doing the right thing, you'd be using a hook that receives a Title object which you can use to get the namespace of the page.

Balerion300 (talkcontribs)

I am using hooks, but I'm not sure how to get the namespace from that point. We use the SiteNoticeAfter, SkinBuildSidebar, and the SkinAfterContent hooks -- how would I work a check on namespace into that?

76.68.139.34 (talkcontribs)

Don't use hooks associated with the skin. Use hooks associated with page rendering (see Manual::hooks for details). Then do something like:

if($title->getNamespace == NS_MAIN){

$out->addModules('myscript');

}

76.68.139.34 (talkcontribs)

maybe try this hook:

Manual:Hooks/BeforePageDisplay

public static function onBeforePageDisplay( OutputPage &$out, Skin &$skin ) {

if($out->getTitle()->getNamespace() == NS_MAIN){

$out->addModules('mymodule');

}

}

You probably also don't want the module to be loaded for certain actions... so you'll have to make sure to do this only for viewing the article.