You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
3.6 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

(()=>{"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(t,i){for(var a=0;a<i.length;a++){var r=i[a];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,(void 0,n=function(t,i){if("object"!==e(t)||null===t)return t;var a=t[Symbol.toPrimitive];if(void 0!==a){var r=a.call(t,"string");if("object"!==e(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(r.key),"symbol"===e(n)?n:String(n)),r)}var n}!function(e,t){var i="ui.CreatePageWidget".split(".");"isekai"in window||(window.isekai={});for(var a=window.isekai,r=0;r<i.length-1;r++){var n=i[r];n in a||(a[n]={}),a=a[n]}a[i[r]]=t}(0,function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.baseDom=t,this.pageUrl=null,this.api=new mw.Api,this.hasError=!1,this.initDom()}var i,a;return i=e,(a=[{key:"initDom",value:function(){var e=mw.config.get("wgIsekaiCreatePageNamespaces");Array.isArray(e)&&0!==e.length||(e=[{name:"Main",prefix:""}]),this.selectNamespaceDropdown=new OO.ui.DropdownInputWidget({options:e.map((function(e){return{data:e.prefix,label:e.name}}))}),this.selectNamespaceDropdown.on("change",this.onNamespaceChange.bind(this)),this.pageNameInput=new isekai.ui.CreatePageInputWidget({placeholder:mw.message("isekai-createpage-page-title").parse()}),this.pageNameInput.on("enter",this.createPage.bind(this)),this.pageNameInput.on("change",this.onPageNameChange.bind(this)),this.createButton=new OO.ui.ButtonWidget({label:mw.message("isekai-createpage-create-page-button").parse(),flags:["primary","progressive"]}),this.createButton.on("click",this.createPage.bind(this)),this.inputGroup=new OO.ui.ActionFieldLayout(this.pageNameInput,this.createButton,{align:"top"}),this.formGroup=new OO.ui.HorizontalLayout({items:[this.selectNamespaceDropdown,this.inputGroup]}),this.baseDom.find(".card-body .card-content").append(this.formGroup.$element)}},{key:"createPage",value:function(){var e=this,t=this.selectNamespaceDropdown.getValue()+this.pageNameInput.getValue();console.log(t),this.hasError&&this.clearError(),t.trim().length>0?(this.createButton.setDisabled(!0),this.pageExists(t).then((function(i){if(i)e.createButton.setDisabled(!1),e.setError(mw.message("isekai-createpage-page-exists").parse());else{var a=mw.util.getUrl(t,{veaction:"edit"});e.inputGroup.setSuccess([mw.message("isekai-createpage-redirecting").parse()]),location.href=a}}))):this.setError(mw.message("isekai-createpage-title-empty").parse())}},{key:"onPageNameChange",value:function(){this.hasError&&this.clearError();var e=this.pageNameInput.getValue();if(-1!==e.indexOf("")||-1!==e.indexOf("`")){var t=this.pageNameInput.getRange();e=e.replace(//g,":").replace(/`/g,"·"),this.pageNameInput.setValue(e),this.pageNameInput.selectRange(t.from,t.to)}}},{key:"onNamespaceChange",value:function(){this.pageNameInput.setPagePrefix(this.selectNamespaceDropdown.getValue())}},{key:"setError",value:function(e){this.inputGroup.setErrors([e]),this.hasError=!0}},{key:"clearError",value:function(){this.inputGroup.setErrors([]),this.hasError=!1}},{key:"pageExists",value:function(e){var t=this;return new Promise((function(i,a){t.api.get({action:"query",titles:e}).done((function(e){e.query&&e.query.pages?e.query.pages[-1]?i(!1):i(!0):i(!1)})).fail(a)}))}},{key:"setTitle",value:function(e){this.title.text(e)}}])&&t(i.prototype,a),Object.defineProperty(i,"prototype",{writable:!1}),e}())})();