Widget:AddDataRows

/* <![CDATA[ */ $(function { var id = '#weDataSpan';  var $table = $(id).nextAll('table:first');  var ncols = $table.find('tr:first>th').length;  if (ncols === 0) ncols = $table.find('tr:last>td').length;  var saveButton;

if (wgUserName === null) { saveButton = ' You must login to save data'; } else { saveButton = ''; } $table.after('' + saveButton); $(id+'Add').click(function {    var data = [];    for (var i=0; i');    }    $table.append('  ' + data.join('  ') + '  ');    $(id+'Save').removeAttr('disabled');  }); $(id+'Save').click(function {    // disable the buttons    $(id+'Save', id+'Add').attr('disabled', 'true');    var tablerows = '';    $table.children('tbody:first').children('tr').each(function(i) { var rowdata = []; $(this).find('td > input').each(function(j) {       // keep only +/-, digits, decimal, comma        var val = $(this).val.replace(/[^-+0-9.,]/g, );        // don't save rows with blank input        if (val != ) rowdata.push(val);      }); // only add rows that have non-blank entries in all columns if (rowdata.length === ncols) { tablerows += ' ' + rowdata.join('  ') + "  \n"; }   });

// load the wikitext and an edit token var weAPI = wgServer + '/api.php'; $.ajax({     type: 'POST',      url: weAPI,      data: {        action: 'query',        prop: 'info|revisions',        intoken: 'edit',        titles: wgPageName,        rvprop: 'content',        format: 'json'      },      error: function(hdr, stat, err) {        alert("Unable to fetch data page!\n" + stat);      },      success: function (d) {        for (var pg in d.query.pages) {          var page = d.query.pages[pg];          var token = page.edittoken;          var wikitext = page.revisions[0]['*'];        }        $.ajax({ type: 'POST', url: weAPI, data: { action: 'edit', title: wgPageName, summary: 'Added data row(s)', text: wikitext.replace(' ', tablerows + ' '), token: token, format: 'json' },         error: function(hdr, stat, err) { alert("Unable to save data!\n" + stat); },         success: function (d) { // lazy way to redraw, reset window.location = wgServer + '/' + wgPageName; }       });      }    });  }); }); /* ]]> */

Usage
A widget that allows adding rows to the following table. Note that the opening table tag must occur on the same line as the widget. For example: