MediaWiki  1.23.6
HttpTest.php
Go to the documentation of this file.
1 <?php
5 class HttpTest extends MediaWikiTestCase {
10  public function testValidateCookieDomain( $expected, $domain, $origin = null ) {
11  if ( $origin ) {
12  $ok = Cookie::validateCookieDomain( $domain, $origin );
13  $msg = "$domain against origin $origin";
14  } else {
15  $ok = Cookie::validateCookieDomain( $domain );
16  $msg = "$domain";
17  }
18  $this->assertEquals( $expected, $ok, $msg );
19  }
20 
21  public static function cookieDomains() {
22  return array(
23  array( false, "org" ),
24  array( false, ".org" ),
25  array( true, "wikipedia.org" ),
26  array( true, ".wikipedia.org" ),
27  array( false, "co.uk" ),
28  array( false, ".co.uk" ),
29  array( false, "gov.uk" ),
30  array( false, ".gov.uk" ),
31  array( true, "supermarket.uk" ),
32  array( false, "uk" ),
33  array( false, ".uk" ),
34  array( false, "127.0.0." ),
35  array( false, "127." ),
36  array( false, "127.0.0.1." ),
37  array( true, "127.0.0.1" ),
38  array( false, "333.0.0.1" ),
39  array( true, "example.com" ),
40  array( false, "example.com." ),
41  array( true, ".example.com" ),
42 
43  array( true, ".example.com", "www.example.com" ),
44  array( false, "example.com", "www.example.com" ),
45  array( true, "127.0.0.1", "127.0.0.1" ),
46  array( false, "127.0.0.1", "localhost" ),
47  );
48  }
49 
56  public function testIsValidUri( $expect, $URI, $message = '' ) {
57  $this->assertEquals(
58  $expect,
59  (bool)Http::isValidURI( $URI ),
60  $message
61  );
62  }
63 
67  public static function provideURI() {
69  return array(
70  array( false, '¿non sens before!! http://a', 'Allow anything before URI' ),
71 
72  # (http|https) - only two schemes allowed
73  array( true, 'http://www.example.org/' ),
74  array( true, 'https://www.example.org/' ),
75  array( true, 'http://www.example.org', 'URI without directory' ),
76  array( true, 'http://a', 'Short name' ),
77  array( true, 'http://étoile', 'Allow UTF-8 in hostname' ), # 'étoile' is french for 'star'
78  array( false, '\\host\directory', 'CIFS share' ),
79  array( false, 'gopher://host/dir', 'Reject gopher scheme' ),
80  array( false, 'telnet://host', 'Reject telnet scheme' ),
81 
82  # :\/\/ - double slashes
83  array( false, 'http//example.org', 'Reject missing colon in protocol' ),
84  array( false, 'http:/example.org', 'Reject missing slash in protocol' ),
85  array( false, 'http:example.org', 'Must have two slashes' ),
86  # Following fail since hostname can be made of anything
87  array( false, 'http:///example.org', 'Must have exactly two slashes, not three' ),
88 
89  # (\w+:{0,1}\w*@)? - optional user:pass
90  array( true, 'http://user@host', 'Username provided' ),
91  array( true, 'http://user:@host', 'Username provided, no password' ),
92  array( true, 'http://user:pass@host', 'Username and password provided' ),
93 
94  # (\S+) - host part is made of anything not whitespaces
95  array( false, 'http://!"èèè¿¿¿~~\'', 'hostname is made of any non whitespace' ),
96  array( false, 'http://exam:ple.org/', 'hostname can not use colons!' ),
97 
98  # (:[0-9]+)? - port number
99  array( true, 'http://example.org:80/' ),
100  array( true, 'https://example.org:80/' ),
101  array( true, 'http://example.org:443/' ),
102  array( true, 'https://example.org:443/' ),
103 
104  # Part after the hostname is / or / with something else
105  array( true, 'http://example/#' ),
106  array( true, 'http://example/!' ),
107  array( true, 'http://example/:' ),
108  array( true, 'http://example/.' ),
109  array( true, 'http://example/?' ),
110  array( true, 'http://example/+' ),
111  array( true, 'http://example/=' ),
112  array( true, 'http://example/&' ),
113  array( true, 'http://example/%' ),
114  array( true, 'http://example/@' ),
115  array( true, 'http://example/-' ),
116  array( true, 'http://example//' ),
117  array( true, 'http://example/&' ),
118 
119  # Fragment
120  array( true, 'http://exam#ple.org', ), # This one is valid, really!
121  array( true, 'http://example.org:80#anchor' ),
122  array( true, 'http://example.org/?id#anchor' ),
123  array( true, 'http://example.org/?#anchor' ),
124 
125  array( false, 'http://a ¿non !!sens after', 'Allow anything after URI' ),
126  );
127  }
128 
137  public function testRelativeRedirections() {
138  $h = MWHttpRequestTester::factory( 'http://oldsite/file.ext' );
139 
140  # Forge a Location header
141  $h->setRespHeaders( 'location', array(
142  'http://newsite/file.ext',
143  '/newfile.ext',
144  )
145  );
146  # Verify we correctly fix the Location
147  $this->assertEquals(
148  'http://newsite/newfile.ext',
149  $h->getFinalUrl(),
150  "Relative file path Location: interpreted as full URL"
151  );
152 
153  $h->setRespHeaders( 'location', array(
154  'https://oldsite/file.ext'
155  )
156  );
157  $this->assertEquals(
158  'https://oldsite/file.ext',
159  $h->getFinalUrl(),
160  "Location to the HTTPS version of the site"
161  );
162 
163  $h->setRespHeaders( 'location', array(
164  '/anotherfile.ext',
165  'http://anotherfile/hoster.ext',
166  'https://anotherfile/hoster.ext'
167  )
168  );
169  $this->assertEquals(
170  'https://anotherfile/hoster.ext',
171  $h->getFinalUrl( "Relative file path Location: should keep the latest host and scheme!" )
172  );
173  }
174 }
175 
180 
181  // function derived from the MWHttpRequest factory function but
182  // returns appropriate tester class here
183  public static function factory( $url, $options = null ) {
184  if ( !Http::$httpEngine ) {
185  Http::$httpEngine = function_exists( 'curl_init' ) ? 'curl' : 'php';
186  } elseif ( Http::$httpEngine == 'curl' && !function_exists( 'curl_init' ) ) {
187  throw new MWException( __METHOD__ . ': curl (http://php.net/curl) is not installed, but' .
188  'Http::$httpEngine is set to "curl"' );
189  }
190 
191  switch ( Http::$httpEngine ) {
192  case 'curl':
193  return new CurlHttpRequestTester( $url, $options );
194  case 'php':
195  if ( !wfIniGetBool( 'allow_url_fopen' ) ) {
196  throw new MWException( __METHOD__ . ': allow_url_fopen needs to be enabled for pure PHP' .
197  ' http requests to work. If possible, curl should be used instead. See http://php.net/curl.' );
198  }
199 
200  return new PhpHttpRequestTester( $url, $options );
201  default:
202  }
203  }
204 }
205 
207  function setRespHeaders( $name, $value ) {
208  $this->respHeaders[$name] = $value;
209  }
210 }
211 
213  function setRespHeaders( $name, $value ) {
214  $this->respHeaders[$name] = $value;
215  }
216 }
PhpHttpRequestTester\setRespHeaders
setRespHeaders( $name, $value)
Definition: HttpTest.php:213
of
globals txt Globals are evil The original MediaWiki code relied on globals for processing context far too often MediaWiki development since then has been a story of slowly moving context out of global variables and into objects Storing processing context in object member variables allows those objects to be reused in a much more flexible way Consider the elegance of
Definition: globals.txt:10
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
is
We use the convention $dbr for read and $dbw for write to help you keep track of whether the database object is a the world will explode Or to be a subsequent write query which succeeded on the master may fail when replicated to the slave due to a unique key collision Replication on the slave will stop and it may take hours to repair the database and get it back online Setting read_only in my cnf on the slave will avoid this but given the dire we prefer to have as many checks as possible We provide a but the wrapper functions like please read the documentation for except in special pages derived from QueryPage It s a common pitfall for new developers to submit code containing SQL queries which examine huge numbers of rows Remember that COUNT * is(N), counting rows in atable is like counting beans in a bucket.------------------------------------------------------------------------ Replication------------------------------------------------------------------------The largest installation of MediaWiki, Wikimedia, uses a large set ofslave MySQL servers replicating writes made to a master MySQL server. Itis important to understand the issues associated with this setup if youwant to write code destined for Wikipedia.It 's often the case that the best algorithm to use for a given taskdepends on whether or not replication is in use. Due to our unabashedWikipedia-centrism, we often just use the replication-friendly version, but if you like, you can use wfGetLB() ->getServerCount() > 1 tocheck to see if replication is in use.===Lag===Lag primarily occurs when large write queries are sent to the master.Writes on the master are executed in parallel, but they are executed inserial when they are replicated to the slaves. The master writes thequery to the binlog when the transaction is committed. The slaves pollthe binlog and start executing the query as soon as it appears. They canservice reads while they are performing a write query, but will not readanything more from the binlog and thus will perform no more writes. Thismeans that if the write query runs for a long time, the slaves will lagbehind the master for the time it takes for the write query to complete.Lag can be exacerbated by high read load. MediaWiki 's load balancer willstop sending reads to a slave when it is lagged by more than 30 seconds.If the load ratios are set incorrectly, or if there is too much loadgenerally, this may lead to a slave permanently hovering around 30seconds lag.If all slaves are lagged by more than 30 seconds, MediaWiki will stopwriting to the database. All edits and other write operations will berefused, with an error returned to the user. This gives the slaves achance to catch up. Before we had this mechanism, the slaves wouldregularly lag by several minutes, making review of recent editsdifficult.In addition to this, MediaWiki attempts to ensure that the user seesevents occurring on the wiki in chronological order. A few seconds of lagcan be tolerated, as long as the user sees a consistent picture fromsubsequent requests. This is done by saving the master binlog positionin the session, and then at the start of each request, waiting for theslave to catch up to that position before doing any reads from it. Ifthis wait times out, reads are allowed anyway, but the request isconsidered to be in "lagged slave mode". Lagged slave mode can bechecked by calling wfGetLB() ->getLaggedSlaveMode(). The onlypractical consequence at present is a warning displayed in the pagefooter.===Lag avoidance===To avoid excessive lag, queries which write large numbers of rows shouldbe split up, generally to write one row at a time. Multi-row INSERT ...SELECT queries are the worst offenders should be avoided altogether.Instead do the select first and then the insert.===Working with lag===Despite our best efforts, it 's not practical to guarantee a low-lagenvironment. Lag will usually be less than one second, but mayoccasionally be up to 30 seconds. For scalability, it 's very importantto keep load on the master low, so simply sending all your queries tothe master is not the answer. So when you have a genuine need forup-to-date data, the following approach is advised:1) Do a quick query to the master for a sequence number or timestamp 2) Run the full query on the slave and check if it matches the data you gotfrom the master 3) If it doesn 't, run the full query on the masterTo avoid swamping the master every time the slaves lag, use of thisapproach should be kept to a minimum. In most cases you should just readfrom the slave and let the user deal with the delay.------------------------------------------------------------------------ Lock contention------------------------------------------------------------------------Due to the high write rate on Wikipedia(and some other wikis), MediaWiki developers need to be very careful to structure their writesto avoid long-lasting locks. By default, MediaWiki opens a transactionat the first query, and commits it before the output is sent. Locks willbe held from the time when the query is done until the commit. So youcan reduce lock time by doing as much processing as possible before youdo your write queries.Often this approach is not good enough, and it becomes necessary toenclose small groups of queries in their own transaction. Use thefollowing syntax:$dbw=wfGetDB(DB_MASTER
HttpTest\testValidateCookieDomain
testValidateCookieDomain( $expected, $domain, $origin=null)
@dataProvider cookieDomains @covers Cookie::validateCookieDomain
Definition: HttpTest.php:10
CurlHttpRequestTester\setRespHeaders
setRespHeaders( $name, $value)
Definition: HttpTest.php:207
HttpTest\cookieDomains
static cookieDomains()
Definition: HttpTest.php:21
PhpHttpRequestTester
Definition: HttpTest.php:212
anything
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 and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same so they can t rely on Unix and must forbid reads to even standard directories like tmp lest users read each others files We cannot assume that the user has the ability to install or run any programs not written as web accessible PHP scripts Since anything that works on cheap shared hosting will work if you have shell or root access MediaWiki s design is based around catering to the lowest common denominator Although we support higher end setups as the way many things work by default is tailored toward shared hosting These defaults are unconventional from the point of view of and they certainly aren t ideal for someone who s installing MediaWiki as MediaWiki does not conform to normal Unix filesystem layout Hopefully we ll offer direct support for standard layouts in the but for now *any change to the location of files is unsupported *Moving things and leaving symlinks will *probably *not break anything
Definition: distributors.txt:39
fail
as a message key or array as accepted by ApiBase::dieUsageMsg after processing request parameters Return false to let the request fail
Definition: hooks.txt:375
CurlHttpRequest
MWHttpRequest implemented using internal curl compiled into PHP.
Definition: HttpFunctions.php:700
HttpTest\testRelativeRedirections
testRelativeRedirections()
Warning:
Definition: HttpTest.php:137
part
in this case you re responsible for computing and outputting the entire conflict part
Definition: hooks.txt:1038
MWException
MediaWiki exception.
Definition: MWException.php:26
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
MWHttpRequestTester
Class to let us overwrite MWHttpRequest respHeaders variable.
Definition: HttpTest.php:179
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
port
storage can be distributed across multiple and multiple web servers can use the same cache cluster *********************W A R N I N G ***********************Memcached has no security or authentication Please ensure that your server is appropriately and that the port(s) used for memcached servers are not publicly accessible. Otherwise
CurlHttpRequestTester
Definition: HttpTest.php:206
HttpTest\provideURI
static provideURI()
Feeds URI to test a long regular expression in Http::isValidURI.
Definition: HttpTest.php:67
$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
$ok
$ok
Definition: UtfNormalTest.php:71
w
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 and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same so they can t rely on Unix and must forbid reads to even standard directories like tmp lest users read each others files We cannot assume that the user has the ability to install or run any programs not written as web accessible PHP scripts Since anything that works on cheap shared hosting will work if you have shell or root access MediaWiki s design is based around catering to the lowest common denominator Although we support higher end setups as the way many things work by default is tailored toward shared hosting These defaults are unconventional from the point of view of and they certainly aren t ideal for someone who s installing MediaWiki as MediaWiki does not conform to normal Unix filesystem layout Hopefully we ll offer direct support for standard layouts in the but for now *any change to the location of files is unsupported *Moving things and leaving symlinks will *probably *not break but it is *strongly *advised not to try any more intrusive changes to get MediaWiki to conform more closely to your filesystem hierarchy Any such attempt will almost certainly result in unnecessary bugs The standard recommended location to install relative to the web is w(so, e.g.,/var/www/w). Rewrite rules can then be used to enable "pretty URLs" like/wiki/Article instead of/w/index.php?title
user
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 and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same user
Definition: distributors.txt:9
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
$value
$value
Definition: styleTest.css.php:45
Cookie\validateCookieDomain
static validateCookieDomain( $domain, $originDomain=null)
Return the true if the cookie is valid is valid.
Definition: Cookie.php:92
MWHttpRequest
This wrapper class will call out to curl (if available) or fallback to regular PHP if necessary for h...
Definition: HttpFunctions.php:187
MWHttpRequestTester\factory
static factory( $url, $options=null)
Generate a new request object.
Definition: HttpTest.php:183
wfIniGetBool
wfIniGetBool( $setting)
Safety wrapper around ini_get() for boolean settings.
Definition: GlobalFunctions.php:2685
only
published in in Madrid In the first edition of the Vocabolario for was published In in Rotterdam was the Dictionnaire Universel ! html< p > The first monolingual dictionary written in a Romance language was< i > Sebastián Covarrubias</i >< i > Tesoro de la lengua castellana o published in in Madrid In the first edition of the< i > Vocabolario dell< a href="/index.php?title=Accademia_della_Crusca&amp;action=edit&amp;redlink=1" class="new" title="Accademia della Crusca (page does not exist)"> Accademia della Crusca</a ></i > for was published In in Rotterdam was the< i > Dictionnaire Universel</i ></p > ! end ! test Italics and ! wikitext foo ! html< p >< i > foo</i ></p > !end ! test Italics and ! wikitext foo ! html< p >< i > foo</i ></p > !end ! test Italics and ! wikitext foo ! html< p >< i > foo</i ></p > !end ! test Italics and ! wikitext foo ! html php< p >< i > foo</i ></p > ! html parsoid< p >< i > foo</i >< b ></b ></p > !end ! test Italics and ! wikitext foo ! html< p >< i > foo</i ></p > !end ! test Italics and ! wikitext foo ! html< p >< b > foo</b ></p > !end ! test Italics and ! wikitext foo ! html< p >< b > foo</b ></p > !end ! test Italics and ! wikitext foo ! html php< p >< b > foo</b ></p > ! html parsoid< p >< b > foo</b >< i ></i ></p > !end ! test Italics and ! wikitext foo ! html< p >< i > foo</i ></p > !end ! test Italics and ! wikitext foo ! html< p >< b > foo</b ></p > !end ! test Italics and ! wikitext foo ! html< p >< b > foo</b ></p > !end ! test Italics and ! wikitext foo ! html php< p >< b > foo</b ></p > ! html parsoid< p >< b > foo</b >< i ></i ></p > !end ! test Italics and ! options ! wikitext foo ! html< p >< b >< i > foo</i ></b ></p > !end ! test Italics and ! wikitext foo ! html< p >< i >< b > foo</b ></i ></p > !end ! test Italics and ! wikitext foo ! html< p >< i >< b > foo</b ></i ></p > !end ! test Italics and ! wikitext foo ! html< p >< i >< b > foo</b ></i ></p > !end ! test Italics and ! wikitext foo bar ! html< p >< i > foo< b > bar</b ></i ></p > !end ! test Italics and ! wikitext foo bar ! html< p >< i > foo< b > bar</b ></i ></p > !end ! test Italics and ! wikitext foo bar ! html< p >< i > foo< b > bar</b ></i ></p > !end ! test Italics and ! wikitext foo bar ! html php< p >< b > foo</b > bar</p > ! html parsoid< p >< b > foo</b > bar< i ></i ></p > !end ! test Italics and ! wikitext foo bar ! html php< p >< b > foo</b > bar</p > ! html parsoid< p >< b > foo</b > bar< b ></b ></p > !end ! test Italics and ! wikitext this is about foo s family ! html< p >< i > this is about< b > foo s family</b ></i ></p > !end ! test Italics and ! wikitext this is about foo s family ! html< p >< i > this is about< b > foo s</b > family</i ></p > !end ! test Italics and ! wikitext this is about foo s family ! html< p >< b > this is about< i > foo</i ></b >< i > s family</i ></p > !end ! test Italics and ! options ! wikitext this is about foo s family ! html< p >< i > this is about</i > foo< b > s family</b ></p > !end ! test Italics and ! wikitext this is about foo s family ! html< p >< b > this is about< i > foo s</i > family</b ></p > !end ! test Italicized possessive ! wikitext The s talk page ! html< p > The< i >< a href="/wiki/Main_Page" title="Main Page"> Main Page</a ></i > s talk page</p > ! end ! test Parsoid only
Definition: parserTests.txt:396
https
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at https
Definition: design.txt:12
HttpTest\testIsValidUri
testIsValidUri( $expect, $URI, $message='')
Test Http::isValidURI()
Definition: HttpTest.php:56
Http\isValidURI
static isValidURI( $uri)
Checks that the given URI is a valid one.
Definition: HttpFunctions.php:172
HttpTest
@group Broken
Definition: HttpTest.php:5
PhpHttpRequest
Definition: HttpFunctions.php:820
MWHttpRequest\$url
$url
Definition: HttpFunctions.php:201