Extension:Wikindx

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
Wikindx

Release status: stable

Implementation Tag
Description Enables the insertion of Wikindx citations into MediaWiki articles.
Author(s) Cédric Jeanneret (Cédric Jeannerettalk)
Last version 1.0
MediaWiki 1.12
License GPL
Download No link
Parameters

$wgWikindxPath

Hooks used
ParserFirstCallInit
Check usage and version matrix

Contents

What can this extension do? [edit]

This extension enables the insertion of Wikindx citations into MediaWiki articles via the introduced tag <wikindx>. It can extract a citation of a single resource or list all the citations related to an author or a keyword.

The citation can be used within a <ref> tag provided by the Extension:Cite extension.

Usage [edit]

Simply insert a <wikindx> tag in your article where you want the citation (or the list) to be inserted. To select the citations to be extracted from the Wikindx database, use one (and only one) of the following attribute:

  • resource=id
  • author=id
  • keyword=id

To find the value of these ids, simply clic on a resource, a creator or a keyword in your Wikindx web site. Then, look for the value of the id parameter in the URL. For example, xxx/bibliography/index.php?action=listCreatorProcess&id=225 brings an author id of 225.

If there is more than one resource to display (that is, by using the author or keyword attribute), the ouput is a list of citations. The citation is plain-text whose style is defined by your Wikindx configuration (see below. An external link to the resource page of your Wikindx web site is appended to the citation for a rapid access to attachments or quotes for example.

Examples [edit]

The citation of a particular resource:
<wikindx resource=128/>

All resources created by a particular author:
<wikindx author=36/>

Related resources (tagged with keyword YYY):
<wikindx keyword=24/>

Template [edit]

The passing of parameters to tag extension within templates implies the use of the #tag magicword (see Mediawiki bug #2257).

The following template relies on the <ref> tag provided by the Extension:Cite extension. It brings to your articles references à la BibTeX. The parameter is the resource's id.

{{#tag:ref|{{#tag:wikindx||resource={{{1}}}}}|name=m{{{1}}}}}


Download instructions [edit]

Please cut and paste the code found below and place it in $IP/extensions/Wikindx/Wikindx.php and in $IP/extensions/Wikindx/Wikindx.i18n.php.

Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

Installation [edit]

To install this extension, add the following to LocalSettings.php:

require_once("$IP/extensions/Wikindx/Wikindx.php");
# Wikindx installation path
$wgWikindxPath="http://xxx.xx/yyy/";

For some reason, these lines should be added at the end of your LocalSettings.php file (or, if it is present, just before the ?> tag).

Wikindx must also be correctly configured. In the config.php file of your wikindx installation, makes sure that:

  • $WIKINDX_CMS_ALLOW is set to true.
  • $WIKINDX_CMS_BIBSTYLE is set correctly (it defines the citation style used by this extension).

Configuration parameters [edit]

$wgWikindxPath points to your wikindx installation. Include the trailing slash, but not index.php.

Code [edit]

Wikindx.php

<?php
 
/**
 * Protect against register_globals vulnerabilities.
 * This line must be present before any global variable is referenced.
 */
if( !defined( 'MEDIAWIKI' ) ) {
        echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" );
        die( -1 );
}
 
// Extension credits that will show up on Special:Version   
$wgExtensionCredits['parserhook'][] = array(
        'name'           => 'Wikindx',
        'version'        => '1.0',
        'author'         => 'Cédric Jeanneret',
        'descriptionmsg' => 'wikindx_desc',
        'url' => 'http://www.mediawiki.org/wiki/Extension:Wikindx'
 
);
 
$wgExtensionMessagesFiles['Wikindx'] = dirname(__FILE__) . '/Wikindx.i18n.php';
 
//Avoid unstubbing $wgParser on setHook() too early on modern (1.12+) MW versions, as per r35980
if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) {
        $wgHooks['ParserFirstCallInit'][] = 'efWikindxParserInit';
} else { // Otherwise do things the old fashioned way
        $wgExtensionFunctions[] = 'efWikindxParserInit';
}
 
function efWikindxParserInit() {
        global $wgParser;
        global $wgMessageCache;
 
        $wgParser->setHook( 'wikindx', 'efWikindxRender' );
        return true;
}
 
function efWikindxRender( $input, $args, $parser ) {
 
        global $wgWikindxPath;
 
        wfLoadExtensionMessages('Wikindx');
 
        $parser->disableCache();
 
        if(!isset($wgWikindxPath))
        {
                $output = efError('wikindx_error_pathnotset');
        }
        else if(count($args) != 1)
        {
                $output = efError('wikindx_error_wrongnumberofargs');
        }
        else
        {
                if(isset($args['resource']))
                {
                        $resourceId = $args['resource'];
                        $string = file_get_contents("{$wgWikindxPath}cmsprint.php?action=getResource&id={$resourceId}");
                    if($string)
                {
                                $array = unserialize(base64_decode($string));
                                $output = $array[$resourceId] . " ([{$wgWikindxPath}index.php?action=resourceView&id={$resourceId} ".wfMsg('wikindx_detaillabel')."])";
                        }
                        else
                        {
                                $output = efError('wikindx_error_resourcenotfound', $id);
                        }
                }
 
                else if(isset($args['author']))
                {
                        $authorId = $args['author'];
                        $string = file_get_contents("{$wgWikindxPath}cmsprint.php?action=getCreator&id={$authorId}");
                    if($string)
                {
                        $resources = array();
                                $array = unserialize(base64_decode($string));
                                foreach($array as $resourceId => $item)
                                {
                                        $resources[] = "* " . $item . " ([{$wgWikindxPath}index.php?action=resourceView&id={$resourceId} ".wfMsg('wikindx_detaillabel')."])";
                                }
                                $output = implode("\n",$resources);
                        }
                        else
                        {
                                $output = efError('wikindx_error_authornotfound', $authorId);
                        }
        }
 
                else if(isset($args['keyword']))
                {
                        $keywordId = $args['keyword'];
                        $string = file_get_contents("{$wgWikindxPath}cmsprint.php?action=getKeyword&id={$keywordId}");
                    if($string)
                {
                        $resources = array();
                                $array = unserialize(base64_decode($string));
                                foreach($array as $resourceId => $item)
                                {
                                        $resources[] = "* " . $item . " ([{$wgWikindxPath}index.php?action=resourceView&id={$resourceId} ".wfMsg('wikindx_detaillabel')."])";
                                }
                                $output = implode("\n",$resources);
                        }
                        else
                        {
                                $output = efError('wikindx_error_keywordnotfound', $keywordId);
                        }
        }
 
        else
        {
                $output = efError('wikindx_error_invalidargument');        
        }
    }
 
    return $parser->recursiveTagParse($output);
}
 
function efError($key, $param = null) 
{
        return ('<strong class="error">' . wfMsg('wikindx_error', wfMsg($key,$param)) . '</strong>');
}

Wikindx.i18n.php

<?php
/**
 * Internationalisation file for extension Wikindx.
 *
 * @addtogroup Extensions
 */
 
$messages = array();
 
/** English
 * @author Cédric Jeanneret
 */
$messages['en'] = array(
 
        'wikindx_desc' => 'Enables the insertion of [http://wikindx.sourceforge.net/ Wikindx] citations into [[:meta:mediawiki|MediaWiki]] articles.',
 
        'wikindx_detaillabel' => 'details at Wikindx',
 
        'wikindx_error' => 'Wikindx error: $1',
        'wikindx_error_pathnotset' => 'The path to the Wikindx installation has not been set. Please define the variable $wgWikindxPath in localsettings.php.',
        'wikindx_error_wrongnumberofargs' => 'Too many or too few attributes. Please specify one of the following attributes: resource, author or keyword.',
        'wikindx_error_resourcenotfound' => 'Resource not found: $1',
        'wikindx_error_authornotfound' => 'Author not found: $1',
        'wikindx_error_keywordnotfound' => 'Keyword not found: $1',
        'wikindx_error_invalidargument' => 'Invalid attribute. Please specify one of the following attributes: resource, author or keyword.',
);

See also [edit]

The citations produced by this extension can be used within a <ref> tag provided by the Extension:Cite extension.

Wikindx is a free bibliographic and quotations/notes management web application.

This extension can be useful for the Wiki Research Bibliography project. The extension would need some modification to extract resource based on a creation year.