AddLinkTagsBookmarklet

Summary: Adding links, selected text and tags from another page to a wiki page
Version: 2017-10-27
Prerequisites: v2.2+
Status: Maintained
License: GPLv2
Maintainer: Said Achmiz
Categories: Links
Users: -1 (view / edit)

Questions answered by this recipe

How can I save a clipping from a web page into my wiki?

Description

Adding links, selected text and tags from another page to a wiki page.

The original Cookbook:AddLinkBookmarklet recipe was useful, but it lacked the ability to tag new links and collect a selection. The Cookbook:Kind-ofBlog? recipe improved on this, but was specialized for the kob journaling system. This is meant to bridge the gap between these.

The first version lacked any sort of customizability, and had a few errors. Also, it necessitated having two different bookmarklets, one for IE, and one for everyone else.

This version goes quite a bit further. Its features include:

  1. The ability to select text to be included in the bookmark.
  2. The ability to add a set of tags to the bookmark.
  3. The ability to configure the format of the bookmark entries on the catching page.
  4. The catching page edit opens in a new tab or window, rather than changing the location of the current tab/window. This is so much better because you can pop back to the sending tab/window if need be without losing your edit.

Installation

Download addlink-tags2.phpΔ to your pmwiki directory and unzip the file. This will put the recipe into the cookbook subdirectory.

Add the following to the local/config.php configuration file:

    ## Enable the AddLink Bookmarklet recipe.
    if ($action == 'edit' || $action == 'browse' || $action == 'addlink') {
      include_once("$FarmD/cookbook/addlink-tags2.php");
    }

Configuration

Configuration options include:

  • $EnableAddLinkToEnd - if set to 1, links will be appended to the page text, otherwise they will be added to the top.
  • $AddLinkFmt - a format specification for how you want the captured link to appear on the capture page.
    • $AddLinkTitle - the title of the linked page
    • $AddLinkUrl - the url of the linked page
    • $AddLinkSelection - the selected text
    • $AddLinkTags - tags given when clipping
    • $AddLinkTime - time link was sent
    • $AddLinkPrefixText - text that should appear before the link
    • $AddLinkSuffixText - text that should appear after the link
  • $AddLinkDefaultCharset - the selection text is converted into HTML entities. The script attempts to detact the character set of the string, but if it fails, the default characters set given in $AddLinkDefaultCharset is used. The default value is 'UTF-8'.

Usage

Creating a capture page

To create a capture page, simply put the bookmarklet markup on the page somewhere: (:addlink:). When you save the page, drag the bookmarklet created to your bookmark toolbar to save and activate it. Once you've done this for your various browsers, there is no need to keep the (:addlink:) markup in the page, although you may want to so you can easily add the bookmarklet for new browsers.

Using the Bookmarklet to Capture Web Pages

Whenever you want to bookmark a page, you can simply click on the bookmarklet when you are viewing the page. You may optionally select some text from the page to be included, and you will be prompted for tags to give the link.

You will then be shown a new window/tab with the landing page in edit mode with the new links either at the top (default) or the bottom (set $EnableAddLinkToEnd to 1 in local/config.php). Your will be formatted as either the default or whatever format you've specified.

The landing page must always be editable by anyone attempting to save a link. This usually means that page must be wide open to edits from everyone. If that concerns you, consider installing a captcha recipe.

Example

Adding links to the end of the page, and specifying a different format for the captured link.

$EnableAddLinkToEnd=1;
$AddLinkFmt="(:linebreaks:)
Link: [[\$AddLinkTitle -> \$AddLinkURL]]
Tags: \$AddLinkTags
Posted: \$AddLinkTime
(:nolinebreaks:)
>>quote<<
(:nolinkwikiwords:)
\$AddLinkSelection
(:linkwikiwords:)
>><<
";
if (in_array($action,array('edit','browse','addlink'))) include_once("$FarmD/cookbook/addlink-tags2.php");

Notes

Change log / Release notes

  • 2017-10-27 Said Achmiz
    • Updated recipe for compatibility with PHP 5.5 & 7.2
    • Updated default link format to current standard link format
    • Fixed bug with $AddLinkTime, it works now (and uses PmWiki's {(ftime)} markup expression, making it customizable via the $FTimeFmt variable)
    • Changed default character set to UTF-8
    • Hitting the Cancel button in either prompt now actually cancels
    • Cleaned up default bookmark format

See also

Contributors

Inspirations:

Comments

See discussion at AddLinkTagsBookmarklet-Talk

User notes -1: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.