User:Alexis Jazz/Factotum-test.js: Difference between revisions
Appearance
Content deleted Content added
Alexis Jazz (talk | contribs) store translation in localStorage |
Alexis Jazz (talk | contribs) rewrite postReply function, basic language support through MediaWiki translations, full page editing option, draft option, license change, load ToS dynamically |
||
Line 1: | Line 1: | ||
//Bawl[https://en.wikipedia.org/wiki/User:Alexis_Jazz/Bawl] is a userscript to add comments to discussions with more features and options than usual. Probably better support too. Report issues to the talk page. |
|||
//<nowiki> |
|||
//<nowiki>Bawl is public domain, WTFPL Version 2[http://www.wtfpl.net/about/]. If you don't like that or think it's invalid where you live you may use Bawl under CC BY-SA 3.0, CC BY 2.5 or CC BY 4.0 instead. Your choice. |
|||
//Bawl is a userscript to add comments to discussions with more features and options than usual. Probably better support too. |
|||
if ( ( window.localStorage.BawlenableEverywhere && typeof $('#ca-edit')[0] != "undefined" ) || $('#ca-addsection')[0] || $('.ext-discussiontools-init-replylink-buttons')[0] || $('.BawlCmt')[0] || ( mw.config.get('wgNamespaceNumber') != -1 && mw.config.get('wgNamespaceNumber') != 2 && ( mw.config.get('wgNamespaceNumber') != 0 || mw.config.get('wgDBname') == 'metawiki' ) && mw.config.get('wgNamespaceNumber') != 6 && mw.config.get('wgNamespaceNumber') != 14 && mw.config.get('wgPageContentModel') == 'wikitext' && mw.config.get('wgAction') == 'view' && mw.config.get('wgDiffNewId') == null && window.location.href.match('veaction=') == null && window.location.href.match('oldid=') == null ) ) { |
|||
//https://en.wikipedia.org/wiki/User:Alexis_Jazz/Bawl (report issues to the talk page) |
|||
if ( $('#ca-addsection')[0] || ( $('.ext-discussiontools-init-replylink-buttons')[0] && $('.ext-discussiontools-init-replylink-buttons')[0] ) || ( mw.config.get('wgNamespaceNumber') != -1 && mw.config.get('wgNamespaceNumber') != 2 && ( mw.config.get('wgNamespaceNumber') != 0 || mw.config.get('wgDBname') == 'metawiki' ) && mw.config.get('wgNamespaceNumber') != 6 && mw.config.get('wgNamespaceNumber') != 14 && mw.config.get('wgPageContentModel') == 'wikitext' && mw.config.get('wgAction') == 'view' && mw.config.get('wgDiffNewId') == null && window.location.href.match('veaction=') == null && window.location.href.match('oldid=') == null ) ) { |
|||
Bawl = {}; |
Bawl = {}; |
||
//</nowiki> |
//</nowiki> |
||
Bawl.versionDate = ' |
Bawl.versionDate = '22:17, 13 February 2022 (UTC)'; |
||
//<nowiki> |
//<nowiki> |
||
Bawl.msgsObj = {}; |
Bawl.msgsObj = {}; |
||
Bawl.basicmsgsObj = {}; |
Bawl.basicmsgsObj = {}; |
||
Bawl.wikiMsgsObj = {}; |
Bawl.wikiMsgsObj = {}; |
||
var api = new mw.Api(); |
|||
Bawl.ToSlink = 'https://foundation.wikimedia.org/wiki/Special:MyLanguage/Terms_of_Use'; |
|||
Bawl. |
Bawl.ToSlicenselinks = '<a href="https://creativecommons.org/licenses/by-sa/3.0">CC BY-SA 3.0</a>+<a href="https://en.wikipedia.org/wiki/Wikipedia:Text_of_the_GNU_Free_Documentation_License">GFDL</a>'; //when can we get rid of the GFDL? |
||
Bawl. |
Bawl.ToSmoreInfoLink = '<a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Terms_of_Use">ToU</a>'; |
||
Bawl.GFDLlink = 'https://en.wikipedia.org/wiki/Wikipedia:Text_of_the_GNU_Free_Documentation_License'; |
|||
Bawl.msgsObj.mul = { //multilingual and default texts, selected using wgUserLanguage. Messages that are used beyond the initial opening of the form. |
Bawl.msgsObj.mul = { //multilingual and default texts, selected using wgUserLanguage. Messages that are used beyond the initial opening of the form. |
||
'UILabelInterface':'Interface', |
'UILabelInterface':'Interface', |
||
Line 22: | Line 20: | ||
'secLinks':'Insert links to add subsections', |
'secLinks':'Insert links to add subsections', |
||
'inputBoxTO':'Take over <a href="https://www.mediawiki.org/wiki/Extension:InputBox" target="_new">InputBoxes</a>', |
'inputBoxTO':'Take over <a href="https://www.mediawiki.org/wiki/Extension:InputBox" target="_new">InputBoxes</a>', |
||
'enableEverywhere':'Enable full page editing with Bawl', |
|||
'editLinks':'Insert links to edit my comments', |
'editLinks':'Insert links to edit my comments', |
||
'editNotice':'Show <a href="https://en.wikipedia.org/wiki/Wikipedia:Editnotice" target="_new">editnotices</a>', |
'editNotice':'Show <a href="https://en.wikipedia.org/wiki/Wikipedia:Editnotice" target="_new">editnotices</a>', |
||
Line 29: | Line 28: | ||
'wrongUI':'Put buttons on the wrong side like <a href="' + mw.config.get('wgServer') + mw.config.get('wgArticlePath').replace('$1', 'm:Special:MyLanguage/Talk_pages_project/Feature_summary') + '" target="_new">DiscussionTools</a>', |
'wrongUI':'Put buttons on the wrong side like <a href="' + mw.config.get('wgServer') + mw.config.get('wgArticlePath').replace('$1', 'm:Special:MyLanguage/Talk_pages_project/Feature_summary') + '" target="_new">DiscussionTools</a>', |
||
'livePreview':'Live preview', |
'livePreview':'Live preview', |
||
'saveDraft':'Save unsent comments of >100 characters in browser for up to a week', |
|||
'checkNewComments':'Check for new comments when opening form/preview', |
'checkNewComments':'Check for new comments when opening form/preview', |
||
'limitWidth':'Limit interface width', |
'limitWidth':'Limit interface width', |
||
Line 51: | Line 51: | ||
'debug':'Enable test/debug mode', |
'debug':'Enable test/debug mode', |
||
'saveTo':'Save settings to:', |
'saveTo':'Save settings to:', |
||
'resetPreferencesBrowser':' (browser)', |
|||
'saveSettings':'Save', |
|||
'resetPreferencesCommonJS':' (account)', |
|||
'resetPreferencesBrowser':'Clear browser preferences', |
|||
'resetPreferencesGlobalJS':' (global account)', |
|||
'resetPreferencesCommonJS':'Clear account preferences', |
|||
'resetPreferencesGlobalJS':'Clear global account preferences', |
|||
'watchlistexpirydays':'DAYS days', |
'watchlistexpirydays':'DAYS days', |
||
'BawlCustomInsertPlaceholder':'fooNUM:<<bar>>', |
'BawlCustomInsertPlaceholder':'fooNUM:<<bar>>', |
||
Line 70: | Line 69: | ||
'saveToCommonJS':'Account (public)', |
'saveToCommonJS':'Account (public)', |
||
'saveToBrowser':'This browser', |
'saveToBrowser':'This browser', |
||
' |
'commentDone':'Done!', |
||
'commentEdited':'Comment changed!', |
|||
'sectionAdded':'Section added!', |
|||
'commentPostedThankYou':' Thank you for using <a href="https://en.wikipedia.org/wiki/User:Alexis_Jazz/Bawl" target="_new">Bawl!</a>', |
'commentPostedThankYou':' Thank you for using <a href="https://en.wikipedia.org/wiki/User:Alexis_Jazz/Bawl" target="_new">Bawl!</a>', |
||
'tosNagText':'<div id="BawlToSNag">By pressing "Reply", you agree to Wikimedia\'s <a href="' + Bawl.ToSlink + '">Terms of Use</a> and agree to irrevocably release your text under the <a href="' + Bawl.CCBYSAlink + '" target="_new">CC BY-SA 3.0 License</a> and <a href="' + Bawl.GFDLlink + '" target="_new">GFDL</a>. You can <a onclick="Bawl.openSettings(\'open\'); window.BawlPreftosNag.scrollIntoView()">disable this nagging message.</a></div>', |
|||
'editNoticeSetting':'<a onclick="Bawl.openSettings(\'open\'); window.editNotice.scrollIntoView()"><span style="color:black; opacity:0.5; font-size:smaller; float:right;">Editnotices can be disabled</span></a>', //todo: insert this |
'editNoticeSetting':'<a onclick="Bawl.openSettings(\'open\'); window.editNotice.scrollIntoView()"><span style="color:black; opacity:0.5; font-size:smaller; float:right;">Editnotices can be disabled</span></a>', //todo: insert this |
||
'BawlAddSectionToolbar':'Add section (Bawl)', |
'BawlAddSectionToolbar':'Add section (Bawl)', |
||
Line 83: | Line 79: | ||
'editTitle':'Change comment', |
'editTitle':'Change comment', |
||
'showNewLinesButton':'Show changed and added content', |
'showNewLinesButton':'Show changed and added content', |
||
'restoredDraft':'Restored draft', |
|||
'lang':'mul', |
'lang':'mul', |
||
}; |
}; |
||
Line 89: | Line 86: | ||
'replyToTitle':'Reply to USER', |
'replyToTitle':'Reply to USER', |
||
'editTitle':'Edit comment', |
'editTitle':'Edit comment', |
||
} |
}; |
||
Bawl.msgsObj.es = {'titlePlaceholder':'Asunto'}; |
Bawl.msgsObj.es = {'titlePlaceholder':'Asunto'}; |
||
Bawl.msgsObj.fr = {'titlePlaceholder':'Sujet'}; |
Bawl.msgsObj.fr = {'titlePlaceholder':'Sujet'}; |
||
Line 104: | Line 101: | ||
Bawl.basicmsgsObj.mul = { //multilingual and default texts, selected using wgUserLanguage. Messages that are required to load the script and open the form |
Bawl.basicmsgsObj.mul = { //multilingual and default texts, selected using wgUserLanguage. Messages that are required to load the script and open the form |
||
'BawlUIReplyButton':' 📢 ', //regular spaces are stripped, figure spaces are not |
'BawlUIReplyButton':' 📢 ', //regular spaces are stripped, figure spaces are not |
||
'BawlUIEditButton' |
'BawlUIEditButton': ' 🖋️ ', |
||
'BawlUIPreviewButton':' 👁 ', |
'BawlUIPreviewButton':' 👁 ', |
||
'BawlUICancelButton':' 🗑️ ', |
'BawlUICancelButton':' 🗑️ ', |
||
'saveSettings':'Save', |
|||
'resetPreferences': 'Restore all default settings', |
|||
'bold':' B ', |
'bold':' B ', |
||
'italic':' I ', |
'italic':' I ', |
||
'strike':'ABC', |
'strike':'ABC', |
||
}; |
}; |
||
Bawl.basicmsgsObj.en = {'BawlUIReplyButton':'Reply','BawlUIEditButton' : 'Submit','BawlUIPreviewButton':'Preview','BawlUICancelButton':'Cancel'}; |
|||
Bawl.basicmsgsObj.en = { |
|||
if ( typeof BawlBasicmsgsObj != 'undefined' && BawlBasicmsgsObj[ mw.config.get('wgUserLanguage') ] ) { // BawlBasicmsgsObj could be specified in common.js before Bawl is loaded |
|||
'BawlUIReplyButton':'Reply', |
|||
Bawl.basicmsgs = Object.assign(Bawl.basicmsgsObj.mul, BawlBasicmsgsObj[ mw.config.get('wgUserLanguage') ]); |
|||
'BawlUIEditButton' : 'Submit', |
|||
} else if ( mw.config.get('wgUserLanguage') == 'en' ) { |
|||
'BawlUIPreviewButton':'Preview', |
|||
Bawl.basicmsgs = Object.assign(Bawl.basicmsgsObj.mul, Bawl.basicmsgsObj.en); |
|||
'BawlUICancelButton':'Cancel', |
|||
} else if ( window.localStorage['BawlBasicLang'+mw.config.get('wgUserLanguage')] && JSON.parse(window.localStorage['BawlBasicLang'+mw.config.get('wgUserLanguage')]) && JSON.parse(window.localStorage['BawlBasicLang'+mw.config.get('wgUserLanguage')]).version == Bawl.versionDate ) { |
|||
}; |
|||
Bawl.basicmsgs = Object.assign(Bawl.basicmsgsObj.mul, JSON.parse(window.localStorage['BawlBasicLang'+mw.config.get('wgUserLanguage')])); |
|||
Bawl.basicmsgsObj.de = { |
|||
} else { |
|||
'BawlUIReplyButton':'Antworten', |
|||
Bawl.basicMsgsWikiText = '<span class="basicMsg">{{int:htmlform-submit}}</span><span class="basicMsg">{{int:edit}}</span><span class="basicMsg">{{int:preview}}</span><span class="basicMsg">{{int:cancel}}</span><span class="basicMsg">{{int:saveprefs}}</span><span class="basicMsg">{{int:restoreprefs}}</span>'; |
|||
'BawlUIEditButton' : 'Bearbeiten', |
|||
api.get( { |
|||
'BawlUIPreviewButton':'Vorschau zeigen', |
|||
format: 'json', action: 'parse', text: Bawl.basicMsgsWikiText |
|||
'BawlUICancelButton':'Abbrechen', |
|||
} ).done( function ( data ) { |
|||
}; |
|||
Bawl.basicMsgsArrayRegExp = new RegExp('(?:<span class="basicMsg">)([^<]*)(?:<\/span>)', 'g'); |
|||
Bawl.basicmsgsObj.es = { |
|||
Bawl.basicMsgsArray = data.parse.text['*'].match(Bawl.basicMsgsArrayRegExp); |
|||
'BawlUIReplyButton':'Responder', |
|||
if ( Bawl.basicMsgsArray ) { |
|||
'BawlUIEditButton' : 'Publicar cambios', |
|||
Bawl.basicmsgsObj[mw.config.get('wgUserLanguage')] = { |
|||
'BawlUIPreviewButton':'Previsualización', |
|||
'BawlUIReplyButton':Bawl.basicMsgsArray[0].replace(Bawl.basicMsgsArrayRegExp, '$1'), |
|||
'BawlUICancelButton':'Cancelar', |
|||
'BawlUIEditButton':Bawl.basicMsgsArray[1].replace(Bawl.basicMsgsArrayRegExp, '$1'), |
|||
}; |
|||
'BawlUIPreviewButton':Bawl.basicMsgsArray[2].replace(Bawl.basicMsgsArrayRegExp, '$1'), |
|||
Bawl.basicmsgsObj.fr = { |
|||
'BawlUICancelButton':Bawl.basicMsgsArray[3].replace(Bawl.basicMsgsArrayRegExp, '$1'), |
|||
'BawlUIReplyButton':'Répondre', |
|||
'saveSettings':Bawl.basicMsgsArray[4].replace(Bawl.basicMsgsArrayRegExp, '$1'), |
|||
'BawlUIEditButton' : 'Publier vos modifications', |
|||
'resetPreferences':Bawl.basicMsgsArray[5].replace(Bawl.basicMsgsArrayRegExp, '$1'), |
|||
'BawlUIPreviewButton':'Aperçu', |
|||
'version':Bawl.versionDate |
|||
'BawlUICancelButton':'Annuler', |
|||
}; |
|||
'titlePlaceholder':'Sujet', |
|||
Bawl.basicLangString = JSON.stringify(Bawl.basicmsgsObj[mw.config.get('wgUserLanguage')]); |
|||
}; |
|||
window.localStorage.setItem('BawlBasicLang'+mw.config.get('wgUserLanguage'), Bawl.basicLangString); |
|||
Bawl.basicmsgsObj.zh = { |
|||
Bawl.basicmsgs = Object.assign(Bawl.basicmsgsObj.mul, Bawl.basicmsgsObj[mw.config.get('wgUserLanguage')]); |
|||
'BawlUIReplyButton':'回复', |
|||
} else { |
|||
'BawlUIEditButton' : '发布您的更改', |
|||
Bawl.basicmsgs = Object.assign(Bawl.basicmsgsObj.mul, Bawl.basicmsgsObj.en); //just in case everything goes to shit |
|||
'BawlUIPreviewButton':'预览', |
|||
} |
|||
'BawlUICancelButton':'取消', |
|||
} ); |
|||
'titlePlaceholder':'主题', |
|||
} |
} |
||
Bawl.basicmsgsObj.ru = { |
|||
'BawlUIReplyButton':'Ответить', |
|||
'BawlUIEditButton' : 'Опубликовать ваши изменения', |
|||
'BawlUIPreviewButton':'Предпросмотр', |
|||
'BawlUICancelButton':'Отмена', |
|||
'titlePlaceholder':'Тема', |
|||
}; |
|||
Bawl.basicmsgsObj.pt = { |
|||
'BawlUIReplyButton':'Responder', |
|||
'BawlUIEditButton' : 'Publicar as suas alterações', |
|||
'BawlUIPreviewButton':'Pré-visualizar', |
|||
'BawlUICancelButton':'Cancelar', |
|||
'titlePlaceholder':'Assunto', |
|||
}; |
|||
Bawl.basicmsgsObj.it = { |
|||
'BawlUIReplyButton':'Rispondi', |
|||
'BawlUIEditButton' : 'Pubblica le tue modifiche', |
|||
'BawlUIPreviewButton':'Anteprima', |
|||
'BawlUICancelButton':'Annulla', |
|||
'titlePlaceholder':'Oggetto', |
|||
}; |
|||
Bawl.basicmsgsObj.ja = { |
|||
'BawlUIReplyButton':'返信', |
|||
'BawlUIEditButton' : 'あなたによる変更を公開', |
|||
'BawlUIPreviewButton':'プレビュー', |
|||
'BawlUICancelButton':'キャンセル', |
|||
'titlePlaceholder':'題名', |
|||
}; |
|||
Bawl.basicmsgsObj.pl = { |
|||
'BawlUIReplyButton':'Odpowiedz', |
|||
'BawlUIEditButton' : 'Opublikuj swoje zmiany', |
|||
'BawlUIPreviewButton':'Podgląd', |
|||
'BawlUICancelButton':'Anuluj', |
|||
'titlePlaceholder':'Temat', |
|||
}; |
|||
Bawl.basicmsgsObj.vi = { |
|||
'BawlUIReplyButton':'Trả lời', |
|||
'BawlUIEditButton' : 'Đăng thay đổi của bạn', |
|||
'BawlUIPreviewButton':'Xem trước', |
|||
'BawlUICancelButton':'Hủy bỏ', |
|||
'titlePlaceholder':'Đề mục', |
|||
}; |
|||
Bawl.basicmsgsObj.sv = { |
|||
'BawlUIReplyButton':'Svara', |
|||
'BawlUIEditButton' : 'Publicera dina ändringar', |
|||
'BawlUIPreviewButton':'Förhandsgranska', |
|||
'BawlUICancelButton':'Avbryt', |
|||
'titlePlaceholder':'Ämne', |
|||
}; |
|||
Bawl.basicmsgsObj.uk = { |
|||
'BawlUIReplyButton':'Відповісти', |
|||
'BawlUIEditButton' : 'Опублікувати ваші зміни', |
|||
'BawlUIPreviewButton':'Попередній перегляд', |
|||
'BawlUICancelButton':'Скасувати', |
|||
'titlePlaceholder':'Тема', |
|||
}; |
|||
Bawl.basicmsgsObj.fa = { //as fa is rtl I have no idea if Bawl will work properly in Farsi |
|||
'BawlUIReplyButton':'پاسخ', |
|||
'BawlUIEditButton' : 'انتشار تغییراتتان', |
|||
'BawlUIPreviewButton':'پیشنمایش', |
|||
'BawlUICancelButton':'لغو', |
|||
'titlePlaceholder':'عنوان', |
|||
}; |
|||
Bawl.basicmsgsObj.nl = { |
|||
'BawlUIReplyButton':'Reageren', |
|||
'BawlUIEditButton' : 'Aanpassen', |
|||
'BawlUIPreviewButton':'Voorbeeld', |
|||
'BawlUICancelButton':'Annuleren', |
|||
}; |
|||
Bawl.summaryCredit = ' ([[w:en:User:Alexis Jazz/Bawl|Bawl!]])'; |
Bawl.summaryCredit = ' ([[w:en:User:Alexis Jazz/Bawl|Bawl!]])'; |
||
Bawl.summaryCreditDE = ' ([[w:de:Benutzer:Alexis Jazz/Bawl|Bawl!]])'; |
Bawl.summaryCreditDE = ' ([[w:de:Benutzer:Alexis Jazz/Bawl|Bawl!]])'; |
||
Line 247: | Line 177: | ||
'deletePrefsSummary':'Einstellungen löschen' + Bawl.summaryCreditDE, |
'deletePrefsSummary':'Einstellungen löschen' + Bawl.summaryCreditDE, |
||
}; |
}; |
||
if ( typeof BawlBasicmsgsObj != 'undefined' && BawlBasicmsgsObj[ mw.config.get('wgUserLanguage') ] ) { // BawlBasicmsgsObj could be specified in common.js before Bawl is loaded |
|||
Bawl.basicmsgs = Object.assign(Bawl.basicmsgsObj.mul, BawlBasicmsgsObj[ mw.config.get('wgUserLanguage') ]); |
|||
} else if ( Bawl.basicmsgsObj[ mw.config.get('wgUserLanguage') ] ) { |
|||
Bawl.basicmsgs = Object.assign(Bawl.basicmsgsObj.mul, Bawl.basicmsgsObj[ mw.config.get('wgUserLanguage') ]); |
|||
} else { |
|||
Bawl.basicmsgs = Bawl.basicmsgsObj.mul; |
|||
} |
|||
if ( typeof BawlWikiMsgsObj != 'undefined' && BawlWikiMsgsObj[ mw.config.get('wgPageContentLanguage') ] ) { // BawlwikiMsgsObj could be specified in common.js before Bawl is loaded |
if ( typeof BawlWikiMsgsObj != 'undefined' && BawlWikiMsgsObj[ mw.config.get('wgPageContentLanguage') ] ) { // BawlwikiMsgsObj could be specified in common.js before Bawl is loaded |
||
Bawl.wikiMsgs = Object.assign(Bawl.wikiMsgsObj.mul, BawlWikiMsgsObj[ mw.config.get('wgPageContentLanguage') ]); |
Bawl.wikiMsgs = Object.assign(Bawl.wikiMsgsObj.mul, BawlWikiMsgsObj[ mw.config.get('wgPageContentLanguage') ]); |
||
Line 301: | Line 224: | ||
Bawl.pageLoadTimestamp = new Date().toISOString(); //to detect new comments since loading the page |
Bawl.pageLoadTimestamp = new Date().toISOString(); //to detect new comments since loading the page |
||
mw.loader.using( [ 'oojs-ui', 'oojs-ui.styles.icons-interactions' ] ).then( function () { |
mw.loader.using( [ 'oojs-ui', 'oojs-ui.styles.icons-interactions' ] ).then( function () { |
||
Bawl.trySectionEdit = true; |
|||
Bawl.editConflictRetries = 10; |
Bawl.editConflictRetries = 10; |
||
Bawl.defaultSettings = { //default settings |
Bawl.defaultSettings = { //default settings |
||
Line 308: | Line 230: | ||
'afterPost':'parsecomment', //currently reload, link or parsecomment |
'afterPost':'parsecomment', //currently reload, link or parsecomment |
||
'nSecLink': true, |
'nSecLink': true, |
||
'replySecLink': |
'replySecLink': false, |
||
'secLinks': |
'secLinks': false, |
||
'inputBoxTO': true, |
'inputBoxTO': true, |
||
'enableEverywhere': false, |
|||
'editLinks': true, |
'editLinks': true, |
||
'editNotice': false, |
'editNotice': false, |
||
'dateLinksIcon': |
'dateLinksIcon': false, |
||
'dateLinks': false, |
'dateLinks': false, |
||
'dateLinksLocalTime': false, |
'dateLinksLocalTime': false, |
||
'wrongUI': false, |
'wrongUI': false, |
||
'livePreview': false, |
'livePreview': false, |
||
'saveDraft': true, |
|||
'checkNewComments' : true, |
'checkNewComments' : true, |
||
'limitWidth': false, |
'limitWidth': false, |
||
Line 385: | Line 309: | ||
} else if ( typeof BawlTZ == 'string' ) { //timezone specified in common.js or something. allows overriding localStorage, useful if a wiki changes timezone |
} else if ( typeof BawlTZ == 'string' ) { //timezone specified in common.js or something. allows overriding localStorage, useful if a wiki changes timezone |
||
Bawl.wikiTimezone = BawlTZ; |
Bawl.wikiTimezone = BawlTZ; |
||
} else if ( window.localStorage.BawlTZ ) { |
} else if ( window.localStorage.BawlTZ && JSON.parse(window.localStorage.BawlTZ).version == Bawl.versionDate ) { |
||
Bawl.wikiTimezone = window.localStorage.BawlTZ; |
Bawl.wikiTimezone = JSON.parse(window.localStorage.BawlTZ).timezone; |
||
Bawl.settings.wikiTZ = window.localStorage.BawlTZ; |
Bawl.settings.wikiTZ = JSON.parse(window.localStorage.BawlTZ).timezone; |
||
} else if ( Bawl.settings.wikiTZ ) { |
} else if ( Bawl.settings.wikiTZ ) { |
||
Bawl.wikiTimezone = Bawl.settings.wikiTZ; |
Bawl.wikiTimezone = Bawl.settings.wikiTZ; |
||
} else { |
} else { |
||
Bawl.dbg('get wiki timezone from API'); |
|||
var api = new mw.Api(); |
|||
api.get( { |
api.get( { |
||
format: 'json', action: 'query', meta: 'siteinfo', siprop: 'general' |
format: 'json', action: 'query', meta: 'siteinfo', siprop: 'general' |
||
} ).done( function ( data ) { |
} ).done( function ( data ) { |
||
Bawl.TZObj = JSON.stringify({'version':Bawl.versionDate,'timezone':data.query.general.timezone}); |
|||
window.localStorage.setItem('BawlTZ', Bawl.TZObj); |
|||
Bawl.settings.wikiTZ = data.query.general.timezone; |
Bawl.settings.wikiTZ = data.query.general.timezone; |
||
Bawl.wikiTimezone = data.query.general.timezone; |
Bawl.wikiTimezone = data.query.general.timezone; |
||
Line 445: | Line 370: | ||
Bawl.prefsVarName = 'window.BawlGlobalPrefs'; |
Bawl.prefsVarName = 'window.BawlGlobalPrefs'; |
||
} else { |
} else { |
||
var api = new mw.Api(); |
|||
Bawl.prefsVarName = 'window.BawlPrefs'; |
Bawl.prefsVarName = 'window.BawlPrefs'; |
||
Bawl.dbg('selecting mw.Api for ' + params.title + ' on this wiki'); |
Bawl.dbg('selecting mw.Api for ' + params.title + ' on this wiki'); |
||
Line 509: | Line 433: | ||
Bawl.settings[ Bawl.processKey ] = Bawl.settingElement[ Bawl.processKey ].getValue(); |
Bawl.settings[ Bawl.processKey ] = Bawl.settingElement[ Bawl.processKey ].getValue(); |
||
} |
} |
||
} |
|||
if ( Bawl.settings.enableEverywhere == true ) { //loader can't use settings to determine if Bawl should load |
|||
window.localStorage.setItem('BawlenableEverywhere', 'true'); |
|||
} else { |
|||
window.localStorage.removeItem('BawlenableEverywhere'); |
|||
} |
} |
||
for (int = 0; int < 30; int++) { |
for (int = 0; int < 30; int++) { |
||
Line 565: | Line 494: | ||
} |
} |
||
if ( (preftype && preftype == 'browser') || ( ! preftype && Bawl.settingElement.saveTo.getValue() == 'browser' )) { |
if ( (preftype && preftype == 'browser') || ( ! preftype && Bawl.settingElement.saveTo.getValue() == 'browser' )) { |
||
localStorage.removeItem('Bawl'); |
window.localStorage.removeItem('Bawl'); |
||
window.localStorage.removeItem('BawlBasicLang'+mw.config.get('wgUserLanguage')); |
|||
Bawl.dbg('bye localStorage item'); |
|||
window.localStorage.removeItem('BawlLang'+mw.config.get('wgUserLanguage')); |
|||
window.localStorage.removeItem('BawlToSnagText'); |
|||
window.localStorage.removeItem('BawlenableEverywhere'); |
|||
window.localStorage.removeItem('BawlTZ'); |
|||
Bawl.dbg('bye localStorage items'); |
|||
if ( ! preftype ) { |
if ( ! preftype ) { |
||
Bawl.reloadForm(); |
Bawl.reloadForm(); |
||
Line 582: | Line 516: | ||
Bawl.addScrewedLink = function(errorDescription) { |
Bawl.addScrewedLink = function(errorDescription) { |
||
$('#BawlReplyForm').prepend('<b>Looks like Alexis Jazz screwed up. (' + errorDescription + ') <a href="https://en.wikipedia.org/enwiki/w/index.php?title=User_talk:Alexis_Jazz/Bawl&action=edit§ion=new&preloadtitle=You%20messed%20up!%20(' + encodeURIComponent(errorDescription) + ')&preload=User_talk:Alexis%20Jazz/Bawl/preload">Go bawl at \'em here.</a><br/>'); |
$('#BawlReplyForm').prepend('<b>Looks like Alexis Jazz screwed up. (' + errorDescription + ') <a href="https://en.wikipedia.org/enwiki/w/index.php?title=User_talk:Alexis_Jazz/Bawl&action=edit§ion=new&preloadtitle=You%20messed%20up!%20(' + encodeURIComponent(errorDescription) + ')&preload=User_talk:Alexis%20Jazz/Bawl/preload">Go bawl at \'em here.</a><br/>'); |
||
}; |
|||
Bawl.insertToSnag = function() { |
|||
if ( window.localStorage.BawlToSnagText && JSON.parse(window.localStorage.BawlToSnagText).version == Bawl.versionDate ) { |
|||
$('#BawltosNagContainer').append(JSON.parse(window.localStorage.BawlToSnagText).text); |
|||
} else { |
|||
api.get( { |
|||
format: 'json', action: 'parse', text: '{{MediaWiki:Copyrightwarning}}' //MediaWiki:Wikimedia-copyrightwarning is the warning for Wikimedia sites in general and incorrect on projects with a different license like Wikinews. If dewiki wants their regular tosnag they'll have to transclude MediaWiki:Wikimedia-copyrightwarning from MediaWiki:Copyrightwarning |
|||
} ).done( function ( data ) { |
|||
Bawl.ToSnagText = data.parse.text['*'].replace('$2', Bawl.ToSlicenselinks).replace('$1', Bawl.ToSmoreInfoLink).replace(/[\s]*<!\-\-[\s]*\nNewPP[^]*/g,'') + '</div>'; |
|||
Bawl.ToSnagTextObj = JSON.stringify({'version':Bawl.versionDate,'text':Bawl.ToSnagText}); |
|||
window.localStorage.setItem('BawlToSnagText', Bawl.ToSnagTextObj); |
|||
$('#BawltosNagContainer').append(JSON.parse(window.localStorage.BawlToSnagText).text); |
|||
} ); |
|||
} |
|||
}; |
}; |
||
Bawl.toggleTosNag = function() { |
Bawl.toggleTosNag = function() { |
||
if ( ! document.getElementById('BawlToSNag') && Bawl.settingElement.tosNag.isSelected() ) { |
if ( ! document.getElementById('BawlToSNag') && Bawl.settingElement.tosNag.isSelected() ) { |
||
Bawl.insertToSnag(); |
|||
$('#BawltosNagContainer').append(Bawl.msgs.tosNagText); |
|||
} else if ( Bawl.settingElement.tosNag.isSelected() == true ) { |
} else if ( Bawl.settingElement.tosNag.isSelected() == true ) { |
||
$('#BawlToSNag').removeClass('BawlNoDisplay'); |
$('#BawlToSNag').removeClass('BawlNoDisplay'); |
||
Line 592: | Line 540: | ||
} |
} |
||
}; |
}; |
||
Bawl.fastCSSTrans = '0.1s'; |
|||
Bawl.slowCSSTrans = '4.0s'; |
|||
mw.util.addCSS('.BawlReplyButton { font-size:0.5em; font }\ |
mw.util.addCSS('.BawlReplyButton { font-size:0.5em; font }\ |
||
.BawlReplyLink:hover { text-decoration:none;background-color:#EEEEFF; }\ |
.BawlReplyLink:hover { text-decoration:none;background-color:#EEEEFF; }\ |
||
Line 604: | Line 550: | ||
.BawlPreviewBox { background:#FAFAFA;padding:0.1em 1em 0.1em 1em;border:thin dashed gray; }\ |
.BawlPreviewBox { background:#FAFAFA;padding:0.1em 1em 0.1em 1em;border:thin dashed gray; }\ |
||
.BawlFloatRight { float:right; }\ |
.BawlFloatRight { float:right; }\ |
||
.BawlForm { padding:0.5em 0.5em 0em 0.5em;margin:0em 0em 0em 1.5em;font-size:' + Bawl.settings.UIfontSize + ';font-family:sans-serif; font-weight:normal }\ |
.BawlForm { padding:0.5em 0.5em 0em 0.5em;margin:0em 0em 0em 1.5em;font-size:' + Bawl.settings.UIfontSize + ';font-family:sans-serif; font-weight:normal;min-width:50em; }\ |
||
.BawlLimitWidth { max-width:50em; }\ |
.BawlLimitWidth { max-width:50em; }\ |
||
.BawlUnsetLimitWidth { max-width:unset !important; }\ |
.BawlUnsetLimitWidth { max-width:unset !important; }\ |
||
Line 611: | Line 557: | ||
.BawlOOuiFieldLayout { margin-top:0.5em !important; margin-bottom:0.75em; }\ |
.BawlOOuiFieldLayout { margin-top:0.5em !important; margin-bottom:0.75em; }\ |
||
.BawlOOuiFieldLayout::after { clear:none; }\ |
.BawlOOuiFieldLayout::after { clear:none; }\ |
||
.BawlStatusTransred { background:#FFBBBB; transition: all ' + Bawl.fastCSSTrans + ' ease-in; -o-transition: all ' + Bawl.fastCSSTrans + ' ease-in; -webkit-transition: all ' + Bawl.fastCSSTrans + ' ease-in; }\ |
|||
.BawlStatusTransgreen { background:#BBFFBB; transition: all ' + Bawl.fastCSSTrans + ' ease-in; -o-transition: all ' + Bawl.fastCSSTrans + ' ease-in; -webkit-transition: all ' + Bawl.fastCSSTrans + ' ease-in; }\ |
|||
.BawlStatusTransblue { background:#BBBBFF; transition: all ' + Bawl.fastCSSTrans + ' ease-in; -o-transition: all ' + Bawl.fastCSSTrans + ' ease-in; -webkit-transition: all ' + Bawl.fastCSSTrans + ' ease-in; }\ |
|||
.BawlStatusTranscyan { background:#BBFFFF; transition: all ' + Bawl.fastCSSTrans + ' ease-in; -o-transition: all ' + Bawl.fastCSSTrans + ' ease-in; -webkit-transition: all ' + Bawl.fastCSSTrans + ' ease-in; }\ |
|||
.BawlStatusTranspurple { background:#FFBBFF; transition: all ' + Bawl.fastCSSTrans + ' ease-in; -o-transition: all ' + Bawl.fastCSSTrans + ' ease-in; -webkit-transition: all ' + Bawl.fastCSSTrans + ' ease-in; }\ |
|||
.BawlStatusTransyellow { background:#FFFFBB; transition: all ' + Bawl.fastCSSTrans + ' ease-in; -o-transition: all ' + Bawl.fastCSSTrans + ' ease-in; -webkit-transition: all ' + Bawl.fastCSSTrans + ' ease-in; }\ |
|||
.BawlStatusTranswhiteSlow { background:#FFFFFF; transition: all ' + Bawl.slowCSSTrans + ' ease-in; -o-transition: all ' + Bawl.slowCSSTrans + ' ease-in; -webkit-transition: all ' + Bawl.slowCSSTrans + ' ease-in; }\ |
|||
.BawlShakeIt { animation: shake 0.12s; animation-iteration-count: 3;} @keyframes shake { 0% { margin:-0.1em 0em 0.6em 0em; } 9% { margin:-0.2em 0em 0.7em 0em; } 18% { margin:-0.3em 0em 0.8em 0em; } 27% { margin:-0.2em 0em 0.7em 0em; } 36% { margin:-0.1em 0em 0.6em 0em; } 45% { margin:0em 0em 0.5em 0em; } 54% { margin:0.1em 0em 0.4em 0em; } 63% { margin:0.2em 0em 0.3em 0em; } 72% { margin:0.3em 0em 0.2em 0em; } 81% { margin:0.2em 0em 0.3em 0em; } 90% { margin:0.1em 0em 0.4em 0em; } 100% { margin:0em 0em 0.5em 0em; } }\ |
.BawlShakeIt { animation: shake 0.12s; animation-iteration-count: 3;} @keyframes shake { 0% { margin:-0.1em 0em 0.6em 0em; } 9% { margin:-0.2em 0em 0.7em 0em; } 18% { margin:-0.3em 0em 0.8em 0em; } 27% { margin:-0.2em 0em 0.7em 0em; } 36% { margin:-0.1em 0em 0.6em 0em; } 45% { margin:0em 0em 0.5em 0em; } 54% { margin:0.1em 0em 0.4em 0em; } 63% { margin:0.2em 0em 0.3em 0em; } 72% { margin:0.3em 0em 0.2em 0em; } 81% { margin:0.2em 0em 0.3em 0em; } 90% { margin:0.1em 0em 0.4em 0em; } 100% { margin:0em 0em 0.5em 0em; } }\ |
||
.BawlSmallerText { font-size: 70%; }\ |
.BawlSmallerText { font-size: 70%; }\ |
||
Line 627: | Line 566: | ||
.BawlMarkupBold { font-weight: bold; }\ |
.BawlMarkupBold { font-weight: bold; }\ |
||
.BawlMarkupItalic { font-weight: normal; font-style: italic; }\ |
.BawlMarkupItalic { font-weight: normal; font-style: italic; }\ |
||
.BawlPreviewAfterPost { margin-left: 0.5em; font-family:sans-serif; font-weight: normal |
.BawlPreviewAfterPost { margin-left: 0.5em; font-family:sans-serif; font-weight: normal;}\ |
||
.BawlAnonSectReply { font-size:medium;font-weight:normal;line-height:1.3;text-align:center;border:thin solid #ccc;padding:0.2em 3em 0.2em 3em;background:aliceblue; }\ |
.BawlAnonSectReply { font-size:medium;font-weight:normal;line-height:1.3;text-align:center;border:thin solid #ccc;padding:0.2em 3em 0.2em 3em;background:aliceblue; }\ |
||
.BawlNoMaxWidth { max-width:none; }'); |
.BawlNoMaxWidth { max-width:none; }'); |
||
Line 635: | Line 574: | ||
Bawl.apiUrl = mw.util.wikiScript( 'api' ); |
Bawl.apiUrl = mw.util.wikiScript( 'api' ); |
||
Bawl.doAPICall = function( params, situation, callback ) { |
Bawl.doAPICall = function( params, situation, callback ) { |
||
var api = new mw.Api(); |
|||
api.postWithEditToken( params ).done( function ( apiResponse ) { |
api.postWithEditToken( params ).done( function ( apiResponse ) { |
||
if (params.action == 'parse' && situation == 'previewposted' ) { |
if (params.action == 'parse' && situation == 'previewposted' ) { |
||
Line 661: | Line 599: | ||
$('#BawlEditNotice').append(apiResponse.parse.text); |
$('#BawlEditNotice').append(apiResponse.parse.text); |
||
} else if ( ( apiResponse.error && apiResponse.error.code == 'editconflict' ) || ( apiResponse.edit.result == 'Success' && ! apiResponse.edit.newtimestamp ) ) { //that nonsense second condition is a workaround for https://phabricator.wikimedia.org/T299809 |
} else if ( ( apiResponse.error && apiResponse.error.code == 'editconflict' ) || ( apiResponse.edit.result == 'Success' && ! apiResponse.edit.newtimestamp ) ) { //that nonsense second condition is a workaround for https://phabricator.wikimedia.org/T299809 |
||
Bawl.trySectionEdit = false; //do not try section editing on the next try |
|||
Bawl.editConflictRetries = Bawl.editConflictRetries - 1; |
Bawl.editConflictRetries = Bawl.editConflictRetries - 1; |
||
if ( apiResponse.edit.result == 'Success' && ! apiResponse.edit.newtimestamp && Bawl.editConflictRetries > 0 ) { //damage control in case there is a legit situation that triggers this |
if ( apiResponse.edit.result == 'Success' && ! apiResponse.edit.newtimestamp && Bawl.editConflictRetries > 0 ) { //damage control in case there is a legit situation that triggers this |
||
Line 683: | Line 620: | ||
Bawl.newCommentTimestamp = apiResponse.edit.newtimestamp.replace(/([0-9\-T\:]{17})[0-9][0-9]/, '$100.000'); |
Bawl.newCommentTimestamp = apiResponse.edit.newtimestamp.replace(/([0-9\-T\:]{17})[0-9][0-9]/, '$100.000'); |
||
Bawl.newCommentID = '#c-' + encodeURIComponent(mw.config.get('wgUserName').replace(/ /g, '_')) + '-' + encodeURIComponent(apiResponse.edit.newtimestamp.replace(/([0-9\-T\:]{17})[0-9][0-9]/, '$100.000')) + '-' + encodeURIComponent(Bawl.replyLinkParamsOpened.origReplyTo.replace(/ /g, '_')) + '-' + encodeURIComponent(Bawl.replyLinkParamsOpened.origTimestamp); |
Bawl.newCommentID = '#c-' + encodeURIComponent(mw.config.get('wgUserName').replace(/ /g, '_')) + '-' + encodeURIComponent(apiResponse.edit.newtimestamp.replace(/([0-9\-T\:]{17})[0-9][0-9]/, '$100.000')) + '-' + encodeURIComponent(Bawl.replyLinkParamsOpened.origReplyTo.replace(/ /g, '_')) + '-' + encodeURIComponent(Bawl.replyLinkParamsOpened.origTimestamp); |
||
Bawl.thankYouType = Bawl.msgs.commentPosted; |
|||
} else if ( Bawl.postedCommentType == 'heading' ) { //likely wrong |
} else if ( Bawl.postedCommentType == 'heading' ) { //likely wrong |
||
Bawl.newCommentID = '#c-' + encodeURIComponent(mw.config.get('wgUserName').replace(/ /g, '_')) + '-' + encodeURIComponent(apiResponse.edit.newtimestamp.replace(/([0-9\-T\:]{17})[0-9][0-9]/, '$100.000')) + '-' + encodeURIComponent(Bawl.UITextInputTitle.getValue().replace(/ /g, '_')); |
Bawl.newCommentID = '#c-' + encodeURIComponent(mw.config.get('wgUserName').replace(/ /g, '_')) + '-' + encodeURIComponent(apiResponse.edit.newtimestamp.replace(/([0-9\-T\:]{17})[0-9][0-9]/, '$100.000')) + '-' + encodeURIComponent(Bawl.UITextInputTitle.getValue().replace(/ /g, '_')); |
||
Bawl.thankYouType = Bawl.msgs.sectionAdded; |
|||
} else if ( Bawl.postedCommentType == 'newsection' ) { |
} else if ( Bawl.postedCommentType == 'newsection' ) { |
||
Bawl.newCommentID = '#' + encodeURIComponent(Bawl.UITextInputTitle.getValue().replace(/ /g, '_')); |
Bawl.newCommentID = '#' + encodeURIComponent(Bawl.UITextInputTitle.getValue().replace(/ /g, '_')); |
||
Bawl.thankYouType = Bawl.msgs.sectionAdded; |
|||
} else if ( Bawl.postedCommentType == 'edit' && typeof Bawl.replyLinkParamsOpened.origid == 'undefined' ) { |
} else if ( Bawl.postedCommentType == 'edit' && typeof Bawl.replyLinkParamsOpened.origid == 'undefined' ) { |
||
Bawl.newCommentID = '#' + encodeURIComponent(Bawl.replyLinkParamsOpened.id); |
Bawl.newCommentID = '#' + encodeURIComponent(Bawl.replyLinkParamsOpened.id); |
||
Bawl.thankYouType = Bawl.msgs.commentEdited; |
|||
} |
} |
||
Bawl.cancelReply(); //closes the reply form |
Bawl.cancelReply(); //closes the reply form |
||
document.getElementById('bawlForm-' + Bawl.repliedToCommentID).outerHTML = document.getElementById('bawlForm-' + Bawl.repliedToCommentID).outerHTML + '<span id="thanksForUsing"><a href="?' + Math.floor(Math.random()*100000) + Bawl.newCommentID + '">' + Bawl. |
document.getElementById('bawlForm-' + Bawl.repliedToCommentID).outerHTML = document.getElementById('bawlForm-' + Bawl.repliedToCommentID).outerHTML + '<span id="thanksForUsing"><a href="?' + Math.floor(Math.random()*100000) + Bawl.newCommentID + '">' + Bawl.msgs.commentDone + '</a>' + Bawl.msgs.commentPostedThankYou + '</span>'; // the ? forces page reload, # provides anchor to the comment that was commented on |
||
if ( Bawl.settings.afterPost == 'reload' || ( Bawl.replyLinkParamsOpened.type != 'comment' && Bawl.settings.afterPost != 'link' ) ) { |
if ( Bawl.settings.afterPost == 'reload' || ( Bawl.replyLinkParamsOpened.type != 'comment' && Bawl.settings.afterPost != 'link' ) ) { |
||
window.location = Bawl.newCommentID; |
window.location = Bawl.newCommentID; |
||
Line 713: | Line 646: | ||
'origTimestamp': Bawl.newCommentTimestamp, |
'origTimestamp': Bawl.newCommentTimestamp, |
||
'sectionTitle': Bawl.replyLinkParamsOpenedPreview.sectionTitle, |
'sectionTitle': Bawl.replyLinkParamsOpenedPreview.sectionTitle, |
||
'origLevel': Bawl.replyLinkParamsOpenedPreview.origLevel + 1, |
|||
'origReplyTo2': Bawl.replyLinkParamsOpenedPreview.origReplyTo, |
|||
'origTimestamp2': Bawl.replyLinkParamsOpenedPreview.origTimestamp2, |
|||
'headingLevel': Bawl.replyLinkParamsOpenedPreview.headingLevel |
|||
}; |
}; |
||
Bawl.PreviewAfterPostID = 'BawlPreviewAfterPost-' + Bawl.previewPostedParams.id.replace(/%/g, ''); |
Bawl.PreviewAfterPostID = 'BawlPreviewAfterPost-' + Bawl.previewPostedParams.id.replace(/%/g, ''); |
||
Line 816: | Line 745: | ||
Bawl.wikiswithsmileytemplate = [ 'afwiki','alswiki','barwiki','dawiki','dewiki','enwiki','eswiki','fowiki','guwiki','jvwiki','kabwiki','kswiki','lijwiki','mywiki','nds_nlwiki','nlwiki','nowiki','orwiki','rowiki','scowiki','sdwiki','simplewiki','srwiki','svwiki','tawiki','thwiki','vecwiki','zhwiki' ,'enwikiversity' ,'dewikibooks','nlwikibooks','nowikibooks','enwikinews','eswikinews','enwikinews','nlwikinews','nowikinews','enwikiquote','nlwikiquote','enwikisource','guwikisource','enwikiversity','dewikivoyage','eswikivoyage','enwiktionary','eswiktionary','nlwiktionary','commonswiki','mediawikiwiki','metawiki','wikidatawiki' ]; |
Bawl.wikiswithsmileytemplate = [ 'afwiki','alswiki','barwiki','dawiki','dewiki','enwiki','eswiki','fowiki','guwiki','jvwiki','kabwiki','kswiki','lijwiki','mywiki','nds_nlwiki','nlwiki','nowiki','orwiki','rowiki','scowiki','sdwiki','simplewiki','srwiki','svwiki','tawiki','thwiki','vecwiki','zhwiki' ,'enwikiversity' ,'dewikibooks','nlwikibooks','nowikibooks','enwikinews','eswikinews','enwikinews','nlwikinews','nowikinews','enwikiquote','nlwikiquote','enwikisource','guwikisource','enwikiversity','dewikivoyage','eswikivoyage','enwiktionary','eswiktionary','nlwiktionary','commonswiki','mediawikiwiki','metawiki','wikidatawiki' ]; |
||
if ( Bawl.wikiswithsmileytemplate.indexOf(mw.config.get('wgDBname')) != -1 ) { |
if ( Bawl.wikiswithsmileytemplate.indexOf(mw.config.get('wgDBname')) != -1 ) { |
||
text = text.replace(/(^| |\n)(:-\)|;-\)\|:-\()([^a-zA-Z0-9])/g, '$1{{Smiley|$2}}$3'); |
text = text.replace(/(^| |\n)(:-\)|;-\)\|:-\()([^a-zA-Z0-9]|$)/g, '$1{{Smiley|$2}}$3'); |
||
} |
} |
||
return text.replace(/\[\/?[Bb]\]/g, '\'\'\'').replace(/\[\/?[Ii]\]/g, '\'\'').replace(/\[(\/)?[Uu]\]/g, '<$1u>').replace(/\[(\/)?[Ss]\]/g, '<$1s>').replace(/\[url\](http)?(s?)(:\/\/)?([^\/\[]*)([^\[]*)\[\/url\]/gi, '[http$2://$4$5 ' + '$4' + ']').replace(/\[url="?(http)?(s?)(:\/\/)?([^\/\[]*)([^\[]*)"?\]([^\[]*)\[\/url\]/gi, '[http$2://$4$5 ' + '$6' + ']').replace(/\[img\]([^:\[]*:)?([^\[]*)\[\/img\]/g, '[[' + mw.config.get('wgFormattedNamespaces')[6] + ':$2|thumb]]').replace(/\[(\/)?[Cc]ode\]/g, '<$1code>').replace(/\[[Ss]tyle size="?([0-9]*)"?\]([^\[]*)\[\/(style)?\]/g, '<span style="font-size: $1pt">$2</span>').replace(/\[[Ss]tyle size="?([^"\]]*)"?\]([^\[]*)\[\/(style)?\]/g, '<span style="font-size: $1">$2</span>').replace(/\[([Ss]tyle )?color="?([0-9A-Fa-z]*)"?\]([^\[]*)\[\/(style|color)?\]/g, '<span style="color: $2">$3</span>').replace(/\[\*\] ?([^\n\[]*)\s*/gm, '<li>$1</li>').replace(/\[[Ll]ist\]\s*([^]*)\[\/[Ll]ist\]/gm, '<ul>$1</ul>').replace(/\s*<\/(ul|li)>/g, '</$1>').replace(/\[[Qq](uote)?\]([^\[]*)\[\/[Qq](uote)?\]/g, '<blockquote><p>$2</p></blockquote>').replace(/\[[Qq](uote)?=?"?([^"\]]*)"?\]([^\[]*)\[\/[Qq](uote)?\]/g, '<blockquote><p>$3</p>—$2</blockquote>').replace(/\s*\[(\/)?(td|tr)\]\s*/g, '<$1$2>').replace(/\[[Tt]able\]/g, '<table class="wikitable">').replace(/\[\/[Tt]able\]/g, '</table>'); |
return text.replace(/\[\/?[Bb]\]/g, '\'\'\'').replace(/\[\/?[Ii]\]/g, '\'\'').replace(/\[(\/)?[Uu]\]/g, '<$1u>').replace(/\[(\/)?[Ss]\]/g, '<$1s>').replace(/\[url\](http)?(s?)(:\/\/)?([^\/\[]*)([^\[]*)\[\/url\]/gi, '[http$2://$4$5 ' + '$4' + ']').replace(/\[url="?(http)?(s?)(:\/\/)?([^\/\[]*)([^\[]*)"?\]([^\[]*)\[\/url\]/gi, '[http$2://$4$5 ' + '$6' + ']').replace(/\[img\]([^:\[]*:)?([^\[]*)\[\/img\]/g, '[[' + mw.config.get('wgFormattedNamespaces')[6] + ':$2|thumb]]').replace(/\[(\/)?[Cc]ode\]/g, '<$1code>').replace(/\[[Ss]tyle size="?([0-9]*)"?\]([^\[]*)\[\/(style)?\]/g, '<span style="font-size: $1pt">$2</span>').replace(/\[[Ss]tyle size="?([^"\]]*)"?\]([^\[]*)\[\/(style)?\]/g, '<span style="font-size: $1">$2</span>').replace(/\[([Ss]tyle )?color="?([0-9A-Fa-z]*)"?\]([^\[]*)\[\/(style|color)?\]/g, '<span style="color: $2">$3</span>').replace(/\[\*\] ?([^\n\[]*)\s*/gm, '<li>$1</li>').replace(/\[[Ll]ist\]\s*([^]*)\[\/[Ll]ist\]/gm, '<ul>$1</ul>').replace(/\s*<\/(ul|li)>/g, '</$1>').replace(/\[[Qq](uote)?\]([^\[]*)\[\/[Qq](uote)?\]/g, '<blockquote><p>$2</p></blockquote>').replace(/\[[Qq](uote)?=?"?([^"\]]*)"?\]([^\[]*)\[\/[Qq](uote)?\]/g, '<blockquote><p>$3</p>—$2</blockquote>').replace(/\s*\[(\/)?(td|tr)\]\s*/g, '<$1$2>').replace(/\[[Tt]able\]/g, '<table class="wikitable">').replace(/\[\/[Tt]able\]/g, '</table>'); |
||
Line 851: | Line 780: | ||
} |
} |
||
Bawl.addSignature = function(text) { |
Bawl.addSignature = function(text) { |
||
if ( text.match(/NOSIGN$/) |
if ( text.match(/NOSIGN$/) || Bawl.replyLinkParamsOpened.type == 'edit' ) { |
||
Bawl.dbg('found NOSIGN, skipping signature'); |
Bawl.dbg('found NOSIGN or this is an edit which doesn\'t need to be (re-)signed, skipping signature'); |
||
return text; |
return text; |
||
} else { |
} else { |
||
Line 871: | Line 800: | ||
document.getElementById('bawlForm-' + Bawl.replyLinkParamsOpened.id).classList = [ 'BawlNoDisplay BawlForm' ]; |
document.getElementById('bawlForm-' + Bawl.replyLinkParamsOpened.id).classList = [ 'BawlNoDisplay BawlForm' ]; |
||
}; |
}; |
||
Bawl. |
Bawl.processComment = function(text) { |
||
text = text.replace(/^[\s]*/, '').replace(/[\s]*$/, ''); |
|||
Bawl.dbg('preview'); |
|||
if ( situation != 'previewposted' ) { |
|||
$(document.getElementsByClassName('BawlPreviewBox')).removeClass('BawlNoDisplay'); |
|||
if ( Bawl.settings.checkNewComments == true ) { |
|||
Bawl.checkForNewComments(Bawl.replyLinkParamsOpened, 'preview'); |
|||
} |
|||
} |
|||
Bawl.processedCommentText = Bawl.UITextInput.getValue(); |
|||
if ( Bawl.settings.bbcode == true ) { |
if ( Bawl.settings.bbcode == true ) { |
||
text = Bawl.applyBBCode(text); |
|||
} |
} |
||
Bawl.progressPlusOne(); |
|||
if ( Bawl.settings.markdown == true ) { |
if ( Bawl.settings.markdown == true ) { |
||
text = Bawl.applyMarkdown(text); |
|||
} |
} |
||
Bawl.progressPlusOne(); |
|||
if ( Bawl.settings.rewritun == true ) { |
if ( Bawl.settings.rewritun == true ) { |
||
text = Bawl.rewritunUrUrlz(text); |
|||
} else { |
|||
Bawl.processedCommentText = Bawl.UITextInput.getValue(); |
|||
} |
} |
||
Bawl.progressPlusOne(); |
|||
if ( Bawl.settings.enableCIThatRun == true ) { |
if ( Bawl.settings.enableCIThatRun == true ) { |
||
Bawl.dbg('applying your regular expressions'); |
Bawl.dbg('applying your regular expressions'); |
||
text = Bawl.runCI(text); |
|||
} |
|||
Bawl.progressPlusOne(); |
|||
if ( Bawl.replyLinkParamsOpened.type == 'editFullPage' ) { |
|||
return text; |
|||
} else { |
|||
text = Bawl.addSignature(text); |
|||
return Bawl.convertToOneLineCmt(text); |
|||
} |
|||
}; |
|||
Bawl.doPreview = function(situation) { |
|||
Bawl.dbg('preview'); |
|||
if ( situation != 'previewposted' ) { |
|||
$(document.getElementsByClassName('BawlPreviewBox')).removeClass('BawlNoDisplay'); |
|||
if ( Bawl.settings.checkNewComments == true ) { |
|||
Bawl.checkForNewComments(Bawl.replyLinkParamsOpened, 'preview'); |
|||
} |
|||
} |
} |
||
Bawl. |
Bawl.processedComment = Bawl.processComment(Bawl.UITextInput.getValue()); |
||
Bawl.processedCommentTextSignedOneLine = Bawl.convertToOneLineCmt(Bawl.processedCommentTextSigned); |
|||
if ( situation == 'previewposted' ) { |
if ( situation == 'previewposted' ) { |
||
Bawl.dbg('add the last character from the indentation so preview renders properly with its indentation'); |
Bawl.dbg('add the last character+space from the indentation so preview renders properly with its indentation'); |
||
Bawl. |
Bawl.processedComment = Bawl.commentTextIndent.slice(-2,) + Bawl.processedComment; |
||
} |
} |
||
Bawl.previewCommentParams = { |
Bawl.previewCommentParams = { |
||
Line 908: | Line 846: | ||
prop: 'text', |
prop: 'text', |
||
formatversion: '2', |
formatversion: '2', |
||
text: Bawl. |
text: Bawl.processedComment + Bawl.repairTagImbalance(Bawl.processedComment) |
||
}; |
}; |
||
Bawl.doAPICall(Bawl.previewCommentParams, situation); |
Bawl.doAPICall(Bawl.previewCommentParams, situation); |
||
Line 914: | Line 852: | ||
Bawl.compareRevisionsToCheckForComments = function(replyLinkParams, situation) { |
Bawl.compareRevisionsToCheckForComments = function(replyLinkParams, situation) { |
||
Bawl.dbg('compare current revision to revision since last check'); |
Bawl.dbg('compare current revision to revision since last check'); |
||
var api = new mw.Api(); |
|||
api.get( { |
api.get( { |
||
action: 'query', prop: 'revisions', format: 'json', titles: replyLinkParams.pageTitle, rvlimit: 1, rvprop: 'timestamp|user|comment|content', rvslots: '*', |
action: 'query', prop: 'revisions', format: 'json', titles: replyLinkParams.pageTitle, rvlimit: 1, rvprop: 'timestamp|user|comment|content', rvslots: '*', |
||
Line 925: | Line 862: | ||
Bawl.pageRevisionCurrentText = ''; |
Bawl.pageRevisionCurrentText = ''; |
||
} |
} |
||
Bawl. |
Bawl.pageRevisionCurrentText = Bawl.getInsertionPointSection(Bawl.pageRevisionCurrentText, replyLinkParams).sectiontext; |
||
Bawl.pageRevisionSinceLastCheckText = Bawl.getInsertionPointSection(Bawl.pageRevisionSinceLastCheck[replyLinkParams.pageTitle], replyLinkParams).sectiontext; |
|||
if ( replyLinkParams.sectionnum ) { |
|||
Bawl.pageRevisionCurrentText = Bawl.getSectionByNum(Bawl.pageRevisionCurrentText, replyLinkParams.sectionnum); |
|||
Bawl.pageRevisionSinceLastCheckText = Bawl.getSectionByNum(Bawl.pageRevisionSinceLastCheck[replyLinkParams.pageTitle], replyLinkParams.sectionnum); |
|||
} |
|||
if ( Bawl.pageRevisionCurrentText != Bawl.pageRevisionSinceLastCheckText ){ |
if ( Bawl.pageRevisionCurrentText != Bawl.pageRevisionSinceLastCheckText ){ |
||
Bawl.pageRevisionCurrentSplit = Bawl.pageRevisionCurrentText.split('\n'); |
Bawl.pageRevisionCurrentSplit = Bawl.pageRevisionCurrentText.split('\n'); |
||
Line 971: | Line 905: | ||
if ( Bawl.pageRevisionSinceLastCheck[replyLinkParams.pageTitle] ) { |
if ( Bawl.pageRevisionSinceLastCheck[replyLinkParams.pageTitle] ) { |
||
Bawl.compareRevisionsToCheckForComments(replyLinkParams, situation); |
Bawl.compareRevisionsToCheckForComments(replyLinkParams, situation); |
||
} else if ( replyLinkParams.type == 'comment' ) { |
|||
} else { |
|||
var api = new mw.Api(); |
|||
api.get( { |
api.get( { |
||
action: 'query', prop: 'revisions', format: 'json', titles: replyLinkParams.pageTitle, rvlimit: 1, rvprop: 'timestamp|user|comment|content', rvslots: '*', rvstart: Bawl.pageLoadTimestamp, |
action: 'query', prop: 'revisions', format: 'json', titles: replyLinkParams.pageTitle, rvlimit: 1, rvprop: 'timestamp|user|comment|content', rvslots: '*', rvstart: Bawl.pageLoadTimestamp, |
||
Line 1,116: | Line 1,049: | ||
placeholder: Bawl.msgs.titlePlaceholder, |
placeholder: Bawl.msgs.titlePlaceholder, |
||
} ); |
} ); |
||
if ( replyLinkParams.type == 'editFullPage' ) { |
|||
Bawl.UITextInputRows = 25; |
|||
} else { |
|||
Bawl.UITextInputRows = 6; |
|||
} |
|||
Bawl.UITextInput = new OO.ui.MultilineTextInputWidget( { |
Bawl.UITextInput = new OO.ui.MultilineTextInputWidget( { |
||
id: 'BawlUITextInput', |
id: 'BawlUITextInput', |
||
rows: |
rows: Bawl.UITextInputRows, |
||
classes: [ 'BawlMarginHalfEm', 'BawlUnsetLimitWidth' ], |
classes: [ 'BawlMarginHalfEm', 'BawlUnsetLimitWidth' ], |
||
value: Bawl.preloadText, |
value: Bawl.preloadText, |
||
Line 1,136: | Line 1,074: | ||
delete BawlCurrentInputValue; |
delete BawlCurrentInputValue; |
||
}, 500); |
}, 500); |
||
}); |
|||
} |
|||
if ( Bawl.settings.saveDraft == true ) { |
|||
Bawl.UITextInput.on('change', function() { |
|||
Bawl.dbg('should we save a draft?'); |
|||
const BawlCurrentInputValueDraft = Bawl.UITextInput.getValue(); |
|||
var DelayedSaveDraft = setInterval(function () { // only save draft if content has been stable for at least 5 seconds |
|||
Bawl.newInputValueDraft = Bawl.UITextInput.getValue(); |
|||
clearInterval(DelayedSaveDraft); |
|||
if ( BawlCurrentInputValueDraft == Bawl.newInputValueDraft ) { |
|||
Bawl.dbg('saving draft to localStorage'); |
|||
if ( window.localStorage.BawlDrafts ) { |
|||
Bawl.dbg('found existing drafts in localStorage'); |
|||
Bawl.savedDrafts = JSON.parse(window.localStorage.BawlDrafts); |
|||
} else { |
|||
Bawl.savedDrafts = {}; |
|||
} |
|||
Bawl.timestampNowDraft = new Date().getTime(); |
|||
Bawl.timestampNowDraftLastWeek = Bawl.timestampNowDraft - 604800000; |
|||
for (BawlDraftInt = 0; BawlDraftInt < Bawl.savedDrafts.length; BawlDraftInt++) { |
|||
Bawl.dbg(Bawl.processDraftKey); |
|||
Bawl.processDraftKey = Object.keys(Bawl.savedDrafts)[prefint]; |
|||
if ( Bawl.savedDrafts[Bawl.processDraftKey].time < Bawl.timestampNowDraftLastWeek ) { |
|||
Bawl.dbg('draft ' + Bawl.processDraftKey + ' is over a week old, removing it'); |
|||
delete Bawl.savedDrafts[Bawl.processDraftKey]; |
|||
} |
|||
} |
|||
if ( Bawl.UITextInput.getValue().length > 100 ) { |
|||
Bawl.dbg('add comment to drafts'); |
|||
Bawl.savedDrafts[encodeURIComponent(replyLinkParams.pageTitle.replace(/ /g,'_'))] = {'time':Bawl.timestampNowDraft,'text':Bawl.UITextInput.getValue()}; |
|||
} else { |
|||
Bawl.dbg('too short, removing draft'); |
|||
delete Bawl.savedDrafts[encodeURIComponent(replyLinkParams.pageTitle.replace(/ /g,'_'))]; |
|||
} |
|||
window.localStorage.setItem('BawlDrafts',JSON.stringify(Bawl.savedDrafts)); |
|||
} else { |
|||
Bawl.dbg('you\'re typing too fast to save the draft!!'); |
|||
} |
|||
delete BawlCurrentInputValueDraft; |
|||
}, 5000); |
|||
}); |
}); |
||
} |
} |
||
Line 1,261: | Line 1,239: | ||
$(document.getElementById('bawlForm-' + replyLinkParams.id)).removeClass('BawlNoDisplay'); |
$(document.getElementById('bawlForm-' + replyLinkParams.id)).removeClass('BawlNoDisplay'); |
||
$(document.getElementById('bawlForm-' + replyLinkParams.id)).append(Bawl.editNoticeDiv).append(Bawl.ReplyForm.$element); |
$(document.getElementById('bawlForm-' + replyLinkParams.id)).append(Bawl.editNoticeDiv).append(Bawl.ReplyForm.$element); |
||
if ( window.localStorage.BawlDrafts ) { |
|||
if ( replyLinkParams.type == 'edit' ) { //preload content |
|||
Bawl.loadedDrafts = JSON.parse(window.localStorage.BawlDrafts); |
|||
} |
|||
if ( Bawl.settings.saveDraft == true && Bawl.loadedDrafts[encodeURIComponent(replyLinkParams.pageTitle.replace(/ /g,'_'))] && Bawl.loadedDrafts[encodeURIComponent(replyLinkParams.pageTitle.replace(/ /g,'_'))].time > (new Date().getTime() - 604800000) ) { |
|||
Bawl.dbg('load draft from localStorage'); |
|||
Bawl.UITextInput.setValue(Bawl.loadedDrafts[encodeURIComponent(replyLinkParams.pageTitle.replace(/ /g,'_'))].text); |
|||
mw.notify(Bawl.msgs.restoredDraft); |
|||
} else if ( replyLinkParams.type == 'edit' || replyLinkParams.type == 'editFullPage' ) { //preload content |
|||
Bawl.UITextInput.setDisabled(true); //disable textinput until preload is done |
Bawl.UITextInput.setDisabled(true); //disable textinput until preload is done |
||
Bawl.UIReplyButton.setLabel(Bawl.basicmsgs.BawlUIEditButton); |
Bawl.UIReplyButton.setLabel(Bawl.basicmsgs.BawlUIEditButton); |
||
Bawl.dbg('preloading existing comment'); |
Bawl.dbg('preloading existing comment'); |
||
var api = new mw.Api(); |
|||
api.get( { |
api.get( { |
||
action: 'query', export: 'true', format: 'json', titles: replyLinkParams.pageTitle, |
action: 'query', export: 'true', format: 'json', titles: replyLinkParams.pageTitle, |
||
Line 1,271: | Line 1,255: | ||
Bawl.dbg(data); |
Bawl.dbg(data); |
||
Bawl.wikiTextForEdit = Bawl.getWikitextFromExport(data.query.export["*"]); |
Bawl.wikiTextForEdit = Bawl.getWikitextFromExport(data.query.export["*"]); |
||
if ( replyLinkParams.type == 'editFullPage' ) { |
|||
Bawl.UITextInput.setValue(Bawl.wikiTextForEdit); |
|||
Bawl.UITextInput.setDisabled(false); |
|||
return; |
|||
} |
|||
Bawl.origTimeAsInSig = Bawl.timestampToTimeAsInSig(replyLinkParams.origTimestamp); |
Bawl.origTimeAsInSig = Bawl.timestampToTimeAsInSig(replyLinkParams.origTimestamp); |
||
Bawl.endOfCommentLocatorRegExp = new RegExp(' *(\{\{BawlCmt|<span id="[^"]*" class="BawlCmt").*'); |
Bawl.endOfCommentLocatorRegExp = new RegExp(' *(\{\{BawlCmt|<span id="[^"]*" class="BawlCmt").*'); |
||
Line 1,283: | Line 1,272: | ||
Bawl.UITextInput.focus(); |
Bawl.UITextInput.focus(); |
||
}); |
}); |
||
} else if ( (replyLinkParams.preload || replyLinkParams.preloadtitle) && Bawl.UITextInput.getValue() == '' && Bawl.UITextInputTitle.getValue() == '' ) { //InputBox/Bawl-comment-link preload |
|||
}; |
|||
if ( (replyLinkParams.preload || replyLinkParams.preloadtitle) && Bawl.UITextInput.getValue() == '' && Bawl.UITextInputTitle.getValue() == '' ) { //InputBox/Bawl-comment-link preload |
|||
for (intInputBoxPreload = 0; intInputBoxPreload < $('.bawlprocess')[replyLinkParams.int].children.length; intInputBoxPreload++) { |
for (intInputBoxPreload = 0; intInputBoxPreload < $('.bawlprocess')[replyLinkParams.int].children.length; intInputBoxPreload++) { |
||
Bawl.dbg('process child element #' + intInputBoxPreload + '/' + $('.bawlprocess')[replyLinkParams.int].children.length + ' for element #' + int); |
Bawl.dbg('process child element #' + intInputBoxPreload + '/' + $('.bawlprocess')[replyLinkParams.int].children.length + ' for element #' + int); |
||
Line 1,298: | Line 1,286: | ||
Bawl.UITextInput.setDisabled(true); //disable textinput until preload is done |
Bawl.UITextInput.setDisabled(true); //disable textinput until preload is done |
||
Bawl.dbg('preloading page specified by InputBox'); |
Bawl.dbg('preloading page specified by InputBox'); |
||
var api = new mw.Api(); |
|||
api.get( { |
api.get( { |
||
action: 'query', export: 'true', format: 'json', titles: replyLinkParams.preload, |
action: 'query', export: 'true', format: 'json', titles: replyLinkParams.preload, |
||
Line 1,326: | Line 1,313: | ||
$('#BawlReplyForm').append(Bawl.tosNagContainer); |
$('#BawlReplyForm').append(Bawl.tosNagContainer); |
||
if ( Bawl.settings.tosNag == true && ! document.getElementById('BawlToSNag') ) { |
if ( Bawl.settings.tosNag == true && ! document.getElementById('BawlToSNag') ) { |
||
Bawl.insertToSnag(); |
|||
$('#BawltosNagContainer').append(Bawl.msgs.tosNagText); |
|||
}; |
}; |
||
$(document.getElementById('bawlForm-' + replyLinkParams.id)).append(Bawl.previewAndSettingsDiv); |
$(document.getElementById('bawlForm-' + replyLinkParams.id)).append(Bawl.previewAndSettingsDiv); |
||
Line 1,396: | Line 1,383: | ||
$('BawlUITextInput').addClass('BawlLimitWidth') |
$('BawlUITextInput').addClass('BawlLimitWidth') |
||
} |
} |
||
if ( replyLinkParams.type == 'comment' || replyLinkParams.type == 'edit' || replyLinkParams.subtype == 'BCL' ) { |
if ( replyLinkParams.type == 'comment' || replyLinkParams.type == 'edit' || replyLinkParams.subtype == 'BCL' || replyLinkParams.type == 'editFullPage' ) { |
||
Bawl.dbg('hide title input and make it read-only'); |
Bawl.dbg('hide title input and make it read-only'); |
||
Bawl.UITextInputTitle.setValue(''); |
Bawl.UITextInputTitle.setValue(''); |
||
Line 1,516: | Line 1,503: | ||
Bawl.toggleClearPrefButton = function() { |
Bawl.toggleClearPrefButton = function() { |
||
if ( Bawl.settingElement.saveTo.getValue() == 'browser' ) { |
if ( Bawl.settingElement.saveTo.getValue() == 'browser' ) { |
||
Bawl.settingElement.resetPreferencesButton.setLabel(Bawl.msgs.resetPreferencesBrowser); |
Bawl.settingElement.resetPreferencesButton.setLabel(Bawl.basicmsgs.resetPreferences + Bawl.msgs.resetPreferencesBrowser); |
||
} else if ( Bawl.settingElement.saveTo.getValue() == 'commonjs' ) { |
} else if ( Bawl.settingElement.saveTo.getValue() == 'commonjs' ) { |
||
Bawl.settingElement.resetPreferencesButton.setLabel(Bawl.msgs.resetPreferencesCommonJS); |
Bawl.settingElement.resetPreferencesButton.setLabel(Bawl.basicmsgs.resetPreferences + Bawl.msgs.resetPreferencesCommonJS); |
||
} else if ( Bawl.settingElement.saveTo.getValue() == 'globaljs' ) { |
} else if ( Bawl.settingElement.saveTo.getValue() == 'globaljs' ) { |
||
Bawl.settingElement.resetPreferencesButton.setLabel(Bawl.msgs.resetPreferencesGlobalJS); |
Bawl.settingElement.resetPreferencesButton.setLabel(Bawl.basicmsgs.resetPreferences + Bawl.msgs.resetPreferencesGlobalJS); |
||
} |
} |
||
}; |
}; |
||
Line 1,532: | Line 1,519: | ||
Bawl.settingElement.pingTextFieldLayout = new OO.ui.FieldLayout( Bawl.settingElement.pingText, { label: Bawl.msgs.pingText, align: 'inline', classes: [ 'BawlOOuiFieldLayout' ] } ); |
Bawl.settingElement.pingTextFieldLayout = new OO.ui.FieldLayout( Bawl.settingElement.pingText, { label: Bawl.msgs.pingText, align: 'inline', classes: [ 'BawlOOuiFieldLayout' ] } ); |
||
Bawl.settingElement.UIversionDate = new OO.ui.LabelWidget( { |
Bawl.settingElement.UIversionDate = new OO.ui.LabelWidget( { |
||
label: Bawl.versionDate, |
label: Bawl.versionDate + ' (' + Bawl.stopwatchAddLinks3 + 'ms)', |
||
classes: [ 'BawlFloatRight', 'BawlSmallerText' ] |
classes: [ 'BawlFloatRight', 'BawlSmallerText' ] |
||
} ); |
} ); |
||
Line 1,538: | Line 1,525: | ||
id: 'saveSettingsButton', |
id: 'saveSettingsButton', |
||
flags: [ 'primary', 'progressive' ], |
flags: [ 'primary', 'progressive' ], |
||
label: Bawl. |
label: Bawl.basicmsgs.saveSettings |
||
} ); |
} ); |
||
Bawl.settingElement.resetPreferencesButton = new OO.ui.ButtonWidget( { |
Bawl.settingElement.resetPreferencesButton = new OO.ui.ButtonWidget( { |
||
Line 1,593: | Line 1,580: | ||
Bawl.settingFormArray.push(Bawl.settingElement.SettingsButtonBar); |
Bawl.settingFormArray.push(Bawl.settingElement.SettingsButtonBar); |
||
Bawl.settingElement.tosNag.on('change', Bawl.toggleTosNag ); |
Bawl.settingElement.tosNag.on('change', Bawl.toggleTosNag ); |
||
Bawl.settingElement.dateLinks.on('change', function() { if ( Bawl.settingElement.dateLinks.isSelected() ) { Bawl.settingElement.dateLinksLocalTime.setDisabled(false) } else { Bawl.settingElement.dateLinksLocalTime.setDisabled(true) } } ); |
Bawl.settingElement.dateLinks.on('change', function() { if ( Bawl.settingElement.dateLinks.isSelected() ) { Bawl.settingElement.dateLinksLocalTime.setDisabled(false) } else { Bawl.settingElement.dateLinksLocalTime.setDisabled(true);Bawl.settingElement.dateLinksLocalTime.setSelected(false) } } ); |
||
if ( Bawl.settings.dateLinks == false ) { |
if ( Bawl.settings.dateLinks == false ) { |
||
Bawl.settingElement.dateLinksLocalTime.setDisabled(true); |
Bawl.settingElement.dateLinksLocalTime.setDisabled(true); |
||
Line 1,764: | Line 1,751: | ||
return ''; |
return ''; |
||
} |
} |
||
}; |
|||
Bawl.getMostPopularIndent = function(fullpagetext, sectiontext) { |
|||
if ( sectiontext ) { |
|||
Bawl.textSearchIndentation = sectiontext; |
|||
} else { |
|||
Bawl.textSearchIndentation = fullpagetext; |
|||
} |
|||
Bawl.dbg('find the most popular indentation type'); |
|||
if ( Bawl.textSearchIndentation.match(/^\#/gm) ) { Bawl.countHashtags = Bawl.textSearchIndentation.match(/^\#/gm).length } else { Bawl.countHashtags = 0 } |
|||
if ( Bawl.textSearchIndentation.match(/^:/gm) ) { Bawl.countColons = Bawl.textSearchIndentation.match(/^:/gm).length } else { Bawl.countColons = 0 } |
|||
if ( Bawl.textSearchIndentation.match(/^\*/gm) ) { Bawl.countAsterisks = Bawl.textSearchIndentation.match(/^\*/gm).length } else { Bawl.countAsterisks = 0 } |
|||
Bawl.countCombined = Bawl.countHashtags + Bawl.countColons + Bawl.countAsterisks; |
|||
Bawl.dbg('total: ' + Bawl.countCombined + ', hashtags: ' + Bawl.countHashtags + ', colons: ' + Bawl.countColons + ', asterisks: ' + Bawl.countAsterisks); |
|||
if ( Bawl.countAsterisks >= Bawl.countColons && Bawl.countAsterisks >= Bawl.countHashtags && Bawl.countCombined > 0 ) { |
|||
Bawl.dbg('the asterisks have it'); |
|||
return '*'; |
|||
} else if ( Bawl.countColons >= Bawl.countAsterisks && Bawl.countColons >= Bawl.countHashtags && Bawl.countCombined > 0 ) { |
|||
Bawl.dbg('the colons have it'); |
|||
return ':'; |
|||
} else if ( Bawl.countHashtags > Bawl.countColons || Bawl.countHashtags > Bawl.countAsterisks && Bawl.countCombined > 0 ) { |
|||
Bawl.dbg('the hashtags have it'); |
|||
return '#'; |
|||
} else if ( sectiontext ) { |
|||
Bawl.dbg('unable to determine indendation for section. try full page.'); |
|||
return Bawl.getMostPopularIndent(fullpagetext); |
|||
} else { |
|||
return Bawl.commentTextIndentWikiDefault; |
|||
} |
|||
}; |
|||
Bawl.getInsertionPointComment = function(justCurrentPageText, replyLinkParams) { |
|||
Bawl.dbg('collect sectiontext, indentation and insertion point of original comment'); |
|||
Bawl.wikiTextSplitByUserRegExp = new RegExp(':' + Bawl.origReplyTo + '.*' + Bawl.origTimeAsInSig + '.*', 'g'); |
|||
Bawl.wikiTextSplitByUser = justCurrentPageText.split(Bawl.wikiTextSplitByUserRegExp); |
|||
if ( typeof replyLinkParams.seq == 'number' && replyLinkParams.seq <= Bawl.wikiTextSplitByUser.length ) { |
|||
Bawl.dbg('there are ' + ( Bawl.wikiTextSplitByUser.length - 1 ) + ' occurences of username "' + Bawl.origReplyTo + '" with timestamp ' + Bawl.origTimeAsInSig + ' on this page'); |
|||
Bawl.wikiTextUpToSig = ''; |
|||
for (wikitextseqint = 0; wikitextseqint <= replyLinkParams.seq; wikitextseqint++) { |
|||
Bawl.wikiTextUpToSig = Bawl.wikiTextUpToSig + Bawl.wikiTextSplitByUser[wikitextseqint]; |
|||
} |
|||
Bawl.wikiTextNum = Bawl.wikiTextUpToSig.match(/^=.*=[ ]*$/gm); |
|||
if ( Bawl.wikiTextNum ) { |
|||
Bawl.sectionText = Bawl.getSectionByNum(justCurrentPageText,Bawl.wikiTextNum.length); |
|||
} else { |
|||
Bawl.dbg('found no section headers in the text leading up to the comment'); |
|||
Bawl.sectionText = 'SECTIONLESS'; |
|||
} |
|||
Bawl.relevantPrecedingLine = Bawl.wikiTextUpToSig.split(/\n/)[ Bawl.wikiTextUpToSig.split(/\n/).length - 2 ] + '\n'; |
|||
if ( Bawl.relevantPrecedingLine == '\n' ) { Bawl.relevantPrecedingLine == ''; } |
|||
Bawl.relevantCommentNoSig = Bawl.wikiTextUpToSig.split(/\n/)[ Bawl.wikiTextUpToSig.split(/\n/).length - 1 ]; |
|||
Bawl.relevantCommentSig = justCurrentPageText.match(Bawl.wikiTextSplitByUserRegExp)[replyLinkParams.seq]; |
|||
Bawl.relevantIndentation = Bawl.relevantCommentNoSig.replace(/([\\:\\*\\#]*).*/, '$1'); |
|||
Bawl.dbg('returning requested info'); |
|||
return { 'sectiontext':Bawl.sectionText,'sectionnum':Bawl.wikiTextNum.length,'relevantIndentation':Bawl.relevantIndentation,'relevantComment':Bawl.relevantCommentNoSig + Bawl.relevantCommentSig,'relevantPrecedingLine':Bawl.relevantPrecedingLine}; |
|||
} else if ( ! Bawl.wikiTextSplitByUser ) { |
|||
Bawl.dbg('username+timestamp not found'); |
|||
return 'ERROR'; |
|||
} else { |
|||
return 'ERRORBAD'; |
|||
} |
|||
}; |
|||
Bawl.getInsertionPointSection = function(justCurrentPageText, replyLinkParams) { |
|||
Bawl.wikiTextSplitBySectionTitleRegExp = new RegExp('(?:^|\n)[=]+[\\[: ]*(?:[^\\|\n]*\\|)?' + replyLinkParams.sectionTitle + '[\\] ]*[=]+', 'gm'); |
|||
Bawl.wikiTextSplitBySectionTitle = justCurrentPageText.split(Bawl.wikiTextSplitBySectionTitleRegExp); |
|||
Bawl.wikiTextUpToHeader = ''; |
|||
for (wikitextseqint = 0; wikitextseqint <= replyLinkParams.sectionseq; wikitextseqint++) { |
|||
Bawl.wikiTextUpToHeader = Bawl.wikiTextUpToHeader + Bawl.wikiTextSplitBySectionTitle[wikitextseqint]; |
|||
} |
|||
Bawl.wikiTextNum = Bawl.wikiTextUpToHeader.match(/^=.*=[ ]*$/gm); |
|||
if ( Bawl.wikiTextNum ) { |
|||
return { 'sectiontext':Bawl.getSectionByNum(justCurrentPageText,Bawl.wikiTextNum.length + replyLinkParams.sectionseq + 1),'sectionnum':Bawl.wikiTextNum.length + replyLinkParams.sectionseq + 1}; |
|||
} |
|||
}; |
}; |
||
Bawl.postReply1 = function(replyLinkParams, newCommentsChecked) { |
Bawl.postReply1 = function(replyLinkParams, newCommentsChecked) { |
||
Line 1,814: | Line 1,872: | ||
Bawl.postCommentSummarySectionLink = ''; //no section? no link |
Bawl.postCommentSummarySectionLink = ''; //no section? no link |
||
} |
} |
||
Bawl.origReplyTo = Bawl.escapeRegExp(replyLinkParams.origReplyTo).replace(/ /g, '[_ ]'); //some users sign with [[User:User_Name]], others with [[User:User Name]] |
|||
if ( replyLinkParams.type == 'comment' ) { |
|||
Bawl.origTimeAsInSig = Bawl.timestampToTimeAsInSig(replyLinkParams.origTimestamp); |
|||
Bawl.postCommentSummary = Bawl.postCommentSummarySectionLink + Bawl.wikiMsgs.postCommentSummaryPost.replace(/USER/g, Bawl.escapeReplacement(replyLinkParams.origReplyTo)); |
|||
} else if ( replyLinkParams.type == 'anonSectReply' ) { |
|||
Bawl.postCommentSummary = Bawl.postCommentSummarySectionLink + Bawl.wikiMsgs.postCommentSummaryPost.replace(/USER/g, Bawl.escapeReplacement(replyLinkParams.sectionTitle)); |
|||
} else if ( replyLinkParams.subtype == 'BCL' ) { |
|||
Bawl.postCommentSummary = Bawl.postCommentSummarySectionLink + Bawl.summaryCredit; |
|||
} else if ( replyLinkParams.type == 'heading' ) { |
|||
Bawl.postCommentSummary = Bawl.postCommentSummarySectionLink + Bawl.wikiMsgs.postSubsectionSummaryPost.replace(/SUBSECTION/g, Bawl.escapeReplacement(Bawl.UITextInputTitle.getValue())); |
|||
} else if ( replyLinkParams.type == 'newsection' && replyLinkParams.summary ) { |
|||
Bawl.dbg('insert InputBox provided summary'); |
|||
Bawl.postCommentSummary = Bawl.wikiMsgs.postCommentSummaryNewSection.replace('SUMMARY', ' / ' + replyLinkParams.summary).replace(/NEWSECTION/g, Bawl.escapeReplacement(Bawl.UITextInputTitle.getValue())); |
|||
} else if ( replyLinkParams.type == 'newsection' ) { |
|||
Bawl.postCommentSummary = Bawl.wikiMsgs.postCommentSummaryNewSection.replace('SUMMARY', '').replace(/NEWSECTION/g, Bawl.escapeReplacement(Bawl.UITextInputTitle.getValue())); |
|||
} else if ( replyLinkParams.type == 'edit' ) { |
|||
Bawl.postCommentSummary = Bawl.postCommentSummarySectionLink + Bawl.wikiMsgs.editCommentSummary; |
|||
} |
|||
Bawl.origCmtLevel = replyLinkParams.origLevel; |
|||
Bawl.origCmtLevelPlusOne = Bawl.origCmtLevel + 1; |
|||
Bawl.dbg('replyLinkParams:'); |
Bawl.dbg('replyLinkParams:'); |
||
Bawl.dbg(replyLinkParams); |
Bawl.dbg(replyLinkParams); |
||
Bawl.postCommentParams = { |
|||
Bawl.origTimeAsInSig = Bawl.timestampToTimeAsInSig(replyLinkParams.origTimestamp); |
|||
format: 'json', |
|||
if ( replyLinkParams.origTimestamp2 && replyLinkParams.origTimestamp2 != "" ) { |
|||
action: 'edit', |
|||
Bawl.origTimeAsInSig2 = Bawl.timestampToTimeAsInSig(replyLinkParams.origTimestamp2); |
|||
title: replyLinkParams.pageTitle, |
|||
} else { |
|||
baserevid: currentRevID, |
|||
Bawl.origTimeAsInSig2 = 'NO-VALUE-PLEASE-IGNORE'; |
|||
nocreate: true, |
|||
} |
|||
watchlist: Bawl.settings.watchlist, |
|||
Bawl.origReplyTo = Bawl.escapeRegExp(replyLinkParams.origReplyTo).replace(/ /g, '[_ ]'); //some users sign with [[User:User_Name]], others with [[User:User Name]] |
|||
watchlistexpiry: Bawl.settings.watchlistexpiry |
|||
Bawl.origReplyTo2 = Bawl.escapeRegExp(replyLinkParams.origReplyTo2).replace(/_/g, '[_ ]'); |
|||
}; |
|||
Bawl.returnOriginalMessageIndentRegExp2 = new RegExp('(' + Bawl.origReplyTo2 + '.{0,255}' + Bawl.origTimeAsInSig2 + '.*)((\n[\\:\\*\\#]{' + Bawl.origCmtLevel + ',50}([^\:\*\#]|[$]).*){0,15})(\n[\\:\\*\\#]{' + Bawl.origCmtLevel + '})(.*' + Bawl.origReplyTo + '.{0,255}' + Bawl.origTimeAsInSig + '.*)((\n*[\\:\\*\\#]{' + Bawl.origCmtLevelPlusOne + ',50}.*)*)', 'm'); |
|||
Bawl.processedComment = Bawl.processComment(Bawl.UITextInput.getValue()); |
|||
if ( Bawl.origCmtLevel == 0 ) { // fully select stuff like "foo bar ~~~~\nalmost forgot foo ~~~~\nand don't forget bar ~~~~" for which DiscussionTools takes data from the FIRST signature but puts the reply-link after the last signature (just brilliant!) |
|||
Bawl.dbg('posting type and subtype: ' + replyLinkParams.type + '/' + replyLinkParams.subtype); |
|||
Bawl.dbg('using special RegExp for unindented comments to catch ugly markup'); |
|||
if ( replyLinkParams.type == 'comment' && replyLinkParams.subtype != 'anonSectReply' ) { |
|||
Bawl.returnOriginalMessageIndentRegExp = new RegExp('()^()([^\\:\\*\\#].*' + Bawl.origReplyTo + '.{0,255}' + Bawl.origTimeAsInSig + '.*)+((\n[^\\:\\*\\#\\=\n].*)*(\n[\\:\\*\\#]{' + Bawl.origCmtLevelPlusOne + ',}([^\:\*\#]|[$]).*)*)', 'm'); |
|||
Bawl.summarySnippetText = ''; |
|||
} else { |
|||
if ( Bawl.settings.sumSnippet == true && replyLinkParams.type == 'comment' && Bawl.processedComment ) { |
|||
Bawl.returnOriginalMessageIndentRegExp = new RegExp('()^([\\:\\*\\#]{' + Bawl.origCmtLevel + '})([^\:\*\#\=].*' + Bawl.origReplyTo + '.{0,255}' + Bawl.origTimeAsInSig + '.*)+((\n[\\:\\*\\#]{' + Bawl.origCmtLevelPlusOne + ',}([^\\:\\*\\#\\=]|[$]).*)*)', 'm'); |
|||
Bawl.snippetRemoveRecipient = new RegExp('^' + Bawl.escapeRegExp(Bawl.replyLinkParamsOpened.origReplyTo) + '[ ,:;]*') |
|||
} |
|||
Bawl.snippetForSummary = Bawl.processedComment.replace(/\[\[[^:]*:([^\\|\]]*)\|?\]\]/g, '$1').replace(/\{\{[^\\|\\\}\\\{]*\|([^\\\}]*)(\|[^\}]*)*\}\}/g, '$1').replace(/\[\[[^\\|]*\\|([^\\]])+\\]\\]/g, '$1').replace(/'''/g, '').replace(/''/g, '').replace(/^[\\:\\*\\#]*/, '').replace(/ *\{\{BawlCmt.*/, '').replace(Bawl.snippetRemoveRecipient, ''); |
|||
Bawl.dbg('check if the post we\'re replying to can be found..'); |
|||
if ( Bawl.snippetForSummary.length > 5 ) { |
|||
Bawl.stopwatch1 = new Date().getTime(); |
|||
Bawl.snippetForSummaryShort = Bawl.snippetForSummary; |
|||
Bawl.justCurrentPageTextMatch = justCurrentPageText.match(Bawl.returnOriginalMessageIndentRegExp); |
|||
if ( Bawl.snippetForSummary.length > 50 ) { |
|||
Bawl.stopwatch2 = new Date().getTime(); |
|||
Bawl. |
Bawl.snippetForSummaryShort = Bawl.snippetForSummary.slice(0,40) + '...'; |
||
} |
|||
Bawl.dbg('took ' + Bawl.stopwatch3 + 'ms'); |
|||
Bawl.summarySnippetText = ': ' + Bawl.snippetForSummaryShort; |
|||
if ( Bawl.stopwatch3 > 200 ) { |
|||
} |
|||
Bawl.errorReport = new Date().toLocaleString("en-GB", {timeZone: 'UTC'}) + ' (UTC) Regular expression 1 took longer than expected (probably not a fatal error) (RegExp 1: ' + Bawl.returnOriginalMessageIndentRegExp + ', RegExp 2: ' + Bawl.returnOriginalMessageIndentRegExp2 + ' Page: ' + replyLinkParams.pageTitle; |
|||
Bawl.addScrewedLink(Bawl.errorReport); |
|||
} |
|||
Bawl.dbg('check if the post we\'re replying to AND the post they replied to can be found..'); |
|||
Bawl.stopwatch1 = new Date().getTime(); |
|||
Bawl.justCurrentPageTextMatch2 = justCurrentPageText.match(Bawl.returnOriginalMessageIndentRegExp2); |
|||
Bawl.stopwatch2 = new Date().getTime(); |
|||
Bawl.stopwatch3 = Bawl.stopwatch2 - Bawl.stopwatch1; |
|||
Bawl.dbg('took ' + Bawl.stopwatch3 + 'ms'); |
|||
if ( Bawl.stopwatch3 > 2000 ) { |
|||
Bawl.errorReport = new Date().toLocaleString("en-GB", {timeZone: 'UTC'}) + ' (UTC) Regular expression 2 took longer than expected (probably not a fatal error) (RegExp 1: ' + Bawl.returnOriginalMessageIndentRegExp + ', RegExp 2: ' + Bawl.returnOriginalMessageIndentRegExp2 + ' Page: ' + replyLinkParams.pageTitle; |
|||
Bawl.addScrewedLink(Bawl.errorReport); |
|||
} |
|||
Bawl.progressPlusOne(); |
|||
if ( Bawl.trySectionEdit == true && replyLinkParams.type == 'comment' && replyLinkParams.sectionnum ) { |
|||
Bawl.dbg('checking if a section edit (which is faster) is an option'); |
|||
Bawl.sectionWikiTextByNum = Bawl.getSectionByNum(justCurrentPageText, replyLinkParams.sectionnum); |
|||
if ( Bawl.sectionWikiTextByNum ) { |
|||
Bawl.dbg('got section wikitext') |
|||
}; |
|||
Bawl.sectionWikiTextByNumMatch = Bawl.sectionWikiTextByNum.match(Bawl.returnOriginalMessageIndentRegExp); |
|||
Bawl.sectionWikiTextByNumMatch2 = Bawl.sectionWikiTextByNum.match(Bawl.returnOriginalMessageIndentRegExp2); |
|||
if ( typeof Bawl.sectionWikiTextByNumMatch == null && typeof Bawl.sectionWikiTextByNumMatch2 == null ) { |
|||
Bawl.dbg('section edit not possible'); |
|||
Bawl.trySectionEdit = false; |
|||
} |
} |
||
Bawl.postCommentParams.summary = Bawl.postCommentSummarySectionLink + Bawl.wikiMsgs.postCommentSummaryPost.replace(/USER/g, Bawl.escapeReplacement(replyLinkParams.origReplyTo) + Bawl.summarySnippetText); |
|||
} else { |
|||
Bawl.origCmtData = Bawl.getInsertionPointComment(justCurrentPageText, replyLinkParams); |
|||
Bawl.dbg('no good conditions for a section edit'); |
|||
Bawl. |
Bawl.progressPlusOne(); |
||
if (Bawl.origCmtData.relevantIndentation.length != 0) { |
|||
delete Bawl.sectionWikiTextByNum; |
|||
Bawl.dbg('repeating the last character of the indentation of the previous message so e.g. ::* becomes ::**'); |
|||
delete Bawl.sectionWikiTextByNumMatch; |
|||
Bawl.commentTextIndent = Bawl.origCmtData.relevantIndentation + Bawl.origCmtData.relevantIndentation.slice(Bawl.origCmtData.relevantIndentation.length - 1,) + ' '; |
|||
delete Bawl.sectionWikiTextByNumMatch2; |
|||
Bawl.dbg('new indendation: ' + Bawl.commentTextIndent); |
|||
} |
|||
if ( Bawl.trySectionEdit == true && replyLinkParams.type != 'newsection' ) { |
|||
justCurrentPageText = Bawl.sectionWikiTextByNum + '\n'; |
|||
} |
|||
if ( replyLinkParams.origTimestamp.match(/^[0-9]*$/) && replyLinkParams.origReplyTo != 'anonSectReply' ) { |
|||
Bawl.dbg('Bawl locator doesn\'t record indentation levels, find indentation'); |
|||
Bawl.origMessageIndentLocatorRegExp = new RegExp('(^|\n)([\\:\\*\\#]*).*' + Bawl.escapeRegExp(encodeURIComponent(replyLinkParams.origReplyTo)) + '.*' + Bawl.escapeRegExp(replyLinkParams.origTimestamp) + '[^\n]*'); |
|||
Bawl.origMessageIndent = justCurrentPageText.match(Bawl.origMessageIndentLocatorRegExp)[2]; |
|||
Bawl.origCmtLevelPlusOne = Bawl.origMessageIndent.length + 1; |
|||
Bawl.origMessageLocatorRegExp = new RegExp('(^|\n)([\\:\\*\\#]*).*' + Bawl.escapeRegExp(encodeURIComponent(replyLinkParams.origReplyTo)) + '.*' + Bawl.escapeRegExp(replyLinkParams.origTimestamp) + '[^\n]*((\n[\\:\\*\\#]{' + Bawl.origCmtLevelPlusOne + ',}([^\\:\\*\\#\\=]|[$]).*)*)'); |
|||
Bawl.relevantSectionPart = justCurrentPageText.match(Bawl.origMessageLocatorRegExp)[0]; |
|||
} else if ( replyLinkParams.origReplyTo == 'anonSectReply' ) { |
|||
Bawl.origMessageIndent = ''; |
|||
Bawl.checkWikiTextForSectionTitleRegExp = new RegExp('(^|\n)=.*' + Bawl.escapeRegExp(replyLinkParams.sectionTitle) + '.*=.*'); |
|||
Bawl.checkWikiTextForSectionTextRegExp = new RegExp('(^|\n)=.*' + Bawl.escapeRegExp(replyLinkParams.sectionTitle) + '.*=.*(\n[^=].*)*'); |
|||
if ( Bawl.trySectionEdit == true && Bawl.sectionWikiTextByNum.match(Bawl.checkWikiTextForSectionTitleRegExp) ) { |
|||
Bawl.dbg('anonSectReply, add section text to params'); |
|||
Bawl.relevantSectionPart = Bawl.sectionWikiTextByNum.match(Bawl.checkWikiTextForSectionTextRegExp)[0]; |
|||
} else if ( Bawl.trySectionEdit == false && justCurrentPageText.match(Bawl.checkWikiTextForSectionTitleRegExp).length == 1 ) { |
|||
Bawl.dbg('anonSectReply, insert comment using whole page'); |
|||
Bawl.relevantSectionPart = justCurrentPageText.match(Bawl.checkWikiTextForSectionTextRegExp)[0]; |
|||
} else { |
} else { |
||
Bawl.commentTextIndent = Bawl.getMostPopularIndent(justCurrentPageText, Bawl.origCmtData.sectiontext) + ' '; |
|||
Bawl.errorReport = new Date().toLocaleString("en-GB", {timeZone: 'UTC'}) + ' (UTC) Could not locate section "' + replyLinkParams.sectionTitle + '"to add comment to (anonSectReply) Page: ' + replyLinkParams.pageTitle; |
|||
Bawl.addScrewedLink(Bawl.errorReport); |
|||
} |
} |
||
if ( Bawl.origCmtData.sectiontext != 'SECTIONLESS' ) { |
|||
Bawl.postCommentParams.section = Bawl.origCmtData.sectionnum; |
|||
Bawl.relevantSectionPart = justCurrentPageText.match(Bawl.returnOriginalMessageIndentRegExp2)[0]; |
|||
Bawl.originalWikiText = Bawl.origCmtData.sectiontext; |
|||
Bawl.origMessageIndent = Bawl.sectionWikiTextByNum.match(Bawl.returnOriginalMessageIndentRegExp2)[5].slice(1,); |
|||
} else { |
|||
Bawl.dbg('attempting section edit, we know who we\'re replying to and who they replied to. Indentation of original message: "' + Bawl.origMessageIndent + '"'); |
|||
Bawl.originalWikiText = justCurrentPageText; |
|||
} else if ( Bawl.sectionWikiTextByNumMatch ) { |
|||
Bawl.relevantSectionPart = justCurrentPageText.match(Bawl.returnOriginalMessageIndentRegExp)[0]; |
|||
Bawl.origMessageIndent = Bawl.sectionWikiTextByNum.match(Bawl.returnOriginalMessageIndentRegExp)[2]; |
|||
Bawl.dbg('attempting section edit, we know who we\'re replying to BUT NOT who they replied to. Indentation of original message: "' + Bawl.origMessageIndent + '"'); |
|||
} else if ( Bawl.justCurrentPageTextMatch2 ) { //looks like we know not only who we're replying to but also who they replied to, use both to determine insertion point |
|||
Bawl.relevantSectionPart = justCurrentPageText.match(Bawl.returnOriginalMessageIndentRegExp2)[0]; |
|||
Bawl.origMessageIndent = justCurrentPageText.match(Bawl.returnOriginalMessageIndentRegExp2)[5].slice(1,); |
|||
Bawl.dbg('we know who we\'re replying to and who they replied to. Indentation of original message: "' + Bawl.origMessageIndent + '"'); |
|||
} else if ( Bawl.justCurrentPageTextMatch ) { //fallback to just using who we are replying to |
|||
Bawl.relevantSectionPart = justCurrentPageText.match(Bawl.returnOriginalMessageIndentRegExp)[0]; |
|||
Bawl.origMessageIndent = justCurrentPageText.match(Bawl.returnOriginalMessageIndentRegExp)[2]; |
|||
Bawl.dbg('we know who we\'re replying to BUT NOT who they replied to. Indentation of original message: "' + Bawl.origMessageIndent + '"'); |
|||
} else if ( replyLinkParams.origReplyTo == 'NO-VALUE-PLEASE-IGNORE' && replyLinkParams.type == 'heading' ) { |
|||
Bawl.dbg('creating new subsection in section without timestamp'); |
|||
Bawl.origMessageIndent = ''; |
|||
} else if ( replyLinkParams.type != 'newsection' && replyLinkParams.type != 'heading' && ! replyLinkParams.origTimestamp.match(/^[0-9]*$/) ) { //maybe try adding to the bottom of the section instead? not sure |
|||
Bawl.dbg('insertion point not found'); |
|||
Bawl.errorReport = new Date().toLocaleString("en-GB", {timeZone: 'UTC'}) + ' (UTC) insertion point not found (RegExp 1: ' + Bawl.returnOriginalMessageIndentRegExp + ', RegExp 2: ' + Bawl.returnOriginalMessageIndentRegExp2 + ' Page: ' + replyLinkParams.pageTitle; |
|||
Bawl.addScrewedLink(Bawl.errorReport); |
|||
Bawl.origMessageIndent = ''; |
|||
} |
|||
Bawl.progressPlusOne(); |
|||
Bawl.dbg('original indentation: "' + Bawl.origMessageIndent + '"'); |
|||
if ( replyLinkParams.type != 'newsection' ) { |
|||
Bawl.dbg('Find section in wikitext'); |
|||
Bawl.headingLevelPlusOne = replyLinkParams.headingLevel + 1; |
|||
Bawl.headingLevelInsertionPoint = replyLinkParams.headingLevel; |
|||
Bawl.justCurrentPageTextSectionRegExp = new RegExp('(^[\=]{' + Bawl.headingLevelInsertionPoint + '}.*' + Bawl.escapeRegExp(replyLinkParams.sectionTitle) + '.*[\=]{' + Bawl.headingLevelInsertionPoint + '}[ ]*)(((\n[^\=\n]{1}.*|\n[\=]{' + Bawl.headingLevelPlusOne + '}.*|\n))*)(.*' + Bawl.origReplyTo + '.*' + Bawl.origTimeAsInSig + '.*)(((\n[^\=\n]{1}.*|\n[\=]{' + Bawl.headingLevelPlusOne + '}.*|\n))*)', 'm'); |
|||
Bawl.justCurrentPageTextSectionMatch = justCurrentPageText.match(Bawl.justCurrentPageTextSectionRegExp); |
|||
if ( Bawl.justCurrentPageTextSectionMatch ) { // found section with username+timestamp in it |
|||
Bawl.justCurrentPageTextSection = Bawl.justCurrentPageTextSectionMatch[0]; |
|||
Bawl.dbg('Wikitext section, including user and timestamp:\n' + Bawl.justCurrentPageTextSection); |
|||
} else { //try to find a section with this name regardless of timestamps contained within. section might be empty |
|||
Bawl.justCurrentPageTextSectionRegExpAnon = new RegExp('(^[\=]{' + Bawl.headingLevelInsertionPoint + '}.*' + Bawl.escapeRegExp(replyLinkParams.sectionTitle) + '.*[\=]{' + Bawl.headingLevelInsertionPoint + '}[ ]*)(((\n[^\=\n]{1}.*|\n[\=]{' + Bawl.headingLevelPlusOne + '}.*|\n))*)', 'm'); |
|||
Bawl.justCurrentPageTextSectionMatchAnon = justCurrentPageText.match(Bawl.justCurrentPageTextSectionRegExpAnon); |
|||
if ( Bawl.justCurrentPageTextSectionMatchAnon ) { |
|||
Bawl.justCurrentPageTextSection = Bawl.justCurrentPageTextSectionMatchAnon[0]; |
|||
Bawl.dbg('Wikitext section, couldn\'t find user/timestamp:\n' + Bawl.justCurrentPageTextSection); |
|||
} else { |
|||
Bawl.dbg('could not locate section in wikitext. this is probably bad'); |
|||
} |
|||
} |
} |
||
Bawl.origCmtLevelPlusOne = Bawl.origCmtData.relevantIndentation.length + 1; |
|||
} |
|||
Bawl.replyBelowThisRegExp = new RegExp('(' + Bawl.escapeRegExp(Bawl.origCmtData.relevantPrecedingLine + Bawl.origCmtData.relevantComment) + ')((\n[\\:\\*\\#]{' + Bawl.origCmtLevelPlusOne + ',}([^\\:\\*\\#\\=]|[$]).*)*)', 'm'); |
|||
if ( Bawl.origMessageIndent == '' && replyLinkParams.type == 'comment' ) { //responding to an unindented comment |
|||
if ( ! Bawl.originalWikiText.match(Bawl.replyBelowThisRegExp) ) { |
|||
Bawl.dbg('respond to unindented comment'); |
|||
Bawl.replyBelowThisRegExp = new RegExp('(' + Bawl.escapeRegExp(Bawl.origCmtData.relevantComment) + ')((\n[\\:\\*\\#]{' + Bawl.origCmtLevelPlusOne + ',}([^\\:\\*\\#\\=]|[$]).*)*)', 'm'); |
|||
//if that's no success, use the full page |
|||
//find # of ^\#[^\#:\*], ^:[^\#:\*] and ^\*[^\#:\*], if * >= : && * <= # do *, if : >= * && : <= # do :, if # >= * || # >= : do # |
|||
Bawl.mostPopularIndent = function(text, textType) { |
|||
if ( text ) { |
|||
Bawl.dbg('find the most popular indentation type (' + textType + ')'); |
|||
if ( text.match(/^\#/gm) ) { Bawl.countHashtags = text.match(/^\#/gm).length } else { Bawl.countHashtags = 0 } |
|||
if ( text.match(/^:/gm) ) { Bawl.countColons = text.match(/^:/gm).length } else { Bawl.countColons = 0 } |
|||
if ( text.match(/^\*/gm) ) { Bawl.countAsterisks = text.match(/^\*/gm).length } else { Bawl.countAsterisks = 0 } |
|||
Bawl.countCombined = Bawl.countHashtags + Bawl.countColons + Bawl.countAsterisks; |
|||
Bawl.dbg('total: ' + Bawl.countCombined + ', hashtags: ' + Bawl.countHashtags + ', colons: ' + Bawl.countColons + ', asterisks: ' + Bawl.countAsterisks); |
|||
if ( Bawl.countAsterisks >= Bawl.countColons && Bawl.countAsterisks >= Bawl.countHashtags && Bawl.countCombined > 0 ) { |
|||
Bawl.dbg('the asterisks have it (' + textType + ')'); |
|||
return '*'; |
|||
} else if ( Bawl.countColons >= Bawl.countAsterisks && Bawl.countColons >= Bawl.countHashtags && Bawl.countCombined > 0 ) { |
|||
Bawl.dbg('the colons have it (' + textType + ')'); |
|||
return ':'; |
|||
} else if ( Bawl.countHashtags > Bawl.countColons || Bawl.countHashtags > Bawl.countAsterisks && Bawl.countCombined > 0 ) { |
|||
Bawl.dbg('the hashtags have it (' + textType + ')'); |
|||
return '#'; |
|||
} else { |
|||
Bawl.dbg('no indentation (' + textType + ')'); |
|||
return ''; |
|||
} |
|||
} else { |
|||
return ''; |
|||
} |
|||
} |
} |
||
Bawl. |
Bawl.replyBelowThis = Bawl.originalWikiText.match(Bawl.replyBelowThisRegExp)[0]; |
||
Bawl.postCommentParams.text = Bawl.originalWikiText.replace(Bawl.replyBelowThis, Bawl.replyBelowThis + '\n' + Bawl.commentTextIndent + Bawl.processedComment + Bawl.repairTagImbalance(Bawl.processedComment)); |
|||
if ( Bawl.mostPopularIndentInSection != "" ) { |
|||
} else if ( replyLinkParams.subtype == 'anonSectReply' || replyLinkParams.type == 'BCL' ) { |
|||
Bawl.dbg('a most popular indendation for the section is known'); |
|||
Bawl.postCommentParams.summary = Bawl.postCommentSummarySectionLink + Bawl.wikiMsgs.postCommentSummaryPost.replace(/USER/g, Bawl.escapeReplacement(replyLinkParams.sectionTitle)); |
|||
Bawl.commentTextIndent = Bawl.mostPopularIndent(Bawl.justCurrentPageTextSection, 'section'); |
|||
Bawl.origCmtData = Bawl.getInsertionPointSection(justCurrentPageText, replyLinkParams); |
|||
} else { |
|||
Bawl.commentTextIndent = Bawl.getMostPopularIndent(justCurrentPageText, Bawl.origCmtData.sectiontext) + ' '; |
|||
Bawl.postCommentParams.section = Bawl.origCmtData.sectionnum; |
|||
if ( Bawl.mostPopularIndentInFullPage != "" ) { |
|||
if ( replyLinkParams.type == 'BCL' ) { |
|||
Bawl.dbg('a most popular indendation for the whole page is known (could not be determined for just the section)'); |
|||
Bawl.postCommentParams.summary = Bawl.postCommentSummarySectionLink + Bawl.summaryCredit; |
|||
Bawl.commentTextIndent = Bawl.mostPopularIndentInFullPage; |
|||
if ( replyLinkParams.subtype == 'page' ) { |
|||
} else { |
|||
delete Bawl.postCommentParams.section; |
|||
Bawl.dbg('a most popular indendation could not be determined'); |
|||
} |
|||
Bawl.commentTextIndent = Bawl.commentTextIndentWikiDefault; |
|||
if ( replyLinkParams.indentation && replyLinkParams.indentation.match(/^\#\:\*$/) ) { |
|||
Bawl.commentTextIndent = replyLinkParams.indentation + ' '; |
|||
} |
} |
||
} |
} |
||
Bawl.postCommentParams.appendtext = '\n' + Bawl.commentTextIndent + Bawl.processedComment + Bawl.repairTagImbalance(Bawl.processedComment); |
|||
} else if ( replyLinkParams.type == 'comment' ) { |
|||
} else if ( replyLinkParams.type == 'heading' ) { |
|||
Bawl.dbg('responding to indented comment'); |
|||
Bawl.postCommentParams.summary = Bawl.postCommentSummarySectionLink + Bawl.wikiMsgs.postSubsectionSummaryPost.replace(/SUBSECTION/g, Bawl.escapeReplacement(Bawl.UITextInputTitle.getValue())); |
|||
Bawl.commentTextIndent = Bawl.origMessageIndent + Bawl.origMessageIndent.slice(Bawl.origMessageIndent.length - 1, Bawl.origMessageIndent.length); //repeat the last character of the indentation of the previous message, so e.g. ::* becomes ::** |
|||
Bawl.origSectData = Bawl.getInsertionPointSection(justCurrentPageText, replyLinkParams); |
|||
} |
|||
Bawl. |
Bawl.postCommentParams.section = Bawl.origSectData.sectionnum; |
||
Bawl.newSectionLevel = Bawl.origSectData.sectiontext.match(/^[=]*/)[0]; |
|||
if ( Bawl.settings.bbcode == true ) { |
|||
if ( Bawl.newSectionLevel.length < 6 ) { |
|||
Bawl.processedCommentText = Bawl.applyBBCode(Bawl.processedCommentText); |
|||
Bawl.newSectionLevel = Bawl.newSectionLevel + '='; |
|||
} |
|||
if ( Bawl.settings.markdown == true ) { |
|||
Bawl.processedCommentText = Bawl.applyMarkdown(Bawl.processedCommentText); |
|||
} |
|||
if ( Bawl.settings.rewritun == true ) { |
|||
Bawl.dbg('rewritun ur urlz'); |
|||
Bawl.processedCommentText = Bawl.rewritunUrUrlz(Bawl.processedCommentText); |
|||
} else { |
|||
Bawl.processedCommentText = Bawl.UITextInput.getValue(); |
|||
} |
|||
if ( Bawl.settings.enableCIThatRun == true ) { |
|||
Bawl.dbg('applying your regular expressions'); |
|||
Bawl.processedCommentText = Bawl.runCI(Bawl.processedCommentText); |
|||
} |
|||
Bawl.commentTextSigned = Bawl.addSignature(Bawl.processedCommentText); |
|||
Bawl.dbg('replacing newlines with templates'); |
|||
Bawl.commentTextSignedOneLine = Bawl.convertToOneLineCmt(Bawl.commentTextSigned); |
|||
if ( replyLinkParams.type == 'heading' && replyLinkParams.subtype != 'BCL' ) { //new subsection |
|||
Bawl.subsectionHeader = ''; |
|||
while ( Bawl.subsectionHeader.length < 6 && Bawl.subsectionHeader.length <= replyLinkParams.headingLevel) { |
|||
Bawl.subsectionHeader = Bawl.subsectionHeader + '='; |
|||
} |
} |
||
Bawl. |
Bawl.postCommentParams.appendtext = '\n' + Bawl.newSectionLevel + Bawl.UITextInputTitle.getValue() + Bawl.newSectionLevel + '\n' + Bawl.processedComment + Bawl.repairTagImbalance(Bawl.processedComment); |
||
} else if ( replyLinkParams. |
} else if ( replyLinkParams.type == 'newsection' ) { |
||
Bawl.postCommentParams.summary = Bawl.wikiMsgs.postCommentSummaryNewSection.replace('SUMMARY', '').replace(/NEWSECTION/g, Bawl.escapeReplacement(Bawl.UITextInputTitle.getValue())); |
|||
if ( replyLinkParams.indentation && replyLinkParams.indentation.match(/^\#\:\*$/) ) { |
|||
if ( replyLinkParams.summary ) { |
|||
Bawl.dbg('insert InputBox provided summary'); |
|||
} else { |
|||
Bawl.postCommentParams.summary = Bawl.wikiMsgs.postCommentSummaryNewSection.replace('SUMMARY', ' / ' + replyLinkParams.summary).replace(/NEWSECTION/g, Bawl.escapeReplacement(Bawl.UITextInputTitle.getValue())); |
|||
Bawl.commentTextIndent = '* '; |
|||
} |
} |
||
if ( replyLinkParams.minor == true ) { |
|||
Bawl. |
Bawl.dbg('adding InputBox specified minor flag'); |
||
Bawl.postCommentParams.minor = true; |
|||
} |
|||
} |
|||
Bawl.commentTextIndentedSigned = Bawl.commentTextIndent + Bawl.commentTextSignedOneLine; |
|||
Bawl.postCommentParams.section = 'new'; |
|||
if ( replyLinkParams.type == 'comment' ) { |
|||
Bawl.postCommentParams.sectiontitle = Bawl.UITextInputTitle.getValue(); |
|||
Bawl.wikiTextWithComment = justCurrentPageText.replace(Bawl.relevantSectionPart, Bawl.relevantSectionPart + '\n' + Bawl.commentTextIndentedSigned); |
|||
Bawl.postCommentParams.text = Bawl.processedComment + Bawl.repairTagImbalance(Bawl.processedComment); |
|||
} else if ( replyLinkParams.type == 'heading' && replyLinkParams.subtype != 'BCL' ) { //new subsection, replace section with section+new subsection |
|||
delete Bawl.postCommentParams.nocreate; |
|||
Bawl.sectionWithNewSubsection = Bawl.justCurrentPageTextSection + Bawl.commentTextIndentedSigned + '\n\n'; |
|||
Bawl.sectionWithNewSubsection2 = Bawl.sectionWithNewSubsection.replace(/\n\n\n/g, '\n\n').replace(/\n\n\n/g, '\n\n').replace(/\n\n\n/g, '\n\n'); |
|||
Bawl.wikiTextWithComment = justCurrentPageText.replace(Bawl.justCurrentPageTextSection, Bawl.sectionWithNewSubsection2); |
|||
} else if ( replyLinkParams.type == 'edit' ) { |
} else if ( replyLinkParams.type == 'edit' ) { |
||
Bawl. |
Bawl.postCommentParams.summary = Bawl.postCommentSummarySectionLink + Bawl.wikiMsgs.editCommentSummary; |
||
Bawl.origCmtData = Bawl.getInsertionPointComment(justCurrentPageText, replyLinkParams); |
|||
Bawl.wikiTextForEditCommentWithSignRegExp = new RegExp(Bawl.escapeRegExp(Bawl.wikiTextForEditComment) + '(.*' + Bawl.escapeRegExp(Bawl.origTimeAsInSig) + ')'); |
|||
if ( Bawl.origCmtData.sectiontext != 'SECTIONLESS' ) { |
|||
Bawl.wikiTextWithComment = justCurrentPageText.replace(Bawl.wikiTextForEditCommentWithSignRegExp, Bawl.commentTextOneLine + '$1'); |
|||
Bawl.postCommentParams.section = Bawl.origCmtData.sectionnum; |
|||
} |
|||
Bawl.originalWikiText = Bawl.origCmtData.sectiontext; |
|||
if ( Bawl.wikiTextWithComment ) { |
|||
} else { |
|||
Bawl.wikiTextWithComment = Bawl.wikiTextWithComment.replace(/^[\s]*/, '').replace(/[\s]*$/, ''); //removing leading and trailing whitespace/newlines |
|||
Bawl.originalWikiText = justCurrentPageText; |
|||
} |
|||
if ( Bawl.settings.sumSnippet == true && replyLinkParams.type == 'comment' && Bawl.commentTextIndentedSigned ) { |
|||
Bawl.snippetForSummary = Bawl.commentTextIndentedSigned.replace(/\[\[[^:]*:([^\\|\]]*)\|?\]\]/g, '$1').replace(/\{\{[^\\|\\\}\\\{]*\|([^\\\}]*)(\|[^\}]*)*\}\}/g, '$1').replace(/\[\[[^\\|]*\\|([^\\]])+\\]\\]/g, '$1').replace(/'''/g, '').replace(/''/g, '').replace(/^[\\:\\*\\#]*/, '').replace(/ *\{\{BawlCmt.*/, ''); |
|||
if ( Bawl.snippetForSummary.length > 5 ) { |
|||
Bawl.snippetForSummaryShort = Bawl.snippetForSummary; |
|||
if ( Bawl.snippetForSummary.length > 50 ) { |
|||
Bawl.snippetForSummaryShort = Bawl.snippetForSummary.slice(0,40) + '...'; |
|||
} |
|||
Bawl.postCommentSummary = Bawl.postCommentSummarySectionLink + Bawl.wikiMsgs.postCommentSummaryPost.replace(/USER/g, Bawl.escapeReplacement(replyLinkParams.origReplyTo) + ': ' + Bawl.snippetForSummaryShort); |
|||
} |
} |
||
Bawl.commentToReplace = Bawl.origCmtData.relevantComment.replace(/([\\:\\*\\#]*).*/, '$1'); |
|||
} |
|||
Bawl.dbg('getting usernames mentioned in this comment (WP:PINGFIX)'); |
|||
Bawl.dbg('getting usernames mentioned in this comment'); |
|||
Bawl.usernamesInEditedComment = Bawl.extractUsernames(Bawl.UITextInput.getValue()); |
Bawl.usernamesInEditedComment = Bawl.extractUsernames(Bawl.UITextInput.getValue()); |
||
Bawl.usernamesInUneditedComment = Bawl.extractUsernames(Bawl.wikiTextForEditComment); |
Bawl.usernamesInUneditedComment = Bawl.extractUsernames(Bawl.wikiTextForEditComment); |
||
Line 2,078: | Line 1,981: | ||
} |
} |
||
} |
} |
||
if ( Bawl.userMentionInSummary ) { |
if ( Bawl.userMentionInSummary != '' ) { |
||
Bawl. |
Bawl.postCommentParams.summary = Bawl.postCommentParams.summary.replace(Bawl.summaryCredit, ' (' + Bawl.userMentionInSummary.replace(/^, /, '') + ')' + Bawl.summaryCredit); |
||
} |
} |
||
Bawl.postCommentParams.text = Bawl.originalWikiText.replace(Bawl.wikiTextForEditComment, Bawl.processedComment); |
|||
} |
|||
} else if ( replyLinkParams.type == 'editFullPage' ) { |
|||
Bawl.postCommentParams = { |
|||
Bawl.postCommentParams.summary = Bawl.summaryCredit; |
|||
format: 'json', |
|||
Bawl.postCommentParams.text = Bawl.processedComment; |
|||
action: 'edit', |
|||
title: replyLinkParams.pageTitle, |
|||
nocreate: true, |
|||
summary: Bawl.postCommentSummary, |
|||
baserevid: currentRevID, |
|||
text: Bawl.wikiTextWithComment + Bawl.repairTagImbalance(Bawl.commentTextIndentedSigned), |
|||
watchlist: Bawl.settings.watchlist, |
|||
watchlistexpiry: Bawl.settings.watchlistexpiry |
|||
}; |
|||
if ( replyLinkParams.subtype == 'BCL' ) { |
|||
Bawl.dbg('set appendtext for BCL'); |
|||
delete Bawl.postCommentParams.text; |
|||
Bawl.postCommentParams.appendtext = '\n' + Bawl.commentTextIndentedSigned + Bawl.repairTagImbalance(Bawl.commentTextIndentedSigned); |
|||
if ( replyLinkParams.type == 'heading' ) { |
|||
Bawl.dbg('set sectionnum in params for BCL section edit'); |
|||
Bawl.postCommentParams.section = replyLinkParams.sectionnum; |
|||
} |
|||
} else if ( replyLinkParams.type == 'newsection' ) { |
|||
Bawl.postCommentParams.sectiontitle = Bawl.UITextInputTitle.getValue(); |
|||
Bawl.postCommentParams.section = 'new'; |
|||
Bawl.postCommentParams.text = Bawl.commentTextIndentedSigned + Bawl.repairTagImbalance(Bawl.commentTextIndentedSigned); |
|||
delete Bawl.postCommentParams.nocreate; |
|||
} |
|||
if ( replyLinkParams.minor == true ) { |
|||
Bawl.dbg('adding InputBox specified minor flag'); |
|||
Bawl.postCommentParams.minor = true; |
|||
} |
|||
if ( Bawl.trySectionEdit == true ) { |
|||
Bawl.dbg('set sectionnum for params'); |
|||
Bawl.postCommentParams.section = replyLinkParams.sectionnum; |
|||
} |
} |
||
Bawl.progressPlusOne(); |
Bawl.progressPlusOne(); |
||
Line 2,140: | Line 2,014: | ||
} |
} |
||
}; //end Bawl.postReply2 |
}; //end Bawl.postReply2 |
||
Bawl.addedReplyLinks = []; |
|||
Bawl.sectionsFound = []; |
|||
Bawl.addReplyLinkTo = function(replyLinkParams) { |
Bawl.addReplyLinkTo = function(replyLinkParams) { |
||
if ( Bawl.settings.RLmasq == true && mw.config.get('wgUserLanguage') == 'pt' ) { //afaik reply-link only ever had a translation in Portuguese |
if ( Bawl.settings.RLmasq == true && mw.config.get('wgUserLanguage') == 'pt' ) { //afaik reply-link only ever had a translation in Portuguese |
||
Line 2,146: | Line 2,022: | ||
Bawl.svgBawlIcon = '<span style="color: #000">(</span><span style="color: #0645ad">reply</span><span style="color: #000">)</span>'; |
Bawl.svgBawlIcon = '<span style="color: #000">(</span><span style="color: #0645ad">reply</span><span style="color: #000">)</span>'; |
||
} |
} |
||
if ( replyLinkParams.type == 'comment' && replyLinkParams.subtype != 'anonSectReply' ) { |
|||
Bawl.replyUserDate = replyLinkParams.origReplyTo + replyLinkParams.origTimestamp; |
|||
for (seqint = 0; seqint < 100; seqint++) { |
|||
Bawl.dbg('make record of the username+timestamp so other comments with the same data can be identified this is #' + seqint); |
|||
if ( Bawl.addedReplyLinks.indexOf(Bawl.replyUserDate + '-' + seqint) == -1 ) { |
|||
Bawl.addedReplyLinks.push(Bawl.replyUserDate + '-' + seqint); |
|||
replyLinkParams.seq = seqint; |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
replyLinkParams.sectionseq = Bawl.sectionseq; |
|||
Bawl.replyLinkDebugInfo = ''; |
Bawl.replyLinkDebugInfo = ''; |
||
if ( Bawl.settings.debug == true && int ) { |
if ( Bawl.settings.debug == true && int ) { |
||
Line 2,212: | Line 2,100: | ||
'origReplyTo':'NO-VALUE-PLEASE-IGNORE', |
'origReplyTo':'NO-VALUE-PLEASE-IGNORE', |
||
'origTimestamp':'2000-01-01T00:00:00.000Z', |
'origTimestamp':'2000-01-01T00:00:00.000Z', |
||
'origReplyTo2':'NO-VALUE-PLEASE-IGNORE', |
|||
'headingLevel': 0 |
|||
} |
} |
||
//skin support: replying and new sections should work everywhere, new subsections (dealth with further down) should work on Vector, timeless, monobook and modern. Not on Minerva |
//skin support: replying and new sections should work everywhere, new subsections (dealth with further down) should work on Vector, timeless, monobook and modern. Not on Minerva |
||
Line 2,226: | Line 2,112: | ||
} |
} |
||
$('#mw-content-text').append('<div id="bawlForm-newSectionForm" class="BawlNoDisplay BawlForm"><\/div>'); |
$('#mw-content-text').append('<div id="bawlForm-newSectionForm" class="BawlNoDisplay BawlForm"><\/div>'); |
||
} |
|||
if ( Bawl.settings.enableEverywhere == true ) { |
|||
Bawl.replyLinkParams = { |
|||
'id':'editFullPage', |
|||
'type':'editFullPage', |
|||
'pageTitle': mw.config.get('wgPageName'), |
|||
} |
|||
if ( (mw.config.get('skin') == 'vector' || mw.config.get('skin') == 'vector-2022') && typeof $('#ca-edit')[0] != "undefined" ) { |
|||
$('#ca-edit')[0].outerHTML = $('#ca-edit')[0].outerHTML + $('#ca-edit')[0].outerHTML.replace('ca-edit', 'ca-bawleditFullPage').replace(/href="[^"]*"/, 'onclick="Bawl.openReplyForm(\'' + encodeURIComponent(JSON.stringify(Bawl.replyLinkParams)).replace(/\'/g, '%27') + '\')"').replace('++', '+0').replace('accesskey="+"', 'accesskey="0"').replace(/<span>.*<\/span>/, '<span>' + Bawl.svgBawlIconEdit + '</span>'); |
|||
} else if ( mw.config.get('skin') == 'minerva' && typeof $('#ca-edit')[0] != "undefined" ) { |
|||
$('#ca-edit')[0].outerHTML = $('#ca-edit')[0].outerHTML + $('#ca-edit')[0].outerHTML.replace('ca-edit', 'ca-bawleditFullPage').replace(/href="[^"]*"/, 'style="background-image: url(' + Bawl.svgBawlIconEditEditData + ');background-repeat: no-repeat" onclick="Bawl.openReplyForm(\'' + encodeURIComponent(JSON.stringify(Bawl.replyLinkParams)).replace(/\'/g, '%27') + '\')"').replace('++', '+0').replace('accesskey="+"', 'accesskey="0"').replace(/(\<a.*\>)([^\<]*)(\<\/a\>)/, '$1' + '$3').replace(/title="[^"]*"/, 'title="' + Bawl.msgs.bawleditFullPageToolbar + '"').replace('mw-ui-icon-wikimedia-edit-base20', ''); |
|||
} else if ( ( mw.config.get('skin') == 'modern' && typeof $('#ca-edit')[0] != "undefined" ) || ( mw.config.get('skin') == 'monobook' && typeof $('#ca-edit')[0] != "undefined" ) ) { |
|||
$('#ca-edit')[0].outerHTML = $('#ca-edit')[0].outerHTML + $('#ca-edit')[0].outerHTML.replace('ca-edit', 'ca-bawleditFullPage').replace(/href="[^"]*"/, 'onclick="Bawl.openReplyForm(\'' + encodeURIComponent(JSON.stringify(Bawl.replyLinkParams)).replace(/\'/g, '%27') + '\')"').replace('++', '+0').replace('accesskey="+"', 'accesskey="0"').replace(/>([^<]*)</, '>Bawl!<'); |
|||
} else if ( mw.config.get('skin') == 'timeless' && typeof $('#ca-edit')[0] != "undefined" ) { |
|||
$('#ca-edit')[0].outerHTML = $('#ca-edit')[0].outerHTML + $('#ca-edit')[0].outerHTML.replace('ca-edit', 'ca-bawleditFullPage').replace(/href="[^"]*"/, 'onclick="Bawl.openReplyForm(\'' + encodeURIComponent(JSON.stringify(Bawl.replyLinkParams)).replace(/\'/g, '%27') + '\')"').replace('++', '+0').replace('accesskey="+"', 'accesskey="0"').replace(/<span>.*<\/span>/, '<span>' + Bawl.svgBawlIconEdit + '</span>'); |
|||
} |
|||
$('#mw-content-text').prepend('<div id="bawlForm-editFullPage" class="BawlNoDisplay BawlForm"><\/div>'); |
|||
} |
} |
||
$('.ext-discussiontools-init-replylink-buttons').addClass('BawlYesDisplay'); |
$('.ext-discussiontools-init-replylink-buttons').addClass('BawlYesDisplay'); |
||
Line 2,236: | Line 2,139: | ||
for (int = 0; int < document.getElementsByClassName('bawlprocess').length; int++) { |
for (int = 0; int < document.getElementsByClassName('bawlprocess').length; int++) { |
||
Bawl.dbg('Process element #' + int + '/' + (document.getElementsByClassName('bawlprocess').length - 1) + ' with "bawlprocess" class'); |
Bawl.dbg('Process element #' + int + '/' + (document.getElementsByClassName('bawlprocess').length - 1) + ' with "bawlprocess" class'); |
||
if ( Bawl.replyToSectionLinkNeeded |
if ( Bawl.replyToSectionLinkNeeded && ( ( typeof document.getElementsByClassName('bawlprocess')[int].className != "undefined" && document.getElementsByClassName('bawlprocess')[int].className.match('mw-headline') ) || ! document.getElementsByClassName('bawlprocess')[int+1] ) ) { |
||
Bawl.dbg('found a new section or the last element to be processed. adding reply to section link'); |
Bawl.dbg('found a new section or the last element to be processed. adding reply to section link'); |
||
Bawl.replyLinkParams = { |
Bawl.replyLinkParams = { |
||
'int': int, |
'int': int, |
||
'type':'comment', |
'type':'comment', |
||
' |
'subtype':'anonSectReply', |
||
'sectionseq':Bawl.sectionseq, |
|||
'id':'anonSectReply:' + Bawl.pageTitleToEdit + ':' + Bawl.sectionTitle + ':' + Bawl.sectionseq, |
|||
'pageTitle': Bawl.pageTitleToEdit, |
'pageTitle': Bawl.pageTitleToEdit, |
||
'sectionTitle': Bawl.sectionTitle, |
'sectionTitle': Bawl.sectionTitle, |
||
'origReplyTo':'anonSectReply', |
'origReplyTo':'anonSectReply', |
||
'origTimestamp':'', |
'origTimestamp':'', |
||
'origLevel': 0, |
|||
'origTimestamp2':'', |
|||
'origReplyTo2':'', |
|||
'headingLevel': 0, |
|||
'sectionnum': Bawl.sectionNumberToEdit, |
|||
} |
} |
||
Bawl.replyToSectionButton = document.createElement('div'); |
Bawl.replyToSectionButton = document.createElement('div'); |
||
Line 2,269: | Line 2,169: | ||
Bawl.dbg('found a comment to add a link to'); |
Bawl.dbg('found a comment to add a link to'); |
||
Bawl.formDataset[int] = JSON.parse(document.getElementsByClassName('bawlprocess')[int].childNodes[1].dataset.mwComment); |
Bawl.formDataset[int] = JSON.parse(document.getElementsByClassName('bawlprocess')[int].childNodes[1].dataset.mwComment); |
||
Bawl.origLevel = Bawl.formDataset[int].level - 1; // metadata considers an unindented message as level 1, first indent as 2, etc, but we need the number of indentation characters |
|||
Bawl.getDataFromIdRegExp = new RegExp('^c-(.*)\-([0-9]{4}-[0-1][0-9]-[0-3][0-9]T[^-]*)-(.*)-([0-9]{4}-[0-1][0-9]-[0-3][0-9]T.*)'); //RegExp notes: $1 is the first username, $2 the first timestamp, $3 the second username, $4 the second timestamp |
|||
if ( Bawl.formDataset[int].id.match( Bawl.getDataFromIdRegExp ) && Bawl.formDataset[int].id.match( Bawl.getDataFromIdRegExp ).length == 5 ) { //id contains data for the comment above the one we're replying to, this can help to find the insertion point in case of duplicated combinations of username+timestamp |
|||
Bawl.dbg('id contains a second username'); |
|||
Bawl.origTimestamp2 = Bawl.formDataset[int].id.replace( Bawl.getDataFromIdRegExp, '$4' ); |
|||
Bawl.origReplyTo2 = Bawl.formDataset[int].id.replace( Bawl.getDataFromIdRegExp, '$3' ); |
|||
} else { // would happen if you reply to the intial post of a discussion |
|||
Bawl.dbg('no second username found'); |
|||
Bawl.origTimestamp2 = ''; |
|||
Bawl.origReplyTo2 = ''; |
|||
} |
|||
if ( Bawl.formDataset[int].type == "comment" ) { //only add a link to comments here |
if ( Bawl.formDataset[int].type == "comment" ) { //only add a link to comments here |
||
Bawl.replyLinkParams = { |
Bawl.replyLinkParams = { |
||
Line 2,289: | Line 2,178: | ||
'origReplyTo': Bawl.formDataset[int].author, |
'origReplyTo': Bawl.formDataset[int].author, |
||
'origTimestamp': Bawl.formDataset[int].timestamp, |
'origTimestamp': Bawl.formDataset[int].timestamp, |
||
'origLevel': Bawl.origLevel, |
|||
'origTimestamp2': Bawl.origTimestamp2, |
|||
'origReplyTo2': Bawl.origReplyTo2, |
|||
'headingLevel': Bawl.headingLevel, //used for section extraction |
|||
'sectionnum': Bawl.sectionNumberToEdit, |
|||
} |
} |
||
if ( $('.bawlprocess')[int-1] && $('.bawlprocess')[int-1].classList && $('.bawlprocess')[int-1].classList[0] == 'BawlCmt' && decodeURIComponent($('.bawlprocess')[int-1].id.replace(/([^\:]*).*/, '$1')) == Bawl.replyLinkParams.origReplyTo && new Date(new Number($('.bawlprocess')[int-1].id.replace(/([^\:]*)\:([0-9]*).*/, '$2').replace(/[^0-9]*/g, ''))).toLocaleString("en-GB", {timeZone: 'UTC'}).slice(0,-3) == new Date(Bawl.formDataset[int].timestamp).toLocaleString("en-GB", {timeZone: 'UTC'}).slice(0,-3) ) { |
if ( $('.bawlprocess')[int-1] && $('.bawlprocess')[int-1].classList && $('.bawlprocess')[int-1].classList[0] == 'BawlCmt' && decodeURIComponent($('.bawlprocess')[int-1].id.replace(/([^\:]*).*/, '$1')) == Bawl.replyLinkParams.origReplyTo && new Date(new Number($('.bawlprocess')[int-1].id.replace(/([^\:]*)\:([0-9]*).*/, '$2').replace(/[^0-9]*/g, ''))).toLocaleString("en-GB", {timeZone: 'UTC'}).slice(0,-3) == new Date(Bawl.formDataset[int].timestamp).toLocaleString("en-GB", {timeZone: 'UTC'}).slice(0,-3) ) { |
||
Line 2,336: | Line 2,220: | ||
} |
} |
||
} else if (typeof document.getElementsByClassName('bawlprocess')[int].childNodes != "undefined" && typeof document.getElementsByClassName('bawlprocess')[int].childNodes[1] == 'object' && typeof document.getElementsByClassName('bawlprocess')[int].childNodes[1].href != "undefined" && document.getElementsByClassName('bawlprocess')[int].className.match('mw-editsection') ) { //edit section link, extract page title and section |
} else if (typeof document.getElementsByClassName('bawlprocess')[int].childNodes != "undefined" && typeof document.getElementsByClassName('bawlprocess')[int].childNodes[1] == 'object' && typeof document.getElementsByClassName('bawlprocess')[int].childNodes[1].href != "undefined" && document.getElementsByClassName('bawlprocess')[int].className.match('mw-editsection') ) { //edit section link, extract page title and section |
||
if ( Bawl.settings.replySecLink == true ) { |
if ( Bawl.settings.replySecLink == true && ( $('#ca-addsection')[0] || $('.ext-discussiontools-init-replylink-buttons')[0] || $('.BawlCmt')[0] ) ) { |
||
Bawl.replyToSectionLinkNeeded = true; |
Bawl.replyToSectionLinkNeeded = true; |
||
} |
} |
||
Bawl.dbg('section link found, extract page title and section (' + int + ')'); |
Bawl.dbg('section link found, extract page title and section (' + int + ')'); |
||
Bawl.pageTitleToEdit = decodeURIComponent(document.getElementsByClassName('bawlprocess')[int].childNodes[1].href.replace( /.*title=([^&]*).*/, '$1')).replace(/_/g, ' '); |
Bawl.pageTitleToEdit = decodeURIComponent(document.getElementsByClassName('bawlprocess')[int].childNodes[1].href.replace( /.*title=([^&]*).*/, '$1')).replace(/_/g, ' '); |
||
Bawl.sectionPlusPage = Bawl.sectionTitle + Bawl.pageTitleToEdit; |
|||
Bawl.sectionNumberToEdit = decodeURIComponent(document.getElementsByClassName('bawlprocess')[int].childNodes[1].href.replace( /.*section=(T\-)?([0-9]*).*/, '$2')).replace(/_/g, ' ').replace(/([^0-9]*)/g, ''); |
|||
for (secseqint = 0; secseqint < 100; secseqint++) { |
|||
Bawl.dbg('make record of the section+pagename so others with the same data can be identified - this is #' + secseqint); |
|||
if ( Bawl.sectionsFound.indexOf(Bawl.sectionPlusPage + '-' + secseqint) == -1 ) { |
|||
Bawl.sectionsFound.push(Bawl.sectionPlusPage + '-' + secseqint); |
|||
Bawl.sectionseq = secseqint; |
|||
break; |
|||
} |
|||
} |
|||
if ( document.getElementsByClassName('bawlprocess')[int - 1] && typeof document.getElementsByClassName('bawlprocess')[int - 1].dataset != "undefined" && typeof document.getElementsByClassName('bawlprocess')[int - 1].dataset.mwComment == 'string' ) { |
if ( document.getElementsByClassName('bawlprocess')[int - 1] && typeof document.getElementsByClassName('bawlprocess')[int - 1].dataset != "undefined" && typeof document.getElementsByClassName('bawlprocess')[int - 1].dataset.mwComment == 'string' ) { |
||
Bawl.formDataset[int - 1] = JSON.parse(document.getElementsByClassName('bawlprocess')[int - 1].dataset.mwComment); |
Bawl.formDataset[int - 1] = JSON.parse(document.getElementsByClassName('bawlprocess')[int - 1].dataset.mwComment); |
||
Line 2,363: | Line 2,255: | ||
'origReplyTo': Bawl.paramorigReplyTo, |
'origReplyTo': Bawl.paramorigReplyTo, |
||
'origTimestamp': Bawl.paramorigTimestamp, |
'origTimestamp': Bawl.paramorigTimestamp, |
||
'origReplyTo2':'NO-VALUE-PLEASE-IGNORE', |
|||
'headingLevel': Bawl.formDataset[int - 1].headingLevel, //section extraction and determine the level for the new header |
|||
'sectionnum': Bawl.sectionNumberToEdit, |
|||
} |
} |
||
Bawl.headingLevel = Bawl.replyLinkParams.headingLevel; |
Bawl.headingLevel = Bawl.replyLinkParams.headingLevel; |
||
Line 2,385: | Line 2,274: | ||
'int': int, |
'int': int, |
||
'type':'comment', |
'type':'comment', |
||
'subtype':'bylocator', |
|||
'id': $('.bawlprocess')[int].id, |
'id': $('.bawlprocess')[int].id, |
||
'pageTitle': decodeURIComponent(Bawl.locatorPageTitle), |
'pageTitle': decodeURIComponent(Bawl.locatorPageTitle), |
||
Line 2,390: | Line 2,280: | ||
'origReplyTo': decodeURIComponent(Bawl.locatorUsername), |
'origReplyTo': decodeURIComponent(Bawl.locatorUsername), |
||
'origTimestamp': Bawl.locatorTimestamp, |
'origTimestamp': Bawl.locatorTimestamp, |
||
'origLevel': 0, |
|||
'origTimestamp2':'', |
|||
'origReplyTo2':'', |
|||
'headingLevel': Bawl.headingLevel, //used for section extraction |
|||
'sectionnum': Bawl.sectionNumberToEdit, |
|||
} |
} |
||
Bawl.addReplyLinkTo(Bawl.replyLinkParams); |
Bawl.addReplyLinkTo(Bawl.replyLinkParams); |
||
Line 2,442: | Line 2,327: | ||
'int': int, |
'int': int, |
||
'id':'Bawl-comment-link', |
'id':'Bawl-comment-link', |
||
'type':' |
'type':'BCL', |
||
'subtype':' |
'subtype':'page', |
||
'pageTitle': mw.config.get('wgPageName'), |
'pageTitle': mw.config.get('wgPageName'), |
||
'sectionTitle': Bawl.sectionTitle, |
'sectionTitle': Bawl.sectionTitle, |
||
'origReplyTo':'NO-VALUE-PLEASE-IGNORE', |
'origReplyTo':'NO-VALUE-PLEASE-IGNORE', |
||
'origTimestamp':'2000-01-01T00:00:00.000Z', |
'origTimestamp':'2000-01-01T00:00:00.000Z', |
||
'origReplyTo2':'NO-VALUE-PLEASE-IGNORE', |
|||
'headingLevel': 0, |
|||
'sectionnum': Bawl.sectionNumberToEdit, |
|||
'preloadparams': [] |
'preloadparams': [] |
||
} |
} |
||
Bawl.commentLinkID = JSON.parse($('.bawlprocess')[int].id); |
Bawl.commentLinkID = JSON.parse($('.bawlprocess')[int].id); |
||
if ( Bawl.commentLinkID.type == 'section' ) { |
if ( Bawl.commentLinkID.type == 'section' ) { |
||
Bawl.replyLinkParams. |
Bawl.replyLinkParams.subtype = 'section'; |
||
} |
} |
||
if ( Bawl.commentLinkID.page ) { |
if ( Bawl.commentLinkID.page ) { |
||
Line 2,478: | Line 2,360: | ||
Bawl.stopwatchAddLinks2 = new Date().getTime(); |
Bawl.stopwatchAddLinks2 = new Date().getTime(); |
||
Bawl.stopwatchAddLinks3 = Bawl.stopwatchAddLinks2 - Bawl.stopwatchAddLinks1; |
Bawl.stopwatchAddLinks3 = Bawl.stopwatchAddLinks2 - Bawl.stopwatchAddLinks1; |
||
if ( window.location.hash != '' ) { |
|||
Bawl.dbg('adding links took ' + Bawl.stopwatchAddLinks3 + 'ms'); |
|||
Bawl.dbg('url contains an anchor. as the page may have jumped, re-jump to anchor'); |
|||
//console.log('adding links took ' + Bawl.stopwatchAddLinks3 + 'ms'); |
|||
Bawl.locationHash = window.location.hash; |
|||
window.location = '#'; |
|||
window.location = Bawl.locationHash; |
|||
} |
|||
if ( Bawl.automaticallyOpenFormParams ) { |
if ( Bawl.automaticallyOpenFormParams ) { |
||
Bawl.openReplyForm(Bawl.automaticallyOpenFormParams); |
Bawl.openReplyForm(Bawl.automaticallyOpenFormParams); |
Revision as of 22:17, 13 February 2022
//Bawl[https://en.wikipedia.org/wiki/User:Alexis_Jazz/Bawl] is a userscript to add comments to discussions with more features and options than usual. Probably better support too. Report issues to the talk page.
//<nowiki>Bawl is public domain, WTFPL Version 2[http://www.wtfpl.net/about/]. If you don't like that or think it's invalid where you live you may use Bawl under CC BY-SA 3.0, CC BY 2.5 or CC BY 4.0 instead. Your choice.
if ( ( window.localStorage.BawlenableEverywhere && typeof $('#ca-edit')[0] != "undefined" ) || $('#ca-addsection')[0] || $('.ext-discussiontools-init-replylink-buttons')[0] || $('.BawlCmt')[0] || ( mw.config.get('wgNamespaceNumber') != -1 && mw.config.get('wgNamespaceNumber') != 2 && ( mw.config.get('wgNamespaceNumber') != 0 || mw.config.get('wgDBname') == 'metawiki' ) && mw.config.get('wgNamespaceNumber') != 6 && mw.config.get('wgNamespaceNumber') != 14 && mw.config.get('wgPageContentModel') == 'wikitext' && mw.config.get('wgAction') == 'view' && mw.config.get('wgDiffNewId') == null && window.location.href.match('veaction=') == null && window.location.href.match('oldid=') == null ) ) {
Bawl = {};
//</nowiki>
Bawl.versionDate = '22:17, 13 February 2022 (UTC)';
//<nowiki>
Bawl.msgsObj = {};
Bawl.basicmsgsObj = {};
Bawl.wikiMsgsObj = {};
var api = new mw.Api();
Bawl.ToSlicenselinks = '<a href="https://creativecommons.org/licenses/by-sa/3.0">CC BY-SA 3.0</a>+<a href="https://en.wikipedia.org/wiki/Wikipedia:Text_of_the_GNU_Free_Documentation_License">GFDL</a>'; //when can we get rid of the GFDL?
Bawl.ToSmoreInfoLink = '<a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Terms_of_Use">ToU</a>';
Bawl.msgsObj.mul = { //multilingual and default texts, selected using wgUserLanguage. Messages that are used beyond the initial opening of the form.
'UILabelInterface':'Interface',
'tosNag':'Annoy me with the ToS all the time (you can disable this!)',
'afterPost':'After posting:',
'nSecLink':'Insert link to add a new section',
'replySecLink':'Add reply button at the bottom of sections',
'secLinks':'Insert links to add subsections',
'inputBoxTO':'Take over <a href="https://www.mediawiki.org/wiki/Extension:InputBox" target="_new">InputBoxes</a>',
'enableEverywhere':'Enable full page editing with Bawl',
'editLinks':'Insert links to edit my comments',
'editNotice':'Show <a href="https://en.wikipedia.org/wiki/Wikipedia:Editnotice" target="_new">editnotices</a>',
'dateLinksIcon':'Link comments through comment link icon',
'dateLinks':'Link comments through signature dates (may break other gadgets that insert buttons near comments)',
'dateLinksLocalTime':'Display signature date in local time (requires above)',
'wrongUI':'Put buttons on the wrong side like <a href="' + mw.config.get('wgServer') + mw.config.get('wgArticlePath').replace('$1', 'm:Special:MyLanguage/Talk_pages_project/Feature_summary') + '" target="_new">DiscussionTools</a>',
'livePreview':'Live preview',
'saveDraft':'Save unsent comments of >100 characters in browser for up to a week',
'checkNewComments':'Check for new comments when opening form/preview',
'limitWidth':'Limit interface width',
'RLmasq':'Masquerade as reply-link',
'warnExit':'Warn before leaving the page with an entered comment',
'UIfontSize':'Interface size:',
'UILabelEditing':'Editing',
'autoPing':'Auto-mention',
'markup':'Enable basic markup toolbar',
'enableCI':'Enable custom inserts',
'enableCIThatRun':'Enable custom regular expressions that are automatically applied on preview/publish',
'rewritun':'Rewrite external URLs to internal ones where possible, clean internal links',
'markdown':'Convert <a href="https://en.wikipedia.org/wiki/Markdown" target="_new">Markdown</a> markup language (partial implementation)',
'bbcode':'Convert <a href="https://en.wikipedia.org/wiki/BBCode" target="_new">BBCode</a> markup language',
'useLocator':'Add invisible comment locator to comments (improves functionality)',
'sumSnippet':'Add snippet to edit summary',
'pingText':'Mention format, e.g. "Yo [[User:USER|USER]]! "',
'UILabelAdvanced':'Advanced',
'watchlist':'Watchlist setting:',
'watchlistexpiry':'Watchlist expiration: ',
'hideThePain':'Hide reply links from DiscussionTools',
'debug':'Enable test/debug mode',
'saveTo':'Save settings to:',
'resetPreferencesBrowser':' (browser)',
'resetPreferencesCommonJS':' (account)',
'resetPreferencesGlobalJS':' (global account)',
'watchlistexpirydays':'DAYS days',
'BawlCustomInsertPlaceholder':'fooNUM:<<bar>>',
'BawlCustomInsertThatRunPlaceholder':'/[Ff]ooNUM/bar/g',
'UIfontSize0875em':'0.875em',
'UIfontSizeTiny':'Tiny!',
'UIfontSizeSmall':'Small',
'UIfontSizeMedium':'Medium',
'UIfontSizeLarge':'Large',
'UIfontSizeHuge':'Huge',
'reloadafter':'Reload the page (slowest)',
'linkafter':'Just show a link (fastest)',
'parsecomment':'Parse comment in place (might be inaccurate)',
'saveToGlobalJS':'Global account (public)',
'saveToCommonJS':'Account (public)',
'saveToBrowser':'This browser',
'commentDone':'Done!',
'commentPostedThankYou':' Thank you for using <a href="https://en.wikipedia.org/wiki/User:Alexis_Jazz/Bawl" target="_new">Bawl!</a>',
'editNoticeSetting':'<a onclick="Bawl.openSettings(\'open\'); window.editNotice.scrollIntoView()"><span style="color:black; opacity:0.5; font-size:smaller; float:right;">Editnotices can be disabled</span></a>', //todo: insert this
'BawlAddSectionToolbar':'Add section (Bawl)',
'nopingNotify':'This user doesn\'t want their username to be linked.',
'titlePlaceholder':'',
'replyToTitle':'🗨 USER',
'newSectionTitle':'Add section',
'editTitle':'Change comment',
'showNewLinesButton':'Show changed and added content',
'restoredDraft':'Restored draft',
'lang':'mul',
};
Bawl.msgsObj.en = {
'titlePlaceholder':'Title',
'replyToTitle':'Reply to USER',
'editTitle':'Edit comment',
};
Bawl.msgsObj.es = {'titlePlaceholder':'Asunto'};
Bawl.msgsObj.fr = {'titlePlaceholder':'Sujet'};
Bawl.msgsObj.zh = {'titlePlaceholder':'主题'};
Bawl.msgsObj.ru = {'titlePlaceholder':'Тема'};
Bawl.msgsObj.pt = {'titlePlaceholder':'Assunto'};
Bawl.msgsObj.it = {'titlePlaceholder':'Oggetto'};
Bawl.msgsObj.ja = {'titlePlaceholder':'題名'};
Bawl.msgsObj.pl = {'titlePlaceholder':'Temat'};
Bawl.msgsObj.vi = {'titlePlaceholder':'Đề mục'};
Bawl.msgsObj.sv = {'titlePlaceholder':'Ämne'};
Bawl.msgsObj.uk = {'titlePlaceholder':'Тема'};
Bawl.msgsObj.fa = {'titlePlaceholder':'عنوان'};
Bawl.basicmsgsObj.mul = { //multilingual and default texts, selected using wgUserLanguage. Messages that are required to load the script and open the form
'BawlUIReplyButton':' 📢 ', //regular spaces are stripped, figure spaces are not
'BawlUIEditButton': ' 🖋️ ',
'BawlUIPreviewButton':' 👁 ',
'BawlUICancelButton':' 🗑️ ',
'saveSettings':'Save',
'resetPreferences': 'Restore all default settings',
'bold':' B ',
'italic':' I ',
'strike':'ABC',
};
Bawl.basicmsgsObj.en = {'BawlUIReplyButton':'Reply','BawlUIEditButton' : 'Submit','BawlUIPreviewButton':'Preview','BawlUICancelButton':'Cancel'};
if ( typeof BawlBasicmsgsObj != 'undefined' && BawlBasicmsgsObj[ mw.config.get('wgUserLanguage') ] ) { // BawlBasicmsgsObj could be specified in common.js before Bawl is loaded
Bawl.basicmsgs = Object.assign(Bawl.basicmsgsObj.mul, BawlBasicmsgsObj[ mw.config.get('wgUserLanguage') ]);
} else if ( mw.config.get('wgUserLanguage') == 'en' ) {
Bawl.basicmsgs = Object.assign(Bawl.basicmsgsObj.mul, Bawl.basicmsgsObj.en);
} else if ( window.localStorage['BawlBasicLang'+mw.config.get('wgUserLanguage')] && JSON.parse(window.localStorage['BawlBasicLang'+mw.config.get('wgUserLanguage')]) && JSON.parse(window.localStorage['BawlBasicLang'+mw.config.get('wgUserLanguage')]).version == Bawl.versionDate ) {
Bawl.basicmsgs = Object.assign(Bawl.basicmsgsObj.mul, JSON.parse(window.localStorage['BawlBasicLang'+mw.config.get('wgUserLanguage')]));
} else {
Bawl.basicMsgsWikiText = '<span class="basicMsg">{{int:htmlform-submit}}</span><span class="basicMsg">{{int:edit}}</span><span class="basicMsg">{{int:preview}}</span><span class="basicMsg">{{int:cancel}}</span><span class="basicMsg">{{int:saveprefs}}</span><span class="basicMsg">{{int:restoreprefs}}</span>';
api.get( {
format: 'json', action: 'parse', text: Bawl.basicMsgsWikiText
} ).done( function ( data ) {
Bawl.basicMsgsArrayRegExp = new RegExp('(?:<span class="basicMsg">)([^<]*)(?:<\/span>)', 'g');
Bawl.basicMsgsArray = data.parse.text['*'].match(Bawl.basicMsgsArrayRegExp);
if ( Bawl.basicMsgsArray ) {
Bawl.basicmsgsObj[mw.config.get('wgUserLanguage')] = {
'BawlUIReplyButton':Bawl.basicMsgsArray[0].replace(Bawl.basicMsgsArrayRegExp, '$1'),
'BawlUIEditButton':Bawl.basicMsgsArray[1].replace(Bawl.basicMsgsArrayRegExp, '$1'),
'BawlUIPreviewButton':Bawl.basicMsgsArray[2].replace(Bawl.basicMsgsArrayRegExp, '$1'),
'BawlUICancelButton':Bawl.basicMsgsArray[3].replace(Bawl.basicMsgsArrayRegExp, '$1'),
'saveSettings':Bawl.basicMsgsArray[4].replace(Bawl.basicMsgsArrayRegExp, '$1'),
'resetPreferences':Bawl.basicMsgsArray[5].replace(Bawl.basicMsgsArrayRegExp, '$1'),
'version':Bawl.versionDate
};
Bawl.basicLangString = JSON.stringify(Bawl.basicmsgsObj[mw.config.get('wgUserLanguage')]);
window.localStorage.setItem('BawlBasicLang'+mw.config.get('wgUserLanguage'), Bawl.basicLangString);
Bawl.basicmsgs = Object.assign(Bawl.basicmsgsObj.mul, Bawl.basicmsgsObj[mw.config.get('wgUserLanguage')]);
} else {
Bawl.basicmsgs = Object.assign(Bawl.basicmsgsObj.mul, Bawl.basicmsgsObj.en); //just in case everything goes to shit
}
} );
}
Bawl.summaryCredit = ' ([[w:en:User:Alexis Jazz/Bawl|Bawl!]])';
Bawl.summaryCreditDE = ' ([[w:de:Benutzer:Alexis Jazz/Bawl|Bawl!]])';
Bawl.wikiMsgsObj.mul = { //multilingual and default texts. Messages that end up in wikitext or edit summaries. Selected using wgPageContentLanguage
'difflinkname':' (diff $7)',
'difflinknameprevnext':' (diff ~$8)',
'pageHistoryLinkName':'$4 (page history)',
'postCommentSummaryPost':'replying to USER' + Bawl.summaryCredit,
'postSubsectionSummaryPost':'new subsection: [[#SUBSECTION|SUBSECTION]]' + Bawl.summaryCredit,
'postCommentSummaryNewSection':'[[#NEWSECTION|→NEWSECTION]]: new sectionSUMMARY' + Bawl.summaryCredit,
'editCommentSummary':'editing comment' + Bawl.summaryCredit,
'savePrefsSummary':'Saving preferences' + Bawl.summaryCredit,
'deletePrefsSummary':'Clearing preferences' + Bawl.summaryCredit,
};
Bawl.wikiMsgsObj.nl = {
'difflinkname':' (diff $7)',
'difflinknameprevnext':' (diff ~$8)',
'pageHistoryLinkName':'$4 (paginageschiedenis)',
'postCommentSummaryPost':'reactie op USER' + Bawl.summaryCredit,
'postSubsectionSummaryPost':'nieuwe subsectie: [[#SUBSECTION|SUBSECTION]]' + Bawl.summaryCredit,
'postCommentSummaryNewSection':'[[#NEWSECTION|→NEWSECTION]]: nieuw onderwerpSUMMARY' + Bawl.summaryCredit,
'editCommentSummary':'wijzig reactie' + Bawl.summaryCredit,
'savePrefsSummary':'Voorkeuren opslaan' + Bawl.summaryCredit,
'deletePrefsSummary':'Voorkeuren wissen' + Bawl.summaryCredit,
};
Bawl.wikiMsgsObj.de = {
'difflinkname':' (diff $7)',
'difflinknameprevnext':' (diff ~$8)',
'pageHistoryLinkName':'$4 (Versionsgeschichte)',
'postCommentSummaryPost':'Antwort an USER ([[w:en:User:Alexis Jazz/Bawl|Bawl!]])' + Bawl.summaryCreditDE,
'postSubsectionSummaryPost':'neuen Teilabschnitt: [[#SUBSECTION|SUBSECTION]]' + Bawl.summaryCreditDE,
'postCommentSummaryNewSection':'[[#NEWSECTION|→NEWSECTION]]: neuen AbschnittSUMMARY' + Bawl.summaryCreditDE,
'editCommentSummary':'Kommentar bearbeiten' + Bawl.summaryCreditDE,
'savePrefsSummary':'Einstellungen speichern' + Bawl.summaryCreditDE,
'deletePrefsSummary':'Einstellungen löschen' + Bawl.summaryCreditDE,
};
if ( typeof BawlWikiMsgsObj != 'undefined' && BawlWikiMsgsObj[ mw.config.get('wgPageContentLanguage') ] ) { // BawlwikiMsgsObj could be specified in common.js before Bawl is loaded
Bawl.wikiMsgs = Object.assign(Bawl.wikiMsgsObj.mul, BawlWikiMsgsObj[ mw.config.get('wgPageContentLanguage') ]);
} else if ( Bawl.wikiMsgsObj[ mw.config.get('wgPageContentLanguage') ] ) {
Bawl.wikiMsgs = Object.assign(Bawl.wikiMsgsObj.mul, Bawl.wikiMsgsObj[ mw.config.get('wgPageContentLanguage') ]);
} else {
Bawl.wikiMsgs = Bawl.wikiMsgsObj.mul;
}
if ( typeof BawlmsgsObj != 'undefined' && BawlmsgsObj[ mw.config.get('wgUserLanguage') ] ) { // BawlmsgsObj could be specified in common.js before Bawl is loaded
Bawl.msgs = Object.assign(Bawl.msgsObj.mul, BawlmsgsObj[ mw.config.get('wgUserLanguage') ]);
} else if ( window.localStorage['BawlLang'+mw.config.get('wgUserLanguage')] && JSON.parse(window.localStorage['BawlLang'+mw.config.get('wgUserLanguage')]) && JSON.parse(window.localStorage['BawlLang'+mw.config.get('wgUserLanguage')]).date == Bawl.versionDate && JSON.parse(window.localStorage['BawlLang'+mw.config.get('wgUserLanguage')]).lang == mw.config.get('wgUserLanguage') ) {
Bawl.msgs = Object.assign(Bawl.msgsObj.mul, JSON.parse(window.localStorage['BawlLang'+mw.config.get('wgUserLanguage')]) );
} else {
Bawl.msgs = Bawl.msgsObj.mul;
}
if ( ['smurf', 'tlh'].indexOf(mw.config.get('wgUserLanguage')) != -1 ) {
mw.loader.getScript('https://en.wikipedia.org/enwiki/w/index.php?title=User:Alexis_Jazz/Bawl-lang.js&action=raw&ctype=text/javascript');
}
//default wiki config
Bawl.pingText = '[[' + mw.config.get('wgFormattedNamespaces')[2] + ':USERNAME|]], ';
Bawl.pingTextAnon = '[[' + mw.config.get('wgFormattedNamespaces')[-1] + ':Contributions/USERNAME|USERNAME]], ';
Bawl.commentTextIndentWikiDefault = '*';
Bawl.defaultSectionHeader = '==';
Bawl.newLineTemplate = '<br />';
Bawl.monthNames = mw.config.get('wgMonthNames'); // months as found in signatures
Bawl.timestampFormat = '$6$7$8:$9$10$11'; //just the time without date as date is unpredictable, could cause problems if there are multiple comments at the same time by the same user on the same page, recommended to configure for your wiki. Use "MONTHNAME" to insert the name of the month. Processed by /(0?)([1-3]?)([0-9])\/([0-1][0-9])\/([0-9]{4}), (0?)([1-2]?)([0-9])\:(0?)([0-9]?)([0-9])/
Bawl.endOfCommentLocator = '{{subst:#ifexist:Template:BawlCmt|{{BawlCmt|USERTIME|INNERCONTENT}}|<span id="USERTIME" class="BawlCmt">INNERCONTENT</span>}}';
if ( mw.config.get('wgDBname') == 'enwiki' ) { //overwrite config where needed
Bawl.wikiTimezone = 'UTC'; //used with new Date().toLocaleString("en-GB", {timeZone: Bawl.wikiTimezone});, toLocaleString takes care of DST so CET/CEST is just CET
Bawl.pingText = '{{u|USERNAME}}, ';
Bawl.newLineTemplate = '{{Break}}';
Bawl.timestampFormat = '$6$7$8:$9$10$11, $2$3 MONTHNAME $5';
} else if ( mw.config.get('wgDBname') == 'dewiki' ) {
Bawl.monthNames = { 1: 'Jan.', 2: 'Feb.', 3: 'Mär.', 4: 'Apr.', 5: 'Mai', 6: 'Jun.', 7: 'Jul.', 8: 'Aug.', 9: 'Sep.', 10: 'Okt.', 11: 'Nov.', 12: 'Dez.' };
Bawl.timestampFormat = '$6$7$8:$9$10$11, $2$3. MONTHNAME $5';
Bawl.wikiTimezone = 'CET';
} else if ( mw.config.get('wgDBname') == 'nlwiktionary' || mw.config.get('wgDBname') == 'nlwiki' ) {
Bawl.commentTextIndentWikiDefault = ':';
Bawl.monthNames = { 1: 'jan', 2: 'feb', 3: 'mrt', 4: 'apr', 5: 'mei', 6: 'jun', 7: 'jul', 8: 'aug', 9: 'sep', 10: 'okt', 11: 'nov', 12: 'dec' };
Bawl.timestampFormat = '$2$3 MONTHNAME $5 $6$7$8:$9$10$11';
Bawl.wikiTimezone = 'CET';
} else if ( [ 'thwikibooks', 'thwiki', 'thwikisource', 'thwiktionary', 'thwikiquote' ].indexOf(mw.config.get('wgDBname')) != -1 ) {
Bawl.wikiTimezone = 'Asia/Bangkok';
Bawl.timestampFormat = '$6$7$8:$9$10$11, $2$3 MONTHNAME'; //Thai solar calendar. Who needs to know what year it is anyway
}
Bawl.languagesAvailableInExternalFile = ['nl','de']; //array of full translations available in Bawl-lang.js
Bawl.pageLoadTimestamp = new Date().toISOString(); //to detect new comments since loading the page
mw.loader.using( [ 'oojs-ui', 'oojs-ui.styles.icons-interactions' ] ).then( function () {
Bawl.editConflictRetries = 10;
Bawl.defaultSettings = { //default settings
'UILabelInterface':'LABEL',
'tosNag': true,
'afterPost':'parsecomment', //currently reload, link or parsecomment
'nSecLink': true,
'replySecLink': false,
'secLinks': false,
'inputBoxTO': true,
'enableEverywhere': false,
'editLinks': true,
'editNotice': false,
'dateLinksIcon': false,
'dateLinks': false,
'dateLinksLocalTime': false,
'wrongUI': false,
'livePreview': false,
'saveDraft': true,
'checkNewComments' : true,
'limitWidth': false,
'RLmasq': false,
'warnExit': true,
'UIfontSize':'small',
'UILabelEditing':'LABEL',
'autoPing': true,
'markup': true,
'enableCI': true,
'enableCIThatRun': true,
'cI': {}, //examples: /youtu\.be(.)/youtube.com$1watch\?/, '''Keep''', {{AIV|chk}}, {{subst:AfC invite}}
'cIThatRun': {}, //custom inserts that get automatically executed.
'rewritun': true,
'markdown': false,
'bbcode': false,
'useLocator': true,
'sumSnippet': true,
'pingText': Bawl.pingText,
'UILabelAdvanced':'LABEL',
'watchlist':'watch',
'watchlistexpiry':'90 days',
'hideThePain': true,
'debug': false,
'saveTo':'commonjs',
};
Bawl.settings = $.extend( true, {}, Bawl.defaultSettings ); // copy as = only creates a shortcut
//ensure a concistent look, icons are own work
Bawl.svgBawlIconData = 'data:image/svg+xml,' + encodeURIComponent('<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="720px" height="720px" viewBox="0 0 720 720"><defs><mask id="cut"><rect fill="#FFF" x="0" y="0" width="720" height="720"/><ellipse fill="#000" cx="870" cy="370" rx="300" ry="400"/></mask></defs><ellipse fill="#8af" cx="700" cy="420" rx="450" ry="280" mask="url(#cut)"/><ellipse fill="#8af" cx="360" cy="310" rx="340" ry="280"/></svg>');
Bawl.svgBawlIcon = '<img style="height:1em" src="' + Bawl.svgBawlIconData + '">';
Bawl.svgBawlIconNewSectionData = 'data:image/svg+xml,' + encodeURIComponent('<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="1080px" height="720px" viewBox="0 0 1080 720"><defs><mask id="cut"><rect fill="#FFF" x="0" y="0" width="720" height="720"/><ellipse fill="#000" cx="870" cy="370" rx="300" ry="400"/></mask></defs><ellipse fill="#8af" cx="700" cy="420" rx="450" ry="280" mask="url(#cut)"/><ellipse fill="#8af" cx="360" cy="310" rx="340" ry="280"/><rect fill="#000" x="820" y="0" width="60" height="320"/><rect fill="#000" x="680" y="130" width="320" height="60"/></svg>');
Bawl.svgBawlIconNewSection = '<img style="height:1em" src="' + Bawl.svgBawlIconNewSectionData + '">';
Bawl.svgBawlIconEditData = 'data:image/svg+xml,' + encodeURIComponent('<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="720px" height="720px" viewBox="0 0 720 720"><g transform="rotate(40)"><g transform="translate(530 200) scale(1 1.5) rotate(45)"><rect fill="#8bf" x="0" y="0" width="127" height="127"/></g><rect fill="#8af" x="440" y="-365" width="180" height="700"/><rect fill="#79e" x="460" y="-230" width="40" height="520"/><rect fill="#67e" x="440" y="-365" width="180" height="100"/></g></svg>');
Bawl.svgBawlIconEdit = '<img style="height:1em" src="' + Bawl.svgBawlIconEditData + '">';
Bawl.tosNagContainer = document.createElement('div');
Bawl.tosNagContainer.id = 'BawltosNagContainer';
if ( mw.config.get('wgServer').match(/beta\.wmflabs/) ) { Bawl.metawikiAPI = 'https://meta.wikimedia.beta.wmflabs.org/enwiki/w/api.php' } else { Bawl.metawikiAPI = 'https://meta.wikimedia.org/enwiki/w/api.php' }
Bawl.dbg = function(errortext) {
if ( Bawl.settings.debug == true ) {
if ( typeof errortext == "string" || typeof errortext == "number" ) {
console.log('Bawl: ' + errortext);
} else {
console.log(errortext);
}
}
};
Bawl.loadSettings = function() {
if ( window.BawlGlobalPrefs ) { //first try to load preferences from global.js
Bawl.dbg('settings loaded from global.js');
}
if ( window.BawlPrefs ) { //no matter if we got any, overwrite with settings from common.js if there are any
Bawl.dbg('settings loaded from common.js');
}
if ( window.localStorage.Bawl && window.localStorage.Bawl.match(/^\{/) ) { //and finally overwrite with the settings from a cookie if present
Bawl.dbg('load settings from localStorage');
Bawl.browserSettings = JSON.parse(window.localStorage.Bawl);
Bawl.settings = Object.assign(Bawl.settings, Bawl.browserSettings);
} else if ( window.BawlPrefs && typeof window.BawlPrefs == 'object' ) {
Bawl.settings = Object.assign(Bawl.settings, window.BawlPrefs);
} else if ( window.BawlGlobalPrefs && typeof window.BawlGlobalPrefs == 'object' ) {
Bawl.settings = Object.assign(Bawl.settings, window.BawlGlobalPrefs);
}
};
Bawl.loadSettings();
if ( Bawl.wikiTimezone ) { //timezone was in wikiconfig above
Bawl.wikiTimezone = Bawl.wikiTimezone;
} else if ( typeof BawlTZ == 'string' ) { //timezone specified in common.js or something. allows overriding localStorage, useful if a wiki changes timezone
Bawl.wikiTimezone = BawlTZ;
} else if ( window.localStorage.BawlTZ && JSON.parse(window.localStorage.BawlTZ).version == Bawl.versionDate ) {
Bawl.wikiTimezone = JSON.parse(window.localStorage.BawlTZ).timezone;
Bawl.settings.wikiTZ = JSON.parse(window.localStorage.BawlTZ).timezone;
} else if ( Bawl.settings.wikiTZ ) {
Bawl.wikiTimezone = Bawl.settings.wikiTZ;
} else {
Bawl.dbg('get wiki timezone from API');
api.get( {
format: 'json', action: 'query', meta: 'siteinfo', siprop: 'general'
} ).done( function ( data ) {
Bawl.TZObj = JSON.stringify({'version':Bawl.versionDate,'timezone':data.query.general.timezone});
window.localStorage.setItem('BawlTZ', Bawl.TZObj);
Bawl.settings.wikiTZ = data.query.general.timezone;
Bawl.wikiTimezone = data.query.general.timezone;
} );
}
Bawl.reloadForm = function() {
Bawl.loadSettings();
Bawl.cancelReply(); //clear form entirely
Bawl.openReplyForm(Bawl.replyLinkParamsOpened); //force reloading everything
window.BawlUITextInput.scrollIntoView();
};
Bawl.disableForm = function(setdisableform) {
Bawl.UITextInputTitle.setReadOnly(setdisableform);
Bawl.UITextInput.setReadOnly(setdisableform);
Bawl.UIReplyButton.setDisabled(setdisableform);
Bawl.UIPreviewButton.setDisabled(setdisableform);
Bawl.UICancelButton.setDisabled(setdisableform);
Bawl.UISettingsButton.setDisabled(setdisableform);
if ( Bawl.saveSettingsButton ) {
Bawl.saveSettingsButton.setDisabled(setdisableform);
Bawl.resetPreferencesButton.setDisabled(setdisableform);
Bawl.cancelSettingsButton.setDisabled(setdisableform);
}
};
Bawl.getWikitextFromExport = function(text) {
if ( text.match(/[^]*<text bytes[^>]*>([^]*)<\/text>[^]*/) ) {
return text.replace(/[^]*<text bytes[^>]*>([^]*)<\/text>[^]*/, '$1').replace(/\<\;/g, '<').replace(/\>\;/g, '>').replace(/\&\;/g, '&');
} else {
return '';
}
};
Bawl.extractUsernames = function(text) {
Bawl.extractUsernamesPingTextRegExp = new RegExp('(' + Bawl.escapeRegExp(Bawl.pingText).replace('USERNAME', '([^\\]\\}]*)') + '|\\[\\[User:[^\\|\\]]*|\\[\\[' + mw.config.get('wgFormattedNamespaces')[2] + ':[^\\|\\]]*|\{\{[Pp]ing\\|[^}]*|\{\{[Rr]eply to\\|[^}]*)', 'g');
Bawl.extractedUsernames = text.match(Bawl.extractUsernamesPingTextRegExp);
Bawl.extractedUsernamesClean = [];
if ( Bawl.extractedUsernames ) {
for (int = 0; int < Bawl.extractedUsernames.length; int++) {
Bawl.cleanUserPing = new RegExp('(\\[\\[:?[Uu]ser:|\\[\\[:?' + mw.config.get('wgFormattedNamespaces')[2] + ':|\{\{[Pp]ing\\||\{\{[Rr]eply to\\||\\|\\]\\])', 'g');
Bawl.extractedUsernamesClean[int] = Bawl.extractedUsernames[int].replace(Bawl.cleanUserPing, '');
}
}
return Bawl.extractedUsernamesClean;
}
Bawl.changePreferences = function(params, actionToPerform) {
if ( params.title == 'User:' + mw.config.get('wgUserName') + '/global.js' ) {
Bawl.dbg('selecting mw.ForeignApi for ' + params.title + ' on metawiki');
var apiMeta = new mw.ForeignApi( Bawl.metawikiAPI );
api = apiMeta;
Bawl.prefsVarName = 'window.BawlGlobalPrefs';
} else {
Bawl.prefsVarName = 'window.BawlPrefs';
Bawl.dbg('selecting mw.Api for ' + params.title + ' on this wiki');
}
api.get( {
action: 'query', export: 'true', format: 'json', titles: params.title,
} ).done( function ( data ) {
Bawl.dbg(data);
Bawl.newSettingsCommonJS = Bawl.prefsVarName + ' = ' + Bawl.encodedPrefs + '; //Preferences for [[w:en:User:Alexis Jazz/Bawl]]';
if ( data.query.export["*"].match(/[^]*<text bytes[^>]*>([^]*)<\/text>[^]*/) ) {
Bawl.commonJSwikitext = Bawl.getWikitextFromExport(data.query.export["*"]);
Bawl.commonJSwikitextRegExp = new RegExp('^' + Bawl.escapeRegExp(Bawl.prefsVarName) + '.*(\n?)', 'm');
if ( actionToPerform == 'delete' ) {
Bawl.newCommonJSwikitext = Bawl.commonJSwikitext.replace(Bawl.commonJSwikitextRegExp, '');
Bawl.dbg('removing ' + Bawl.prefsVarName + ' from ' + params.title );
} else if ( Bawl.commonJSwikitext.match(Bawl.commonJSwikitextRegExp) ) {
Bawl.newCommonJSwikitext = Bawl.commonJSwikitext.replace(Bawl.commonJSwikitextRegExp, Bawl.newSettingsCommonJS + '$1');
Bawl.dbg('updating existing ' + Bawl.prefsVarName + ' in ' + params.title);
} else if ( Bawl.commonJSwikitext.match(/.*Bawl\.js.*/) ) {
Bawl.newCommonJSwikitext = Bawl.commonJSwikitext.replace(/(.*Bawl\.js.*)/, Bawl.newSettingsCommonJS + '\n$1');
Bawl.dbg('prepending ' + Bawl.prefsVarName + ' before Bawl.js line in ' + params.title);
} else {
Bawl.newCommonJSwikitext = Bawl.commonJSwikitext + '\n' + Bawl.newSettingsCommonJS;
Bawl.dbg('appending ' + Bawl.prefsVarName + ' to ' + params.title);
}
} else if ( data.query.export["*"] ) { //common.js no exist but we did get a response from our export request
Bawl.dbg(Bawl.prefsVarName + ' no exist');
Bawl.newCommonJSwikitext = Bawl.newSettingsCommonJS;
}
if ( typeof Bawl.newCommonJSwikitext == 'string' ) { //always true, but aditional error handling may be added later
if ( actionToPerform == 'delete' ) {
Bawl.prefsSummary = Bawl.wikiMsgs.deletePrefsSummary;
} else {
Bawl.prefsSummary = Bawl.wikiMsgs.savePrefsSummary;
}
api.postWithEditToken( {
format: 'json', title: params.title, action: 'edit', summary: Bawl.prefsSummary, text: Bawl.newCommonJSwikitext,
} ).done( function ( data ) {
Bawl.dbg( data );
if ( data.edit && data.edit.result == 'Success' ) {
if ( actionToPerform == 'delete' ) {
Bawl.dbg('cleared prefences to ' + Bawl.prefsVarName + ' successfully');
} else {
Bawl.dbg('saved prefences to ' + Bawl.prefsVarName + ' successfully');
}
Bawl.reloadForm();
}
} );
} //end Bawl.newCommonJSwikitext
} ); //end data function
};
Bawl.saveSettings = function() {
Bawl.disableForm(true); //disable buttons so you can't double click
$(document.getElementById('saveSettingsButton')).addClass('BawlPendingBlink');
Bawl.dbg('Saving settings..');
Bawl.prefCount = Object.keys(Bawl.defaultSettings).length;
for (prefint = 0; prefint < Bawl.prefCount; prefint++) {
Bawl.processKey = Object.keys(Bawl.defaultSettings)[prefint];
Bawl.dbg('process element for saving ' + (prefint + 1) + '/' + Bawl.prefCount + ': ' + Bawl.processKey);
if ( Bawl.settingElement[ Bawl.processKey ] && typeof Bawl.settingElement[ Bawl.processKey ].isSelected == 'function' ) {
Bawl.settings[ Bawl.processKey ] = Bawl.settingElement[ Bawl.processKey ].isSelected();
} else if ( Bawl.settingElement[ Bawl.processKey ] && typeof Bawl.settingElement[ Bawl.processKey ].getValue == 'function' ) {
Bawl.settings[ Bawl.processKey ] = Bawl.settingElement[ Bawl.processKey ].getValue();
}
}
if ( Bawl.settings.enableEverywhere == true ) { //loader can't use settings to determine if Bawl should load
window.localStorage.setItem('BawlenableEverywhere', 'true');
} else {
window.localStorage.removeItem('BawlenableEverywhere');
}
for (int = 0; int < 30; int++) {
if ( Bawl.customInsertTextInput[int].getValue() != '' ) {
Bawl.settings.cI[int] = Bawl.customInsertTextInput[int].getValue();
} else {
delete Bawl.settings.cI[int];
}
if ( Bawl.customInsertThatRunTextInput[int].getValue() != '' ) {
Bawl.settings.cIThatRun[int] = Bawl.customInsertThatRunTextInput[int].getValue();
} else {
delete Bawl.settings.cIThatRun[int];
}
}
if ( window.BawlGlobalPrefs ) { window.BawlGlobalPrefs = Bawl.settingsToSave } //refreshing this would otherwise require a page reload
if ( window.BawlPrefs ) { window.BawlPrefs = Bawl.settingsToSave }
Bawl.prefCount = Object.keys(Bawl.defaultSettings).length;
Bawl.settingsToSave = $.extend( true, {}, Bawl.settings );
Bawl.dbg('compacting preferences');
for (prefint = 0; prefint < Bawl.prefCount; prefint++) { //compacting settings by removing values that match defaults
Bawl.processKey = Object.keys(Bawl.defaultSettings)[prefint];
Bawl.dbg('checking ' + prefint + '/' + Bawl.prefCount + ': ' + Bawl.processKey);
if ( ( typeof Bawl.settingsToSave[Bawl.processKey] == "boolean" || typeof Bawl.settingsToSave[Bawl.processKey] == "string" ) && Bawl.settingsToSave[Bawl.processKey] == Bawl.defaultSettings[Bawl.processKey] ) {
Bawl.dbg('removing ' + Bawl.processKey + ' from settings to save, same as default');
delete Bawl.settingsToSave[Bawl.processKey];
} else {
Bawl.dbg(Bawl.processKey + ': ' + Bawl.settingsToSave[Bawl.processKey] + ' does not match ' + Bawl.defaultSettings[Bawl.processKey]);
}
}
Bawl.dbg('finished compacting preferences');
if ( Bawl.settings.saveTo == 'globaljs' ) { // timezone is project-specific and should never be saved to the global account
delete Bawl.settingsToSave.wikiTZ;
}
Bawl.encodedPrefs = JSON.stringify(Bawl.settingsToSave); //store object as a base64 encoded JSON. encodeURIComponent because btoa only supports Latin1
if ( Bawl.settings.saveTo == 'browser' ) {
Bawl.dbg('saving settings to localStorage');
window.localStorage.setItem('Bawl', Bawl.encodedPrefs)
Bawl.reloadForm();
} else if ( Bawl.settings.saveTo == 'commonjs' ) {
Bawl.dbg('saving settings to common.js, getting current common.js');
Bawl.resetPreferences('browser'); //removing localStorage so that won't override common.js
Bawl.changePreferencesParams = { 'title':'User:' + mw.config.get('wgUserName') + '/common.js' };
Bawl.changePreferences(Bawl.changePreferencesParams);
} else if ( Bawl.settings.saveTo == 'globaljs' ) {
Bawl.resetPreferences('browser'); //removing localStorage so that won't override global.js
Bawl.resetPreferences('commonjs'); //removing settings from common.js so they won't override global.js
Bawl.dbg('saving settings to global.js on metawiki, getting current global.js');
Bawl.changePreferencesParams = { 'title':'User:' + mw.config.get('wgUserName') + '/global.js' }; // Bawl.changePreferences automatically switches to metawiki based on page title
Bawl.changePreferences(Bawl.changePreferencesParams);
} // end globaljs
};
Bawl.resetPreferences = function(preftype) {
if ( ! preftype ) { // the reset/delete preferences button was pressed
Bawl.disableForm(true);
$(document.getElementById('resetPreferencesButton')).addClass('BawlPendingBlink');
}
if ( (preftype && preftype == 'browser') || ( ! preftype && Bawl.settingElement.saveTo.getValue() == 'browser' )) {
window.localStorage.removeItem('Bawl');
window.localStorage.removeItem('BawlBasicLang'+mw.config.get('wgUserLanguage'));
window.localStorage.removeItem('BawlLang'+mw.config.get('wgUserLanguage'));
window.localStorage.removeItem('BawlToSnagText');
window.localStorage.removeItem('BawlenableEverywhere');
window.localStorage.removeItem('BawlTZ');
Bawl.dbg('bye localStorage items');
if ( ! preftype ) {
Bawl.reloadForm();
}
} else if ( (preftype && preftype == 'commonjs') || ( ! preftype && Bawl.settingElement.saveTo.getValue() == 'commonjs' )) {
Bawl.dbg('removing settings from common.js');
Bawl.changePreferencesParams = { 'title':'User:' + mw.config.get('wgUserName') + '/common.js' };
Bawl.changePreferences(Bawl.changePreferencesParams, 'delete');
} else if ( (preftype && preftype == 'globaljs') || ( ! preftype && Bawl.settingElement.saveTo.getValue() == 'globaljs' )) {
Bawl.dbg('removing settings from global.js');
Bawl.changePreferencesParams = { 'title':'User:' + mw.config.get('wgUserName') + '/global.js' };
Bawl.changePreferences(Bawl.changePreferencesParams, 'delete');
}
};
Bawl.addScrewedLink = function(errorDescription) {
$('#BawlReplyForm').prepend('<b>Looks like Alexis Jazz screwed up. (' + errorDescription + ') <a href="https://en.wikipedia.org/enwiki/w/index.php?title=User_talk:Alexis_Jazz/Bawl&action=edit§ion=new&preloadtitle=You%20messed%20up!%20(' + encodeURIComponent(errorDescription) + ')&preload=User_talk:Alexis%20Jazz/Bawl/preload">Go bawl at \'em here.</a><br/>');
};
Bawl.insertToSnag = function() {
if ( window.localStorage.BawlToSnagText && JSON.parse(window.localStorage.BawlToSnagText).version == Bawl.versionDate ) {
$('#BawltosNagContainer').append(JSON.parse(window.localStorage.BawlToSnagText).text);
} else {
api.get( {
format: 'json', action: 'parse', text: '{{MediaWiki:Copyrightwarning}}' //MediaWiki:Wikimedia-copyrightwarning is the warning for Wikimedia sites in general and incorrect on projects with a different license like Wikinews. If dewiki wants their regular tosnag they'll have to transclude MediaWiki:Wikimedia-copyrightwarning from MediaWiki:Copyrightwarning
} ).done( function ( data ) {
Bawl.ToSnagText = data.parse.text['*'].replace('$2', Bawl.ToSlicenselinks).replace('$1', Bawl.ToSmoreInfoLink).replace(/[\s]*<!\-\-[\s]*\nNewPP[^]*/g,'') + '</div>';
Bawl.ToSnagTextObj = JSON.stringify({'version':Bawl.versionDate,'text':Bawl.ToSnagText});
window.localStorage.setItem('BawlToSnagText', Bawl.ToSnagTextObj);
$('#BawltosNagContainer').append(JSON.parse(window.localStorage.BawlToSnagText).text);
} );
}
};
Bawl.toggleTosNag = function() {
if ( ! document.getElementById('BawlToSNag') && Bawl.settingElement.tosNag.isSelected() ) {
Bawl.insertToSnag();
} else if ( Bawl.settingElement.tosNag.isSelected() == true ) {
$('#BawlToSNag').removeClass('BawlNoDisplay');
} else if ( Bawl.settingElement.tosNag.isSelected() == false ){
$('#BawlToSNag').addClass('BawlNoDisplay');
}
};
mw.util.addCSS('.BawlReplyButton { font-size:0.5em; font }\
.BawlReplyLink:hover { text-decoration:none;background-color:#EEEEFF; }\
.BawlReplyLink:active { text-decoration:none;background-color:#EEEEFF; }\
.BawlReplyLinkIcon { margin-left:0.6em; margin-right:0.6em}\
.BawlNoDisplay { display:none !important }\
.BawlYesDisplay { display:inline !important }\
.BawlMarginHalfEm { margin-bottom: 0.5em; }\
.BawlMarginHalfEmTop { margin-top:0.5em; }\
.BawlPreviewBox { background:#FAFAFA;padding:0.1em 1em 0.1em 1em;border:thin dashed gray; }\
.BawlFloatRight { float:right; }\
.BawlForm { padding:0.5em 0.5em 0em 0.5em;margin:0em 0em 0em 1.5em;font-size:' + Bawl.settings.UIfontSize + ';font-family:sans-serif; font-weight:normal;min-width:50em; }\
.BawlLimitWidth { max-width:50em; }\
.BawlUnsetLimitWidth { max-width:unset !important; }\
.BawlSettings { background:#FEFEFF;padding:0.1em 0.5em 0.1em 0.5em;border:thin solid lightgray; }\
.BawlDropDownMenu { max-width:30em; }\
.BawlOOuiFieldLayout { margin-top:0.5em !important; margin-bottom:0.75em; }\
.BawlOOuiFieldLayout::after { clear:none; }\
.BawlShakeIt { animation: shake 0.12s; animation-iteration-count: 3;} @keyframes shake { 0% { margin:-0.1em 0em 0.6em 0em; } 9% { margin:-0.2em 0em 0.7em 0em; } 18% { margin:-0.3em 0em 0.8em 0em; } 27% { margin:-0.2em 0em 0.7em 0em; } 36% { margin:-0.1em 0em 0.6em 0em; } 45% { margin:0em 0em 0.5em 0em; } 54% { margin:0.1em 0em 0.4em 0em; } 63% { margin:0.2em 0em 0.3em 0em; } 72% { margin:0.3em 0em 0.2em 0em; } 81% { margin:0.2em 0em 0.3em 0em; } 90% { margin:0.1em 0em 0.4em 0em; } 100% { margin:0em 0em 0.5em 0em; } }\
.BawlSmallerText { font-size: 70%; }\
.BawlSettingsSectionLabel { font-size: bigger; font-weight: bold; }\
.BawlEditNoticeDiv { max-height:12em; overflow:auto; }\
@keyframes BawlBlinker { 50% { opacity: 0.5; } }\
.BawlPendingBlink { animation: BawlBlinker 1s linear infinite; }\
.BawlLeftRightMargin { margin-left: 0.5em; margin-right: 0.5em; }\
.BawlMarkupBold { font-weight: bold; }\
.BawlMarkupItalic { font-weight: normal; font-style: italic; }\
.BawlPreviewAfterPost { margin-left: 0.5em; font-family:sans-serif; font-weight: normal;}\
.BawlAnonSectReply { font-size:medium;font-weight:normal;line-height:1.3;text-align:center;border:thin solid #ccc;padding:0.2em 3em 0.2em 3em;background:aliceblue; }\
.BawlNoMaxWidth { max-width:none; }');
Bawl.replyLink = {};
Bawl.formDataset = {};
Bawl.pageRevisionSinceLastCheck = {};
Bawl.apiUrl = mw.util.wikiScript( 'api' );
Bawl.doAPICall = function( params, situation, callback ) {
api.postWithEditToken( params ).done( function ( apiResponse ) {
if (params.action == 'parse' && situation == 'previewposted' ) {
Bawl.dbg('Got parsed comment:' + apiResponse.parse.text);
if ( ! Bawl.PreviewAfterPostID ) {
Bawl.PreviewAfterPostID = '';
}
if ( document.getElementById(Bawl.PreviousPreviewAfterPostID) ) { // This code is no longer reachable because type=edit will always reload (or link), never parse. Technically updates to comments that were just posted could be parsed in-place, but replacing individual comments in-place wouldn't work outside of that because MediaWiki doesn't wrap individual comments in their own container, well not in a practical way anyway.
Bawl.dbg('replacing existing parsed comment');
document.getElementById(Bawl.PreviousPreviewAfterPostID).outerHTML = '<div class="BawlPreviewAfterPost" id="' + Bawl.PreviousPreviewAfterPostID + '">' + apiResponse.parse.text.replace(/(<\/span>)(\n<\/p>\n<!-- \nNewPP)/m, '$1<span id="Bawlpreviewlinks"><a href="' + Bawl.newCommentID + '" class="BawlReplyLink"> 🔗 </a></div>$2') + '</span></div>';
} else { // this is reachable though
Bawl.postedCommentParsed = apiResponse.parse.text;
}
if ( Bawl.postCommentSuccess == true ) { //if the parsing takes longer than the actual posting (unlikely) we'll insert it here. otherwise below
Bawl.dbg('preview parsing took longer than editing (this is rare), insert parsed preview with HTML element ID ' + Bawl.PreviewAfterPostID);
$('#thanksForUsing')[0].outerHTML = '<div class="BawlPreviewAfterPost" id="' + Bawl.PreviewAfterPostID + '">' + Bawl.postedCommentParsed.replace(/(<\/span>)(\n<\/p>\n<!-- \nNewPP)/m, '$1<span id="Bawlpreviewlinks"><a href="' + Bawl.newCommentID + '" class="BawlReplyLink"> 🔗 </a></div>$2') + '</span></div>';
Bawl.dbg('add edit link to posted comment with ID ' + Bawl.previewPostedParams.id);
Bawl.addReplyLinkTo(Bawl.previewPostedParams); //adds edit link
}
} else if (params.action == 'parse' && situation == 'preview' ) {
Bawl.dbg('Loading preview');
$(document.getElementsByClassName('BawlPreviewBox'))[0].innerHTML = apiResponse.parse.text;
} else if (params.action == 'parse' && situation == 'editnotice' ) {
Bawl.dbg('Loading editnotice');
$('#BawlEditNotice').append(apiResponse.parse.text);
} else if ( ( apiResponse.error && apiResponse.error.code == 'editconflict' ) || ( apiResponse.edit.result == 'Success' && ! apiResponse.edit.newtimestamp ) ) { //that nonsense second condition is a workaround for https://phabricator.wikimedia.org/T299809
Bawl.editConflictRetries = Bawl.editConflictRetries - 1;
if ( apiResponse.edit.result == 'Success' && ! apiResponse.edit.newtimestamp && Bawl.editConflictRetries > 0 ) { //damage control in case there is a legit situation that triggers this
Bawl.editConflictRetries = 1;
}
Bawl.dbg('encountered edit conflict. ' + Bawl.editConflictRetries + ' tries left.');
if ( Bawl.editConflictRetries >= 1 ) {
Bawl.postReply1(Bawl.replyLinkParamsOpened);
} else {
Bawl.dbg('giving up');
}
} else if (params.action == 'edit' && apiResponse.edit.result == 'Success' ) { //edit made successfully
Bawl.postedCommentType = encodeURIComponent(Bawl.replyLinkParamsOpened.type.replace(/ /g, '_'));
if ( Bawl.replyLinkParamsOpened.subtype ) {
Bawl.postedCommentSubType = encodeURIComponent(Bawl.replyLinkParamsOpened.subtype.replace(/ /g, '_'));
} else {
delete Bawl.postedCommentSubType;
}
Bawl.repliedToCommentID = Bawl.replyLinkParamsOpened.id;
if ( Bawl.postedCommentType == 'comment' || Bawl.postedCommentSubType == 'BCL' ) {
Bawl.newCommentTimestamp = apiResponse.edit.newtimestamp.replace(/([0-9\-T\:]{17})[0-9][0-9]/, '$100.000');
Bawl.newCommentID = '#c-' + encodeURIComponent(mw.config.get('wgUserName').replace(/ /g, '_')) + '-' + encodeURIComponent(apiResponse.edit.newtimestamp.replace(/([0-9\-T\:]{17})[0-9][0-9]/, '$100.000')) + '-' + encodeURIComponent(Bawl.replyLinkParamsOpened.origReplyTo.replace(/ /g, '_')) + '-' + encodeURIComponent(Bawl.replyLinkParamsOpened.origTimestamp);
} else if ( Bawl.postedCommentType == 'heading' ) { //likely wrong
Bawl.newCommentID = '#c-' + encodeURIComponent(mw.config.get('wgUserName').replace(/ /g, '_')) + '-' + encodeURIComponent(apiResponse.edit.newtimestamp.replace(/([0-9\-T\:]{17})[0-9][0-9]/, '$100.000')) + '-' + encodeURIComponent(Bawl.UITextInputTitle.getValue().replace(/ /g, '_'));
} else if ( Bawl.postedCommentType == 'newsection' ) {
Bawl.newCommentID = '#' + encodeURIComponent(Bawl.UITextInputTitle.getValue().replace(/ /g, '_'));
} else if ( Bawl.postedCommentType == 'edit' && typeof Bawl.replyLinkParamsOpened.origid == 'undefined' ) {
Bawl.newCommentID = '#' + encodeURIComponent(Bawl.replyLinkParamsOpened.id);
}
Bawl.cancelReply(); //closes the reply form
document.getElementById('bawlForm-' + Bawl.repliedToCommentID).outerHTML = document.getElementById('bawlForm-' + Bawl.repliedToCommentID).outerHTML + '<span id="thanksForUsing"><a href="?' + Math.floor(Math.random()*100000) + Bawl.newCommentID + '">' + Bawl.msgs.commentDone + '</a>' + Bawl.msgs.commentPostedThankYou + '</span>'; // the ? forces page reload, # provides anchor to the comment that was commented on
if ( Bawl.settings.afterPost == 'reload' || ( Bawl.replyLinkParamsOpened.type != 'comment' && Bawl.settings.afterPost != 'link' ) ) {
window.location = Bawl.newCommentID;
var DelayedReload = setInterval(function () {
clearInterval(DelayedReload); location.reload(); //if we reload immediately we may not get served the most recent revision with our comment
}, 2000);
} else if ( Bawl.settings.afterPost == 'parsecomment' ) {
Bawl.replyLinkParamsOpenedPreview = Bawl.replyLinkParamsOpened;
Bawl.previewPostedParams = {
'preview': true,
'int': Bawl.replyLinkParamsOpenedPreview.int,
'type':'edit',
'id': Bawl.newCommentID.slice(1,),
'origid': Bawl.replyLinkParamsOpened.id,
'pageTitle': Bawl.pageTitleToEdit,
'origReplyTo': mw.config.get('wgUserName'),
'origTimestamp': Bawl.newCommentTimestamp,
'sectionTitle': Bawl.replyLinkParamsOpenedPreview.sectionTitle,
};
Bawl.PreviewAfterPostID = 'BawlPreviewAfterPost-' + Bawl.previewPostedParams.id.replace(/%/g, '');
Bawl.postCommentSuccess = true;
if ( Bawl.postedCommentParsed ) { //comment preview has already been parsed
Bawl.dbg('editing took longer than preview parsing (this is common), insert parsed preview with HTML element ID ' + Bawl.PreviewAfterPostID);
$('#thanksForUsing')[0].outerHTML = '<div class="BawlPreviewAfterPost" id="' + Bawl.PreviewAfterPostID + '">' + Bawl.postedCommentParsed.replace(/(<\/span>)(\n<\/p>\n<!-- \nNewPP)/m, '$1<span id="Bawlpreviewlinks"><a href="' + Bawl.newCommentID + '" class="BawlReplyLink"> 🔗 </a></div>$2') + '</span></div>';
Bawl.dbg('add edit link to posted comment with ID ' + Bawl.previewPostedParams.id);
Bawl.addReplyLinkTo(Bawl.previewPostedParams); //adds edit link
}
}
Bawl.UITextInput.setValue('');
Bawl.UITextInputTitle.setValue('');
}
} );
};
Bawl.escapeRegExp = function(text) {
return mw.util.escapeRegExp(text);
}
Bawl.escapeReplacement = function(text) {
return text.replace(/\$/g, '$$$$');
}
Bawl.escapeHTML = function(text) {
return text.replace(/\&/g, '&').replace(/\'/g, ''').replace(/\"/g, '"').replace(/\</g, '<').replace(/\>/g, '>');
}
Bawl.rewritunUrUrlz = function(text) {
Bawl.dbg('rewritun ur urlz');
Bawl.rewritunUrUrlz2=text;
Bawl.dbg('rewritun externalLinkRegExp');
Bawl.rewritunRegExps = {
'phabpage':'/https\\:\\/\\/phabricator\.wikimedia\.org\\/(([^\\n\\.\\,\\?\\& ]|[\\.\\,\\?\\&][^$ \\n])*)/[[:phab:$1]]/g',
'page':'/https\\:\\/\\/([a-z\-]{0,10})(\.m)?\.(wikipedia|wikimedia|mediawiki|wikidata|wikibooks|wiktionary|wikinews|wikiquote|wikisource|wikiversity|wikivoyage)\.org\\/wiki\\/(([^\\n\\.\\,\\?\\& ]|[\\.\\,\\?\\&][^$ \\n])*)/[[INTERWIKI:$1.$3:$4]]/g',
'diff':'/https\\:\\/\\/([a-z\-]{0,10})(\.m)?\.(wikipedia|wikimedia|mediawiki|wikidata|wikibooks|wiktionary|wikinews|wikiquote|wikisource|wikiversity|wikivoyage)\.org\\/w\\/index\.php\\?(title\=(([^\\n\\.\\,\\?\\& ]|[\\.\\,\\?\\&][^$ \\n])*)\\&)?diff\=([0-9]+)\\&oldid\=[0-9]*/[[INTERWIKI:$1.$3:Special:DiffSLASHCHAR$7|$5' + Bawl.wikiMsgs.difflinkname + ']]/g',
'diffprevnext':'/https\\:\\/\\/([a-z\-]{0,10})(\.m)?\.(wikipedia|wikimedia|mediawiki|wikidata|wikibooks|wiktionary|wikinews|wikiquote|wikisource|wikiversity|wikivoyage)\.org\\/w\\/index\.php\\?(title\=(([^\\n\\.\\,\\?\\& ]|[\\.\\,\\?\\&][^$ \\n])*)\\&)?diff\=(next|prev)\\&oldid\=([0-9]*)/[[INTERWIKI:$1.$3:Special:DiffSLASHCHAR$8SLASHCHAR$7|$5' + Bawl.wikiMsgs.difflinknameprevnext + ']]/g',
'spaceremoval':'/(Special\:Diff.[0-9]*)(\\/)?(prev|next)?. /$1$2$3|/g',
'redlink':'/https\\:\\/\\/([a-z\-]{0,10})(\.m)?\.(wikipedia|wikimedia|mediawiki|wikidata|wikibooks|wiktionary|wikinews|wikiquote|wikisource|wikiversity|wikivoyage)\.org\\/w\\/index\\.php\\?title=([^\\&]*)\\&action=edit\\&redlink=1/[[INTERWIKI:$1.$3:$4]]/g',
'history':'/https\\:\\/\\/([a-z\-]{0,10})(\.m)?\.(wikipedia|wikimedia|mediawiki|wikidata|wikibooks|wiktionary|wikinews|wikiquote|wikisource|wikiversity|wikivoyage)\.org\\/w\\/index\\.php\\?title=([^\\&]*)\\&action=history/[[INTERWIKI:$1.$3:Special:PageHistorySLASHCHAR$4|' + Bawl.wikiMsgs.pageHistoryLinkName + ']]/g',
'localwiki':'/\\[\\[INTERWIKI:' + Bawl.escapeRegExp(mw.config.get('wgServer').replace(/\/\/([^\/]*)\.org.*/, '$1')) + '/[[/g',
'testwiki':'/\\[\\[INTERWIKI:test\\.wikipedia/[[:testwiki/g',
'commons':'/\\[\\[INTERWIKI:commons\\.wikimedia/[[:c/g',
'meta':'/\\[\\[INTERWIKI:meta\\.wikimedia/[[:m/g',
'mediawiki':'/\\[\\[INTERWIKI:www\\.mediawiki/[[:mw/g',
'foundation':'/\\[\\[INTERWIKI:foundation\\.wikimedia/[[:foundation/g',
'species':'/\\[\\[INTERWIKI:species\\.wikimedia/[[:species/g',
'wikidata':'/\\[\\[INTERWIKI:wikidata\\.wikimedia/[[:d/g',
'wikipedia':'/\\[\\[INTERWIKI:([a-z\-]{0,10})\\.wikipedia/[[:w:$1/g',
'wikibooks':'/\\[\\[INTERWIKI:([a-z\-]{0,10})\\.wikibooks/[[:b:$1/g',
'wiktionary':'/\\[\\[INTERWIKI:([a-z\-]{0,10})\\.wiktionary/[[:wikt:$1/g',
'wikinews':'/\\[\\[INTERWIKI:([a-z\-]{0,10})\\.wikinews/[[:n:$1/g',
'wikiquote':'/\\[\\[INTERWIKI:([a-z\-]{0,10})\\.wikiquote/[[:q:$1/g',
'wikisource':'/\\[\\[INTERWIKI:([a-z\-]{0,10})\\.wikisource/[[:s:$1/g',
'wikiversity':'/\\[\\[INTERWIKI:([a-z\-]{0,10})\\.wikiversity/[[:v:$1/g',
'wikivoyage':'/\\[\\[INTERWIKI:([a-z\-]{0,10})\\.wikivoyage/[[:voy:$1/g',
}
for (int = 0; int < Object.keys(Bawl.rewritunRegExps).length; int++) {
Bawl.rewritunReg = Bawl.rewritunRegExps[Object.keys(Bawl.rewritunRegExps)[int]].replace(/^\/(.*[^\\])\/(.*[^\\])\/(.*[^\\])/, '$1');
Bawl.rewritunFlags = Bawl.rewritunRegExps[Object.keys(Bawl.rewritunRegExps)[int]].replace(/^\/(.*[^\\])\/(.*[^\\])\/(.*[^\\])/, '$3');
Bawl.rewritunReplacement = Bawl.rewritunRegExps[Object.keys(Bawl.rewritunRegExps)[int]].replace(/^\/(.*[^\\])\/(.*[^\\])\/(.*[^\\])/, '$2');
Bawl.dbg('Expression #' + int + ': ' + Bawl.rewritunReg + ', flags: ' + Bawl.rewritunFlags + ', replacement: ' + Bawl.rewritunReplacement);
Bawl.rewritunRegExp = new RegExp(Bawl.rewritunReg, Bawl.rewritunFlags);
Bawl.rewritunUrUrlz2 = Bawl.rewritunUrUrlz2.replace(Bawl.rewritunRegExp, Bawl.rewritunReplacement).replace(/SLASHCHAR/g, '/');
}
Bawl.rewritunMatchDiffs = Bawl.rewritunUrUrlz2.match(/Special:Diff\/([0-9]+)\|([^\]]*) \([^\)]*[0-9]+[^\)]*\)/g);
if ( Bawl.rewritunMatchDiffs ) {
for (int = 0; int < Bawl.rewritunMatchDiffs.length; int++) {
Bawl.rewritunUrUrlz2 = Bawl.rewritunUrUrlz2.replace(Bawl.rewritunMatchDiffs[int], decodeURIComponent(Bawl.rewritunMatchDiffs[int].replace(/_/g, ' ')));
}
}
Bawl.dbg('Rewritten urls: ' + Bawl.rewritunUrUrlz2);
Bawl.dbg('rewritun youtu.be');
Bawl.rewritunUrUrlz2 = Bawl.rewritunUrUrlz2.replace(/\/\/youtu\.be\/([^\?]*)\?\//g, '\/\/www.youtube.com\/watch\?$1&').replace(/\/\/youtu\.be\//g, '\/\/www.youtube.com\/watch\?'); //rewrite youtu.be shortened urls (these are blacklisted)
Bawl.rewritunUrUrlz3 = Bawl.rewritunUrUrlz2;
int=0;
while ( ( Bawl.rewritunUrUrlz2 != Bawl.rewritunUrUrlz3 && int < 1000 ) || int == 0 ) {
Bawl.rewritunUrUrlz2 = Bawl.rewritunUrUrlz3;
Bawl.rewritunUrUrlz3 = Bawl.rewritunUrUrlz3.replace(/\[\[([^_\]]*)_(.*\]\])/g, '[[$1 $2'); //replace underscores in internal links with spaces
int = int + 1;
Bawl.dbg('rewritun #' + int + ' (' + Bawl.rewritunUrUrlz2 + ' to ' + Bawl.rewritunUrUrlz3 + ')' );
}
Bawl.rewritunUrUrlz4 = Bawl.rewritunUrUrlz3;
Bawl.rewritunUrUrlz4RegExp = new RegExp('(\\[\\[[^\\]]*\\]\\])', 'g');
Bawl.rewritunUrUrlz4match = Bawl.rewritunUrUrlz4.match(Bawl.rewritunUrUrlz4RegExp);
if ( Bawl.rewritunUrUrlz4match ) {
for (int = 0; int < Bawl.rewritunUrUrlz4match.length; int++) {
Bawl.rewritunUrUrlz4 = Bawl.rewritunUrUrlz4.replace(Bawl.rewritunUrUrlz4match[int], decodeURIComponent(Bawl.rewritunUrUrlz4match[int]));
}
}
Bawl.UITextInput.setValue(Bawl.rewritunUrUrlz4);
return Bawl.rewritunUrUrlz4;
};
Bawl.applyMarkdown = function(text) {
Bawl.dbg('Applying Markdown markup');
return text.replace(/\*\*([^\*]*)\*\*/g, '\'\'\'$1\'\'\'').replace(/(^|\n| )_([^\_]*)_($|\n|[ \.\!\?])/g, '$1\'\'$2\'\'$3').replace(/`([^`]*)`/g, '<code>$1</code>').replace(/(^|\n)---($|\n)/, '$1<hr />$2');
//todo: lists, links, images, maybe headers
};
Bawl.applyBBCode = function(text) {
Bawl.dbg('applying BBCode');
//list of wikis with a template:Smiley
Bawl.wikiswithsmileytemplate = [ 'afwiki','alswiki','barwiki','dawiki','dewiki','enwiki','eswiki','fowiki','guwiki','jvwiki','kabwiki','kswiki','lijwiki','mywiki','nds_nlwiki','nlwiki','nowiki','orwiki','rowiki','scowiki','sdwiki','simplewiki','srwiki','svwiki','tawiki','thwiki','vecwiki','zhwiki' ,'enwikiversity' ,'dewikibooks','nlwikibooks','nowikibooks','enwikinews','eswikinews','enwikinews','nlwikinews','nowikinews','enwikiquote','nlwikiquote','enwikisource','guwikisource','enwikiversity','dewikivoyage','eswikivoyage','enwiktionary','eswiktionary','nlwiktionary','commonswiki','mediawikiwiki','metawiki','wikidatawiki' ];
if ( Bawl.wikiswithsmileytemplate.indexOf(mw.config.get('wgDBname')) != -1 ) {
text = text.replace(/(^| |\n)(:-\)|;-\)\|:-\()([^a-zA-Z0-9]|$)/g, '$1{{Smiley|$2}}$3');
}
return text.replace(/\[\/?[Bb]\]/g, '\'\'\'').replace(/\[\/?[Ii]\]/g, '\'\'').replace(/\[(\/)?[Uu]\]/g, '<$1u>').replace(/\[(\/)?[Ss]\]/g, '<$1s>').replace(/\[url\](http)?(s?)(:\/\/)?([^\/\[]*)([^\[]*)\[\/url\]/gi, '[http$2://$4$5 ' + '$4' + ']').replace(/\[url="?(http)?(s?)(:\/\/)?([^\/\[]*)([^\[]*)"?\]([^\[]*)\[\/url\]/gi, '[http$2://$4$5 ' + '$6' + ']').replace(/\[img\]([^:\[]*:)?([^\[]*)\[\/img\]/g, '[[' + mw.config.get('wgFormattedNamespaces')[6] + ':$2|thumb]]').replace(/\[(\/)?[Cc]ode\]/g, '<$1code>').replace(/\[[Ss]tyle size="?([0-9]*)"?\]([^\[]*)\[\/(style)?\]/g, '<span style="font-size: $1pt">$2</span>').replace(/\[[Ss]tyle size="?([^"\]]*)"?\]([^\[]*)\[\/(style)?\]/g, '<span style="font-size: $1">$2</span>').replace(/\[([Ss]tyle )?color="?([0-9A-Fa-z]*)"?\]([^\[]*)\[\/(style|color)?\]/g, '<span style="color: $2">$3</span>').replace(/\[\*\] ?([^\n\[]*)\s*/gm, '<li>$1</li>').replace(/\[[Ll]ist\]\s*([^]*)\[\/[Ll]ist\]/gm, '<ul>$1</ul>').replace(/\s*<\/(ul|li)>/g, '</$1>').replace(/\[[Qq](uote)?\]([^\[]*)\[\/[Qq](uote)?\]/g, '<blockquote><p>$2</p></blockquote>').replace(/\[[Qq](uote)?=?"?([^"\]]*)"?\]([^\[]*)\[\/[Qq](uote)?\]/g, '<blockquote><p>$3</p>—$2</blockquote>').replace(/\s*\[(\/)?(td|tr)\]\s*/g, '<$1$2>').replace(/\[[Tt]able\]/g, '<table class="wikitable">').replace(/\[\/[Tt]able\]/g, '</table>');
};
Bawl.runCI = function(text) {
Bawl.replacedInput = text;
Bawl.dbg('start to process automatically applied custom inserts that are regular expressions');
for (int = 0; int < 30; int++) {
if ( Bawl.settings.cIThatRun && Bawl.settings.cIThatRun[int] && Bawl.settings.cIThatRun[int] != "" ) { //non-empty insert found
Bawl.dbg('process automatically applied custom inserts that are regular expressions ' + (int + 1) + '/30');
Bawl.insertIsRegExpRegExp = new RegExp('^\/(.*)([^\])\/(.*)([^\])\/([gmi]*)$');
if ( Bawl.settings.cIThatRun[int].match(Bawl.insertIsRegExpRegExp) && Bawl.settings.cIThatRun[int].match(Bawl.insertIsRegExpRegExp).length == 6 ) {
Bawl.customInsertRegExpNowParts = Bawl.settings.cIThatRun[int].match(Bawl.insertIsRegExpRegExp);
Bawl.customInsertRegExpNow = new RegExp(Bawl.customInsertRegExpNowParts[1] + Bawl.customInsertRegExpNowParts[2], Bawl.customInsertRegExpNowParts[5]);
Bawl.replacedInput = Bawl.UITextInput.getValue().replace(Bawl.customInsertRegExpNow, Bawl.customInsertRegExpNowParts[3] + Bawl.customInsertRegExpNowParts[4]);
Bawl.UITextInput.setValue(Bawl.replacedInput);
Bawl.dbg('replaced ' + Bawl.customInsertRegExpNow + ' with ' + Bawl.customInsertRegExpNowParts[3] + Bawl.customInsertRegExpNowParts[4]);
}
}
}
return Bawl.replacedInput;
};
Bawl.convertToOneLineCmt = function(text) {
Bawl.dbg('converting comment to a single line');
Bawl.multilineText1 = ' \n \n' + text;
Bawl.multilineText2 = '';
Bawl.listInt = 0;
while ( Bawl.multilineText1 != Bawl.multilineText2 && Bawl.listInt < 1000 ) {
Bawl.listInt = Bawl.listInt + 1;
Bawl.multilineText2 = Bawl.multilineText1;
Bawl.multilineText1 = Bawl.multilineText1.replace(/(\n[^\#].*\n)(\#[ ]*)/g, '$1' + Bawl.listInt + '. ');
}
return Bawl.multilineText1.replace(/^[\s]*/, '').replace(/[\s]*$/, '').replace(/^[\*][\s]*/gm, '• ').replace( /\n/gm, Bawl.newLineTemplate );
}
Bawl.addSignature = function(text) {
if ( text.match(/NOSIGN$/) || Bawl.replyLinkParamsOpened.type == 'edit' ) {
Bawl.dbg('found NOSIGN or this is an edit which doesn\'t need to be (re-)signed, skipping signature');
return text;
} else {
Bawl.dbg('adding signature');
if ( Bawl.settings.useLocator == true ) {
Bawl.commentMilliseconds = new Date().getTime().toFixed().slice(-3,); //indeed, the local clock may differ from server time which we primarily rely on through {{subst:#time:U}}. And it's irrelevant as the milliseconds are only used to make the identifier more unique. Making two edits within the same second is already implausible but within the same millisecond? Get out. Doesn't solve the issue of non-Bawl users adding multiple comments in a single edit, but solving that would require MediaWiki to support "random" as a magic word that can produce different numbers when called multiple times within the same edit. Or have a bot that slightly adjusts timestamps to ensure they're unique.
return text + ' ' + Bawl.endOfCommentLocator.replace(/INNERCONTENT/g, '~~~~').replace(/USERTIME/g, encodeURIComponent(mw.config.get('wgUserName')) + ':{{subst:#time:U}}' + Bawl.commentMilliseconds + ':' + encodeURIComponent(Bawl.replyLinkParamsOpened.pageTitle));
} else {
return text + ' ~~~~';
}
}
};
Bawl.progressPlusOne = function(reset) {
$('#BawlProgressIndicator').append('▮'); //HTML: ▮ BLACK VERTICAL RECTANGLE
};
Bawl.cancelReply = function() {
document.getElementById('bawlForm-' + Bawl.replyLinkParamsOpened.id).innerHTML = '';
document.getElementById('bawlForm-' + Bawl.replyLinkParamsOpened.id).classList = [ 'BawlNoDisplay BawlForm' ];
};
Bawl.processComment = function(text) {
text = text.replace(/^[\s]*/, '').replace(/[\s]*$/, '');
if ( Bawl.settings.bbcode == true ) {
text = Bawl.applyBBCode(text);
}
Bawl.progressPlusOne();
if ( Bawl.settings.markdown == true ) {
text = Bawl.applyMarkdown(text);
}
Bawl.progressPlusOne();
if ( Bawl.settings.rewritun == true ) {
text = Bawl.rewritunUrUrlz(text);
}
Bawl.progressPlusOne();
if ( Bawl.settings.enableCIThatRun == true ) {
Bawl.dbg('applying your regular expressions');
text = Bawl.runCI(text);
}
Bawl.progressPlusOne();
if ( Bawl.replyLinkParamsOpened.type == 'editFullPage' ) {
return text;
} else {
text = Bawl.addSignature(text);
return Bawl.convertToOneLineCmt(text);
}
};
Bawl.doPreview = function(situation) {
Bawl.dbg('preview');
if ( situation != 'previewposted' ) {
$(document.getElementsByClassName('BawlPreviewBox')).removeClass('BawlNoDisplay');
if ( Bawl.settings.checkNewComments == true ) {
Bawl.checkForNewComments(Bawl.replyLinkParamsOpened, 'preview');
}
}
Bawl.processedComment = Bawl.processComment(Bawl.UITextInput.getValue());
if ( situation == 'previewposted' ) {
Bawl.dbg('add the last character+space from the indentation so preview renders properly with its indentation');
Bawl.processedComment = Bawl.commentTextIndent.slice(-2,) + Bawl.processedComment;
}
Bawl.previewCommentParams = {
format: 'json',
action: 'parse',
title: Bawl.replyLinkParamsOpened.pageTitle,
pst: '1',
prop: 'text',
formatversion: '2',
text: Bawl.processedComment + Bawl.repairTagImbalance(Bawl.processedComment)
};
Bawl.doAPICall(Bawl.previewCommentParams, situation);
};
Bawl.compareRevisionsToCheckForComments = function(replyLinkParams, situation) {
Bawl.dbg('compare current revision to revision since last check');
api.get( {
action: 'query', prop: 'revisions', format: 'json', titles: replyLinkParams.pageTitle, rvlimit: 1, rvprop: 'timestamp|user|comment|content', rvslots: '*',
} ).done( function ( data ) {
Bawl.dbg('page content now:');
Bawl.dbg(data);
if ( data.query && data.query.pages && data.query.pages[ Object.keys(data.query.pages)[0] ] && data.query.pages[ Object.keys(data.query.pages)[0] ].revisions && data.query.pages[ Object.keys(data.query.pages)[0] ].revisions[0] ) {
Bawl.pageRevisionCurrentText = data.query.pages[ Object.keys(data.query.pages)[0] ].revisions[0].slots.main['*'];
} else {
Bawl.pageRevisionCurrentText = '';
}
Bawl.pageRevisionCurrentText = Bawl.getInsertionPointSection(Bawl.pageRevisionCurrentText, replyLinkParams).sectiontext;
Bawl.pageRevisionSinceLastCheckText = Bawl.getInsertionPointSection(Bawl.pageRevisionSinceLastCheck[replyLinkParams.pageTitle], replyLinkParams).sectiontext;
if ( Bawl.pageRevisionCurrentText != Bawl.pageRevisionSinceLastCheckText ){
Bawl.pageRevisionCurrentSplit = Bawl.pageRevisionCurrentText.split('\n');
Bawl.pageRevisionSinceLastCheckSplit = Bawl.pageRevisionSinceLastCheckText.split('\n');
Bawl.linesSinceLastCheck = '';
for (commentCheckInt = 0; commentCheckInt < Bawl.pageRevisionCurrentSplit.length; commentCheckInt++) {
if ( Bawl.pageRevisionSinceLastCheckSplit.indexOf(Bawl.pageRevisionCurrentSplit[commentCheckInt]) == -1 ) {
Bawl.dbg('line not found in the old revision of this page: ' + Bawl.pageRevisionCurrentSplit[commentCheckInt]);
Bawl.linesSinceLastCheck = Bawl.linesSinceLastCheck + Bawl.pageRevisionCurrentSplit[commentCheckInt] + '\n';
}
}
Bawl.showNewLinesButton = new OO.ui.ButtonWidget( {
id: 'BawlshowNewLinesButton',
label: Bawl.msgs.showNewLinesButton,
flags: [ 'primary' ],
} );
Bawl.showNewLinesButton.on('click', function() {
Bawl.showNewLinesButton.setDisabled(true);
api.post( {
action: 'parse', prop: 'revisions', format: 'json', title: mw.config.get('wgPageName'), pst: '1', prop: 'text', formatversion: '2', text: Bawl.linesSinceLastCheck
} ).done( function ( data ) {
Bawl.showNewLinesButton.setDisabled(false);
$('#showNewLinesButton')[0].innerHTML = '';
$('#BawlPreviewBox')[0].innerHTML = '';
$('#BawlPreviewBox').removeClass('BawlNoDisplay');
$('#BawlPreviewBox').append(data.parse.text);
});
});
$('#showNewLinesButton').removeClass('BawlNoDisplay');
$('#showNewLinesButton').innerHTML = '';
$('#showNewLinesButton').append(Bawl.showNewLinesButton.$element);
}
if ( data.query && data.query.pages && data.query.pages[ Object.keys(data.query.pages)[0] ] && data.query.pages[ Object.keys(data.query.pages)[0] ].revisions && data.query.pages[ Object.keys(data.query.pages)[0] ].revisions[0] ) {
Bawl.pageRevisionSinceLastCheck[replyLinkParams.pageTitle] = data.query.pages[ Object.keys(data.query.pages)[0] ].revisions[0].slots.main['*'];
} else {
Bawl.pageRevisionSinceLastCheck[replyLinkParams.pageTitle] = '';
}
});
};
Bawl.checkForNewComments = function(replyLinkParams, situation) {
if ( Bawl.pageRevisionSinceLastCheck[replyLinkParams.pageTitle] ) {
Bawl.compareRevisionsToCheckForComments(replyLinkParams, situation);
} else if ( replyLinkParams.type == 'comment' ) {
api.get( {
action: 'query', prop: 'revisions', format: 'json', titles: replyLinkParams.pageTitle, rvlimit: 1, rvprop: 'timestamp|user|comment|content', rvslots: '*', rvstart: Bawl.pageLoadTimestamp,
} ).done( function ( data ) {
Bawl.dbg('page content as it was when loading the page:');
Bawl.dbg(data);
if ( data.query && data.query.pages && data.query.pages[ Object.keys(data.query.pages)[0] ] && data.query.pages[ Object.keys(data.query.pages)[0] ].revisions && data.query.pages[ Object.keys(data.query.pages)[0] ].revisions[0] ) {
Bawl.pageRevisionSinceLastCheck[replyLinkParams.pageTitle] = data.query.pages[ Object.keys(data.query.pages)[0] ].revisions[0].slots.main['*'];
} else {
Bawl.pageRevisionSinceLastCheck[replyLinkParams.pageTitle] = '';
}
Bawl.compareRevisionsToCheckForComments(replyLinkParams, situation);
});
}
};
Bawl.closeSettings = function() {
$(document.getElementsByClassName('BawlSettings')).addClass('BawlNoDisplay');
window.BawlUITextInput.scrollIntoView();
};
Bawl.createPingText = function(replyLinkParams) {
Bawl.dbg('create ping text');
Bawl.recipientIsAnon = replyLinkParams.origReplyTo.match(/(^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$|\:)/); //IPv4 or contains a colon as in IPv6 which is disallowed in usernames. Will need adjustment after IP anonimization
Bawl.userHatesPingTimestamp = Bawl.timestampToTimeAsInSig(replyLinkParams.origTimestamp);
Bawl.checkHtmlForNoping = $('.bawlprocess')[replyLinkParams.int].parentElement.innerHTML;
Bawl.checkLessHtmlForNopingRegExp = new RegExp(Bawl.escapeRegExp(replyLinkParams.origReplyTo) + '.*NOPING.*' + Bawl.userHatesPingTimestamp);
Bawl.checkLessHtmlForNoping = '';
if ( Bawl.checkHtmlForNoping.match(Bawl.checkLessHtmlForNopingRegExp) ) {
Bawl.checkLessHtmlForNoping = Bawl.checkHtmlForNoping.match(Bawl.checkLessHtmlForNopingRegExp)[0];
}
Bawl.userHatesPingRegExp = new RegExp('(' + Bawl.escapeRegExp(replyLinkParams.origReplyTo) + '.*)NOPING(\:[^\:\<\>\"]{0,120})?(\:[^\:\<\>\"]{0,120})?(\:[^\:\<\>\"]{0,120})?(\:[^\:\<\>\"]{0,120})?(\:[^\:\<\>\"]{0,120})?(.{0,100}' + Bawl.userHatesPingTimestamp + '.*)');
Bawl.userHatesPing = Bawl.checkLessHtmlForNoping.match(Bawl.userHatesPingRegExp);
if ( Bawl.recipientIsAnon != null ) {
Bawl.dbg('anon user found');
return Bawl.pingTextAnon.replace(/USERNAME/g, Bawl.escapeReplacement(replyLinkParams.origReplyTo));
} else if ( Bawl.userHatesPing ) {
Bawl.dbg('user hates pings');
Bawl.userNemesis = Bawl.checkLessHtmlForNoping.replace(Bawl.userHatesPingRegExp, '$2$3$4$5$6').replace(/_/g, ' ');
if ( Bawl.userNemesis == '' || Bawl.userNemesis.match(':' + mw.config.get('wgUserName') + ':') ) {
Bawl.dbg(replyLinkParams.origReplyTo + ' doesn\'t want to be pinged');
if ( Bawl.userNemesis.match(':' + mw.config.get('wgUserName') + ':') ) {
Bawl.dbg('BY YOU.');
}
mw.notify(Bawl.msgs.nopingNotify);
return replyLinkParams.origReplyTo + ', ';
} else {
Bawl.dbg('this user has enemies, but you aren\'t one of them. adding ping');
return Bawl.settings.pingText.replace(/USERNAME/g, Bawl.escapeReplacement(replyLinkParams.origReplyTo));
}
} else {
return Bawl.settings.pingText.replace(/USERNAME/g, Bawl.escapeReplacement(replyLinkParams.origReplyTo));
}
};
Bawl.openReplyForm = function(replyLinkParams) {
Bawl.loadSettings();
if ( Bawl.languagesAvailableInExternalFile.indexOf(mw.config.get('wgUserLanguage')) != -1 ) {
mw.loader.getScript('https://en.wikipedia.org/enwiki/w/index.php?title=User:Alexis_Jazz/Bawl-lang.js&action=raw&ctype=text/javascript');
}
if ( typeof replyLinkParams == 'string' ) {
replyLinkParams = JSON.parse(decodeURIComponent(replyLinkParams.replace(/\%27/g, '\'')));
}
Bawl.postCommentSuccess = false;
if ( Bawl.settings.warnExit == true ) {
window.onbeforeunload = function() { if ( Bawl.UITextInput.getValue() != '' && document.getElementById('BawlReplyForm') ) { return ''; } };
}
Bawl.dbg(replyLinkParams);
Bawl.dbg('Bawl.openReplyForm');
if ( document.getElementById('BawlUITextInput') != null && replyLinkParams.origReplyTo != 'anonSectReply' && replyLinkParams.type == 'comment' ) { //there is already a reply form open, add a ping instead
Bawl.dbg('form already open, adding ping');
Bawl.currentMessageLastCharacter = Bawl.UITextInput.getValue().slice(Bawl.UITextInput.getValue().length - 1, Bawl.UITextInput.getValue().length);
if ( Bawl.currentMessageLastCharacter != " " ) {
Bawl.spaceBeforePing = " ";
} else {
Bawl.spaceBeforePing = "";
}
Bawl.userPingText = Bawl.createPingText(replyLinkParams);
if ( Bawl.UITextInput.getValue().match(Bawl.escapeRegExp(Bawl.userPingText)) ) {
Bawl.dbg('this user has already been mentioned. I\'ll scroll Bawl into view so you can see');
Bawl.UITextInput.scrollElementIntoView();
Bawl.UIReplyButton.scrollElementIntoView();
Bawl.UITextInput.focus();
} else {
Bawl.dbg('insert user ' + Bawl.userPingText);
//Bawl.UITextInput.encapsulateContent() is the easier way to do this, but that will always focus the input field and scroll it into view. the focus isn't the issue, the scrolling can be if you are adding multiple names from elsewhere in the discussion
Bawl.cursorPos = Bawl.UITextInput.getRange().from;
Bawl.textInputWithMention = Bawl.UITextInput.getValue().slice(0, Bawl.cursorPos) + Bawl.spaceBeforePing + Bawl.userPingText + Bawl.UITextInput.getValue().slice(Bawl.cursorPos,);
Bawl.UITextInput.setValue(Bawl.textInputWithMention);
}
} else if ( document.getElementById('BawlUITextInput') != null && ( replyLinkParams.origReplyTo == 'anonSectReply' || replyLinkParams.type != 'comment' ) ) {
Bawl.dbg('not adding a mention for not-comment icons');
Bawl.UITextInput.scrollElementIntoView();
Bawl.UIReplyButton.scrollElementIntoView();
} else if ( document.getElementById('BawlUITextInput') == null ) { //there is no reply form yet, create one
Bawl.replyLinkParamsOpened = replyLinkParams;
Bawl.bawlFormHTML = document.createElement('div');
Bawl.bawlFormHTML.id = 'bawlForm-' + replyLinkParams.id;
Bawl.bawlFormHTML.classList = [ 'BawlNoDisplay BawlForm' ];
if ( replyLinkParams.origReplyTo == 'anonSectReply' ) {
document.getElementById(replyLinkParams.id).append(Bawl.bawlFormHTML);
} else if ( replyLinkParams.type == 'comment' || replyLinkParams.type == 'edit' ) {
Bawl.dbg('add form to edit comment');
if ( $('.bawlprocess')[replyLinkParams.int].parentElement && $('.bawlprocess')[replyLinkParams.int].parentElement.nextElementSibling && $('.bawlprocess')[replyLinkParams.int].parentElement.nextElementSibling.tagName == 'DL' && replyLinkParams.origLevel == 0 ) {
Bawl.dbg('unindented comment with indented comments below it, insert the reply form below it. This should generally put the reply form where the reply will be.');
$('.bawlprocess')[replyLinkParams.int].parentElement.nextElementSibling.append(Bawl.bawlFormHTML);
} else {
Bawl.dbg('unindented comment without indented comments below it, appending to:');
Bawl.dbg($('.bawlprocess')[replyLinkParams.int].parentElement);
$('.bawlprocess')[replyLinkParams.int].parentElement.append(Bawl.bawlFormHTML);
}
if ( replyLinkParams.preview == true ) {
Bawl.dbg('add form to edit from preview');
$('#Bawlpreviewlinks').append(Bawl.bawlFormHTML);
}
} else if ( replyLinkParams.type == 'edit' ) {
Bawl.bawlFormHTML.id = 'bawlForm-edit-' + replyLinkParams.id;
if ( replyLinkParams.preview == true ) {
$('#Bawlpreviewlinks').append(Bawl.bawlFormHTML);
}
} else if ( replyLinkParams.type == 'heading' ) {
$('.bawlprocess')[replyLinkParams.int].append(Bawl.bawlFormHTML);
} else if ( replyLinkParams.subtype == 'BCL' ) {
$('.bawlprocess')[replyLinkParams.int].append(Bawl.bawlFormHTML);
}
if ( Bawl.UITextInput && Bawl.UITextInput.getValue() != '' ) {
Bawl.dbg('form was opened previously, reload last input');
Bawl.preloadText = Bawl.UITextInput.getValue();
} else if ( replyLinkParams.origReplyTo != 'anonSectReply' && replyLinkParams.origReplyTo != 'NO-VALUE-PLEASE-IGNORE' && Bawl.settings.autoPing == true && replyLinkParams.type == "comment" && replyLinkParams.origReplyTo != mw.config.get( "wgUserName" ) && !( replyLinkParams.origReplyTo == mw.config.get('wgTitle') && mw.config.get('wgNamespaceNumber') == 3 ) ) { //don't ping yourself and don't ping the recipient on their own talk page
Bawl.dbg('preloading auto-mention');
Bawl.preloadText = Bawl.createPingText(replyLinkParams);
} else {
Bawl.dbg('skipping auto-mention');
Bawl.preloadText = '';
}
if ( Bawl.UITextInputTitle ) { Bawl.preloadTitle = Bawl.UITextInputTitle.getValue() } else { Bawl.preloadTitle = '' };
if ( Bawl.settings.limitWidth == false ) {
Bawl.BawlUITextInputTitleClass = 'BawlNoMaxWidth';
} else {
Bawl.BawlUITextInputTitleClass = '';
}
Bawl.UITextInputTitle = new OO.ui.TextInputWidget( {
id: 'BawlUITextInputTitle',
classes: [ 'BawlMarginHalfEm',Bawl.BawlUITextInputTitleClass ],
value: Bawl.preloadTitle,
placeholder: Bawl.msgs.titlePlaceholder,
} );
if ( replyLinkParams.type == 'editFullPage' ) {
Bawl.UITextInputRows = 25;
} else {
Bawl.UITextInputRows = 6;
}
Bawl.UITextInput = new OO.ui.MultilineTextInputWidget( {
id: 'BawlUITextInput',
rows: Bawl.UITextInputRows,
classes: [ 'BawlMarginHalfEm', 'BawlUnsetLimitWidth' ],
value: Bawl.preloadText,
} );
if ( Bawl.settings.livePreview == true ) {
Bawl.UITextInput.on('change', function() {
const BawlCurrentInputValue = Bawl.UITextInput.getValue();
var DelayedPreview = setInterval(function () { // only parse preview if content has been stable for at least half a second
Bawl.newInputValue = Bawl.UITextInput.getValue();
clearInterval(DelayedPreview);
if ( BawlCurrentInputValue == Bawl.newInputValue ) {
Bawl.doPreview('preview');
Bawl.dbg('live preview');
} else {
Bawl.dbg('you\'re typing too fast!!');
}
delete BawlCurrentInputValue;
}, 500);
});
}
if ( Bawl.settings.saveDraft == true ) {
Bawl.UITextInput.on('change', function() {
Bawl.dbg('should we save a draft?');
const BawlCurrentInputValueDraft = Bawl.UITextInput.getValue();
var DelayedSaveDraft = setInterval(function () { // only save draft if content has been stable for at least 5 seconds
Bawl.newInputValueDraft = Bawl.UITextInput.getValue();
clearInterval(DelayedSaveDraft);
if ( BawlCurrentInputValueDraft == Bawl.newInputValueDraft ) {
Bawl.dbg('saving draft to localStorage');
if ( window.localStorage.BawlDrafts ) {
Bawl.dbg('found existing drafts in localStorage');
Bawl.savedDrafts = JSON.parse(window.localStorage.BawlDrafts);
} else {
Bawl.savedDrafts = {};
}
Bawl.timestampNowDraft = new Date().getTime();
Bawl.timestampNowDraftLastWeek = Bawl.timestampNowDraft - 604800000;
for (BawlDraftInt = 0; BawlDraftInt < Bawl.savedDrafts.length; BawlDraftInt++) {
Bawl.dbg(Bawl.processDraftKey);
Bawl.processDraftKey = Object.keys(Bawl.savedDrafts)[prefint];
if ( Bawl.savedDrafts[Bawl.processDraftKey].time < Bawl.timestampNowDraftLastWeek ) {
Bawl.dbg('draft ' + Bawl.processDraftKey + ' is over a week old, removing it');
delete Bawl.savedDrafts[Bawl.processDraftKey];
}
}
if ( Bawl.UITextInput.getValue().length > 100 ) {
Bawl.dbg('add comment to drafts');
Bawl.savedDrafts[encodeURIComponent(replyLinkParams.pageTitle.replace(/ /g,'_'))] = {'time':Bawl.timestampNowDraft,'text':Bawl.UITextInput.getValue()};
} else {
Bawl.dbg('too short, removing draft');
delete Bawl.savedDrafts[encodeURIComponent(replyLinkParams.pageTitle.replace(/ /g,'_'))];
}
window.localStorage.setItem('BawlDrafts',JSON.stringify(Bawl.savedDrafts));
} else {
Bawl.dbg('you\'re typing too fast to save the draft!!');
}
delete BawlCurrentInputValueDraft;
}, 5000);
});
}
Bawl.buttonOnTheWrongSideClass = '';
if ( Bawl.settings.wrongUI == true ) {
Bawl.buttonOnTheWrongSideClass = 'BawlFloatRight';
}
Bawl.UIReplyButton = new OO.ui.ButtonWidget( {
id: 'BawlUIReplyButton',
label: Bawl.basicmsgs.BawlUIReplyButton,
flags: [ 'primary', 'progressive' ],
classes: [ Bawl.buttonOnTheWrongSideClass ]
} );
Bawl.UIReplyButton.on('click', function() { Bawl.postReply1(replyLinkParams) });
Bawl.UIDryRunButton = new OO.ui.ButtonWidget( {
id: 'BawlUIDryRunButton',
label: 'Dry run',
flags: [ 'primary', 'progressive' ],
classes: [ Bawl.buttonOnTheWrongSideClass ]
} );
Bawl.UIDryRunButton.on('click', function() { Bawl.dryRunOnce = true;Bawl.postReply1(replyLinkParams) });
Bawl.UIPreviewButton = new OO.ui.ButtonWidget( {
id: 'BawlUIPreviewButton',
label: Bawl.basicmsgs.BawlUIPreviewButton,
flags: [ 'primary' ],
classes: [ Bawl.buttonOnTheWrongSideClass ]
} );
Bawl.UIPreviewButton.on('click', function() { Bawl.doPreview('preview') });
Bawl.UICancelButton = new OO.ui.ButtonWidget( {
id: 'BawlUICancelButton',
label: Bawl.basicmsgs.BawlUICancelButton,
classes: [ Bawl.buttonOnTheWrongSideClass ]
} );
Bawl.UISettingsButton = new OO.ui.ButtonWidget( {
id: 'BawlUISettingsButton',
icon: 'settings',
classes: ['BawlFloatRight'],
framed: false,
} );
Bawl.UICancelButton.on('click', Bawl.cancelReply);
Bawl.UIprogressIndicatorHTML = new OO.ui.HtmlSnippet('<span id="BawlProgressIndicator"></span>');
Bawl.UIprogressIndicator = new OO.ui.LabelWidget( {
label: Bawl.UIprogressIndicatorHTML,
} );
Bawl.UIMarkupBoldButton = new OO.ui.ButtonWidget( {
id: 'BawlUIMarkupBoldButton',
label: Bawl.basicmsgs.bold,
framed: false,
classes: ['BawlLeftRightMargin', 'BawlMarkupBold']
} );
Bawl.UIMarkupItalicButton = new OO.ui.ButtonWidget( {
id: 'BawlUIMarkupItalicButton',
label: Bawl.basicmsgs.italic,
framed: false,
classes: ['BawlLeftRightMargin', 'BawlMarkupItalic']
} );
Bawl.UIMarkupStrikeButtonLabel = new OO.ui.HtmlSnippet('<span style="text-decoration:line-through">' + Bawl.basicmsgs.strike + '</span>');
Bawl.UIMarkupStrikeButton = new OO.ui.ButtonWidget( {
id: 'BawlUIMarkupStrikeButton',
label: Bawl.UIMarkupStrikeButtonLabel,
framed: false,
classes: ['BawlLeftRightMargin']
} );
Bawl.UIMarkupLinkButton = new OO.ui.ButtonWidget( {
id: 'BawlUIMarkupLinkButton',
label: '[[]]',
framed: false,
classes: ['BawlLeftRightMargin']
} );
Bawl.UIMarkupBoldButton.on('click', function() { Bawl.UITextInput.encapsulateContent('\'\'\'', '\'\'\'') } );
Bawl.UIMarkupItalicButton.on('click', function() { Bawl.UITextInput.encapsulateContent('\'\'', '\'\'') } );
Bawl.UIMarkupStrikeButton.on('click', function() { Bawl.UITextInput.encapsulateContent('<s>', '</s>') } );
Bawl.UIMarkupLinkButton.on('click', function() { Bawl.UITextInput.encapsulateContent('[[', ']]') } );
if ( Bawl.settings.markup == true ) {
Bawl.MarkupButtonBar = new OO.ui.HorizontalLayout( {
items: [
Bawl.UIMarkupBoldButton,
Bawl.UIMarkupItalicButton,
Bawl.UIMarkupStrikeButton,
Bawl.UIMarkupLinkButton
],
id: 'BawlMarkupButtonBar',
classes: ['BawlLeftRightMargin']
} );
} else {
Bawl.MarkupButtonBar = new OO.ui.HorizontalLayout( {} );
}
if ( Bawl.settings.wrongUI == false ) {
Bawl.ButtonBarItems = [
Bawl.UIReplyButton,
Bawl.UIPreviewButton,
Bawl.UICancelButton,
Bawl.UIprogressIndicator,
Bawl.MarkupButtonBar,
Bawl.UISettingsButton
];
} else {
Bawl.ButtonBarItems = [
Bawl.UIprogressIndicator,
Bawl.UIReplyButton,
Bawl.UIPreviewButton,
Bawl.UICancelButton,
Bawl.UISettingsButton,
Bawl.MarkupButtonBar,
];
}
if ( Bawl.settings.debug == true ) {
Bawl.ButtonBarItems.push(Bawl.UIDryRunButton);
}
Bawl.ButtonBar = new OO.ui.HorizontalLayout( {
items: Bawl.ButtonBarItems,
id: 'BawlMainButtonBar',
} );
Bawl.previewAndSettingsDiv = '<div id="BawlCustomInserts" class="BawlCustomInserts BawlMarginHalfEm BawlNoDisplay"></div><div id="showNewLinesButton" class="BawlNoDisplay"></div><div id="BawlPreviewBox" class="BawlPreviewBox BawlMarginHalfEm BawlNoDisplay"></div><div id="BawlSettings" class="BawlSettings BawlMarginHalfEm BawlNoDisplay"><span class="BawlFloatRight"><a href="https://en.wikipedia.org/wiki/User:Alexis_Jazz/Bawl" style="font-weight: bold">Bawl!</a> (early access)</span></div>';
Bawl.editNoticeDiv = '<div id="BawlEditNotice" class="BawlNoDisplay BawlForm BawlEditNoticeDiv"></div>';
Bawl.ReplyForm = new OO.ui.FormLayout( {
items: [
Bawl.UITextInputTitle,
Bawl.UITextInput,
Bawl.ButtonBar,
],
id: 'BawlReplyForm',
classes: ['BawlReplyForm'],
} );
$(document.getElementById('bawlForm-' + replyLinkParams.id)).removeClass('BawlNoDisplay');
$(document.getElementById('bawlForm-' + replyLinkParams.id)).append(Bawl.editNoticeDiv).append(Bawl.ReplyForm.$element);
if ( window.localStorage.BawlDrafts ) {
Bawl.loadedDrafts = JSON.parse(window.localStorage.BawlDrafts);
}
if ( Bawl.settings.saveDraft == true && Bawl.loadedDrafts[encodeURIComponent(replyLinkParams.pageTitle.replace(/ /g,'_'))] && Bawl.loadedDrafts[encodeURIComponent(replyLinkParams.pageTitle.replace(/ /g,'_'))].time > (new Date().getTime() - 604800000) ) {
Bawl.dbg('load draft from localStorage');
Bawl.UITextInput.setValue(Bawl.loadedDrafts[encodeURIComponent(replyLinkParams.pageTitle.replace(/ /g,'_'))].text);
mw.notify(Bawl.msgs.restoredDraft);
} else if ( replyLinkParams.type == 'edit' || replyLinkParams.type == 'editFullPage' ) { //preload content
Bawl.UITextInput.setDisabled(true); //disable textinput until preload is done
Bawl.UIReplyButton.setLabel(Bawl.basicmsgs.BawlUIEditButton);
Bawl.dbg('preloading existing comment');
api.get( {
action: 'query', export: 'true', format: 'json', titles: replyLinkParams.pageTitle,
} ).done( function ( data ) {
Bawl.dbg(data);
Bawl.wikiTextForEdit = Bawl.getWikitextFromExport(data.query.export["*"]);
if ( replyLinkParams.type == 'editFullPage' ) {
Bawl.UITextInput.setValue(Bawl.wikiTextForEdit);
Bawl.UITextInput.setDisabled(false);
return;
}
Bawl.origTimeAsInSig = Bawl.timestampToTimeAsInSig(replyLinkParams.origTimestamp);
Bawl.endOfCommentLocatorRegExp = new RegExp(' *(\{\{BawlCmt|<span id="[^"]*" class="BawlCmt").*');
Bawl.wikiTextForEditCommentRegExp = new RegExp('(^|\n)[\\:\\*\\#]{' + replyLinkParams.origLevel + '}(.*(' + Bawl.escapeRegExp(encodeURIComponent(replyLinkParams.origReplyTo)).replace(/ /g, '[_ ]') + '|' + Bawl.escapeRegExp(replyLinkParams.origReplyTo).replace(/ /g, '[_ ]') + ').{0,255}' + Bawl.origTimeAsInSig + '.*)', '');
Bawl.restoreNewlineRegExp = new RegExp(Bawl.escapeRegExp(Bawl.newLineTemplate), 'g');
Bawl.origTimeAsInSigEditRegExp = new RegExp(' *' + Bawl.origTimeAsInSig + '[^]*');
Bawl.wikiTextForEditComment = Bawl.wikiTextForEdit.match(Bawl.wikiTextForEditCommentRegExp)[2].replace(Bawl.endOfCommentLocatorRegExp, '').replace(Bawl.origTimeAsInSigEditRegExp, '').replace(/^[\*\:\#]*/, '');
Bawl.wikiTextForEditCommentMultiline = Bawl.wikiTextForEditComment.replace( Bawl.restoreNewlineRegExp, '\n' );
Bawl.UITextInput.setValue(Bawl.wikiTextForEditCommentMultiline);
Bawl.UITextInput.setDisabled(false);
Bawl.dbg('edit preload done, focus text input');
Bawl.UITextInput.focus();
});
} else if ( (replyLinkParams.preload || replyLinkParams.preloadtitle) && Bawl.UITextInput.getValue() == '' && Bawl.UITextInputTitle.getValue() == '' ) { //InputBox/Bawl-comment-link preload
for (intInputBoxPreload = 0; intInputBoxPreload < $('.bawlprocess')[replyLinkParams.int].children.length; intInputBoxPreload++) {
Bawl.dbg('process child element #' + intInputBoxPreload + '/' + $('.bawlprocess')[replyLinkParams.int].children.length + ' for element #' + int);
if ( $('.bawlprocess')[replyLinkParams.int].children[intInputBoxPreload].name == 'preloadtitle' ) {
replyLinkParams.preloadtitle = $('.bawlprocess')[replyLinkParams.int].children[intInputBoxPreload].value;
}
}
if ( replyLinkParams.preloadtitle ) {
Bawl.dbg('preloading title');
Bawl.UITextInputTitle.setValue(replyLinkParams.preloadtitle);
}
if ( replyLinkParams.preload ) {
Bawl.UITextInput.setDisabled(true); //disable textinput until preload is done
Bawl.dbg('preloading page specified by InputBox');
api.get( {
action: 'query', export: 'true', format: 'json', titles: replyLinkParams.preload,
} ).done( function ( data ) {
Bawl.dbg(data);
Bawl.wikiTextForEdit = Bawl.getWikitextFromExport(data.query.export["*"]);
if ( typeof replyLinkParams.preloadparams == 'string' ) {
replyLinkParams.preloadparams = JSON.parse(decodeURIComponent(replyLinkParams.preloadparams).replace(/\"\;/g, '"'));
}
for (intInputBoxPreloadParams = 0; intInputBoxPreloadParams < replyLinkParams.preloadparams.length; intInputBoxPreloadParams++) {
Bawl.dbg('replacing preloadparam ' + (intInputBoxPreloadParams + 1));
Bawl.replacePreloadVar = new RegExp('\\$' + ( intInputBoxPreloadParams + 1) + '([^0-9]|$)', 'g')
Bawl.wikiTextForEdit = Bawl.wikiTextForEdit.replace(Bawl.replacePreloadVar, replyLinkParams.preloadparams[intInputBoxPreloadParams] + '$1');
}
Bawl.UITextInput.setValue(Bawl.wikiTextForEdit);
Bawl.UITextInput.setDisabled(false);
if ( Bawl.UITextInputTitle.isVisible() == false ) {
Bawl.dbg('loaded requested preload page, focus input field');
Bawl.UITextInput.focus();
}
});
}
};
if ( replyLinkParams.type == 'newsection' ) {
window.BawlUITextInputTitle.scrollIntoView();
}
$('#BawlReplyForm').append(Bawl.tosNagContainer);
if ( Bawl.settings.tosNag == true && ! document.getElementById('BawlToSNag') ) {
Bawl.insertToSnag();
};
$(document.getElementById('bawlForm-' + replyLinkParams.id)).append(Bawl.previewAndSettingsDiv);
Bawl.customInsertButton = {};
for (int = 0; int < 30; int++) {
Bawl.dbg('process custom inserts');
if ( Bawl.settings.cI && Bawl.settings.cI[int] && Bawl.settings.cI[int] != "" ) { //non-empty insert found
$('.BawlCustomInserts').removeClass('BawlNoDisplay');
Bawl.dbg('adding button for custom insert #' + int);
if ( Bawl.settings.cI[int].match(/\:\<\<([^\>]*)\>\>/) ) {
Bawl.settings.cILabel = Bawl.settings.cI[int].replace(/.*\:\<\<([^\>]*)\>\>/, '$1');
} else if ( Bawl.settings.cI[int].length > 14 ) {
Bawl.settings.cILabel = Bawl.settings.cI[int].slice(0,10) + '..';
} else {
Bawl.settings.cILabel = Bawl.settings.cI[int];
}
Bawl.insertIsRegExpRegExp = new RegExp('^\/(.*)([^\])\/(.*)([^\])\/([gmi]*)$');
Bawl.customInsertButton[int] = new OO.ui.ButtonWidget( {
label: Bawl.settings.cILabel,
classes: [ 'BawlMarginHalfEm' ]
});
Bawl.insertCustomInsert = function(num) {
Bawl.activatedCustomInsert = Bawl.settings.cI[num].replace(/\:\<\<[^\>]*\>\>$/, '');
if ( Bawl.activatedCustomInsert.match(Bawl.insertIsRegExpRegExp) && Bawl.activatedCustomInsert.match(Bawl.insertIsRegExpRegExp).length == 6 ) {
Bawl.customInsertRegExpNowParts = Bawl.activatedCustomInsert.match(Bawl.insertIsRegExpRegExp);
Bawl.customInsertRegExpNow = new RegExp(Bawl.customInsertRegExpNowParts[1] + Bawl.customInsertRegExpNowParts[2], Bawl.customInsertRegExpNowParts[5]);
Bawl.UITextInput.setValue(Bawl.UITextInput.getValue().replace(Bawl.customInsertRegExpNow, Bawl.customInsertRegExpNowParts[3] + Bawl.customInsertRegExpNowParts[4]));
} else {
Bawl.UITextInput.encapsulateContent(Bawl.activatedCustomInsert,'');
}
}
if ( int == 0 ) { Bawl.customInsertButton[0].on('click', function() { Bawl.insertCustomInsert(0); }); //this isn't very pretty but I'm not sure how else to solve it. You can't just call int because that'll be 10 by the time you press a button
} else if ( int == 1 ) { Bawl.customInsertButton[1].on('click', function() { Bawl.insertCustomInsert(1); });
} else if ( int == 2 ) { Bawl.customInsertButton[2].on('click', function() { Bawl.insertCustomInsert(2); });
} else if ( int == 3 ) { Bawl.customInsertButton[3].on('click', function() { Bawl.insertCustomInsert(3); });
} else if ( int == 4 ) { Bawl.customInsertButton[4].on('click', function() { Bawl.insertCustomInsert(4); });
} else if ( int == 5 ) { Bawl.customInsertButton[5].on('click', function() { Bawl.insertCustomInsert(5); });
} else if ( int == 6 ) { Bawl.customInsertButton[6].on('click', function() { Bawl.insertCustomInsert(6); });
} else if ( int == 7 ) { Bawl.customInsertButton[7].on('click', function() { Bawl.insertCustomInsert(7); });
} else if ( int == 8 ) { Bawl.customInsertButton[8].on('click', function() { Bawl.insertCustomInsert(8); });
} else if ( int == 9 ) { Bawl.customInsertButton[9].on('click', function() { Bawl.insertCustomInsert(9); });
} else if ( int == 10 ) { Bawl.customInsertButton[10].on('click', function() { Bawl.insertCustomInsert(10); });
} else if ( int == 11 ) { Bawl.customInsertButton[11].on('click', function() { Bawl.insertCustomInsert(11); });
} else if ( int == 12 ) { Bawl.customInsertButton[12].on('click', function() { Bawl.insertCustomInsert(12); });
} else if ( int == 13 ) { Bawl.customInsertButton[13].on('click', function() { Bawl.insertCustomInsert(13); });
} else if ( int == 14 ) { Bawl.customInsertButton[14].on('click', function() { Bawl.insertCustomInsert(14); });
} else if ( int == 15 ) { Bawl.customInsertButton[15].on('click', function() { Bawl.insertCustomInsert(15); });
} else if ( int == 16 ) { Bawl.customInsertButton[16].on('click', function() { Bawl.insertCustomInsert(16); });
} else if ( int == 17 ) { Bawl.customInsertButton[17].on('click', function() { Bawl.insertCustomInsert(17); });
} else if ( int == 18 ) { Bawl.customInsertButton[18].on('click', function() { Bawl.insertCustomInsert(18); });
} else if ( int == 19 ) { Bawl.customInsertButton[19].on('click', function() { Bawl.insertCustomInsert(19); });
} else if ( int == 20 ) { Bawl.customInsertButton[20].on('click', function() { Bawl.insertCustomInsert(20); });
} else if ( int == 21 ) { Bawl.customInsertButton[21].on('click', function() { Bawl.insertCustomInsert(21); });
} else if ( int == 22 ) { Bawl.customInsertButton[22].on('click', function() { Bawl.insertCustomInsert(22); });
} else if ( int == 23 ) { Bawl.customInsertButton[23].on('click', function() { Bawl.insertCustomInsert(23); });
} else if ( int == 24 ) { Bawl.customInsertButton[24].on('click', function() { Bawl.insertCustomInsert(24); });
} else if ( int == 25 ) { Bawl.customInsertButton[25].on('click', function() { Bawl.insertCustomInsert(25); });
} else if ( int == 26 ) { Bawl.customInsertButton[26].on('click', function() { Bawl.insertCustomInsert(26); });
} else if ( int == 27 ) { Bawl.customInsertButton[27].on('click', function() { Bawl.insertCustomInsert(27); });
} else if ( int == 28 ) { Bawl.customInsertButton[28].on('click', function() { Bawl.insertCustomInsert(28); });
} else if ( int == 29 ) { Bawl.customInsertButton[29].on('click', function() { Bawl.insertCustomInsert(29); });
}
$('.BawlCustomInserts').append(Bawl.customInsertButton[int].$element);
} //end non-empty insert found
} //end for
if ( Bawl.settings.limitWidth == true ) {
$('.BawlForm').addClass('BawlLimitWidth');
$('BawlUITextInput').removeClass('BawlUnsetLimitWidth');
$('BawlUITextInput').addClass('BawlLimitWidth')
}
if ( replyLinkParams.type == 'comment' || replyLinkParams.type == 'edit' || replyLinkParams.subtype == 'BCL' || replyLinkParams.type == 'editFullPage' ) {
Bawl.dbg('hide title input and make it read-only');
Bawl.UITextInputTitle.setValue('');
Bawl.UITextInputTitle.setReadOnly(true);
Bawl.UITextInputTitle.toggle(false);
}
if ( Bawl.settings.editNotice == true || replyLinkParams.editIntro ) { // load editnotice. if there isn't any it'll just be blank
Bawl.dbg('Loading editnotice');
$('#BawlEditNotice').removeClass('BawlNoDisplay');
Bawl.editNoticeParams = {
format: 'json',
action: 'parse',
title: Bawl.replyLinkParamsOpened.pageTitle,
pst: '1',
prop: 'text',
formatversion: '2',
text: '{{#ifexist:MediaWiki:Editnotice-{{NAMESPACENUMBER}}-{{#invoke:String|replace|{{PAGENAME}}|/|-}}|{{MediaWiki:Editnotice-{{NAMESPACENUMBER}}-{{#invoke:String|replace|{{PAGENAME}}|/|-}}}}|{{#ifexist:MediaWiki:Editnotice-{{NAMESPACENUMBER}}|{{MediaWiki:Editnotice-{{NAMESPACENUMBER}}}}}}}}',
};
if ( replyLinkParams.editIntro ) {
Bawl.editNoticeParams.text = '{{:' + replyLinkParams.editIntro + '}}';
}
Bawl.doAPICall(Bawl.editNoticeParams, 'editnotice');
}
if ( Bawl.settings.checkNewComments == true ) {
Bawl.checkForNewComments(replyLinkParams, 'openform');
}
Bawl.dbg('scroll reply button into view');
Bawl.UIReplyButton.scrollElementIntoView();
if ( replyLinkParams.type == 'newsection' | replyLinkParams.type == 'heading' ) {
Bawl.dbg('focus input title and scroll it into view');
Bawl.UITextInputTitle.focus();
Bawl.UITextInputTitle.scrollElementIntoView();
} else {
Bawl.dbg('focus text input');
Bawl.UITextInput.focus();
}
Bawl.openSettings = function(openclose) {
Bawl.UISettingsButton.blur();
if ( document.getElementById('saveSettingsButton') && ! $(document.getElementsByClassName('BawlSettings')).hasClass('BawlNoDisplay') && openclose != 'open' ) {
Bawl.dbg('settings are already opened. hiding them');
Bawl.closeSettings();
return;
} else if ( document.getElementById('saveSettingsButton') && $(document.getElementsByClassName('BawlSettings')).hasClass('BawlNoDisplay') ) {
Bawl.dbg('settings were opened previously but currently hidden. unhiding them');
$(document.getElementsByClassName('BawlSettings')).removeClass('BawlNoDisplay');
return;
}
$(document.getElementsByClassName('BawlSettings')).removeClass('BawlNoDisplay');
Bawl.settingElement = {};
Bawl.settingElement.watchlist = new OO.ui.DropdownInputWidget( {
options: [
{ data: 'nochange', label: Bawl.msgs.watchlistexpirynochange },
{ data: 'preferences', label: Bawl.msgs.watchlistexpirypreferences },
{ data: 'unwatch', label: Bawl.msgs.watchlistexpiryunwatch },
{ data: 'watch', label: Bawl.msgs.watchlistexpirywatch },
],
label: 'Bawl.msgs.watchlist',
value: Bawl.settings.watchlist,
id: 'UIwatchlist',
classes: [ 'BawlDropDownMenu' ],
} );
Bawl.settingElement.watchlistFieldLayout = new OO.ui.FieldLayout( Bawl.settingElement.watchlist, { label: Bawl.msgs.watchlist, align: 'inline', classes: [ 'BawlOOuiFieldLayout' ] } );
Bawl.settingElement.watchlistexpiry = new OO.ui.DropdownInputWidget( {
options: [
{ data: '14 days', label: Bawl.msgs.watchlistexpirydays.replace('DAYS', '14') },
{ data: '30 days', label: Bawl.msgs.watchlistexpirydays.replace('DAYS', '30') },
{ data: '90 days', label: Bawl.msgs.watchlistexpirydays.replace('DAYS', '90') },
{ data: '180 days', label: Bawl.msgs.watchlistexpirydays.replace('DAYS', '180') },
{ data: '365 days', label: Bawl.msgs.watchlistexpirydays.replace('DAYS', '365') },
{ data: '730 days', label: Bawl.msgs.watchlistexpirydays.replace('DAYS', '730') },
{ data: 'indefinite', label: Bawl.msgs.watchlistexpirydays.replace('DAYS', '∞') },
],
label: 'Bawl.msgs.watchlistexpiry',
value: Bawl.settings.watchlistexpiry,
id: 'UIwatchlistexpiry',
classes: [ 'BawlDropDownMenu' ],
} );
Bawl.settingElement.watchlistexpiryFieldLayout = new OO.ui.FieldLayout( Bawl.settingElement.watchlistexpiry, { label: Bawl.msgs.watchlistexpiry, align: 'inline', classes: [ 'BawlOOuiFieldLayout' ] } );
Bawl.settingElement.UIfontSize = new OO.ui.DropdownInputWidget( {
options: [
{ data: '0.875em', label: Bawl.msgs.UIfontSize0875em },
{ data: 'x-small', label: Bawl.msgs.UIfontSizeTiny },
{ data: 'small', label: Bawl.msgs.UIfontSizeSmall },
{ data: 'medium' , label: Bawl.msgs.UIfontSizeMedium },
{ data: 'large' , label: Bawl.msgs.UIfontSizeLarge },
{ data: 'x-large', label: Bawl.msgs.UIfontSizeHuge },
],
label: 'Bawl.msgs.UIfontSizeDefault',
value: Bawl.settings.UIfontSize,
id: 'UIfontSize',
classes: [ 'BawlDropDownMenu' ],
} );
Bawl.settingElement.UIfontSizeFieldLayout = new OO.ui.FieldLayout( Bawl.settingElement.UIfontSize, { label: Bawl.msgs.UIfontSize, align: 'inline', classes: [ 'BawlOOuiFieldLayout' ] } );
Bawl.settingElement.afterPost = new OO.ui.DropdownInputWidget( {
options: [
{ data: 'parsecomment', label: Bawl.msgs.parsecomment },
{ data: 'reload', label: Bawl.msgs.reloadafter } ,
{ data: 'link', label: Bawl.msgs.linkafter },
],
label: 'Bawl.msgs.afterPost',
value: Bawl.settings.afterPost,
id: 'BawlAfterPost',
classes: [ 'BawlDropDownMenu' ],
} );
Bawl.settingElement.afterPostFieldLayout = new OO.ui.FieldLayout( Bawl.settingElement.afterPost, { label: Bawl.msgs.afterPost, align: 'inline', classes: [ 'BawlOOuiFieldLayout' ] } );
Bawl.settingElement.saveOptionsList = [ { data: 'browser', label: Bawl.msgs.saveToBrowser }, { data: 'commonjs', label: Bawl.msgs.saveToCommonJS } ];
if ( mw.config.get('wgNoticeProject') == 'wikipedia' || mw.config.get('wgServerName').match(/[a-z\-]{0,20}\.wikipedia\.[a-z]*$/) || mw.config.get('wgDBname').match(/([a-z\-]{0,20})?(wiktionary|wikiquote|wikinews|wikisource|wikibooks|wikiversity|wikivoyage|commonswiki|wikidatawiki|specieswiki|metawiki|mediawikiwiki|incubatorwiki)/) ) {
Bawl.dbg('This appears to be a Wikimedia SUL wiki. Add option to save preferences to global.js on metawiki');
Bawl.settingElement.saveOptionsList.push({ data: 'globaljs', label: Bawl.msgs.saveToGlobalJS });
}
Bawl.settingElement.saveTo = new OO.ui.DropdownInputWidget( {
options: Bawl.settingElement.saveOptionsList,
label: 'Bawl.msgs.saveTo',
value: Bawl.settings.saveTo,
id: 'BawlSaveTo',
classes: [ 'BawlDropDownMenu' ],
} );
Bawl.settingElement.saveToFieldLayout = new OO.ui.FieldLayout( Bawl.settingElement.saveTo, { label: Bawl.msgs.saveTo, align: 'inline', classes: [ 'BawlOOuiFieldLayout' ] } );
Bawl.toggleClearPrefButton = function() {
if ( Bawl.settingElement.saveTo.getValue() == 'browser' ) {
Bawl.settingElement.resetPreferencesButton.setLabel(Bawl.basicmsgs.resetPreferences + Bawl.msgs.resetPreferencesBrowser);
} else if ( Bawl.settingElement.saveTo.getValue() == 'commonjs' ) {
Bawl.settingElement.resetPreferencesButton.setLabel(Bawl.basicmsgs.resetPreferences + Bawl.msgs.resetPreferencesCommonJS);
} else if ( Bawl.settingElement.saveTo.getValue() == 'globaljs' ) {
Bawl.settingElement.resetPreferencesButton.setLabel(Bawl.basicmsgs.resetPreferences + Bawl.msgs.resetPreferencesGlobalJS);
}
};
Bawl.settingElement.saveTo.on('change', Bawl.toggleClearPrefButton );
Bawl.settingElement.pingText = new OO.ui.TextInputWidget( {
value: Bawl.settings.pingText,
id: 'BawlPingTextInput',
placeholder: Bawl.msgs.BawlPingTextInputPlaceholder,
classes: [ 'BawlMarginHalfEmTop', 'BawlMarginHalfEm', 'BawlCustomInsertTextInput' ],
} );
Bawl.settingElement.pingTextFieldLayout = new OO.ui.FieldLayout( Bawl.settingElement.pingText, { label: Bawl.msgs.pingText, align: 'inline', classes: [ 'BawlOOuiFieldLayout' ] } );
Bawl.settingElement.UIversionDate = new OO.ui.LabelWidget( {
label: Bawl.versionDate + ' (' + Bawl.stopwatchAddLinks3 + 'ms)',
classes: [ 'BawlFloatRight', 'BawlSmallerText' ]
} );
Bawl.settingElement.saveSettingsButton = new OO.ui.ButtonWidget( {
id: 'saveSettingsButton',
flags: [ 'primary', 'progressive' ],
label: Bawl.basicmsgs.saveSettings
} );
Bawl.settingElement.resetPreferencesButton = new OO.ui.ButtonWidget( {
id: 'resetPreferencesButton',
flags: [ 'primary', 'destructive' ],
label: Bawl.resetPreferencesButtonLabel,
} );
Bawl.toggleClearPrefButton();
Bawl.settingElement.cancelSettingsButton = new OO.ui.ButtonWidget( {
id: 'cancelSettingsButton',
label: Bawl.basicmsgs.BawlUICancelButton,
} );
Bawl.settingElement.saveSettingsButton.on('click', Bawl.saveSettings );
Bawl.settingElement.resetPreferencesButton.on('click', Bawl.resetPreferences );
Bawl.settingElement.cancelSettingsButton.on('click', Bawl.closeSettings );
Bawl.settingElement.SettingsButtonBar = new OO.ui.HorizontalLayout( {
items: [
Bawl.settingElement.saveSettingsButton,
Bawl.settingElement.resetPreferencesButton,
Bawl.settingElement.cancelSettingsButton,
Bawl.settingElement.UIversionDate
],
classes: [ 'BawlMarginHalfEmTop' ],
} );
Bawl.settingFormArray = [];
Bawl.prefCount = Object.keys(Bawl.defaultSettings).length;
for (prefint = 0; prefint < Bawl.prefCount; prefint++) {
Bawl.processKey = Object.keys(Bawl.defaultSettings)[prefint];
Bawl.dbg('process/create element ' + (prefint + 1) + '/' + Bawl.prefCount + ': ' + Bawl.processKey);
if ( typeof Bawl.settings[ Bawl.processKey ] == 'string' && Bawl.settings[ Bawl.processKey ] == 'LABEL' ) {
Bawl.dbg('make label');
Bawl.settingElement[ Bawl.processKey + 'FieldLayout' ] = new OO.ui.LabelWidget( {
label: Bawl.msgs[ Bawl.processKey ],
classes: [ 'BawlSettingsSectionLabel' ]
} );
} else if ( typeof Bawl.settings[ Bawl.processKey ] != 'object' ) { //do not process the CI/runCI objects
Bawl.dbg('make checkbox');
if ( ! Bawl.settingElement[ Bawl.processKey ] ) {
if ( typeof Bawl.msgs[ Bawl.processKey ] == 'string' && Bawl.msgs[ Bawl.processKey ].match(/\<a/) ) {
Bawl.msgs[ Bawl.processKey ] = new OO.ui.HtmlSnippet(Bawl.msgs[ Bawl.processKey ]);
}
Bawl.settingElement[ Bawl.processKey ] = new OO.ui.CheckboxInputWidget( {
id: 'BawlPref' + Bawl.processKey,
selected: Bawl.settings[ Bawl.processKey ],
} );
Bawl.settingElement[ Bawl.processKey + 'FieldLayout' ] = new OO.ui.FieldLayout( Bawl.settingElement[ Bawl.processKey ], { id: 'BawlPref' + Bawl.processKey + 'FieldLayout', label: Bawl.msgs[ Bawl.processKey ], align: 'inline', classes: [ 'BawlOOuiFieldLayout' ] } );
}
}
if ( Bawl.settingElement[ Bawl.processKey + 'FieldLayout' ] ) {
Bawl.settingFormArray.push(Bawl.settingElement[ Bawl.processKey + 'FieldLayout' ]);
}
}
Bawl.dbg('add settings button bar');
Bawl.settingFormArray.push(Bawl.settingElement.SettingsButtonBar);
Bawl.settingElement.tosNag.on('change', Bawl.toggleTosNag );
Bawl.settingElement.dateLinks.on('change', function() { if ( Bawl.settingElement.dateLinks.isSelected() ) { Bawl.settingElement.dateLinksLocalTime.setDisabled(false) } else { Bawl.settingElement.dateLinksLocalTime.setDisabled(true);Bawl.settingElement.dateLinksLocalTime.setSelected(false) } } );
if ( Bawl.settings.dateLinks == false ) {
Bawl.settingElement.dateLinksLocalTime.setDisabled(true);
}
Bawl.settingsForm = new OO.ui.FormLayout( {
items: Bawl.settingFormArray,
id: 'BawlReplyForm',
classes: ['BawlReplyForm'],
} );
$('#BawlSettings').append(Bawl.settingsForm.$element);
Bawl.customInsertTextInput = {};
Bawl.customInsertThatRunTextInput = {};
Bawl.hideFurtherCIInputFields = false;
Bawl.hideFurtherCIThatRunInputFields = false;
for (int = 0; int < 30; int++) {
Bawl.dbg('process custom inserts');
Bawl.placeholderIntPlusOne = int + 1;
if ( int == 0 ) {
Bawl.customInsertClass = 'BawlMarginHalfEmTop';
} else if ( Bawl.hideFurtherCIInputFields == false ) {
Bawl.customInsertClass = '';
if ( ( int.toFixed().slice(-1,) == 4 || int.toFixed().slice(-1,) == 9 ) && ! Bawl.settings.cI[int] ) {
Bawl.dbg('hide further CI input fields');
Bawl.hideFurtherCIInputFields = true;
}
} else {
Bawl.customInsertClass = 'BawlNoDisplay';
}
if ( int == 0 ) {
Bawl.customInsertThatRunClass = 'BawlMarginHalfEmTop';
} else if ( Bawl.hideFurtherCIThatRunInputFields == false ) {
Bawl.customInsertThatRunClass = '';
if ( ( int.toFixed().slice(-1,) == 4 || int.toFixed().slice(-1,) == 9 ) && ! Bawl.settings.cIThatRun[int] ) {
Bawl.dbg('hide further CIThatRun input fields');
Bawl.hideFurtherCIThatRunInputFields = true;
}
} else {
Bawl.customInsertThatRunClass = 'BawlNoDisplay';
}
Bawl.customInsertTextInput[int] = new OO.ui.TextInputWidget( {
value: Bawl.settings.cI[int],
id: 'BawlCustomInsert' + int,
placeholder: Bawl.msgs.BawlCustomInsertPlaceholder.replace(/NUM/g, Bawl.placeholderIntPlusOne),
classes: [ 'BawlMarginHalfEm', 'BawlCustomInsertTextInput', Bawl.customInsertClass ],
} );
Bawl.customInsertThatRunTextInput[int] = new OO.ui.TextInputWidget( {
value: Bawl.settings.cIThatRun[int],
id: 'BawlCustomInsertThatRun' + int,
placeholder: Bawl.msgs.BawlCustomInsertThatRunPlaceholder.replace('NUM', Bawl.placeholderIntPlusOne),
classes: [ 'BawlMarginHalfEm', 'BawlCustomInsertTextInput', Bawl.customInsertThatRunClass ],
} );
if ( int == 4 ) { Bawl.customInsertTextInput[4].on('change', function() { if ( Bawl.customInsertTextInput[4].getValue() != '' ) { $('#BawlCustomInsert' + 5).removeClass('BawlNoDisplay'); $('#BawlCustomInsert' + 6).removeClass('BawlNoDisplay'); $('#BawlCustomInsert' + 7).removeClass('BawlNoDisplay'); $('#BawlCustomInsert' + 8).removeClass('BawlNoDisplay'); $('#BawlCustomInsert' + 9).removeClass('BawlNoDisplay') } } ); //this isn't very pretty but I'm not sure how else to solve it. You can't just call int because that'll be 10 by the time you press a button
} else if ( int == 9 ) { Bawl.customInsertTextInput[9].on('change', function() { if ( Bawl.customInsertTextInput[9].getValue() != '' ) { $('#BawlCustomInsert' + 10).removeClass('BawlNoDisplay'); $('#BawlCustomInsert' + 11).removeClass('BawlNoDisplay'); $('#BawlCustomInsert' + 12).removeClass('BawlNoDisplay'); $('#BawlCustomInsert' + 13).removeClass('BawlNoDisplay'); $('#BawlCustomInsert' + 14).removeClass('BawlNoDisplay') } } );
} else if ( int == 14 ) { Bawl.customInsertTextInput[14].on('change', function() { if ( Bawl.customInsertTextInput[14].getValue() != '' ) { $('#BawlCustomInsert' + 15).removeClass('BawlNoDisplay'); $('#BawlCustomInsert' + 16).removeClass('BawlNoDisplay'); $('#BawlCustomInsert' + 17).removeClass('BawlNoDisplay'); $('#BawlCustomInsert' + 18).removeClass('BawlNoDisplay'); $('#BawlCustomInsert' + 19).removeClass('BawlNoDisplay') } } );
} else if ( int == 19 ) { Bawl.customInsertTextInput[19].on('change', function() { if ( Bawl.customInsertTextInput[19].getValue() != '' ) { $('#BawlCustomInsert' + 20).removeClass('BawlNoDisplay'); $('#BawlCustomInsert' + 21).removeClass('BawlNoDisplay'); $('#BawlCustomInsert' + 22).removeClass('BawlNoDisplay'); $('#BawlCustomInsert' + 23).removeClass('BawlNoDisplay'); $('#BawlCustomInsert' + 24).removeClass('BawlNoDisplay') } } );
} else if ( int == 24 ) { Bawl.customInsertTextInput[24].on('change', function() { if ( Bawl.customInsertTextInput[24].getValue() != '' ) { $('#BawlCustomInsert' + 25).removeClass('BawlNoDisplay'); $('#BawlCustomInsert' + 26).removeClass('BawlNoDisplay'); $('#BawlCustomInsert' + 27).removeClass('BawlNoDisplay'); $('#BawlCustomInsert' + 28).removeClass('BawlNoDisplay'); $('#BawlCustomInsert' + 29).removeClass('BawlNoDisplay') } } );
}
if ( int == 4 ) { Bawl.customInsertThatRunTextInput[4].on('change', function() { if ( Bawl.customInsertThatRunTextInput[4].getValue() != '' ) { $('#BawlCustomInsertThatRun' + 5).removeClass('BawlNoDisplay'); $('#BawlCustomInsertThatRun' + 6).removeClass('BawlNoDisplay'); $('#BawlCustomInsertThatRun' + 7).removeClass('BawlNoDisplay'); $('#BawlCustomInsertThatRun' + 8).removeClass('BawlNoDisplay'); $('#BawlCustomInsertThatRun' + 9).removeClass('BawlNoDisplay') } } ); //this isn't very pretty but I'm not sure how else to solve it. You can't just call int because that'll be 10 by the time you press a button
} else if ( int == 9 ) { Bawl.customInsertThatRunTextInput[9].on('change', function() { if ( Bawl.customInsertThatRunTextInput[9].getValue() != '' ) { $('#BawlCustomInsertThatRun' + 10).removeClass('BawlNoDisplay'); $('#BawlCustomInsertThatRun' + 11).removeClass('BawlNoDisplay'); $('#BawlCustomInsertThatRun' + 12).removeClass('BawlNoDisplay'); $('#BawlCustomInsertThatRun' + 13).removeClass('BawlNoDisplay'); $('#BawlCustomInsertThatRun' + 14).removeClass('BawlNoDisplay') } } );
} else if ( int == 14 ) { Bawl.customInsertThatRunTextInput[14].on('change', function() { if ( Bawl.customInsertThatRunTextInput[14].getValue() != '' ) { $('#BawlCustomInsertThatRun' + 15).removeClass('BawlNoDisplay'); $('#BawlCustomInsertThatRun' + 16).removeClass('BawlNoDisplay'); $('#BawlCustomInsertThatRun' + 17).removeClass('BawlNoDisplay'); $('#BawlCustomInsertThatRun' + 18).removeClass('BawlNoDisplay'); $('#BawlCustomInsertThatRun' + 19).removeClass('BawlNoDisplay') } } );
} else if ( int == 19 ) { Bawl.customInsertThatRunTextInput[19].on('change', function() { if ( Bawl.customInsertThatRunTextInput[19].getValue() != '' ) { $('#BawlCustomInsertThatRun' + 20).removeClass('BawlNoDisplay'); $('#BawlCustomInsertThatRun' + 21).removeClass('BawlNoDisplay'); $('#BawlCustomInsertThatRun' + 22).removeClass('BawlNoDisplay'); $('#BawlCustomInsertThatRun' + 23).removeClass('BawlNoDisplay'); $('#BawlCustomInsertThatRun' + 24).removeClass('BawlNoDisplay') } } );
} else if ( int == 24 ) { Bawl.customInsertThatRunTextInput[24].on('change', function() { if ( Bawl.customInsertThatRunTextInput[24].getValue() != '' ) { $('#BawlCustomInsertThatRun' + 25).removeClass('BawlNoDisplay'); $('#BawlCustomInsertThatRun' + 26).removeClass('BawlNoDisplay'); $('#BawlCustomInsertThatRun' + 27).removeClass('BawlNoDisplay'); $('#BawlCustomInsertThatRun' + 28).removeClass('BawlNoDisplay'); $('#BawlCustomInsertThatRun' + 29).removeClass('BawlNoDisplay') } } );
}
$('#BawlPrefenableCIFieldLayout').append(Bawl.customInsertTextInput[int].$element);
$('#BawlPrefenableCIThatRunFieldLayout').append(Bawl.customInsertThatRunTextInput[int].$element);
} //end for loop
}; //end function opensettings
Bawl.UISettingsButton.on('click', Bawl.openSettings);
} //end there is no reply form yet, create one
}; //end Bawl.openReplyForm
Bawl.timestampToTimeAsInSig = function(origTimestamp, timezone) { //convert timestamp like 2021-12-11T14:29:00.000Z to whatever is found in signatures.
if ( origTimestamp.match(/^[0-9]*$/) ) { // timestamp consists of only numbers, indicating this is locator timestamp. locator timestamp don't require any kind of conversion
return origTimestamp;
}
Bawl.origTimestamp = origTimestamp.replace(/Z.*/, 'Z'); // when the ID isn't unique numbers get added like data-mw-comment='{"type":"comment","level":10,"id":"c-Alexis_Jazz-2022-01-08T22:48:00.000Z-1989-2022-01-08T21:09:00.000Z","replies":["c-1989-2022-01-09T03:42:00.000Z-Alexis_Jazz-2022-01-08T22:48:00.000Z","c-1989-2022-01-09T03:42:00.000Z-Alexis_Jazz-2022-01-08T22:48:00.000Z-1"],"timestamp":"2022-01-08T22:48:00.000Z","author":"Alexis Jazz"}'
if ( typeof timezone != 'undefined' ) {
Bawl.targetTimezone = timezone;
} else {
Bawl.targetTimezone = Bawl.wikiTimezone;
}
Bawl.origTime = new Date(Bawl.origTimestamp).toLocaleString("en-GB", {timeZone: Bawl.targetTimezone});
Bawl.monthName = Bawl.origTime.match(/[0-3][0-9]\/0?([1-9]?[0-9])\//)[1];
Bawl.monthName = Bawl.monthNames[Bawl.monthName];
return Bawl.origTime.replace(/(0?)([1-3]?)([0-9])\/([0-1][0-9])\/([0-9]{4}), (0?)([1-2]?)([0-9])\:(0?)([0-9]?)([0-9])\:[0-6][0-9]/, Bawl.timestampFormat).replace('MONTHNAME', Bawl.monthName);
};
Bawl.getSectionByNum = function(wikitext, num) {
Bawl.dbg('get section #' + num);
Bawl.sectionByNumSplit = '\n' + wikitext.replace(/(^|\n)\=/g, '$1==');
Bawl.sectionByNumSplit = Bawl.sectionByNumSplit.split('\n=');
if ( Bawl.sectionByNumSplit[num] ) {
Bawl.sectionByNumHeaderLevel = Bawl.sectionByNumSplit[num].match(/^[\=]*/)[0].length;
Bawl.sectionByNumFoundEnd = 0;
Bawl.sectionByNumWikiText = Bawl.sectionByNumSplit[num];
for (int = 0; int < Bawl.sectionByNumSplit.length; int++) {
if ( int >= num && Bawl.sectionByNumSplit[int].match(/^[\=]*/)[0].length > Bawl.sectionByNumHeaderLevel && Bawl.sectionByNumFoundEnd == 0 ) {
Bawl.sectionByNumWikiText = Bawl.sectionByNumWikiText + Bawl.sectionByNumSplit[int];
} else if ( int >= num && Bawl.sectionByNumSplit[int].match(/^[\=]*/)[0].length <= Bawl.sectionByNumHeaderLevel ) {
Bawl.sectionByNumFoundEnd = 1;
}
}
return Bawl.sectionByNumWikiText.replace(/^\n*/, '').replace(/\n*$/, '');
} else {
return null;
}
};
Bawl.repairWikiText = function(text) {
Bawl.dbg('look for a time (like 12:00) followed by more than one newline followed by an indented message and reduce the number of newlines to one. Otherwise replies to the that first post will go right under that post which is strictly speaking correct behavior (which is why I refuse to correct THAT), but not desired. Also: fuck you DiscussionTools.');
return text.replace(/([0-9]{1,2}:[0-5][0-9].*)[\n]{2,}([\\:\\*\\#])/g, '$1\n$2');
};
Bawl.repairTagImbalance = function(text) {
Bawl.dbg('check for unbalanced \'\', \'\'\', <i>, <b>, <s> and <span> and return an appropriate set of closing tags.');
if ( text && Bawl.replyLinkParamsOpened.type != 'edit' ) {
Bawl.balancingTags = '';
Bawl.balancingTextCleaned = text.replace(/\<nowiki\>[^]*\<\/nowiki\>/gm, '').replace(/\{\{([^\{\}]|[\{\}][^\{\}])*\}\}/gm, '').replace(/\{\{([^\{\}]|[\{\}][^\{\}])*\}\}/gm, '').replace(/\{\{([^\{\}]|[\{\}][^\{\}])*\}\}/gm, '').replace(/\{\{([^\{\}]|[\{\}][^\{\}])*\}\}/gm, '').replace(/\{\{([^\{\}]|[\{\}][^\{\}])*\}\}/gm, '');
for (int = 0; int < 10; int++) { //removing complete tag combinations in the right order. times 10 to also catch nested tags
Bawl.balancingTextCleaned = Bawl.balancingTextCleaned.replace(/\<(?![\/]?[bis]\>|[\/]?span( [^>]*)?)/g, '').replace(/\<span( [^\>]*)?\>([^\<]|\<[\/]?[bis]\>)*\<\/span\>/gmi, '$2').replace(/\<b( [^\>]*)?\>([^\<]*|\<[\/]?span[^\>]*\>|\<[\/]?[is]\>)*\<\/b\>/gmi, '$2').replace(/\<i( [^\>]*)?\>([^\<]*|\<[\/]?[bs]\>|\<[\/]?span[^\>]*\>)*\<\/i\>/gmi, '$2').replace(/\<s( [^\>]*)?\>([^\<]*|\<[\/]?[bi]\>|\<[\/]?span[^\>]*\>)*\<\/s\>/gmi, '$2');
}
Bawl.dbg('text that will be checked for unbalanced tags:\n' + Bawl.balancingTextCleaned);
Bawl.balancingOperations = 0; //prevent infinite loops in case something is screwed up
Bawl.balancingTextTwoSingleQuotes = Bawl.balancingTextCleaned.match(/(^|[^\'])\'\'($|[^\'])/g);
if ( Bawl.balancingTextTwoSingleQuotes ) { Bawl.balancingTextTwoSingleQuotes = Bawl.balancingTextTwoSingleQuotes.length};
Bawl.balancingTextThreeSingleQuotes = Bawl.balancingTextCleaned.match(/(^|[^\'])\'\'\'($|[^\'])/g);
if ( Bawl.balancingTextThreeSingleQuotes ) { Bawl.balancingTextThreeSingleQuotes = Bawl.balancingTextThreeSingleQuotes.length};
if ( Bawl.balancingTextTwoSingleQuotes / 2 != (Bawl.balancingTextTwoSingleQuotes / 2).toFixed() ) {
Bawl.balancingOperations = Bawl.balancingOperations + 1;
Bawl.dbg('adding closing \'\' tag (' + Bawl.balancingOperations + ' tags added)');
Bawl.balancingTags = Bawl.balancingTags + '\'\'';
}
if ( Bawl.balancingTextThreeSingleQuotes / 2 != (Bawl.balancingTextTwoSingleQuotes / 2).toFixed() ) {
Bawl.balancingOperations = Bawl.balancingOperations + 1;
Bawl.dbg('adding closing \'\'\' tag (' + Bawl.balancingOperations + ' tags added)');
Bawl.balancingTags = Bawl.balancingTags + '\'\'\'';
}
Bawl.balancingTextOpenSpan = Bawl.balancingTextCleaned.match(/\<span( [^\>]*)?\>/gi);
Bawl.balancingTextOpenB = Bawl.balancingTextCleaned.match(/\<b( [^\>]*)?\>/gi);
Bawl.balancingTextOpenI = Bawl.balancingTextCleaned.match(/\<i( [^\>]*)?\>/gi);
Bawl.balancingTextOpenS = Bawl.balancingTextCleaned.match(/\<s( [^\>]*)?\>/gi);
if ( Bawl.balancingTextOpenSpan ) { Bawl.balancingTextOpenSpan = Bawl.balancingTextOpenSpan.length};
if ( Bawl.balancingTextOpenB ) { Bawl.balancingTextOpenB = Bawl.balancingTextOpenB.length};
if ( Bawl.balancingTextOpenI ) { Bawl.balancingTextOpenI = Bawl.balancingTextOpenI.length};
if ( Bawl.balancingTextOpenS ) { Bawl.balancingTextOpenS = Bawl.balancingTextOpenS.length};
while ( Bawl.balancingOperations < 100 && 0+Bawl.balancingTextOpenSpan > 0 ) {
Bawl.balancingOperations = Bawl.balancingOperations + 1;
Bawl.dbg('adding closing span tag (' + Bawl.balancingOperations + ' tags added)');
Bawl.balancingTextOpenSpan = Bawl.balancingTextOpenSpan - 1;
Bawl.balancingTags = Bawl.balancingTags + '</span>';
}
while ( Bawl.balancingOperations < 100 && 0+Bawl.balancingTextOpenB > 0 ) {
Bawl.balancingOperations = Bawl.balancingOperations + 1;
Bawl.dbg('adding closing B tag (' + Bawl.balancingOperations + ' tags added)');
Bawl.balancingTextOpenB = Bawl.balancingTextOpenB - 1;
Bawl.balancingTags = Bawl.balancingTags + '</b>';
}
while ( Bawl.balancingOperations < 100 && 0+Bawl.balancingTextOpenI > 0 ) {
Bawl.balancingOperations = Bawl.balancingOperations + 1;
Bawl.dbg('adding closing I tag (' + Bawl.balancingOperations + ' tags added)');
Bawl.balancingTextOpenI = Bawl.balancingTextOpenI - 1;
Bawl.balancingTags = Bawl.balancingTags + '</i>';
}
while ( Bawl.balancingOperations < 100 && 0+Bawl.balancingTextOpenS > 0 ) {
Bawl.balancingOperations = Bawl.balancingOperations + 1;
Bawl.dbg('adding closing S tag (' + Bawl.balancingOperations + ' tags added)');
Bawl.balancingTextOpenS = Bawl.balancingTextOpenS - 1;
Bawl.balancingTags = Bawl.balancingTags + '</s>';
}
Bawl.dbg(Bawl.balancingOperations + ' balancing tags added');
return Bawl.balancingTags;
} else {
Bawl.dbg('no text input to balance');
return '';
}
};
Bawl.getMostPopularIndent = function(fullpagetext, sectiontext) {
if ( sectiontext ) {
Bawl.textSearchIndentation = sectiontext;
} else {
Bawl.textSearchIndentation = fullpagetext;
}
Bawl.dbg('find the most popular indentation type');
if ( Bawl.textSearchIndentation.match(/^\#/gm) ) { Bawl.countHashtags = Bawl.textSearchIndentation.match(/^\#/gm).length } else { Bawl.countHashtags = 0 }
if ( Bawl.textSearchIndentation.match(/^:/gm) ) { Bawl.countColons = Bawl.textSearchIndentation.match(/^:/gm).length } else { Bawl.countColons = 0 }
if ( Bawl.textSearchIndentation.match(/^\*/gm) ) { Bawl.countAsterisks = Bawl.textSearchIndentation.match(/^\*/gm).length } else { Bawl.countAsterisks = 0 }
Bawl.countCombined = Bawl.countHashtags + Bawl.countColons + Bawl.countAsterisks;
Bawl.dbg('total: ' + Bawl.countCombined + ', hashtags: ' + Bawl.countHashtags + ', colons: ' + Bawl.countColons + ', asterisks: ' + Bawl.countAsterisks);
if ( Bawl.countAsterisks >= Bawl.countColons && Bawl.countAsterisks >= Bawl.countHashtags && Bawl.countCombined > 0 ) {
Bawl.dbg('the asterisks have it');
return '*';
} else if ( Bawl.countColons >= Bawl.countAsterisks && Bawl.countColons >= Bawl.countHashtags && Bawl.countCombined > 0 ) {
Bawl.dbg('the colons have it');
return ':';
} else if ( Bawl.countHashtags > Bawl.countColons || Bawl.countHashtags > Bawl.countAsterisks && Bawl.countCombined > 0 ) {
Bawl.dbg('the hashtags have it');
return '#';
} else if ( sectiontext ) {
Bawl.dbg('unable to determine indendation for section. try full page.');
return Bawl.getMostPopularIndent(fullpagetext);
} else {
return Bawl.commentTextIndentWikiDefault;
}
};
Bawl.getInsertionPointComment = function(justCurrentPageText, replyLinkParams) {
Bawl.dbg('collect sectiontext, indentation and insertion point of original comment');
Bawl.wikiTextSplitByUserRegExp = new RegExp(':' + Bawl.origReplyTo + '.*' + Bawl.origTimeAsInSig + '.*', 'g');
Bawl.wikiTextSplitByUser = justCurrentPageText.split(Bawl.wikiTextSplitByUserRegExp);
if ( typeof replyLinkParams.seq == 'number' && replyLinkParams.seq <= Bawl.wikiTextSplitByUser.length ) {
Bawl.dbg('there are ' + ( Bawl.wikiTextSplitByUser.length - 1 ) + ' occurences of username "' + Bawl.origReplyTo + '" with timestamp ' + Bawl.origTimeAsInSig + ' on this page');
Bawl.wikiTextUpToSig = '';
for (wikitextseqint = 0; wikitextseqint <= replyLinkParams.seq; wikitextseqint++) {
Bawl.wikiTextUpToSig = Bawl.wikiTextUpToSig + Bawl.wikiTextSplitByUser[wikitextseqint];
}
Bawl.wikiTextNum = Bawl.wikiTextUpToSig.match(/^=.*=[ ]*$/gm);
if ( Bawl.wikiTextNum ) {
Bawl.sectionText = Bawl.getSectionByNum(justCurrentPageText,Bawl.wikiTextNum.length);
} else {
Bawl.dbg('found no section headers in the text leading up to the comment');
Bawl.sectionText = 'SECTIONLESS';
}
Bawl.relevantPrecedingLine = Bawl.wikiTextUpToSig.split(/\n/)[ Bawl.wikiTextUpToSig.split(/\n/).length - 2 ] + '\n';
if ( Bawl.relevantPrecedingLine == '\n' ) { Bawl.relevantPrecedingLine == ''; }
Bawl.relevantCommentNoSig = Bawl.wikiTextUpToSig.split(/\n/)[ Bawl.wikiTextUpToSig.split(/\n/).length - 1 ];
Bawl.relevantCommentSig = justCurrentPageText.match(Bawl.wikiTextSplitByUserRegExp)[replyLinkParams.seq];
Bawl.relevantIndentation = Bawl.relevantCommentNoSig.replace(/([\\:\\*\\#]*).*/, '$1');
Bawl.dbg('returning requested info');
return { 'sectiontext':Bawl.sectionText,'sectionnum':Bawl.wikiTextNum.length,'relevantIndentation':Bawl.relevantIndentation,'relevantComment':Bawl.relevantCommentNoSig + Bawl.relevantCommentSig,'relevantPrecedingLine':Bawl.relevantPrecedingLine};
} else if ( ! Bawl.wikiTextSplitByUser ) {
Bawl.dbg('username+timestamp not found');
return 'ERROR';
} else {
return 'ERRORBAD';
}
};
Bawl.getInsertionPointSection = function(justCurrentPageText, replyLinkParams) {
Bawl.wikiTextSplitBySectionTitleRegExp = new RegExp('(?:^|\n)[=]+[\\[: ]*(?:[^\\|\n]*\\|)?' + replyLinkParams.sectionTitle + '[\\] ]*[=]+', 'gm');
Bawl.wikiTextSplitBySectionTitle = justCurrentPageText.split(Bawl.wikiTextSplitBySectionTitleRegExp);
Bawl.wikiTextUpToHeader = '';
for (wikitextseqint = 0; wikitextseqint <= replyLinkParams.sectionseq; wikitextseqint++) {
Bawl.wikiTextUpToHeader = Bawl.wikiTextUpToHeader + Bawl.wikiTextSplitBySectionTitle[wikitextseqint];
}
Bawl.wikiTextNum = Bawl.wikiTextUpToHeader.match(/^=.*=[ ]*$/gm);
if ( Bawl.wikiTextNum ) {
return { 'sectiontext':Bawl.getSectionByNum(justCurrentPageText,Bawl.wikiTextNum.length + replyLinkParams.sectionseq + 1),'sectionnum':Bawl.wikiTextNum.length + replyLinkParams.sectionseq + 1};
}
};
Bawl.postReply1 = function(replyLinkParams, newCommentsChecked) {
Bawl.dbg('postReply1');
if ( Bawl.UITextInputTitle.getValue() == '' && Bawl.UITextInputTitle.isVisible() ) {
$('#BawlUITextInputTitle').removeClass('BawlShakeIt');
var BawlShakeTitle = setInterval(function () {
clearInterval(BawlShakeTitle);
$('#BawlUITextInputTitle').addClass('BawlShakeIt');
}, 20);
Bawl.dbg('title is empty');
return
}
Bawl.disableForm(true); //disable form so you can't double click
$(document.getElementById('BawlUIReplyButton')).addClass('BawlPendingBlink');
if ( Bawl.settings.checkNewComments == true || newCommentsChecked ) {
Bawl.checkForNewComments(replyLinkParams, 'postreply');
//return //kill it for now, Bawl.checkForNewComments() will call this function again with newCommentsChecked if there are no new comments. todo: actually make it do that
}
Bawl.dbg('get the wikitext of the page we want to add the comment to');
Bawl.currentPageTextParams = {
'action':'query',
'export':'true',
'titles': replyLinkParams.pageTitle,
'prop':'revisions'
}
var currentPageText = new mw.Api();
currentPageText.post(Bawl.currentPageTextParams).done(function(currentPageText)
{
Bawl.dbg(currentPageText);
//should consider adding some error handling here, check currentPageText.warnings, currentPageText.error.code, etc
if ( ! currentPageText.query.pages[-1] ) {
Bawl.dbg('got wikitext');
Bawl.justCurrentPageText = Bawl.repairWikiText(Bawl.getWikitextFromExport(currentPageText.query.export["*"]));
Bawl.currentRevID = currentPageText.query.pages[ Object.keys(currentPageText.query.pages)[0] ].revisions[0].revid;
} else {
Bawl.dbg('response indicates this page doesn\'t exist');
Bawl.justCurrentPageText = '';
Bawl.currentRevID = 0;
}
Bawl.postReply2(Bawl.justCurrentPageText, replyLinkParams, Bawl.currentRevID);
})
}
Bawl.postReply2 = function(justCurrentPageText, replyLinkParams, currentRevID) {
Bawl.progressPlusOne();
Bawl.dbg('postReply2, process comment and actually post it');
if ( replyLinkParams.sectionTitle != "" ) {
Bawl.postCommentSummarySectionLink = '[[#' + replyLinkParams.sectionTitle + '|→' + replyLinkParams.sectionTitle + ']]: ';
} else {
Bawl.postCommentSummarySectionLink = ''; //no section? no link
}
Bawl.origReplyTo = Bawl.escapeRegExp(replyLinkParams.origReplyTo).replace(/ /g, '[_ ]'); //some users sign with [[User:User_Name]], others with [[User:User Name]]
Bawl.origTimeAsInSig = Bawl.timestampToTimeAsInSig(replyLinkParams.origTimestamp);
Bawl.dbg('replyLinkParams:');
Bawl.dbg(replyLinkParams);
Bawl.postCommentParams = {
format: 'json',
action: 'edit',
title: replyLinkParams.pageTitle,
baserevid: currentRevID,
nocreate: true,
watchlist: Bawl.settings.watchlist,
watchlistexpiry: Bawl.settings.watchlistexpiry
};
Bawl.processedComment = Bawl.processComment(Bawl.UITextInput.getValue());
Bawl.dbg('posting type and subtype: ' + replyLinkParams.type + '/' + replyLinkParams.subtype);
if ( replyLinkParams.type == 'comment' && replyLinkParams.subtype != 'anonSectReply' ) {
Bawl.summarySnippetText = '';
if ( Bawl.settings.sumSnippet == true && replyLinkParams.type == 'comment' && Bawl.processedComment ) {
Bawl.snippetRemoveRecipient = new RegExp('^' + Bawl.escapeRegExp(Bawl.replyLinkParamsOpened.origReplyTo) + '[ ,:;]*')
Bawl.snippetForSummary = Bawl.processedComment.replace(/\[\[[^:]*:([^\\|\]]*)\|?\]\]/g, '$1').replace(/\{\{[^\\|\\\}\\\{]*\|([^\\\}]*)(\|[^\}]*)*\}\}/g, '$1').replace(/\[\[[^\\|]*\\|([^\\]])+\\]\\]/g, '$1').replace(/'''/g, '').replace(/''/g, '').replace(/^[\\:\\*\\#]*/, '').replace(/ *\{\{BawlCmt.*/, '').replace(Bawl.snippetRemoveRecipient, '');
if ( Bawl.snippetForSummary.length > 5 ) {
Bawl.snippetForSummaryShort = Bawl.snippetForSummary;
if ( Bawl.snippetForSummary.length > 50 ) {
Bawl.snippetForSummaryShort = Bawl.snippetForSummary.slice(0,40) + '...';
}
Bawl.summarySnippetText = ': ' + Bawl.snippetForSummaryShort;
}
}
Bawl.postCommentParams.summary = Bawl.postCommentSummarySectionLink + Bawl.wikiMsgs.postCommentSummaryPost.replace(/USER/g, Bawl.escapeReplacement(replyLinkParams.origReplyTo) + Bawl.summarySnippetText);
Bawl.origCmtData = Bawl.getInsertionPointComment(justCurrentPageText, replyLinkParams);
Bawl.progressPlusOne();
if (Bawl.origCmtData.relevantIndentation.length != 0) {
Bawl.dbg('repeating the last character of the indentation of the previous message so e.g. ::* becomes ::**');
Bawl.commentTextIndent = Bawl.origCmtData.relevantIndentation + Bawl.origCmtData.relevantIndentation.slice(Bawl.origCmtData.relevantIndentation.length - 1,) + ' ';
Bawl.dbg('new indendation: ' + Bawl.commentTextIndent);
} else {
Bawl.commentTextIndent = Bawl.getMostPopularIndent(justCurrentPageText, Bawl.origCmtData.sectiontext) + ' ';
}
if ( Bawl.origCmtData.sectiontext != 'SECTIONLESS' ) {
Bawl.postCommentParams.section = Bawl.origCmtData.sectionnum;
Bawl.originalWikiText = Bawl.origCmtData.sectiontext;
} else {
Bawl.originalWikiText = justCurrentPageText;
}
Bawl.origCmtLevelPlusOne = Bawl.origCmtData.relevantIndentation.length + 1;
Bawl.replyBelowThisRegExp = new RegExp('(' + Bawl.escapeRegExp(Bawl.origCmtData.relevantPrecedingLine + Bawl.origCmtData.relevantComment) + ')((\n[\\:\\*\\#]{' + Bawl.origCmtLevelPlusOne + ',}([^\\:\\*\\#\\=]|[$]).*)*)', 'm');
if ( ! Bawl.originalWikiText.match(Bawl.replyBelowThisRegExp) ) {
Bawl.replyBelowThisRegExp = new RegExp('(' + Bawl.escapeRegExp(Bawl.origCmtData.relevantComment) + ')((\n[\\:\\*\\#]{' + Bawl.origCmtLevelPlusOne + ',}([^\\:\\*\\#\\=]|[$]).*)*)', 'm');
}
Bawl.replyBelowThis = Bawl.originalWikiText.match(Bawl.replyBelowThisRegExp)[0];
Bawl.postCommentParams.text = Bawl.originalWikiText.replace(Bawl.replyBelowThis, Bawl.replyBelowThis + '\n' + Bawl.commentTextIndent + Bawl.processedComment + Bawl.repairTagImbalance(Bawl.processedComment));
} else if ( replyLinkParams.subtype == 'anonSectReply' || replyLinkParams.type == 'BCL' ) {
Bawl.postCommentParams.summary = Bawl.postCommentSummarySectionLink + Bawl.wikiMsgs.postCommentSummaryPost.replace(/USER/g, Bawl.escapeReplacement(replyLinkParams.sectionTitle));
Bawl.origCmtData = Bawl.getInsertionPointSection(justCurrentPageText, replyLinkParams);
Bawl.commentTextIndent = Bawl.getMostPopularIndent(justCurrentPageText, Bawl.origCmtData.sectiontext) + ' ';
Bawl.postCommentParams.section = Bawl.origCmtData.sectionnum;
if ( replyLinkParams.type == 'BCL' ) {
Bawl.postCommentParams.summary = Bawl.postCommentSummarySectionLink + Bawl.summaryCredit;
if ( replyLinkParams.subtype == 'page' ) {
delete Bawl.postCommentParams.section;
}
if ( replyLinkParams.indentation && replyLinkParams.indentation.match(/^\#\:\*$/) ) {
Bawl.commentTextIndent = replyLinkParams.indentation + ' ';
}
}
Bawl.postCommentParams.appendtext = '\n' + Bawl.commentTextIndent + Bawl.processedComment + Bawl.repairTagImbalance(Bawl.processedComment);
} else if ( replyLinkParams.type == 'heading' ) {
Bawl.postCommentParams.summary = Bawl.postCommentSummarySectionLink + Bawl.wikiMsgs.postSubsectionSummaryPost.replace(/SUBSECTION/g, Bawl.escapeReplacement(Bawl.UITextInputTitle.getValue()));
Bawl.origSectData = Bawl.getInsertionPointSection(justCurrentPageText, replyLinkParams);
Bawl.postCommentParams.section = Bawl.origSectData.sectionnum;
Bawl.newSectionLevel = Bawl.origSectData.sectiontext.match(/^[=]*/)[0];
if ( Bawl.newSectionLevel.length < 6 ) {
Bawl.newSectionLevel = Bawl.newSectionLevel + '=';
}
Bawl.postCommentParams.appendtext = '\n' + Bawl.newSectionLevel + Bawl.UITextInputTitle.getValue() + Bawl.newSectionLevel + '\n' + Bawl.processedComment + Bawl.repairTagImbalance(Bawl.processedComment);
} else if ( replyLinkParams.type == 'newsection' ) {
Bawl.postCommentParams.summary = Bawl.wikiMsgs.postCommentSummaryNewSection.replace('SUMMARY', '').replace(/NEWSECTION/g, Bawl.escapeReplacement(Bawl.UITextInputTitle.getValue()));
if ( replyLinkParams.summary ) {
Bawl.dbg('insert InputBox provided summary');
Bawl.postCommentParams.summary = Bawl.wikiMsgs.postCommentSummaryNewSection.replace('SUMMARY', ' / ' + replyLinkParams.summary).replace(/NEWSECTION/g, Bawl.escapeReplacement(Bawl.UITextInputTitle.getValue()));
}
if ( replyLinkParams.minor == true ) {
Bawl.dbg('adding InputBox specified minor flag');
Bawl.postCommentParams.minor = true;
}
Bawl.postCommentParams.section = 'new';
Bawl.postCommentParams.sectiontitle = Bawl.UITextInputTitle.getValue();
Bawl.postCommentParams.text = Bawl.processedComment + Bawl.repairTagImbalance(Bawl.processedComment);
delete Bawl.postCommentParams.nocreate;
} else if ( replyLinkParams.type == 'edit' ) {
Bawl.postCommentParams.summary = Bawl.postCommentSummarySectionLink + Bawl.wikiMsgs.editCommentSummary;
Bawl.origCmtData = Bawl.getInsertionPointComment(justCurrentPageText, replyLinkParams);
if ( Bawl.origCmtData.sectiontext != 'SECTIONLESS' ) {
Bawl.postCommentParams.section = Bawl.origCmtData.sectionnum;
Bawl.originalWikiText = Bawl.origCmtData.sectiontext;
} else {
Bawl.originalWikiText = justCurrentPageText;
}
Bawl.commentToReplace = Bawl.origCmtData.relevantComment.replace(/([\\:\\*\\#]*).*/, '$1');
Bawl.dbg('getting usernames mentioned in this comment (WP:PINGFIX)');
Bawl.usernamesInEditedComment = Bawl.extractUsernames(Bawl.UITextInput.getValue());
Bawl.usernamesInUneditedComment = Bawl.extractUsernames(Bawl.wikiTextForEditComment);
Bawl.userMentionInSummary = '';
for (int = 0; int < Bawl.usernamesInEditedComment.length; int++) {
Bawl.dbg('checking ' + Bawl.usernamesInEditedComment[int]);
if ( Bawl.usernamesInEditedComment[int] && Bawl.usernamesInUneditedComment.indexOf(Bawl.usernamesInEditedComment[int]) == -1 && ! Bawl.userMentionInSummary.match(Bawl.usernamesInEditedComment[int] + '\\|') ) {
Bawl.userMentionInSummary = Bawl.userMentionInSummary + ', [[' + mw.config.get('wgFormattedNamespaces')[2] + ':' + Bawl.usernamesInEditedComment[int] + '|' + Bawl.usernamesInEditedComment[int] + ']]';
}
}
if ( Bawl.userMentionInSummary != '' ) {
Bawl.postCommentParams.summary = Bawl.postCommentParams.summary.replace(Bawl.summaryCredit, ' (' + Bawl.userMentionInSummary.replace(/^, /, '') + ')' + Bawl.summaryCredit);
}
Bawl.postCommentParams.text = Bawl.originalWikiText.replace(Bawl.wikiTextForEditComment, Bawl.processedComment);
} else if ( replyLinkParams.type == 'editFullPage' ) {
Bawl.postCommentParams.summary = Bawl.summaryCredit;
Bawl.postCommentParams.text = Bawl.processedComment;
}
Bawl.progressPlusOne();
if ( justCurrentPageText != Bawl.wikiTextWithComment || Bawl.postCommentParams.appendtext ) {
if ( ! Bawl.postCommentParams.appendtext ) {
Bawl.dbg('generated wikitext is different from the current wikitext, so it can be posted (without being a null edit). wikitext:\n' + Bawl.postCommentParams.text);
}
Bawl.dbg(Bawl.postCommentParams);
if ( Bawl.dryRunOnce == true ) {
Bawl.dryRunOnce = false;
Bawl.dbg('dry run enabled, skipped API call');
Bawl.disableForm(false); //re-enable form
$(document.getElementById('BawlUIReplyButton')).removeClass('BawlPendingBlink');
} else {
Bawl.doAPICall(Bawl.postCommentParams);
if ( Bawl.settings.afterPost == 'parsecomment' ) {
delete Bawl.postedCommentParsed;
Bawl.doPreview('previewposted');
}
}
} else {
Bawl.progressPlusOne();
Bawl.dbg('couldn\'t insert comment, wikitext same as current text, possibly insertion point failure');
Bawl.disableForm(false); //re-enable form
$(document.getElementById('BawlUIReplyButton')).removeClass('BawlPendingBlink');
}
}; //end Bawl.postReply2
Bawl.addedReplyLinks = [];
Bawl.sectionsFound = [];
Bawl.addReplyLinkTo = function(replyLinkParams) {
if ( Bawl.settings.RLmasq == true && mw.config.get('wgUserLanguage') == 'pt' ) { //afaik reply-link only ever had a translation in Portuguese
Bawl.svgBawlIcon = '<span style="color: #000"(</span><span style="color: #0645ad">responder</span><span style="color: #000">)</span>';
} else if ( Bawl.settings.RLmasq == true ) {
Bawl.svgBawlIcon = '<span style="color: #000">(</span><span style="color: #0645ad">reply</span><span style="color: #000">)</span>';
}
if ( replyLinkParams.type == 'comment' && replyLinkParams.subtype != 'anonSectReply' ) {
Bawl.replyUserDate = replyLinkParams.origReplyTo + replyLinkParams.origTimestamp;
for (seqint = 0; seqint < 100; seqint++) {
Bawl.dbg('make record of the username+timestamp so other comments with the same data can be identified this is #' + seqint);
if ( Bawl.addedReplyLinks.indexOf(Bawl.replyUserDate + '-' + seqint) == -1 ) {
Bawl.addedReplyLinks.push(Bawl.replyUserDate + '-' + seqint);
replyLinkParams.seq = seqint;
break;
}
}
}
replyLinkParams.sectionseq = Bawl.sectionseq;
Bawl.replyLinkDebugInfo = '';
if ( Bawl.settings.debug == true && int ) {
Bawl.replyLinkDebugInfo = ' (' + int + ')';
if ( ( replyLinkParams.type == 'comment' || replyLinkParams.type == 'edit' ) && replyLinkParams.origTimestamp.match(/^[0-9]*$/) ) { //Bawl locator
Bawl.replyLinkDebugInfo = Bawl.replyLinkDebugInfo + ' (locator)';
}
}
if ( replyLinkParams.type == 'comment' ) {
Bawl.replyLinkText = '<span title="' + Bawl.msgs.replyToTitle.replace('USER', Bawl.escapeHTML(replyLinkParams.origReplyTo)) + Bawl.replyLinkDebugInfo + '" class="BawlReplyLinkIcon BawlReplyLink">' + Bawl.svgBawlIcon + '</span>';
} else if ( replyLinkParams.type == 'heading' ) {
Bawl.replyLinkText = '<span title="' + Bawl.msgs.newSectionTitle + Bawl.replyLinkDebugInfo + '" class="BawlReplyLinkIcon BawlReplyLink">' + Bawl.svgBawlIconNewSection + '</span>';
} else if ( replyLinkParams.type == 'edit' ) {
Bawl.replyLinkText = '<span title="' + Bawl.msgs.editTitle + Bawl.replyLinkDebugInfo + '" class="BawlReplyLinkIcon BawlReplyLink">' + Bawl.svgBawlIconEdit + '</span>';
}
Bawl.replyLinkHTML = document.createElement('span');
Bawl.replyLinkHTML.id = 'bawlLink-' + replyLinkParams.id
Bawl.replyLinkHTML.innerHTML = '<a class="BawlReplyLink" onclick="Bawl.openReplyForm(\'' + encodeURIComponent(JSON.stringify(replyLinkParams)).replace(/\'/g, '%27') + '\')">' + Bawl.replyLinkText + '</a>';
if ( replyLinkParams.type == 'comment' && Bawl.settings.dateLinksIcon == true ) {
Bawl.dbg('try to add link to comment');
Bawl.linkedSignaturedate = document.createElement('a');
Bawl.linkedSignaturedate.href = '#' + encodeURIComponent(Bawl.replyLinkParams.id);
Bawl.linkedSignaturedate.innerHTML = ' 🔗 ';
Bawl.linkedSignaturedate.classList = [ 'BawlReplyLink' ];
Bawl.replyLinkHTML.prepend(Bawl.linkedSignaturedate);
}
if ( ( replyLinkParams.type == 'comment' || replyLinkParams.type == 'edit' ) && replyLinkParams.origTimestamp.match(/^[0-9]*$/) ) { //Bawl locator
Bawl.dbg('insert link to add comment (using locator)');
$('.bawlprocess')[int].append(Bawl.replyLinkHTML);
} else if ( replyLinkParams.type == 'comment' ) {
Bawl.dbg('insert link to add comment (' + int + ')');
$('.bawlprocess')[int].prepend(Bawl.replyLinkHTML);
} else if ( replyLinkParams.type == 'edit' ) {
Bawl.dbg('insert link to edit comment (' + int + ')' + ' bawlLink-' + replyLinkParams.id);
if ( replyLinkParams.preview == true ) {
$('#Bawlpreviewlinks').append(Bawl.replyLinkHTML);
} else {
$('.bawlprocess')[int].append(Bawl.replyLinkHTML);
}
} else if ( replyLinkParams.type == 'heading' ) {
Bawl.dbg('insert link to add subsection (' + int + ')');
$('.bawlprocess')[int].append(Bawl.replyLinkHTML);
}
if ( Bawl.replyLinkParams.type == 'comment' && Bawl.replyLinkParams.origReplyTo == mw.config.get('wgUserName') && replyLinkParams.preview != true && Bawl.settings.editLinks == true ) { //wait, I know this fucker
Bawl.dbg('add edit link');
Bawl.replyLinkParams.type = 'edit';
Bawl.addReplyLinkTo(Bawl.replyLinkParams);
}
};
//adding classes to elements we can extract the page title to edit from (which we extract from the "edit" link next to the section header) and DiscussionTools replylink-buttons (which we extract metadata from and append Bawl to)
//this allows us to cycle through both in one loop in the original order, so the right page title can be added to each Bawl reply link
$(document.getElementsByClassName('mw-editsection')).addClass('bawlprocess'); //section edit link to extract the name of the page to be edited in case of transcluded discussions
$(document.getElementsByClassName('ext-discussiontools-init-replylink-buttons')).addClass('bawlprocess'); //insertion of comment link and extraction of comment metadata
$(document.getElementsByClassName('mw-headline')).addClass('bawlprocess'); // h3/h4 sections
$(document.getElementsByClassName('BawlCmt')).addClass('bawlprocess'); // Bawl locators
$(document.getElementsByClassName('commentbox')).addClass('bawlprocess'); // InputBox
$(document.getElementsByClassName('Bawl-comment-link')).addClass('bawlprocess'); // Special Bawl-comment-link that either opens the reply form or points to a &withJS page to load Bawl
Bawl.pageTitleToEdit = mw.config.get('wgPageName'); //in case the first comment comes before any section edit link we define the [[Page title]]
Bawl.sectionTitle = ""; //same for the ==Section title==
if ( Bawl.settings.nSecLink == true ) {
Bawl.replyLinkParams = {
'id':'newSectionForm',
'type':'newsection',
'pageTitle': mw.config.get('wgPageName'),
'sectionTitle':'NO-VALUE-PLEASE-IGNORE',
'origReplyTo':'NO-VALUE-PLEASE-IGNORE',
'origTimestamp':'2000-01-01T00:00:00.000Z',
}
//skin support: replying and new sections should work everywhere, new subsections (dealth with further down) should work on Vector, timeless, monobook and modern. Not on Minerva
if ( (mw.config.get('skin') == 'vector' || mw.config.get('skin') == 'vector-2022') && typeof $('#ca-addsection')[0] != "undefined" ) {
$('#ca-addsection')[0].outerHTML = $('#ca-addsection')[0].outerHTML + $('#ca-addsection')[0].outerHTML.replace('ca-addsection', 'ca-bawladdsection').replace(/href="[^"]*"/, 'onclick="Bawl.openReplyForm(\'' + encodeURIComponent(JSON.stringify(Bawl.replyLinkParams)).replace(/\'/g, '%27') + '\')"').replace('++', '+9').replace('accesskey="+"', 'accesskey="9"').replace(/<span>.*<\/span>/, '<span>' + Bawl.svgBawlIcon + '</span>');
} else if ( mw.config.get('skin') == 'minerva' && typeof $('#ca-edit')[0] != "undefined" ) {
$('#ca-edit')[0].outerHTML = $('#ca-edit')[0].outerHTML + $('#ca-edit')[0].outerHTML.replace('ca-edit', 'ca-bawladdsection').replace(/href="[^"]*"/, 'style="background-image: url(' + Bawl.svgBawlIconData + ');background-repeat: no-repeat" onclick="Bawl.openReplyForm(\'' + encodeURIComponent(JSON.stringify(Bawl.replyLinkParams)).replace(/\'/g, '%27') + '\')"').replace('++', '+9').replace('accesskey="+"', 'accesskey="9"').replace(/(\<a.*\>)([^\<]*)(\<\/a\>)/, '$1' + '$3').replace(/title="[^"]*"/, 'title="' + Bawl.msgs.BawlAddSectionToolbar + '"').replace('mw-ui-icon-wikimedia-edit-base20', '');
} else if ( ( mw.config.get('skin') == 'modern' && typeof $('#ca-addsection')[0] != "undefined" ) || ( mw.config.get('skin') == 'monobook' && typeof $('#ca-addsection')[0] != "undefined" ) ) {
$('#ca-addsection')[0].outerHTML = $('#ca-addsection')[0].outerHTML + $('#ca-addsection')[0].outerHTML.replace('ca-addsection', 'ca-bawladdsection').replace(/href="[^"]*"/, 'onclick="Bawl.openReplyForm(\'' + encodeURIComponent(JSON.stringify(Bawl.replyLinkParams)).replace(/\'/g, '%27') + '\')"').replace('++', '+9').replace('accesskey="+"', 'accesskey="9"').replace(/>New section</, '>Bawl!<');
} else if ( mw.config.get('skin') == 'timeless' && typeof $('#ca-addsection')[0] != "undefined" ) {
$('#ca-addsection')[0].outerHTML = $('#ca-addsection')[0].outerHTML + $('#ca-addsection')[0].outerHTML.replace('ca-addsection', 'ca-bawladdsection').replace(/href="[^"]*"/, 'onclick="Bawl.openReplyForm(\'' + encodeURIComponent(JSON.stringify(Bawl.replyLinkParams)).replace(/\'/g, '%27') + '\')"').replace('++', '+9').replace('accesskey="+"', 'accesskey="9"').replace(/<span>.*<\/span>/, '<span>' + Bawl.svgBawlIcon + '</span>');
}
$('#mw-content-text').append('<div id="bawlForm-newSectionForm" class="BawlNoDisplay BawlForm"><\/div>');
}
if ( Bawl.settings.enableEverywhere == true ) {
Bawl.replyLinkParams = {
'id':'editFullPage',
'type':'editFullPage',
'pageTitle': mw.config.get('wgPageName'),
}
if ( (mw.config.get('skin') == 'vector' || mw.config.get('skin') == 'vector-2022') && typeof $('#ca-edit')[0] != "undefined" ) {
$('#ca-edit')[0].outerHTML = $('#ca-edit')[0].outerHTML + $('#ca-edit')[0].outerHTML.replace('ca-edit', 'ca-bawleditFullPage').replace(/href="[^"]*"/, 'onclick="Bawl.openReplyForm(\'' + encodeURIComponent(JSON.stringify(Bawl.replyLinkParams)).replace(/\'/g, '%27') + '\')"').replace('++', '+0').replace('accesskey="+"', 'accesskey="0"').replace(/<span>.*<\/span>/, '<span>' + Bawl.svgBawlIconEdit + '</span>');
} else if ( mw.config.get('skin') == 'minerva' && typeof $('#ca-edit')[0] != "undefined" ) {
$('#ca-edit')[0].outerHTML = $('#ca-edit')[0].outerHTML + $('#ca-edit')[0].outerHTML.replace('ca-edit', 'ca-bawleditFullPage').replace(/href="[^"]*"/, 'style="background-image: url(' + Bawl.svgBawlIconEditEditData + ');background-repeat: no-repeat" onclick="Bawl.openReplyForm(\'' + encodeURIComponent(JSON.stringify(Bawl.replyLinkParams)).replace(/\'/g, '%27') + '\')"').replace('++', '+0').replace('accesskey="+"', 'accesskey="0"').replace(/(\<a.*\>)([^\<]*)(\<\/a\>)/, '$1' + '$3').replace(/title="[^"]*"/, 'title="' + Bawl.msgs.bawleditFullPageToolbar + '"').replace('mw-ui-icon-wikimedia-edit-base20', '');
} else if ( ( mw.config.get('skin') == 'modern' && typeof $('#ca-edit')[0] != "undefined" ) || ( mw.config.get('skin') == 'monobook' && typeof $('#ca-edit')[0] != "undefined" ) ) {
$('#ca-edit')[0].outerHTML = $('#ca-edit')[0].outerHTML + $('#ca-edit')[0].outerHTML.replace('ca-edit', 'ca-bawleditFullPage').replace(/href="[^"]*"/, 'onclick="Bawl.openReplyForm(\'' + encodeURIComponent(JSON.stringify(Bawl.replyLinkParams)).replace(/\'/g, '%27') + '\')"').replace('++', '+0').replace('accesskey="+"', 'accesskey="0"').replace(/>([^<]*)</, '>Bawl!<');
} else if ( mw.config.get('skin') == 'timeless' && typeof $('#ca-edit')[0] != "undefined" ) {
$('#ca-edit')[0].outerHTML = $('#ca-edit')[0].outerHTML + $('#ca-edit')[0].outerHTML.replace('ca-edit', 'ca-bawleditFullPage').replace(/href="[^"]*"/, 'onclick="Bawl.openReplyForm(\'' + encodeURIComponent(JSON.stringify(Bawl.replyLinkParams)).replace(/\'/g, '%27') + '\')"').replace('++', '+0').replace('accesskey="+"', 'accesskey="0"').replace(/<span>.*<\/span>/, '<span>' + Bawl.svgBawlIconEdit + '</span>');
}
$('#mw-content-text').prepend('<div id="bawlForm-editFullPage" class="BawlNoDisplay BawlForm"><\/div>');
}
$('.ext-discussiontools-init-replylink-buttons').addClass('BawlYesDisplay');
if ( Bawl.settings.hideThePain == true ) {
$('.ext-discussiontools-init-replylink-bracket').addClass('BawlNoDisplay');
$('.ext-discussiontools-init-replylink-reply').addClass('BawlNoDisplay');
$('#ca-addsection').addClass('BawlNoDisplay');
}
Bawl.stopwatchAddLinks1 = new Date().getTime();
for (int = 0; int < document.getElementsByClassName('bawlprocess').length; int++) {
Bawl.dbg('Process element #' + int + '/' + (document.getElementsByClassName('bawlprocess').length - 1) + ' with "bawlprocess" class');
if ( Bawl.replyToSectionLinkNeeded && ( ( typeof document.getElementsByClassName('bawlprocess')[int].className != "undefined" && document.getElementsByClassName('bawlprocess')[int].className.match('mw-headline') ) || ! document.getElementsByClassName('bawlprocess')[int+1] ) ) {
Bawl.dbg('found a new section or the last element to be processed. adding reply to section link');
Bawl.replyLinkParams = {
'int': int,
'type':'comment',
'subtype':'anonSectReply',
'sectionseq':Bawl.sectionseq,
'id':'anonSectReply:' + Bawl.pageTitleToEdit + ':' + Bawl.sectionTitle + ':' + Bawl.sectionseq,
'pageTitle': Bawl.pageTitleToEdit,
'sectionTitle': Bawl.sectionTitle,
'origReplyTo':'anonSectReply',
'origTimestamp':'',
}
Bawl.replyToSectionButton = document.createElement('div');
Bawl.replyToSectionButton.style = 'width:100%;margin-bottom:0.5em';
Bawl.replyToSectionButton.id = Bawl.escapeHTML(Bawl.replyLinkParams.id);
Bawl.replyToSectionButton.innerHTML = '<a onclick="Bawl.openReplyForm(\'' + encodeURIComponent(JSON.stringify(Bawl.replyLinkParams)) + '\')"><span class="BawlAnonSectReply">' + Bawl.svgBawlIcon + '</span></a>';
if ( ! document.getElementsByClassName('bawlprocess')[int+1] ) {
Bawl.dbg('last element to process, append link');
Bawl.replyToSectionButton.style = 'width:8em;margin-top:0.5em';
document.getElementById('mw-content-text').append(Bawl.replyToSectionButton);
} else {
Bawl.dbg('another section, prepend link');
document.getElementsByClassName('bawlprocess')[int].parentElement.style = 'margin-top:0.5em'; //reduce the padding from the section element
document.getElementsByClassName('bawlprocess')[int].prepend(Bawl.replyToSectionButton);
}
}
if ( document.getElementsByClassName('bawlprocess')[int].childNodes[1] && typeof document.getElementsByClassName('bawlprocess')[int].childNodes[1].dataset != "undefined" && typeof document.getElementsByClassName('bawlprocess')[int].childNodes[1].dataset.mwComment != "undefined" ) { //time to cheat, extract metadata
Bawl.dbg('found a comment to add a link to');
Bawl.formDataset[int] = JSON.parse(document.getElementsByClassName('bawlprocess')[int].childNodes[1].dataset.mwComment);
if ( Bawl.formDataset[int].type == "comment" ) { //only add a link to comments here
Bawl.replyLinkParams = {
'int': int,
'type': Bawl.formDataset[int].type,
'id': Bawl.formDataset[int].id.replace(/'/g, ''),
'pageTitle': Bawl.pageTitleToEdit,
'sectionTitle': Bawl.sectionTitle,
'origReplyTo': Bawl.formDataset[int].author,
'origTimestamp': Bawl.formDataset[int].timestamp,
}
if ( $('.bawlprocess')[int-1] && $('.bawlprocess')[int-1].classList && $('.bawlprocess')[int-1].classList[0] == 'BawlCmt' && decodeURIComponent($('.bawlprocess')[int-1].id.replace(/([^\:]*).*/, '$1')) == Bawl.replyLinkParams.origReplyTo && new Date(new Number($('.bawlprocess')[int-1].id.replace(/([^\:]*)\:([0-9]*).*/, '$2').replace(/[^0-9]*/g, ''))).toLocaleString("en-GB", {timeZone: 'UTC'}).slice(0,-3) == new Date(Bawl.formDataset[int].timestamp).toLocaleString("en-GB", {timeZone: 'UTC'}).slice(0,-3) ) {
Bawl.dbg('previous element is a Bawl locator for the same username+timestamp combo, skipping');
} else {
Bawl.addReplyLinkTo(Bawl.replyLinkParams);
}
if ( Bawl.settings.dateLinks == true ) {
Bawl.dbg('try to add link to comment');
Bawl.signatureTimeStampToLink = Bawl.timestampToTimeAsInSig(Bawl.replyLinkParams.origTimestamp);
if ( $('.bawlprocess')[int].parentElement && $('.bawlprocess')[int].parentElement.innerHTML.match(' ' + Bawl.signatureTimeStampToLink) ) { //the space ensures we can't accidentally alter the commentID instead which is mostly an issue for wikis that rely on the hh:mm fallback. But seriously: why aren't signature dates wrapped in their own tag? The hacks Enterprisey must have gone through..
Bawl.linkedSignaturedate = document.createElement('a');
Bawl.linkedSignaturedate.href = '#' + encodeURIComponent(Bawl.replyLinkParams.id);
if ( Bawl.settings.dateLinks == true ) {
if ( Bawl.settings.dateLinksLocalTime == true ) {
Bawl.browserTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
Bawl.browserTimeZoneDisplay = new Date().getTimezoneOffset() / 60;
if (Bawl.browserTimeZoneDisplay >= 0 ) {
Bawl.browserTimeZoneDisplay = 'UTC -' + Bawl.browserTimeZoneDisplay;
} else {
Bawl.browserTimeZoneDisplay = 'UTC +' + ( Bawl.browserTimeZoneDisplay * -1 );
}
Bawl.signatureTimeStampLocalTime = Bawl.timestampToTimeAsInSig(Bawl.replyLinkParams.origTimestamp, Bawl.browserTimeZone);
Bawl.linkedSignaturedate.innerText = Bawl.signatureTimeStampLocalTime;
Bawl.signatureTimeStampToLinkRegExp = new RegExp(' ' + Bawl.escapeRegExp(Bawl.signatureTimeStampToLink) + '([^\(]*)\\([^\)]*\\)');
$('.bawlprocess')[int].parentElement.innerHTML = $('.bawlprocess')[int].parentElement.innerHTML.replace(Bawl.signatureTimeStampToLinkRegExp, ' ' + Bawl.linkedSignaturedate.outerHTML + '$1' + ' (' + Bawl.browserTimeZoneDisplay + ')');
} else {
Bawl.linkedSignaturedate.innerText = Bawl.signatureTimeStampToLink;
$('.bawlprocess')[int].parentElement.innerHTML = $('.bawlprocess')[int].parentElement.innerHTML.replace(' ' + Bawl.signatureTimeStampToLink, ' ' + Bawl.linkedSignaturedate.outerHTML);
}
Bawl.dbg('linked signature date');
}
if ( Bawl.settings.dateLinksIcon == true ) {
Bawl.linkedSignaturedate.innerHTML = '🔗';
Bawl.linkedSignaturedate.classList = [ 'BawlReplyLink BawlReplyLinkIcon' ];
$('.bawlprocess')[int].prepend(Bawl.linkedSignaturedate);
}
} else {
Bawl.dbg('could not link signature date');
}
}
}
} else if (typeof document.getElementsByClassName('bawlprocess')[int].childNodes != "undefined" && typeof document.getElementsByClassName('bawlprocess')[int].childNodes[1] == 'object' && typeof document.getElementsByClassName('bawlprocess')[int].childNodes[1].href != "undefined" && document.getElementsByClassName('bawlprocess')[int].className.match('mw-editsection') ) { //edit section link, extract page title and section
if ( Bawl.settings.replySecLink == true && ( $('#ca-addsection')[0] || $('.ext-discussiontools-init-replylink-buttons')[0] || $('.BawlCmt')[0] ) ) {
Bawl.replyToSectionLinkNeeded = true;
}
Bawl.dbg('section link found, extract page title and section (' + int + ')');
Bawl.pageTitleToEdit = decodeURIComponent(document.getElementsByClassName('bawlprocess')[int].childNodes[1].href.replace( /.*title=([^&]*).*/, '$1')).replace(/_/g, ' ');
Bawl.sectionPlusPage = Bawl.sectionTitle + Bawl.pageTitleToEdit;
for (secseqint = 0; secseqint < 100; secseqint++) {
Bawl.dbg('make record of the section+pagename so others with the same data can be identified - this is #' + secseqint);
if ( Bawl.sectionsFound.indexOf(Bawl.sectionPlusPage + '-' + secseqint) == -1 ) {
Bawl.sectionsFound.push(Bawl.sectionPlusPage + '-' + secseqint);
Bawl.sectionseq = secseqint;
break;
}
}
if ( document.getElementsByClassName('bawlprocess')[int - 1] && typeof document.getElementsByClassName('bawlprocess')[int - 1].dataset != "undefined" && typeof document.getElementsByClassName('bawlprocess')[int - 1].dataset.mwComment == 'string' ) {
Bawl.formDataset[int - 1] = JSON.parse(document.getElementsByClassName('bawlprocess')[int - 1].dataset.mwComment);
if ( Bawl.formDataset[int - 1] && Bawl.formDataset[int - 1].type == "heading" ) {
if ( document.getElementsByClassName('bawlprocess')[int - 1] && typeof document.getElementsByClassName('bawlprocess')[int - 1].dataset != "undefined" && typeof document.getElementsByClassName('bawlprocess')[int - 1].dataset.mwComment ) {
Bawl.getDataFromIdRegExpHeading = new RegExp('^c-(.*)\-([0-9]{4}-[0-1][0-9]-[0-3][0-9]T[^-]*).*');
//need to deal with sections which have no replies or timestamps
if ( typeof Bawl.formDataset[int - 1].replies[0] == 'undefined' ) {
Bawl.paramorigReplyTo = 'NO-VALUE-PLEASE-IGNORE';
Bawl.paramorigTimestamp = '2000-01-01T00:00:00.000Z';
} else {
Bawl.paramorigReplyTo = Bawl.formDataset[int - 1].replies[0].replace(Bawl.getDataFromIdRegExpHeading, '$1');
Bawl.paramorigTimestamp = Bawl.formDataset[int - 1].replies[0].replace(Bawl.getDataFromIdRegExpHeading, '$2');
}
Bawl.replyLinkParams = {
'int': int,
'id': Bawl.formDataset[int - 1].id,
'type':'heading',
'pageTitle': Bawl.pageTitleToEdit,
'sectionTitle': Bawl.sectionTitle,
'origReplyTo': Bawl.paramorigReplyTo,
'origTimestamp': Bawl.paramorigTimestamp,
}
Bawl.headingLevel = Bawl.replyLinkParams.headingLevel;
if ( Bawl.settings.secLinks == true ) {
Bawl.addReplyLinkTo(Bawl.replyLinkParams); //add link to create a new subsection
}
}
}
}
} else if (typeof document.getElementsByClassName('bawlprocess')[int].className != "undefined" && document.getElementsByClassName('bawlprocess')[int].className.match('mw-headline') ) { //section header, extract section title
Bawl.dbg('section header found, extract section title');
Bawl.sectionTitle = document.getElementsByClassName('bawlprocess')[int].innerText;
} else if ( $('.bawlprocess')[int].classList[0] == 'BawlCmt' ) { //locator
Bawl.dbg('locator found');
Bawl.locatorUsername = $('.bawlprocess')[int].id.replace(/(.*)\:([0-9]{13,14})\:([^\:]*).*/, '$1');
Bawl.locatorTimestamp = $('.bawlprocess')[int].id.replace(/(.*)\:([0-9]{13,14})\:([^\:]*).*/, '$2');
Bawl.locatorPageTitle = $('.bawlprocess')[int].id.replace(/(.*)\:([0-9]{13,14})\:([^\:]*).*/, '$3');
Bawl.replyLinkParams = {
'int': int,
'type':'comment',
'subtype':'bylocator',
'id': $('.bawlprocess')[int].id,
'pageTitle': decodeURIComponent(Bawl.locatorPageTitle),
'sectionTitle': Bawl.sectionTitle,
'origReplyTo': decodeURIComponent(Bawl.locatorUsername),
'origTimestamp': Bawl.locatorTimestamp,
}
Bawl.addReplyLinkTo(Bawl.replyLinkParams);
} else if ( $('.bawlprocess')[int].className && ( $('.bawlprocess')[int].className.match('commentbox') || $('.bawlprocess')[int].className.match('createbox') ) ) {
Bawl.dbg('found InputBox');
if ( Bawl.settings.inputBoxTO == true ) {
Bawl.dbg('inputbox takeover enabled');
Bawl.replyLinkParams = {
'int': int,
'id':'newSectionForm',
'type':'newsection',
'subtype':'InputBox',
'pageTitle': mw.config.get('wgPageName'),
'sectionTitle':'NO-VALUE-PLEASE-IGNORE',
'origReplyTo':'NO-VALUE-PLEASE-IGNORE',
'origTimestamp':'2000-01-01T00:00:00.000Z',
'origReplyTo2':'NO-VALUE-PLEASE-IGNORE',
'headingLevel': 0,
'preloadparams': []
}
for (intInputBox = 0; intInputBox < $('.bawlprocess')[int].children.length; intInputBox++) {
Bawl.dbg('process child element #' + intInputBox + '/' + $('.bawlprocess')[int].children.length + ' for element #' + int);
if ( $('.bawlprocess')[int].children[intInputBox].name == 'preload' ) {
Bawl.replyLinkParams.preload = $('.bawlprocess')[int].children[intInputBox].value;
} else if ( $('.bawlprocess')[int].children[intInputBox].name == 'preloadparams[]' ) {
Bawl.replyLinkParams.preloadparams.push($('.bawlprocess')[int].children[intInputBox].value);
} else if ( $('.bawlprocess')[int].children[intInputBox].name == 'editintro' ) {
Bawl.replyLinkParams.editIntro = $('.bawlprocess')[int].children[intInputBox].value;
} else if ( $('.bawlprocess')[int].children[intInputBox].name == 'summary' ) {
Bawl.replyLinkParams.summary = $('.bawlprocess')[int].children[intInputBox].value;
} else if ( $('.bawlprocess')[int].children[intInputBox].name == 'minor' ) {
Bawl.replyLinkParams.minor = $('.bawlprocess')[int].children[intInputBox].value;
} else if ( $('.bawlprocess')[int].children[intInputBox].name == 'title' ) {
Bawl.replyLinkParams.pageTitle = $('.bawlprocess')[int].children[intInputBox].value;
} else if ( $('.bawlprocess')[int].children[intInputBox].name == 'preloadtitle' ) {
Bawl.replyLinkParams.preloadtitle = $('.bawlprocess')[int].children[intInputBox].value;
} else if ( $('.bawlprocess')[int].children[intInputBox].type == 'submit' ) {
Bawl.dbg('sabotage submit, add our own onclick instead');
$('.bawlprocess')[int].children[intInputBox].type = ''; //don't do whatever you normally do
$('.bawlprocess')[int].children[intInputBox].outerHTML = $('.bawlprocess')[int].children[intInputBox].outerHTML.replace(/>$/, ' onclick="Bawl.openReplyForm(\'' + encodeURIComponent(JSON.stringify(Bawl.replyLinkParams)).replace(/\'/g, '%27') + '\')">');
}
}//for
}//Bawl.settings.inputBoxTO == true
} else if ( $('.bawlprocess')[int].className && $('.bawlprocess')[int].className.match('Bawl-comment-link') && $('.bawlprocess')[int].id && $('.bawlprocess')[int].id.match(/^\{(\"[a-z]*\":\"[^"]*\",)*\"[a-z]*\":\"[^"]*\"\}/) ) {
Bawl.dbg('Bawl-comment-link found');
Bawl.replyLinkParams = {
'int': int,
'id':'Bawl-comment-link',
'type':'BCL',
'subtype':'page',
'pageTitle': mw.config.get('wgPageName'),
'sectionTitle': Bawl.sectionTitle,
'origReplyTo':'NO-VALUE-PLEASE-IGNORE',
'origTimestamp':'2000-01-01T00:00:00.000Z',
'preloadparams': []
}
Bawl.commentLinkID = JSON.parse($('.bawlprocess')[int].id);
if ( Bawl.commentLinkID.type == 'section' ) {
Bawl.replyLinkParams.subtype = 'section';
}
if ( Bawl.commentLinkID.page ) {
Bawl.replyLinkParams.pageTitle = Bawl.commentLinkID.page;
}
if ( Bawl.commentLinkID.preload ) {
Bawl.replyLinkParams.preload = Bawl.commentLinkID.preload;
}
if ( Bawl.commentLinkID.preloadparams ) {
Bawl.replyLinkParams.preloadparams = Bawl.commentLinkID.preloadparams;
}
document.getElementsByClassName('bawlprocess')[int].innerHTML = document.getElementsByClassName('bawlprocess')[int].innerHTML.replace(/href=\"[^"]*\"/, 'onclick="Bawl.openReplyForm(\'' + encodeURIComponent(JSON.stringify(Bawl.replyLinkParams)).replace(/\'/g, '\\\'') + '\')"');
Bawl.checkUrlForBawlformRegExp = new RegExp('withJS=.*Bawl(\-core)\.js.*Bawlform=' + Bawl.commentLinkID.id);
if ( document.location.href.match(Bawl.checkUrlForBawlformRegExp) ) {
Bawl.automaticallyOpenFormParams = $.extend( true, {}, Bawl.replyLinkParams ); // copy as = only creates a shortcut
if ( Bawl.automaticallyOpenFormParams.preloadparams && Bawl.automaticallyOpenFormParams.preloadparams.length > 0 ) {
Bawl.automaticallyOpenFormParams.preloadparams = JSON.parse(decodeURIComponent(Bawl.automaticallyOpenFormParams.preloadparams).replace(/\"\;/g, '"'));
}
}
}
} //end for
Bawl.stopwatchAddLinks2 = new Date().getTime();
Bawl.stopwatchAddLinks3 = Bawl.stopwatchAddLinks2 - Bawl.stopwatchAddLinks1;
if ( window.location.hash != '' ) {
Bawl.dbg('url contains an anchor. as the page may have jumped, re-jump to anchor');
Bawl.locationHash = window.location.hash;
window.location = '#';
window.location = Bawl.locationHash;
}
if ( Bawl.automaticallyOpenFormParams ) {
Bawl.openReplyForm(Bawl.automaticallyOpenFormParams);
}
if ( mw.config.get('wgDiscussionToolsFeaturesEnabled') == null ) {
//TODO fallback method to add links
}
}
);
} else {
console.log('Bawl: this doesn\'t seem like an appropriate page to load Bawl on, but if it is, report it');
};
//</nowiki>