Qeyd: Dəyişiklikləri yayımladıqdan sonra etdiyiniz dəyişikliklərin görünməsi üçün brauzerinizin keşinin təmizlənməsi lazım ola bilər.
- Firefox / Safari: Reload düyməsinə basılı tutarkən Shift düyməsinə basın, və ya Ctrl+F5 və ya Ctrl+R (Mac üçün ⌘-R )
- Google Chrome: Ctrl-Shift-R (Mac üçün ⌘-Shift-R)
- Edge: Ctrl düyməsini basılı tutarkən Refresh düyməsinə basın, və ya sadəcə Ctrl+F5.
/**
* [[İstifadəçi:Əkrəm]] tərəfindən [[Xüsusi:DaimiKeçid/7227712]] əsasında,
* "CodexEnhanced" qadcetinin tərkib hissəsi kimi hazırlanmışdır.
* Ətraflı [[Vikipediya:CodexEnhanced]] səhifəsində.
*/
/* <nowiki> */
var { createMwApp } = require('vue'),
{ CdxCheckbox, CdxDialog, CdxField, CdxLookup, CdxProgressBar, CdxTextInput } = require('@wikimedia/codex'),
api = new mw.Api({ userAgent: 'CodexEnhanced/azwiki' }),
app = createMwApp({
data: () => ({
checkboxes: [
{ value: 'movetalk', label: 'Müzakirə səhifəsinin də adı dəyişilsin' },
{ value: 'redirect', label: 'Köhnə addan yenisinə istiqamətləndirmə yaradılsın' }
],
checkboxValue: ['movetalk'],
currentTitle: mw.config.get('wgPageName').replaceAll('_', ' '),
currentTitleBlurred: false,
currentTitleLookupInputValue: mw.config.get('wgPageName').replaceAll('_', ' '),
currentTitleLookupMenuItems: [],
editedPages: [],
dialogShown: false,
movetalk: true,
newTitle: 'Kateqoriya:',
newTitleBlurred: false,
reason: '',
redirect: false,
status: 'form'
}),
computed: {
currentTitleError() {
return this.currentTitleBlurred && (!this.currentTitle ? 'Zəhmət olmasa, menyudan bir kateqoriya seçin.' : this.currentTitle && !this.currentTitle.startsWith('Kateqoriya:') ? 'Seçdiyiniz səhifə "Kateqoriya" ad fəzasında deyil.' : undefined)
},
disabled() {
return this.currentTitleError || this.newTitleError || !this.currentTitle || this.currentTitle.length === 0 || this.newTitle.slice(11).length === 0
},
newTitleError() {
return this.newTitleBlurred && (this.newTitle.replace('Kateqoriya:', '').length === 0 ? 'Zəhmət olmasa, bir ad daxil edin.' : !this.newTitle.startsWith('Kateqoriya:') ? 'Daxil etdiyiniz ad "Kateqoriya" ad fəzasında deyil.' : this.currentTitle && this.currentTitle === this.newTitle ? 'Daxil etdiyiniz ad səhifənin hal-hazırkı adı ilə eynidir.' : this.newTitle.match(/#|\<|\>|\[|\]|\||\{\}_/) ? 'Daxil etdiyiniz adda səhifə adlarına uyğun olmayan simvollar mövcuddur.' : undefined)
}
},
methods: {
getUrl(pageName) {
return mw.util.getUrl(pageName)
},
onDefaultAction() {
this.status === 'success' ? window.location.href = this.getUrl(this.newTitle) : this.toggleDialog()
},
onLookupInput(inputValue) {
if (inputValue.length < 3) return
api.get({
action: 'query',
list: 'search',
srsearch: inputValue,
format: 'json'
})
.done(data => {
this.currentTitleLookupMenuItems = data.query.search.map(result => ({
value: result.title,
}))
})
},
// bu hissə formanın göndərilməsi düyməsi sıxılan zaman işə düşəcək
onSubmit() {
if (!this.currentTitle) return mw.notify('Zəhmət olmasa, adını dəyişdirmək istədiyiniz kateqoriyanı seçin.', { type: 'error' }) // əgər adı dəyişiləcək səhifə seçilməyibsə, istifadəçiyə xəbərdarlıq edilir
if (!this.currentTitle.startsWith('Kateqoriya:')) return mw.notify('Adını dəyişdirmək istədiyiniz səhifə kateqoriya səhifəsi olmalıdır.', { type: 'error' }) // əgər adı dəyişiləcək səhifə kateqoriya ad fəzasında deyilsə, istifadəçiyə xəbərdarlıq edilir
if (!this.newTitle) return mw.notify('Zəhmət olmasa, seçdiyiniz səhifənin yerləşməsini istədiyiniz adı daxil edin.', { type: 'error' }) // əgər yeni bir ad daxil edilməyibsə, istifadəçiyə xəbərdarlıq edilir
if (!this.newTitle.startsWith('Kateqoriya:')) return mw.notify('Daxil etdiyiniz yeni ad "Kateqoriya" ad fəzasında deyil.', { type: 'error' }) // əgər yeni ad "Kateqoriya" ad fəzasında deyilsə, istifadəçiyə xəbərdarlıq edilir
if (this.currentTitle === this.newTitle) return mw.notify('Daxil etdiyiniz yeni ad səhifənin hal-hazırkı adı ilə eynidir.', { type: 'error' }) // əgər daxil edilən yeni ad kateqoriyanın mövcud adı ilə eynidirsə, istifadəçiyə xəbərdarlıq edilir
/**
* Əgər formanın doldurulması zamanı bir problem ərsəyə gəlməyibsə, müraciət emal edilir.
* Kateqoriyanın adı dəyişdirilir və oraya daxil olan bütün səhifələr
* (maksimal hədd 500 səhifədir) müvafiq olaraq edilir.
*/
this.status = 'editing'
api.postWithEditToken({
action: 'move',
from: this.currentTitle,
to: this.newTitle,
reason: this.reason,
movetalk: this.checkboxValue.includes('movetalk'),
noredirect: !this.checkboxValue.includes('redirect'),
format: 'json'
})
.done(() => {
api.get({
action: 'query',
list: 'categorymembers',
cmtitle: this.currentTitle,
cmlimit: 500,
format: 'json'
})
.done(data => {
if (data.query.categorymembers.length > 0) {
Promise.all(data.query.categorymembers.map(({ title }) => api.get({
action: 'parse',
page: title,
prop: 'wikitext',
format: 'json'
})
.then(data => {
var wikitext = data.parse.wikitext['*'],
match = wikitext.match(new RegExp(`\\[\\[(?:[Kk]at(?:eqoriya)?|[Cc]ategory)\\s*:\\s*([${this.currentTitle.replace('Kateqoriya:', '')[0] + this.currentTitle.replace('Kateqoriya:', '')[0].toLocaleLowerCase('az')}]${this.currentTitle.replace('Kateqoriya:', '').slice(1)})(?:\\|(.*?))?\\]\\]`, 'i'))
if (match) {
return api.postWithEditToken({
action: 'edit',
title,
text: wikitext.replace(match[0], `[[${this.newTitle}${match[2] ? ('|' + match[2]) : ''}]]`),
format: 'json'
})
.done(() => this.editedPages.push(`<span style="color: var(--color-subtle, #54595d)"><a href="${this.getUrl(title)}">${title}</a> səhifəsindəki keçid uğurla dəyişdirildi.</span>`))
} else {
this.editedPages.push(`<span style="color: var(--color-error, #bf3c2c)">Xəta: <a href="${this.getUrl(title)}">${title}</a> səhifəsindən kateqoriyaya birbaşa keçid tapılmadı. Bu, əsasən, səhifə kateqoriyaya şablon vasitəsilə daxil edilən zaman baş verir.</span>`)
return Promise.resolve()
}
})
))
.then(() => this.status = 'success')
} else {
this.status = 'success'
}
})
})
},
toggleDialog() {
this.dialogShown = !this.dialogShown
}
},
template: `
<cdx-dialog
v-model:open="dialogShown"
:title="status === 'form' ? 'Kateqoriyanın adını dəyişin' : status === 'editing' ? 'Əməliyyat yerinə yetirilir...' : 'Uğurlu!'"
:subtitle="status === 'form' ? 'Kateqoriyanın adını dəyişmək üçün aşağıdakı formanı doldurun.' : status === 'editing' ? 'Kateqoriyanın və oraya daxil olan səhifələrin adı dəyişdirilir...' : 'Kateqoriyanın adı uğurla dəyişdirildi. Bu menyunu, yaxud səhifəni bağlaya bilərsiniz.'"
:use-close-button="true"
close-button-label="Bağla"
:primary-action="status === 'form' ? { label: 'Adı dəyiş', actionType: 'progressive', disabled } : undefined"
:default-action="status === 'form' ? { label: 'İmtina' } : { label: 'Bağla' }"
@primary="onSubmit"
@default="onDefaultAction"
>
<template
#default
v-if="status === 'form'"
>
<cdx-field
label-icon="\u003Cpath d='M7 0a2 2 0 00-2 2h9a2 2 0 012 2v12a2 2 0 002-2V2a2 2 0 00-2-2z' /\u003E\u003Cpath d='M13 20a2 2 0 002-2V5a2 2 0 00-2-2H4a2 2 0 00-2 2v13a2 2 0 002 2zM9 5h4v5H9zM4 5h4v1H4zm0 2h4v1H4zm0 2h4v1H4zm0 2h9v1H4zm0 2h9v1H4zm0 2h9v1H4z' /\u003E"
:status="currentTitleError ? 'error' : 'default'"
:messages="{ error: currentTitleError }"
>
<template #label>Mövcud ad</template>
<template #description>Kateqoriyanın hal-hazırda yerləşdiyi ad nədir?</template>
<cdx-lookup
v-model:selected="currentTitle"
:menu-items="currentTitleLookupMenuItems"
v-model:input-value="currentTitleLookupInputValue"
:menu-config="{ showThumbnail: true, boldLabel: true, hideDescriptionOverflow: true }"
@input="onLookupInput"
@blur="() => currentTitleBlurred = true"
>
<template
#no-results
v-if="currentTitleLookupInputValue?.length >= 3"
>
Qeyd etdiyiniz adda səhifə tapılmadı.
</template>
</cdx-lookup>
</cdx-field>
<cdx-field
label-icon="\u003Cpath d='m16.77 8 1.94-2a1 1 0 000-1.41l-3.34-3.3a1 1 0 00-1.41 0L12 3.23zM1 14.25V19h4.75l9.96-9.96-4.75-4.75z' /\u003E"
:status="newTitleError ? 'error' : 'default'"
:messages="{ error: newTitleError }"
>
<template #label>Yeni ad</template>
<template #description>Kateqoriyanın adının nə olmasını istəyirsiniz?</template>
<cdx-text-input
v-model="newTitle"
@blur="() => newTitleBlurred = true"
/>
<template #help-text>[[ və ]] daxil etməyə ehtiyac yoxdur.</template>
</cdx-field>
<cdx-field label-icon="\u003Cpath d='M6 14H0v6z' /\u003E\u003Crect width='20' height='16' rx='2' /\u003E">
<template #label>Səbəb</template>
<template #description>Kateqoriyanın adını niyə dəyişirsiniz?</template>
<cdx-text-input v-model="reason" />
</cdx-field>
<cdx-field label-icon="\u003Cpath d='m19 10-4-3v2h-4V5h2l-3-4-3 4h2v4H5V7l-4 3 4 3v-2h4v4H7l3 4 3-4h-2v-4h4v2z' /\u003E">
<template #label>Əlavə</template>
<template #description>Addəyişmə prosesi ilə bağlı əlavə məqamlar</template>
<cdx-checkbox
v-for="checkbox in checkboxes"
:key="'checkbox-' + checkbox.value"
v-model="checkboxValue"
:input-value="checkbox.value"
>
{{ checkbox.label }}
</cdx-checkbox>
</cdx-field>
</template>
<template
#default
v-if="status === 'editing'"
>
<cdx-progress-bar aria-label="Əməliyyat yerinə yetirilir..." />
<p v-for="page in editedPages" :key="page" v-html="page"></p>
</template>
<template
#footer-text
v-if="status !== 'success'"
>
Nəzərdə saxlayın ki, texniki məhdudiyyətlərdən ötrü kateqoriyada mövcud olan səhifələrdən yalnız 500-ə qədəri birdəfəyə oluna bilər.
</template>
</cdx-dialog>
`,
mounted() {
(mw.config.get('skin') === 'minerva' ? document.querySelector('[data-event-name="menu.move"]') : document.getElementById('ca-move')).addEventListener('click', event => {
event.preventDefault()
this.toggleDialog()
})
},
unmounted() {
(mw.config.get('skin') === 'minerva' ? document.querySelector('[data-event-name="menu.move"]') : document.getElementById('ca-move')).removeEventListener('click')
},
components: {
'cdx-checkbox': CdxCheckbox,
'cdx-dialog': CdxDialog,
'cdx-field': CdxField,
'cdx-lookup': CdxLookup,
'cdx-progress-bar': CdxProgressBar,
'cdx-text-input': CdxTextInput
}
})
api.getUserInfo()
.done(data => {
if (
data.rights.includes('move-categorypages') && // kateqoriyaların adını dəyişdirmə hüququ olmayan istifadəçilərdə işə düşməyəcək
mw.config.get('wgNamespaceNumber') === 14 // "Kateqoriya" ad fəzasından kənarda işə düşməyəcək
) app.mount(document.body.appendChild(document.createElement('div')))
})
/* </nowiki> */