User talk:Badmadevil: Difference between revisions

 
(9 intermediate revisions by 2 users not shown)
Line 1:
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? --[[User:Short Circuit|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. -[[User:Badmadevil|badmadevil]] 03:03, 24 February 2008 (MST)
 
== Theme problems ==
Hi there, I'm really not seeing the issues you're reporting about the new skin. <del>If you could, post the browser version as well, as I see neither of the problems you've listed in the ones I'm testing with (FF3, Opera 9.5, IE7)</del> I'm really not seeing the issues you're talking about. Perhaps your font size is larger than normal? Ctrl + 0 or View > Zoom > Reset.
--[[User:Qrush|qrush]] 19:54, 22 June 2008 (UTC)
:oops... then my browser setting problem is the most possible explanation, sorry for the extra work. (btw, in my FF3, by changing zoom, it only affect the size of top-left logo's ''Rosetta Code'' text if ''zoom text only'', else everything is proportional) -- [[User:Badmadevil|badmadevil]] 04:08, 23 June 2008 (UTC)
:: This should be fixed. Give the skim another try. --[[User:Short Circuit|Short Circuit]] 00:14, 14 February 2009 (UTC)
 
== Mylang ==
Line 9 ⟶ 15:
== Not Implemented Tasks by Language ==
 
Hello. IIRC, it has been mentioned an idea to display a page of tasks not implemented by a specific language (It is from [[User:IanOsgood|Ian Osgood]]'s [[Rosetta_Code:Wiki_Wishlist|wishlist]]), it seems no such page at Rosetta Code yet. I've coded a dirty hack of such page using client-side javascriptPHP. It<br use/><br xmlhttprequest/>This toversion getshould thepreserve contentsRosetta ofCode's Solutions_by_Programming_Taskpages &look theand language specified page that contains tasks such language has been completedfeel, thenand bymay parsingbe asbetter DOM,integrated extractinginto linksRC undersite.<br some specify id/tag, the links of set different of these 2 page are tasks that not implemented.><br />'''limitation :'''
''Bugs fix notes :''
*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;
*When PHP flag <i>allow_url_fopen</i> is enabled, it is possible to read contents from RC Site via local server. Then, by directly testing with RC Site, many bugs were found;
*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? )
*''fixed'', it seems that articles in tasks or languages' pages have at least 3 version of url. In most cases, they refer to the same file, but it seems some are not (may be re-direction?). Previously, some url can be accessed while other cannot, if only using one version of url; now all 3 version is tried. The version of '/w/index.php?title=' has highest priority, so that page like C++ will not mistaken by C page;
<br />
::''changed'', it seems I'm wrong again. All pages can be accesses by '/wiki/Category:' version's url, only that to not mistaken C++ page with C page, url extracted from RC page have to be encoded 2 times. In most case, this '/wiki/Category:(encoded-url)' can reach the page correctly, only pages like ''PL/I'', ''PL/SQL'' need 1 decode. No more other version of url is needed. -- [[User:Badmadevil|badmadevil]] 09:14, 17 June 2008 (MDT)
''Sources'':
*''fixed'', previously, required link nodes to be got by xpath are assumed to be inside a table, but it is found that language page having 7 or less task completed didn't use a table; the later case is dealing with another proper xpath;
*some pages have not any task completed, eg. assembler, pike, JoCaml. They are treated as error loading page, rather than display all tasks from Task-list page;
*''unsolved'', there are unknown errors on parsing pages of ''JScript.NET'' & ''Visual Basic.NET'' as DOM. They can be load as DOMDocument (so that it is not a problem of url, eg.wrong encoding of url string), but can't get the required Node by getElementById inside the DOMDoc;
::''fixed'', it is really a problem of wrong encoding, the 'dot' is not properly encoded, and the page loaded I said previously is the create new articles page. It has been fixed. All bugs should has been fixed. -- [[User:Badmadevil|badmadevil]] 12:22, 16 June 2008 (MDT)
*''Usage'', this version need not config, as long as allow_url_fopen is enabled. Place this script in a server (local server or RC Site) some where can be access from www, and that is it.
*Tested with PHP 5.2.1
<br /><br />''Sources'':
{||-
| style="height:36em;float:left;clear:both;overflow:auto;" |
<php><?php
&lt;html&gt;
// may be need to enable allow_url_fopen, or change it to local file path
&lt;title&gt;Not Implemented Task by Langauge&lt;/title&gt;
define('RCHost' , 'www.rosettacode.org') ;
&lt;!--script src="/http.js"&gt;&lt;/script--&gt;
define('ROSETTA', 'http://' . RCHost) ;
&lt;!--script src="http.js"&gt;&lt;/script--&gt;
define('Prefix', ROSETTA . '/wiki/Category:') ;
&lt;script&gt;
define('TaskURL', 'Solutions_by_Programming_Task') ;
<javascript>
define('ListURL', 'Solutions_by_Programming_Language') ;
/**
 
** C o n f i g
define('LANGID', 'LANGID') ; // if use as a query string key-value pair
**/
define('NA', 'NotAvaliable') ;
// javascript's XMLHTTPRequest doesn't allow cross site request,
 
// so this script's location's host has to be same as the Category pages.
$subfix = "" ;
// the prefix change to 'http://rosettacode.org/wiki/Category:' should be ok
$langID = LangId() ;
//var mySitePrefix = 'http://localhost/wiki/' ;
$IDLang = myDecode($langID) ;
var mySitePrefix = 'http://rosettacode.org/wiki/Category:' ;
 
// this control how to access this scrtpt
// set to false if test in a localhost
$scriptURL = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['URL'] ;
// set to true if mySitePrefix is at rosetta site,
 
// should allow reach C++, C# etc. pages
function ScriptURL($langId){
//var usesafeurl = false ;
global $scriptURL, $subfix;
var usesafeurl = true ;
if($langId == NA)
// problem :
$tail = strlen($subfix) == 0 ? '' : '?' . $subfix ;
// 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 {
$tail = strlen($subfix) == 0 ? '' : '&' . $subfix ;
if(typeof(ActiveXObject) != 'undefined') {
$tail = '?' . LANGID . '=' . myEncode($langId) . $tail ;
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;
}
}
return $scriptURL . $tail ;
}
// 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 ;
}
function pageUrl($page) {
var scriptUrl ;
global $subfix;
with(window.location)
scriptUrl$tail = protocolstrlen($subfix) +== 0 ? '//' +: host'?' +. pathname$subfix ;
return Prefix . $page . $tail ;
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 myEncode($s) { return str_replace('.', '%252E', rawurlencode($s)) ; }
function myDecode($s) { return str_replace('_', ' ' , rawurldecode($s)) ; }
function safeurl(langname) {
 
if(!langname) langname = langID ;
function LangId(){
return rosettaUrl + '/w/index.php?title=' + langname ;
global $subfix ;
}
$langId = NA ;
if(count($_SERVER['QUERY_STRING']) > 0) {
function process() {
parse_str($_SERVER['QUERY_STRING'], $query) ;
tasklist = document.getElementById("tasklist") ;
if(array_key_exists(LANGID, $query) && strlen($query[LANGID]) > 0)
langlist = document.getElementById("langlist") ;
$langId = $query[LANGID] ;
tasklist.innerHTML = "...loading..." ;
else
langlist.innerHTML = "...loading..." ;
foreach($query as $key => $value)
task.request() ;
if(strlen($value) == 0) {
list.request() ;
$query[LANGID] = $key ;
if(langID != NA) {
lang.request() $langId = $key ;
unset($query[$key]) ;
document.title = 'Not Implemented Tasks by Langauge ' + langID ;
break ;
}
if(array_key_exists(LANGID, $query))
unset($query[LANGID]) ;
$subfix = http_build_query($query) ;
}
waitLoad()return $langId ;
}
 
function waitLoad() {
class Page extends DOMDocument {
timeoutCnt-- ;
public $lnk , $hdr, $msg , $tds, $url, $context ;
tasklist.innerHTML = "...loading, timeout in " + timeoutCnt + " sec..." ;
public $dict = array() , $ok = TRUE ;
if(timeoutCnt > 0
public $cnt = 0 , $notCnt = 0 ; // $notCnt = count of not implemented tasks
&& ((langID != NA && lang.htm == NA) || task.htm == NA || list.htm == NA))
 
return setTimeout(waitLoad,1000) ;
function __construct($url, $id) {
if(langID == NA)
returnglobal failLoad()$langID ;
if(timeoutCnt$url <== 0$langID) {
if(!@$this->loadHTMLFile($this->url = pageURL($langID)))
return failLoad() ;
if(!@$this->loadHTMLFile($this->url = pageURL(myDecode($langID))))
if(task.cnt == 0 || list.cnt == 0 || lang.cnt == 0) return failLoad ;
$this->ok = FALSE ;
doParse() ;
if($this->ok) $this->context = $this->getElementById($id) ;
}
} else {
function failLoad() { // this part may be simplified to display just a short err message
if(@$this->loadHTMLFile($url))
var errmsg = "" ;
$this->context = $this->getElementById($id) ;
if(lang.htm == NA) { // may be not known language
}
if(langID == NA)
if($this->context) {
errmsg += 'Language ID not known.' ;
$xpath = new DOMXPath($this) ;
else
$this->hdr = $xpath->query('h2', $this->context)->item(0) ;
errmsg += 'Error Page - url : ' +
$this->msg = $xpath->query('p', $this->context)->item(0) ;
alink(scriptUrl + '?' + langID,langID,langID, true) ;
if($xpath->query('table', $this->context)->length)
$this->lnk = $xpath->query('table/tr/td/ul/li', $this->context) ;
else // not inside a table
$this->lnk = $xpath->query('ul/li', $this->context) ;
$this->cnt = $this->lnk->length ;
} else
$this->ok = FALSE ;
}
function toHTML() {
errmsg += '<br />' ;
// not need if this script is inside RC site
with(lang) if(htm == NA)
if(stristr($_SERVER['HTTP_HOST'], RCHost) === FALSE) {
errmsg += 'fail to load this url : ' + alink(url, url, url) + '<br />' ;
$head = $this->getElementsByTagName("head")->item(0) ;
with(list) if(htm == NA)
errmsg += 'fail$base to load= $this url : ' + alink->createElement(url, url, url"base") + '<br />' ;
$base->setAttribute("href", ROSETTA) ;
with(task) if(htm == NA)
$head->insertBefore($base, $head->firstChild) ;
errmsg += 'fail to load this url : ' + alink(url, url, url) + '<br />' ;
}
tasklist.innerHTML = errmsg + makeStatus() ;
return $this->saveHTML() ;
var taskdom = ""
if(task.cnt > 0 && lang.cnt > 0) taskdom = makeTask() ;
try {
if(taskdom == "") taskdom = task.dom.innerHTML ;
} catch(e) {
taskdom = "" ;
}
function prepare(&$taskList) {
if(taskdom != "")
taskdom$temp = makeMenuarray() + '<br />' + taskdom ;
// collect lang's task list
else
for($i = 0 ; $i < $this->lnk->length ; $i++) {
taskdom = makeMenu() + '<br />Tasks Page not found/load.' ;
$alink = $this->lnk->item($i)->getElementsByTagName("a")->item(0) ;
var listdom = "" ;
$temp[$alink->getAttribute("href")] = TRUE ;
if(list.cnt >0) listdom = makeList();
try { }
// set diff : total tasks - lang's tasks => not completed tasks
if(listdom == "") listdom = list.dom.innerHTML ;
for($i = 0 ; $i < $taskList->length ; $i++) {
} catch(e) {
$alink = $taskList->item($i)->getElementsByTagName("a")->item(0) ;
listdom = "" ;
if(array_key_exists($alink->getAttribute("href"), $temp) === FALSE)
$this->dict[$this->notCnt++] = // import from Tasks into Lang
$this->importNode($taskList->item($i),true) ;
}
$lang->lnk = null ; // release node ref. to be remove
// clear All nodes under $this->context(id)'s node
while($this->context->lastChild)
$this->context->removeChild($this->context->lastChild) ;
// create new hdr, msg
$this->hdr = $this->context->appendChild($this->createElement("h2")) ;
$this->msg = $this->context->appendChild($this->createElement("p")) ;
// make table
$table = $this->createElement("table") ;
$tr = $this->createElement("tr") ;
for($i = 0 ; $i < 3 ; $i++)
$tr->appendChild($this->createElement("td")) ;
$table->appendChild($tr) ;
$this->context->appendChild($table) ;
// get tds later work with
$xpath = new DOMXPath($this) ;
$this->tds = $xpath->query('table/tr/td', $this->context) ;
}
if(listdom != "")
listdom = '<hr />' + makeReturn() + '<hr />' + listdom ;
else
listdom = '<hr />' + makeReturn() + '<hr />Languages List Page not found/load.' ;
langlist.innerHTML = taskdom + listdom ;
}
 
function doParse() {
function process_task(){
var taskdom = makeTask() ;
global $task, $lang ;
tasklist.innerHTML = makeMenu() + '<h2>Tasks not implemented by ' + alink(rosettaUrl +
 
'/wiki/' + langID, langID,langID, true) + '</h2><hr /><br />There are <strong>' +
if($lang->notCnt == 0) {
count + '</strong> not implemented tasks out of <strong>' + task.cnt +
$lang->msg->nodeValue =
'</strong> total tasks. ' + '(' + lang.cnt+ ' completed tasks, implementations' +
"All {$task->cnt} simpler tasks are completed ( {$lang->cnt} " .
' & puzzles etc.)<br />' + taskdom ;
"total completed tasks, some implementations and puzzles may be " .
langlist.innerHTML = makeReturn() + '<hr /><h3>Other languages :</h3>' + makeList() ;
"not yet completed )." ;
}
// no more tasks below, add a height to the table to look like a void.
function alink(url, tip, txt, normalsize) {
$lang->tds->item(0)->setAttribute("height", "100px") ;
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 {
$lang->msg->nodeValue =
backLink = alink(safeurl(), safeurl(), 'Return to Category : ' + langID)
"There are {$lang->notCnt} not completed tasks " .
}
"out of {$task->cnt} total tasks ( {$lang->cnt} " .
return '<a name="returntop" href="#otherlanguages">' +
"completed tasks, implementations and puzzles etc.)." ;
'Select other languages</a>&nbsp;&nbsp;|&nbsp;&nbsp;' +
 
backLink + '<hr />' ;
$curr = 0 ;
}
$splitMax = $lang->tds->length ;
function makeReturn() {
$splitMax = intval(($lang->notCnt + $splitMax - 1) / $splitMax) ;
return '<a href="#returntop" name="otherlanguages">TOP</a>&nbsp;&nbsp;|' +
if($splitMax < 5) $splitMax = 5 ;
'&nbsp;&nbsp;' + makeStatus() ;
 
}
$capital = '' ;
function makeStatus() {
for($i = 0 ; $i < $lang->tds->length ; $i++) {
return '(total&nbsp;/&nbsp;langs&nbsp;/&nbsp;taskss) - pages length : ' +
$td = $lang->tds->item($i) ;
task.htm.length + '&nbsp;/&nbsp;' + list.htm.length + '&nbsp;/&nbsp;' +
$td->setAttribute("width", intval(100/$lang->tds->length) . "%") ;
lang.htm.length + '&nbsp;&nbsp;|&nbsp;&nbsp;link count : ' + task.cnt +
$td->setAttribute("valign", "top") ;
'&nbsp;/&nbsp;' + list.cnt + '&nbsp;/&nbsp;' + lang.cnt ;
$ul = NULL ;
}
$splitCnt = 0 ;
function makeList() {
while($curr < $lang->notCnt && $splitCnt < $splitMax) {
if(list.cnt == 0) return "" ;
$li = $lang->dict[$curr] ;
var html = '<table width="100%"><tr>' ;
splitCnt $heading = 0$capital ;
$title = $li->getElementsByTagName("a")->item(0)->getAttribute("title") ;
var cols = 6 ;
$capital = strtoupper(substr($title, 0, 1)) ;
var wd = 'width="' + Math.floor(100/cols) + '%"' ;
if($splitCnt == 0) {
for(i in list.lnk)
if(list.lnk[i]$capital == $heading){
$h3 = $lang->createElement("h3", $capital . " cont.") ;
var txt = list.lnk[i] ;
var uri = i ;else
var langTag $h3 = txt.split$lang->createElement(':'"h3", $capital) ;
var langUri = uri.split $td->appendChild(':'$h3) ;
$ul = $lang->createElement("ul") ;
if(langTag.length == 2) {
} else if(splitCnt$capital >!= cols$heading) {
splitCnt = 1$td->appendChild($ul) ;
html$h3 += '</tr$lang-><tr>'createElement("h3", $capital) ;
} else $td->appendChild($h3) ;
splitCnt++$ul = $lang->createElement("ul") ;
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>' ;
}
$ul->appendChild($li) ;
if(heading.charAt(0) != capital.charAt(0)) {
$curr++ if(heading != "?");
html $splitCnt++= '</ul>';
html += '<h3>' + capital + '<h3><ul>'
}
html += '<li>' + alink(lnk, txt, txt) + '</li>' ;
}
html += '</if($ul) $td->'appendChild($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;
}
}
}
function process_list(){ // replace languages link with corresponding scriptURL
// If we get here, none of the factory candidates succeeded,
global $list ;
// so throw an exception now and for all future calls.
for($i = 0 ; $i < $list->lnk->length ; $i++) {
HTTP._factory = function() {
$alink = $list->lnk->item($i)->getElementsByTagName("a")->item(0) ;
throw new Error("XMLHttpRequest not supported");
$href = $alink->getAttribute("href") ;
$idLang = substr($href, 1 + strrpos($href,":")) ;
$alink->setAttribute("href", ScriptURL($idLang)) ;
}
HTTP._factory(); // Throw an error
}
function linkText(&$node, $pre, $href, $text, $post) {
$doc = $node->ownerDocument ;
/**
if($pre ) $node->appendChild($doc->createElement("span", $pre)) ;
* Use XMLHttpRequest to fetch the contents of the specified URL using
if($href) {
* an HTTP GET request. When the response arrives, pass it (as plain
if(!$text) $text = 'null' ;
* text) to the specified callback function.
$alink = $doc->createElement("a", $text) ;
*
$alink->setAttribute("href", $href) ;
* This function does not block and has no return value.
$alink->setAttribute("title", $text) ;
*/
$node->appendChild($alink) ;
HTTP.getText = function(url, callback) {
var request = HTTP.newRequest();
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200)
callback(request.responseText);
}
if($post) $node->appendChild($doc->createElement("span", $post)) ;
request.open("GET", url);
}
request.send(null);
 
};
/*
* Main Body
/**
* 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) {
if($langID != NA) {
var request = HTTP.newRequest();
$lang = new Page($langID, 'mw-pages') ;
request.onreadystatechange = function() {
if($lang->ok) {
if (request.readyState == 4 && request.status == 200)
$task = new Page(pageURL(TaskURL), 'mw-pages') ;
callback(request.responseXML);
if($task->ok)
$lang->prepare($task->lnk) ;
}
}
request.open("GET", url);
 
request.send(null);
if($langID != NA && $lang->ok && $task->ok) {
};
linkText($lang->hdr, 'Not Completed Tasks by ', $lang->url, $IDLang, NULL) ;
linkText($lang->hdr, ' ( ', ScriptURL(NA), 'Other Languages', ' ) ') ;
/**
 
* Use an HTTP HEAD request to obtain the headers for the specified URL.
process_task() ;
* When the headers arrive, parse them with HTTP.parseHeaders() and pass the
echo $lang->toHTML() ;
* resulting object to the specified callback function. If the server returns
} else {
* an error code, invoke the specified errorHandler function instead. If no
$list = new Page(pageURL(ListURL), 'mw-subcategories') ;
* error handler is specified, pass null to the callback function.
if($list->ok) {
*/
if($langID == NA)
HTTP.getHeaders = function(url, callback, errorHandler) {
$list->hdr->nodeValue = 'Not Completed Tasks by Languages' ;
var request = HTTP.newRequest();
else {
request.onreadystatechange = function() {
$list->hdr->removeChild($list->hdr->lastChild) ;
if (request.readyState == 4) {
linkText($list->hdr, 'Not Completed Tasks by Languages ( "',
if (request.status == 200) {
$lang->url, $IDLang, '" hasn\'t any task completed yet ) ') ;
callback(HTTP.parseHeaders(request));
}
else {
if (errorHandler)
errorHandler(request.status, request.statusText);
else
callback(null);
}
}
process_list() ;
echo $list->toHTML() ;
}
else
request.open("HEAD", url);
echo '<html><body><br/><br/>
request.send(null);
<h3 align=center>Unknown Error,
};
<a href="' . ROSETTA . '">Return Rosetta Code Main Page</a> or
<a href="javascript:history.go(-1) ;">Go Back</a>.
/**
</h3>
* Parse the response headers from an XMLHttpRequest object and return
</body></html>' ;
* 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);
}
?></php>
// 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]] 1112:3533, 1322 June 2008 (MDTUTC)