views:

28

answers:

1

Complete beginner here. I want to create a new tab on each page that has a custom action. When clicked, it takes you to a new page which has custom HTML on it along with the text or the original article.

So far I could create a new Tab and could give a custom action mycustomaction to it. I am pasting what I did so far here. Please let me know if I am using the correct hooks etc. and what is a better way to achieve this basic functionality.

So far with their docs I have done this:

#Hook for Tab
$wgHooks['SkinTemplateContentActions'][] = 'myTab';

#Callback
function myTab( $content_actions) {
      global $wgTitle;
      $content_actions['0'] = array(
          'text' => 'my custom label',
          'href' => $wgTitle->getFullURL( 'action=mycustomaction' ),
      );      
      return true;
 }

#new action hook
$wgHooks['UnknownAction'][] = 'mycustomaction';

#callback
function mycustomaction($action, $article) {
    echo $action;                                                                                                
    return true;
}

This gives me error:

No such action

The action specified by the URL is invalid. You might have mistyped the URL, or followed an incorrect link. This might also indicate a bug in the software used by yourplugin

+1  A: 

What I was doing wrong:

$content_actions[‘0’] should simply be $content_actions[] (minor nitpick)

$content_actions is passed-by-reference, it should be function myTab( &$content_actions ) {}

mycustomaction() should do something along the lines of

if ( $action == ‘mycustomaction’ ) { 
  do stuff; return false; 
} 
else { 
  return true; 
}

It should use $wgOut->addHTML() instead of echo

Thanks a lot everyone for your help!

AJ