Page MenuHomePhabricator

Deprecation warnings in JS console
Closed, ResolvedPublic

Description

Author: jgonera

Description:
There are two warnings in JS console because of the way we extend mw.user:

Use of "name" is deprecated. Use mw.user.getName instead.
Use of "anonymous" is deprecated. Use mw.user.isAnon instead.

They seem to be false positives, but we should get rid of them somehow anyway.


Version: unspecified
Severity: normal

Details

Reference
bz65643

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 3:15 AM
bzimport set Reference to bz65643.
bzimport added a subscriber: Unknown Object (MLST).

bingle-admin wrote:

Prioritization and scheduling of this bug is tracked on Trello card https://trello.com/c/BxpqQtzw

But this isn't a bg of MobileFrontend, am i right?

MobileFrontend uses getName and isAnon already. The deprecated message appears in mobileView and on desktop view, because it's generated every time mediawiki.user.js is included:
https://github.com/wikimedia/mediawiki-core/blob/9f7e79ab6ba0fd3a0e4b002ca46b600a4a880a75/resources/src/mediawiki/mediawiki.user.js#L245

I think, for now we haven't to do anything :)

I think you are right here Florian...

jgonera wrote:

I can't see any deprecation warnings in desktop mode.

I'm not sure, when mediawiki.user.js is loaded, but if i missed nothing i have searched all files of MobileFrontend and there is nowhere used the deprecated functions.

I have deleted the lines from file i have linked in comment #2 and the messages are away, so i'm pretty sure, that we talk about these lines, which are both in core :)

I had a closer look and Juliusz is right.

Running this:
$.extend( {}, mw.user );

seems to be what causes the deprecation notices so I'm pretty sure there is nothing we can do here and this bug is a WONTFIX/INVALID or something similar

Yeah, is right :) I think we missunderstand us. I meaned, that we can't do anything without change something in core :)

Juliusz feel free to disagree but I can't imagine we want to do anything here.
In theory we could do the following:

delete mw.user.name;
delete mw.user.anonymous;
user = $.extend( {}, mw.user, {

which suppresses the warnings - but that seems like a waste of time.

jgonera wrote:

I think we should do something about it. One option is not to extend mw.user, but have something separate instead. We could also upstream what we have there into core. Leaving those warnings is bad because we'll get used to them, start ignoring them and in future we'll miss other warnings that might appear in the console.

Okay after talking to Juliusz we decided we should do some sort of shallow clone without using extend

e.g

M.define( 'user', {
getName: mw.user.getName,
isAnon: mw.user.isAnon
} );

Change 138487 had a related patch set uploaded by Jdlrobson:
Avoid JavaScript deprecation warnings in user module

https://gerrit.wikimedia.org/r/138487

Change 138487 merged by jenkins-bot:
Avoid JavaScript deprecation warnings in user module

https://gerrit.wikimedia.org/r/138487