User:Fxparlant/Blog
From Meta, a Wikimedia project coordination wiki
My contributions are currently really diminished because
Club-internet,
from T-online
IS NOT WORKING PROPERLY !!
in PERIGUEUX
Client: 2620140
[edit] Notice
My mediawiki blog extension is mainly used to aggregate quotes. It aggregates backlinks pages with a Category condition.
For example: 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);
As for any extension, it must be declared in your LocalSettings.php.
See it work: under the list of seminars dates, find the aggregation of pages linked to this seminar's year.
[edit] Code
<?php
$wgExtensionFunctions[] = "wfBlogExtension";
function wfBlogExtension() {
global $wgParser;
$wgParser->setHook( "blog", "renderExample" );
} function renderExample( $input ) {
global $wgTitle;
$pageTitle = $wgTitle->getPrefixedDbKey();
//Get parameters
$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 .= 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 );
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 .= "<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§ion=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();
$parsed = $wgParser->parse( $mytext, $wgTitle, $wgOut->mParserOptions, true);
$output .= $parsed->getText();
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