پرش به محتوا

مدیاویکی:Gadget-CatMaker.js: تفاوت میان نسخه‌ها

از دانشنامه علوم انسانی
imported>Yamaha5
بدون خلاصۀ ویرایش
imported>Yamaha5
بدون خلاصۀ ویرایش
خط ۱: خط ۱:
//-------------------Load and save----------------
function savePage(title, text, summary, callback) {
    function loadPage(title, callback) {
  new mw.Api().post({
        new mw.Api().get({
    action: 'edit',
            action: 'query',
    title: title,
            prop: 'revisions',
    text: text,
            titles: title,
    summary: summary,
            rvprop: 'content',
    minor: '',
            format: 'json'
    token: mw.user.tokens.get('editToken')
        }).done(function (data) {
  }).done(function (data) {
        try {
    if (data.error && data.error.info) {
            callback($.map(data.query.pages, function (value) {
      mw.notify(data.error.info);
                return value;
    } else {
            })[0].revisions[0]['*']);
      callback();
        }
        catch (exception) {
            callback('');}
        }).fail(function (data) {
            callback($.map(data.query.pages, function (value) {
                return value;
            })[0].revisions[0]);
        });
    }
    function savePage(title, text, summary, callback) {
        new mw.Api().post({
            action: 'edit',
            title: title,
            text: text,
            summary: summary,
            minor: '',
            token: mw.user.tokens.get('editToken')
        }).done(function (data) {
            if (data.error && data.error.info) {
                mw.notify(data.error.info);
            } else {
                callback();
            }
        }).fail(function (data) {
            mw.notify(data);
        });
    }
 
    function loadSavePageRefresh(page, replaceCallback, summary) {
        loadPage(page, function (text) {
            savePage(page, replaceCallback(text), summary, function () {
                //window.location = mw.util.wikiGetlink(page) + '?action=purge';
            });
        });
     }
     }
  }).fail(function (data) {
    mw.notify(data);
  });
}


//-------------translation------------------
function faWikiName(title) {
function faWikiName(title) {
   return $.ajax({
   return $.ajax({
خط ۵۶: خط ۲۴:
     dataType: 'jsonp'
     dataType: 'jsonp'
   }).then(function (data) {
   }).then(function (data) {
     return $.grep($.map(c.query.pages, function (x) { return x; })[0].langlinks, function (x) { return x.lang === 'fa'; })[0];
     return $.grep($.map(data.query.pages, function (x) { return x; })[0].langlinks, function (x) { return x.lang === 'fa'; })[0];
  }).then(function (x) {
    return x['*'];
   });
   });
}
}


function catParents(title) {
function catParents(title) {
   $.ajax({
   return $.ajax({
     url: '//en.wikipedia.org/w/api.php',
     url: '//en.wikipedia.org/w/api.php',
     data: { action: 'query', prop: 'categories', titles: title, clshow: '!hidden', cllimit: 500, format: 'json' },
     data: { action: 'query', prop: 'categories', titles: title, clshow: '!hidden', cllimit: 500, format: 'json' },
     dataType: 'jsonp'
     dataType: 'jsonp'
   }).then(function (data) {
   }).then(function (data) {
     return $.map($.map(c.query.pages, function (x) { return x; })[0].categories, function (x) { return x.title; })
     return $.map($.map(data.query.pages, function (x) { return x; })[0].categories, function (x) { return x.title; });
   });
   });
}
}
//var test=GetCategory('ایران')
//--------------------------------------------


$(function () {
$(function () {
خط ۷۹: خط ۴۶:
   $(mw.util.addPortletLink('p-views', '#', 'رده‌ساز', 'ca-catmaker'))
   $(mw.util.addPortletLink('p-views', '#', 'رده‌ساز', 'ca-catmaker'))
     .click(function (e) {
     .click(function (e) {
      alert(prompt('نام ردهٔ معادل انگلیسی؟'));
       e.preventDefault();
       e.preventDefault();
      var title = prompt('نام ردهٔ معادل انگلیسی؟');
      catParents(title).done(function (x) {
        $.when.apply(null, $.map(x, function (y) { return faWikiName(y); })).done(function () {
          savePage(
            wgPageName,
            $.map(arguments, function (x) { return '[[' + x + ']]'; }).join('\n'),
            'ایجاد ردهٔ معادل به کمک ابزار رده‌ساز',
            function () { location.href = location.href; }
          );
        });
      });
     });
     });
});
});

نسخهٔ ۲۸ مارس ۲۰۱۴، ساعت ۱۵:۲۸

function savePage(title, text, summary, callback) {
  new mw.Api().post({
    action: 'edit',
    title: title,
    text: text,
    summary: summary,
    minor: '',
    token: mw.user.tokens.get('editToken')
  }).done(function (data) {
    if (data.error && data.error.info) {
      mw.notify(data.error.info);
    } else {
      callback();
    }
  }).fail(function (data) {
    mw.notify(data);
  });
}

function faWikiName(title) {
  return $.ajax({
    url: '//en.wikipedia.org/w/api.php',
    data: { action: 'query', prop: 'langlinks', titles: title, redirects: 1, format: 'json', lllimit:500 },
    dataType: 'jsonp'
  }).then(function (data) {
    return $.grep($.map(data.query.pages, function (x) { return x; })[0].langlinks, function (x) { return x.lang === 'fa'; })[0];
  }).then(function (x) {
    return x['*'];
  });
}

function catParents(title) {
  return $.ajax({
    url: '//en.wikipedia.org/w/api.php',
    data: { action: 'query', prop: 'categories', titles: title, clshow: '!hidden', cllimit: 500, format: 'json' },
    dataType: 'jsonp'
  }).then(function (data) {
    return $.map($.map(data.query.pages, function (x) { return x; })[0].categories, function (x) { return x.title; });
  });
}

$(function () {
  if (wgNamespaceNumber !== 14 || $('.noarticletext').length === 0) {
    return;
  }
  $(mw.util.addPortletLink('p-views', '#', 'رده‌ساز', 'ca-catmaker'))
    .click(function (e) {
      e.preventDefault();
      var title = prompt('نام ردهٔ معادل انگلیسی؟');
      catParents(title).done(function (x) {
        $.when.apply(null, $.map(x, function (y) { return faWikiName(y); })).done(function () {
          savePage(
            wgPageName,
            $.map(arguments, function (x) { return '[[' + x + ']]'; }).join('\n'),
            'ایجاد ردهٔ معادل به کمک ابزار رده‌ساز',
            function () { location.href = location.href; }
          );
        });
      });
    });
});