I'm an admin, bureaucrat, and founder of http://pufflescp.wikia.com.
--
I want to add a "Demote" option to the dropdown menu of the "Edit" button. When it's clicked, {{demoted}} will be added to top the article.
I'm an admin, bureaucrat, and founder of http://pufflescp.wikia.com.
--
I want to add a "Demote" option to the dropdown menu of the "Edit" button. When it's clicked, {{demoted}} will be added to top the article.
Pretty easy with JavaScript. I've restricted the script to pages on the mainspace, though you can change that if you wish. Be aware; I'm fairly certain the use of such a script on a wiki-wide level is forbidden by the Customization Policy as it adjusts elements in the header.
require(["mw", "BannerNotification"], function (mw, BannerNotification) { "use strict"; var $conf = mw.config.get([ "wgPageName", "wgNamespaceNumber" ]); if (window.isDemotedButtonLoaded || $conf.wgNamespaceNumber !== 0) { return; } window.isDemotedButtonLoaded = true; var DemotedButton = { showBanner: function ($message, $status) { var $statusClass = ($status === "error" ? "error" : "confirm"); new BannerNotification($message, $statusClass).show(); }, prependTemplate: function ($template, that) { jQuery.ajax({ type: "POST", url: mw.util.wikiScript("api"), data: { action: "edit", minor: true, title: $conf.wgPageName, prependtext: $template, token: mw.user.tokens.get("editToken") } }).success(function ($data) { that.showBanner("Template added!", "confirm"); }).fail(function ($data) { that.showBanner("An error was encountered.", "error"); }); }, constructItem: function ($text) { return mw.html.element("li", { "id": "demoteButton-li" }, new mw.html.Raw( mw.html.element("a", { "id": "demoteButton-a", "href": "#", "title": $text }, $text) )); }, init: function () { var that = this; var $menuElement = this.constructItem("Demote"); jQuery($menuElement).prependTo(".page-header__contribution-buttons .wds-list"); jQuery("#demoteButton-a").click(function () { that.prependTemplate("{{demote}}", that); }); } }; mw.loader.using(["mediawiki.util", "mediawiki.api"]).then(function () { DemotedButton.init(); }); });
Good boi Midas writing less-janked code
@Count of Howard - http://pufflescp.wikia.com/wiki/Help:Customization_policy
"Other customization may only be implemented via Theme Designer, with the following exceptions:
OH YEAH! After a long period of deliberation, they recently decided to allow that.
Rip Midas and your cane-shaking :3
Thanks soo much--you don't know how much this means to me! The code is here , and I made a tweak to change the confirmation message. :)
I'd like you to add a couple of things to it, if that's all right. I'm really sorry if it seems I'm trying to complicate it, just a few tweaks:
Done. I moved all the various text-based strings to an $i18n variable for ease in adjustment and translation as well.
/** * @file Adds a demote button to Edit dropdown menu * @author Count of Howard <dev.wikia.com/wiki/User_talk:Count_of_Howard> * @license Apache-2.0 */ /*jslint browser */ /*global mw, jQuery, window, BannerNotification */ require(["mw", "BannerNotification"], function (mw, BannerNotification) { "use strict"; var $conf = mw.config.get([ "stylepath", "wgPageName", "wgUserGroups", "wgUserLanguage", "wgNamespaceNumber" ]); var $hasRights = /(sysop|content-moderator)/.test($conf.wgUserGroups.join(" ")); if ( window.isDemotedButtonLoaded || $conf.wgNamespaceNumber !== 0 || !$hasRights ) { return; } window.isDemotedButtonLoaded = true; var $i18n = { "en": { buttonText: "Demote", editSummary: "Demoting article to quality review. Disagree? Contact me, an admin, or a content moderator.", successBanner: "This article has been demoted.", errorBanner: "An error was encountered.", reloadText: "Getting page...", template: "{{demoted}}" } }; var $lang = jQuery.extend( $i18n.en, $i18n[$conf.wgUserLanguage.split("-")[0]], $i18n[$conf.wgUserLanguage] ); var DemotedButton = { showBanner: function ($message, $status) { var $statusClass = ($status === "error" ? "error" : "confirm"); new BannerNotification($message, $statusClass).show(); }, partialReload: function () { jQuery("#mw-content-text").load(window.location.href + " #mw-content-text > *", function () { jQuery(".WikiaArticle").stopThrobbing(); jQuery("#mw-content-text").fadeToggle(3000); }); }, prependTemplate: function ($template, that) { jQuery.ajax({ type: "POST", url: mw.util.wikiScript("api"), data: { action: "edit", minor: true, title: $conf.wgPageName, summary: $lang.editSummary, prependtext: $template, token: mw.user.tokens.get("editToken") } }).success(function ($data) { that.showBanner($lang.successBanner, "confirm"); that.partialReload(); }).fail(function ($data) { that.showBanner($lang.errorBanner, "error"); that.partialReload(); }); }, constructItem: function ($text) { return mw.html.element("li", { "id": "demoteButton-li" }, new mw.html.Raw( mw.html.element("a", { "id": "demoteButton-a", "href": "#", "title": $text }, $text) )); }, init: function () { var that = this; var $menuElement = this.constructItem($lang.buttonText); jQuery($menuElement).prependTo(".page-header__contribution-buttons .wds-list"); jQuery("#demoteButton-a").click(function () { jQuery("#mw-content-text").fadeToggle(1400); jQuery(".WikiaArticle").startThrobbing(); jQuery("#mw-content-text").html("<img id='demoteButton-throbber' src='" + $conf.stylepath + "/common/images/ajax.gif' /> " + $lang.reloadText); that.prependTemplate($lang.template, that); }); } }; mw.loader.using(["mediawiki.util", "mediawiki.api"]).then(function () { DemotedButton.init(); }); });
Looking good so far! The first half of my quality review system is done. Can we do this please: :)
Demote
1. Click Demote button.
2. Demoted tag added, article refreshes, and confirmation message shown.
Promote
1. Click Promote button. (If possible, hide demote button while {{demoted}} is placed on the article)
2. Remove {{demoted}} and auto-refresh the page.
3. Confirmation message: This article has been promoted.
2. Edit summary: Promoting article to fully published status. Disagree? Contact me, an admin, or a content moderator.
3. "Promote" button is replaced with "Demote" in dropdown.
Eh, close enough. I do wish you had told me about this desired second button from the start; I've had to revamp the script to integrate these new features, which has resulted in a bit of code spaghettification.
Nonetheless, both buttons have been added to the script. The Demote button adds the template to the page and only appears in the dropdown when the template does not exist on the page. The Promote button only appears if the template is present. When the Promote button is pressed, the script removes the template and reloads the content area. The necessary summaries change as well depending on the action being undertaken.
You can find the code here. If I were you, rather than copy/pasting it to your wiki, I'd submit it for review there on Dev, remove it from your Wikia.js, and use MediaWiki:ImportJS to import it to your wiki, but it's your choice.
I will warn you that this script is very resource-intensive. It makes two-three calls to the API in a very short amount of time, which can occasionally result in delays in the button being added or changes being submitted. Just baby the script when you use it.
I think I've provided a fair start; I'm sure you can figure out whatever small modifications you may wish to implement from here on out. Good luck!