(bug 16066) Inline history goes into endless loop and runs out of memory

When the inline history tries to display the history and notes together and the
last note is younger then all history items the next_entry function
will go into an endless loop crashing the server
Update for inline history
 * Fixed the descending history
 * Simplified and fixed the sorting and comparing with bug notes
Small improvements

 * Use isset instead of compating to NULL
 * Removed some code cuplication by exctracting logic to function
Fix infinite loop when there is only one history entry

Pull request #2