Created
October 6, 2011 12:39
-
-
Save kopiro/1267304 to your computer and use it in GitHub Desktop.
Access to Wikipedia Obscured (4-Oct)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$q = $_GET["q"]; | |
if (!$q) $q = $_GET["search"]; | |
$q = str_replace(" ", "_", ucwords($q)); | |
if (!$q) { | |
header("location: index.php?q=Wikipedia"); | |
die(); | |
} | |
if (file_exists("./cache/$q.html")) { | |
echo file_get_contents("./cache/$q.html"); | |
die(); | |
} | |
class JSLikeHTMLElement extends DOMElement { | |
public function __set($name, $value) { | |
if ($name == 'innerHTML') { | |
for ($x=$this->childNodes->length-1; $x>=0; $x--) | |
$this->removeChild($this->childNodes->item($x)); | |
if ($value != '') { | |
$f = $this->ownerDocument->createDocumentFragment(); | |
$result = @$f->appendXML($value); | |
if ($result) if ($f->hasChildNodes()) $this->appendChild($f); | |
else { | |
$f = new DOMDocument(); | |
$value = mb_convert_encoding($value, 'HTML-ENTITIES', 'UTF-8'); | |
$result = @$f->loadHTML('<htmlfragment>'.$value.'</htmlfragment>'); | |
if ($result) { | |
$import = $f->getElementsByTagName('htmlfragment')->item(0); | |
foreach ($import->childNodes as $child) { | |
$importedNode = $this->ownerDocument->importNode($child, true); | |
$this->appendChild($importedNode); | |
} | |
} | |
} | |
} | |
} | |
} | |
public function __get($name) { | |
if ($name == 'innerHTML') { | |
$inner = ''; | |
foreach ($this->childNodes as $child) | |
$inner .= $this->ownerDocument->saveXML($child); | |
return $inner; | |
} | |
} | |
public function __toString() { | |
return '['.$this->tagName.']'; | |
} | |
} | |
ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9'); | |
$wiki = new DomDocument(); | |
$wiki->loadHTMLFile("http://it.wikipedia.org/"); | |
echo $wiki->saveHTML(); | |
$wiki->registerNodeClass('DOMElement', 'JSLikeHTMLElement'); | |
foreach ($wiki->getElementsByTagName("body")->item(0)->getElementsByTagName("script") as $i) { | |
if (preg_match("/modules=site/i", $i->getAttribute("src"))) { | |
$script = $wiki->createElement('script', 'window.location.replace=function(){};mediaWiki.config.set("wgUserGroups", ["sysop"]);'); | |
$i->parentNode->insertBefore($script, $i); | |
break; | |
} | |
} | |
$mwiki = new DomDocument(); | |
$mwiki->registerNodeClass('DOMElement', 'JSLikeHTMLElement'); | |
$mwiki->loadHTMLFile("http://it.m.wikipedia.org/wiki/$q"); | |
$wiki->getElementById("searchform")->setAttribute("action", "index.php"); | |
$wiki_content = $wiki->getElementById("content"); | |
$mwiki_content = $mwiki->getElementById("content"); | |
$mwiki->getElementById("firstHeading")->setAttribute("style", "display:block !important"); | |
$mwiki->getElementById("bodyContent")->setAttribute("style", "display:block !important"); | |
foreach ($mwiki->getElementsByTagName("button") as $i) | |
$i->parentNode->removeChild($i); | |
$wiki_content->innerHTML = $mwiki_content->innerHTML; | |
$wiki->saveHTMLFile("./cache/$q.html"); | |
echo file_get_contents("./cache/$q.html"); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment