User "Krinkle" posted a comment on MediaWiki.r90331.
Full URL:
https://secure.wikimedia.org/wikipedia/mediawiki/wiki/Special:Code/MediaWiki/90331#c20354
Commit summary:
Implement mw.Title in core
* Based on UploadWizard/resources/mw.Title.js
* Refactored to use local scope and prototypes instead of re-declaring them
per-instance in the private scope through 'this' (re-use by reference, faster
instantiation and performance)
* Fix potential ReferenceError in the check for wgArticlePath (inline if
statements will fail for undeclared variables, needs typeof undefined check).
Using mw.config instead to avoid this problem.
* The following two methods were not ported from UploadWizard because they were
or became redundant and/or merged with another method:
-- setNameText (redundant with the improved setName)
-- setPrefix (redundant wit the improved setNamespace)
* Ported all jasmine tests to QUnit. Left them exactly the same to make sure
it's compatible with UploadWizard. Perhaps I'll expand or adjust the suite
later to be less file-specific, but for now make letting this revision go
through TestSwarm to be sure it's compatible and behaves exactly the same.
* Added getName() method instead, replacing direct access to '_name' This in
order to check for wgCaseSensitiveNamespaces (bug 29441; r90234)
-- Prevents breakages on wiktionary and other wikis with case sensitivity. ie.
on a Wiktionary:
new mw.Title('apple').toString()
> "Apple"
-- This fix will make it return 'apple' instead of 'Apple' (that is, if 0 is in
wgCaseSensitiveNamespaces).
* There used to be a strip-bug in scenarios where a namespace-like string
appears inside of a title. Imagine pagename: "Category:Wikipedia:Foo bar"
(exist on several wikis; NS_CATEGORY= 14)
new mw.Title( 'Wikipedia:Foo bar', 14 ).toString()
> "Category:Foo_bar" // Stripped "Wikipedia:" !!
In order to fix this:
-- Removed assumption that every title has a namespace prefix.
UploadWizard/mw.Title has one initialization RegExp (which was ported as-is to
"setAll"). In addition there is now a "setNameAndExtension" method (which
doesn't extract or set the namespace). Now the above case:
new mw.Title( 'Wikipedia:Foo bar', 14 ).toString()
> "Category:Wikipedia_Foo_bar" // Better, but now the colon is gone..
-- In order to fix that, "\x3a" was removed from the clean() function. Colons
are valid in MediaWiki titles, no need to escape.
new mw.Title( 'Wikipedia:Foo bar', 14 ).toString()
> "Category:Wikipedia:Foo_bar" // Yay!
* Last but not least, another little bug fixed due to the previous point. It
also fixed a thrown exception in case a colon is part of the title in the main
namespace (not rare for movies and books):
new mw.Title( 'The Wiki: Awesomeness')
> Error: mw.Title> Unrecognized canonical namespace: the_wiki
This exception is thrown from setNamespace(). That exception would make sense
if setNamespace() was called by the user direcly, but when called from setAll()
it should gracefully fallback by putting the prefix in the name instead and
assuming NS_MAIN (just like the server side does). To achieve this I added a
try/catch around setAll() and fallback to the new setNameAndExtension().
* Passes JSHint.
* Additional feature: exists(). Return true/false if known, otherwise null.
Extensions can populate this for titles they are interested in and the
front-end can construct url's and UI elements with correct redlink-status.
Gadgets can populate it as well but that would require an API-request to get
the information. A bit of a stub for later use, although I think it works fine.
* Bugfix in jquery.qunit.completenessTest.js (first triggered by the
introduction of mw.Title). Don't traverse the 'constructor' property (recursive
loop, ouch!)
---
(bug 29397) Implement mw.Title module in core
Comment:
Sounds reasonable, removed them as public methods in r93702.
Also removing 'needs-js-test' tag as it the CompletenessTest now indicates 0
missing tests for this module as of r93702.
_______________________________________________
MediaWiki-CodeReview mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-codereview