User talk:Badmadevil: Difference between revisions

From Rosetta Code
Content added Content deleted
mNo edit summary
m (→‎Not Implemented Tasks by Language: replace download with sources)
Line 12: Line 12:
*javascript's XMLHTTPRequest doesn't allow cross site request, so this script's url host has to be same as the Category pages, that is , the pages has to be upload to Rosetta Code's website;
*javascript's XMLHTTPRequest doesn't allow cross site request, so this script's url host has to be same as the Category pages, that is , the pages has to be upload to Rosetta Code's website;
*the bigger problem is, the pages does not work on IE browser. IE browser does not support DOMParser, which is currently required, and other workaround found on web seems not really work. (Hope experient coder can give some advice, or I may be re-done it using RegExp later, ... or try a PHP solution? )
*the bigger problem is, the pages does not work on IE browser. IE browser does not support DOMParser, which is currently required, and other workaround found on web seems not really work. (Hope experient coder can give some advice, or I may be re-done it using RegExp later, ... or try a PHP solution? )
<br />
This is the javascript/html pages, zipped [http://www.megaupload.com/?d=BCF12MPS NotImpl.zip].<br>Hope it can be a temporary solution. -- [[User:Badmadevil|badmadevil]] 02:24, 12 June 2008 (MDT)
''Sources'':
{||-
| style="height:36em;float:left;clear:both;overflow:auto;" |
&lt;html&gt;
&lt;title&gt;Not Implemented Task by Langauge&lt;/title&gt;
&lt;!--script src="/http.js"&gt;&lt;/script--&gt;
&lt;!--script src="http.js"&gt;&lt;/script--&gt;
&lt;script&gt;
<javascript>
/**
** C o n f i g
**/
// javascript's XMLHTTPRequest doesn't allow cross site request,
// so this script's location's host has to be same as the Category pages.
// the prefix change to 'http://rosettacode.org/wiki/Category:' should be ok
//var mySitePrefix = 'http://localhost/wiki/' ;
var mySitePrefix = 'http://rosettacode.org/wiki/Category:' ;
// set to false if test in a localhost
// set to true if mySitePrefix is at rosetta site,
// should allow reach C++, C# etc. pages
//var usesafeurl = false ;
var usesafeurl = true ;
// problem :
// M$' IE has no DOMParser & workarounds seems not work, see a
// workaround : http://www.van-steenbeek.net/?q=explorer_domparser_parsefromstring
function parseDOM(xhtml) {
var contentType = "application/xhtml+xml" ;
if(typeof(DOMParser) != 'undefined')
return (new DOMParser()).parseFromString(xhtml,contentType) ;
else {
if(typeof(ActiveXObject) != 'undefined') {
var xmldata = new ActiveXObject('MSXML.DomDocument');
xmldata.async = false;
xmldata.loadXML(xhtml);
return xmldata;
} else if(typeof(XMLHttpRequest) != 'undefined') {
var xmldata = new XMLHttpRequest;
//contentType = 'application/xml';
xmldata.open('GET', 'data:' + contentType + ';charset=utf-8,' +
encodeURIComponent(xhtml), false);
if(xmldata.overrideMimeType)
xmldata.overrideMimeType(contentType);
xmldata.send(null);
return xmldata.responseXML;
}
}
}
// To test in a loacl web server (eg. http://localhost):
// 1.mkdir wiki in root dir of localhost,
// save http://rosettacode.org/wiki/Category:<CATEGORYNAME> to
// localhost/wiki/<CATEGORYNAME>/index.htm,
// 2.<CATEGORYNAME> should at leat include Solutions_by_Programming_Task &
// Solutions_by_Programming_Language, then include some other languages
// categories, eg. C, Java, Python, etc. to start testing.
// 3.place http.js where this html can located,
// 4.no query string should be in url of this html,
// 5.config mySitePrefix etc.
var NA = "?N/A" ;
function Page(url, ID) {
var o = new Object ;
o.url = url ;
o.ID = ID ;
o.cnt = 0 ;
o.htm = NA ;
o.dom ;
o.lnk = new Array() ;
o.setHtm = function(txt) {
o.htm = txt ;
var doc = parseDOM(o.htm) ;
o.dom = doc.getElementById(o.ID) ;
o.getlink() ;
}
o.request = function() { HTTP.getText(o.url, o.setHtm)}
o.getlink = function() {
if(o.htm != NA) {
var links = o.dom.getElementsByTagName("a") ;
for(i in links) {
if(links[i].innerHTML) {
o.lnk[links[i].getAttributeNode("href").value] =
links[i].getAttributeNode("title").value ;
o.cnt++ ;
}
}
}
}
return o ;
}
var scriptUrl ;
with(window.location)
scriptUrl = protocol + '//' + host + pathname ;
var rosettaUrl = 'http://rosettacode.org'
var langID = getLangID() ;
// var safeurl = rosettaUrl + '/w/index.php?title=' + langID ;
var langurl = langID != NA && usesafeurl ? safeurl() : mySitePrefix + langID ;
var task = Page(mySitePrefix + 'Solutions_by_Programming_Task', "mw-pages") ;
var lang = Page(langurl, "mw-pages") ;
var list = Page(mySitePrefix + 'Solutions_by_Programming_Language', "mw-subcategories") ;
var tasklist ;
var langlist ;
var timeoutCnt = 3 ;
var count = 0 ;
function getLangID() {
var langid = window.location.search.slice(1) ;
if(langid.length == 0) return NA ;
return langid ;
}
function safeurl(langname) {
if(!langname) langname = langID ;
return rosettaUrl + '/w/index.php?title=' + langname ;
}
function process() {
tasklist = document.getElementById("tasklist") ;
langlist = document.getElementById("langlist") ;
tasklist.innerHTML = "...loading..." ;
langlist.innerHTML = "...loading..." ;
task.request() ;
list.request() ;
if(langID != NA) {
lang.request() ;
document.title = 'Not Implemented Tasks by Langauge ' + langID ;
}
waitLoad() ;
}
function waitLoad() {
timeoutCnt-- ;
tasklist.innerHTML = "...loading, timeout in " + timeoutCnt + " sec..." ;
if(timeoutCnt > 0
&& ((langID != NA && lang.htm == NA) || task.htm == NA || list.htm == NA))
return setTimeout(waitLoad,1000) ;
if(langID == NA)
return failLoad() ;
if(timeoutCnt <= 0)
return failLoad() ;
if(task.cnt == 0 || list.cnt == 0 || lang.cnt == 0) failLoad ;
doParse() ;
}
function failLoad() { // this part may be simplified to display just a short err message
var errmsg = "" ;
if(lang.htm == NA) { // may be not known language
if(langID == NA)
errmsg += 'Language ID not known.' ;
else
errmsg += 'Error Page - url : ' +
alink(scriptUrl + '?' + langID,langID,langID, true) ;
}
errmsg += '<br />' ;
with(lang) if(htm == NA)
errmsg += 'fail to load this url : ' + alink(url, url, url) + '<br />' ;
with(list) if(htm == NA)
errmsg += 'fail to load this url : ' + alink(url, url, url) + '<br />' ;
with(task) if(htm == NA)
errmsg += 'fail to load this url : ' + alink(url, url, url) + '<br />' ;
tasklist.innerHTML = errmsg + makeStatus() ;
var taskdom = ""
if(task.cnt > 0 && lang.cnt > 0) taskdom = makeTask() ;
try {
if(taskdom == "") taskdom = task.dom.innerHTML ;
} catch(e) {
taskdom = "" ;
}
if(taskdom != "")
taskdom = makeMenu() + '<br />' + taskdom ;
else
taskdom = makeMenu() + '<br />Tasks Page not found/load.' ;
var listdom = "" ;
if(list.cnt >0) listdom = makeList();
try {
if(listdom == "") listdom = list.dom.innerHTML ;
} catch(e) {
listdom = "" ;
}
if(listdom != "")
listdom = '<hr />' + makeReturn() + '<hr />' + listdom ;
else
listdom = '<hr />' + makeReturn() + '<hr />Languages List Page not found/load.' ;
langlist.innerHTML = taskdom + listdom ;
}
function doParse() {
var taskdom = makeTask() ;
tasklist.innerHTML = makeMenu() + '<h2>Tasks not implemented by ' + alink(rosettaUrl +
'/wiki/' + langID, langID,langID, true) + '</h2><hr /><br />There are <strong>' +
count + '</strong> not implemented tasks out of <strong>' + task.cnt +
'</strong> total tasks. ' + '(' + lang.cnt+ ' completed tasks, implementations' +
' & puzzles etc.)<br />' + taskdom ;
langlist.innerHTML = makeReturn() + '<hr /><h3>Other languages :</h3>' + makeList() ;
}
function alink(url, tip, txt, normalsize) {
var styleTxt = normalsize ? "" : ' style="font-size:smaller;"';
// var shortTxt = txt.length > 20 ? txt.slice(0,20) : txt ;
return '<a href="' + url + '" title="' + tip + '"' + styleTxt + '>' + unescape(txt) +
'</a>' ;
}
function makeMenu() {
var backLink ;
if(langID == NA) {
backLink = alink(list.url, "Solution by Languages",
'Return to Category : Solution by Languages') ;
} else {
backLink = alink(safeurl(), safeurl(), 'Return to Category : ' + langID)
}
return '<a name="returntop" href="#otherlanguages">' +
'Select other languages</a>&nbsp;&nbsp;|&nbsp;&nbsp;' +
backLink + '<hr />' ;
}
function makeReturn() {
return '<a href="#returntop" name="otherlanguages">TOP</a>&nbsp;&nbsp;|' +
'&nbsp;&nbsp;' + makeStatus() ;
}
function makeStatus() {
return '(total&nbsp;/&nbsp;langs&nbsp;/&nbsp;taskss) - pages length : ' +
task.htm.length + '&nbsp;/&nbsp;' + list.htm.length + '&nbsp;/&nbsp;' +
lang.htm.length + '&nbsp;&nbsp;|&nbsp;&nbsp;link count : ' + task.cnt +
'&nbsp;/&nbsp;' + list.cnt + '&nbsp;/&nbsp;' + lang.cnt ;
}
function makeList() {
if(list.cnt == 0) return "" ;
var html = '<table width="100%"><tr>' ;
splitCnt = 0 ;
var cols = 6 ;
var wd = 'width="' + Math.floor(100/cols) + '%"' ;
for(i in list.lnk)
if(list.lnk[i]){
var txt = list.lnk[i] ;
var uri = i ;
var langTag = txt.split(':') ;
var langUri = uri.split(':') ;
if(langTag.length == 2) {
if(splitCnt >= cols) {
splitCnt = 1 ;
html += '</tr><tr>' ;
} else
splitCnt++ ;
var langId = langTag[1] ;
var langUr = langUri[1] ;
html += '<td ' + wd + '>' + alink(safeurl(langUr), txt,"&#8251") + '&nbsp;' +
alink(scriptUrl + '?' + langUr, langId,langId) + '</td>' ;
}
}
html += '</tr></table>' ;
return html ;
}
function makeTask() {
var html = '<table width="100%"><tr><td valign="top" width="33%">' ;
var capital = "?" ;
var heading ;
for(i in task.lnk)
if(!lang.lnk[i]) count++ ;
if(count > 0) {
var splitCnt = 0 ;
for(i in task.lnk)
if(!lang.lnk[i]) {
splitCnt++ ;
var lnk = rosettaUrl + i ;
var txt = task.lnk[i] ;
heading = capital ;
capital = txt.charAt(0) ;
if(splitCnt*3 > count + 2) {
splitCnt = 0 ;
html += '</ul></td><td valign="top" width="33%">'
if(capital == heading)
html += '<h3>' + heading + ' cont.<h3><ul>' ;
}
if(heading.charAt(0) != capital.charAt(0)) {
if(heading != "?")
html += '</ul>'
html += '<h3>' + capital + '<h3><ul>'
}
html += '<li>' + alink(lnk, txt, txt) + '</li>' ;
}
html += '</ul>' ;
} else
return "" ;
html += '</td></tr></table><br />' ;
return html ;
}</javascript>
&lt;/script&gt;
&lt;!-- from http://examples.oreilly.com/jscript5/ --&gt;
&lt;script&gt;
<javascript>/**
* http.js: utilities for scripted HTTP requests
*
* From the book JavaScript: The Definitive Guide, 5th Edition,
* by David Flanagan. Copyright 2006 O'Reilly Media, Inc. (ISBN: 0596101996)
*/
// Make sure we haven't already been loaded
var HTTP;
if (HTTP && (typeof HTTP != "object" || HTTP.NAME))
throw new Error("Namespace 'HTTP' already exists");
// Create our namespace, and specify some meta-information
HTTP = {};
HTTP.NAME = "HTTP"; // The name of this namespace
HTTP.VERSION = 1.0; // The version of this namespace
// This is a list of XMLHttpRequest creation factory functions to try
HTTP._factories = [
function() { return new XMLHttpRequest(); },
function() { return new ActiveXObject("Msxml2.XMLHTTP"); },
function() { return new ActiveXObject("Microsoft.XMLHTTP"); }
];
// When we find a factory that works, store it here
HTTP._factory = null;
/**
* Create and return a new XMLHttpRequest object.
*
* The first time we're called, try the list of factory functions until
* we find one that returns a nonnull value and does not throw an
* exception. Once we find a working factory, remember it for later use.
*/
HTTP.newRequest = function() {
if (HTTP._factory != null)
return HTTP._factory();
for(var i = 0; i < HTTP._factories.length; i++) {
try {
var factory = HTTP._factories[i];
var request = factory();
if (request != null) {
HTTP._factory = factory;
return request;
}
}
catch(e) {
continue;
}
}
// If we get here, none of the factory candidates succeeded,
// so throw an exception now and for all future calls.
HTTP._factory = function() {
throw new Error("XMLHttpRequest not supported");
}
HTTP._factory(); // Throw an error
}
/**
* Use XMLHttpRequest to fetch the contents of the specified URL using
* an HTTP GET request. When the response arrives, pass it (as plain
* text) to the specified callback function.
*
* This function does not block and has no return value.
*/
HTTP.getText = function(url, callback) {
var request = HTTP.newRequest();
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200)
callback(request.responseText);
}
request.open("GET", url);
request.send(null);
};
/**
* Use XMLHttpRequest to fetch the contents of the specified URL using
* an HTTP GET request. When the response arrives, pass it (as a parsed
* XML Document object) to the specified callback function.
*
* This function does not block and has no return value.
*/
HTTP.getXML = function(url, callback) {
var request = HTTP.newRequest();
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200)
callback(request.responseXML);
}
request.open("GET", url);
request.send(null);
};
/**
* Use an HTTP HEAD request to obtain the headers for the specified URL.
* When the headers arrive, parse them with HTTP.parseHeaders() and pass the
* resulting object to the specified callback function. If the server returns
* an error code, invoke the specified errorHandler function instead. If no
* error handler is specified, pass null to the callback function.
*/
HTTP.getHeaders = function(url, callback, errorHandler) {
var request = HTTP.newRequest();
request.onreadystatechange = function() {
if (request.readyState == 4) {
if (request.status == 200) {
callback(HTTP.parseHeaders(request));
}
else {
if (errorHandler)
errorHandler(request.status, request.statusText);
else
callback(null);
}
}
}
request.open("HEAD", url);
request.send(null);
};
/**
* Parse the response headers from an XMLHttpRequest object and return
* the header names and values as property names and values of a new object.
*/
HTTP.parseHeaders = function(request) {
var headerText = request.getAllResponseHeaders(); // Text from the server
var headers = {}; // This will be our return value
var ls = /^\s*/; // Leading space regular expression
var ts = /\s*$/; // Trailing space regular expression
// Break the headers into lines
var lines = headerText.split("\n");
// Loop through the lines
for(var i = 0; i < lines.length; i++) {
var line = lines[i];
if (line.length == 0) continue; // Skip empty lines
// Split each line at first colon, and trim whitespace away
var pos = line.indexOf(':');
var name = line.substring(0, pos).replace(ls, "").replace(ts, "");
var value = line.substring(pos+1).replace(ls, "").replace(ts, "");
// Store the header name/value pair in a JavaScript object
headers[name] = value;
}
return headers;
};
/**
* Send an HTTP POST request to the specified URL, using the names and values
* of the properties of the values object as the body of the request.
* Parse the server's response according to its content type and pass
* the resulting value to the callback function. If an HTTP error occurs,
* call the specified errorHandler function, or pass null to the callback
* if no error handler is specified.
**/
HTTP.post = function(url, values, callback, errorHandler) {
var request = HTTP.newRequest();
request.onreadystatechange = function() {
if (request.readyState == 4) {
if (request.status == 200) {
callback(HTTP._getResponse(request));
} else {
if (errorHandler)
errorHandler(request.status, request.statusText);
else
callback(null);
}
}
}
request.open("POST", url);
// This header tells the server how to interpret the body of the request
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
// Encode the properties of the values object and send them as
// the body of the request.
request.send(HTTP.encodeFormData(values));
};
/**
* Encode the property name/value pairs of an object as if they were from
* an HTML form, using application/x-www-form-urlencoded format
*/
HTTP.encodeFormData = function(data) {
var pairs = [];
var regexp = /%20/g; // A regular expression to match an encoded space
for(var name in data) {
var value = data[name].toString();
// Create a name/value pair, but encode name and value first
// The global function encodeURIComponent does almost what we want,
// but it encodes spaces as %20 instead of as "+". We have to
// fix that with String.replace()
var pair = encodeURIComponent(name).replace(regexp,"+") + '=' +
encodeURIComponent(value).replace(regexp,"+");
pairs.push(pair);
}
// Concatenate all the name/value pairs, separating them with &
return pairs.join('&');
};
/**
* Parse an HTTP response based on its Content-Type header
* and return the parsed object
*/
HTTP._getResponse = function(request) {
// Check the content type returned by the server
switch(request.getResponseHeader("Content-Type")) {
case "text/xml":
// If it is an XML document, use the parsed Document object
return request.responseXML;
case "text/json":
case "application/json":
case "text/javascript":
case "application/javascript":
case "application/x-javascript":
// If the response is JavaScript code, or a JSON-encoded value,
// call eval() on the text to "parse" it to a JavaScript value.
// Note: only do this if the JavaScript code is from a trusted server!
return eval(request.responseText);
default:
// Otherwise, treat the response as plain text and return as a string
return request.responseText;
}
};
/**
* Send an HTTP GET request for the specified URL. If a successful
* response is received, it is converted to an object based on the
* Content-Type header and passed to the specified callback function.
* Additional arguments may be specified as properties of the options object.
*
* If an error response is received (e.g., a 404 Not Found error),
* the status code and message are passed to the options.errorHandler
* function. If no error handler is specified, the callback
* function is called instead with a null argument.
*
* If the options.parameters object is specified, its properties are
* taken as the names and values of request parameters. They are
* converted to a URL-encoded string with HTTP.encodeFormData() and
* are appended to the URL following a '?'.
*
* If an options.progressHandler function is specified, it is
* called each time the readyState property is set to some value less
* than 4. Each call to the progress handler function is passed an
* integer that specifies how many times it has been called.
*
* If an options.timeout value is specified, the XMLHttpRequest
* is aborted if it has not completed before the specified number
* of milliseconds have elapsed. If the timeout elapses and an
* options.timeoutHandler is specified, that function is called with
* the requested URL as its argument.
**/
HTTP.get = function(url, callback, options) {
var request = HTTP.newRequest();
var n = 0;
var timer;
if (options.timeout)
timer = setTimeout(
function() {
request.abort();
if (options.timeoutHandler)
options.timeoutHandler(url);
},
options.timeout);
request.onreadystatechange = function() {
if (request.readyState == 4) {
if (timer)
clearTimeout(timer);
if (request.status == 200) {
callback(HTTP._getResponse(request));
} else {
if (options.errorHandler)
options.errorHandler(request.status, request.statusText);
else
callback(null);
}
} else
if (options.progressHandler) {
options.progressHandler(++n);
}
}
var target = url;
if (options.parameters)
target += "?" + HTTP.encodeFormData(options.parameters)
request.open("GET", target);
request.send(null);
};
HTTP.getTextWithScript = function(url, callback) {
// Create a new script element and add it to the document
var script = document.createElement("script");
document.body.appendChild(script);
// Get a unique function name
var funcname = "func" + HTTP.getTextWithScript.counter++;
// Define a function with that name, using this function as a
// convenient namespace. The script generated on the server
// invokes this function
HTTP.getTextWithScript[funcname] = function(text) {
// Pass the text to the callback function
callback(text);
// Clean up the script tag and the generated function
document.body.removeChild(script);
delete HTTP.getTextWithScript[funcname];
}
// Encode the URL we want to fetch and the name of the function
// as arguments to the jsquoter.php server-side script. Set the src
// property of the script tag to fetch the URL
script.src = "jsquoter.php" +
"?url=" + encodeURIComponent(url) + "&func=" +
encodeURIComponent("HTTP.getTextWithScript." + funcname);
}
// We use this to generate unique function callback names in case there
// is more than one request pending at a time.
HTTP.getTextWithScript.counter = 0;</javascript>
&lt;/script&gt;
&lt;body onLoad="process();" &gt;
&lt;table width="100%"&gt;
&lt;tr&gt;&lt;td valign=top&gt;&lt;div id="tasklist"&gt;
&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;hr /&gt;&lt;td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td valign=top&gt;&lt;div id="langlist"&gt;
&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
|}
Hope it can be a temporary solution. -- [[User:Badmadevil|badmadevil]] 02:24, 12 June 2008 (MDT)

Revision as of 16:55, 13 June 2008

Welcome to Rosetta Code! I founded RC around a year ago, and still do most of the administrative work. Thanks for your code contributions. I'm curious, though, how did you hear about RC? --Short Circuit 10:44, 23 February 2008 (MST)

Hi, thanks. I heard from a forward message posted at Digital Mars D newsgroup about a month ago. -badmadevil 03:03, 24 February 2008 (MST)

Mylang

Good job with the mylang templates. I had done as well as I could before, but these are better. --Mwn3d 13:52, 22 March 2008 (MDT)

thank for appreciation :) --badmadevil 07:54, 23 March 2008 (MDT)

Not Implemented Tasks by Language

Hello. IIRC, it has been mentioned a need to display a page of tasks not implemented by a specific language, it seems no such page at Rosetta Code yet. I've coded a dirty hack of such page using client-side javascript. It use xmlhttprequest to get the contents of Solutions_by_Programming_Task & the language specified page that contains tasks such language has been completed, then by parsing as DOM, extracting links under some specify id/tag, the links of set different of these 2 page are tasks that not implemented.
limitation :

  • javascript's XMLHTTPRequest doesn't allow cross site request, so this script's url host has to be same as the Category pages, that is , the pages has to be upload to Rosetta Code's website;
  • the bigger problem is, the pages does not work on IE browser. IE browser does not support DOMParser, which is currently required, and other workaround found on web seems not really work. (Hope experient coder can give some advice, or I may be re-done it using RegExp later, ... or try a PHP solution? )


Sources:

<html>
<title>Not Implemented Task by Langauge</title>
<!--script src="/http.js"></script--> 
<!--script src="http.js"></script--> 
<script>

<javascript> /**

**   C o n f i g
**/

// javascript's XMLHTTPRequest doesn't allow cross site request, // so this script's location's host has to be same as the Category pages. // the prefix change to 'http://rosettacode.org/wiki/Category:' should be ok //var mySitePrefix = 'http://localhost/wiki/' ; var mySitePrefix = 'http://rosettacode.org/wiki/Category:' ;

// set to false if test in a localhost // set to true if mySitePrefix is at rosetta site, // should allow reach C++, C# etc. pages //var usesafeurl = false ; var usesafeurl = true ;

// problem : // M$' IE has no DOMParser & workarounds seems not work, see a // workaround : http://www.van-steenbeek.net/?q=explorer_domparser_parsefromstring function parseDOM(xhtml) {

 var contentType = "application/xhtml+xml" ;
 if(typeof(DOMParser) != 'undefined')
   return (new DOMParser()).parseFromString(xhtml,contentType) ;
 else {
   if(typeof(ActiveXObject) != 'undefined') {
     var xmldata = new ActiveXObject('MSXML.DomDocument');
     xmldata.async = false;
     xmldata.loadXML(xhtml);
     return xmldata;
   } else if(typeof(XMLHttpRequest) != 'undefined') {
     var xmldata = new XMLHttpRequest;
     //contentType = 'application/xml';
     xmldata.open('GET', 'data:' + contentType + ';charset=utf-8,' + 
       encodeURIComponent(xhtml), false);
     if(xmldata.overrideMimeType)
       xmldata.overrideMimeType(contentType);
     xmldata.send(null);
     return xmldata.responseXML;
   }
 }

}

// To test in a loacl web server (eg. http://localhost): // 1.mkdir wiki in root dir of localhost, // save http://rosettacode.org/wiki/Category:<CATEGORYNAME> to // localhost/wiki/<CATEGORYNAME>/index.htm, // 2.<CATEGORYNAME> should at leat include Solutions_by_Programming_Task & // Solutions_by_Programming_Language, then include some other languages // categories, eg. C, Java, Python, etc. to start testing. // 3.place http.js where this html can located, // 4.no query string should be in url of this html, // 5.config mySitePrefix etc.

var NA = "?N/A" ; function Page(url, ID) {

 var o = new Object ;
 o.url  = url ;
 o.ID   = ID ;
 o.cnt  = 0 ;
 o.htm  = NA ;
 o.dom  ; 
 o.lnk  = new Array() ;
 o.setHtm = function(txt) { 
   o.htm = txt ; 
   var doc = parseDOM(o.htm) ; 
   o.dom = doc.getElementById(o.ID) ;
   o.getlink() ;
 }
 o.request = function() { HTTP.getText(o.url, o.setHtm)}
 o.getlink = function() {
   if(o.htm != NA) {
     var links = o.dom.getElementsByTagName("a") ;
     for(i in links) {
       if(links[i].innerHTML) {
         o.lnk[links[i].getAttributeNode("href").value] = 
           links[i].getAttributeNode("title").value ; 
         o.cnt++ ;
       }
     }
   }
 }
 return o ;

} var scriptUrl ; with(window.location)

 scriptUrl = protocol + '//' + host + pathname ;

var rosettaUrl = 'http://rosettacode.org' var langID = getLangID() ; // var safeurl = rosettaUrl + '/w/index.php?title=' + langID ; var langurl = langID != NA && usesafeurl ? safeurl() : mySitePrefix + langID ; var task = Page(mySitePrefix + 'Solutions_by_Programming_Task', "mw-pages") ; var lang = Page(langurl, "mw-pages") ; var list = Page(mySitePrefix + 'Solutions_by_Programming_Language', "mw-subcategories") ; var tasklist ; var langlist ; var timeoutCnt = 3 ; var count = 0 ;

function getLangID() {

 var langid = window.location.search.slice(1) ;
 if(langid.length == 0) return NA ;

 return langid ;

}

function safeurl(langname) {

 if(!langname) langname = langID ;
 return rosettaUrl + '/w/index.php?title=' + langname ;

}

function process() {

 tasklist = document.getElementById("tasklist") ;
 langlist = document.getElementById("langlist") ;
 tasklist.innerHTML = "...loading..." ;
 langlist.innerHTML = "...loading..." ;
 task.request() ;
 list.request() ;
 if(langID != NA) {
   lang.request() ;
   document.title = 'Not Implemented Tasks by Langauge ' + langID ;
 }
 waitLoad() ;

} function waitLoad() {

 timeoutCnt-- ;
 tasklist.innerHTML = "...loading, timeout in " + timeoutCnt + " sec..." ;
 if(timeoutCnt > 0 
     && ((langID != NA && lang.htm == NA) || task.htm == NA || list.htm == NA)) 
   return setTimeout(waitLoad,1000) ;  
 if(langID == NA)
   return failLoad() ;
 if(timeoutCnt <= 0)
   return failLoad() ;
 if(task.cnt == 0 || list.cnt == 0 || lang.cnt == 0) failLoad ;
 doParse() ;

} function failLoad() { // this part may be simplified to display just a short err message

 var errmsg = "" ;
 if(lang.htm == NA) { // may be not known language
   if(langID == NA)
     errmsg += 'Language ID not known.' ;
   else 
     errmsg += 'Error Page - url : ' + 
       alink(scriptUrl + '?' + langID,langID,langID, true)  ;
 }
 errmsg += '
' ; with(lang) if(htm == NA) errmsg += 'fail to load this url : ' + alink(url, url, url) + '
' ; with(list) if(htm == NA) errmsg += 'fail to load this url : ' + alink(url, url, url) + '
' ; with(task) if(htm == NA) errmsg += 'fail to load this url : ' + alink(url, url, url) + '
' ; tasklist.innerHTML = errmsg + makeStatus()  ; var taskdom = "" if(task.cnt > 0 && lang.cnt > 0) taskdom = makeTask() ; try { if(taskdom == "") taskdom = task.dom.innerHTML ; } catch(e) { taskdom = "" ; } if(taskdom != "") taskdom = makeMenu() + '
' + taskdom ; else taskdom = makeMenu() + '
Tasks Page not found/load.' ; var listdom = "" ; if(list.cnt >0) listdom = makeList(); try { if(listdom == "") listdom = list.dom.innerHTML ; } catch(e) { listdom = "" ; } if(listdom != "")
listdom = '
' + makeReturn() + '
' + listdom ;
 else 
listdom = '
' + makeReturn() + '
Languages List Page not found/load.' ;
 langlist.innerHTML = taskdom + listdom ;

} function doParse() {

 var taskdom = makeTask() ;
tasklist.innerHTML = makeMenu() + '

Tasks not implemented by ' + alink(rosettaUrl + '/wiki/' + langID, langID,langID, true) + '



There are ' +
   count + ' not implemented tasks out of ' + task.cnt + 
   ' total tasks. ' + '(' + lang.cnt+ ' completed tasks, implementations' + 
   ' & puzzles etc.)
' + taskdom ;
langlist.innerHTML = makeReturn() + '

Other languages :

' + makeList() ;

} function alink(url, tip, txt, normalsize) {

 var styleTxt = normalsize ? "" : ' style="font-size:smaller;"';

// var shortTxt = txt.length > 20 ? txt.slice(0,20) : txt ;

 return '<a href="' + url +  '" title="' + tip + '"' + styleTxt + '>' + unescape(txt) + 
   '</a>' ;

} function makeMenu() {

 var backLink ;
 if(langID == NA) {
   backLink = alink(list.url, "Solution by Languages", 
     'Return to Category : Solution by Languages') ;
 } else {
   backLink = alink(safeurl(), safeurl(), 'Return to Category : ' + langID)
 }
 return '<a name="returntop" href="#otherlanguages">' + 
   'Select other languages</a>  |  ' + 
backLink + '
' ;

} function makeReturn() {

 return '<a href="#returntop" name="otherlanguages">TOP</a>  |' + 
   '  ' + makeStatus() ;

} function makeStatus() {

 return '(total / langs / taskss) - pages length : ' + 
   task.htm.length + ' / ' + list.htm.length + ' / ' + 
   lang.htm.length  + '  |  link count : ' + task.cnt + 
   ' / ' + list.cnt + ' / ' + lang.cnt  ;

} function makeList() {

 if(list.cnt == 0) return "" ;
var html = '' ; splitCnt = 0 ; var cols = 6 ; var wd = 'width="' + Math.floor(100/cols) + '%"' ; for(i in list.lnk) if(list.lnk[i]){ var txt = list.lnk[i] ; var uri = i ; var langTag = txt.split(':') ; var langUri = uri.split(':') ; if(langTag.length == 2) { if(splitCnt >= cols) { splitCnt = 1 ; html += '' ; } else splitCnt++ ; var langId = langTag[1] ; var langUr = langUri[1] ; html += '' ; } } html += '
' + alink(safeurl(langUr), txt,"&#8251") + ' ' + alink(scriptUrl + '?' + langUr, langId,langId) + '
' ;
 return html ;

} function makeTask() {

var html = '
' ;
 var capital = "?" ;
 var heading ;
 for(i in task.lnk)
   if(!lang.lnk[i]) count++ ;    
 if(count > 0) {
   var splitCnt = 0 ;
   for(i in task.lnk)
     if(!lang.lnk[i]) {
       splitCnt++ ;
       var lnk = rosettaUrl + i ;
       var txt = task.lnk[i] ;
       heading = capital ;
       capital = txt.charAt(0) ;
       if(splitCnt*3 > count + 2)  {
         splitCnt = 0 ;      
html += '
'
         if(capital == heading)
html += '

' + heading + ' cont.

    ' ; } if(heading.charAt(0) != capital.charAt(0)) { if(heading != "?") html += '
' html += '

' + capital + '

    ' } html += '
  • ' + alink(lnk, txt, txt) + '
  • ' ; } html += '
' ;
 } else
   return "" ;
html += '


' ;
 return html ;

}</javascript>

</script>
<!-- from http://examples.oreilly.com/jscript5/ -->
<script>

<javascript>/**

* http.js: utilities for scripted HTTP requests
*
* From the book JavaScript: The Definitive Guide, 5th Edition,
* by David Flanagan. Copyright 2006 O'Reilly Media, Inc. (ISBN: 0596101996)
*/

// Make sure we haven't already been loaded var HTTP; if (HTTP && (typeof HTTP != "object" || HTTP.NAME))

 throw new Error("Namespace 'HTTP' already exists");

// Create our namespace, and specify some meta-information HTTP = {}; HTTP.NAME = "HTTP"; // The name of this namespace HTTP.VERSION = 1.0; // The version of this namespace

// This is a list of XMLHttpRequest creation factory functions to try HTTP._factories = [

 function() { return new XMLHttpRequest(); },
 function() { return new ActiveXObject("Msxml2.XMLHTTP"); },
 function() { return new ActiveXObject("Microsoft.XMLHTTP"); }

];

// When we find a factory that works, store it here HTTP._factory = null;

/**

* Create and return a new XMLHttpRequest object.
* 
* The first time we're called, try the list of factory functions until
* we find one that returns a nonnull value and does not throw an
* exception.  Once we find a working factory, remember it for later use.
*/

HTTP.newRequest = function() {

 if (HTTP._factory != null) 
   return  HTTP._factory();

 for(var i = 0; i < HTTP._factories.length; i++) {
   try {
     var factory = HTTP._factories[i];
     var request = factory();
     if (request != null) {
       HTTP._factory = factory;
       return request;
     }
   }
   catch(e) {
     continue;
   }
 }

 // If we get here, none of the factory candidates succeeded,
 // so throw an exception now and for all future calls.
 HTTP._factory = function() {
   throw new Error("XMLHttpRequest not supported");
 }
 HTTP._factory(); // Throw an error

}

/**

* Use XMLHttpRequest to fetch the contents of the specified URL using
* an HTTP GET request.  When the response arrives, pass it (as plain
* text) to the specified callback function.
* 
* This function does not block and has no return value.
*/

HTTP.getText = function(url, callback) {

 var request = HTTP.newRequest();
 request.onreadystatechange = function() {
   if (request.readyState == 4 && request.status == 200)
     callback(request.responseText);
 }
 request.open("GET", url);
 request.send(null);

};

/**

* Use XMLHttpRequest to fetch the contents of the specified URL using
* an HTTP GET request.  When the response arrives, pass it (as a parsed
* XML Document object) to the specified callback function.
* 
* This function does not block and has no return value.
*/

HTTP.getXML = function(url, callback) {

 var request = HTTP.newRequest();
 request.onreadystatechange = function() {
   if (request.readyState == 4 && request.status == 200)
     callback(request.responseXML);
 }
 request.open("GET", url);
 request.send(null);

};

/**

* Use an HTTP HEAD request to obtain the headers for the specified URL.
* When the headers arrive, parse them with HTTP.parseHeaders() and pass the
* resulting object to the specified callback function. If the server returns
* an error code, invoke the specified errorHandler function instead.  If no
* error handler is specified, pass null to the callback function.
*/

HTTP.getHeaders = function(url, callback, errorHandler) {

 var request = HTTP.newRequest();
 request.onreadystatechange = function() {
   if (request.readyState == 4) {
     if (request.status == 200) {
       callback(HTTP.parseHeaders(request));
     }
     else {
       if (errorHandler) 
         errorHandler(request.status, request.statusText);
       else 
         callback(null);
     }
   }
 }
 request.open("HEAD", url);
 request.send(null);

};

/**

* Parse the response headers from an XMLHttpRequest object and return
* the header names and values as property names and values of a new object.
*/

HTTP.parseHeaders = function(request) {

 var headerText = request.getAllResponseHeaders();  // Text from the server
 var headers = {}; // This will be our return value
 var ls = /^\s*/;  // Leading space regular expression
 var ts = /\s*$/;  // Trailing space regular expression

 // Break the headers into lines
 var lines = headerText.split("\n");
 // Loop through the lines
 for(var i = 0; i < lines.length; i++) {
   var line = lines[i];
   if (line.length == 0) continue;  // Skip empty lines
   // Split each line at first colon, and trim whitespace away
   var pos = line.indexOf(':');     
   var name = line.substring(0, pos).replace(ls, "").replace(ts, "");
   var value = line.substring(pos+1).replace(ls, "").replace(ts, "");
   // Store the header name/value pair in a JavaScript object
   headers[name] = value;
 }
 return headers;

};

/**

* Send an HTTP POST request to the specified URL, using the names and values
* of the properties of the values object as the body of the request.
* Parse the server's response according to its content type and pass
* the resulting value to the callback function.  If an HTTP error occurs,
* call the specified errorHandler function, or pass null to the callback
* if no error handler is specified.
**/

HTTP.post = function(url, values, callback, errorHandler) {

 var request = HTTP.newRequest();
 request.onreadystatechange = function() {
   if (request.readyState == 4) {
     if (request.status == 200) {
       callback(HTTP._getResponse(request));
     } else {
       if (errorHandler) 
         errorHandler(request.status, request.statusText);
       else 
         callback(null);
     }
   }
 }

 request.open("POST", url);
 // This header tells the server how to interpret the body of the request
 request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 // Encode the properties of the values object and send them as
 // the body of the request.
 request.send(HTTP.encodeFormData(values));

};

/**

* Encode the property name/value pairs of an object as if they were from
* an HTML form, using application/x-www-form-urlencoded format
*/

HTTP.encodeFormData = function(data) {

 var pairs = [];
 var regexp = /%20/g; // A regular expression to match an encoded space

 for(var name in data) {
   var value = data[name].toString();
   // Create a name/value pair, but encode name and value first
   // The global function encodeURIComponent does almost what we want,
   // but it encodes spaces as %20 instead of as "+". We have to
   // fix that with String.replace()
   var pair = encodeURIComponent(name).replace(regexp,"+") + '=' +
     encodeURIComponent(value).replace(regexp,"+");
   pairs.push(pair);
 }

 // Concatenate all the name/value pairs, separating them with &
 return pairs.join('&');

};

/**

* Parse an HTTP response based on its Content-Type header
* and return the parsed object
*/

HTTP._getResponse = function(request) {

 // Check the content type returned by the server
 switch(request.getResponseHeader("Content-Type")) {
   case "text/xml":
     // If it is an XML document, use the parsed Document object
     return request.responseXML;
   case "text/json":
   case "application/json": 
   case "text/javascript":
   case "application/javascript":
   case "application/x-javascript":
       // If the response is JavaScript code, or a JSON-encoded value,
       // call eval() on the text to "parse" it to a JavaScript value.
       // Note: only do this if the JavaScript code is from a trusted server!
       return eval(request.responseText);
   default:
       // Otherwise, treat the response as plain text and return as a string
       return request.responseText;
 }

};

/**

* Send an HTTP GET request for the specified URL.  If a successful
* response is received, it is converted to an object based on the
* Content-Type header and passed to the specified callback function.
* Additional arguments may be specified as properties of the options object.
*
* If an error response is received (e.g., a 404 Not Found error),
* the status code and message are passed to the options.errorHandler
* function.  If no error handler is specified, the callback
* function is called instead with a null argument.
* 
* If the options.parameters object is specified, its properties are
* taken as the names and values of request parameters.  They are
* converted to a URL-encoded string with HTTP.encodeFormData() and
* are appended to the URL following a '?'.
* 
* If an options.progressHandler function is specified, it is
* called each time the readyState property is set to some value less
* than 4.  Each call to the progress handler function is passed an
* integer that specifies how many times it has been called.
*
* If an options.timeout value is specified, the XMLHttpRequest
* is aborted if it has not completed before the specified number
* of milliseconds have elapsed.  If the timeout elapses and an
* options.timeoutHandler is specified, that function is called with
* the requested URL as its argument.
**/

HTTP.get = function(url, callback, options) {

 var request = HTTP.newRequest();
 var n = 0;
 var timer;
 if (options.timeout)
   timer = setTimeout(
     function()  {
       request.abort();
       if (options.timeoutHandler)
         options.timeoutHandler(url);
     },
     options.timeout);

 request.onreadystatechange = function() {
   if (request.readyState == 4) {
     if (timer) 
       clearTimeout(timer);
     if (request.status == 200) {
       callback(HTTP._getResponse(request));
     } else {
       if (options.errorHandler)
         options.errorHandler(request.status, request.statusText);
       else 
         callback(null);
     }
   } else 
     if  (options.progressHandler) {
       options.progressHandler(++n);
     }
 }

 var target = url;
 if (options.parameters)
   target += "?" + HTTP.encodeFormData(options.parameters)
 request.open("GET", target);
 request.send(null);

};

HTTP.getTextWithScript = function(url, callback) {

 // Create a new script element and add it to the document
 var script = document.createElement("script");
 document.body.appendChild(script);

 // Get a unique function name
 var funcname = "func" + HTTP.getTextWithScript.counter++;

 // Define a function with that name, using this function as a
 // convenient namespace.  The script generated on the server
 // invokes this function
 HTTP.getTextWithScript[funcname] = function(text) {
   // Pass the text to the callback function
   callback(text);

   // Clean up the script tag and the generated function
   document.body.removeChild(script);
   delete HTTP.getTextWithScript[funcname];
 }

 // Encode the URL we want to fetch and the name of the function
 // as arguments to the jsquoter.php server-side script.  Set the src
 // property of the script tag to fetch the URL
 script.src = "jsquoter.php" +
   "?url=" + encodeURIComponent(url) + "&func="  +
   encodeURIComponent("HTTP.getTextWithScript."  + funcname);

}

// We use this to generate unique function callback names in case there // is more than one request pending at a time. HTTP.getTextWithScript.counter = 0;</javascript>

</script>
<body onLoad="process();" >
<table width="100%">
<tr><td valign=top><div id="tasklist">
</div></td></tr>
<tr><td><hr /><td></tr>
<tr><td valign=top><div id="langlist">
</div></td></tr>
</table>
</body>
</html>

Hope it can be a temporary solution. -- badmadevil 02:24, 12 June 2008 (MDT)