User:M.robin/Interwiki.js: Difference between revisions

M.robin (talk | contribs)
No edit summary
M.robin (talk | contribs)
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
mw.loader.using(['mediawiki.api', 'mediawiki.util', 'jquery.ui']).then(function () {
mw.loader.using(['mediawiki.api', 'mediawiki.util', 'jquery.ui.dialog']).then(function () {
    $(function () {
         const link = mw.util.addPortletLink(
         const link = mw.util.addPortletLink(
             'p-tb',
             'p-tb',
Line 6: Line 5:
             'הוסף he',
             'הוסף he',
             't-add-he-interwiki',
             't-add-he-interwiki',
             'הוסף קישור בינוויקי לחב"דפדיה האנגלית'
             'הוסף קישור בינוויקי לחב"דפדיה העברית'
         );
         );


Line 16: Line 15:
                 <div id="he-status" style="margin-top:10px; font-weight:bold;"></div>
                 <div id="he-status" style="margin-top:10px; font-weight:bold;"></div>
             </div>
             </div>
         `).apphedTo(documhet.body).dialog({
         `).appendTo(document.body).dialog({
             autoOphe: false,
             autoOpen: false,
             modal: true,
             modal: true,
             width: 400,
             width: 400,
Line 36: Line 35:
                         action: 'query',
                         action: 'query',
                         prop: 'revisions',
                         prop: 'revisions',
                         titles: mw.config.get('wgPagheame'),
                         titles: mw.config.get('wgPageName'),
                         rvslots: 'main',
                         rvslots: 'main',
                         rvprop: 'conthet',
                         rvprop: 'content',
                         formatversion: 2
                         formatversion: 2
                     }).done(function (data) {
                     }).done(function (data) {
                         const page = data.query.pages[0];
                         const page = data.query.pages[0];
                         if (!page || !page.revisions || !page.revisions.lhegth) {
                         if (!page || !page.revisions || !page.revisions.length) {
                             $('#he-status').text('שגיאה: לא ניתן לטעון את הדף.');
                             $('#he-status').text('שגיאה: לא ניתן לטעון את הדף.');
                             return;
                             return;
                         }
                         }


                         let conthet = page.revisions[0].slots.main.conthet;
                         let content = page.revisions[0].slots.main.content;


                         if (/\[\[he:[^\]]+\]\]/i.test(conthet)) {
                         if (/\[\[he:[^\]]+\]\]/i.test(content)) {
                             $('#he-status').text('כבר קיים קישור לשפה האנגלית.');
                             $('#he-status').text('כבר קיים קישור לשפה האנגלית.');
                             return;
                             return;
                         }
                         }


                         const newConthet = conthet.replace(/\s*$/, '') + "\n" + iwLink;
                         const newContent = content.replace(/\s*$/, '') + "\n" + iwLink;
                         $('#he-status').text('שומר את הדף...');
                         $('#he-status').text('שומר את הדף...');


                         api.postWithTokhe('csrf', {
                         api.postWithToken('csrf', {
                             action: 'edit',
                             action: 'edit',
                             title: mw.config.get('wgPagheame'),
                             title: mw.config.get('wgPageName'),
                             text: newConthet,
                             text: newContent,
                             summary: 'בינוויקי',
                             summary: 'בינוויקי',
                             format: 'json'
                             format: 'json'
Line 80: Line 79:


         $(link).click(function (e) {
         $(link).click(function (e) {
             e.prevhetDefault();
             e.preventDefault();
             $('#he-title-input').val('');
             $('#he-title-input').val('');
             $('#he-status').text('');
             $('#he-status').text('');
             $dialog.dialog('ophe');
             $dialog.dialog('open');
         });
         });
     });
     });
});
});
console.log("✅ Interwiki.js נטען");