|
|
!function(e){var t={};function r(i){if(t[i])return t[i].exports;var a=t[i]={i:i,l:!1,exports:{}};return e[i].call(a.exports,a,a.exports,r),a.l=!0,a.exports}r.m=e,r.c=t,r.d=function(e,t,i){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(r.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)r.d(i,a,function(t){return e[t]}.bind(null,a));return i},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=4)}([function(e,t){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(e){"object"==typeof window&&(r=window)}e.exports=r},,,,function(e,t,r){e.exports=r(5)},function(e,t,r){(function(e){e.isekai||(e.isekai={}),e.isekai.CreatePagePanel=class{constructor(e){this.baseDom=e,this.pageUrl=null,this.api=new mw.Api,this.hasError=!1,this.initDom()}initDom(){this.pageNameInput=new OO.ui.TextInputWidget({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.formGroup=new OO.ui.ActionFieldLayout(this.pageNameInput,this.createButton,{align:"top"}),this.baseDom.find(".card-body .card-content").append(this.formGroup.$element)}createPage(){let e=this.pageNameInput.getValue();this.hasError&&this.clearError(),e.trim().length>0?(this.createButton.setDisabled(!0),this.pageExists(e).then(t=>{if(t)this.createButton.setDisabled(!1),this.setError(mw.message("isekai-createpage-page-exists").parse());else{let t=mw.util.getUrl(e,{veaction:"edit"});this.formGroup.setSuccess([mw.message("isekai-createpage-redirecting").parse()]),location.href=t}})):this.setError(mw.message("isekai-createpage-title-empty").parse())}onPageNameChange(){this.hasError&&this.clearError();let e=this.pageNameInput.getValue();if(-1!==e.indexOf(":")||-1!==e.indexOf("`")){let t=this.pageNameInput.getRange();e=e.replace(/:/g,":").replace(/`/g,"·"),this.pageNameInput.setValue(e),this.pageNameInput.selectRange(t.from,t.to)}}setError(e){this.formGroup.setErrors([e]),this.hasError=!0}clearError(){this.formGroup.setErrors([]),this.hasError=!1}pageExists(e){return new Promise((t,r)=>{this.api.get({action:"query",titles:e}).done(e=>{e.query&&e.query.pages?e.query.pages[-1]?t(!1):t(!0):t(!1)}).fail(r)})}setTitle(e){this.title.text(e)}}}).call(this,r(0))}]); |