Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js |
— | — | @@ -1859,6 +1859,29 @@ |
1860 | 1860 | }, |
1861 | 1861 | |
1862 | 1862 | // }}} |
| 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 | + // }}} |
1863 | 1886 | // {{{ build |
1864 | 1887 | |
1865 | 1888 | /** |
— | — | @@ -2325,6 +2348,7 @@ |
2326 | 2349 | && 'feedback_id' in data.articlefeedbackv5 |
2327 | 2350 | && 'cta_id' in data.articlefeedbackv5 ) { |
2328 | 2351 | $.articleFeedbackv5.feedbackId = data.articlefeedbackv5.feedback_id; |
| 2352 | + $.articleFeedbackv5.selectCTA( data.articlefeedbackv5.cta_id ); |
2329 | 2353 | $.articleFeedbackv5.ctaId = data.articlefeedbackv5.cta_id; |
2330 | 2354 | $.articleFeedbackv5.unlockForm(); |
2331 | 2355 | $.articleFeedbackv5.showCTA(); |
— | — | @@ -2361,6 +2385,29 @@ |
2362 | 2386 | }; |
2363 | 2387 | |
2364 | 2388 | // }}} |
| 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 | + // }}} |
2365 | 2412 | // {{{ showCTA |
2366 | 2413 | |
2367 | 2414 | /** |
— | — | @@ -2368,7 +2415,7 @@ |
2369 | 2416 | */ |
2370 | 2417 | $.articleFeedbackv5.showCTA = function () { |
2371 | 2418 | |
2372 | | - // Build the form |
| 2419 | + // Build the cta |
2373 | 2420 | var cta = $.articleFeedbackv5.currentCTA(); |
2374 | 2421 | if ( !( 'build' in cta ) ) { |
2375 | 2422 | return; |