Index: trunk/extensions/TSPoll/http.func.php |
— | — | @@ -0,0 +1,166 @@ |
| 2 | +<?PHP |
| 3 | + |
| 4 | +###Der folgende Code wurde von Marco Schuster bereit gestellt und ist unter der GPL ver�ffentlicht. Quelle: http://code.harddisk.is-a-geek.org/filedetails.php?repname=hd_bot&path=%2Fhttp.inc.php&sc=1&rev=66 |
| 5 | + |
| 6 | +// the HTTP wrapper class. replace this file with another for e.g. TOR/Proxy/CURL support |
| 7 | +// use like $http=new http_w("de.wikipedia.org","/w/index.php"); $http->get(""); |
| 8 | +// provides functions post, get |
| 9 | +// result is stored in data, header. for a full HTTP response do $full=$http->header."\r\n\r\n".$http->data; |
| 10 | + |
| 11 | +//let's fake some browser agent to bypass MediaWiki squid block (evil!) |
| 12 | +define("USERAGENT","Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1"); //Mozilla Firefox |
| 13 | +define("COOKIEJAR","private/cookiejar.txt"); |
| 14 | +define("USE_COOKIEJAR",false); |
| 15 | +class http_w { |
| 16 | + public $data; |
| 17 | + public $headers; |
| 18 | + |
| 19 | + var $server; |
| 20 | + var $file; |
| 21 | + var $raw; |
| 22 | + |
| 23 | + |
| 24 | + function __construct($server, $file) { |
| 25 | + global $cookies; |
| 26 | + //debug(__FUNCTION__,"new instance of http_w initialized",1); |
| 27 | + $this->data=""; |
| 28 | + $this->headers=""; |
| 29 | + $this->raw=""; |
| 30 | + $this->server=$server; |
| 31 | + $this->file=$file; |
| 32 | + if(USE_COOKIEJAR) { |
| 33 | + $fp=fopen(COOKIEJAR,"r"); |
| 34 | + while (!feof($fp)) { |
| 35 | + $buf.= fgets($fp,128); |
| 36 | + } |
| 37 | + fclose($fp); |
| 38 | + $cookies=$buf; |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + function get($param="", $ignore_redir=false) { |
| 43 | + //debug(__FUNCTION__,"get called. param='$param', ignore_redir='$ignore_redir', server='".$this->server."', file='".$this->file."'",1); |
| 44 | + |
| 45 | + if($param!="") { $p="?".$param; } else { $p=""; } |
| 46 | + |
| 47 | + $cookies=$this->cookiestring(); |
| 48 | + |
| 49 | + $fp = fsockopen ($this->server, 80, $errno, $errstr, 10); |
| 50 | + |
| 51 | + if ($fp) { |
| 52 | + $query="GET ".$this->file.$p." HTTP/1.1 |
| 53 | +Host: ".$this->server." |
| 54 | +Cookie: $cookies |
| 55 | +User-Agent: ".USERAGENT." |
| 56 | +\r\n\r\n"; |
| 57 | + //debug(__FUNCTION__,$query,3); |
| 58 | + fputs ($fp,$query); |
| 59 | + $buf = ""; |
| 60 | + while (!feof($fp)) { |
| 61 | + $buf.= fgets($fp,128); |
| 62 | + } |
| 63 | + fclose($fp); |
| 64 | + $this->raw=$buf; |
| 65 | + |
| 66 | + $this->headers=$this->getheaders(); |
| 67 | + $this->data=$this->removeheaders(); |
| 68 | + //debug(__FUNCTION__,$this->headers,3); |
| 69 | + //debug(__FUNCTION__,$this->data,3); |
| 70 | + |
| 71 | + $this->update_cookies(); |
| 72 | + preg_match('@Location: http://(.*)/(.*)\r\n@iU',$this->headers,$hit); |
| 73 | + if($hit[1]!="" && (!$ignore_redir)) { |
| 74 | + $this->server=$hit[1]; |
| 75 | + $this->file="/".$hit[2]; |
| 76 | + //debug(__FUNCTION__,"following http redirect to ".$this->server." // ".$this->file,1); |
| 77 | + $this->data=$this->get(""); |
| 78 | + } |
| 79 | + flush(); |
| 80 | + return $this->data; |
| 81 | + } else { |
| 82 | + echo "$errno: $errstr"; |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + function post($param="", $content="", $ignore_redir=false) { |
| 87 | + //debug(__FUNCTION__,"post called. param='$param', ignore_redir='$ignore_redir', server='".$this->server."', file='".$this->file."', post content='".$content["message"]."'",1); |
| 88 | + |
| 89 | + if($content=="") { die("thou shalt not use post without content!"); } |
| 90 | + |
| 91 | + if($param!="") { $p="?".$param; } else { $p=""; } |
| 92 | + |
| 93 | + $cookies=$this->cookiestring(); |
| 94 | + |
| 95 | + $fp = fsockopen ($this->server, 80, $errno, $errstr, 10); |
| 96 | + |
| 97 | + if ($fp) { |
| 98 | + $query="POST ".$this->file.$p." HTTP/1.1 |
| 99 | +Host: ".$this->server." |
| 100 | +Cookie: $cookies |
| 101 | +User-Agent: ".USERAGENT." |
| 102 | +Content-Type: ".$content["type"]." |
| 103 | +Content-Length: ".strlen($content["message"])." |
| 104 | + |
| 105 | +".$content["message"]." |
| 106 | +\r\n\r\n"; |
| 107 | + //debug(__FUNCTION__,$query,3); |
| 108 | + fputs ($fp,$query); |
| 109 | + while (!feof($fp)) { |
| 110 | + $buf.= fgets($fp,128); |
| 111 | + } |
| 112 | + fclose($fp); |
| 113 | + $this->raw=$buf; |
| 114 | + |
| 115 | + $this->headers=$this->getheaders(); |
| 116 | + $this->data=$this->removeheaders(); |
| 117 | + //debug(__FUNCTION__,$this->headers,3); |
| 118 | + //debug(__FUNCTION__,$this->data,3); |
| 119 | + $this->update_cookies(); |
| 120 | + preg_match('@Location: http://(.*)/(.*)\r\n@iU',$this->headers,$hit); |
| 121 | + if($hit[1]!="" && (!$ignore_redir)) { |
| 122 | + $this->server=$hit[1]; |
| 123 | + $this->file="/".$hit[2]; |
| 124 | + //debug(__FUNCTION__,"following http redirect to ".$this->server." // ".$this->file,1); |
| 125 | + $this->data=$this->post("",$content); |
| 126 | + } |
| 127 | + flush(); |
| 128 | + return $this->data; |
| 129 | + } else { |
| 130 | + echo "$errno: $errstr"; |
| 131 | + } |
| 132 | + } |
| 133 | + |
| 134 | + function removeheaders() { |
| 135 | + //debug(__FUNCTION__,__FUNCTION__." called",1); |
| 136 | + preg_match ("/\r\n\r\n(.*)$/is",$this->raw,$hit); |
| 137 | + return $hit[1]; |
| 138 | + } |
| 139 | + function getheaders() { |
| 140 | + //debug(__FUNCTION__,__FUNCTION__." called",1); |
| 141 | + preg_match ("/^(.*)\r\n\r\n/is",$this->raw,$hit); |
| 142 | + return $hit[1]; |
| 143 | + } |
| 144 | + |
| 145 | + function cookiestring() { |
| 146 | + global $cookies; |
| 147 | + //debug(__FUNCTION__,__FUNCTION__." called",1); |
| 148 | + return $cookies; |
| 149 | + } |
| 150 | + function update_cookies() { |
| 151 | + global $cookies; |
| 152 | + //debug(__FUNCTION__,__FUNCTION__." called",1); |
| 153 | + $hits=preg_match_all('@Set-Cookie: (.*)=(.*); (expires|path)(.*)@isU',$this->headers,$hit,PREG_SET_ORDER); |
| 154 | + //debug(__FUNCTION__,"cookie preg hits $hits",3); |
| 155 | + foreach($hit as $k=>$v) { |
| 156 | + $cookies.=$v[1]."=".$v[2].";"; |
| 157 | + } |
| 158 | + //debug(__FUNCTION__,"cookies updated to $cookies",3); |
| 159 | + if(USE_COOKIEJAR) { |
| 160 | + $fp=fopen(COOKIEJAR,"w"); |
| 161 | + fputs($fp,$cookies); |
| 162 | + fclose($fp); |
| 163 | + } |
| 164 | + } |
| 165 | +} |
| 166 | + |
| 167 | +?> |
\ No newline at end of file |
Property changes on: trunk/extensions/TSPoll/http.func.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 168 | + native |
Index: trunk/extensions/TSPoll/TSPoll.i18n.php |
— | — | @@ -0,0 +1,12 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * @ingroup Extensions |
| 5 | + */ |
| 6 | + |
| 7 | +$messages = array(); |
| 8 | +$messages['en'] = array( |
| 9 | + 'descript_msg' => 'Include the [http://www.toolserver.org/~jan/poll/index.php Toolserver-Poll-Skript] as a HTML-tag', |
| 10 | +); |
| 11 | +$messages['de'] = array( |
| 12 | + 'descript_msg' => 'Bindet das [http://www.toolserver.org/~jan/poll/index.php Toolserver-Poll-Skript] als ein HTML-Tag ein', |
| 13 | +); |
Property changes on: trunk/extensions/TSPoll/TSPoll.i18n.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 14 | + native |
Index: trunk/extensions/TSPoll/TSPoll.php |
— | — | @@ -0,0 +1,71 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Toolserver Poll - Include the Toolserver-Poll-Skript(http://toolserver.org/~jan/poll/index.php) |
| 5 | + * |
| 6 | + * To activate this extension, add the following into your LocalSettings.php file: |
| 7 | + * require_once("$IP/extensions/TSPoll/TSPoll.php"); |
| 8 | + * |
| 9 | + * @ingroup Extensions |
| 10 | + * @author Jan Luca <jan@toolserver.org> |
| 11 | + * @version 1.0 Dev |
| 12 | + * @link http://www.mediawiki.org/wiki/User:Jan_Luca/Extension:TSPoll Documentation |
| 13 | + * @license http://creativecommons.org/licenses/by-sa/3.0/ Attribution-Share Alike 3.0 Unported or later |
| 14 | + */ |
| 15 | + |
| 16 | +/** |
| 17 | + * Protect against register_globals vulnerabilities. |
| 18 | + * This line must be present before any global variable is referenced. |
| 19 | + */ |
| 20 | + |
| 21 | +//Abbrechen des Skriptes, wenn es nicht in Mediawiki eingebunden ist |
| 22 | +if( !defined( 'MEDIAWIKI' ) ) { |
| 23 | + echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" ); |
| 24 | + die( -1 ); |
| 25 | +} |
| 26 | + |
| 27 | +// Extension credits that will show up on Special:Version |
| 28 | +$wgExtensionCredits['parserhook'][] = array( |
| 29 | + 'name' => 'TSPoll', |
| 30 | + 'version' => '1.0 Dev', |
| 31 | + 'author' => 'Jan Luca', |
| 32 | + 'url' => 'http://www.mediawiki.org/wiki/User:Jan_Luca/Extension:TSPoll', |
| 33 | + 'descriptionmsg'=> 'descript_msg' |
| 34 | +); |
| 35 | + |
| 36 | +//Avoid unstubbing $wgParser on setHook() too early on modern (1.12+) MW versions, as per r35980 |
| 37 | +if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) { |
| 38 | + $wgHooks['ParserFirstCallInit'][] = 'efTSPollSetup'; |
| 39 | +} else { // Otherwise do things the old fashioned way |
| 40 | + $wgExtensionFunctions[] = 'efTSPollSetup'; |
| 41 | +} |
| 42 | + |
| 43 | +$wgExtensionMessagesFiles['TSPoll'] = dirname( __FILE__ ) . '/TSPoll.i18n.php'; |
| 44 | +include_once(dirname( __FILE__ ) . '/http.func.php'); |
| 45 | + |
| 46 | +function efTSPollSetup() { |
| 47 | + global $wgParser; |
| 48 | + $wgParser->setHook( 'TSPoll', 'efTSPollRender' ); |
| 49 | + $wgParser->setHook( 'tspoll', 'efTSPollRender' ); |
| 50 | + return true; |
| 51 | +} |
| 52 | + |
| 53 | +function efTSPollRender( $input, $args, $parser ) { |
| 54 | + foreach( $args as $name => $value ) { |
| 55 | + if ($name == "id") { |
| 56 | + $id = htmlspecialchars( $value ); |
| 57 | + break; |
| 58 | + } |
| 59 | + else { |
| 60 | + continue; |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + $http = new http_w("toolserver.org","/~jan/poll/main.php?page=wiki_output&id=".$id.""); |
| 65 | + $get_server = $http->get(""); |
| 66 | + if($get_server != "") { |
| 67 | + return $get_server; |
| 68 | + } |
| 69 | + else { |
| 70 | + return "Fehler beim Holen!"; |
| 71 | + } |
| 72 | +} |
Property changes on: trunk/extensions/TSPoll/TSPoll.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 73 | + native |
Index: trunk/extensions/TSPoll/README |