Benutzer:TenWhile6/OSRequester.js
Erscheinungsbild
Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.
- Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
- Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
- Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
//<nowiki>
DB = mw.config.get('wgDBname');
Ov = 'v1.0';
On = 'OSRequester';
OSRequester = `${On} ${Ov}`;
blocation = mw.config.get('wgMFMode') == 'stable' ? 'p-tb' : 'p-cactions';
api = new mw.Api();
curPageName = mw.config.get('wgPageName').replace(/_/g, ' ');
RelevantPageName = mw.config.get('wgRelevantPageName') != null ? mw.config.get('wgRelevantPageName').replace(/_/g, ' ') : '';
RelevantUserName = mw.config.get('wgRelevantUserName') != null ? mw.config.get('wgRelevantUserName') : '';
requesterusername = mw.config.get('wgUserName') == 'TenWhile6' ? 'Ten' : mw.config.get('wgUserName');
metaapi = mw.config.get('wgDBname') == 'metawiki' ? api : new mw.ForeignApi('https://meta.wikimedia.org/w/api.php');
metaapi.get({
action: 'query',
prop: 'revisions',
titles: 'User:TenWhile6/XReport/languageData.json',
rvlimit: '1',
rvprop: 'content',
rvslots: 'main',
formatversion: '2',
format: 'json'
}).done( function(Ldata) {
LangData = JSON.parse(Ldata.query.pages[0].revisions[0].slots.main.content);
var mwh = '<div style=\'position:absolute; right:1em; top:0.1em\'><p style=\'color:red\'>Made with ❤️ by <a href=\'' + (lang == 'de' ? 'https://de.wikipedia.org/wiki/User:TenWhile6' : 'https://meta.wikimedia.org/wiki/User:TenWhile6') + '\'>TenWhile6</a></p></div><div style=\'position:absolute; left:1em; top:0.5em; font-weight: bold\'><a href=\'' + (lang == 'de' ? 'https://de.wikipedia.org/wiki/Benutzer_Diskussion:TenWhile6/OSRequester' : 'https://meta.wikimedia.org/wiki/User_talk:TenWhile6/OSRequester') + '\'>Bug reports / Feedback</a></div>';
var lang = 'en';
if (mw.user.options.get('language') in LangData) {
lang = mw.user.options.get('language');
}
else {
mwh = mwh + '<div style=\'position:absolute; left:1em; bottom:0.2em\'>Your language is not supported? Feel free to <a style=\'font-weight: bold\' href=\'https://meta.wikimedia.org/wiki/User_talk:TenWhile6/XReport#User_interface\'>translate</a> the user interface!</div>';
}
function trnslt(key) {
if (LangData[lang][key]) {
return LangData[lang][key];
}
return LangData.en[key];
}
var WikiData = {
'stewards': 'Wikimedia_Stewards_(Oversight)',
'metawiki': 'Meta-Wiki_oversighters',
'dewiki': 'Oversight-Email',
'enwiki': 'Oversight',
'bnwiki': 'গোপনকারী',
'zhwiki': 'Oversight-zhwp',
'fiwiki': 'H%C3%A4ivytyspyynn%C3%B6t',
'frwiki': 'Masqueurs',
'itwiki': 'Soppressori',
'jawiki': 'Oversight-JAWP',
'kowiki': '기록보호자',
'eswiki': 'Supervisor~eswiki',
'ptwiki': 'Supressor',
'simplewiki': 'Oversight~simplewiki',
'wikidatawiki': 'Wikidata Oversight',
'bewiki': false,
'idwiki': false,
'fawiki': false,
'plwiki': false,
'ruwiki': false,
'trwiki': false,
'commonswiki': 'Oversight Commons',
};
function DBdata() {
DBx = DB in WikiData ? DB : 'stewards';
if (WikiData[DBx]) {
return WikiData[DBx];
}
else {
mw.notify(`Error: DBdata() at ${DBx} status ${status} in ${key}`,{'type':'error','title':OSRequester});
}
}
console.log(DBdata());
if (DB in WikiData) {
if (WikiData[DB] == false) {
return;
}
}
( function() {
function getUserDialog(){
var style = '.done{margin-bottom: 1em;}' + '.OSR-intro-text{font-size: 80%; margin-bottom: 1em;}' + '.OSR-errors{color: red; margin: 1em;}';
mw.util.addCSS(style);
function CreateUserDialog(config){
CreateUserDialog.parent.call(this, config);
}
OO.inheritClass(CreateUserDialog, OO.ui.ProcessDialog);
CreateUserDialog.static.name = 'CreateUserDialog';
CreateUserDialog.static.title = OSRequester;
CreateUserDialog.prototype.initialize = function() {
var self = this;
CreateUserDialog.parent.prototype.initialize.call( this);
var $introText = $( '<div />',{class: 'OSR-intro-text'})
.append( $( '<p/>').append(mwh));
var $errorsField = $( '<div />',{class: 'OSR-errors'});
var $doneField = $( '<div />',{class: 'done'});
const clearError = function() {
$errorsField.text( '');
self.updateSize();
};
this.curPageID = 'page-1';
var usernameInput = new mw.widgets.UserInputWidget({align: 'top', required: true, validate: 'non-empty', value:RelevantUserName});
usernameInputField = new OO.ui.FieldLayout(usernameInput,{label: trnslt('username')});
var urlInput = new OO.ui.MultilineTextInputWidget({align: 'top', required: true, value:window.location, rows: 3, autosize: true});
urlInputField = new OO.ui.FieldLayout(urlInput,{label: 'URL'});
var reasonInput = new OO.ui.MultilineTextInputWidget({align: 'top', placeholder: lang == 'de' ? 'Begründung / weitere Links (optional)' : '', /*required: true,*/ disabled:true, rows: 3, autosize: true});
reasonInputField = new OO.ui.FieldLayout(reasonInput,{label: trnslt('c-reason')});
var dropDown = new OO.ui.DropdownWidget( {
label: trnslt('OSR-choose'),
menu: {
items: [
new OO.ui.MenuOptionWidget( {
data: 'OS#1',
label: DB == 'dewiki' & lang == 'de' ? 'OS#1: Nicht-öffentliche persönliche Informationen' : 'OS#1: Non-public personal information',
} ),
new OO.ui.MenuOptionWidget( {
data: 'OS#2',
label: DB == 'dewiki' & lang == 'de'? 'OS#2: potenziell verleumderische Informationen': 'OS#2: Potentially libelous information',
} ),
new OO.ui.MenuOptionWidget( {
data: 'OS#4',
label: DB == 'dewiki' & lang == 'de'? 'OS#4: Benutzername, der einen schwerwiegenden Angriff darstellt' : 'OS#4: Blatant attack username',
} ),
]
}
} ),
itemSelected = function(){
if (dropDown.getMenu().getVisibleItems()[0].selected) {usernameInputField.toggle(false);urlInputField.toggle(true);}
else if (dropDown.getMenu().getVisibleItems()[1].selected) {usernameInputField.toggle(false);urlInputField.toggle(true);}
else if (dropDown.getMenu().getVisibleItems()[2].selected) {usernameInputField.toggle(true);urlInputField.toggle(false);}
reasonInput.setDisabled(false);
mainButton.setDisabled(false);
self.updateSize();
};
dropDown.getMenu().on('select', itemSelected);
mainButton = new OO.ui.ButtonWidget({label: trnslt('button'), flags: ['primary', 'progressive'] ,icon: 'feedback'}).on( 'click', function() {
var URL = urlInput.getValue();
if (dropDown.getMenu().getVisibleItems()[0].selected) {
OS = dropDown.getMenu().getVisibleItems()[0].data;
OSText = dropDown.getMenu().getVisibleItems()[0].label;
if (!URL){
$errorsField.text ('URL?');
self.updateSize();
return;
}
}
else if (dropDown.getMenu().getVisibleItems()[1].selected) {
OS = dropDown.getMenu().getVisibleItems()[1].data;
OSText = dropDown.getMenu().getVisibleItems()[1].label;
if (!URL){
$errorsField.text ('URL?');
self.updateSize();
return;
}
}
else if (dropDown.getMenu().getVisibleItems()[2].selected) {
OS = dropDown.getMenu().getVisibleItems()[2].data;
OSText = dropDown.getMenu().getVisibleItems()[2].label;
var username = usernameInput.getValue();
if (!username){
$errorsField.text (trnslt('error-user'));
self.updateSize();
return;
} else {
URL = "https:"+mw.config.get("wgServer")+"/wiki/Special:Contributions/" + username.replace(/ /g, '_');
}
}
var reason = reasonInput.getValue();
reason = reason.replace( /(.*)--~~~~/g, '$1');
reason = reason.replace( /(.*)~~~~/g, '$1');
if (reason.charAt(0) == ''){
reason = reason.substr(1);
}
clearError();
self.switchTo('page-2');
$doneField.append($( '<span>')
.text(trnslt('process'))
.prop('style', 'position:relative; top:0.35em; color: black; font-weight: bold')
);
self.updateSize();
closeButton.setDisabled(true);
var success = function() {
self.updateSize();
$doneField.append( $( '<span>')
.text(trnslt('success'))
.prop('style', 'position:relative; left:1.5em; top:0.35em; color: #009000; font-weight: bold'));
closeButton.setDisabled(false);
self.updateSize();
timeout = function() {
window.location.reload();
self.close();
};
setTimeout(timeout, 5000);
};
xapi = DB in WikiData ? api : metaapi;
xapi.postWithEditToken({
action: 'emailuser',
target: DBdata(),
subject: OS,
text: 'Oversight-Request per '+OSText+'.\n'+URL+(reason != '' ? '\n'+reason+'\n\n' : '\n\n')+(DB == 'dewiki' ? 'Freundliche Grüße' : 'Best regards')+'\n'+requesterusername,
format: 'json',
ccme: (requesterusername == 'Ten' ? false : true)
}).then(function(data){
if (data.error && data.error.info){
mw.notify(`Error: OSRequester at ${DB}, action: postWithEditToken`,{'type':'error','title':OSRequester,autoHide: false});
} else {
success();
}
});
self.updateSize();
});
var page1Buttons = new OO.ui.HorizontalLayout({
items: [
new OO.ui.ButtonWidget({label: trnslt('close'), align: 'left' , icon:'close'}).on( 'click', function() {
self.close();
clearError();
}),
mainButton,
]
});
var page1Form = new OO.ui.FieldsetLayout({
items: [
dropDown,
usernameInputField,
urlInputField,
reasonInputField,
new OO.ui.FieldLayout(
new OO.ui.Widget(
{
content: [page1Buttons]
}
)
)
]
});
var closeButton = new OO.ui.ButtonWidget({label: trnslt('close'), flags: ['primary','progressive'], icon:'close'}).on( 'click', function() {
window.location.reload();
self.close();
});
var page2Buttons = new OO.ui.HorizontalLayout({
items: [closeButton],
});
var page2Form = new OO.ui.FieldsetLayout({
items: [
new OO.ui.FieldLayout( new OO.ui.Widget({content: [page2Buttons]}),{align: 'top'})
]
});
this.panelLayout = new OO.ui.PanelLayout({padded: true, expanded: false});
this.panelLayout.$element.append(
$introText,
$errorsField,
$doneField,
$('<div />',{id: 'page-1'}).append( page1Form.$element),
$('<div />',{id: 'page-2' , style: 'display:none'}).append( page2Form.$element)
);
this.$body.append( this.panelLayout.$element);
};
CreateUserDialog.prototype.getBodyHeight = function() {
return this.panelLayout.$element.outerHeight( true);
};
CreateUserDialog.prototype.switchTo = function(nextPageID){
$( '#' + this.curPageID).hide();
this.curPageID = nextPageID;
$( '#' + nextPageID).show();
this.updateSize();
};
return new CreateUserDialog({
size: 'medium'
});
}
var dialog, windowManager;
function openUserDialog(){
if (!dialog){
dialog = getUserDialog();
windowManager = new OO.ui.WindowManager();
$('body').append(windowManager.$element);
windowManager.addWindows([dialog]);
usernameInputField.toggle(false);
urlInputField.toggle(false);
mainButton.setDisabled(true);
}
windowManager.openWindow(dialog);
}
var portletLink = mw.util.addPortletLink(
blocation,
'#',
trnslt('OSR-button'),
'ca-osrequester',
trnslt('OSR-description'),
null,
'#ca-osrequester'
);
$(portletLink).click(function(e) {
e.preventDefault();
openUserDialog();
});
mw.loader.using(['mediawiki.util', 'mediawiki.widgets.UserInputWidget', 'oojs-ui', 'oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows']);
})();
});
//</nowiki>