Merge branch 'master' of ssh://git.ikiwiki.info/srv/git/ikiwiki.info
[ikiwiki] / doc / bugs / bestlink_returns_deleted_pages.mdwn
1 To reproduce: 
2
3 1. Add the backlinkbug plugin below to ikiwiki. 
4 2. Create a page named test.mdwn somewhere in the wiki. 
5 3. Refresh ikiwiki in verbose mode. Pages whose bestlink is the test.mwdn page will be printed to the terminal.
6 4. Delete test.mdwn.
7 5. Refresh ikiwiki in verbose mode again. The same pages will be printed to the terminal again.
8 6. Refresh ikiwiki in verbose mode another time. Now no pages will be printed.
9
10 bestlink() checks %links (and %pagecase) to confirm the existance of the page.
11 However, find_del_files() does not remove the deleted page from %links (and %pagecase).
12
13 Since find_del_files removes the deleted page from %pagesources and %destsources,
14 won't it make sense for bestlink() to check %pagesources first? --[[harishcm]]
15
16 > This same problem turned out to also be the root of half of ikiwiki's
17 > second-oldest bug, [[bestlink_change_update_issue]].
18
19 > Fixing it is really a bit involved, see commit
20 > f1ddf4bd98821a597d8fa1532092f09d3d9b5483. The fix I committed fixes
21 > bestlink to not return deleted pages, but only *after* the needsbuild and
22 > scan hooks are called. So I was able to fix it for every case except the
23 > one you gave! Sorry for that. To fix it during beedsbuild and scan, 
24 > a much more involved approach would be needed. AFAICS, no existing plugin
25 > in ikiwiki uses bestlink in needsbuild or scan though.
26
27 > If the other half of [[bestlink_change_update_issue]] is fixed, 
28 > maybe by keeping a copy of the old backlinks info, then that fix could be
29 > applied here too. --[[Joey]]
30
31 >> Cool that was fast! Well at least half the bug is solved :) For now I'll
32 >> probably try using a workaround if using bestlink within the needsbuild
33 >> or scan hooks. Maybe by testing if pagemtime equals zero. --[[harishcm]]
34
35 ----
36
37     #!/usr/bin/perl
38     # Plugin to reproduce bestlink returning deleted pages. 
39     # Run with ikiwiki in verbose mode.
40     
41     package IkiWiki::Plugin::bestlinkbug;
42     
43     use warnings;
44     use strict;
45     use IkiWiki 3.00;
46     
47     sub import {
48         hook(type => "getsetup", id => "bestlinkbug", call => \&getsetup);
49         hook(type => "needsbuild", id => "bestlinkbug", call => \&needsbuild);
50     }
51     
52     sub getsetup () {
53         return
54                 plugin => {
55                         safe => 1,
56                         rebuild => 0,
57                 },
58     }
59     
60     sub needsbuild (@) {
61         my $needsbuild=shift;
62         
63         foreach my $page (keys %pagestate) {
64                 my $testpage=bestlink($page, "test") || next;
65                 
66                 debug("$page");
67         }
68     }   
69     
70     1
71
72