wikindx plugin

wikindx plugin by Andreas Wagner
interact with a wikindx site (see wikindx.sf.net)

Last updated on 2008-11-26. Provides Syntax.
No compatibility info given!

Similar to refworks.

Tagged with bibliography, quotes, references, wikindx.

    usage

    you can call on the wikindx site to give you a nice reference by putting {{wikindx>id}} in your text, where id is the resource id from the wikindx database (okay, these are not very intuitive, but you need not much digging to find them).

    You can specify particular sections in that resource like this: {{wikindx>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 ;: {{wikindx>1234:1-4;5678:chapter 5}}.

    Now you can also use a tag {{wikindxbib}} to have it output a list of all references used on this page.

    Update 2008-11-26: With the version at the bottom, now you can use {{wxbib}} and {{wxcite>id}} instead of {{wikindxbib}} and {{wikindx>id}} respectively. Also, you can now use {{wxnote>id}} to display the note of the resource with the id “id”. On the other hand, this only works if you make some modifications wo wikindx's cmsprint.php and core/cms/CMS.php…

    syntax.php

    You have to specify the wikindx site in the WKX_URL variable in the class syntax_plugin_wikindx. Citation formatting is done by the configuration of the wikindx site…

    Old version:

    <?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>
    *
    * TODO: SECURITY checking!!!
    *       Provide switch to not insert a citation into the tracking array
    *       Also directly access notes, quotes, musings etc., authors, categories, lists etc.
    *
    */
     
    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://my-wikindx.site/';
     
        //Report module information
        function getInfo()
        {
            return array(
                    'author' => 'Andreas Wagner',
                    'email'  => 'Andreas.Wagner@em.uni-frankfurt.de',
                    'date'   => '2008-05-27',
                    'name'   => 'Wikindx Citation Module',
                    'desc'   => 'Insert citations as links to a Wikindx wiki (and have that format the text used as link)',
                    'url'    => 'http://www.dokuwiki.org/plugin:wikindx',
            );
        }
     
        function getType()  { return 'substition'; }
     
        // Just after build in links
        function getSort()  { return 217; }
     
        // Grab everything between {{wikindx> and }}  (resp. grab {{wikindxbib}})
        function connectTo($mode)
        {
            $this->Lexer->addSpecialPattern('\{\{(?:wikindxbib|wikindx>[^}]*?)\}\}',$mode,'plugin_wikindx');
        }
     
        /**
         * Handle the match
         */
        function handle($match, $state, $pos, &$handler)
        {
            global $WKX_USED_IDS;
            if($match=='{{wikindxbib}}')
            {
                    $callingmodus="bib";
                    $ids=array_unique($WKX_USED_IDS);
            }
            else
            {
                    $callingmodus="cite";
                    $data = trim(substr($match,10,-2));     // strip '{{wikindx>' from start and '}}' from end
                    $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;
                    $linkUrl[] = $this->WKX_URL . "index.php?action=resourceView&id=" . $resId;
                    $queryUrl  = $this->WKX_URL . "cmsprint.php?action=getResource&id=" . $resId;
                    $html  = $http->get($queryUrl);
                    if(!empty($html))
                    {
                            $array = unserialize(base64_decode($html));
                            foreach($array as $rid => $item)
                            {
                                    $resourceHtml[] = $item;
                            }
                    }
            }
            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 .= "; ";
                    if($data[4][$i]=="bib")
                            $output .= "<br />";
            }
            $renderer->doc .= $output;
            return true;
        }
    }
     
    //Setup VIM: ex: et ts=4 enc=utf-8 :

    New Version 2008-11-26:

    <?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>
    *
    * TODO: 
    * 	SECURITY checking!!!
    *       Provide switch to not insert a citation into the tracking array
    * 	Provide switch to only insert a short citation
    *	Allow inclusion of quotes/musings etc.
    * 	Allow to put bibliography before all the citations? 
    *
    */
     
    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://my-wikindx.site/';
     
        //Report module information
        function getInfo()
        {
            return array(
                    'author' => 'Andreas Wagner',
                    'email'  => 'Andreas.Wagner@em.uni-frankfurt.de',
                    'date'   => '2008-11-26',
                    '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 'substition'; }
     
        // Just after build in links
        function getSort()  { return 217; }
     
        // Grab everything between {{wikindx> and }}  (resp. grab {{wikindxbib}})
        function connectTo($mode)
        {
    //        $this->Lexer->addSpecialPattern('\{\{(?:wikindxbib|wikindx>[^}]*?)\}\}',$mode,'plugin_wikindx');
            $this->Lexer->addSpecialPattern('\{\{(?:wikindxbib|wxbib|wikindx>[^}]*?|wxcite>[^}]*?|wxnote>[^}]*?)\}\}',$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 '{{wxcite>':
    		    $callingmodus="cite";
    		    $data = trim(substr($match,9,-2));     // strip '{{wikindx>' from start and '}}' from end
    		    break;
    		case '{{wikindx>':
    		    $callingmodus="cite";
    		    $data = trim(substr($match,10,-2));     // strip '{{wikindx>' from start and '}}' from end
    		    break;
    		case '{{wxnote>':
    		    $callingmodus="note";
    		    $data = trim(substr($match,9,-2));     // strip '{{wikindx>' 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;
                    $linkUrl[] = $this->WKX_URL . "index.php?action=resourceView&id=" . $resId;
    		switch($callingmodus) {
    		    case 'note':
    			$queryUrl  = $this->WKX_URL . "cmsprint.php?action=getNote&id=" . $resId;
    			$htmlIsCoded = FALSE;
    			$htmlIsArray = FALSE;
    			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;
    			}
                    }
            }
            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 .= "; ";
                    if($data[4][$i]=="bib")
                            $output .= "<br />";
            }
            $renderer->doc .= $output;
            return true;
        }
    }
     
    //Setup VIM: ex: et ts=4 enc=utf-8 :

    wikindx3 diff in order to get the new Version 2008-11-26 to work:

    --- cmsprint.php.old	2008-04-15 10:42:00.000000000 +0200
    +++ cmsprint.php	2008-11-26 23:33:09.000000000 +0100
    @@ -38,7 +38,7 @@
     include_once("core/sql/SQL.php");
     $db = new SQL();
     
    -// Check if request is to parse text for [cite]...[/cite tags
    +// Check if request is to parse text for [cite]...[/cite] tags
     if(($_GET['action'] == 'parseText') && (!array_key_exists('address', $_GET) || !$_GET['address']))
     	die('Missing or incorrect queryString');
     else if($_GET['action'] == 'parseText')
    @@ -55,7 +55,21 @@
     list($sql, $limit) = CMS::getSql($db);
     // Force HTTP to UTF-8 charset overriding any AddDefaultCharset set in Apache.
     @header('Content-type: text/html; charset=utf-8');
    -print CMS::queryDb($db, $sql, $WIKINDX_CMS_BIBSTYLE, $limit);
    +// old: print CMS::queryDb($db, $sql, $WIKINDX_CMS_BIBSTYLE, $limit);
    +
    +if($_GET['action']=='getNote') {
    +    include_once("core/html/HTML.php");
    +    $html = new HTML();
    +    $resultset = $db->query($sql);
    +    $resultrow = $db->fetchrow($resultset);
    +    print "Note: " . $html->dbToHtmlTidy($resultrow['text']);
    +}
    +else
    +//if(array_key_exists('mode', $_GET) && $_GET['mode'] == 'bib')
    +	print CMS::queryDb($db, $sql, $WIKINDX_CMS_BIBSTYLE, $limit, "bib");
    +//elseif(array_key_exists('mode', $_GET) && $_GET['mode'] == 'cite')
    +//	print CMS::queryDb($db, $sql, $WIKINDX_CMS_BIBSTYLE, $limit, "cite");
    +
     die;
     
     /**
    --- core/cms/CMS.php.bak	2008-11-26 14:42:00.000000000 +0100
    +++ core/cms/CMS.php	2008-11-26 23:19:07.000000000 +0100
    @@ -269,14 +269,15 @@
     		include_once("core/sql/STATEMENTS.php");
     		$stmt = new STATEMENTS($db);
     		$join = $condition = FALSE;
    -		if($_GET['action'] == 'getResource')
    -		{
    +		$sql = "";
    +
    +		switch($_GET['action']) {
    +		    case 'getResource':
     			$condition = ' WHERE WKX_resource.id=' . join(' OR WKX_resource.id=', $ids);
     // Ignore limit in this case
     			unset($_GET['limit']);
    -		}
    -		else if($_GET['action'] == 'getCategory')
    -		{
    +			break;
    +		    case 'getCategory':
     			$join = " LEFT JOIN " . 
     				$db->formatTable("WKX_resource_category") . " ON " . 
     				$db->formatField("WKX_resource.id") . "=" . 
    @@ -285,9 +286,17 @@
     			foreach($ids as $id)
     				$set[] = "FIND_IN_SET(" . $id . ", CONCAT(" . $db->formatField('categories') . ", ',')" . ")";
     			$condition = " WHERE (" . join(')' . $sqlMethod . '(', $set) . ')';
    -		}
    -		else if($_GET['action'] == 'getKeyword')
    -		{
    +			break;
    +		    case 'getNote':
    +			$sql = $db->selectNoExecute(array("WKX_resource_note"), array("text"), "WHERE id=" . $_GET['id']);
    +//				$db->formatField("WKX_resource_note.id");
    +// NB MySQL bug: http://bugs.mysql.com/bug.php?id=2047 -- append comma temporarily
    +//			foreach($ids as $id)
    +//				$set[] = "FIND_IN_SET(" . $id . ", CONCAT(" . $db->formatField('text') . ", ',')" . ")";
    +//			$condition = " WHERE (" . join(')' . $sqlMethod . '(', $set) . ')';
    +			break;
    +//			die('bailing out - but correct case');
    +		    case 'getKeyword':
     			$join = " LEFT JOIN " . 
     				$db->formatTable("WKX_resource_keyword") . " ON " . 
     				$db->formatField("WKX_resource.id") . "=" . 
    @@ -296,9 +305,8 @@
     			foreach($ids as $id)
     				$set[] = "FIND_IN_SET(" . $id . ", CONCAT(" . $db->formatField('keywords') . ", ',')" . ")";
     			$condition = " WHERE (" . join(')' . $sqlMethod . '(', $set) . ')';
    -		}
    -		else if($_GET['action'] == 'getCreator')
    -		{
    +			break;
    +		    case 'getCreator':
     // NB MySQL bug: http://bugs.mysql.com/bug.php?id=2047 -- append comma temporarily
     			foreach($ids as $id)
     				$set[] = "
    @@ -313,9 +321,8 @@
     				FIND_IN_SET(" . $id . ", CONCAT(" . 
     					$db->formatField('creator5') . ", ','))";
     			$condition = " WHERE (" . join(')' . $sqlMethod . '(' , $set) . ')';
    -		}
    -		else if($_GET['action'] == 'getPublisher')
    -		{
    +			break;
    +		    case 'getPublisher':
     // 'proceedings_article' resource type has publisher in 'miscField1' (if publisher exists)
     			foreach($ids as $id)
     				$set[] = "IF(" . 
    @@ -324,12 +331,12 @@
     				$db->formatField('miscField1') . '=' . $id . ',' . 
     				$db->formatField('publisher') . '=' . $id . ')';
     			$condition = " WHERE " . join(' OR ' , $set);
    -		}
    -		else if($_GET['action'] == 'getCollection')
    +			break;
    +		    case 'getCollection':
     			$condition = ' WHERE ' . $db->formatField('collection') . '=' . 
     				join(' OR ' . $db->formatField('collection') . '=', $ids);
    -		else if($_GET['action'] == 'getRecent')
    -		{
    +			break;
    +		    case 'getRecent':
     			if(array_key_exists('days', $_GET))
     			{
     				$days = $_GET['days'];
    @@ -340,9 +347,11 @@
     				$condition = FALSE;
     			$order = 'timestampAdd';
     			$stmt->ascDesc = 'DESC';
    -		}
    -		else
    +			break;
    +		    default:
     			die('Missing or incorrect queryString');
    +		}
    +
     		if(!isset($order))
     		{
     // 'creator' is order default
    @@ -352,6 +361,7 @@
     			else
     				$order = 'creator';
     		}
    +		if(!$sql)
     		$sql = $db->selectNoExecute(array("WKX_resource"),  
     			$stmt->listFields($order), $stmt->listJoin($order, $join . $condition));
     //print "$sql<P>";
    
     
    plugin/wikindx.txt · Last modified: 2009/10/07 14:07 by laynee
     
    Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
    Imprint Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
    WikiForumIRCBugsGitXRefTranslate