MediaWiki talk:Common.js/Archive 8: Difference between revisions
Content deleted Content added
Shadowbot3 (talk | contribs) m Automated archival of 1 sections from MediaWiki talk:Common.js |
Shadowbot3 (talk | contribs) m Automated archival of 1 sections from MediaWiki talk:Common.js |
||
Line 342:
:::It's not as simple for {{tl|wrongtitle}}, for example see [[P*U*L*S*E (film)]]: the javascript code is smart enough not to replace the heading but it does replace the page title, also the template shows "The correct title is …" message. P.S. [http://svn.wikimedia.org/viewvc/mediawiki?view=rev&revision=23393 This seems to be a revision] which enabled <code><nowiki>{{DISPLAYTITLE:}}</nowiki></code> ∴ [[User:Alex Smotrov|Alex Smotrov]] 16:20, 18 July 2007 (UTC)
<span id="63310490192" />
== Administrator.js ==
Perhaps we should create [[MediaWiki:Administrator.js]] which can contain various scripts only useful for admins, which is then loaded from here only if the user has the sysop flag set in wgUserGroups. THat would allow us to add features less or not useful for normal readers and editors without burdening them interface or bandwidth-wise. —''[[User:Ruud Koot|Ruud]]'' 10:21, 28 May 2007 (UTC)
:User:^demon's "CSD reasons" script is a good example of something that might be useful there. [[User:CMummert|CMummert]] · <small>[[User talk:CMummert|talk]]</small> 12:20, 28 May 2007 (UTC)
:That could easily be done. We'd import MediaWiki:Administrator.js [[iff]] their wgUserGroups array contains "sysop" <span style="color:red;font-weight:bold">^</span>[[User:^demon|<span style="color:black;font-weight:bold;">demon</span>]]<sup>[[User_talk:^demon|<span style="color:red">[omg plz]</span>]]</sup> <em style="font-size:10px;">22:22, 29 June 2007 (UTC)</em>
I went ahead and implemented this, the file is at [[MediaWiki:Sysop.js]]. <span style="color:red;font-weight:bold">^</span>[[User:^demon|<span style="color:black;font-weight:bold;">demon</span>]]<sup>[[User_talk:^demon|<span style="color:red">[omg plz]</span>]]</sup> <em style="font-size:10px;">15:13, 24 July 2007 (UTC)</em>
:You could also mention [[:bugzilla:10666]]… As for the code
:* does <code>if("sysop" in wgUserGroups)</code> really work
:* are you sure <code>&ctype=text/javascript</code> is not required
:* opt-out would probably be a nice thing (<code> … && !window.disableSysopJS</code>)
:∴ [[User:Alex Smotrov|Alex Smotrov]] 15:34, 24 July 2007 (UTC)
:: The in syntax requires JS 1.4 (e.g. won't work in IE5 or below). I'd also just use importScript to include the file, keeps everything in one place (so you don't forget the ctype etc.) —''[[User:Ruud Koot|Ruud]]'' 16:29, 24 July 2007 (UTC)
for ( var g in wgUserGroups ) if ( wgUserGroups[g] == "sysop" && !window.disableSysopJS ) importScript( "MediaWiki:Sysop.js" );
:::Let's get back to the '''in''' part. wgUserGroups is not an object, it's an array. This code simply doesn't work for me in Firefox 1.5 / Opera 9.2 / IE6. Also, for anons <code>var wgUserGroups = null</code> and all 3 browsers report Javascript error. This needs to be fixed asap.
:::Your code seems okay to me, except I would add <code>if (wgUserGroups)</code> in the beginning to speed it up for anons a little ∴ [[User:Alex Smotrov|Alex Smotrov]] 17:15, 24 July 2007 (UTC)
:::: Are you completely sure about that? Objects in javascript can be treated a associative arrays, so one would expect that the reverse would also hold. —''[[User:Ruud Koot|Ruud]]'' 20:30, 24 July 2007 (UTC)
:::::Array in Javascript is not "Associative" by itself, I think [http://www.andrewdupont.net/2006/05/18/javascript-associative-arrays-considered-harmful/ this article] should explain it better than me. In any case, <code>javascript:alert("user" in wgUserGroups)</code> (in browser address field) shows false in all browsers I tried.
:::::By the way, everybody seems to have their own version of "call Sysop.js" code, here's mine: <code> if (wgUserGroups && (wgUserGroups[0] == "sysop" ) && !window.disableSysopJS)<code>. Advantages: most simple and efficient; works right now; if it stops working, people who notice will be able to fix it :) ∴ [[User:Alex Smotrov|Alex Smotrov]] 03:49, 25 July 2007 (UTC)
::::::Personally I just use something like <code>wgUserGroups.join(' ').indexOf('sysop')</code>. --[[User:Splarka|Splarka]] ([[User_talk:Splarka|rant]]) 07:16, 25 July 2007 (UTC)
|