note
[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 >>> Yeah, and bestlink could also do that. However, it feels nasty to have
36 >>> it need to look at pagemtime. --[[Joey]]
37
38 ----
39
40     #!/usr/bin/perl
41     # Plugin to reproduce bestlink returning deleted pages. 
42     # Run with ikiwiki in verbose mode.
43     
44     package IkiWiki::Plugin::bestlinkbug;
45     
46     use warnings;
47     use strict;
48     use IkiWiki 3.00;
49     
50     sub import {
51         hook(type => "getsetup", id => "bestlinkbug", call => \&getsetup);
52         hook(type => "needsbuild", id => "bestlinkbug", call => \&needsbuild);
53     }
54     
55     sub getsetup () {
56         return
57                 plugin => {
58                         safe => 1,
59                         rebuild => 0,
60                 },
61     }
62     
63     sub needsbuild (@) {
64         my $needsbuild=shift;
65         
66         foreach my $page (keys %pagestate) {
67                 my $testpage=bestlink($page, "test") || next;
68                 
69                 debug("$page");
70         }
71     }   
72     
73     1
74
75