Thanks again, Dmitriy!

I've converted the extension code to be a parser function, and now the semantic property was expanded! But there´s still on issue, now I´m getting the HTML code corresponding to the link as a string in the text, instead of having a link in the file.

Eg, I can see the text "<a href='c:\whatever\foo.txt'>c:\whatever\foo.txt</a>" in the page that uses {{#file:c:\whatever\foo.txt }}. This didn´t happen when the extension were using tags.

I´m looking at parser.php, but, as it´s a little big, I´d appreciate any help to try to fix this issue.

I´m posting below my modified version of the FileProtocolLinks extension

$wgExtensionFunctions[] = 'registerFileProtocolLinks';
$wgHooks['LanguageGetMagic'][]       = 'registerFileProtocolLinks_Magic';

function registerFileProtocolLinks() {
    global $wgParser;
    $wgParser->setFunctionHook('file', 'renderFileProtocolLink');
}
function registerFileProtocolLinks_Magic( &$magicWords, $langCode ) {
        $magicWords['file'] = array( 0, 'file' );
        return true;
}
function renderFileProtocolLink(&$parser, $input, $param2 = '') {
    $exploded = explode('|', $input);
    $uri = htmlentities($exploded[0], ENT_COMPAT, "UTF-8");

    if (!isset($exploded[1]) || empty($exploded[1])) {
        // no linktext has been specified ==> use the URI as linktext
        $linktext = $uri;
    }
    else {
        $linktext = htmlentities($exploded[1], ENT_COMPAT, "UTF-8");
    }

    $linkTextW=$parser->recursiveTagParse( $linktext );
    return sprintf('<a style="color:green" href="file:///%s">%s</a>',
        $uri, $linkTextW);
}

[],
Matheus

CNIT escreveu:
28.12.2009 12:57, Matheus Garcia Barbosa de Figueiredo пишет:
Thanks, Dmitriy!
But it didn´t work the way I expected.

Now, as an output to:

<file>[[path::{{{path}}}]]</file>

I got

{{{path}}}

instead of the value of mt path variable (c:\whatever\foo.txt)

Here´s my modified version:

function renderFileProtocolLink($input)
{
    global $wgParser;

    $exploded = explode('|', $input);
    $uri = htmlentities($exploded[0], ENT_COMPAT, "UTF-8");
 
    if (!isset($exploded[1]) || empty($exploded[1])) {
        // no linktext has been specified ==> use the URI as linktext
        $linktext = $uri;
    }
    else {
        $linktext = htmlentities($exploded[1], ENT_COMPAT, "UTF-8");
    }
 

    #Removed
    #return sprintf('<a style="color:green" href="file:///%s">%s</a>', 
    #    $uri, $linktext);

    # Added
    $linkTextW=$wgParser->recursiveTagParse( $linktext );
    return sprintf('<a style="color:green" href="file:///%s">%s</a>', 
        $uri, $linktextW);
}

I´ll keep trying, any news I´ll post here.

  
I am not sure that $wgParser is a suitable instance. Sad, but it seems that tag hooks doesn't provide a proper instance of Parser in such case. Context is wrong, thus {{{path}}} is not expanding.
You have either to extend Parser class (which is not very easy) or, much better idea is to convert parser tag to parser function. Usually it is not difficult:
Instead of $wgParser->setHook() try using $wgParser->setFunctionHook(). Such way the recursive parsing will be done "automatically" and it should work much better with SMW then.
See includes/Parser/Parser.php and http://www.mediawiki.org/wiki/Manual:Parser_functions for details.
Dmitriy


--

Matheus Garcia Barbosa de Figueiredo
Tel.: (31) 2108 - 7018
Analista de Sistemas
Gerência de Desenvolvimento de Sistemas - GDS
Gerência-Geral de Sistemas de Informação - GSI
Assembleia Legislativa de Minas Gerais - ALMG