fixed.. partly
[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 ----
32
33     #!/usr/bin/perl
34     # Plugin to reproduce bestlink returning deleted pages. 
35     # Run with ikiwiki in verbose mode.
36     
37     package IkiWiki::Plugin::bestlinkbug;
38     
39     use warnings;
40     use strict;
41     use IkiWiki 3.00;
42     
43     sub import {
44         hook(type => "getsetup", id => "bestlinkbug", call => \&getsetup);
45         hook(type => "needsbuild", id => "bestlinkbug", call => \&needsbuild);
46     }
47     
48     sub getsetup () {
49         return
50                 plugin => {
51                         safe => 1,
52                         rebuild => 0,
53                 },
54     }
55     
56     sub needsbuild (@) {
57         my $needsbuild=shift;
58         
59         foreach my $page (keys %pagestate) {
60                 my $testpage=bestlink($page, "test") || next;
61                 
62                 debug("$page");
63         }
64     }   
65     
66     1
67
68