MediaWiki:Gadget-articlefeedback-tools.js

From RuneRealm Wiki

This is an old revision of this page, as edited by Alex (talk | contribs) at 01:33, 13 October 2024 (Created page with "→‎* <nowiki> * Secondary gadget for the wiki article feedback feature, which runs solely on * pages that have the feedback wrapper (talk pages). It allows people to * mark feedback as "resolved". * * @author Jayden: var conf = mw.config.get([ 'wgPageName' ]), main = { →‎* * Startup method: init: function () { var wrappers = $('.gloop-feedback-wrapper'); // Loop through all of the feedback..."). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

After saving, you may need to bypass your browser's cache to see the changes. For further information, see Wikipedia:Bypass your cache.

  • In most Windows and Linux browsers: Hold down Ctrl and press F5.
  • In Safari: Hold down ⇧ Shift and click the Reload button.
  • In Chrome and Firefox for Mac: Hold down both ⌘ Cmd+⇧ Shift and press R.
/** <nowiki>
* Secondary gadget for the wiki article feedback feature, which runs solely on
* pages that have the feedback wrapper (talk pages). It allows people to
* mark feedback as "resolved".
*
* @author Jayden
*/

var conf = mw.config.get([
        'wgPageName'
    ]),

    main = {
        /**
         * Startup method
         */
        init: function () {
        	var wrappers = $('.gloop-feedback-wrapper');
        	
        	// Loop through all of the feedback on the page, and add a link to resolve them
            for (var i = 0; i < wrappers.length; i++) {
            	var current = wrappers[i];
            	main.handleWrapper(current);
            }
        },
        
        handleWrapper: function (wrapper) {
        	// Get the ID of the feedback section
        	var feedbackId = $(wrapper).data('id');

        	if (!feedbackId) {
        		// No ID exists, don't do anything
        		console.warn('Could not init feedback actions: no ID present', wrapper);
        		return;
        	}
        	
        	// Find the toggle to resolve the feedback
        	var toggle = $(wrapper).find('.gloop-feedback-resolve-toggle');
        	
        	if (!toggle.length) {
        		// No toggle exists, don't do anything
        		console.warn('Could not init feedback actions: no toggle present', wrapper);
        	}
        	
        	if (toggle.hasClass('table-bg-green')) {
        		// Already resolved, don't let people resolve it again
        		return;
        	}
        	
        	$(toggle).css('cursor', 'pointer');
			$(toggle).on('click', function () {
				main.doResolveConfirm(feedbackId, toggle);
			});
        },
        
        /**
         * Shows a confirmation popup for resolving feedback
         **/
        doResolveConfirm: function (feedbackId, toggle) {
        	console.log('feedback id', feedbackId);
        	OO.ui.confirm('Clicking OK will resolve this feedback, marking it as complete/no action needed. You cannot unresolve feedback after resolving it.').done(function (confirmed) {
			    if (confirmed) {
			        main.doResolve(feedbackId, toggle);
			    }
			});
        },
        
        doResolve: function (feedbackId, toggle) {
        	
        	var searchString = '\\|id=' + feedbackId + '\n\\|date=(.*)\n\\|resolved=no';
        	var regex = new RegExp(searchString, 'gim');
        	
			new mw.Api().edit(
			    conf.wgPageName,
			    function (revision) {
			        return {
			            text: revision.content.replace( regex, '|id=' + feedbackId + '\n|date=$1\n|resolved=yes' ),
			            summary: 'Resolving user-submitted feedback',
			            assert: 'user',
			            minor: true
			        };
			    }
			)
			.then(function () {
			    $(toggle).removeClass('table-bg-red');
			    $(toggle).addClass('table-bg-green');
			    $(toggle).find('span').text('Resolved');
			    $(toggle).off('click');
			});
        }
    };

mw.loader.using(['mediawiki.api', 'oojs-ui-core', 'oojs-ui-windows'], function () {
    $(main.init);
});

// </nowiki>