Topic on Project:Support desk

Question on Title Class properties

6
82.135.88.167 (talkcontribs)

Hi, my company will use a wiki within intranet, probably version 1.19.0. The Wiki is not accessible from www. We wanna have articles with same article names but different namespaces, eg. BAR:foo / BAZ:foo / RAB:foo. To build navigation links, I'm looking for the object properties to get the Namespace name and article name for the displayed article. I've looked over the title class reference but didn't get through really. Maybe you can help me out telling me which methods / property will hold this vars?

To be exact, if the article would be BAR:foo, i would need to call a property to return "BAR" and one to return "foo".

Thanks in advance, regards, Dennis

MarkAHershberger (talkcontribs)

Why not just split the title on ":" to get that information?

MarkAHershberger (talkcontribs)

Also, you don't make clear what you are using to get at the title object. Assuming you're writing an extension or skin for MediaWiki, look at the getNamespace and getText methods.

62.153.144.77 (talkcontribs)

Hi, you guess right, I try to make a small extension to add extra tabs right beside the page / talk / edit tabs of the used skin. The idea is to have a simple navigation to swap betweeen the three namespaces. The namespaces represent different views on the same topic, say customer service info, technical support info, product management info on a certain product.

I've found a code sample that will do so with a static url to stick with the new tab, now I'm searching an easy way to get it working dynamic. I've added the php code below, to make it possibly more clear. To get it work dynamically, I would need to compare if the actual display page is one of the 3 namespaces Tec / PM / CS and which is the title of the page ('Seite' in the code below). I Could parse the URL by myself of course, but hoped there is an easy way to access the values though wiki object attributes.

Next step will be to detect if the specific Namespace:title exists yet, so I can make the extension decide to display the action tab in red or blue and to skip making the extra tab buttons in case the actual displayed page is a specialpage.

My problem is, I am not too familiar with the wiki object modell, I read accross the manual for article and title classes, but didn't get the clue yet how access the values I needed. Just hoped to find someone here, who is so familiar with that so he/she can tell this out of sleep :) If this was to optimistic, I'll go on trying to understand from the manual :)

Regards, Dennis


<?php
// ParserHook
 $wgHooks['SkinTemplateContentActions'][] = 'ReplaceTabs'; 
// Function to add the tabs
 function ReplaceTabs ($content_actions) {  
     $tectitle = Title::newFromText('Tec:Seite');
     $pmtitle = Title::newFromText('PM:Seite');
     $cstitle = Title::newFromText('CS:Seite');
 
     $main_action['tec'] = array(
        'class' => false,						//if the tab should be highlighted
        'text' => 'Tec',						//what the tab says
        'href' => $tectitle->getFullURL(),		//where it links to
      );
     $main_action['pm'] = array(
        'class' => false,						//if the tab should be highlighted
        'text' => 'PM',							//what the tab says
        'href' => $pmtitle->getFullURL(),		//where it links to
      );
     $main_action['cs'] = array(
        'class' => false,						//if the tab should be highlighted
        'text' => 'CS',							//what the tab says
        'href' => $cstitle->getFullURL(),		//where it links to
      );
 
	  $content_actions = array_merge( $main_action, $content_actions);   //add tabs to the bar
      return true;
 }
 ?>
MarkAHershberger (talkcontribs)

To make your code dynamic, you would need the current page's title object from the global variable $wgTitle or (in newer MediaWiki) from the request context.

Once you have that you can use the getBaseText() method to get the part of the title you want. So instead of

 $tectitle = Title::newFromText('Tec:Seite');

you would have (note that this is untested):

 global $wgTitle;
 $tectitle = Title::newFromText( 'Tec:' . $wgTitle->getBaseText() );
Reply to "Question on Title Class properties"