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.
<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>
— 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
Hello guys, dokubookmark plugin was not maintained for few years and seems not compatible with the latest version of Dokuwiki “Igor”. I amended the original post2wiki.php code. The code may not look tidy but it works. I posted the code here https://github.com/edwardcodelab/bookmark2wiki and hope if anyone can help to make it better. Thank you.
— edwardcodelab