MediaWiki-diskusjon:Gadget-page-authors-simple.js
Updates[rediger kilde]
|besvart=nei
eller |answered=no
for å reaktivere redigeringsanmodningen.Hi! Could someone apply these changes to this script? Here is a summary of what changed:
- Migration to functions available in latest version of MediaWiki:
- Use mw.config.get(...) to access config variables (they won't be global forever)
- Use mw.util.wikiScript( 'api' ) to get an API link
- Use mw.util.wikiGetlink(...) to get links to wikipages
- Use mw.util.addPortletLink(...) to create portlet links
- Fixes for some problems found by JSHint (a tool recommended by MediaWiki developers for validating JavaScript code)
- Remove unnecessary semicolons and add others which are needed
- Make consistent use of tabs for indentation
- Variables should not be declared multiple times in the same scope
- Use the array literal notation [] instead of new Array()
- Use '===' to compare with 'null'
- Don't make functions within a loop
Best regards, Helder.wiki 19. okt 2011 kl. 17:47 (CEST)
- My coding style doesn't go well with JShint, so I stopped using it. Basically it nags about details that isn't important at all, and tries to enforce coding styles that are error prone. Especially the nagging about multiple declarations are troublesome. I can update the script, but please note as I wrote in the bug report that there is a few additional problems with this script. Use it as an example of whats possible, not how something like this should be implemented. — Jeblad 20. okt 2011 kl. 13:47 (CEST)
- The usage of one variable per function is indeed a coding style that one can choose to adopt (one that is disabled by default in JSHint and is only enabled with
/*jshint onevar:true */
). The other issues it found here, however, ae matters of code quality, not coding style (unnecessary semicolons, array literal notation, misunderstood comparison to 'null', functions in a loop) are all instances of the author misunderstanding how the language works or just trivial clean up. Krinkle (diskusjon) 15. jul. 2014 kl. 19:31 (CEST)
- The usage of one variable per function is indeed a coding style that one can choose to adopt (one that is disabled by default in JSHint and is only enabled with
Endringsforslag[rediger kilde]
Har ikke sjekket, men virker som det er en mindre endring i APIet. Endre linje 192 fra
query.rvstartid = data['query-continue'].revisions.rvstartid;
til noe ala
query.rvstartid = data['query-continue'].revisions.rvcontinue;
Tror det er alt som skal til for å få dette til å fungere igjen. — Jeblad 19. aug 2012 kl. 14:31 (CEST)
- Implementert. Ser ut til å fungere. Stigmj (diskusjon) 19. aug 2012 kl. 14:57 (CEST)
- Takk! — Jeblad 19. aug 2012 kl. 15:01 (CEST)
Code clean up[rediger kilde]
Hi,
I've applied some updates to remove misunderstood code and enforce code quality. Here is an overview of the changes. Since Jeblad is here, I've also added an additional note explaining it briefly.
- Removed confusing semicolons.
This isn't a case of coding style or relying on Automatic Semicolon Insertion. Instead, this is a matter of confusing semicolons. JavaScript terminates statements with a semicolon. However these where in fact function declarations (likeclass Foo {}
in other languages), not a function expression assigned in a statement. The semicolon merely results in an additional empty statement being created. - Broken comparison to
null
.
Thenull
value in javascript is separate fromundefined
. The default value for new variables, and the value yielded from an inexistent object property isundefined
, notnull
.null
is a defined and custom value that is only returned you explicitly return it and should generally be avoided elsewhere. This code worked because the two errors (using null and using loose comparison) cancelled each other out since the "loose equality" operator also toleratesundefined
when compared againstnull
(similar to how it tolerates a numerical string when comparing against a number). - Remove double declared variables. JavaScript has no block scope, only function scope. This in no way changes behaviour or even interpretation of the application. Any
var
statement is hoisted before execution to the top of its function scope.
Krinkle (diskusjon) 15. jul. 2014 kl. 19:48 (CEST)
- You made your point previously, and I don't agree. Especially the null tests was added on purpose. — Jeblad 16. jul. 2014 kl. 10:36 (CEST)
Utdatert[rediger kilde]
Vet ikke hvorfor det fortsatt er aktivitet på denne siden, den er utdatert og ikke i bruk. Ny kode er på MediaWiki:Gadget-page-contributors.js. — Jeblad 16. jul. 2014 kl. 10:57 (CEST)