User:Shrikarsan/விக்கியன்பு.js

Daga Wikipedia, Insakulofidiya ta kyauta.

Asani: Bayan wallafawa, zaku yi juyar da cache na browser din ku dan ganin sauye-sauye.

  • Firefox / Safari: Rike Shift asanda kuke danna Reload, ko danna kodai Ctrl-F5 ko kuma Ctrl-R (⌘-R akan Mac)
  • Google Chrome: Danna Ctrl-Shift-R (⌘-Shift-R akan Mac)
  • Internet Explorer / Edge: Rike Ctrl asanda kuke danna Refresh, ko latsa Ctrl-F5
  • Opera: Danna Ctrl-F5.
//<nowiki>
if (( wgNamespaceNumber == 3 && wgAction == 'view' && skin == 'vector' && !$.wikiLove )) {
  // Script depends on jQuery dialog widget
  mw.loader.using( 'jquery.ui', function() {
    // Construct object (to prevent namespace conflicts)
    wikiLove = {
 
      displayProgress: function( form, message ) {
        $('#'+form+' div').hide(); // remove everything else from the dialog box
        $('#'+form).append ( $('<div style="text-align:center;margin:3em 0;"></div>').html( message+'<br/><img src="http://upload.wikimedia.org/wikipedia/commons/4/42/Loading.gif" />' ) );
      },
 
      displayError: function( form, error ) {
        $('#'+form+' div').hide(); // remove everything else from the dialog box
        $('#'+form).append ( $('<div style="color:#990000;margin-top:0.4em;"></div>').html( 'Error: '+error ) );
      },
 
      getEditToken: function() {
        $.ajax({
          url: wgScriptPath + '/api.php?',
          data: 'action=query&prop=info&intoken=edit&titles=Main%20Page&indexpageids&format=json',
          dataType: 'json',
          success: function( data ) {
            if ( data.query.pages && data.query.pageids ) {
              var pageid = data.query.pageids[0];
              wikiLove.editToken = data.query.pages[pageid].edittoken;
            }
          }
        });
      },
 
      getEmailable: function() {
        // Test to see if the 'E-mail this user' link exists
        wikiLove.emailable = $('#t-emailuser').length ? true : false;
      },
 
      editPage: function( form, summary, template ) {
        $.ajax({
          url: wgScriptPath + '/api.php?',
          data: 'action=edit&title='+encodeURIComponent(mw.config.get('wgPageName'))+'&section=new&summary='+encodeURIComponent(summary)+'&text='+encodeURIComponent(template)+'&format=json&token='+encodeURIComponent(wikiLove.editToken),
          dataType: 'json',
          type: 'POST',
          success: function( data ) {
            if ( data.edit.result == "Success" ) {
              window.location.reload();
            } else {
              wikiLove.displayError( form, 'Unknown result from API.' );
            }
          },
          error: function( xhr ) {
            wikiLove.displayError( form, 'සංස්කරණය අසමක් විණි.' );
            //console.debug( xhr.responseText );
          }
        });
      },
 
      sendEmail: function( form, subject, text ) {
        $.ajax({
          url: wgScriptPath + '/api.php?',
          data: 'action=emailuser&target='+encodeURIComponent(wgTitle)+'&subject='+encodeURIComponent(subject)+'&text='+encodeURIComponent(text)+'&format=json&token='+encodeURIComponent(wikiLove.editToken),
          dataType: 'json',
          type: 'POST'
        });
      },
 
      launchDialog: function( interface, emailOption ) {
        // If user is emailable, add email checkbox to forms that request it
        if ( emailOption && typeof wikiLove.emailable !== 'undefined' && wikiLove.emailable ) {
          if ( typeof interface.data('emailCheckboxAppended') == 'undefined' ) {
            interface.append( $('<div style="margin-top:0.4em;"></div>').html('<input type="checkbox" name="notify"/> பயனருக்கு மின்னஞ்சல் மூலம் தெரியப்படுத்தவும்') );
            interface.data('emailCheckboxAppended', true);
          }
        }
        // Open the dialog box
        interface.dialog('open');
        // Retrieve the edit token so it will be available when the form is submitted
        wikiLove.getEditToken();
      },
 
      initialize: function() {
 
        // Function to make a list of images selectable
        $.fn.selectItem = function() {
          return this.each(function() {
            var containerId = this.id;
            var customId = 0;
            $('#'+containerId+' img').css('border', '8px solid transparent');
            $('#'+containerId+' img').each(function() {
              if (this.id == '') {
                this.id = 'select_img_' + customId;
                customId++;
              }
              $('#'+this.id).click(function() {
                  $('#'+containerId+'Selected').val(this.title);
                  $('#'+containerId+' img').css('border', '8px solid transparent');
                  $('#'+this.id).css('border', '8px solid #AED0EA');
              })
            });
          });
        };
 
        // கிடைக்கக்கூடிய பதக்கங்கள்
        var $barnstarList = [
          'விக்கிப்புயல் பதக்கம்',
          'சிறந்த உழைப்பாளர் பதக்கம்',
          'விடாமுயற்சியாளர் பதக்கம்',
          'களைப்படையாப் பங்களிப்பாளர் பதக்கம்',
          'சிறந்த படக்கலைஞர் பதக்கம்',
          'விக்கிப்பதக்கத் தக்கவைப்பாளர் பதக்கம்',
          'தீக்குறும்பு களைவர் பதக்கம்',
          'சிறந்த நகைச்சுவை உணர்வாளர் பதக்கம்',
          'சிறந்த உரைதிருத்துனர் பதக்கம்',
          'சிறப்புப் பதக்கம்',
          'சிறந்த மேற்கோள்வழங்குனர் பதக்கம்',
          'சிறந்த கூட்டுமுயற்சிப் பதக்கம்',
          'செயல்நயம் மிக்கவர் பதக்கம்',
          'மரியாதை மிக்கவர் பதக்கம்',
          'மெய்வாழ்வுப் பதக்கம்',
          'அசத்தும் புதிய பயனர் பதக்கம்',
          'உங்களுக்குத் தெரியுமா பங்களிப்புப் பதக்கம்',
          'முதற்பக்கக் கட்டுரைப் பங்களிப்புப் பதக்கம்',
          'பகுப்பாக்குனர் பதக்கம்',
          'சிறந்த வழிகாட்டிப் பதக்கம்',
          'ஊக்குவிப்பாளர் பதக்கம்',
          'பயனர் பக்கப்பதக்கம்',
          'வார்ப்புரு ஆக்குனர் பதக்கம்',
          'சிறந்த யோசனைக்கான பதக்கம்',
          'நடப்பு நிகழ்வுகள் பதக்கம்',
          'வாய்மொழி விண்மீன் பதக்கம்',
          'சிறந்த கூட்டு முயற்சிக் கட்டுரையாளர்',
          'சிறந்த முக்கிய கட்டுரை உருவாக்குனர்',
          'அசத்தும் பள்ளி மாணவர் பதக்கம்',
        ];
 
         // பதக்க இடைமுகப்பை வரையறுத்தல்
        $wlBarnstars = $('<div id="barnstarForm" style="position:relative;"></div>')
          .append( $('<div style="margin-top:0.4em;"></div>').html( 'பதக்கத்தைத் தெரிவு செய்யவும்: ' ).append( $('<select id="barnstarSelect" style="padding:1px;vertical-align:baseline;"></select>') ) )
          .append( $('<div style="margin-top:0.4em;"></div>').html( 'ஒரு செய்தியை உள்ளிடவும் (கையொப்பமின்றி):<br/>' ).append( $('<textarea name="message" id="barnstarMessage" style="width:99%" rows="4" cols="60"></textarea>') ) )
          .dialog({
            width: 500,
            autoOpen: false,
            title: 'ஒரு பதக்கத்தைத் தரவும்',
            modal: true,
            buttons: { "பதக்கத்தை அளிக்கவும்": function() { 
              $(this).dialog({buttons:{}});
              if ( typeof wikiLove.editToken !== 'undefined' ) {
                if ( $('#barnstarForm input[name="notify"]').attr('checked') ) {
                  // மின்னஞ்சல் அனுப்பவும்
                  wikiLove.sendEmail( 'barnstarForm', 'உங்களுக்கு ஒரு பதக்கம் தரப்பட்டுள்ளது!', 'வணக்கம் '+wgTitle+'!\n\nநான் உங்களுக்கு '+$('#barnstarSelect').val()+' என்ற பதக்கத்தைத் தங்களது தமிழ் விக்கிப்பீடியா பேச்சுப் பக்கத்தில் தந்துள்ளேன்! வாழ்த்துகள்.' );
                }
                // பக்கத்தில் தொகுத்தலை மேற்கொள்ளல்
                wikiLove.displayProgress( 'barnstarForm', 'பதக்கம் சேர்க்கப்பட்டுக் கொண்டிருக்கிறது...' );
                var template = '{{subst:'+$('#barnstarSelect').val()+'|'+$('#barnstarMessage').val() +' ~~~~}}';
                wikiLove.editPage( 'barnstarForm', 'பதக்கம்', template );
              } else {
                wikiLove.displayError( 'barnstarForm', 'தொகுத்தலைத் திரும்பப் பெற முடியவில்லை.' );
              }
            }}
          });
 
        // பதக்கத் தெரிவுப் பட்டியலைப் பரப்பவும்
        $.each( $barnstarList, function(index, value) { $('#barnstarSelect').append( $('<option></option>').val(value).html(value) ); });
 
        // List of all available foods
        var $foodList = [
          'brownie',
          'cookie',
          'cupcake',
          'pie',
          'plate of sausages'
        ];
 
        // Define food interface
        $wlFood = $('<div id="foodForm" style="position:relative;"></div>')
          .append( $('<div style="margin-top:0.4em;"></div>').html( 'Select food: ' ).append( $('<select id="foodSelect" style="padding:1px;vertical-align:baseline;"></select>') ) )
          .append( $('<div style="margin-top:0.4em;"></div>').html( 'Enter a personalized message (optional):<br/>' ).append( $('<textarea name="message" id="foodMessage" style="width:99%" rows="4" cols="60"></textarea>') ) )
          .dialog({
            width: 500,
            autoOpen: false,
            title: 'Give some food',
            modal: true,
            buttons: { "Give food": function() { 
              $(this).dialog({buttons:{}});
              if ( typeof wikiLove.editToken !== 'undefined' ) {
                $selectedFood = $('#foodSelect').val();
                // Perform edit to page
                wikiLove.displayProgress( 'foodForm', 'Adding '+$selectedFood+' to page...' );
                if ( $('#foodMessage').val() != '' ) {
                  var template = '{{subst:WikiLove-'+$selectedFood+'|'+$('#foodMessage').val()+'}}';
                } else {
                  var template = '{{subst:WikiLove-'+$selectedFood+'}}';
                }
                wikiLove.editPage( 'foodForm', 'A '+$selectedFood+' for you!', template );
              } else {
                wikiLove.displayError( 'foodForm', 'Could not retrieve edit token.' );
              }
            }}
          });
 
        // Populate food select list
        $.each( $foodList, function(index, value) { $('#foodSelect').append( $('<option></option>').val(value).html(value) ); });
 
        // Define kitten interface
        $wlKittens = $('<div id="kittenForm" style="position:relative;"></div>')
          .html( '<input type="hidden" id="kittenSelected" name="kittenSelected" value="Kitten-stare.jpg"/>' )
          .append( $('<div style="margin-top:0.4em;"></div>').html( 'Select which kitten you want to give:' ) )
          .append( $('<div style="margin-top:1em;text-align:center;" id="kitten"></div>')
            .html( '<img height="60" src="http://upload.wikimedia.org/wikipedia/commons/b/b1/Wordsmith%27s_barnstar.png" title="Kitten-stare.jpg" alt="Staring kitten"/><img height="60" src="http://upload.wikimedia.org/wikipedia/commons/b/b6/Barnstar_of_One_Year_Diligence.png" title="Cucciolo_gatto_Bibo.jpg" alt="Kitten sticking tongue out"/><img height="60" src="http://upload.wikimedia.org/wikipedia/commons/4/45/SpecialBarnstar.png" title="Kitten_(06)_by_Ron.jpg" alt="Attack kitten"/>' )
          )
          .dialog({
            width: 400,
            autoOpen: false,
            title: 'Give a kitten',
            modal: true,
            buttons: { "Give kitten": function() {
              $(this).dialog({buttons:{}});
              if ( typeof wikiLove.editToken !== 'undefined' ) {
                if ( $('#kittenForm input[name="notify"]').attr('checked') ) {
                  // Send email
                  wikiLove.sendEmail( 'kittenForm', 'You\'ve been given a kitten!', 'Hello '+wgTitle+'!\n\nI just left a kitten for you on your English Wikipedia talk page.' );
                }
                // Perform edit to page
                wikiLove.displayProgress( 'kittenForm', 'Adding kitten to page...' );
                var template = '{{subst:Kitten|image='+$('#kittenSelected').val()+'}}';
                wikiLove.editPage( 'kittenForm', 'A kitten for you!', template );
              } else {
                wikiLove.displayError( 'kittenForm', 'Could not retrieve edit token.' );
              }
            }}
          });
 
        // Apply special image selection interface for choosing kittens
        $('#kitten').selectItem();
 
        // Insert new tab into page
        var menuBarnstar = '<li id="wl-barnstar"><li style="background:#ffff00"><span><a onclick="wikiLove.launchDialog( $wlBarnstars, true ); return false;" href="#">பதக்கம்</a></span></li></li>';
        var menuFood = '<li id="wl-food"><li style="background:#DEF740"><span><a onclick="wikiLove.launchDialog( $wlFood, false ); return false;" href="#">உணவு</a></span></li></li>';
        var menuKitten = '<li id="wl-kitten"><li style="background:#00ffff"><span><a onclick="wikiLove.launchDialog( $wlKittens, false ); return false;" href="#">பூனைக்குட்டி</a></span></li></li>';
        var wikiLoveMenu = '<div class="vectorMenu" id="p-wikilove"><a href="#" style="padding:0 0.4em;width:auto;"><span style="display:inline-block;height:2.5em;width:21px;margin-right:5px;margin-left:5px;background-position:0 70%;background-attachment:scroll;background-image:url(http://upload.wikimedia.org/wikipedia/commons/thumb/7/7d/Heart_icon.svg/20px-Heart_icon.svg.png);background-repeat:no-repeat;">&nbsp;</span></a><div class="menu"><ul>'+menuBarnstar+menuFood+menuKitten+'</ul></div></div>';
        $('#p-cactions').after(wikiLoveMenu);
 
      } // close initialize function
 
    } // close wikiLove object
    wikiLove.initialize();
    wikiLove.getEmailable();
  }) // close mw.loader
} // close if
//</nowiki>