FastBacklinks

Note: Starting with release 2.0.4, PmWiki has a built-in link indexing system (inspired by this one).

Questions

What can I do to make pages in my Category group load faster, and finally stop annoying me? How can I make PmWiki find backlinks faster?

Answer

The Attach:FastBacklinks.php scripts is a PmWiki plugin, which significantly improves PmWiki's backlinks listing speed (when used with a special (:backlinks:) markup). This way also pages in your Category group can load much faster, finally making Categories really useful.

Description

This script's goal is to make all backlinks in PmWiki load much faster, and thus to extinguish frustration rising when waiting for some pages to generate, especially the Categories pages.

The scripts provides you with a new directive - (:backlinks:), which should be used in place of the: (:pagelist link={$Group}.{$Page}:) directive. This directive generates a sorted index of all regular pages linking to that page.

For example, if each of pages: `Test.Foo, `Test.Bar and `Test.Third contains a link to `Category.Test, the (:backlinks:) directive on the `Category.Test page will render a list similar to the one below:

Test.Bar
Test.Foo
Test.Third?

Additionally, you're provided with a new action you can use to show pages linking to any page you want. Just open the page links to which you want to see in your browser, and add: '?action=fastbacklinks' in your browser's address bar to see the list.

Important Note:

Unfortunately, there's one small drawback considering the script's usage. When rendering the (:backlinks:) directive, the scripts shows only those pages, which were modified or created after the script was turned on (by the include_once(...) line in config.php). Therefore, you should manually touch every page listed before by the (:pagelist:) directive. When doing that, please note, that PmWiki is very smart, and it notices if you save a page not changing it at all - therefore you must at least add some empty line in a page to force it to do the save. Note however, that there is no such problem if installing the recipe on a brand new Wiki installation - as all pages will be created after the installation, and thus every link will be correctly noticed.

Upgrade: I've created a Attach:FastBacklinks-starter.php script, which aims to do this 'manual touching' work for you in an automated way. However, the script is, unfortunately, not guaranteed to complete it's work, especially if your wiki is very large. Please, note below your experience with this script for further users, writing also your Wiki size (in kilobytes and number of pages, possibly) and script's work time. I may consider implementing a different approach to the pre-generation (dividing it into some pieces, or other you'd suggest) based on the feedback. Usage instructions for this script are below, in section Installation.
Note also, that the script is written to work as fast as possible; the side effect is, that the backlinks lists will be unsorted at first (but they will sort as soon as they change).

Installation

Step 1 - The Script

  1. download the file Attach:FastBacklinks.php and save it in your cookbook directory,
  2. activate the plugin by adding the line below to your 'local/config.php' file,
    include_once( 'cookbook/FastBacklinks.php' );
  3. open any page of your Wiki, and follow the instructions you're given, if any (they'll tell you how to add a backlinks.d/ subdirectory in your PmWiki installation directory).

Step 2 - First-time Backlinks Generator

  1. download the file Attach:FastBacklinks-starter.php and save it in your PmWiki installation main directory (the directory where your pmwiki.php file is located),
  2. open the script-page in your browser - that is, a page with an address similar to: [(approve links) edit diff]
  3. follow the instructions you see in your browser.

Configuration

Options that can be reconfigured in config.php:

$FastBacklinksDir
(default: backlinks.d/)
Name of the directory where script's data about the backlinks will be stored.
$FastBacklinksDontOversmart
(default: 1)
Change to 0 if you experience problems with pages saving very long after editing - there's a chance it might help you (but rather only if you use a skin which doesn't load any page before the edit window...)
$FastBacklinksPageForm
(default: $[Site.FastBacklinks])
Instructs the recipe where should it look for the '?action=backlinks' page template. Note, that it can be internationalised by redefining 'Site.FastBacklinks' on your XLPage.

External Configuration

(options configured out of config.php)

You can redefine the look of the page shown when '?action=backlinks' is invoked on the Site.FastBacklinks page of your wiki. Please note you should include the (:backlinks:) markup somewhere in that page for the feature to work correctly.

Notes and Comments

  • This recipe was last tested on PmWiki version: 2.0beta55
  • This recipe requires at least PmWiki version: ???

  • The recipe was meant to be written quickly - it's just working, not with full-blown configurability in mind (though it might be improved in possible further versions). Therefore:
    • it doesn't allow for changing the backlinks-list formatting, or sort order, or the page links to which are listed, in contrary to (:pagelist:)?;
    • it may need some tweaking to work properly in WikiFarms - but maybe not; I'm not sure (note, that it's data directory can be configured by $FastBacklinksDir).

What Should Be Improved in the Script

  • Solve the issues presented in Notes and Comments
    • possibly incorporate the script into (:pagelist:)
      -> added in the modified version below
    • make sure it works in WikiFarms
  • Create an installation script, that would populate the backlinks.d/ directory on start, so that no manual pages touching would be necessary.
A first attempt at this feature is completed - see section Installation and above.
Another possibility with new action 'makebacklinks' added in the modified version below
  • Add action=fastbacklinks which could be used in links and should generate a backlinks list on the current page, instead of the page content (similar to action=search showing results on the current page).
Added now in FastBacklinks 1.1beta001. See also History section below.
  • Add the Lock() function invocation.

Modified and improved Version of the script

The standard version 1.01beta001 didn't work properly in my wiki installation. The problem was, that it didn't write the fastbacklink-files just when a link was written in the first line of a wiki page. In the modified version Attach:fastbacklinks_mod.php this problem was solved and some important improvements to the script were added:

  • Automatic backlink writing is included in the $EditFunctions variable with a new function PostFastBacklinks.
  • Special new action 'makebacklinks' which will generate or update the complete backlinks.d-directory. The action is password protected and needs admin rights. It can be invoked by appending '?action=makebacklinks' to a page's address in your browser's address bar.
  • Better Layout of the backlink list similar to the normal PmWiki searchresult list.
  • New function 'FastBacklinkPagelist' for integrating Fast Backlinks in the normal PmWiki Pagelist markup. This can be done by changing the file 'scripts/pagelist.php'. Include the following line after line 160 (PmWiki version 2.02: $FmtV['$MatchSearched'] = count($list); ):
if (@$opt['link']) $list = FastBacklinkPagelist( $opt['link'], $list );

Contributor: Siegfried Seibert - Improved Version 2005-09-07

See Also

Contributors

  • Mateusz - if you are having issues with the recipe, when emailing the mailing list please send me a copy of your email (I'm not actively reading the list).

History

  • 2005-09-07 (modified version 1.11mod) - improved integration into (:pagelist:).
  • 2005-09-06 (modified version 1.1mod) - added '?action=makebacklinks', added integration into (:pagelist:).
  • 2005-08-31 (version 1.1beta001) - added '?action=fastbacklinks'.
  • 2005-08-31 - FastBacklinks-starter script created, to automate backlinks data generation.
  • 2005-08-27 - first version of the script released.

Feedback

Cool! :-) I'd like my wiki to have a Wikipedia-like "What links here" functionality, and your script looks just like the solution. However, the requirement for manually touching all pages makes the script impractical as there are already 1000+ pages in my wiki :-/ --Henning August 29, 2005, at 05:31 AM

A first attempt at this feature is completed - see section Installation and above. I'd be grateful if you tried it and provided some feedback - did it manage to complete? If yes, how long did it take? How big your wiki is, in pages and/or kilobytes?
Another way could be to use the modified version (see above) with its '?action=makebacklinks'. (S. Seibert - 2005-09-06)
Hm, it seems that this solution is now integrated in the standard release. Thanks for getting the ball rolling! :-) --Henning

Category: Superceded