User talk:Badmadevil: Difference between revisions

m (→‎Not Implemented Tasks by Language: php version, hopefully the final version)
 
(7 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 PHP. <br /><br />This version should preserve Rosetta Code's pages look and feel, and may be better integrated into RC site.<br /><br />''Sources'':
''Bugs fix notes :''
*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;
*''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;
::''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)
*''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
// may be need to enable allow_url_fopen, or change it to local file path
define('RCHost' , 'www.rosettacode.org') ;
define('ROSETTA', 'http://' . RCHost) ;
define('Prefix', ROSETTA . '/wiki/Category:') ;
define('TaskURL', 'Solutions_by_Programming_Task') ;
define('ListURL', 'Solutions_by_Programming_Language') ;
 
define('LANGID', 'LANGID') ; // if use as a query string key-value pair
define('Prefix', 'http://www.lynx.ran/wiki/') ;
//define('PrefixNA', 'http://rosettacode.org/wiki/Category:NotAvaliable') ;
define('SafeURL', FALSE) ;
//define('SafeURL', TRUE) ;
define('SafePath', '/w/index.php?title=') ;
define('ROSETTA', 'http://rosettacode.org') ;
 
define('NoWarning', TRUE) ;
//define('NoWarning', FALSE) ;
 
define('LANG', 'lang') ; // if use as a query string key-value pair
define('NA', 'Not Avaliable') ;
 
define('TaskURL', Prefix . 'Solutions_by_Programming_Task') ;
define('ListURL', Prefix . 'Solutions_by_Programming_Language') ;
 
$subfix = "" ;
$langID = LangId() ;
$langURLIDLang = LangURLmyDecode($langID) ;
 
// this control how to access this scrtpt
$scriptURL = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAMEURL'] ;
function ScriptURL($langId = NA){
global $langID, $scriptURL ;
if($langId == NA) $langId = $langID ;
return $scriptURL . ($langId == NA ? "" : '?' . $langId) ;
}
 
function ScriptURL($langId){
// use only by the specifuc language page, use SafeURL to reach C++ pages
global $scriptURL, $subfix;
function LangURL($langId = NA){
global $langID ;
if($langId == NA) $langId = $langID ;
if($langId == NA)
$tail = strlen($subfix) == 0 ? '' : '?' . $subfix ;
return "http://" ; // if $langID is NA, this url will not be used anyway.
else {
return SafeURL ? ROSETTA . SafePath . $langId : Prefix . $langId ;
$tail = strlen($subfix) == 0 ? '' : '&' . $subfix ;
$tail = '?' . LANGID . '=' . myEncode($langId) . $tail ;
}
return $scriptURL . $tail ;
}
function pageUrl($page) {
global $subfix;
$tail = strlen($subfix) == 0 ? '' : '?' . $subfix ;
return Prefix . $page . $tail ;
}
function myEncode($s) { return str_replace('.', '%252E', rawurlencode($s)) ; }
function myDecode($s) { return str_replace('_', ' ' , rawurldecode($s)) ; }
 
function LangId(){
global $subfix ;
$langId = NA ;
if(count($_SERVER['QUERY_STRING']) > 0) {
parse_str($_SERVER['QUERY_STRING'], $query) ;
if(array_key_exists(LANGID, $query) && strlen($query[LANGID]) > 0)
$langId = $query[LANGID] ;
else
foreach($query as $key => $value)
if(strlen($value) == 0) {
$query[LANGID] = $key ;
$langId = $key ;
unset($query[$key]) ;
break ;
}
if(array_key_exists(LANGID, $query))
unset($query[LANGID]) ;
$subfix = http_build_query($query) ;
}
return $langId ;
}
 
class Page extends DOMDocument {
public $lnk =, NULL$hdr, $msg , $tds, $url, $context ;
public $hdr,dict $msg= array() , $tdsok = TRUE ;
public $cnt = 0 , $notCnt = 0 ; // $notCnt = count of not implemented tasks
public $dict = array() ;
public $ok = FALSE ;
public $cnt , $notCnt = 0 ; // $notCnt = count of not implemented tasks
 
function __construct($url, $id,$isLangPage = FALSE) {
global $langID ;
if($this->loadHTMLFile($url)) {
if($contexturl == $this->getElementById($idlangID) ;{
if(!@$this->loadHTMLFile($this->url = pageURL($langID)))
if(!@$this->loadHTMLFile($this->url = pageURL(myDecode($langID))))
$this->ok = FALSE ;
if($this->ok) $this->context = $this->getElementById($id) ;
} else {
if(@$this->loadHTMLFile($url))
$this->context = $this->getElementById($id) ;
}
if($this->context) {
$xpath = new DOMXPath($this) ;
$this->lnkhdr = $xpath->query('table/tr/td/ul/lih2', $this->context)->item(0) ;
if($this->lnkmsg = $xpath->query('p', && $this->lnkcontext)->length > item(0) {;
$this->hdr = if($xpath->query('h2table', $this->context)->item(0length) ;
$this->msglnk = $xpath->query('ptable/tr/td/ul/li', $context)this->item(0context) ;
else // if($isLangPage)not inside a table
$this->tdslnk = $xpath->query('tableul/tr/tdli', $this->context) ;
$this->cnt = $this->lnk->length ;
} else
$this->ok = TRUE ;
}$this->ok = FALSE ;
}
function toHTML() {
// not need if this script is inside RC site
if(stristr($_SERVER['HTTP_HOST'], RCHost) === FALSE) {
$head = $this->getElementsByTagName("head")->item(0) ;
$base = $this->createElement("base") ;
$base->setAttribute("href", ROSETTA) ;
$head->insertBefore($base, $head->firstChild) ;
}
return $this->saveHTML() ;
}
function prepare(&$taskList) {
 
function makeDict(&$taskList) {
$temp = array() ;
// collect lang's task list
for($i = 0 ; $i < $this->lnk->length ; $i++) {
$alink = $this->lnk->item($i)->getElementsByTagName("a")->item(0) ;
$href = temp[$alink->getAttribute("href")] = TRUE ;
$temp[$href] = TRUE ;
}
// set diff : total tasks - lang's tasks => not completed tasks
for($i = 0 ; $i < $taskList->length ; $i++) {
$alink = $taskList->item($i)->getElementsByTagName("a")->item(0) ;
$href = if(array_key_exists($alink->getAttribute("href"), ;$temp) === FALSE)
$this->dict[$this->notCnt++] = // import from Tasks into Lang
if(array_key_exists($href, $temp) == FALSE)
$this->dict[$this->notCnt++] = $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) ;
}
}
Line 97 ⟶ 168:
"total completed tasks, some implementations and puzzles may be " .
"not yet completed )." ;
// no more tasks below, add a height to the table to look like a void.
$lang->tds->item(0)->setAttribute("height", "100px") ;
} else {
$lang->msg->nodeValue =
Line 102 ⟶ 175:
"out of {$task->cnt} total tasks ( {$lang->cnt} " .
"completed tasks, implementations and puzzles etc.)." ;
 
$curr = 0 ;
$splitMax = intval(($lang->notCnt + 2) / 3)tds->length ;
$splitMax = intval(($lang->notCnt + $splitMax - 1) / $splitMax) ;
if($splitMax < 5) $splitMax = 5 ;
 
$capital = '?' ;
$heading = '' ;
$lang->lnk = null ; // release node ref. to be remove
for($i = 0 ; $i < $lang->tds->length ; $i++) {
$td = $lang->tds->item($i) ;
$td->setAttribute("width", intval(100/$lang->tds->length) . "%") ;
// clear old content
while ($td->childNodes->lengthsetAttribute("valign", "top") ;
$ul = NULL ;
$td->removeChild($td->childNodes->item(0));
$td->setAttribute("width", "33%") ;
$ul = NULL ;
$splitCnt = 0 ;
while($curr < $lang->notCnt && $splitCnt < $splitMax) {
$li = $lang->dict[$curr] ;
$heading = $capital ;
$title = $li->getElementsByTagName("a")->item(0)->getAttribute("title") ;
$capital = strtoupper(substr($title, 0, 1)) ;
if($splitCnt == 0) {
if($capital == $heading)
$h3 = $lang->createElement("h3", $capital . " cont.") ;
else
Line 135 ⟶ 203:
$td->appendChild($ul) ;
$h3 = $lang->createElement("h3", $capital) ;
$td->appendChild($h3) ;
$ul = $lang->createElement("ul") ;
}
Line 141 ⟶ 209:
$curr++ ;
$splitCnt++ ;
}
if($ul) $td->appendChild($ul) ;
}
}
}
 
function process_list(){ // replace languages link with corresponding scriptURL
global $list ;
Line 156 ⟶ 223:
}
}
function linkText(&$node, $pre, $href, $text, $post) {
 
$doc = $node->ownerDocument ;
function LangId(){
if($pre ) $node->appendChild($doc->createElement("span", $pre)) ;
$langId = NA ;
if(count($_GET) > 0href) {
if(!$text) $text = 'null' ;
if(array_key_exists(LANG, $_GET) && strlen($_GET[LANG]) > 0)
$langIdalink = $_GET[LANG]doc->createElement("a", $text) ;
$alink->setAttribute("href", $href) ;
else {
$alink->setAttribute("title", $text) ;
$keys = array_keys($_GET) ;
$node->appendChild($alink) ;
if(count($keys) > 0 && strlen($keys[0]) > 0)
$langId = $keys[0] ;
}
}
if($post) $node->appendChild($doc->createElement("span", $post)) ;
return $langId ;
}
 
Line 174 ⟶ 239:
* Main Body
*/
 
if(NoWarning) {
$error_flag = ini_get("error_reporting") ;
ini_set("error_reporting",$error_flag & ~(E_WARNING|E_NOTICE) ) ;
}
 
if($langID != NA) {
$lang = new Page($langURLlangID, 'mw-pages',TRUE) ;
if($lang->ok) {
$task = new Page(pageURL(TaskURL), 'mw-pages') ;
if($task->ok)
$lang->makeDictprepare($task->lnk) ;
}
}
 
if($langID != NA && $lang->ok && $task->ok) {
linkText($lang->hdr->nodeValue =, 'Not Completed Tasks by ', .$lang->url, $langIDIDLang, NULL) ;
linkText($lang->hdr, ' ( ', ScriptURL(NA), 'Other Languages', ' ) ') ;
 
process_task() ;
echo $lang->toHTML() ;
 
echo $lang->saveHTML() ;
} else {
$list = new Page(pageURL(ListURL), 'mw-subcategories') ;
if($list->ok) {
if($langID == NA)
$list->hdr->nodeValue = 'Not Completed Tasks by Other Languages' ;
else {
$list->hdr->nodeValue = 'Not Completed Tasks by Other Languages removeChild($list->hdr->lastChild) "';
linkText($list->hdr, 'Not Completed Tasks by Languages ( "',
. $langID . '" page not found )' ;
$lang->url, $IDLang, '" hasn\'t any task completed yet ) ') ;
 
}
process_list() ;
echo $list->toHTML() ;
 
echo $list->saveHTML() ;
}
else
echo '<html><body><br/><br/>
<h3 align=center>Unknown Error,
<html><body>
<a href="' . ROSETTA . '">Return Rosetta Code Main Page</a> or
<h3>Unknown Error,
<a href="' javascript:history.go(-1) ROSETTA . ';">ReturnGo Rosetta Code Main PageBack</a> or.
<a href="javascript:history.go(-1) ;">Go Back </ah3>.
</h3body></html>' ;
</body></html>' ;
}
 
if(NoWarning) ini_set("error_reporting",$error_flag) ;
?></php>
|}
Hope it can be a temporary solution. -- [[User:Badmadevil|badmadevil]] 0212:5233, 1422 June 2008 (MDTUTC)