On 24/10/13 23:19, Jeroen De Dauw wrote:
Hey,
Proposed:
$tp = new TextTitleParser(); try { $title = $tp->parse( $text ); $tf = new UrlTitleFormatter( $title, 'foo=bar ); return $tf->format(); } catch( MWException ) { return null; }
I hope this is your own interpretation of what would happen on top of what is proposed and not what is actually proposed, since this code snippet has some issues.
Those parser and Formatter objects contain configuration specific state. If you instantiate them like this, you are creating code that is just as bad as Title::newFromText, where this newFromText method relies on similar config specific state. In both cases you are using global state and programming against concretions.
No, it's not what's proposed, it's proposed to have a thing called a ServiceRegistry which would supply parser/formatter instances. I think the ServiceRegistry itself should be managed by the RequestContext, for lifetime control, whereas Daniel Kinzler thinks it should be a singleton.
Does the RFC also sate exceptions should be used rather than returned error values? Seems like a quite disjoint concern to me. And if you use exceptions, please use them properly and do not copy-paste MWException all over.
No, the RFC does not state that exceptions should be used.
Maybe you should both read the RFC.
https://www.mediawiki.org/wiki/Requests_for_comment/TitleValue
-- Tim Starling