r105750 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105749‎ | r105750 | r105751 >
Date:03:29, 10 December 2011
Author:rsterbin
Status:resolved (Comments)
Tags:
Comment:
Updated the jquery module to override the edit CTA if the article is not
editable:
- New method verify() for ctas[1]
* NB: Contents copied from ATFv4
- New method selectCTA() checks that the requested CTA actually exists, and
runs its verify method (if it has one) to check that it can be allowed.
Failure at either point causes the empty CTA to be selected.
- Updated submitForm() to use selectCTA() rather than setting it directly
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js
@@ -1859,6 +1859,29 @@
18601860 },
18611861
18621862 // }}}
 1863+ // {{{ verify
 1864+
 1865+ /**
 1866+ * Verifies that this CTA can be displayed
 1867+ *
 1868+ * @return bool whether the CTA can be displayed
 1869+ */
 1870+ verify: function () {
 1871+ // An empty restrictions array means anyone can edit
 1872+ var restrictions = mw.config.get( 'wgRestrictionEdit', [] );
 1873+ if ( restrictions.length ) {
 1874+ var groups = mw.config.get( 'wgUserGroups' );
 1875+ // Verify that each restriction exists in the user's groups
 1876+ for ( var i = 0; i < restrictions.length; i++ ) {
 1877+ if ( $.inArray( restrictions[i], groups ) < 0 ) {
 1878+ return false;
 1879+ }
 1880+ }
 1881+ }
 1882+ return true;
 1883+ },
 1884+
 1885+ // }}}
18631886 // {{{ build
18641887
18651888 /**
@@ -2325,6 +2348,7 @@
23262349 && 'feedback_id' in data.articlefeedbackv5
23272350 && 'cta_id' in data.articlefeedbackv5 ) {
23282351 $.articleFeedbackv5.feedbackId = data.articlefeedbackv5.feedback_id;
 2352+ $.articleFeedbackv5.selectCTA( data.articlefeedbackv5.cta_id );
23292353 $.articleFeedbackv5.ctaId = data.articlefeedbackv5.cta_id;
23302354 $.articleFeedbackv5.unlockForm();
23312355 $.articleFeedbackv5.showCTA();
@@ -2361,6 +2385,29 @@
23622386 };
23632387
23642388 // }}}
 2389+ // {{{ selectCTA
 2390+
 2391+ /**
 2392+ * Chooses a CTA
 2393+ *
 2394+ * @param requested int the requested id
 2395+ * @return int the selected id
 2396+ */
 2397+ $.articleFeedbackv5.selectCTA = function ( requested ) {
 2398+ if ( !( requested in $.articleFeedbackv5.ctas ) ) {
 2399+ requested = '0';
 2400+ }
 2401+ temp = $.articleFeedbackv5.ctas[requested];
 2402+ if ( 'verify' in temp ) {
 2403+ if ( !temp.verify() ) {
 2404+ requested = '0';
 2405+ }
 2406+ }
 2407+ $.articleFeedbackv5.ctaId = requested;
 2408+ return requested;
 2409+ };
 2410+
 2411+ // }}}
23652412 // {{{ showCTA
23662413
23672414 /**
@@ -2368,7 +2415,7 @@
23692416 */
23702417 $.articleFeedbackv5.showCTA = function () {
23712418
2372 - // Build the form
 2419+ // Build the cta
23732420 var cta = $.articleFeedbackv5.currentCTA();
23742421 if ( !( 'build' in cta ) ) {
23752422 return;

Follow-up revisions

RevisionCommit summaryAuthorDate
r105968Fix variable temp leaking into the global scope (fixes r105750)rsterbin01:52, 13 December 2011

Comments

#Comment by Catrope (talk | contribs)   20:59, 12 December 2011
+		temp = $.articleFeedbackv5.ctas[requested];

This variable is leaked to the global scope. OK otherwise.

#Comment by Rsterbin (talk | contribs)   01:59, 13 December 2011

Thanks, fixed.

Status & tagging log