User:Yitzi/wikia.js

/* */ /* */ $('.DBQuery').each(function { var lines = $(this).text.split(($(this).text.indexOf('\r') != -1) ? '\r' : '\n'); var database = ; var formId = ; var resultId = ''; var properties = ["test", "test2"]; var entries = [];

// Give an error in the results area function showError(str) { $('#' + resultId).empty.append($(' ').addClass('jcError').text(str)); }

// Parse config for (var i in lines) { var temp = lines[i].split('=', 2); if (temp.length != 2) {   continue; } switch ($.trim(temp[0])) {   case 'database': database = ($.trim(temp[1])); break; case 'form': formId = ($.trim(temp[1])); break; case 'result': resultId = ($.trim(temp[1])); break; } }

function stripHTML(string) { var linkre=/<(.*?)>/g; string=string.replace(linkre,""); return(string); } function loadDB(data) { alert('beginning load2');

}

$.ajax( {  data:     {    'action': 'query',    'prop': 'revisions',    'titles': database,    'rvprop': 'content',    'redirects': '',    'format': 'json'    },  dataType: 'json',  success: loadDB,  error: showError,  url: mw.config.get( 'wgScriptPath' ) + '/api.php',  timeout: 10000 // millisec  });

//Now to construct the list of entries fulfilling a particular query: function query(queryentries,modes,allownones) { alert (properties); } //Next, a constructor function to create a new table-containing div. function DBtablediv(name,tableentries) { this.testproperty="test"; } //And now to make the actual query form. var $queryTable=$(' ').addClass('wikitable jcTable'); for (var i in properties) { var $tr = $(' '); $tr.append(' '+properties[i]+' '); var querymode=document.createElement("select"); var temp=document.createElement("option"); temp.text='Allowed values:'; querymode.add(temp,null); var temp=document.createElement("option"); temp.text='Disallowed values:'; querymode.add(temp,null); querymode.selectedIndex=1; querymode.id=properties[i]+"queryMode"; var $td = $(' '); $td.append(querymode); $tr.append($td); var $td = $(' '); var queryValues=document.createElement("input"); queryValues.type="text"; queryValues.id=properties[i]+'queryValue'; $td.append(queryValues); $tr.append($td); var allowNone=document.createElement("input"); allowNone.id=properties[i]+'allowNone'; allowNone.type="checkbox"; allowNone.checked=true; var $td = $(' '); $td.append('Allow empty entries').append(allowNone); $tr.append($td); $queryTable.append($tr); } $form = $(' ').attr({'action': '#', 'id': 'jcForm' + formId}).submit(function {  queryentries=[];  modes=[];  allownones=[];  for (var i in properties)    {    temp=document.getElementById(properties[i]+'queryValue');    queryentries.push(temp.value);    temp=document.getElementById(properties[i]+'queryMode');    modes.push(temp.selectedIndex);    temp=document.getElementById(properties[i]+'allowNone');    allownones.push(temp.checked);    }  newEntries=query(queryentries,modes,allownones);  new DBtablediv(queryName.value,newEntries);  }); $form.append($queryTable); $form.append(' '); $form.append('Name for new table:'); var queryName=document.createElement("input"); queryName.type="text"; $form.append(queryName); $form.append($(' ').attr({type: 'submit', value: 'Get matching entries'})); $('#bodyContent #' + formId + ',#WikiaArticle #' + formId).empty.append($form); }); /* */ /* */