Hey all,

Last Friday, the mw.Title rewrite landed in master. Here's a brief summary of 
the changes.

TL:DR;
* New static constructor mw.Title.newFromText  (returns mw.Title or null).
* New internal title parser (uses wgLegalTitleChars and mirrors most of 
Title::secureAndSplit).
* Bugs like [[.com]] throwing have been fixed.
* Big thanks to David Chan!

New: Static constructor mw.Title.newFromText

Unlike the regular constructor, this one does not throw exceptions on invalid 
input. Instead it returns null. This should make using mw.Title less awkward.

As a reminder, you are still required to account for invalid input. Where you 
previously wrapped `new mw.Title` it in a try/catch (which many users forgot), 
one may now use mw.Title.newFromText and check the result for truthiness.

Examples:

```php
$title = Title::newFromText( $input );
if ( $title ) { .. }
```

```js
title = mw.Title.newFromText( input );
if ( title ) { .. }
```

Regular constructor (old pattern):
```js
try {
    title = new mw.Title( input );
} catch ( e ) { .. }

if ( title ) {  .. }
```

New: Title parser

Previously mw.Title had a very basic processor for the text input. It was 
designed to be looser than its PHP counterpart so that it is fast and defaults 
to considering something valid. It is indeed more important to not consider 
something invalid when it is is in fact valid, than the other way around. 
Clients should never be blocking an action and it'll have to go through the 
server anyway at some point. Though that design is good, it is not what it 
really was.

In practice mw.Title's old processor considered various things invalid that 
were valid. And it had certain side-effects that weren't very intuitive (it 
removed certain invalid characters so that the title would become valid;in 
other cases it would throw an exception).

The new parser uses wgLegalTitleChars [2] and mirrors most of 
Title::secureAndSplit. For this we had to convert the character sequences in 
wgLegalTitleChars from bytes to Unicode. Big thanks to David Chan for making 
this work!

A full list of bugs fixed and patterns now properly recognised as valid and 
invalid can be found in the commit message[1] and by examining the added test 
cases.

Various bugs have been fixed (e.g. titles starting with dots, such as [[.com]], 
throwing an exception).

Documentation: 
https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.Title

-- Timo

[1]
https://gerrit.wikimedia.org/r/#/c/83047/
https://github.com/wikimedia/mediawiki-core/commit/4894793ab60ea0a245372cb472150b4ed79d19f4
[2]
https://gerrit.wikimedia.org/r/#/c/82040/
https://github.com/wikimedia/mediawiki-core/commit/dc9c9ee7fc6d96f957e15b4f56276000cb8e8f06
[3]  https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.Title

_______________________________________________
Wikitech-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Reply via email to