[Mediawiki-l] Re: Embedding a section of a page in another page (syntax??)

FxParlant f-x.p at laposte.net
Sat Nov 26 10:54:16 UTC 2005


As far as I know, there isn't any simple solution for this in mediawiki.
Nevertheless an extension could do this or at least could build
something with this solution.

I worked on a similar problem: I have a page with a lot of books
references, and sometimes, I'd like to insert the description (author
name, title, edition) in a page, without having to rewrite everything.
And I also want that any modification applied to a description appears
in every page where the description was included.

To do this, I droped completely the idea of using the "section" of a
page. The section is not something fix. And it has not precise end:
there are no "end section tags".
I wouldn't use the automatic section tagging to do this, and I'd prefer
the manual tagging. Define the beginning and the end of the section by
some html/wml tag with your own id. For example:

<div id="begin_ruiter_1" /> ..the section.. <div id="end_ruiter_1" />
or with "span" or "a", I'm not sure which tags can be empty in w3c rules.
<span id="begin_ruiter_1" /> ..the section.. <span id="end_ruiter_1" />


The advantage, is that using empty tags you can define a section
crossing another:
begin_section_1
begin_section_2
end_section_1
end_section_2

And as mentioned above, the end of your sections will be precisely and
explicitely defined.  You just have to hope that nobody will delete
these tags :-(

How to make the extension:
*make a tag and is parameters: <include>p=Page;s=Section</include>
that's how you'll call a section in a page
*call the page from database
*cut the section with a regular expression
*apply the wiki engine to the section
*include

HERE IS AN INSIGHT OF HOW THE CODE COULD BEGIN

<?php
$wgExtensionFunctions[] = "wfIncludeExtension";
function wfIncludeExtension() {


        global $wgParser;


$wgParser->setHook( "include", "renderInclude" );

}
    function renderInclude( $input ) {
     global $wgTitle;
     $pageTitle = $wgTitle->getPrefixedDbKey();

     //Get parameters from plugin
    $params = split(';', trim($input));
    $arguments = array();
    foreach ($params as $param) {
		$parts = split( '=', $param );
		if (isset($parts[0]) && isset($parts[1])) {
		    $name = trim($parts[0]);
		    $arguments[$name] = trim($parts[1]);
		}
    }

    if (isset($arguments['p'])){
    $pageTitle = $arguments['p'];
    }

    if (isset($arguments['s'])){
    $section = $arguments['s'];
    }
     $output .= wfIncludeList($pageTitle,$s);
     return $output;
}


unction wfIncludeList($target, $s='Notions'){
    global
$wgUseCategoryMagic,$wgRequest,$wgUser,$wgParser,$parserOptions,$wgTitle,
$wgOut,$wgLinkCache;

$pageTitle = $wgTitle->getPrefixedDbKey();
$nt = Title::newFromURL( $target );
$lid = $nt->getArticleID();

$fname = "wfIncludeList";

$sql = "SELECT cur_id,cur_namespace,cur_title,cur_text FROM cur WHERE
cur_id={$lid};

$res = wfQuery( $sql, DB_READ, $fname );

while ( $row = wfFetchObject( $res ) ) {
 $entryTitle = $row->cur_title;

$mytext =  preg_replace("#THE_REG_EXP#","",$row->cur_text);
}

$wgLinkCache->suspend();
    $parsed = $wgParser->parse( $mytext, $wgTitle,
$wgOut->mParserOptions, true);
    $output = $parsed->getText();
     return $output;
}


Of course your should have a look at the code from the editsection page.

Hope this helps

François

Marcel de Ruiter wrote:
> Hi there,
>    
>   Could anyone out here please provide my the syntax used to embed a section of a page in another page. I tried several ways but they all fail. Embedding a page does work: {{:pagename}}.
>    
>   Thanks.
>    
>   Best regards,
>    
>   Marcel
> 
> 		
> ---------------------------------
> How much free photo storage do you get? Store your holiday snaps for FREE with Yahoo! Photos. Get Yahoo! Photos




More information about the MediaWiki-l mailing list