MediaWiki  1.23.3
HttpFunctions.php
Go to the documentation of this file.
1 <?php
32 class Http {
33  static public $httpEngine = false;
34 
60  public static function request( $method, $url, $options = array() ) {
61  wfDebug( "HTTP: $method: $url\n" );
62  wfProfileIn( __METHOD__ . "-$method" );
63 
64  $options['method'] = strtoupper( $method );
65 
66  if ( !isset( $options['timeout'] ) ) {
67  $options['timeout'] = 'default';
68  }
69  if ( !isset( $options['connectTimeout'] ) ) {
70  $options['connectTimeout'] = 'default';
71  }
72 
73  $req = MWHttpRequest::factory( $url, $options );
74  $status = $req->execute();
75 
76  $content = false;
77  if ( $status->isOK() ) {
78  $content = $req->getContent();
79  }
80  wfProfileOut( __METHOD__ . "-$method" );
81  return $content;
82  }
83 
93  public static function get( $url, $timeout = 'default', $options = array() ) {
94  $options['timeout'] = $timeout;
95  return Http::request( 'GET', $url, $options );
96  }
97 
106  public static function post( $url, $options = array() ) {
107  return Http::request( 'POST', $url, $options );
108  }
109 
116  public static function isLocalURL( $url ) {
117  global $wgCommandLineMode, $wgConf;
118 
119  if ( $wgCommandLineMode ) {
120  return false;
121  }
122 
123  // Extract host part
124  $matches = array();
125  if ( preg_match( '!^http://([\w.-]+)[/:].*$!', $url, $matches ) ) {
126  $host = $matches[1];
127  // Split up dotwise
128  $domainParts = explode( '.', $host );
129  // Check if this domain or any superdomain is listed in $wgConf as a local virtual host
130  $domainParts = array_reverse( $domainParts );
131 
132  $domain = '';
133  $countParts = count( $domainParts );
134  for ( $i = 0; $i < $countParts; $i++ ) {
135  $domainPart = $domainParts[$i];
136  if ( $i == 0 ) {
137  $domain = $domainPart;
138  } else {
139  $domain = $domainPart . '.' . $domain;
140  }
141 
142  if ( $wgConf->isLocalVHost( $domain ) ) {
143  return true;
144  }
145  }
146  }
147 
148  return false;
149  }
150 
155  public static function userAgent() {
156  global $wgVersion;
157  return "MediaWiki/$wgVersion";
158  }
159 
172  public static function isValidURI( $uri ) {
173  return preg_match(
174  '/^https?:\/\/[^\/\s]\S*$/D',
175  $uri
176  );
177  }
178 }
179 
188  const SUPPORTS_FILE_POSTS = false;
189 
190  protected $content;
191  protected $timeout = 'default';
192  protected $headersOnly = null;
193  protected $postData = null;
194  protected $proxy = null;
195  protected $noProxy = false;
196  protected $sslVerifyHost = true;
197  protected $sslVerifyCert = true;
198  protected $caInfo = null;
199  protected $method = "GET";
200  protected $reqHeaders = array();
201  protected $url;
202  protected $parsedUrl;
203  protected $callback;
204  protected $maxRedirects = 5;
205  protected $followRedirects = false;
206 
210  protected $cookieJar;
211 
212  protected $headerList = array();
213  protected $respVersion = "0.9";
214  protected $respStatus = "200 Ok";
215  protected $respHeaders = array();
216 
217  public $status;
218 
223  protected function __construct( $url, $options = array() ) {
224  global $wgHTTPTimeout, $wgHTTPConnectTimeout;
225 
226  $this->url = wfExpandUrl( $url, PROTO_HTTP );
227  $this->parsedUrl = wfParseUrl( $this->url );
228 
229  if ( !$this->parsedUrl || !Http::isValidURI( $this->url ) ) {
230  $this->status = Status::newFatal( 'http-invalid-url' );
231  } else {
232  $this->status = Status::newGood( 100 ); // continue
233  }
234 
235  if ( isset( $options['timeout'] ) && $options['timeout'] != 'default' ) {
236  $this->timeout = $options['timeout'];
237  } else {
238  $this->timeout = $wgHTTPTimeout;
239  }
240  if ( isset( $options['connectTimeout'] ) && $options['connectTimeout'] != 'default' ) {
241  $this->connectTimeout = $options['connectTimeout'];
242  } else {
243  $this->connectTimeout = $wgHTTPConnectTimeout;
244  }
245  if ( isset( $options['userAgent'] ) ) {
246  $this->setUserAgent( $options['userAgent'] );
247  }
248 
249  $members = array( "postData", "proxy", "noProxy", "sslVerifyHost", "caInfo",
250  "method", "followRedirects", "maxRedirects", "sslVerifyCert", "callback" );
251 
252  foreach ( $members as $o ) {
253  if ( isset( $options[$o] ) ) {
254  // ensure that MWHttpRequest::method is always
255  // uppercased. Bug 36137
256  if ( $o == 'method' ) {
257  $options[$o] = strtoupper( $options[$o] );
258  }
259  $this->$o = $options[$o];
260  }
261  }
262 
263  if ( $this->noProxy ) {
264  $this->proxy = ''; // noProxy takes precedence
265  }
266  }
267 
273  public static function canMakeRequests() {
274  return function_exists( 'curl_init' ) || wfIniGetBool( 'allow_url_fopen' );
275  }
276 
285  public static function factory( $url, $options = null ) {
286  if ( !Http::$httpEngine ) {
287  Http::$httpEngine = function_exists( 'curl_init' ) ? 'curl' : 'php';
288  } elseif ( Http::$httpEngine == 'curl' && !function_exists( 'curl_init' ) ) {
289  throw new MWException( __METHOD__ . ': curl (http://php.net/curl) is not installed, but' .
290  ' Http::$httpEngine is set to "curl"' );
291  }
292 
293  switch ( Http::$httpEngine ) {
294  case 'curl':
295  return new CurlHttpRequest( $url, $options );
296  case 'php':
297  if ( !wfIniGetBool( 'allow_url_fopen' ) ) {
298  throw new MWException( __METHOD__ . ': allow_url_fopen ' .
299  'needs to be enabled for pure PHP http requests to ' .
300  'work. If possible, curl should be used instead. See ' .
301  'http://php.net/curl.'
302  );
303  }
304  return new PhpHttpRequest( $url, $options );
305  default:
306  throw new MWException( __METHOD__ . ': The setting of Http::$httpEngine is not valid.' );
307  }
308  }
309 
315  public function getContent() {
316  return $this->content;
317  }
318 
325  public function setData( $args ) {
326  $this->postData = $args;
327  }
328 
334  public function proxySetup() {
335  global $wgHTTPProxy;
336 
337  // If there is an explicit proxy set and proxies are not disabled, then use it
338  if ( $this->proxy && !$this->noProxy ) {
339  return;
340  }
341 
342  // Otherwise, fallback to $wgHTTPProxy/http_proxy (when set) if this is not a machine
343  // local URL and proxies are not disabled
344  if ( Http::isLocalURL( $this->url ) || $this->noProxy ) {
345  $this->proxy = '';
346  } elseif ( $wgHTTPProxy ) {
347  $this->proxy = $wgHTTPProxy;
348  } elseif ( getenv( "http_proxy" ) ) {
349  $this->proxy = getenv( "http_proxy" );
350  }
351  }
352 
357  public function setUserAgent( $UA ) {
358  $this->setHeader( 'User-Agent', $UA );
359  }
360 
366  public function setHeader( $name, $value ) {
367  // I feel like I should normalize the case here...
368  $this->reqHeaders[$name] = $value;
369  }
370 
375  public function getHeaderList() {
376  $list = array();
377 
378  if ( $this->cookieJar ) {
379  $this->reqHeaders['Cookie'] =
380  $this->cookieJar->serializeToHttpRequest(
381  $this->parsedUrl['path'],
382  $this->parsedUrl['host']
383  );
384  }
385 
386  foreach ( $this->reqHeaders as $name => $value ) {
387  $list[] = "$name: $value";
388  }
389 
390  return $list;
391  }
392 
411  public function setCallback( $callback ) {
412  if ( !is_callable( $callback ) ) {
413  throw new MWException( 'Invalid MwHttpRequest callback' );
414  }
415  $this->callback = $callback;
416  }
417 
426  public function read( $fh, $content ) {
427  $this->content .= $content;
428  return strlen( $content );
429  }
430 
436  public function execute() {
437  wfProfileIn( __METHOD__ );
438 
439  $this->content = "";
440 
441  if ( strtoupper( $this->method ) == "HEAD" ) {
442  $this->headersOnly = true;
443  }
444 
445  $this->proxySetup(); // set up any proxy as needed
446 
447  if ( !$this->callback ) {
448  $this->setCallback( array( $this, 'read' ) );
449  }
450 
451  if ( !isset( $this->reqHeaders['User-Agent'] ) ) {
452  $this->setUserAgent( Http::userAgent() );
453  }
454 
455  wfProfileOut( __METHOD__ );
456  }
457 
463  protected function parseHeader() {
464  wfProfileIn( __METHOD__ );
465 
466  $lastname = "";
467 
468  foreach ( $this->headerList as $header ) {
469  if ( preg_match( "#^HTTP/([0-9.]+) (.*)#", $header, $match ) ) {
470  $this->respVersion = $match[1];
471  $this->respStatus = $match[2];
472  } elseif ( preg_match( "#^[ \t]#", $header ) ) {
473  $last = count( $this->respHeaders[$lastname] ) - 1;
474  $this->respHeaders[$lastname][$last] .= "\r\n$header";
475  } elseif ( preg_match( "#^([^:]*):[\t ]*(.*)#", $header, $match ) ) {
476  $this->respHeaders[strtolower( $match[1] )][] = $match[2];
477  $lastname = strtolower( $match[1] );
478  }
479  }
480 
481  $this->parseCookies();
482 
483  wfProfileOut( __METHOD__ );
484  }
485 
494  protected function setStatus() {
495  if ( !$this->respHeaders ) {
496  $this->parseHeader();
497  }
498 
499  if ( (int)$this->respStatus > 399 ) {
500  list( $code, $message ) = explode( " ", $this->respStatus, 2 );
501  $this->status->fatal( "http-bad-status", $code, $message );
502  }
503  }
504 
512  public function getStatus() {
513  if ( !$this->respHeaders ) {
514  $this->parseHeader();
515  }
516 
517  return (int)$this->respStatus;
518  }
519 
525  public function isRedirect() {
526  if ( !$this->respHeaders ) {
527  $this->parseHeader();
528  }
529 
530  $status = (int)$this->respStatus;
531 
532  if ( $status >= 300 && $status <= 303 ) {
533  return true;
534  }
535 
536  return false;
537  }
538 
547  public function getResponseHeaders() {
548  if ( !$this->respHeaders ) {
549  $this->parseHeader();
550  }
551 
552  return $this->respHeaders;
553  }
554 
561  public function getResponseHeader( $header ) {
562  if ( !$this->respHeaders ) {
563  $this->parseHeader();
564  }
565 
566  if ( isset( $this->respHeaders[strtolower( $header )] ) ) {
567  $v = $this->respHeaders[strtolower( $header )];
568  return $v[count( $v ) - 1];
569  }
570 
571  return null;
572  }
573 
579  public function setCookieJar( $jar ) {
580  $this->cookieJar = $jar;
581  }
582 
588  public function getCookieJar() {
589  if ( !$this->respHeaders ) {
590  $this->parseHeader();
591  }
592 
593  return $this->cookieJar;
594  }
595 
605  public function setCookie( $name, $value = null, $attr = null ) {
606  if ( !$this->cookieJar ) {
607  $this->cookieJar = new CookieJar;
608  }
609 
610  $this->cookieJar->setCookie( $name, $value, $attr );
611  }
612 
616  protected function parseCookies() {
617  wfProfileIn( __METHOD__ );
618 
619  if ( !$this->cookieJar ) {
620  $this->cookieJar = new CookieJar;
621  }
622 
623  if ( isset( $this->respHeaders['set-cookie'] ) ) {
624  $url = parse_url( $this->getFinalUrl() );
625  foreach ( $this->respHeaders['set-cookie'] as $cookie ) {
626  $this->cookieJar->parseCookieResponseHeader( $cookie, $url['host'] );
627  }
628  }
629 
630  wfProfileOut( __METHOD__ );
631  }
632 
649  public function getFinalUrl() {
650  $headers = $this->getResponseHeaders();
651 
652  //return full url (fix for incorrect but handled relative location)
653  if ( isset( $headers['location'] ) ) {
654  $locations = $headers['location'];
655  $domain = '';
656  $foundRelativeURI = false;
657  $countLocations = count( $locations );
658 
659  for ( $i = $countLocations - 1; $i >= 0; $i-- ) {
660  $url = parse_url( $locations[$i] );
661 
662  if ( isset( $url['host'] ) ) {
663  $domain = $url['scheme'] . '://' . $url['host'];
664  break; //found correct URI (with host)
665  } else {
666  $foundRelativeURI = true;
667  }
668  }
669 
670  if ( $foundRelativeURI ) {
671  if ( $domain ) {
672  return $domain . $locations[$countLocations - 1];
673  } else {
674  $url = parse_url( $this->url );
675  if ( isset( $url['host'] ) ) {
676  return $url['scheme'] . '://' . $url['host'] .
677  $locations[$countLocations - 1];
678  }
679  }
680  } else {
681  return $locations[$countLocations - 1];
682  }
683  }
684 
685  return $this->url;
686  }
687 
693  public function canFollowRedirects() {
694  return true;
695  }
696 }
697 
702  const SUPPORTS_FILE_POSTS = true;
703 
704  protected $curlOptions = array();
705  protected $headerText = "";
706 
712  protected function readHeader( $fh, $content ) {
713  $this->headerText .= $content;
714  return strlen( $content );
715  }
716 
717  public function execute() {
718  wfProfileIn( __METHOD__ );
719 
720  parent::execute();
721 
722  if ( !$this->status->isOK() ) {
723  wfProfileOut( __METHOD__ );
724  return $this->status;
725  }
726 
727  $this->curlOptions[CURLOPT_PROXY] = $this->proxy;
728  $this->curlOptions[CURLOPT_TIMEOUT] = $this->timeout;
729 
730  // Only supported in curl >= 7.16.2
731  if ( defined( 'CURLOPT_CONNECTTIMEOUT_MS' ) ) {
732  $this->curlOptions[CURLOPT_CONNECTTIMEOUT_MS] = $this->connectTimeout * 1000;
733  }
734 
735  $this->curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0;
736  $this->curlOptions[CURLOPT_WRITEFUNCTION] = $this->callback;
737  $this->curlOptions[CURLOPT_HEADERFUNCTION] = array( $this, "readHeader" );
738  $this->curlOptions[CURLOPT_MAXREDIRS] = $this->maxRedirects;
739  $this->curlOptions[CURLOPT_ENCODING] = ""; # Enable compression
740 
741  $this->curlOptions[CURLOPT_USERAGENT] = $this->reqHeaders['User-Agent'];
742 
743  $this->curlOptions[CURLOPT_SSL_VERIFYHOST] = $this->sslVerifyHost ? 2 : 0;
744  $this->curlOptions[CURLOPT_SSL_VERIFYPEER] = $this->sslVerifyCert;
745 
746  if ( $this->caInfo ) {
747  $this->curlOptions[CURLOPT_CAINFO] = $this->caInfo;
748  }
749 
750  if ( $this->headersOnly ) {
751  $this->curlOptions[CURLOPT_NOBODY] = true;
752  $this->curlOptions[CURLOPT_HEADER] = true;
753  } elseif ( $this->method == 'POST' ) {
754  $this->curlOptions[CURLOPT_POST] = true;
755  $this->curlOptions[CURLOPT_POSTFIELDS] = $this->postData;
756  // Suppress 'Expect: 100-continue' header, as some servers
757  // will reject it with a 417 and Curl won't auto retry
758  // with HTTP 1.0 fallback
759  $this->reqHeaders['Expect'] = '';
760  } else {
761  $this->curlOptions[CURLOPT_CUSTOMREQUEST] = $this->method;
762  }
763 
764  $this->curlOptions[CURLOPT_HTTPHEADER] = $this->getHeaderList();
765 
766  $curlHandle = curl_init( $this->url );
767 
768  if ( !curl_setopt_array( $curlHandle, $this->curlOptions ) ) {
769  wfProfileOut( __METHOD__ );
770  throw new MWException( "Error setting curl options." );
771  }
772 
773  if ( $this->followRedirects && $this->canFollowRedirects() ) {
775  if ( ! curl_setopt( $curlHandle, CURLOPT_FOLLOWLOCATION, true ) ) {
776  wfDebug( __METHOD__ . ": Couldn't set CURLOPT_FOLLOWLOCATION. " .
777  "Probably safe_mode or open_basedir is set.\n" );
778  // Continue the processing. If it were in curl_setopt_array,
779  // processing would have halted on its entry
780  }
782  }
783 
784  $curlRes = curl_exec( $curlHandle );
785  if ( curl_errno( $curlHandle ) == CURLE_OPERATION_TIMEOUTED ) {
786  $this->status->fatal( 'http-timed-out', $this->url );
787  } elseif ( $curlRes === false ) {
788  $this->status->fatal( 'http-curl-error', curl_error( $curlHandle ) );
789  } else {
790  $this->headerList = explode( "\r\n", $this->headerText );
791  }
792 
793  curl_close( $curlHandle );
794 
795  $this->parseHeader();
796  $this->setStatus();
797 
798  wfProfileOut( __METHOD__ );
799 
800  return $this->status;
801  }
802 
806  public function canFollowRedirects() {
807  if ( strval( ini_get( 'open_basedir' ) ) !== '' || wfIniGetBool( 'safe_mode' ) ) {
808  wfDebug( "Cannot follow redirects in safe mode\n" );
809  return false;
810  }
811 
812  if ( !defined( 'CURLOPT_REDIR_PROTOCOLS' ) ) {
813  wfDebug( "Cannot follow redirects with libcurl < 7.19.4 due to CVE-2009-0037\n" );
814  return false;
815  }
816 
817  return true;
818  }
819 }
820 
821 class PhpHttpRequest extends MWHttpRequest {
822 
827  protected function urlToTcp( $url ) {
828  $parsedUrl = parse_url( $url );
829 
830  return 'tcp://' . $parsedUrl['host'] . ':' . $parsedUrl['port'];
831  }
832 
833  public function execute() {
834  wfProfileIn( __METHOD__ );
835 
836  parent::execute();
837 
838  if ( is_array( $this->postData ) ) {
839  $this->postData = wfArrayToCgi( $this->postData );
840  }
841 
842  if ( $this->parsedUrl['scheme'] != 'http'
843  && $this->parsedUrl['scheme'] != 'https' ) {
844  $this->status->fatal( 'http-invalid-scheme', $this->parsedUrl['scheme'] );
845  }
846 
847  $this->reqHeaders['Accept'] = "*/*";
848  $this->reqHeaders['Connection'] = 'Close';
849  if ( $this->method == 'POST' ) {
850  // Required for HTTP 1.0 POSTs
851  $this->reqHeaders['Content-Length'] = strlen( $this->postData );
852  if ( !isset( $this->reqHeaders['Content-Type'] ) ) {
853  $this->reqHeaders['Content-Type'] = "application/x-www-form-urlencoded";
854  }
855  }
856 
857  // Set up PHP stream context
858  $options = array(
859  'http' => array(
860  'method' => $this->method,
861  'header' => implode( "\r\n", $this->getHeaderList() ),
862  'protocol_version' => '1.1',
863  'max_redirects' => $this->followRedirects ? $this->maxRedirects : 0,
864  'ignore_errors' => true,
865  'timeout' => $this->timeout,
866  // Curl options in case curlwrappers are installed
867  'curl_verify_ssl_host' => $this->sslVerifyHost ? 2 : 0,
868  'curl_verify_ssl_peer' => $this->sslVerifyCert,
869  ),
870  'ssl' => array(
871  'verify_peer' => $this->sslVerifyCert,
872  'SNI_enabled' => true,
873  ),
874  );
875 
876  if ( $this->proxy ) {
877  $options['http']['proxy'] = $this->urlToTCP( $this->proxy );
878  $options['http']['request_fulluri'] = true;
879  }
880 
881  if ( $this->postData ) {
882  $options['http']['content'] = $this->postData;
883  }
884 
885  if ( $this->sslVerifyHost ) {
886  $options['ssl']['CN_match'] = $this->parsedUrl['host'];
887  }
888 
889  if ( is_dir( $this->caInfo ) ) {
890  $options['ssl']['capath'] = $this->caInfo;
891  } elseif ( is_file( $this->caInfo ) ) {
892  $options['ssl']['cafile'] = $this->caInfo;
893  } elseif ( $this->caInfo ) {
894  throw new MWException( "Invalid CA info passed: {$this->caInfo}" );
895  }
896 
897  $context = stream_context_create( $options );
898 
899  $this->headerList = array();
900  $reqCount = 0;
901  $url = $this->url;
902 
903  $result = array();
904 
905  do {
906  $reqCount++;
908  $fh = fopen( $url, "r", false, $context );
910 
911  if ( !$fh ) {
912  break;
913  }
914 
915  $result = stream_get_meta_data( $fh );
916  $this->headerList = $result['wrapper_data'];
917  $this->parseHeader();
918 
919  if ( !$this->followRedirects ) {
920  break;
921  }
922 
923  # Handle manual redirection
924  if ( !$this->isRedirect() || $reqCount > $this->maxRedirects ) {
925  break;
926  }
927  # Check security of URL
928  $url = $this->getResponseHeader( "Location" );
929 
930  if ( !Http::isValidURI( $url ) ) {
931  wfDebug( __METHOD__ . ": insecure redirection\n" );
932  break;
933  }
934  } while ( true );
935 
936  $this->setStatus();
937 
938  if ( $fh === false ) {
939  $this->status->fatal( 'http-request-error' );
940  wfProfileOut( __METHOD__ );
941  return $this->status;
942  }
943 
944  if ( $result['timed_out'] ) {
945  $this->status->fatal( 'http-timed-out', $this->url );
946  wfProfileOut( __METHOD__ );
947  return $this->status;
948  }
949 
950  // If everything went OK, or we received some error code
951  // get the response body content.
952  if ( $this->status->isOK() || (int)$this->respStatus >= 300 ) {
953  while ( !feof( $fh ) ) {
954  $buf = fread( $fh, 8192 );
955 
956  if ( $buf === false ) {
957  $this->status->fatal( 'http-read-error' );
958  break;
959  }
960 
961  if ( strlen( $buf ) ) {
962  call_user_func( $this->callback, $fh, $buf );
963  }
964  }
965  }
966  fclose( $fh );
967 
968  wfProfileOut( __METHOD__ );
969 
970  return $this->status;
971  }
972 }
MWHttpRequest\$headerList
$headerList
Definition: HttpFunctions.php:211
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. $reader:XMLReader object $logInfo:Array of information Return false to stop further processing of the tag 'ImportHandlePageXMLTag':When parsing a XML tag in a page. $reader:XMLReader object $pageInfo:Array of information Return false to stop further processing of the tag 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information Return false to stop further processing of the tag 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. $reader:XMLReader object Return false to stop further processing of the tag 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. $reader:XMLReader object $revisionInfo:Array of information Return false to stop further processing of the tag 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. $title:Title object for the current page $request:WebRequest $ignoreRedirect:boolean to skip redirect check $target:Title/string of redirect target $article:Article object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) $article:article(object) being checked 'IsTrustedProxy':Override the result of wfIsTrustedProxy() $ip:IP being check $result:Change this value to override the result of wfIsTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of User::isValidEmailAddr(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetMagic':DEPRECATED, use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetSpecialPageAliases':DEPRECATED, use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Associative array mapping language codes to prefixed links of the form "language:title". & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LinkBegin':Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1528
MWHttpRequest\$headersOnly
$headersOnly
Definition: HttpFunctions.php:192
Http\$httpEngine
static $httpEngine
Definition: HttpFunctions.php:33
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
content
per default it will return the text for text based content
Definition: contenthandler.txt:107
MWHttpRequest\setStatus
setStatus()
Sets HTTPRequest status member to a fatal value with the error message if the returned integer value ...
Definition: HttpFunctions.php:493
MWHttpRequest\$respVersion
$respVersion
Definition: HttpFunctions.php:212
MWHttpRequest\proxySetup
proxySetup()
Take care of setting up the proxy (do nothing if "noProxy" is set)
Definition: HttpFunctions.php:333
$last
$last
Definition: profileinfo.php:365
MWHttpRequest\$maxRedirects
$maxRedirects
Definition: HttpFunctions.php:204
MWHttpRequest\$sslVerifyCert
$sslVerifyCert
Definition: HttpFunctions.php:197
Http\userAgent
static userAgent()
A standard user-agent we can use for external requests.
Definition: HttpFunctions.php:155
MWHttpRequest\$followRedirects
$followRedirects
Definition: HttpFunctions.php:205
wfProfileIn
wfProfileIn( $functionname)
Begin profiling of a function.
Definition: Profiler.php:33
wfSuppressWarnings
wfSuppressWarnings( $end=false)
Reference-counted warning suppression.
Definition: GlobalFunctions.php:2387
Status\newGood
static newGood( $value=null)
Factory function for good results.
Definition: Status.php:77
Http\isLocalURL
static isLocalURL( $url)
Check if the URL can be served by localhost.
Definition: HttpFunctions.php:116
MWHttpRequest\setData
setData( $args)
Set the parameters of the request.
Definition: HttpFunctions.php:324
MWHttpRequest\$content
$content
Definition: HttpFunctions.php:190
CurlHttpRequest\$headerText
$headerText
Definition: HttpFunctions.php:704
CurlHttpRequest
MWHttpRequest implemented using internal curl compiled into PHP.
Definition: HttpFunctions.php:700
MWHttpRequest\$timeout
$timeout
Definition: HttpFunctions.php:191
MWHttpRequest\$status
$status
Definition: HttpFunctions.php:216
PhpHttpRequest\urlToTcp
urlToTcp( $url)
Definition: HttpFunctions.php:826
MWHttpRequest\getStatus
getStatus()
Get the integer value of the HTTP status code (e.g.
Definition: HttpFunctions.php:511
MWHttpRequest\$noProxy
$noProxy
Definition: HttpFunctions.php:195
MWHttpRequest\__construct
__construct( $url, $options=array())
Definition: HttpFunctions.php:222
MWHttpRequest\parseHeader
parseHeader()
Parses the headers, including the HTTP status code and any Set-Cookie headers.
Definition: HttpFunctions.php:462
wfParseUrl
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
Definition: GlobalFunctions.php:755
MWHttpRequest\$postData
$postData
Definition: HttpFunctions.php:193
Http\request
static request( $method, $url, $options=array())
Perform an HTTP request.
Definition: HttpFunctions.php:60
MWHttpRequest\getContent
getContent()
Get the body, or content, of the response to the request.
Definition: HttpFunctions.php:314
MWException
MediaWiki exception.
Definition: MWException.php:26
MWHttpRequest\SUPPORTS_FILE_POSTS
const SUPPORTS_FILE_POSTS
Definition: HttpFunctions.php:188
wfRestoreWarnings
wfRestoreWarnings()
Restore error level to previous value.
Definition: GlobalFunctions.php:2417
MWHttpRequest\parseCookies
parseCookies()
Parse the cookies in the response headers and store them in the cookie jar.
Definition: HttpFunctions.php:615
MWHttpRequest\$respStatus
$respStatus
Definition: HttpFunctions.php:213
CookieJar\setCookie
setCookie( $name, $value, $attr)
Set a cookie in the cookie jar.
Definition: Cookie.php:214
$wgCommandLineMode
global $wgCommandLineMode
Definition: Setup.php:401
MWHttpRequest\isRedirect
isRedirect()
Returns true if the last status code was a redirect.
Definition: HttpFunctions.php:524
wfProfileOut
wfProfileOut( $functionname='missing')
Stop profiling of a function.
Definition: Profiler.php:46
MWHttpRequest\getCookieJar
getCookieJar()
Returns the cookie jar in use.
Definition: HttpFunctions.php:587
MWHttpRequest\$reqHeaders
$reqHeaders
Definition: HttpFunctions.php:200
MWHttpRequest\setCookieJar
setCookieJar( $jar)
Tells the MWHttpRequest object to use this pre-loaded CookieJar.
Definition: HttpFunctions.php:578
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
MWHttpRequest\$respHeaders
$respHeaders
Definition: HttpFunctions.php:214
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
MWHttpRequest\$cookieJar
CookieJar $cookieJar
Definition: HttpFunctions.php:209
PhpHttpRequest\execute
execute()
Take care of whatever is necessary to perform the URI request.
Definition: HttpFunctions.php:832
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
$options
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1530
MWHttpRequest\read
read( $fh, $content)
A generic callback to read the body of the response from a remote server.
Definition: HttpFunctions.php:425
execute
$batch execute()
wfDebug
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:933
CurlHttpRequest\execute
execute()
Take care of whatever is necessary to perform the URI request.
Definition: HttpFunctions.php:716
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
$matches
if(!defined( 'MEDIAWIKI')) if(!isset( $wgVersion)) $matches
Definition: NoLocalSettings.php:33
$value
$value
Definition: styleTest.css.php:45
MWHttpRequest\$method
$method
Definition: HttpFunctions.php:199
MWHttpRequest
This wrapper class will call out to curl (if available) or fallback to regular PHP if necessary for h...
Definition: HttpFunctions.php:187
MWHttpRequest\setCallback
setCallback( $callback)
Set a read callback to accept data read from the HTTP request.
Definition: HttpFunctions.php:410
MWHttpRequest\setHeader
setHeader( $name, $value)
Set an arbitrary header.
Definition: HttpFunctions.php:365
PROTO_HTTP
const PROTO_HTTP
Definition: Defines.php:267
MWHttpRequest\getHeaderList
getHeaderList()
Get an array of the headers.
Definition: HttpFunctions.php:374
MWHttpRequest\$parsedUrl
$parsedUrl
Definition: HttpFunctions.php:202
MWHttpRequest\setCookie
setCookie( $name, $value=null, $attr=null)
Sets a cookie.
Definition: HttpFunctions.php:604
MWHttpRequest\getResponseHeaders
getResponseHeaders()
Returns an associative array of response headers after the request has been executed.
Definition: HttpFunctions.php:546
wfIniGetBool
wfIniGetBool( $setting)
Safety wrapper around ini_get() for boolean settings.
Definition: GlobalFunctions.php:2685
MWHttpRequest\$sslVerifyHost
$sslVerifyHost
Definition: HttpFunctions.php:196
$args
if( $line===false) $args
Definition: cdb.php:62
CurlHttpRequest\$curlOptions
$curlOptions
Definition: HttpFunctions.php:703
CookieJar
Definition: Cookie.php:207
MWHttpRequest\$caInfo
$caInfo
Definition: HttpFunctions.php:198
MWHttpRequest\canMakeRequests
static canMakeRequests()
Simple function to test if we can make any sort of requests at all, using cURL or fopen()
Definition: HttpFunctions.php:272
CurlHttpRequest\canFollowRedirects
canFollowRedirects()
Definition: HttpFunctions.php:805
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
CurlHttpRequest\SUPPORTS_FILE_POSTS
const SUPPORTS_FILE_POSTS
Definition: HttpFunctions.php:701
MWHttpRequest\getResponseHeader
getResponseHeader( $header)
Returns the value of the given response header.
Definition: HttpFunctions.php:560
MWHttpRequest\setUserAgent
setUserAgent( $UA)
Set the user agent.
Definition: HttpFunctions.php:356
MWHttpRequest\execute
execute()
Take care of whatever is necessary to perform the URI request.
Definition: HttpFunctions.php:435
Http\isValidURI
static isValidURI( $uri)
Checks that the given URI is a valid one.
Definition: HttpFunctions.php:172
CurlHttpRequest\readHeader
readHeader( $fh, $content)
Definition: HttpFunctions.php:711
MWHttpRequest\canFollowRedirects
canFollowRedirects()
Returns true if the backend can follow redirects.
Definition: HttpFunctions.php:692
PhpHttpRequest
Definition: HttpFunctions.php:820
MWHttpRequest\$callback
$callback
Definition: HttpFunctions.php:203
MWHttpRequest\$proxy
$proxy
Definition: HttpFunctions.php:194
MWHttpRequest\factory
static factory( $url, $options=null)
Generate a new request object.
Definition: HttpFunctions.php:284
MWHttpRequest\getFinalUrl
getFinalUrl()
Returns the final URL after all redirections.
Definition: HttpFunctions.php:648
Http
Various HTTP related functions.
Definition: HttpFunctions.php:32
MWHttpRequest\$url
$url
Definition: HttpFunctions.php:201
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:497
Http\post
static post( $url, $options=array())
Simple wrapper for Http::request( 'POST' )
Definition: HttpFunctions.php:106
Status\newFatal
static newFatal( $message)
Factory function for fatal errors.
Definition: Status.php:63
wfArrayToCgi
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes two arrays as input, and returns a CGI-style string, e.g.
Definition: GlobalFunctions.php:367