I need to replicate exactly, Wikipedia's behavior regarding the conversion of [[links]] in the page body to URLs that open the articles they refer to.
The link syntax and its behavior (conversion) are described here. While that article only mentions a few very basic modifications being applied, I think that's not the whole story.
I tried searching the MediaWiki API reference, but haven't found the particular piece of code I was looking for. Is anyone familiar enough with the code to know which PHP function (presumably related to editing/submitting) I might be talking about?
There is two parts to this:
Parsing the link is done by the Parser class, which does all wikitext processing. Links can be more complex that just [[Foo]], e.g. [[Foo#bar|something]], where Foo is the target page, #bar is a section, and "something" is the "surface text" of the resulting link. For generating a URL, you need the target page and section. To generate a link (in HTML), you also need the surface text (if not given, it's the same as the target page + section). There is currently no easy way to just parse a link, without full wikitext processing.
If you already have the target page title (and maybe a section id), you have two choices of getting a URL for it: the old school (monolithic) way, or the new style (service based) way.
The new style method is:
The old school method is:
The old style is easier, because it doesn't require you to create service objects. It relies on global state and has all dependencies hardcoded. The new style uses simple dependency injection, which allows all parts to be swapped out individually and be tested independently - but it requires a little more code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With