User Tools

Site Tools


Dokuwiki Bookmarklet

Goal: I want to be able to add bookmarks/links easily from my web browser to the Read it later page on this wiki.

See it in action:

Inspired by Shaarli's bookmarklet, I created this javascript laden anchor tag on a blank HTML page:

<a title="Drag this link to your bookmarks toolbar or right-click it and Bookmark This Link, then click ✚read it later button in any page you want to add to your wiki" class="bookmarklet-link" href="javascript:(
function() {
)();">✚ read it later</a>

I can drag this onto my bookmarks bar and use on any subsequent pages I visit.

It calls some simple PHP that shows a form that appends a link to the raw file in the dokuwiki data directory (this still keeps all the wiki history - it's marked as an 'external edit').

<style type='text/css'>
h1,h2 {
        text-align: center;
input,textarea {
        width: 100%;
        padding: 0.5em;
input[type=submit] {
        width: 50%;
        padding: 1em;
textarea {
        height: 6em;
        margin-bottom: 1em;
div.buttonbar {
        text-align: center;
$auth_token = "PUT_THE_TOKEN_HERE"; // this should be the one you specify in the bookmarklet above
if(!empty($_REQUEST['save_bookmark'])) {
        if(!empty($_REQUEST['auth_token']) and $_REQUEST['auth_token'] == $auth_token) {
                $filename = "/var/lib/dokuwiki/farm/";
                $string = "  * ";
                if($_REQUEST['title_to_save'] == $_REQUEST['url_to_save']) {
                        $string .= $_REQUEST['url_to_save'];
                } else {
                        $string .= $_REQUEST['url_to_save']." (".$_REQUEST['title_to_save'].")";
                        $string .= " - ".$_REQUEST['desc_to_save'];
                $string .= " [".date("Y-m-d H:i", strtotime('now'))."]";
                $string .= "\n";
                file_put_contents($filename,$string, FILE_APPEND);
        <script type='text/javascript'>window.close();</script>
} else {
        if(empty($_REQUEST['auth_token']) or $_REQUEST['auth_token'] != $auth_token) {
                echo "Access denied.";
        } else {
                <form method='post'>
                <input type='hidden' name='auth_token' value="<?= $auth_token; ?>" />";
                <h1>Read it later</h1>
                <input type='text' name='url_to_save' value="<?= $_REQUEST['post']; ?>" />
                <input type='text' name='title_to_save' value="<?= $_REQUEST['title']; ?>" />
                <textarea name='desc_to_save'><?= $_REQUEST['description']; ?></textarea>
                <div class='buttonbar'>
                <input type='submit' name='save_bookmark' value='Save &amp; Close' />

I know the auth token is in the video - that's the test token, and it's not at that URL :P

I think I might work on something similar next that will allow you share a link directly to a Matrix channel.

dokuwiki_bookmarklet.txt · Last modified: 2020/07/14 03:18 by admin