Extension talk:NavContent

From MediaWiki.org
Jump to navigation Jump to search

$wgNavContentRenderMath = 'renderTex'; doesn't work for me.[edit]

It loads the page but doesn't render with MathJax.

It looks like this in my LocalSettings file:

$wgDefaultUserOptions['mathJax'] = true;
MathJax_Parser::$MathJaxJS = 'http://localhost:8080/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML';
$wgUseMathJax = true;
$wgJQueryRoot = "$IP/skins/common";
$wgNavContentRoot = "$IP/extensions/NavContent";
$wgNavContentRenderMath = 'renderTex';
include_once( "$wgNavContentRoot/NavContent.php" );

Any ideas?

It's not working in Opera.[edit]

In MS IE, Firefox it is working fine.

It's not working with "recaptcha" an d other extensions like "inputbox"

Not working for me[edit]

  • MW 1.12
  • RHEL5

Installed everything. Output is just: {{#NAVCONTENT: Answer|Answer to exercise 1.1}} i.e. no formatting at all, just the text.

Update: It seems to be just showing the Answer right away with clicking on "Answer."

User hide[edit]

Can we, as users making a page, set the contents box to hide as default, allowing the visitor to click the "(show)" link to see the table? I know how to eliminate the contents box, I was hoping there was a way to include it but hidden. 72.79.198.22 02:29, 29 September 2008 (UTC)

some changes to workflow of this extension[edit]

Some brief touches if you want to. this extension is increadibly great but lacks of options...

1. if you want to use different letter in bar instead of pipe | symbol - just replace | in string " | " everywhere in NavContent.js. I use " &bull " combination for template:Language-like appearance. also set in NavContent.css

div.NavContentFrame {width:100%;}
div.NavContentBar {border: 1px solid #AAAAAA; background: #EEF3E2; padding-left: 0.5em}

and you get something very similar to Language bar.

2. if you want to open first link right after loading the page - then you must add this code right in the end of NavContent.js.

$(function(){
  //for each navcontent on page
  $("div.NavContentFrame").each(function(){
     //we must set first link bold
     $("a.NavContentBarLink:first",this).css("fontWeight","bold");
     //let first part be visible, but now it's just showing "loading" icon
     $("div.NavContentPart:first",this).show();
     //real loading of first part
     $("div.load-on-demand:first",this).each(function(){
	if(!$("a",this).hasClass("new")) {
	    addr = $("a",this).attr("href");
	    host = addr.split(/\/index.php/g)[0];
	    addr = addr.split(/\/index.php/g)[1];
            if (/[\?\&]title\=/.test(addr)) {
                addr = addr.match(/[\?\&]title\=[^\?\&]+/);
                addr = addr[0].match(/([\?\&]title\=)([^\?\&]+)/);
                addr = addr[2];
            }
            else {
                addr = addr.slice(1);
            }
	    $(this).load(host + "/index.php?action=ajax&rs=wfAjaxLoadContent&rsargs="
	          + addr,
	    	{},
	    	function(){
	    	    runOnloadSubpagesHook(this);
	    	    $(this).removeClass("load-on-demand");
	   	    $("div.NavContentContentPart:first",this).show();
	    	    $("div.NavContentContentPart:gt(0)",this).hide();
	    	    if($("div.NavContentContentPart",this).size()>1)
	            $(this).parent().find("div.NavContentProgressBar").show();
	   	});
	}
     });
  });
});

p.s. i'm not expert in jquery or in navcontent structure, maybe this code has some errors, i just create it after some hours of efforts, but i hope for further development of this extensions, and discussions. p.p.s. seems i need some more features, then more additions...   Schthaxe 25 january 2009

the next part[edit]

well my previous add has error - print version shows only first block.

anyway. the next thing i try to add.

if you type {{#NavContent:a|b|c|d}} - it works as described, but if you try to use something like

{{#vardefine:List|a|b|c|d}}
{{#NavContent: {{#var:List}} }}

it would not work and shows "UNEVEN number of arguments to #NAVCONTENT", because whole text "a|b|c|d" was passed as one argument (you can easily watch it by typing {{#NavContent: {{#var:List}} |sometext}} )

I need to create list of arguments by program (i want to create list by #Loop - #ifexist construction), so i patched NavContent.php

Find

function wfNavContent_Render( &$parser ) {
        global $wgNavContentRoot;
 
        $arguments = array_slice( func_get_args(), 1 );
        $n = count( $arguments );

insert right after this

	if ( $n == 1 ) { // maybe list has passed in one argument
		$argarray = explode  ( "|", $arguments[0] );
		$arguments = $argarray;
		$n = count( $arguments );
	}

& #124; - is code for pipe character. you can't use <nowiki> for delimiter in your template program (for example you MUST NOT use something like {{#vardefine:List|a<nowiki>|</nowiki>b|c|d}} ), so you can use this code instead {{#vardefine:List|a& #124;b& #124;c& #124;d}} - it renders out just the same as a|b|c|d

User:Schthaxe 28 jan 2009

invoking of templates with parameters[edit]

it is easily to imagine some tasks when you need not only static articles in navcontent but those one that calling with parameters. of course you can countlessly clone template with only difference in substituted parameter, and if you do that you can stop reading here :)

notice 1. all invoked pages are opened via ajax thus they their NavContent and etc is pointing on themselves, not onto the page they're opened in.

notice 2. they are not "included", as template mechanism do, but fully parsed, therefore <noinclude> tags are fully included too, so this tag become useless.

for example, i want to create catalog of albums of rock-group, separated lyricpages for each songs in Song namespace and in "Groupname" category, and template that collected all songs in one page.

Albums|Discography:Rites of Spring|Songs|Template:LyricSheet~Rites of Spring

i use a tilde char as temporary replace for pipe char, but you can use any other. so, in this example navcontent must build "Songs" link that opens Template:LyricSheet|Rites of Spring.

i do it adding a parameter "addparam" to GET call in ajax.

1. create a simple magicword that returns addparam value. (you can look into variables extension on how to make it work)

    function getparam( &$parser ) {
        global $wgRequest;
        return $wgRequest->data['addparam'];
    }

2. patching of navcontent.php

1st part: for checking and working we must clean link from added parameter.

        // Check arguments
        if ( fmod( $n, 2 ) != 0 ) {
	        $output[0] = "<div class=\"mw-warning\"> Uneven number (".$n.") of arguments to #NAVCONTENT</div>";
	        return $output;
        }

        $params=array();/////add this

        foreach( $arguments as $i => $pageref ) {
                if( fmod($i,2) == 1 ) {
                        $pageref0 = explode( '~' , $pageref );/////add this
                        $arguments[$i] = $pageref = $pageref0[0]; /////add this
                        $params[] = $pageref0[1];/////add this
                        if(! Title::newFromText( $pageref ) ) {
	                        $output[0] = "<div class=\"mw-warning\">Argument \""
                        	        . htmlspecialchars($pageref)
                                        . "\" in #NAVCONTENT is referring to a non-valid page</div>";
                                return $output;
                        }
                 }
       }

2nd part. after checking add it back and place on page

		if(! $title->exists() ) 
		        $output[0] .= "class=\"new\" "
			        . "href=\"" . $title->escapeFullURL('action=edit') . "\">";
		else	{ //add bracket
			if( $params[$i/2]!="" ) $addparam = "~". $params[$i/2]; else $addparam = "";/////add this
		        $output[0] .= "href=\"" . $title->escapeFullURL() . $addparam ."\">";#modify this
		}//add closing bracket

3rd part. in edit page we don't need an argument

	                        $z = explode( '|', $z );
	                        foreach( $z as $i => $page ) {
		                        if( fmod($i,2)==1 ) {
					  $page0=explode('~',$page); /////add this
					  $navcontentlinks[] = Title::newFromText( trim($page0[0]) ); /////modify this
					}
				}

4th part. then calling ajax, simply replace emporary argument separator with pipe. wiki understands you.

function wfAjaxLoadContent( $term ) {
 
        global $wgContLang, $wgOut, $wgParser;

	$term = str_replace( "~"  , "|" , $term);/////add this
	$t = Title::newFromText( $term );

3 patch navcontent.js. building GET request, with addparam

					    addr = $("a",contents).attr("href");
					    /////add 3 strings
					    addparam = addr.split("~")[1];
					    addr = addr.split("~")[0];
					    if (addparam!=""){addparam = "&addparam=" + addparam;}

                                            host = addr.split(/\/index.php/g)[0];
                                            addr = addr.split(/\/index.php/g)[1];
                                            if (/[\?\&]title\=/.test(addr)) {
                                                addr = addr.match(/[\?\&]title\=[^\?\&]+/);
                                                addr = addr[0].match(/([\?\&]title\=)([^\?\&]+)/);
                                                addr = addr[2];
                                            }
                                            else {
                                                addr = addr.slice(1);
                                            }
					    $(contents).load(host + "/index.php?action=ajax&rs=wfAjaxLoadContent&rsargs="
					            + addr + addparam, /////modify it

this would work.

p.s. the remaining question is how i build a list of pages in category/namespace. well i do it by making magic word what put results of certain SELECT into magicworded array and when i make a template that looping through that array. but this is another story...

this is my Template:LyricSheet (pagetitle is array where values with "_", pagename - without)

{{#arraynscat:pagetitle|pagename|Songs|{{#getparam:}}}}<!--
-->{{#vardefine: i | 0 }}<!--
-->{{#vardefine:n|{{#arraycount:pagename}} }}
{{#while:
  | {{#ifexpr: {{#var: i }} < {{#var: n }} | true }}
  | '''{{#array:pagename|{{#var:i}}}}'''<br><br>{{:Songs:{{#array:pagetitle|{{#var:i}}}}}}<br><br>
{{#vardefine: i | {{#expr: {{#var: i }} + 1 }} }} }}

--Schthaxe 10:56, 21 February 2009 (UTC)