DokuWiki

It's better when it's simple

User Tools

Site Tools


Sidebar

Translations of this page?:

Learn about DokuWiki

Advanced Use

Corporate Use

Our Community


Follow us on Facebook, Twitter and other social networks.

tips:weblog_bookmarklet

How to use your dokuwiki as a Weblog like tool

This little script is for adding quickly time-organised text-clips and urls with a Bookmarklet.

The idea is to have a button in your browser that adds a timestamped page to your wiki with the url,title and selected text of the webpage you visit.

Since doku.php does not allow GET posting we need something to convert it properly and do some formatting.

Now you can use your dokuwiki as a kind of browser-scrapbook/blog.

Please write your experiences in the Notes section of this page.

How to install

  1. Create a file post2wiki.php and put the content below in it. Put in somewhere on your server.
  2. Change the SETUP sections and make sure the $host and $dokuwikipath are set correctly
  3. Make a standard bookmarklet by dragging the following link to your bookmarks (FireFox) or links (IE) toolbar: DOKU THIS! You could get a security warning when doing this…
  4. Take a look at the properties of the DOKU THIS link:
  5. Change the http://myserver/post2wiki.php part of the bookmark to point to your post2wiki.php
  6. strip the http://www.dokuwiki.org/ part from the beginning

The code

<HTML>
<HEAD>
<HEAD>
<BODY>
<STYLE>
  body{background-color:#FFFFFF;border:5px;margin:0px;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:11px;font-weight:normal;color:#000000;}
  a:link{font-family:Verdana,Arial,Helvetica,sans-serif;text-decoration:none;font-size:11px;color:#000099;}
  a:active{font-family:Verdana,Arial,Helvetica,sans-serif;text-decoration:none;font-size:11px;color:#000099;}
  a:hover{font-family:Verdana,Arial,Helvetica,sans-serif;font-size:11px;color:#000099;text-decoration:underline;}
</STYLE>
 
<?php
        /**
	 * post2wiki.php
	 * Dokuwiki content poster to get it act like a weblog
	 * Version 0.1 
	 * todo : check security of input
         * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
         * @author     riny [at] bk [dot] ru
         **/
 
	// TYPICAL USAGE : Create bookmarklet as shown in the bookmarklet part below: 
        //                 Change the window.open statement to reflect the location of the post2wiki.php script.
        //                 Drag bookmarklet to your toolbar.
        //  BOOKMARKLET : 
	//  javascript:Q=document.selection?document.selection.createRange().text:document.getSelection(); void(window.open('http://myserver/post2wiki.php?te='+escape(Q)+'&ur='+ escape(location.href)+'&ti='+escape(document.title),'dokuwikiadd','scrollbars=yes,resizable=yes,toolbars=yes,width=200,height=100,left=200,top=200,status=yes'));
 
	// SETUP SECTION
	$namespace="weblog";  // default namespace for weblog
	$host="localhost";    // servername where your dokuwiki is
	$dokuwikipath="/dokuwiki/doku.php"; //path to your dokuwiki
 
	// POST TO WIKI
	$timestamp = date("Y:m_d_H_i_s"); //Group blogged items per year
	$wikiid=$namespace.":".$timestamp; // the id would become eg "weblog:2005:09_03_22_15"
	$wikitext=$_GET['te'];  // things to log : Selected text
	$url=$_GET['ur'];       // things to log : URL
	$title=$_GET['ti'];     // things to log : title
	$wikitext="====== $title ======\r\n[[$url]]\r\n----\r\n$wikitext";  // do some wiki formatting
	$targeturl="http://$host$dokuwikipath?id=$wikiid"; 
 
	function PostToHost($host, $path, $referer, $data_to_send,$targeturl) {
	  $fp = fsockopen($host, 80);
	  printf("Weblog found...\n");
	  fputs($fp, "POST $path HTTP/1.1\r\n");
	  fputs($fp, "Host: $host\r\n");
	  fputs($fp, "Referer: $referer\r\n");
	  fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
	  fputs($fp, "Content-length: ". strlen($data_to_send) ."\r\n");
	  fputs($fp, "Connection: close\r\n\r\n");
	  fputs($fp, $data_to_send);
	  printf("submitted</h2><br />");
	  while(!feof($fp)) {
		  $res .= fgets($fp, 128);
	  }
	  printf("<hr /><a href='$targeturl'>View/Edit this entry</a><br/><br /><a href=\"javascript:window.close();\">Close this window</a>");
	  fclose($fp);
	  return $res;
	}
 
	$data = "id=$wikiid&wikitext=".stripslashes($wikitext)."&summary=$title&do=save";
	printf("<h3>Contacting server $host...");
	$x = PostToHost($host, $dokuwikipath,$_SERVER['remote_addr'],$data,$targeturl);
?>
</BODY>
</HTML>

Notes

  • I did not test this for UTF-8
  • to copy the link, copy from the source of this page, not from the rendered page :)
    , or just drag the “doku this” link to your link bar

— iDo

the “doku this” link is escaped by dokuwiki:

javascript:Q=document.selection?document.selection.createRange().text:document.getSelection(); void(window.open('http://myserver/post2wiki.php?te='+escape(Q)+'&ur='+ escape(location.href)+'&ti='+escape(document.title),'dokuwikiadd','scrollbars=yes,resizable=yes,toolbars=yes,width=200,height=100,left=200,top=200,status=yes'));

— robin

Thanks for this code - I elaborated a bit on it, worked around the GET/POST issue and am on the way to make a dokuwiki-plugin out of it: http://mir.dnsalias.com/wiki/dokubookmark released dokubookmark into the wild.

— robin

tips/weblog_bookmarklet.txt · Last modified: 2008/07/24 18:21 by 83.98.240.212