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.
/* <nowiki> */
mw.loader.using(['mediawiki.api', 'mediawiki.util', '@wikimedia/codex', 'vue', 'mediawiki.Title'], function(require) {
const { createMwApp, ref } = require('vue');
const { CdxDialog, CdxField, CdxCheckbox, CdxTextInput } = require('@wikimedia/codex');
const api = new mw.Api();
const page = mw.config.get('wgPageName');
const pageTitle = mw.config.get('wgTitle');
const ns = mw.config.get('wgNamespaceNumber');
const isEligible = mw.config.get('wgUserGroups').includes('extendedconfirmed') || mw.config.get('wgUserGroups').includes('sysop');
if (!isEligible || ns < 0 || page === 'Vikipediya:Qaralama dəftəri') return;
const portletLink = mw.util.addPortletLink(
'p-ap',
'javascript:void(0);',
'Keçid-çıxar',
'p-ap-unlink',
'Səhifəyə verilmiş keçidləri çıxar'
);
const app = createMwApp({
data: () => ({
dialogShown: false,
reason: '',
backlinks: [],
imageusage: [],
selectedPages: [],
status: 'form',
progress: '',
isFile: ns === 6
}),
methods: {
toggleDialog() {
this.dialogShown = !this.dialogShown;
if (this.dialogShown) this.fetchLinks();
},
selectAll() {
this.selectedPages = [...this.backlinks, ...this.imageusage].map(p => p.title);
},
deselectAll() {
this.selectedPages = [];
},
async fetchLinks() {
this.status = 'loading';
this.progress = 'Keçidlər yüklənir...';
const query = {
action: 'query',
list: 'backlinks',
bltitle: page,
blnamespace: '0|1|2|3|4|5|6|7|10|11|100|101|118|119',
blfilterredir: 'nonredirects',
bllimit: 'max',
format: 'json'
};
if (this.isFile) {
query.list += '|imageusage';
query.iutitle = page;
query.iulimit = 'max';
}
const res = await api.get(query);
this.backlinks = res.query && res.query.backlinks ? res.query.backlinks : [];
this.imageusage = res.query && res.query.imageusage ? res.query.imageusage : [];
this.selectedPages = [...this.backlinks, ...this.imageusage].map(p => p.title);
this.status = 'form';
this.progress = '';
},
async submit() {
if (!this.reason) {
mw.notify('Keçidləri çıxarmaq üçün səbəb yazılmalıdır.', { type: 'error' });
return;
}
if (!this.selectedPages.length) {
mw.notify('Ən azı bir səhifə seçilməlidir.', { type: 'error' });
return;
}
this.status = 'sending';
for (const title of this.selectedPages) {
this.progress = `Emal olunur: ${title}`;
await this.unlinkFrom(title);
}
this.status = 'done';
this.progress = 'Keçidlər çıxarıldı.';
setTimeout(() => location.reload(), 2000);
},
async unlinkFrom(title) {
const res = await api.get({
action: 'query',
prop: 'revisions',
titles: title,
rvprop: 'content',
format: 'json'
});
const pageData = Object.values(res.query.pages)[0];
if (pageData.missing) return;
let oldText = '';
if (
pageData.revisions &&
pageData.revisions[0]
) {
if (pageData.revisions[0].slots &&
pageData.revisions[0].slots.main &&
pageData.revisions[0].slots.main['*']
) {
oldText = pageData.revisions[0].slots.main['*'];
} else if (pageData.revisions[0]['*']) {
oldText = pageData.revisions[0]['*'];
}
}
const wikitext = new Morebits.wikitext.page(oldText);
let text = oldText;
let changed = false;
if (this.imageusage.some(p => p.title === title)) {
const newText = wikitext.commentOutImage(pageTitle, 'Gizlədilib').getText();
if (newText !== text) {
text = newText;
changed = true;
}
}
if (this.backlinks.some(p => p.title === title)) {
const newText = wikitext.removeLink(pageTitle).getText();
if (newText !== text) {
text = newText;
changed = true;
}
}
if (!changed) return;
await api.postWithEditToken({
action: 'edit',
title,
text,
summary: `"${pageTitle}" keçid(lər)i çıxarılır: ${this.reason}.`,
nocreate: true
});
}
},
template: `
<cdx-dialog
v-model:open="dialogShown"
title="Keçidlərin çıxarılması"
use-close-button
close-button-label="Bağla"
:primary-action="status === 'form' ? { label: 'Çıxar', actionType: 'destructive', disabled: !selectedPages.length } : undefined"
@primary="submit"
>
<template #default>
<div v-if="status === 'form'">
<p style="margin-bottom: 1em; font-size: 85%;">
Bu səhifəyə verilmiş bütün daxili keçidləri çıxarmaq mümkündür. Məsələn,
<code>[[${pageTitle}|keçid mətni]]</code> keçidi
<code>keçid mətni</code> kimi və
<code>[[${pageTitle}]]</code> keçidi
<code>${pageTitle}</code> kimi görünə bilər.
</p>
<cdx-field label="Keçidlərin çıxarılması səbəbi">
<cdx-text-input
v-model="reason"
placeholder="Keçidlərin çıxarılması üçün səbəb"
type="text"
/>
</cdx-field>
<div>
<p v-if="[...backlinks, ...imageusage].length" style="margin-top: 1em;"><strong>Bu səhifəyə verilmiş keçidlər:</strong></p>
<p v-else style="margin-top: 1em; font-style: italic;">Səhifəyə heç bir keçid verilməyib.</p>
<div v-if="[...backlinks, ...imageusage].length" style="margin: 0.5em 0 1em 0;">
<cdx-button @click="selectAll" size="small" weight="quiet" style="margin-right: 0.5em;">
Hamısını seç
</cdx-button>
<cdx-button @click="deselectAll" size="small" weight="quiet" action-type="destructive">
Hamısını ləğv et
</cdx-button>
</div>
<cdx-field v-if="[...backlinks, ...imageusage].length" label="Keçid verilmiş səhifələr">
<cdx-checkbox
v-for="link in [...backlinks, ...imageusage]"
:key="link.title"
v-model="selectedPages"
:input-value="link.title"
>
{{ link.title }}
</cdx-checkbox>
</cdx-field>
</div>
</div>
<div v-else style="padding: 1em;">
<p>{{ progress }}</p>
</div>
</template>
</cdx-dialog>
`,
mounted() {
portletLink.addEventListener('click', this.toggleDialog);
},
unmounted() {
portletLink.removeEventListener('click', this.toggleDialog);
}
});
app.component('cdx-dialog', CdxDialog)
.component('cdx-field', CdxField)
.component('cdx-checkbox', CdxCheckbox)
.component('cdx-text-input', CdxTextInput)
.component('cdx-button', require('@wikimedia/codex').CdxButton)
.mount(document.body.appendChild(document.createElement('div')));
});
/* </nowiki> */