Anonymous user
User talk:Badmadevil: Difference between revisions
m
→Not Implemented Tasks by Language: add links for navigation, some minor changes
m (→Not Implemented Tasks by Language: bugs fix x 2) |
m (→Not Implemented Tasks by Language: add links for navigation, some minor changes) |
||
Line 13:
*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;
Line 23 ⟶ 24:
| 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' , 'rosettacode.org') ;
define('ROSETTA', 'http://' . RCHost) ;
define('Prefix', ROSETTA . '/wiki/Category:') ;
define('TaskURL', Prefix . 'Solutions_by_Programming_Task') ;
define('ListURL', Prefix . 'Solutions_by_Programming_Language') ;
define('PAGENAME', 'PAGENAME') ; // if use as a query string key-value pair
define('NA', 'NotAvaliable') ;
$langID = LangId() ;
// $langID has been encoded 2 time so that C++ not mistaken with C
$IDLang = myDecode(myDecode($langID)) ;
// this control how to access this scrtpt
$scriptURL = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['URL'] ;
function ScriptURL($langId
global $langID, $scriptURL ;
}
function
function myDecode($s) { return str_replace('_', ' ' , rawurldecode($s)) ; }
function LangId(){
$langId = NA ;
if(count($_GET) > 0) {
if(array_key_exists(PAGENAME, $_GET) && strlen($_GET[PAGENAME]) > 0)
$langId = $_GET[PAGENAME] ;
else {
$keys = array_keys($_GET) ;
if(count($keys) > 0 && strlen($keys[0]) > 0) $langId = $keys[0] ;
}
}
return myEncode($langId) ;
}
class Page extends DOMDocument {
public $lnk
public $dict = array() , $ok =
public $cnt = 0 , $notCnt = 0 ; // $notCnt = count of not implemented tasks
function __construct($url, $id
global $langID ;
if($
if(!@$this->loadHTMLFile($this->url = Prefix . $langID))
if(!@$this->
if($this->ok) $this->context
} else {
if(@$this->loadHTMLFile($url)
$this->context = $this->getElementById($
}
if($this->context) {
$xpath = new DOMXPath($this) ;
$this->hdr = $xpath->query('h2', $this->context)->item(0) ;
$this->msg = $xpath->query('p', $this->context)->item(0) ;
else // not inside a table
$this->lnk = $xpath->query('ul/li', $this->context) ;
$this->cnt =
} else
}
function toHTML() {
// not need if this script is inside RC site
Line 111 ⟶ 97:
return $this->saveHTML() ;
}
function prepare(&$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) ;
$
}
// 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) ;
$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
$this->context
// create new hdr, msg
$this->hdr = $this->context->appendChild($this->createElement("h2")) ;
$this->
// make table
$table = $this->createElement("table") ;
Line 150 ⟶ 128:
$xpath = new DOMXPath($this) ;
$this->tds = $xpath->query('table/tr/td', $this->context) ;
}
}
Line 178 ⟶ 148:
$curr = 0 ;
$splitMax =
$splitMax = intval(($lang->notCnt + $splitMax - 1) / $splitMax) ;
if($splitMax < 5) $splitMax = 5 ;
$capital = '' ;
for($i = 0 ; $i < $lang->tds->length ; $i++) {
$td = $lang->tds->item($i) ;
$td->setAttribute("width", "33%") ;
$td->setAttribute("valign", "top") ;
Line 217 ⟶ 185:
}
}
function process_list(){ // replace languages link with corresponding scriptURL
global $list ;
Line 227 ⟶ 194:
}
}
function linkText(&$node, $pre, $href, $text, $post) {
$doc = $node->ownerDocument ;
if($pre ) $node->appendChild($doc->createElement("span", $pre)) ;
if
if(!$text) $text = 'null' ;
$alink->setAttribute("href", $href) ;
$alink->setAttribute("title", $text) ;
$node->appendChild($alink) ;
}
if($post) $node->appendChild($doc->createElement("span", $post)) ;
}
Line 247 ⟶ 212:
if($langID != NA) {
$lang = new Page($langID, 'mw-pages'
if($lang->ok) {
$task = new Page(TaskURL, 'mw-pages') ;
if($task->ok)
$lang->
}
}
if($langID != NA && $lang->ok && $task->ok) {
linkText($lang->hdr
linkText($lang->hdr, ' ( ', $scriptURL, 'Other Languages', ' ) ') ;
process_task() ;
echo $lang->toHTML() ;
} else {
Line 266 ⟶ 231:
if($langID == NA)
$list->hdr->nodeValue = 'Not Completed Tasks by Languages' ;
else {
$list->hdr->
$lang->url, $IDLang, '" hasn\'t any task completed yet ) ') ;
}
process_list() ;
echo $list->toHTML() ;
}
else
echo '<html><body><br/><br/>
<h3 align=center>Unknown Error,
<a href="' . ROSETTA . '">Return Rosetta Code Main Page</a> or
<a href="
</
}
?></php>
|