Patching is not needed for something like this.
If what you want is to insert an image alongside the headline, why not take advantage of the :before
Modify your conf/userstyle.css
and add someting like this:
Then you can even add some other CSS formatting to make the headline more like the GUI elements:
border: 1px solid gray;
That way it is not necessary to patch DokuWiki for a functionality that has been already discussed to death, and it is not even neccesary to modify the content of the wikipage because the image is "automatic".
Now, if the image changes in every header, it requires some extra work, but it can still be done, with only a bit research and some extra work.