Blog.php
From Fxp Wiki
Demo
Explanation
Mon extension blog pour mediawiki, est utilisée surtout pour agréger les citations. On notera que j'ai dû procéder à des ajustements importants pour éviter les boucles infinies: suspendre la gestion des liens, et effacer les liens de catégories dans les entrées insérés. Comme toute extension, elle doit aussi être déclarée dans LocalSettings.php
My mediawiki blog extension is mainly used to aggregate quotes. It aggregates backlinks pages with a Category condition.
For exemple: in Knowledge, I want to see all the pages with a link to Knowledge, and which belong to Category:Quote (to exclude the other pages)
The text of the page Knowledge, will contain:
<blog>page=Knowledge;cat=Quote</blog>
(here the page attribute could be omitted)
Thus, a quote is written just once, and appears nevertheless in the book in the chapter, in all the notions where it links to(as long as these pages contains the blog tag).
Note that, to avoid infinite loops, I had to suspend the links manager and remove the category links in the included entries.
(here are the two lines)
$wgLinkCache->suspend(); $mytext .= preg_replace("#\[\[Category:[^\[.]*?\]\]#","",$row->cur_text);
<?php $wgExtensionFunctions[] = "wfBlogExtension"; function wfBlogExtension() { global $wgParser; $wgParser->setHook( "blog", "renderExample" ); } function renderExample( $input ) { //$output = wfSpecialWhatlinkshere2("Code3"); 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['page'])){ $pageTitle = $arguments['page']; } if (isset($arguments['cat'])){ $cat = $arguments['cat']; } /* $output .= "<br />PageTitle: $pageTitle"; $output .= "<br />Cat: $cat"; */ $output .= wfblogList($pageTitle,$cat); return $output; } function wfblogList($target, $cat='Notions'){ global $wgUseCategoryMagic, $wgUser,$wgParser,$parserOptions,$wgTitle, $wgOut,$wgLinkCache; $pageTitle = $wgTitle->getPrefixedDbKey(); $nt = Title::newFromURL( $target ); $lid = $nt->getArticleID(); $limit = 500; $fname = "wfblogList"; $sql = "SELECT cur_id,cur_namespace,cur_title,cur_text, cur_is_redirect FROM links,cur,categorylinks WHERE l_to={$lid} AND l_from=cur_id AND cl_from=cur_id AND cl_to='$cat' LIMIT $limit"; $res = wfQuery( $sql, DB_READ, $fname ); /* $mytext.=("<br />"); $mytext.=("{$sql}"); $mytext.=("<br />"); */ if ( 0 == wfNumRows( $res ) ) { if ( 0 == $level ) { $mytext.=( wfMsg( "nolinkshere" ) ); } return; } if ( 0 == $level ) { } $isredir = " (" . wfMsg( "isredirect" ) . ")\n"; $mytext .=" __NOEDITSECTION__ \n"; $mytext .="<h6 style=\"display:none\"> </h6>"; while ( $row = wfFetchObject( $res ) ) { $entryT = $row->cur_title; if (!($row->cur_title == $pageTitle )){ if( !$nt ) { continue; } if ( $row->cur_is_redirect ) { $extra = "redirect=no"; } else { $extra = ""; } //$mytext .= "\n<h1 class=\"entryTitle\">$entryT</h1>\n<div class=\"editsection\" style=\"float: right; margin-left: 5px;\">[<a href=\"/mediawiki/index.php?title=$entryT&action=edit\" title=\"$entryT\">edit</a>] [<a href=\"/mediawiki/index.php?title=Talk:$entryT&action=edit&section=new\" title=\"Talk:$entryT\">commentaire</a>]</div><a name=\"Talk:$entryT\"></a>\n"; $mytext .= "<div class=\"blogEntry\" style=\"border-top: 3px solid black; margin-bottom:4em;\"><a name=\"Talk:$entryT\"></a><div class=\"editsection\" style=\"float:right;margin-left: 5px;\">[<a href=\"/mediawiki/index.php?title=$entryT&action=edit\" title=\"$entryT\">edit</a>] [<a href=\"/mediawiki/index.php?title=Talk:$entryT&action=edit&section=new\" title=\"Talk:$entryT\">commentaire</a>]</div>"; $mytext .= preg_replace("#\[\[Category:[^\[.]*?\]\]#","",$row->cur_text); $mytext .= "</div>\n"; if ( $row->cur_is_redirect ) { if ( $level < 2 ) { //wfblogList( $level + 1, $row->cur_id, $limit ); } } } } $wgLinkCache->suspend(); //$wgUseCategoryMagic = false; $parsed = $wgParser->parse( $mytext, $wgTitle, $wgOut->mParserOptions, true); $output .= $parsed->getText(); //$wgLinkCache->resume(); //$wgUseCategoryMagic = true; return $output; } ?>
Credits
Thanks to Rowan Collins who helped me on newsgroup archives, and to Innocence who gave me the final clue in irc wikitech
