DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:wikindx

wikindx plugin

Compatible with DokuWiki

  • 2013-12-08 "Binky" unknown
  • 2013-05-10 "Weatherwax" unknown
  • 2012-10-13 "Adora Belle" yes
  • 2012-01-25 "Angua" unknown

plugin interact with a wikindx site

Last updated on
2013-01-21
Provides
Syntax

Similar to refworks

Tagged with bibliography, quotes, references, wikindx

This plugin allows you to call on the wikindx site (see http://wikindx.sf.net) to give you a nice reference, display quotes and provide the list of references accessed in this way. It can be seen in action on http://www.commontology.de/polphil/literatur/einbindung_der_literaturdatenbank (german).

Usage

Functions that work with wikindx4 v4.1

References

By putting things like {{wxcite>id}} in your text (where id is the resource id from the wikindx database), a reference to this work is displayed.

You can specify particular sections in that resource like this: {{wxcite>12345:place}}, where place can be a page number, a range of pages, a roman number, etc. just anything except for }} and ;.

You can specify several resources by separating them with a semicolon (';') like this: {{wxcite>1234:1-4;5678:chapter 5}}.

Bibliography

To create a list of all references used on this page, use the tag {{wxbib}} at the end of the page (i.e. after all the works that you want included have been cited).

Functions that, as of 2013-01-21, need the svn version of wikindx

Abstract, Notes

You can use {{wxnotes>id}} and {{wxabstract>id}} to display the notes and abstract fields of the resource with the id “id”.

Quotes, Musings, Paraphrases

You can display quotes and such like this: {{wxquote>id:number}}, {{wxmusing>id:number}}, {{wxparaphs>id:number}}. Here id is the id of the quoted/paraphrased work again, and when 'number' is present (need not be), it should provide a possibility to select which one of several quotes/musings etc. should be displayed.

Except for Quotes, these have not been tested; and even the Quotes functionality has not been tested very thoroughly (e.g. the selection between multiple quotes has not been tested at all).

Configuration

You have to specify the wikindx site in the WKX_URL variable in the class syntax_plugin_wikindx. Also, of course your wikindx site must be set up so as to allow CMS interaction. Citation formatting is done by the configuration of the wikindx site…

License

This plugin is licensed under the terms of the GNU General Public License version 2.

Changes

(The older tags {{wikindxbib}} and {{wikindx>id}} are deprecated. They are still working, but will be phased out in future versions.)

  • 2013-01-21 – The wikindx4 developer has included some of the modifications suggested by this plugin into the development version. (Thanks a lot for this!) So instead of patching the released version, it is recommended to check out and use the svn version of wikindx4.
  • 2013-01-16 – Update for dokuwiki Release 2012-10-13 “Adora Belle” and wikindx v4.1. Also, there's new functionality: I have added the actions getAbstract, getNotes, getQuote, getParaphr, getMusing.

To Do

  • Testing. Also, see what happens with several quote/musing/etc entries?
  • Security checks!: mysql_real_escape_string when entering and html_specialchars when reading from the db.
  • Provide switch to not insert a citation into the tracking array
  • Provide switch to only insert a short citation (via wikindx's bibstyle parameter?)
  • Allow to put bibliography before all the citations?
  • Attachments/URLs (these can be several entries per resource)
  • Improve handling of closing periods.

Code

syntax.php

Here is the plugin, ver 2013-01-21:

<?php
/**
* Wikindx Citation Module
* Derived from: Refworks Plugin by Daniel Terry, Amazon Plugin by Andreas Gohr
*
* @license    GPL (http://www.gnu.org/licenses/gpl.html)
* @author     Andreas Wagner <Andreas.Wagner@em.uni-frankfurt.de>
*
* Online Resources:
*   https://www.dokuwiki.org/plugin:wikindx
*   http://www.commontology.de/polphil/literatur/einbindung_der_literaturdatenbank
*
* CHANGELOG:
*
*
*    2013-01-21: Update to take advantage of wikindx4 svn changes rather than 
*                  patch it myself (patch hence no longer needed).
*    2013-01-16: Update for dokuwiki Release 2012-10-13 "Adora Belle" and 
*                  wikindx v4.1.
*                  (wikindx4's cmsprint.php provides the following actions out 
*                     of the box: getResource, getCategory, getSubcategory, 
*                     getKeyword, getCreator, getPublisher, getCollection, 
*                     getRecent.
*                   Optional parameters are:
*                     limit, days, order, sqlMethod(=and), bibstyle)
*                New functionality: I have added these actions:
*                   getAbstract, getNotes, getQuote, getParaphr, getMusing.
*
* TODO:
*     + Testing. Also, see what happens with several quote/musing/etc
*       entries?
*     + SECURITY checking!!!: Einzutragende Daten mit mysql_real_escape_string 
*       drübergehen und beim auslesen mit html_specialchars
*     + Provide switch to not insert a citation into the tracking array
*     + Provide switch to only insert a short citation (via wikindx's bibstyle 
*       parameter?)
*     + Allow to put bibliography before all the citations?
*     + Attachments/URLs (these can be several entries per resource)
*     + Improve handling of closing periods.
*
*
*/
 
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
 
/* have an array ready to keep track of all cited works on the page */
global $WKX_USED_IDS;
 
/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class syntax_plugin_wikindx extends DokuWiki_Syntax_Plugin
{
    var $WKX_URL = 'http://here.goesyour.site/wikindx4/';
 
    //Report module information
    function getInfo()
    {
        return array(
                'author' => 'Andreas Wagner',
                'email'  => 'Andreas.Wagner@em.uni-frankfurt.de',
                'date'   => '2013-01-21',
                'name'   => 'Wikindx Citation Module',
                'desc'   => 'Insert citations as links to a Wikindx wiki (and have that format the text used as link)',
                'url'    => 'http://wiki.splitbrain.org/plugin:wikindx',
        );
    }
 
    function getType()  { return 'container'; }
 
    // Allow recursing
     function getAllowedTypes() { return array("container","substition","formatting","protected","disabled","paragraphs"); }
 
    // Just after build in links
    function getSort()  { return 217; }
 
    // Grab everything between {{wikindx> and }}  (resp. grab {{wikindxbib}})
    function connectTo($mode)
    {
        $this->Lexer->addSpecialPattern('\{\{(?:wikindxbib|wxbib|wikindx>[^}]*?|' .
                                               'wxcite>[^}]*?|' .
                                               'wxabstract>[^}]*?|' .
                                               'wxnotes>[^}]*?|' .
                                               'wxquote>[^}]*?|' .
                                               'wxparaphr>[^}]*?|' .
                                               'wxmusing>[^}]*?|' .
                                           ')\}\}',$mode,'plugin_wikindx');
    }
 
    /*
     * Handle the match
     */
    function handle($match, $state, $pos, &$handler)
    {
        global $WKX_USED_IDS;
          if ($match=='{{wikindxbib}}' || $match=='{{wxbib}}') {
                $callingmodus="bib";
                $ids=array_unique($WKX_USED_IDS);
          } else {
              switch(substr($match, 0, strpos($match, '>')+1)) {
                case '{{wikindx>':
                    $callingmodus="cite";
                    $data = trim(substr($match,10,-2));     // strip '{{wikindx>' from start and '}}' from end
                    break;
                case '{{wxcite>':
                    $callingmodus="cite";
                    $data = trim(substr($match,9,-2));      // strip '{{wxcite>' from start and '}}' from end
                    break;
                case '{{wxabstract>':
                    $callingmodus="abstract";
                    $data = trim(substr($match,13,-2));     // strip '{{wxabstract>' from start and '}}' from end
                    break;
                case '{{wxnotes>':
                    $callingmodus="notes";
                    $data = trim(substr($match,10,-2));      // strip '{{wxnotes>' from start and '}}' from end
                    break;
                case '{{wxquote>':
                    $callingmodus="quote";
                    $data = trim(substr($match,10,-2));     // strip '{{wxquote>' from start and '}}' from end
                    break;
                case '{{wxparaphr>':
                    $callingmodus="paraphr";
                    $data = trim(substr($match,12,-2));     // strip '{{wxparaphr>' from start and '}}' from end
                    break;
                case '{{wxmusing>':
                    $callingmodus="musing";
                    $data = trim(substr($match,11,-2));     // strip '{{wxmusing>' from start and '}}' from end
                    break;
              }
              $data = trim($data,";");               //remove trailing ;
              $ids = split(";",$data);
          }
 
        //Error checking??
        //if (!$data) {
        //    trigger_error('Bad Things happening: '.htmlspecialchars($match), E_USER_WARNING);
        //    return FALSE;
        //}
 
        //Lookup data
        $http = new DokuHTTPClient();
        foreach($ids as $id)
        {
            list($resId,$page) = explode(':',$id);
            if($callingmodus!="bib")
                $WKX_USED_IDS[] = $resId;
            $callmode[] = $callingmodus;
            $resourceId[] = $resId;
            $pages[] = $page;
            switch($callingmodus) {
                case 'abstract':
                   $queryUrl  = $this->WKX_URL . "cmsprint.php?action=getAbstract&id=" . $resId;
                   $htmlIsCoded = TRUE;
                   $htmlIsArray = TRUE;
                   break;
                case 'notes':
                   $queryUrl  = $this->WKX_URL . "cmsprint.php?action=getNotes&id=" . $resId;
                   $htmlIsCoded = TRUE;
                   $htmlIsArray = TRUE;
                   break;
                case 'quote':
                   if(!$page)
                       $page=0;
                   else
                       $page=$page-1;
                   $queryUrl  = $this->WKX_URL . "cmsprint.php?action=getQuote&id=" . $resId;
                   $html = $http->get($queryUrl);
                   $resultarray = unserialize(base64_decode($html));
                   // the array looks like resId -> quote, details, comments[]
                   // so it can be used also for more verbose purposes.
// print_r($resultarray);
// print_r($resultarray[$resId]['quotes'][$page]['quote']);
                   $resourceHtml[] = $resultarray[$resId]['quotes'][$page]['quote'];
                   $pages = "";                                                         // don't append number to quote.
                   break;
                case 'paraphr':
                   if(!$page)
                       $page=0;
                   else
                       $page=$page-1;
                   $queryUrl  = $this->WKX_URL . "cmsprint.php?action=getParaphrase&id=" . $resId;
                   $html = $http->get($queryUrl);
                   $resultarray = unserialize(base64_decode($html));
                   $resourceHtml[] = $resultarray[$resId]['paraphrases'][$page]['paraphrase'];
                   $pages = "";
                   break;
                case 'musing':
                   if(!$page)
                       $page=0;
                   else
                       $page=$page-1;
                   $queryUrl  = $this->WKX_URL . "cmsprint.php?action=getMusing&id=" . $resId;
                   $html = $http->get($queryUrl);
                   $resultarray = unserialize(base64_decode($html));
                   $resourceHtml[] = $resultarray[$resId]['musings'][$page]['musing'];
                   $pages = "";
                   break;
                case 'cite':
                default:
                   $queryUrl  = $this->WKX_URL . "cmsprint.php?action=getResource&id=" . $resId;
                   $htmlIsCoded = TRUE;
                   $htmlIsArray = TRUE;
            }
            $html = $http->get($queryUrl);
            if(!empty($html)) {
                if($htmlIsCoded)
                    $html = base64_decode($html);
                if(!$htmlIsArray) {
                    $resourceHtml[] = $html;
                } else {
                    $array = unserialize($html);
                    foreach($array as $rid => $item)
                       $resourceHtml[] = $item;
                }
            }
            $linkUrl[] = $this->WKX_URL . "index.php?action=resource_RESOURCEVIEW_CORE&id=" . $resId;
        }
 
        // replace wikindx's own crossref tags (e.g. [cite]2166:37[/cite]) with this plugin's ({{wxcite>2166:37}}
        // to prepare for recursing
        $resourceHtml = preg_replace(array("#\[cite]#i","#\[/cite]#i"), array("{{wxcite>","}}"), $resourceHtml);
 
        return array($resourceId, $resourceHtml, $pages, $linkUrl, $callmode);
    }
 
    /**
     * Create output
     */
    function render($mode, &$renderer, $data)
    {
        if($mode != 'xhtml')  { return false; }
 
        global $WKX_USED_IDS;
        $output = "";
 
        for($i=0;$i<count($data[0]);$i++)
        {
                $output .= "<a href=\"" . $data[3][$i] . "\">" . trim($data[1][$i],".");
                if($data[2][$i])
                    $output .= ", " . $data[2][$i];
                $output .= "</a>";
                if(($data[4][$i]=="cite") AND ($i < count($data[0]) -1))
                    $output .= "; ";
                else
                    $output .= ".";
                if($data[4][$i]=="bib")
                        $output .= "<br />";
        }
        $renderer->doc .= $output;
        return true;
    }
}
 
//Setup VIM: ex: et ts=4 enc=utf-8 :
plugin/wikindx.txt · Last modified: 2013/01/21 19:58 by awagner