Bookmarklet

Summary: Make bookmarklet links, make browser toolbar buttons
Version: 1.4
Prerequisites: none
Status: working
Maintainer:
Discussion: Bookmarklet-Talk
Categories: Links BookMarklet

You can add/install a PmWiki action bookmarklet to your browser by dragging a link to your browser toolbar from this page: Bookmarklet Example

Questions answered by this recipe

  • How do I create bookmarklet links on a PmWiki page.
  • I made my PmWiki site look like a web page without the "View Edit History Print" in the upper right. Is there an easier way to edit than typing "?action=edit" at the end of every URL?

Description

It is really useful to place an EDIT button on your toolbar using a bookmarklet. Especially when you have wiki(s) that do not have edit links and look like non-wiki websites. I find that the EDIT button is the most convenient and useful bookmarklet.

You can drag a bookmarklet link from your browser window to your bookmarks or to your bookmarks toolbar. I prefer the bookmarks toolbar because it makes it into a button for you.

This is useful if you have a wiki that you want to look like a web page without the "View Edit History Print" in the upper right. For instance, drag the bookmarklet link "edit" to the browser bookmark toolbar to create an Edit button. To edit a PmWiki page you can now just click the button. This will save you from having to click in the URL box and typing ?action=edit to the end of the url and then pressing enter. A big ergonomic improvement.

So whenever you are in a pmwiki that is more like a web page you are just 1 click away from actions.

  • Do not confuse this recipe with the OtherBookmarklets or the AddLinkBookmarklet recipes. This recipe creates a bookmarklet link on a displayed PmWiki page. OtherBookmarklets only displays the code necessary to create a bookmarklet in your browser, but does not create a link on you PmWiki page. AddLinkBookmarklet uses a PmWiki page to keep links, I seen no relationship to this "Bookmarklet" recipe except for name.
  • This recipe is secure because it only allows authors to reference bookmarklets which are predefined in your config.php or farmconfig.php file.

A working example of bookmarklets can be found at this link: Bookmarklet Example


NOTE: Adding favicons to bookmarklets no longer works - I know of nothing that provides ability to set a bookmarklet favicon in Firefox.

New feature - Included are some new bookmarklet favicons for some PmWiki actions.

Bookmarklets in FireFox are not required to have name text if they have a icon (favicon). If you are happy with just an icon you can remove the name text. To do this first you must add an icon to your bookmarklet. You can install them easily using the freeware utility AM-DeadLink. Then right-click the bookmarklet and select properties from the popup context menu. Then clear the text in the "name" field and click the "OK" button.

You can still download these, but you will not be able to use them in Firefox. I know of nothing that provides ability to set a bookmarklet favicon in Firefox.

Download them here: pm_bookmarklet_favicons.zipΔ

How To Use

There are 2 solutions here. The first one is for ALL PmWiki actions. The second one is for ONE individual bookmarklet. They both work with a wiki farm.

Installing for all actions

Copy Bookmarklet.phpΔ to your cookbook directory

In your config.php enter:

include_once("cookbook/Bookmarklet.php");

or in your farmconfig.php enter:

include_once("$FarmD/cookbook/Bookmarklet.php");

In you PmWiki page put code like this:

[[action:browse|View]]
[[action:edit|Edit]]
[[action:diff|History]]
[[action:upload|Upload]]
[[action:crypt|Crypt]]
[[action:print|Print]]
[[action:search|Search]]
[[action:source|Source]]
[[action:login|Login]]
[[action:logout|Logout]]
[[action:rss|RSS]]
[[action:atom|Atom]]
[[action:rdf|RDF]]
[[action:dc|DC]]
[[action:refcount|RefCount]]
[[action:ruleset|Ruleset]]
[[action:phpinfo|PHPInfo]]
[[action:diag|Diag]]
[[action:attr|Attributes]]

Installing for a single bookmarklet link.

# This is config.php code using Markup alone:

Example 1:
# create custom bookmarklet link
Markup('pmwikiedit', 'directives', '/\\(:pmwikiedit:\\)/',
     Keep("<a href='javascript:location.href+=\"?action=edit\"'>Edit</a>"));

Example 2:
Markup('AllRecentChanges', 'directives', '/\\(:AllRecentChanges:\\)/',
        Keep("<a href='javascript:location.href+=\"?n=Site.AllRecentChanges\"'>See Changes</a>")) ;

Notes

You can create other kinds of bookmarklets by copying the code above and changing the word "action" to something else and by changing the javascript code.

Working example of bookmarklets can be found at this link:

Security

Currently when PmWiki sees "javascript:blahblahblah" in the page source code it just appends it to the end of the current page url. Patrick Michaud said it is not wise to allow wiki authors to use "javascript:blahblahblah" inside of a PmWiki page source because that would be a security risk. Specifically he said 'here's a page that demonstrates some XSS vulnerabilities using "javascript:" ... http://archives.neohapsis.com/archives/fulldisclosure/2005-10/0445.html '. This recipe is secure because it only allows authors to reference bookmarklets which are predefined in your config.php or farmconfig.php file.

Release Notes

  • 1.2 cleaner code, executes only for specific actions
  • 1.1 Added RecipeInfo, made into an includeable script
  • Initial Release

See Also

Contributors

Comments

See discussion at Bookmarklet-Talk

User notes? : 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.