MediaWiki  1.33.0
CookieJar.php
Go to the documentation of this file.
1 <?php
25 class CookieJar {
27  private $cookie = [];
28 
36  public function setCookie( $name, $value, $attr ) {
37  /* cookies: case insensitive, so this should work.
38  * We'll still send the cookies back in the same case we got them, though.
39  */
40  $index = strtoupper( $name );
41 
42  if ( isset( $this->cookie[$index] ) ) {
43  $this->cookie[$index]->set( $value, $attr );
44  } else {
45  $this->cookie[$index] = new Cookie( $name, $value, $attr );
46  }
47  }
48 
55  public function serializeToHttpRequest( $path, $domain ) {
56  $cookies = [];
57 
58  foreach ( $this->cookie as $c ) {
59  $serialized = $c->serializeToHttpRequest( $path, $domain );
60 
61  if ( $serialized ) {
62  $cookies[] = $serialized;
63  }
64  }
65 
66  return implode( '; ', $cookies );
67  }
68 
76  public function parseCookieResponseHeader( $cookie, $domain ) {
77  $len = strlen( 'Set-Cookie:' );
78 
79  if ( substr_compare( 'Set-Cookie:', $cookie, 0, $len, true ) === 0 ) {
80  $cookie = substr( $cookie, $len );
81  }
82 
83  $bit = array_map( 'trim', explode( ';', $cookie ) );
84 
85  if ( count( $bit ) >= 1 ) {
86  list( $name, $value ) = explode( '=', array_shift( $bit ), 2 );
87  $attr = [];
88 
89  foreach ( $bit as $piece ) {
90  $parts = explode( '=', $piece );
91  if ( count( $parts ) > 1 ) {
92  $attr[strtolower( $parts[0] )] = $parts[1];
93  } else {
94  $attr[strtolower( $parts[0] )] = true;
95  }
96  }
97 
98  if ( !isset( $attr['domain'] ) ) {
99  $attr['domain'] = $domain;
100  } elseif ( !Cookie::validateCookieDomain( $attr['domain'], $domain ) ) {
101  return null;
102  }
103 
104  $this->setCookie( $name, $value, $attr );
105  }
106  }
107 }
captcha-old.count
count
Definition: captcha-old.py:249
CookieJar\$cookie
Cookie[] $cookie
Definition: CookieJar.php:27
$serialized
foreach( $res as $row) $serialized
Definition: testCompression.php:81
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
CookieJar\setCookie
setCookie( $name, $value, $attr)
Set a cookie in the cookie jar.
Definition: CookieJar.php:36
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
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
$value
$value
Definition: styleTest.css.php:49
Cookie\validateCookieDomain
static validateCookieDomain( $domain, $originDomain=null)
Return the true if the cookie is valid is valid.
Definition: Cookie.php:88
Cookie
Definition: Cookie.php:24
CookieJar
Cookie jar to use with MWHttpRequest.
Definition: CookieJar.php:25
$path
$path
Definition: NoLocalSettings.php:25
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
CookieJar\serializeToHttpRequest
serializeToHttpRequest( $path, $domain)
Definition: CookieJar.php:55
CookieJar\parseCookieResponseHeader
parseCookieResponseHeader( $cookie, $domain)
Parse the content of an Set-Cookie HTTP Response header.
Definition: CookieJar.php:76