نوٹ: شایع کَرنہٕ پَتہ یِم تبدیلی وُچِھنہٕ خٲطرٕ کٔرِو براؤزرُک کیش (cache) صاف۔

  • فائرفاکس/ سفاری: ییلہ Reload پؠٹھ کلِک کٔرِو تہٕ Shift تھٲوِو دَبٲیِتھ، یا Ctrl-F5 یا Ctrl-R دَبٲیِو (Mac پؠٹھ R-⌘)
  • گوٗگُل کروم: Ctrl-Shift-R دَبٲیِو (Mac پؠٹھ Shift-R-⌘)
  • اِنٹَرنیٹ ایکسپلورَر: ییلہ Refresh پؠٹھ کِلِک کٔرِو Ctrl یا Ctrl-F5 تھٲوِو دَبٲیِتھ
  • اوپیرا: Tools → Preferences مَنٛز گٔژھو تہٕ کیش (cache) کٔرِو صاف
(function ($, mw) {
  'use strict';

  function createPage(pageTitle, targetPage, fileName, pixelSize, caption, textBody, userName, summary, callback) {
    // Get selected month and year
    var selectedMonth = $('#pagecreator-month').val();
    var selectedYear = $('#pagecreator-year').val();

    // Construct page title using selected month and year
    pageTitle = 'وِکیٖپیٖڈیا:مُنتَخٕب تَصویٖر/' + selectedYear + '-' +selectedMonth ;

    new mw.Api().getToken('csrf').done(function (token) {
      var fileLink = '[[' + fileName;
      if (pixelSize) {
        fileLink += '|' + pixelSize;
      } else {
        fileLink += '|600px';
      }
      if (caption) {
        fileLink += '|' + caption;
      }
      fileLink += ']]';

      var pageContent = '{| role="presentation" style="margin:0 3px 3px; width:100%; box-sizing:border-box; text-align:center; background-color:transparent; border-collapse:collapse; padding:0.9em"\n|  ' +
        fileLink +
        '\n|- \n| style="padding:0 0.9em; text-align:center;" |\n\n' +
        textBody +
        '\n<p style="text-align:center;"><small>فوٹو گرٛاف کریڈٹ: [[' + userName + ']]</small></p>  ';

      new mw.Api().post({
        action: 'edit',
        title: pageTitle,
        text: pageContent,
        summary: summary,
        token: token
      }).done(function (data) {
        if (data.error) {
          mw.notify('Page "' + pageTitle + '" creation failed: ' + data.error.info);
        } else {
          callback(pageTitle);
        }
      }).fail(function (jqXHR, textStatus, errorThrown) {
        mw.notify('Page "' + pageTitle + '" creation failed: ' + textStatus);
      });
    }).fail(function (jqXHR, textStatus, errorThrown) {
      mw.notify('Page "' + pageTitle + '" creation failed: ' + textStatus);
    });
  }

  function init(e) {
    e.preventDefault();
    $('<div>' +
      '<div style="width: 40em">Enter the details for the new page:</div>' +
      '<select style="width: 100%; background-color: white;" id="pagecreator-month">' +
      '  <option value="01">January</option>' +
      '  <option value="02">02</option>' +
      '  <option value="03">03</option>' +
      '  <option value="04">04</option>' +
      '  <option value="05">05</option>' +
      '  <option value="06">06</option>' +
      '  <option value="07">07</option>' +
      '  <option value="08">08</option>' +
      '  <option value="09">09</option>' +
      '  <option value="10">10</option>' +
      '  <option value="11">11</option>' +
      '  <option value="12">12</option>' +
      '</select>' +
      '<select style="width: 100%; background-color: white;" id="pagecreator-year">' +
      '  <option value="2023">2023</option>' +
      '  <option value="2024">2024</option>' +
      '  <option value="2025">2025</option>' +
      '  <option value="2026">2026</option>' +
      '  <option value="2027">2027</option>' +
      '</select>' +
      '<input style="width: 100%; background-color: white;" type="text" placeholder="File Name" id="pagecreator-filename">' +
      '<input style="width: 100%; background-color: white;" type="text" placeholder="Pixel Size" id="pagecreator-pixelsize">' +
      '<input style="width: 100%; background-color: white;" type="text" placeholder="Caption" id="pagecreator-caption">' +
      '<textarea style="width: 100%; background-color: white;" placeholder="Text Body" id="pagecreator-textbody" rows="7"></textarea>' +
      '<input style="width: 100%; background-color: white;" type="text" placeholder="Name of User" id="pagecreator-username">' +
      '<input style="width: 100%; background-color: gray;" type="text" placeholder="Summary" id="pagecreator-summary" value="Page creation">' +
      '</div>'
    ).dialog({
      modal: true,
      width: 450,
      buttons: [{
        id: 'pagecreator-button-create',
        text: 'Create Page',
        click: function () {
          var pageTitle;
          var fileName = $('#pagecreator-filename').val();
          var pixelSize = $('#pagecreator-pixelsize').val();
          var caption = $('#pagecreator-caption').val();
          var textBody = $('#pagecreator-textbody').val();
          var userName = $('#pagecreator-username').val();
          var summary = $('#pagecreator-summary').val();
          var targetPage = mw.config.get('wgPageName');

          if (fileName === '' || textBody === '' || userName === '' || summary === '') {
            mw.notify('Please fill in all the required fields properly.');
            return;
          }

          createPage(pageTitle, targetPage, fileName, pixelSize, caption, textBody, userName, summary, function (pageTitle) {
            mw.notify('Page "' + pageTitle + '" has been created.');
          });
        }
      }]
    });
  }

  mw.loader.using(['jquery.ui'], function () {
    $(function () {
      mw.util.addCSS('#t-pagecreator { font-weight: normal; }');
      $(mw.util.addPortletLink('p-tb', '#', 'مُنتخب تَصویٖر اندراج', 't-pagecreator', 'مُنتخب تَصویٖر اندراج')).click(init);
    });
  });
})(jQuery, mediaWiki);