MediaWiki:Gadget-wikibugs-core.js: Różnice pomiędzy wersjami
Wygląd
Usunięta treść Dodana treść
Przeniesienie tekstu o licencji przesyłanego tekstu na stronę z formularzem, gdzie ten tekst się wpisuje |
jquery.ui -> OOui (na podstawie wikt:pl:MediaWiki:Gadget-wikibugs.js) |
||
Linia 1: | Linia 1: | ||
/* |
/** |
||
* @author: [[:pl:User:Dodek]] (idea and text) |
* @author: [[:pl:User:Dodek]] (idea and text) |
||
* @author: [[:pl:User:Adziura]] (idea and text) |
* @author: [[:pl:User:Adziura]] (idea and text) |
||
Linia 6: | Linia 6: | ||
* @author: [[:pl:User:Beau]] (implementation) |
* @author: [[:pl:User:Beau]] (implementation) |
||
* @author: [[:pt:User:Helder.wiki]] (implementation) |
* @author: [[:pt:User:Helder.wiki]] (implementation) |
||
* @author: [[:pl:User:Peter Bowman]] (rework) |
|||
*/ |
*/ |
||
var config = mw.config.get( [ |
|||
/* Translatable strings */ |
|||
'wgNamespaceIds', |
|||
mw.messages.set( { |
|||
'wgNamespaceNumber', |
|||
'wikibugs-dialog-title': 'Zgłoś błąd', |
|||
'wgPageName', |
|||
'wikibugs-open-form-button': 'Przejdź do formularza', |
|||
'wgRestrictionEdit', |
|||
'wikibugs-edit-page-button': 'Popraw samodzielnie', |
|||
'wgUserGroups', |
|||
'wikibugs-cancel-button': 'Anuluj', |
|||
'wgUserLanguage' |
|||
'wikibugs-submit-report-button': 'Wyślij', |
|||
] ), |
|||
'wikibugs-ip-address-notice': '<b>Uwaga:</b> Twój adres IP zostanie zapisany w historii zgłoszeń.', |
|||
'wikibugs-page-name-label': 'Nazwa strony:<br/><small>(razem z "Plik:", jeżeli zgłaszasz błąd w pliku)</small>', |
|||
'wikibugs-report-content-label': 'Treść zgłoszenia:', |
|||
'wikibugs-report-content-placeholder': 'Opisz błąd możliwie jak najdokładniej. Jeżeli masz taką możliwość, podaj źródło informacji.', |
|||
'wikibugs-signature-label': 'Podpis:', |
|||
'wikibugs-edit-error': '', |
|||
'wikibugs-token-error': '', |
|||
'wikibugs-unknown-token-error': '', |
|||
'wikibugs-ajax-error': 'Wystąpił błąd podczas wysyłania zgłoszenia. Proszę spróbować jeszcze raz.', |
|||
'wikibugs-incomplete-information': 'Opisz dokładnie zgłaszany błąd - wprowadzony opis jest za krótki.', |
|||
'wikibugs-invalid-page': 'Podaj nazwę strony.', |
|||
'wikibugs-reported-by': ' Zgłasza: $1', |
|||
'wikibugs-file-section-line': '<!-- Zgłoszenia błędów w plikach wstawiaj poniżej tej linii. Nowe na górze. -->', |
|||
'wikibugs-page-section-line': '<!-- Zgłoszenia błędów w artykułach wstawiaj poniżej tej linii. Nowe na górze. -->', |
|||
'wikibugs-bad-reports-text': '<p>Formularz <b>nie służy</b> do zgłaszania próśb o rozwinięcie ' + |
|||
'bądź stworzenie nowych artykułów. Zobacz stronę:</p><ul>' + |
|||
'<li><a href="' + mw.util.getUrl( 'Wikipedia:Propozycje tematów' ) + '">' + |
|||
'Propozycje tematów</a></li></ul><p>Wikipedia nie udziela jakichkolwiek porad na ' + |
|||
'życzenie. Jeżeli masz jakąś prośbę o poradę, <b>nie zgłaszaj jej tutaj</b>.</p>' + |
|||
'<p>Informacje, jak skontaktować się z Wikipedią, można znaleźć na stronie:</p>' + |
|||
'<ul><li><a href="' + mw.util.getUrl( 'Wikipedia:Kontakt' ) + '">Kontakt</a></li></ul>', |
|||
'wikibugs-article-intro': '<p style="margin-top:0px;">Możesz zgłaszać znalezione błędy w ' + |
|||
'artykułach w Wikipedii, jednak pamiętaj, że Wikipedia to ' + |
|||
'<a href="' + mw.util.getUrl( 'Wiki' ) + '">wiki</a> i można, ' + |
|||
'a nawet należy <a href="' + mw.util.getUrl( 'Wikipedia:Śmiało modyfikuj strony' ) + '">' + |
|||
'śmiało poprawiać znalezione błędy samemu</a>. ' + |
|||
'Zdajemy sobie jednak sprawę z faktu, że niektórzy czytelnicy Wikipedii mogą z różnych ' + |
|||
'przyczyn nie chcieć samodzielnie poprawiać artykułów. ' + |
|||
'Jeśli to możliwe, dodaj do zgłoszenia informację o źródle, na podstawie którego ' + |
|||
'stwierdzasz istnienie błędu. </p><p><b>Jeżeli potrafisz poprawić ' + |
|||
'błąd – nie zgłaszaj go tutaj.</b></p>' + |
|||
'<p><b>Preferowany format zgłoszenia prostych błędów:</b></p><ul>' + |
|||
'<li>Jest: [podaj fragment zawierający błąd]</li>' + |
|||
'<li>Powinno być: [podaj poprawną wersję (o ile jest znana)]</li>' + |
|||
'<li>Uzasadnienie: [uzasadnij konieczność poprawy, nawet jeśli wydaje Ci się to oczywiste; <a href="' + mw.util.getUrl( 'Wikipedia:Weryfikowalność' ) + '">podaj źródła</a>]</li></ul></p>', |
|||
'wikibugs-image-intro': '<p style="margin-top:0px;">Tu możesz zgłaszać grafiki, które łamią licencję, ' + |
|||
'mają swoje lepsze odpowiedniki w Commons, są błędnie opisane itp.</p>' + |
|||
'<p><b>Jeżeli potrafisz poprawić błąd - nie zgłaszaj go tutaj.</b></p>', |
|||
'wikibugs-already-reported-notice': '<p><b>Uwaga:</b> Jeśli zamieściłeś/-aś raport o błędzie, ' + |
|||
'a teraz go już nie ma, to najprawdopodobniej został on naprawiony. <ul>' + |
|||
'<li><a href="' + mw.util.getUrl( 'Wikipedia:Zgłoś błąd w artykule' ) + '">' + |
|||
'Zobacz listę aktualnie zgłoszonych błędów</a> oraz</li>' + |
|||
'<li><a href="' + mw.util.getUrl( 'Wikipedia:Zgłoś błąd w artykule' ) + '?action=history">' + |
|||
'historię zmian wprowadzanych na tej stronie.</a></li></ul>' + |
|||
'<p></p> ' + |
|||
'<p><b>Zgłoszenie będzie publicznie dostępne – prosimy nie podawać swoich danych teleadresowych!</b></p>', |
|||
'wikibugs-copyright': 'Wysyłając zgłoszenie wyrażasz nieodwołalną zgodę na udostępnianie Twojego wkładu ' + |
|||
'na licencjach CC-BY-SA 3.0 i GFDL oraz na wykorzystanie go w dowolnej formie ' + |
|||
'pod warunkiem podania przynajmniej hiperłącza lub adresu URL do strony, ' + |
|||
'na której powstała treść. Treść ta musi być dostępna na tych zasadach, ' + |
|||
'jeśli nie jest wynikiem Twojej samodzielnej pracy.', |
|||
'wikibugs-footer': '', |
|||
'wikibugs-new-report': 'Nowe zgłoszenie: /* $1 */' |
|||
} ); |
|||
window.wikiBugsGadget = { |
|||
/** |
|||
* Version number of this gadget. |
|||
*/ |
|||
version: 9, |
|||
/** |
/** |
||
* A name of a page where reports are saved. |
* A name of a page where reports are saved. |
||
*/ |
*/ |
||
reportPage |
reportPage = 'Wikipedia:Zgłoś błąd w artykule', |
||
/** |
/** |
||
* Black list of pages which reports should not refer to. |
* Black list of pages which reports should not refer to. |
||
*/ |
*/ |
||
badPages |
badPages = [ |
||
reportPage, |
|||
'Wikipedia:Zgłoś błąd w artykule', |
|||
'Wikipedia:Sprzątanie Wikipedii', |
'Wikipedia:Sprzątanie Wikipedii', |
||
'Wikipedia:Zgłoszone grafiki', |
'Wikipedia:Zgłoszone grafiki', |
||
'Wikipedia:Kontakt z wikipedystami', |
'Wikipedia:Kontakt z wikipedystami', |
||
'Dyskusja Wikipedii:Kontakt z wikipedystami', |
'Dyskusja Wikipedii:Kontakt z wikipedystami', |
||
'Wikipedia:Prośby o przejrzenie edycji' |
'Wikipedia:Prośby o przejrzenie edycji' |
||
], |
], |
||
windowManager = null, |
|||
/** |
|||
api = null; |
|||
* Define pages where it's not needed or tends to encourage submission of large |
|||
* volumes of unrelated errors; instead, these load CSS which hides the "Report A Bug" link |
|||
*/ |
|||
excludedPages: [ |
|||
'Strona główna', |
|||
'Wikipedia:Strona główna' |
|||
], |
|||
/** |
|||
* Message shown on pages in the main namespace. |
|||
*/ |
|||
articleIntro: '<div id="wbBadReports">' + |
|||
mw.msg( 'wikibugs-bad-reports-text' ) + '</div>' + |
|||
mw.msg( 'wikibugs-article-intro' ) + |
|||
mw.msg( 'wikibugs-already-reported-notice' ) + |
|||
mw.msg( 'wikibugs-footer' ), |
|||
/** |
|||
* Message shown on pages in the file namespace. |
|||
*/ |
|||
imageIntro: '<div id="wbBadReports">' + |
|||
mw.msg( 'wikibugs-bad-reports-text' ) + '</div>' + |
|||
mw.msg( 'wikibugs-image-intro' ) + |
|||
mw.msg( 'wikibugs-already-reported-notice' ) + |
|||
mw.msg( 'wikibugs-footer' ), |
|||
function configureMessages() { |
|||
/** |
|||
mw.messages.set( { |
|||
* Checks if a title of the page is valid for a report. |
|||
'wikibugs-dialog-title': 'Zgłoś błąd', |
|||
* @param title A title of the page. |
|||
'wikibugs-open-form-button': 'Przejdź do formularza', |
|||
*/ |
|||
'wikibugs-edit-page-button': 'Popraw samodzielnie', |
|||
isValidPageName: function( title ) { |
|||
'wikibugs-submit-report-button': 'Wyślij', |
|||
// Empty title is not valid |
|||
'wikibugs-ip-address-notice': '<p><strong>Uwaga:</strong> Twój adres IP zostanie zapisany w historii zgłoszeń.</p>', |
|||
if ( title === '' ) { |
|||
'wikibugs-page-name-label': 'Nazwa strony:', |
|||
return false; |
|||
'wikibugs-report-content-label': 'Treść zgłoszenia:', |
|||
} |
|||
'wikibugs-report-content-placeholder': 'Opisz błąd możliwie jak najdokładniej. Jeżeli masz taką możliwość, podaj źródło informacji.', |
|||
// Special pages are not valid too |
|||
'wikibugs-signature-label': 'Podpis:', |
|||
if ( this.getPageNamespaceNumber( title ) === -1 ) { |
|||
'wikibugs-incomplete-information': 'Opisz dokładnie zgłaszany błąd. Wprowadzony opis jest za krótki.', |
|||
return false; |
|||
'wikibugs-invalid-page': 'Podaj nazwę strony.', |
|||
} |
|||
'wikibugs-file-section-line': '<!-- Zgłoszenia błędów w plikach wstawiaj poniżej tej linii. Nowe na górze. -->', |
|||
// Check black list |
|||
'wikibugs-page-section-line': '<!-- Zgłoszenia błędów w artykułach wstawiaj poniżej tej linii. Nowe na górze. -->', |
|||
title = this.getRefinedPageName( title ); |
|||
'wikibugs-bad-reports-text': '<div id="wb-bad-reports"><p>Formularz <strong>nie służy</strong> do zgłaszania próśb o rozwinięcie ' + |
|||
return jQuery.inArray( title, this.badPages ) === -1; |
|||
'bądź stworzenie nowych artykułów. Zobacz stronę:</p><ul>' + |
|||
}, |
|||
'<li><a href="' + mw.util.getUrl( 'Wikipedia:Propozycje tematów' ) + '">' + |
|||
'Propozycje tematów</a></li></ul><p>Wikipedia nie udziela jakichkolwiek porad na ' + |
|||
'życzenie. Jeżeli masz jakąś prośbę o poradę, <b>nie zgłaszaj jej tutaj</b>.</p>' + |
|||
'<p>Informacje, jak skontaktować się z Wikipedią, można znaleźć na stronie:</p>' + |
|||
'<ul><li><a href="' + mw.util.getUrl( 'Wikipedia:Kontakt' ) + '">Kontakt</a></li></ul></div>', |
|||
'wikibugs-article-intro': '<p>Możesz zgłaszać znalezione błędy w ' + |
|||
'artykułach w Wikipedii, jednak pamiętaj, że Wikipedia to ' + |
|||
'<a href="' + mw.util.getUrl( 'Wiki' ) + '">wiki</a> i można, ' + |
|||
'a nawet należy <a href="' + mw.util.getUrl( 'Wikipedia:Śmiało modyfikuj strony' ) + '">' + |
|||
'śmiało poprawiać znalezione błędy samemu</a>. ' + |
|||
'Zdajemy sobie jednak sprawę z faktu, że niektórzy czytelnicy Wikipedii mogą z różnych ' + |
|||
'przyczyn nie chcieć samodzielnie poprawiać artykułów. ' + |
|||
'Jeśli to możliwe, dodaj do zgłoszenia informację o źródle, na podstawie którego ' + |
|||
'stwierdzasz istnienie błędu.</p><p><strong>Jeżeli potrafisz poprawić ' + |
|||
'błąd – nie zgłaszaj go tutaj.</strong></p>' + |
|||
'<p><strong>Preferowany format zgłoszenia prostych błędów:</strong></p><ul>' + |
|||
'<li>Jest: [podaj fragment zawierający błąd]</li>' + |
|||
'<li>Powinno być: [podaj poprawną wersję (o ile jest znana)]</li>' + |
|||
'<li>Uzasadnienie: [uzasadnij konieczność poprawy, nawet jeśli wydaje Ci się to oczywiste; <a href="' + |
|||
mw.util.getUrl( 'Wikipedia:Weryfikowalność' ) + '">podaj źródła</a>]</li></ul></p>', |
|||
'wikibugs-image-intro': '<p>Tu możesz zgłaszać grafiki, które łamią licencję, ' + |
|||
'mają swoje lepsze odpowiedniki w Commons, są błędnie opisane itp.</p>' + |
|||
'<p><strong>Jeżeli potrafisz poprawić błąd – nie zgłaszaj go tutaj.</strong></p>', |
|||
'wikibugs-copyright': '<p>Wysyłając zgłoszenie, wyrażasz nieodwołalną zgodę na udostępnianie Twojego wkładu ' + |
|||
'na licencjach CC-BY-SA 3.0 i GFDL oraz na wykorzystanie go w dowolnej formie ' + |
|||
'pod warunkiem podania przynajmniej hiperłącza lub adresu URL do strony, ' + |
|||
'na której powstała treść. Treść ta musi być dostępna na tych zasadach, ' + |
|||
'jeśli nie jest wynikiem Twojej samodzielnej pracy.</p>', |
|||
'wikibugs-already-reported-notice': '<p><strong>Uwaga:</strong> Jeśli zamieściłeś/-aś raport o błędzie, ' + |
|||
'a teraz go już nie ma, to najprawdopodobniej został on naprawiony. <ul>' + |
|||
'<li><a href="' + mw.util.getUrl( reportPage ) + '">' + |
|||
'Zobacz listę aktualnie zgłoszonych błędów</a> oraz</li>' + |
|||
'<li><a href="' + mw.util.getUrl( reportPage, { action: 'history' } ) + '">' + |
|||
'historię zmian wprowadzanych na tej stronie.</a></li></ul>' + |
|||
'<br>' + |
|||
'<p><strong>Zgłoszenie będzie publicznie dostępne – prosimy nie podawać swoich danych teleadresowych!</strong></p>', |
|||
'wikibugs-new-report': 'Nowe zgłoszenie: /* $1 */' |
|||
} ); |
|||
} |
|||
function buildWindowManager() { |
|||
/** |
|||
var wikibugsDialog, windowManager, |
|||
* Returns a namespace number of a specifed page. |
|||
canEdit = true, |
|||
* @param title A title of the page. |
|||
currentTitle = mw.Title.newFromText( config.wgPageName ), |
|||
*/ |
|||
isBadPage = badPages.indexOf( currentTitle.toText() ) !== -1; |
|||
getPageNamespaceNumber: function( title ) { |
|||
var matches = title.match( /^([^:]+)/ ); |
|||
if ( ( config.wgRestrictionEdit || [] ).length ) { |
|||
if ( matches ) { |
|||
canEdit = config.wgRestrictionEdit.some( function ( group ) { |
|||
var key = matches[1].toLowerCase(); |
|||
return config.wgUserGroups.indexOf( group ) !== -1; |
|||
var namespaces = mw.config.get( 'wgNamespaceIds' ); |
|||
var result = namespaces[key]; |
|||
if ( result !== null ) { |
|||
return result; |
|||
} |
|||
} |
|||
return 0; |
|||
}, |
|||
/** |
|||
* Returns a refined page title. |
|||
* @param title A title of the page. |
|||
*/ |
|||
getRefinedPageName: function( title ) { |
|||
return title.replace( /_/g, ' ' ).trim(); |
|||
}, |
|||
/** |
|||
* Sets up the gadget. |
|||
*/ |
|||
init: function() { |
|||
var that = this; |
|||
var excluded = false; |
|||
// Special pages and MediaWiki pages are excluded |
|||
if ( jQuery.inArray( mw.config.get( 'wgNamespaceNumber' ), [-1, 8] ) > -1 ) { |
|||
excluded = true; |
|||
} else { |
|||
var name = this.getRefinedPageName( mw.config.get( 'wgPageName' ) ); |
|||
excluded = jQuery.inArray( name, this.excludedPages ) !== -1; |
|||
} |
|||
// FIXME: This doesn't exists on "standard", "cologneblue" (no ids) and "nostalgia" (no sidebar) |
|||
var $articleBugLink = jQuery( '#n-bug_in_article' ); |
|||
var $imageBugLink = jQuery( '#n-bad-image' ); |
|||
if ( excluded ) { |
|||
// Hide the links |
|||
$articleBugLink.hide(); |
|||
$imageBugLink.hide(); |
|||
return; |
|||
} |
|||
$articleBugLink.find( 'a' ) |
|||
.attr( 'href', '#' ) |
|||
.click( function( event ) { |
|||
that.open( that.articleIntro ); |
|||
event.preventDefault(); |
|||
} ); |
|||
$imageBugLink.find( 'a' ) |
|||
.attr( 'href', '#' ) |
|||
.click( function( event ) { |
|||
that.open( that.imageIntro ); |
|||
event.preventDefault(); |
|||
} ); |
|||
// Link on the report-an-error page itself |
|||
jQuery( '#report-bug-link a' ).click( function( event ) { |
|||
that.open( that.articleIntro ); |
|||
event.preventDefault(); |
|||
} ); |
} ); |
||
} |
} |
||
function WikibugsDialog( config ) { |
|||
/** |
|||
WikibugsDialog.super.call( this, config ); |
|||
* Redirects to the edit page. |
|||
} |
|||
*/ |
|||
goToEditPage: function() { |
|||
OO.inheritClass( WikibugsDialog, OO.ui.ProcessDialog ); |
|||
var $editLink = jQuery( '#ca-edit' ).find( 'a' ); |
|||
window.location = $editLink.attr( 'href' ) || mw.util.getUrl( this.reportPage ); |
|||
WikibugsDialog.static.name = 'wikibugs'; |
|||
}, |
|||
WikibugsDialog.static.title = mw.msg( 'wikibugs-dialog-title' ); |
|||
WikibugsDialog.static.actions = [ |
|||
* Shows the dialog window. |
|||
{ |
|||
* @param infoHtml The message content. |
|||
action: 'continue', |
|||
*/ |
|||
modes: 'info', |
|||
open: function( infoHtml ) { |
|||
label: mw.msg( 'wikibugs-open-form-button' ), |
|||
var that = this; |
|||
flags: [ 'primary', 'progressive' ] |
|||
}, |
|||
var can_edit = document.getElementById( 'ca-edit' ) ? true : false; |
|||
{ |
|||
modes: 'info', |
|||
var $dialog = jQuery( '<div id="dialogContent"></div>' ).append( infoHtml ); |
|||
flags: [ 'safe', 'close' ] |
|||
}, |
|||
if ( mw.user.isAnon() ) { |
|||
{ |
|||
$dialog.append( '<p>' + mw.msg( 'wikibugs-ip-address-notice' ) + '</p>' ); |
|||
action: 'submit', |
|||
modes: 'report', |
|||
label: mw.msg( 'wikibugs-submit-report-button' ), |
|||
flags: [ 'primary', 'progressive' ] |
|||
}, |
|||
{ |
|||
action: 'submit-captcha', |
|||
modes: 'captcha', |
|||
label: mw.msg( 'wikibugs-submit-report-button' ), |
|||
flags: [ 'primary', 'progressive' ] |
|||
}, |
|||
{ |
|||
action: 'back-to-info', |
|||
modes: 'report', |
|||
flags: [ 'safe', 'back' ] |
|||
}, |
|||
{ |
|||
action: 'back-to-report', |
|||
modes: 'captcha', |
|||
flags: [ 'safe', 'back' ] |
|||
} |
} |
||
]; |
|||
var buttons = {}; |
|||
if ( canEdit ) { |
|||
buttons[mw.msg( 'wikibugs-cancel-button' )] = function() { |
|||
WikibugsDialog.static.actions.push( { |
|||
jQuery( this ).dialog( 'close' ); |
|||
action: 'edit', |
|||
}; |
|||
modes: 'info', |
|||
buttons[mw.msg( 'wikibugs-open-form-button' )] = function() { |
|||
label: mw.msg( 'wikibugs-edit-page-button' ), |
|||
that.openForm( this ); |
|||
icon: 'edit' |
|||
}; |
|||
if ( can_edit ) { |
|||
buttons[mw.msg( 'wikibugs-edit-page-button' )] = function() { |
|||
that.goToEditPage(); |
|||
}; |
|||
} |
|||
$dialog.dialog( { |
|||
width: 700, |
|||
height: 500, |
|||
modal: true, |
|||
resizable: false, |
|||
draggable: true, |
|||
closeOnEscape: true, |
|||
dialogClass: 'reportBugDialog', |
|||
title: mw.msg( 'wikibugs-dialog-title' ), |
|||
close: function() { |
|||
jQuery( this ).dialog( 'destroy' ).remove(); |
|||
}, |
|||
buttons: buttons |
|||
} ); |
} ); |
||
} |
|||
jQuery( 'div.reportBugDialog button:last' ).focus(); |
|||
WikibugsDialog.prototype.initialize = function () { |
|||
/** |
|||
WikibugsDialog.super.prototype.initialize.apply( this, arguments ); |
|||
* Shows the form in the dialog window. |
|||
*/ |
|||
openForm: function( dialog ) { |
|||
var that = this; |
|||
jQuery( '#dialogContent' ).empty().append( |
|||
'<form name="WikibugForm" enctype="multipart/form-data">' + |
|||
'<fieldset>' + |
|||
'<label for="wbPageTitle">' + mw.msg( 'wikibugs-page-name-label' ) + '</label>' + |
|||
'<input id="wbPageTitle" type="text" name="wbPageTitle" class="text ui-widget-content ui-corner-all" />' + |
|||
'<label for="wbText">' + mw.msg( 'wikibugs-report-content-label' ) + '</label>' + |
|||
'<textarea id="wbText" name="wbText" rows="6" class="text ui-widget-content ui-corner-all" ' + |
|||
'placeholder="' + mw.msg( 'wikibugs-report-content-placeholder' ) + '"></textarea>' + |
|||
'<label for="wbAuthor">' + mw.msg( 'wikibugs-signature-label' ) + '</label>' + |
|||
'<input id="wbAuthor" type="text" class="text ui-widget-content ui-corner-all"/>' + |
|||
'</fieldset>' + |
|||
'<small>' + mw.msg( 'wikibugs-copyright' ) + '</small>' + |
|||
'<img id="wikibugs-loading-icon" src="//upload.wikimedia.org/wikipedia/commons/4/49/Linux_Ubuntu_Loader.gif" style="display:none;"/>' + |
|||
'</form>' |
|||
); |
|||
var buttons = {}; |
|||
buttons[mw.msg( 'wikibugs-cancel-button' )] = function() { |
|||
jQuery( this ).dialog( 'close' ); |
|||
}; |
|||
buttons[mw.msg( 'wikibugs-submit-report-button' )] = function() { |
|||
that.submitForm( this ); |
|||
}; |
|||
jQuery( dialog ).dialog( 'option', 'buttons', buttons ); |
|||
if ( this.isValidPageName( mw.config.get( 'wgPageName' ) ) ) { |
|||
jQuery( '#wbPageTitle' ).val( this.getRefinedPageName( mw.config.get( 'wgPageName' ) ) ); |
|||
} |
|||
if ( !mw.user.isAnon() ) { |
|||
var author = document.getElementById( 'wbAuthor' ); |
|||
author.value = '~~' + '~~'; |
|||
author.disabled = 'disabled'; |
|||
} |
|||
}, |
|||
/** |
|||
* Indicates wheter submit should be ignored. |
|||
*/ |
|||
suppressSubmit: false, |
|||
api: null, |
|||
/** |
|||
* Sends the contents of the form. |
|||
*/ |
|||
submitForm: function( dialog ) { |
|||
if ( this.suppressSubmit ) { |
|||
return; |
|||
} |
|||
var form = document.forms.WikibugForm; |
|||
var content = form.wbText.value; |
|||
var that = this; |
|||
if ( |
|||
content.length < 20 || |
|||
!content.match( ' ' ) ) { |
|||
// Description too short or unchanged |
|||
alert( mw.msg( 'wikibugs-incomplete-information' ) ); |
|||
form.wbText.focus(); |
|||
return; |
|||
} |
|||
content = content.trim(); |
|||
// Append a signature to the report |
|||
if ( !mw.user.isAnon() ) { |
|||
content += mw.msg( 'wikibugs-reported-by', '~~' + '~~' ); |
|||
} else { |
|||
content += mw.msg( 'wikibugs-reported-by', form.wbAuthor.value + ' ~~' + '~~' ); |
|||
} |
|||
var reportedPage = this.getRefinedPageName( form.wbPageTitle.value.replace( /[\[\]]/g, '' ) ); |
|||
var isFile = this.getPageNamespaceNumber( reportedPage ) === 6; |
|||
if ( !this.isValidPageName( reportedPage ) ) { |
|||
alert( mw.msg( 'wikibugs-invalid-page' ) ); |
|||
var refinedPageName = this.getRefinedPageName( mw.config.get( 'wgPageName' ) ); |
|||
if ( this.isValidPageName( refinedPageName ) ) { |
|||
form.wbPageTitle.value = refinedPageName; |
|||
} else { |
|||
form.wbPageTitle.value = ''; |
|||
form.wbPageTitle.focus(); |
|||
} |
|||
return; |
|||
} |
|||
this.suppressSubmit = true; |
|||
var $loadingIcon = jQuery( '#wikibugs-loading-icon' ); |
|||
$loadingIcon.show(); |
|||
var toInsert = '=== [[:' + reportedPage + ']] ===\n\n{{Status zgłoszenia|nowe}}\n' + content; |
|||
//initialise the API |
|||
this.api = new mw.Api(); |
|||
this.infoPanel = new OO.ui.PanelLayout( { |
|||
var reportPage = this.reportPage.replace( / /g, '_' ); |
|||
padded: true, |
|||
expanded: false, |
|||
content: [ |
|||
new OO.ui.HtmlSnippet( mw.msg( 'wikibugs-bad-reports-text' ) ), |
|||
new OO.ui.HtmlSnippet( mw.msg( config.wgNamespaceNumber !== config.wgNamespaceIds.file |
|||
? 'wikibugs-article-intro' |
|||
: 'wikibugs-image-intro' |
|||
) ), |
|||
new OO.ui.HtmlSnippet( mw.msg( 'wikibugs-already-reported-notice' ) ) |
|||
] |
|||
} ); |
|||
this.titleInput = new mw.widgets.TitleInputWidget( { |
|||
this.api.get({ |
|||
required: true, |
|||
showMissing: false, |
|||
data: { actions: this.getActions() }, |
|||
rvprop: 'content|timestamp', |
|||
value: !isBadPage ? currentTitle.toText() : '', |
|||
rvdir: 'older', |
|||
disabled: !isBadPage |
|||
titles: this.reportPage, |
|||
} ); |
|||
rvslots: 'main', |
|||
this.titleInput.setValidation( function () { |
|||
var title = mw.Title.newFromText( this.getValue().replace( /[\[\]]/g, '' ) ); |
|||
for (var pageid in page.query.pages) break; |
|||
text = page.query.pages[pageid].revisions[0].slots.main['*']; |
|||
if ( title && title.toString() !== '' && badPages.indexOf( title.toString() ) === -1 ) { |
|||
//process the wikitext of the page |
|||
this.getData().actions.get( { actions: 'submit' } )[ 0 ].setDisabled( false ); |
|||
var sectionLine; |
|||
return true; |
|||
if ( isFile ) { |
|||
sectionLine = mw.msg( 'wikibugs-file-section-line' ); |
|||
} else { |
|||
sectionLine = mw.msg( 'wikibugs-page-section-line' ); |
|||
} |
} |
||
return false; |
|||
var newText = text.replace( sectionLine, sectionLine + '\n\n' + toInsert ); |
|||
} ); |
|||
if ( text === newText ) { |
|||
// Could not find the section line - simply append; |
|||
this.titleField = new OO.ui.FieldLayout( this.titleInput, { |
|||
newText = text + '\n\n' + toInsert; |
|||
label: mw.msg( 'wikibugs-page-name-label' ), |
|||
align: 'top' |
|||
} ); |
|||
this.summaryInput = new OO.ui.MultilineTextInputWidget( { |
|||
autocomplete: false, |
|||
autofocus: true, |
|||
data: { actions: this.getActions() }, |
|||
placeholder: mw.msg( 'wikibugs-report-content-placeholder' ), |
|||
required: true, |
|||
rows: 6 |
|||
} ); |
|||
this.summaryInput.setValidation( function () { |
|||
if ( this.getValue().trim().length >= 20 ) { |
|||
this.getData().actions.get( { actions: 'submit' } )[ 0 ].setDisabled( false ); |
|||
return true; |
|||
} |
} |
||
return false; |
|||
//EDIT THE "REPORT AN ERROR" PAGE |
|||
} ); |
|||
var request = { |
|||
action: 'edit', |
|||
this.summaryField = new OO.ui.FieldLayout( this.summaryInput, { |
|||
title: page.query.pages[pageid].title, |
|||
label: mw.msg( 'wikibugs-report-content-label' ), |
|||
text: newText, |
|||
align: 'top' |
|||
summary: mw.msg( 'wikibugs-new-report', reportedPage ), |
|||
} ); |
|||
minor: false, |
|||
basetimestamp: page.query.pages[pageid].revisions[0].timestamp, |
|||
this.reportFieldset = new OO.ui.FieldsetLayout( { |
|||
starttimestamp: page.curtimestamp |
|||
items: [ this.titleField, this.summaryField ] |
|||
}; |
|||
} ); |
|||
this.reportPanel = new OO.ui.PanelLayout( { |
|||
padded: true, |
|||
expanded: false, |
|||
content: [ this.reportFieldset ] |
|||
} ); |
|||
if ( mw.user.isAnon() ) { |
|||
this.reportAnonNotice = new OO.ui.HtmlSnippet( mw.msg( 'wikibugs-ip-address-notice' ) ); |
|||
this.reportPanel.$element.append( this.reportAnonNotice.toString() ); |
|||
} |
|||
this.copyrightNotice = new OO.ui.HtmlSnippet( mw.msg( 'wikibugs-copyright' ) ); |
|||
this.reportPanel.$element.append( this.copyrightNotice.toString() ); |
|||
this.captchaPanel = new OO.ui.PanelLayout( { |
|||
padded: true, |
|||
expanded: false |
|||
} ); |
|||
this.stackLayout = new OO.ui.StackLayout( { |
|||
items: [ this.infoPanel, this.reportPanel, this.captchaPanel ] |
|||
} ); |
|||
this.$body.append( this.stackLayout.$element ); |
|||
}; |
|||
WikibugsDialog.prototype.getSetupProcess = function ( data ) { |
|||
return WikibugsDialog.super.prototype.getSetupProcess.call( this, data ).next( function () { |
|||
this.stackLayout.setItem( this.infoPanel ); |
|||
this.getActions().setMode( 'info' ); |
|||
}, this ); |
|||
}; |
|||
WikibugsDialog.prototype.getActionProcess = function ( action ) { |
|||
if ( action === 'continue' ) { |
|||
this.stackLayout.setItem( this.reportPanel ); |
|||
this.getActions().setMode( 'report' ); |
|||
this.titleInput.getValue().trim() === '' ? this.titleInput.focus() : this.summaryInput.focus(); |
|||
} else if ( action === 'back-to-info' ) { |
|||
this.stackLayout.setItem( this.infoPanel ); |
|||
this.getActions().setMode( 'info' ); |
|||
} else if ( action === 'back-to-report' ) { |
|||
delete this.editParams; |
|||
this.stackLayout.setItem( this.reportPanel ); |
|||
this.getActions().setMode( 'report' ); |
|||
} else if ( action === 'edit' ) { |
|||
return new OO.ui.Process( function () { |
|||
this.close(); |
|||
window.location = mw.util.getUrl( null, { action: 'edit' } ); |
|||
}, this ); |
|||
} else if ( action === 'submit' ) { |
|||
return new OO.ui.Process( function () { |
|||
return this.titleInput.getValidity().catch( function () { |
|||
return $.Deferred().reject( new OO.ui.Error( mw.msg( 'wikibugs-invalid-page' ), { |
|||
recoverable: false |
|||
} ) ).promise(); |
|||
} ); |
|||
}, this ).next( function () { |
|||
return this.summaryInput.getValidity().catch( function () { |
|||
return $.Deferred().reject( new OO.ui.Error( mw.msg( 'wikibugs-incomplete-information' ), { |
|||
recoverable: false |
|||
} ) ).promise(); |
|||
} ); |
|||
}, this ).next( function () { |
|||
var dialog = this, |
|||
reportedPage = this.titleInput.getValue().trim(), |
|||
reportContent = this.summaryInput.getValue().trim() + ' ~~' + '~~', |
|||
reportSection = mw.format( '=== [[:$1' + ']] ===\n{{Status zgłoszenia|nowe}' + '}\n\n$2', reportedPage, reportContent ), |
|||
isFile = mw.Title.newFromText( reportedPage ).getNamespaceId() === config.wgNamespaceIds.file, |
|||
sectionMarker = mw.msg( !isFile ? 'wikibugs-page-section-line' : 'wikibugs-file-section-line' ); |
|||
this.editParams = this.editParams || { |
|||
summary: mw.msg( 'wikibugs-new-report', reportedPage ) |
|||
}; |
|||
return api.edit( reportPage, function ( revision ) { |
|||
return $.extend( { |
|||
text: revision.content.indexOf( sectionMarker ) !== -1 |
|||
? revision.content.replace( sectionMarker, sectionMarker + '\n\n' + reportSection ) |
|||
: revision.content + '\n\n' + reportSection // simply append |
|||
}, dialog.editParams ); |
|||
} ).then( function ( res ) { |
|||
var deferred = $.Deferred(); |
|||
if ( res.result === 'Failure' && 'captcha' in res ) { |
|||
dialog.captchaWidget = new mw.libs.confirmEdit.CaptchaInputWidget( res.captcha ); |
|||
dialog.captchaPanel.$element.html( dialog.captchaWidget.$element ); |
|||
dialog.captchaWidget.on( 'load', function () { |
|||
dialog.stackLayout.setItem( dialog.captchaPanel ); |
|||
dialog.getActions().setMode( 'captcha' ); |
|||
deferred.resolve(); |
|||
} ); |
|||
} else { |
|||
location.href = mw.util.getUrl( reportPage ) + '#' + mw.util.escapeIdForLink( reportedPage ); |
|||
if ( currentTitle.toText() === reportPage ) { |
|||
that.reportBug( dialog, reportedPage, request ); |
|||
location.reload(); |
|||
}); |
|||
} else { |
|||
}, |
|||
deferred.resolve(); |
|||
} |
|||
reportBug: function( dialog, reportedPage, editRequest ) { |
|||
} |
|||
var that = this; |
|||
var reportPage = this.reportPage.replace( / /g, '_' ); |
|||
return deferred.promise(); |
|||
var $loadingIcon = jQuery( '#wikibugs-loading-icon' ); |
|||
}, function ( code, data ) { |
|||
$loadingIcon.show(); |
|||
var error = new OO.ui.Error( api.getErrorMessage( data ) ); |
|||
this.suppressSubmit = true; |
|||
return $.Deferred().reject( error ).promise(); |
|||
return this.api.postWithEditToken(editRequest).always(function(res){ |
|||
if ( res && res.edit && res.edit.result && res.edit.result === 'Success' ) { |
|||
//saved successfully - go to the report page |
|||
window.location = mw.util.getUrl(reportPage + '#' + reportedPage); |
|||
if ( mw.config.get( 'wgPageName' ) === reportPage ) { |
|||
//we're already there |
|||
window.location.reload(); |
|||
} |
|||
} else if ( res && res.edit && res.edit.result && res.edit.result === 'Failure' && res.edit.captcha ) { |
|||
mw.loader.using( 'ext.confirmEdit.CaptchaInputWidget' ).done( function() { |
|||
that.solveCaptcha( dialog, reportedPage, editRequest, res.edit.captcha ); |
|||
} ); |
} ); |
||
} |
}, this ); |
||
} else if ( action === 'submit-captcha' ) { |
|||
//handle the error |
|||
$.extend( this.editParams, { |
|||
alert( mw.msg( 'wikibugs-ajax-error' ) ); |
|||
captchaid: this.captchaWidget.getCaptchaId(), |
|||
} |
|||
captchaword: this.captchaWidget.getCaptchaWord() |
|||
}).always( function() { |
|||
} ); |
|||
this.suppressSubmit = false; |
|||
$loadingIcon.hide(); |
|||
return new OO.ui.Process( function () { |
|||
} ); |
|||
return this.executeAction( 'submit' ); |
|||
}, |
|||
}, this ); |
|||
} |
|||
return WikibugsDialog.super.prototype.getActionProcess.call( this, action ); |
|||
}; |
|||
wikibugsDialog = new WikibugsDialog( { |
|||
size: 'large' |
|||
} ); |
|||
windowManager = new OO.ui.WindowManager(); |
|||
windowManager.addWindows( { wikibugs: wikibugsDialog } ); |
|||
$( document.body ).append( windowManager.$element ); |
|||
return windowManager; |
|||
} |
|||
function lazyOpen() { |
|||
solveCaptcha: function( dialog, reportedPage, editRequest, captchaData ) { |
|||
mw.loader.using( [ |
|||
var that = this; |
|||
'oojs-ui-core', |
|||
var captchaInput = new mw.libs.confirmEdit.CaptchaInputWidget( captchaData ); |
|||
'oojs-ui-widgets', |
|||
'oojs-ui-windows', |
|||
'oojs-ui.styles.icons-editing-core', |
|||
'mediawiki.api', |
|||
'mediawiki.Title', |
|||
'mediawiki.user', |
|||
'mediawiki.util', |
|||
'mediawiki.widgets', |
|||
'ext.confirmEdit.CaptchaInputWidget' |
|||
] ).done( function () { |
|||
if ( windowManager === null ) { |
|||
mw.util.addCSS( '#wb-bad-reports { float: right; width: 200px; padding: 4px 10px 18px; margin: 2px 0px 0px 10px; font-size: 95%; border: 2px solid #900; }' ); |
|||
configureMessages(); |
|||
api = new mw.Api( { parameters: { |
|||
errorformat: 'html', |
|||
errorlang: config.wgUserLanguage, |
|||
errorsuselocal: true |
|||
} } ); |
|||
windowManager = buildWindowManager(); |
|||
} |
|||
windowManager.openWindow( 'wikibugs' ); |
|||
} ); |
|||
} |
|||
$( function () { |
|||
jQuery( '#dialogContent' ).empty().append( |
|||
$( '#n-bug_in_article, #n-bad-image' ).find( 'a' ) |
|||
captchaInput.$element[ 0 ], |
|||
.attr( 'href', '#' ) |
|||
'<img id="wikibugs-loading-icon" src="//upload.wikimedia.org/wikipedia/commons/4/49/Linux_Ubuntu_Loader.gif" style="display:none;"/>' |
|||
.on( 'click', function ( evt ) { |
|||
); |
|||
lazyOpen(); |
|||
evt.preventDefault(); |
|||
captchaInput.on( 'load', function() { |
|||
captchaInput.focus(); |
|||
captchaInput.scrollElementIntoView(); |
|||
} ); |
} ); |
||
// Link on the report-an-error page itself |
|||
var buttons = {}; |
|||
$( '#report-bug-link a' ).on( 'click', function ( evt ) { |
|||
lazyOpen(); |
|||
jQuery( this ).dialog( 'close' ); |
|||
evt.preventDefault(); |
|||
}; |
|||
} ); |
|||
buttons[mw.msg( 'wikibugs-submit-report-button' )] = function() { |
|||
that.reportBug( dialog, reportedPage, jQuery.extend( editRequest, { |
|||
captchaid: captchaInput.getCaptchaId(), |
|||
captchaword: captchaInput.getCaptchaWord() |
|||
} ) ); |
|||
}; |
|||
jQuery( dialog ).dialog( 'option', 'buttons', buttons ); |
|||
captchaInput.emit( 'load' ); |
|||
} |
|||
}; |
|||
jQuery( document ).ready( function() { |
|||
wikiBugsGadget.init(); |
|||
} ); |
} ); |
Wersja z 18:30, 16 mar 2022
/**
* @author: [[:pl:User:Dodek]] (idea and text)
* @author: [[:pl:User:Adziura]] (idea and text)
* @author: [[:pl:User:Nux]] (implementation)
* @author: [[:pl:User:Saper]] (implementation)
* @author: [[:pl:User:Beau]] (implementation)
* @author: [[:pt:User:Helder.wiki]] (implementation)
* @author: [[:pl:User:Peter Bowman]] (rework)
*/
var config = mw.config.get( [
'wgNamespaceIds',
'wgNamespaceNumber',
'wgPageName',
'wgRestrictionEdit',
'wgUserGroups',
'wgUserLanguage'
] ),
/**
* A name of a page where reports are saved.
*/
reportPage = 'Wikipedia:Zgłoś błąd w artykule',
/**
* Black list of pages which reports should not refer to.
*/
badPages = [
reportPage,
'Wikipedia:Sprzątanie Wikipedii',
'Wikipedia:Zgłoszone grafiki',
'Wikipedia:Kontakt z wikipedystami',
'Dyskusja Wikipedii:Kontakt z wikipedystami',
'Wikipedia:Prośby o przejrzenie edycji'
],
windowManager = null,
api = null;
function configureMessages() {
mw.messages.set( {
'wikibugs-dialog-title': 'Zgłoś błąd',
'wikibugs-open-form-button': 'Przejdź do formularza',
'wikibugs-edit-page-button': 'Popraw samodzielnie',
'wikibugs-submit-report-button': 'Wyślij',
'wikibugs-ip-address-notice': '<p><strong>Uwaga:</strong> Twój adres IP zostanie zapisany w historii zgłoszeń.</p>',
'wikibugs-page-name-label': 'Nazwa strony:',
'wikibugs-report-content-label': 'Treść zgłoszenia:',
'wikibugs-report-content-placeholder': 'Opisz błąd możliwie jak najdokładniej. Jeżeli masz taką możliwość, podaj źródło informacji.',
'wikibugs-signature-label': 'Podpis:',
'wikibugs-incomplete-information': 'Opisz dokładnie zgłaszany błąd. Wprowadzony opis jest za krótki.',
'wikibugs-invalid-page': 'Podaj nazwę strony.',
'wikibugs-file-section-line': '<!-- Zgłoszenia błędów w plikach wstawiaj poniżej tej linii. Nowe na górze. -->',
'wikibugs-page-section-line': '<!-- Zgłoszenia błędów w artykułach wstawiaj poniżej tej linii. Nowe na górze. -->',
'wikibugs-bad-reports-text': '<div id="wb-bad-reports"><p>Formularz <strong>nie służy</strong> do zgłaszania próśb o rozwinięcie ' +
'bądź stworzenie nowych artykułów. Zobacz stronę:</p><ul>' +
'<li><a href="' + mw.util.getUrl( 'Wikipedia:Propozycje tematów' ) + '">' +
'Propozycje tematów</a></li></ul><p>Wikipedia nie udziela jakichkolwiek porad na ' +
'życzenie. Jeżeli masz jakąś prośbę o poradę, <b>nie zgłaszaj jej tutaj</b>.</p>' +
'<p>Informacje, jak skontaktować się z Wikipedią, można znaleźć na stronie:</p>' +
'<ul><li><a href="' + mw.util.getUrl( 'Wikipedia:Kontakt' ) + '">Kontakt</a></li></ul></div>',
'wikibugs-article-intro': '<p>Możesz zgłaszać znalezione błędy w ' +
'artykułach w Wikipedii, jednak pamiętaj, że Wikipedia to ' +
'<a href="' + mw.util.getUrl( 'Wiki' ) + '">wiki</a> i można, ' +
'a nawet należy <a href="' + mw.util.getUrl( 'Wikipedia:Śmiało modyfikuj strony' ) + '">' +
'śmiało poprawiać znalezione błędy samemu</a>. ' +
'Zdajemy sobie jednak sprawę z faktu, że niektórzy czytelnicy Wikipedii mogą z różnych ' +
'przyczyn nie chcieć samodzielnie poprawiać artykułów. ' +
'Jeśli to możliwe, dodaj do zgłoszenia informację o źródle, na podstawie którego ' +
'stwierdzasz istnienie błędu.</p><p><strong>Jeżeli potrafisz poprawić ' +
'błąd – nie zgłaszaj go tutaj.</strong></p>' +
'<p><strong>Preferowany format zgłoszenia prostych błędów:</strong></p><ul>' +
'<li>Jest: [podaj fragment zawierający błąd]</li>' +
'<li>Powinno być: [podaj poprawną wersję (o ile jest znana)]</li>' +
'<li>Uzasadnienie: [uzasadnij konieczność poprawy, nawet jeśli wydaje Ci się to oczywiste; <a href="' +
mw.util.getUrl( 'Wikipedia:Weryfikowalność' ) + '">podaj źródła</a>]</li></ul></p>',
'wikibugs-image-intro': '<p>Tu możesz zgłaszać grafiki, które łamią licencję, ' +
'mają swoje lepsze odpowiedniki w Commons, są błędnie opisane itp.</p>' +
'<p><strong>Jeżeli potrafisz poprawić błąd – nie zgłaszaj go tutaj.</strong></p>',
'wikibugs-copyright': '<p>Wysyłając zgłoszenie, wyrażasz nieodwołalną zgodę na udostępnianie Twojego wkładu ' +
'na licencjach CC-BY-SA 3.0 i GFDL oraz na wykorzystanie go w dowolnej formie ' +
'pod warunkiem podania przynajmniej hiperłącza lub adresu URL do strony, ' +
'na której powstała treść. Treść ta musi być dostępna na tych zasadach, ' +
'jeśli nie jest wynikiem Twojej samodzielnej pracy.</p>',
'wikibugs-already-reported-notice': '<p><strong>Uwaga:</strong> Jeśli zamieściłeś/-aś raport o błędzie, ' +
'a teraz go już nie ma, to najprawdopodobniej został on naprawiony. <ul>' +
'<li><a href="' + mw.util.getUrl( reportPage ) + '">' +
'Zobacz listę aktualnie zgłoszonych błędów</a> oraz</li>' +
'<li><a href="' + mw.util.getUrl( reportPage, { action: 'history' } ) + '">' +
'historię zmian wprowadzanych na tej stronie.</a></li></ul>' +
'<br>' +
'<p><strong>Zgłoszenie będzie publicznie dostępne – prosimy nie podawać swoich danych teleadresowych!</strong></p>',
'wikibugs-new-report': 'Nowe zgłoszenie: /* $1 */'
} );
}
function buildWindowManager() {
var wikibugsDialog, windowManager,
canEdit = true,
currentTitle = mw.Title.newFromText( config.wgPageName ),
isBadPage = badPages.indexOf( currentTitle.toText() ) !== -1;
if ( ( config.wgRestrictionEdit || [] ).length ) {
canEdit = config.wgRestrictionEdit.some( function ( group ) {
return config.wgUserGroups.indexOf( group ) !== -1;
} );
}
function WikibugsDialog( config ) {
WikibugsDialog.super.call( this, config );
}
OO.inheritClass( WikibugsDialog, OO.ui.ProcessDialog );
WikibugsDialog.static.name = 'wikibugs';
WikibugsDialog.static.title = mw.msg( 'wikibugs-dialog-title' );
WikibugsDialog.static.actions = [
{
action: 'continue',
modes: 'info',
label: mw.msg( 'wikibugs-open-form-button' ),
flags: [ 'primary', 'progressive' ]
},
{
modes: 'info',
flags: [ 'safe', 'close' ]
},
{
action: 'submit',
modes: 'report',
label: mw.msg( 'wikibugs-submit-report-button' ),
flags: [ 'primary', 'progressive' ]
},
{
action: 'submit-captcha',
modes: 'captcha',
label: mw.msg( 'wikibugs-submit-report-button' ),
flags: [ 'primary', 'progressive' ]
},
{
action: 'back-to-info',
modes: 'report',
flags: [ 'safe', 'back' ]
},
{
action: 'back-to-report',
modes: 'captcha',
flags: [ 'safe', 'back' ]
}
];
if ( canEdit ) {
WikibugsDialog.static.actions.push( {
action: 'edit',
modes: 'info',
label: mw.msg( 'wikibugs-edit-page-button' ),
icon: 'edit'
} );
}
WikibugsDialog.prototype.initialize = function () {
WikibugsDialog.super.prototype.initialize.apply( this, arguments );
this.infoPanel = new OO.ui.PanelLayout( {
padded: true,
expanded: false,
content: [
new OO.ui.HtmlSnippet( mw.msg( 'wikibugs-bad-reports-text' ) ),
new OO.ui.HtmlSnippet( mw.msg( config.wgNamespaceNumber !== config.wgNamespaceIds.file
? 'wikibugs-article-intro'
: 'wikibugs-image-intro'
) ),
new OO.ui.HtmlSnippet( mw.msg( 'wikibugs-already-reported-notice' ) )
]
} );
this.titleInput = new mw.widgets.TitleInputWidget( {
required: true,
showMissing: false,
data: { actions: this.getActions() },
value: !isBadPage ? currentTitle.toText() : '',
disabled: !isBadPage
} );
this.titleInput.setValidation( function () {
var title = mw.Title.newFromText( this.getValue().replace( /[\[\]]/g, '' ) );
if ( title && title.toString() !== '' && badPages.indexOf( title.toString() ) === -1 ) {
this.getData().actions.get( { actions: 'submit' } )[ 0 ].setDisabled( false );
return true;
}
return false;
} );
this.titleField = new OO.ui.FieldLayout( this.titleInput, {
label: mw.msg( 'wikibugs-page-name-label' ),
align: 'top'
} );
this.summaryInput = new OO.ui.MultilineTextInputWidget( {
autocomplete: false,
autofocus: true,
data: { actions: this.getActions() },
placeholder: mw.msg( 'wikibugs-report-content-placeholder' ),
required: true,
rows: 6
} );
this.summaryInput.setValidation( function () {
if ( this.getValue().trim().length >= 20 ) {
this.getData().actions.get( { actions: 'submit' } )[ 0 ].setDisabled( false );
return true;
}
return false;
} );
this.summaryField = new OO.ui.FieldLayout( this.summaryInput, {
label: mw.msg( 'wikibugs-report-content-label' ),
align: 'top'
} );
this.reportFieldset = new OO.ui.FieldsetLayout( {
items: [ this.titleField, this.summaryField ]
} );
this.reportPanel = new OO.ui.PanelLayout( {
padded: true,
expanded: false,
content: [ this.reportFieldset ]
} );
if ( mw.user.isAnon() ) {
this.reportAnonNotice = new OO.ui.HtmlSnippet( mw.msg( 'wikibugs-ip-address-notice' ) );
this.reportPanel.$element.append( this.reportAnonNotice.toString() );
}
this.copyrightNotice = new OO.ui.HtmlSnippet( mw.msg( 'wikibugs-copyright' ) );
this.reportPanel.$element.append( this.copyrightNotice.toString() );
this.captchaPanel = new OO.ui.PanelLayout( {
padded: true,
expanded: false
} );
this.stackLayout = new OO.ui.StackLayout( {
items: [ this.infoPanel, this.reportPanel, this.captchaPanel ]
} );
this.$body.append( this.stackLayout.$element );
};
WikibugsDialog.prototype.getSetupProcess = function ( data ) {
return WikibugsDialog.super.prototype.getSetupProcess.call( this, data ).next( function () {
this.stackLayout.setItem( this.infoPanel );
this.getActions().setMode( 'info' );
}, this );
};
WikibugsDialog.prototype.getActionProcess = function ( action ) {
if ( action === 'continue' ) {
this.stackLayout.setItem( this.reportPanel );
this.getActions().setMode( 'report' );
this.titleInput.getValue().trim() === '' ? this.titleInput.focus() : this.summaryInput.focus();
} else if ( action === 'back-to-info' ) {
this.stackLayout.setItem( this.infoPanel );
this.getActions().setMode( 'info' );
} else if ( action === 'back-to-report' ) {
delete this.editParams;
this.stackLayout.setItem( this.reportPanel );
this.getActions().setMode( 'report' );
} else if ( action === 'edit' ) {
return new OO.ui.Process( function () {
this.close();
window.location = mw.util.getUrl( null, { action: 'edit' } );
}, this );
} else if ( action === 'submit' ) {
return new OO.ui.Process( function () {
return this.titleInput.getValidity().catch( function () {
return $.Deferred().reject( new OO.ui.Error( mw.msg( 'wikibugs-invalid-page' ), {
recoverable: false
} ) ).promise();
} );
}, this ).next( function () {
return this.summaryInput.getValidity().catch( function () {
return $.Deferred().reject( new OO.ui.Error( mw.msg( 'wikibugs-incomplete-information' ), {
recoverable: false
} ) ).promise();
} );
}, this ).next( function () {
var dialog = this,
reportedPage = this.titleInput.getValue().trim(),
reportContent = this.summaryInput.getValue().trim() + ' ~~' + '~~',
reportSection = mw.format( '=== [[:$1' + ']] ===\n{{Status zgłoszenia|nowe}' + '}\n\n$2', reportedPage, reportContent ),
isFile = mw.Title.newFromText( reportedPage ).getNamespaceId() === config.wgNamespaceIds.file,
sectionMarker = mw.msg( !isFile ? 'wikibugs-page-section-line' : 'wikibugs-file-section-line' );
this.editParams = this.editParams || {
summary: mw.msg( 'wikibugs-new-report', reportedPage )
};
return api.edit( reportPage, function ( revision ) {
return $.extend( {
text: revision.content.indexOf( sectionMarker ) !== -1
? revision.content.replace( sectionMarker, sectionMarker + '\n\n' + reportSection )
: revision.content + '\n\n' + reportSection // simply append
}, dialog.editParams );
} ).then( function ( res ) {
var deferred = $.Deferred();
if ( res.result === 'Failure' && 'captcha' in res ) {
dialog.captchaWidget = new mw.libs.confirmEdit.CaptchaInputWidget( res.captcha );
dialog.captchaPanel.$element.html( dialog.captchaWidget.$element );
dialog.captchaWidget.on( 'load', function () {
dialog.stackLayout.setItem( dialog.captchaPanel );
dialog.getActions().setMode( 'captcha' );
deferred.resolve();
} );
} else {
location.href = mw.util.getUrl( reportPage ) + '#' + mw.util.escapeIdForLink( reportedPage );
if ( currentTitle.toText() === reportPage ) {
location.reload();
} else {
deferred.resolve();
}
}
return deferred.promise();
}, function ( code, data ) {
var error = new OO.ui.Error( api.getErrorMessage( data ) );
return $.Deferred().reject( error ).promise();
} );
}, this );
} else if ( action === 'submit-captcha' ) {
$.extend( this.editParams, {
captchaid: this.captchaWidget.getCaptchaId(),
captchaword: this.captchaWidget.getCaptchaWord()
} );
return new OO.ui.Process( function () {
return this.executeAction( 'submit' );
}, this );
}
return WikibugsDialog.super.prototype.getActionProcess.call( this, action );
};
wikibugsDialog = new WikibugsDialog( {
size: 'large'
} );
windowManager = new OO.ui.WindowManager();
windowManager.addWindows( { wikibugs: wikibugsDialog } );
$( document.body ).append( windowManager.$element );
return windowManager;
}
function lazyOpen() {
mw.loader.using( [
'oojs-ui-core',
'oojs-ui-widgets',
'oojs-ui-windows',
'oojs-ui.styles.icons-editing-core',
'mediawiki.api',
'mediawiki.Title',
'mediawiki.user',
'mediawiki.util',
'mediawiki.widgets',
'ext.confirmEdit.CaptchaInputWidget'
] ).done( function () {
if ( windowManager === null ) {
mw.util.addCSS( '#wb-bad-reports { float: right; width: 200px; padding: 4px 10px 18px; margin: 2px 0px 0px 10px; font-size: 95%; border: 2px solid #900; }' );
configureMessages();
api = new mw.Api( { parameters: {
errorformat: 'html',
errorlang: config.wgUserLanguage,
errorsuselocal: true
} } );
windowManager = buildWindowManager();
}
windowManager.openWindow( 'wikibugs' );
} );
}
$( function () {
$( '#n-bug_in_article, #n-bad-image' ).find( 'a' )
.attr( 'href', '#' )
.on( 'click', function ( evt ) {
lazyOpen();
evt.preventDefault();
} );
// Link on the report-an-error page itself
$( '#report-bug-link a' ).on( 'click', function ( evt ) {
lazyOpen();
evt.preventDefault();
} );
} );