Q:

Day count convention Actual/Actual AFB; Factor for Date1 = 2004-02-28 and Date2 = 2008-02-28

The Actual/Actual AFB day count convention is explained on Wikipedia here. I'll condense the rules here the way I understood them.

Factor = Days(Date1,Date2)/DiY
If 29th february is in date range from Date1 (inclusive) to Date2 (exclusive), DiY=366 else DiY=365
If date range from Date1 to Date2 spans multiple years, calculation is split in two parts:
  
  
Number of complete years counted back from the last day in the period
The remaining initial stub, calculated using the basic rule
ISDA additional rule: If counting backwards for multiple years, if the last day of the relevant period is 28 February the full year should be counted back to 28 February unless 29 February exists in which case 29 February should be used.

Now consider the case Date1 = 2004-02-28 and Date2 = 2008-02-28. Applying the rules gives:

4 full years
Date2' = 2004-02-29 [rebased Date2 by counting back + ISDA additional rule]
DiY = 365, because: Date1 = 2004-02-28, Date2' = 2004-02-29; 29 February is not in date range from Date1 (inclusive) and Date2' (exclusive) i.e. the remaining initial stub
Factor = 4 + 1/365

However, in the example on the Wikipedia page I linked to at the top it shows for those same two dates that Factor = 4 + 1/366. Which factor is correct? And if the result of the Wikipedia page is correct, where did I go wrong with my reasoning?

A:

Looking at the link to QuantLib's implementation of Act/Act AFB posted by Helin Gai in comments, this would be the part that the determines DiY (variable den):
Real den = 365.0; // the DiY

if (Date::isLeap(newD2.year())) {
    temp = Date(29, February, newD2.year());
    if (newD2>temp && d1<=temp)
        den += 1.0;
} else if (Date::isLeap(d1.year())) {
    temp = Date(29, February, d1.year());
    if (newD2>temp && d1<=temp)
        den += 1.0;
}

d1 will be 2004-02-28 and newD2 will be 2004-02-29 after counting back complete years and applying the ISDA additional rule. Applying this bit of code:

if (Date::isLeap(newD2.year())) > True
temp = Date(29, February, newD2.year()); > temp = '2004-02-29'
if (newD2>temp && d1<=temp) > False, since newD2>temp doesn't hold
den is not incremented and remains 365;

So according to QuantLib's implementation, Factor will be 4 + 1/365. It seems my suspicion is true that the example on Wikipedia is incorrect.

