Commit graph

58 commits

Author SHA1 Message Date
TChin
47adb6d65a Refactor global variables to use MediaWikiServices instead
Automatically refactors wg prefixed globals to use MediaWikiServices config using Rector. Doesn't include files that set globals or files that fail CI.

Rector Gist: https://gist.github.com/tchin25/7cc54f6d23aedef010b22e4dfbead228

* This patch uses a modified source code rector library for our specific use case and the rector will have different effects without it.

A writeup for future reference is here: https://meta.wikimedia.org/wiki/User:TChin_(WMF)/Using_Rector_On_MediaWiki

Change-Id: I1a691f01cd82e60bf41207d32501edb4b9835e37
2022-01-10 13:55:53 -05:00
Reedy
7bf779524a Remove or replace usages of "sanity"
Bug: T254646
Change-Id: I2b120f0b9c9e1dc1a6c216bfefa3f2463efe1001
2021-11-19 23:19:42 +00:00
Timo Tijhof
faf2233cf4 OutputHandler: Omit debug() call for common case
Folllows-up I4c2d478b492ff17.

* MW_ENTRY_POINT can only be undefined in very early WebStart/Setup
  code. In code outside those files, and by the time MW_SETUP_CALLBACK
  OutputHandler run, this is always filled in to at least "unknown".

* Inline extra code to the less common conditional block.

Bug: T290776
Change-Id: Ia7fa6cb0ff156ed6cb0212443ac3a97c91982d4b
2021-09-23 00:19:57 +01:00
Aaron Schulz
64a4d6e74f Fix $wgDisableOutputCompression and $phase checks in OutputHandler
The config variable check from 6c81f0b868d2 needed a negation.

The phase check from 374bdc0f7c should have been a conjuction.

Also add some debug logging statements.

Follow-up to 6c81f0b868d2 and 374bdc0f7c.

Bug: T290776
Change-Id: I4c2d478b492ff17bdad76bf75119b5926f7917e8
2021-09-22 13:41:47 -07:00
Tim Starling
9f4eb79c2e Reapply Content-Length deferred updates patches
* Revert "Disable DEFER_SET_LENGTH_AND_FLUSH headers to avoid HTTP
  errors"
* Reapply "Avoid HTTP protocol errors when fastcgi_finish_request() is
  unavailable"
* Reapply "Move logDataPageOutputOnly() call to
  outputResponsePayload()"

This reverts commit 0393ddbb2a.
This reverts commit 89065a22aa.
This reverts commit e70757f58b.

Change-Id: I8a362a80bb1aa147192218a37df34aadba34fb2e
2021-04-08 09:25:56 +00:00
Tim Starling
bcec556b77 Don't send headers on ob_end_clean()
Replace the global variable hack in wfResetOutputBuffers() with a check
for the PHP_OUTPUT_HANDLER_CLEAN flag in the $phase parameter, available
since PHP 5.4.0. Aaron's Content-Length patch will work if applied on top
of this.

Bug: T278579
Change-Id: I9ec12f499821826038a39ebe94eed136f123b078
2021-04-08 11:26:06 +10:00
Reedy
89065a22aa Revert "Avoid HTTP protocol errors when fastcgi_finish_request() is unavailable"
This reverts commit f4f0ad970e.

Bug: T278579
Change-Id: I3071209eff16b5dcc853f497a243a9af0883b67a
2021-04-02 13:31:24 +01:00
Aaron Schulz
f4f0ad970e Avoid HTTP protocol errors when fastcgi_finish_request() is unavailable
This fixes problem that arise with apache2/mod_php due to deferred updates

* Do not send unnecessary and invalid "Content-Encoding: identity" header
* Do not send "Connection: close" if HTTP2 is detected (per the HTTP spec)
  pending, which reduces the use of output buffer and HTTP header tricks
* Make sure that no output is emitted in doPostOutputShutdown() from any
  deferred updates since the response will have already been flushed to
  the client by that point
* Make the Content-Length header logic in outputResponsePayload() account
  for cases where there is a non-empty output buffer, cases where there
  are several output buffers (bail out), and limit the use of the header
  to HTTP 200/404 responses (avoids violation of the HTTP spec)
* Make sure OutputHandler::handle() does not send payloads for responses
  that must not have one (e.g. "204 No Content")
* If an output buffer using OutputHandler::handle is active, then let it
  handle the setting of Content-Length rather than outputResponsePayload()
* Do not bother trying to disable zlib.output_compression, since that did
  not actually stop the client from getting blocked
* Set "no-gzip" via apache_setenv() unconditionally

Bug: T235554
Change-Id: I26f16457698c2c45e561b0c79c78a74e7f47126c
2021-03-24 12:53:31 -07:00
DannyS712
35bd84e9ee Comments: use only // instead of more
No need for three or more slashes

Except in some places where a bunch more are
used for drawing attention to something

Change-Id: Ic90358eb89a14a04d2b66c48e52e8fb20de0eb04
2021-03-10 15:05:57 +00:00
Tim Starling
47a1619027 Remove terminating line breaks from debug messages
A terminating line break has not been required in wfDebug() since 2014,
however no migration was done. Some of these line breaks found their way
into LoggerInterface::debug() calls, where they mess up the formatting
of the debug log.

So, remove terminating line breaks from wfDebug() and
LoggerInterface::debug() calls.

Also:
* Fix the stripping of leading line breaks from the log header emitted
  by Setup.php. This feature, accidentally broken in 2014, allows
  requests to be distinguished in the log file.
* Avoid using the global variable $self.
* Move the logging of the client IP back to Setup.php. It was moved to
  WebRequest in the hopes that it would not always be needed, however
  $wgRequest->getIP() is now called unconditionally a few lines up in
  Setup.php. This means that it is put in its proper place after the
  "start request" message.
* Wrap the log header code in a closure so that variables like $name do
  not leak into global scope.
* In Linker.php, remove a few instances of an unnecessary second
  parameter to wfDebug().

Change-Id: I96651d3044a95b9d210b51cb8368edc76bebbb9e
2020-06-03 12:01:16 +10:00
C. Scott Ananian
ce1bd86a4b Remove $wgUseKeyHeader and OutputPage::getKeyHeader(), deprecated in 1.32
These implemented a since-abandoned draft IETF spec, and the code was
broken due to (1) case-(in)sensitivity issues with the Accept-Language
header and (2) the BCP47 language code compatibility workaround we use.

Change-Id: Ia53d07cd8ce8ab1497294ea244c13c7499f632c7
2019-06-19 15:14:54 -04:00
Thiemo Kreuz
3a66680ec5 Simplify a few list() that only care about the first element
The nice thing about explode() is that the resulting array is
guaranteed to contain at least one element. The array can not be
empty.

In some of these cases it might be possible to use strstr() instead,
but that returns an empty string when the needle character is not
found. explode() returns the original string in this case.

Change-Id: I6ad1f3273defeaf36e2305fd871eaaf9d3c1e134
2019-05-17 16:54:47 +02:00
James D. Forrester
0da97e7a03 Immediately drop wgValidateAllHtml and related code
Bug: T191670
Change-Id: If13d02ee1b30fec1c701226af9d363c6e08b3737
2018-04-10 10:51:28 -07:00
Timo Tijhof
665e9b7bf2 Convert OutputHandler functions to a class
* Convert OutputHandler.php from global functions to a class.

  - wfOutputHandler → OutputHandler::handle
    (no alias, no usage outside core)
  - wfGzipHandler → OutputHandler::handleGzip
    (private, no usage outside class)
  - wfRequestExtension → OutputHandler::findUriExtension
    (private, no usage outside class)
  - wfMangleFlashPolicy → OutputHandler::mangleFlashPolicy
    (private, no usage outside class)
  - wfDoContentLength → OutputHandler::emitContentLength
    (private, no usage outside class)
  - wfHtmlValidationHandler → OutputHandler::validateAllHtml
    (private, no usage outside class)

* Add the class to autoload.php for exposure outside WebStart.
  Specifically, for use in ApiFormatPhpTest. This also removes the
  need to manually load the class because this code runs after
  Setup.php loads AutoLoader.php.

Bug: T189966
Change-Id: I27a41ec0ae0ee30aeb313a616323b967605c4055
2018-03-20 21:11:32 -07:00
Umherirrender
b5cddfb27b Remove empty lines at begin of function, if, foreach, switch
Organize phpcs.xml a bit

Change-Id: Ifb767729b481b4b686e6d6444cf48b1f580cc478
2017-07-01 11:34:16 +00:00
Brad Jorsch
f459c1aeca SECURITY: Improve cross-domain-policy mangling
Take into account that the tag might have parameters.

Bug: T123653
Change-Id: Ie9799f5ea45badfb4e7b4be7e7fbc1c35cc86f26

Signed-off-by: Chad Horohoe <chadh@wikimedia.org>
2016-05-20 09:48:11 -07:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Aaron Schulz
6af3c39c07 Replace "squid" with "CDN" in various comments
Change-Id: Idcc528daf28e119349155d36e30a9bcf61b2e7d5
2015-12-09 17:35:37 -08:00
Faidon Liambotis
7e20cb51fe Replace XVO with support for the Key HTTP header
MediaWiki currently has support for a header called X-Vary-Options
(XVO), used to communicate to upstream caches more granular cache
variance options than the Vary header can.

The header was envisioned by Tim Starling back in 2008 and implemented
into MediaWiki and Squid 2.0, with those patches submitted to the
squid-dev mailing list at the time:
http://www.squid-cache.org/mail-archive/squid-dev/200802/0085.html
The patches never actually made it into an upstream Squid release,
however, and Squid has since evolved in potentially significant ways.

Wikimedia has since switched to Varnish but XVO was not ported over as
it was deemed too complex at the time; custom VCL was used instead. To
our knowledge, noone else is using XVO in production and certainly not
with recent, up-to-date MediaWiki releases.

There is currently work at IETF's httpbis working group for a "Key"
header that is in concept and implementation very similar to Tim's XVO
header: https://datatracker.ietf.org/doc/draft-fielding-http-key/

Rather than rip XVO out of MediaWiki, replace it with support for the
Key header, as preliminary defined by the draft spec. This is an almost
straight search-and-replace.

No other software (caching proxy or user-agent) currently implements Key
to my knowledge, so this is essentially untested.

Change-Id: I949fc289dd5d48bd34f3b37f7739e2b9cd5db277
2015-10-07 21:26:40 -07:00
Sergio Santoro
3de9803c06 Fix case insensitive string comparison for http header names
As of RFC 2616 sec 4.2, http header names are case insensitive.

Change-Id: Ib72df2572f5a9c825c5b3ad7735126f3687aad79
2014-12-12 02:38:43 +00:00
csteipp
92f22cd466 Make calling wfMangleFlashPolicy configurable
Add $wgMangleFlashPolicy so sites that define a safe master flash
policy can disable mangling of the <cross-domain-policy> string.

Bug: 66776
Change-Id: Ic0db939aae9d0bb6bdfc3cd9ce282661bad46783
2014-11-19 11:46:18 -08:00
Siebrand Mazeland
49cffd699c Make phpcs-strict pass on includes/ (2/~10)
Change-Id: I59fa9af7b16e0a5a4eb8a5cc764a605b18137316
2014-05-11 19:22:05 +00:00
umherirrender
8ad1c92441 Fixed some @params documentation (includes/*)
Swapped some "$var type" to "type $var" or added missing types
before the $var. Changed some other types to match the more common
spelling. Makes beginning of some text in captial.
Also added some missing @param.

Change-Id: I7f605aa9e117b5fd80d9b1440864fe526d2b14a5
2014-04-20 21:16:57 +02:00
Alexandre Emsenhuber
559afbf6d3 Fix fatal error when $wgValidateAllHtml is enabled and apache_request_headers() does not exists
Changed apache_request_headers() to headers_list() since the latter is always available

Change-Id: Ia52f5a0d12db0680aa03b57dd45c974291e88af9
2013-07-25 12:05:13 +02:00
Daniel Friesen
97caae596d Drop support for XHTML 1.0
* $wgHtml5 = false; is now ignored completely.
* $wgDocType and $wgDTD have been removed.
* $wgXhtmlDefaultNamespace is now ignored.
* XHTML5 will be output if $wgMimeType is set to an XML mime type (according to HTML5's rules).
* For backwards compatibility with extensions $wgHtml5 and $wgXhtmlDefaultNamespace are set
  in Setup.php but depending on them is deprecated.

Change-Id: Iad9634e2ee420b5a3bbffe550421fde4fa1819b0
2013-05-15 23:09:25 -07:00
umherirrender
ef2f507d23 Fixed spacing in files direct in includes folder
Added spaces before if, foreach
Added some braces for one line statements

Change-Id: Ibb8dd102db045522d12ff939075ba7420d95ab6b
2013-04-21 06:38:49 +00:00
Yuri Astrakhan
9506e3d812 Spellchecked /includes directory
* Ran spell-checker over code comments in /includes/
* A few spellchecking fixes for wfDebug() calls

Found one very strange (NOOP?) line in Linker.php - see "TODO: BUG?"

Change-Id: Ibb86b51073b980eda9ecce2cf0b8dd33f058adbf
2013-03-13 03:42:41 -04:00
Dereckson
7276fd4d90 (bug 43218) Fixing PHP notice: undefined SERVER_PROTOCOL key
Change-Id: I1ce7605a7c8503aed37ed9b3e7c3f3c13083db6f
2012-12-18 15:45:06 +01:00
umherirrender
85d8ee1f87 Remove a bunch of trailing spaces and unneeded newlines
Change-Id: I00f369641320acd7f087427ef031f3ee7efa0997
2012-10-10 20:14:40 +02:00
Alexandre Emsenhuber
d1f8640a3b Added missing GPLv2 headers in some places.
Also made file/class documentation more consistent.

Change-Id: Ia45d0756cd84138da267bf1cbd1a58be7f28c6d1
2012-05-11 10:34:29 +02:00
Antoine Musso
9b6a4c922a debug statements for HTMLFileCache / Output 2012-02-09 10:56:36 +00:00
Sam Reed
3614ecfffb And more documentation. Yaaaay 2011-05-28 17:18:50 +00:00
Sam Reed
a9554c1677 More adding, updating and tweaking of documentation 2011-05-21 19:07:24 +00:00
Siebrand Mazeland
75c6696aa8 Use consistent notation for "@todo FIXME". Should update http://svn.wikimedia.org/doc/todo.html nicely. 2011-05-17 22:03:20 +00:00
Alexandre Emsenhuber
7b79d94515 * Standardised file description headers
* Added some descriptions
* Added @file where needed
2010-08-14 17:42:40 +00:00
Tim Starling
4c94b8a9ec Send XVO headers only if $wgUseXVO is true. 2010-07-23 05:00:58 +00:00
Aryeh Gregor
643866f8b7 War on xml:lang
There is no reason to use this in HTML in addition to the lang
attribute.  No spec requires it (AFAIK) and it's completely redundant.
2010-02-11 17:25:10 +00:00
Platonides
da21210211 (bug 22034) use wfClientAcceptsGzip() in wfGzipHandler instead of reimplementing it.
$wgUseGzip check on wfClientAcceptsGzip() is removed since HTMLFileCache (the only wfClientAcceptsGzip() user) already checked that before calling it. This way, $wgUseGzip stays applying only for file cache, and $wgDisableOutputCompression for  output handler.
2010-01-14 16:35:35 +00:00
Siebrand Mazeland
7c27e42fb8 Revert 60864: "Use wfClientAcceptsGzip() in wfGzipHandler." Causes PHP Notice: Undefined index: HTTP_ACCEPT_ENCODING in GlobalFunctions.php on line 1175 2010-01-09 19:14:43 +00:00
Siebrand Mazeland
29e47fa366 (bug 22034) Use wfClientAcceptsGzip() in wfGzipHandler. Patch by Platonides.
wfGzipHandler should use wfClientAcceptsGzip() instead of reimplementing it. Patch does this and removes the $wgUseGzip check on wfClientAcceptsGzip() since HTMLFileCache (the only wfClientAcceptsGzip() user) already checked that before calling it. This way $wgUseGzip stays applying only for file cache, and $wgDisableOutputCompression for output handler.
2010-01-09 18:10:11 +00:00
Alexandre Emsenhuber
c3ec19debc Replaced all @fixme with "@todo Fixme" since doxygen doesn't have a @fixme command 2009-12-15 21:26:58 +00:00
OverlordQ
a989843cd0 Code cleanup, covert leading spaces into tabs per coding style 2009-11-14 21:27:13 +00:00
Domas Mituzas
1508f598ad sweet spot for compression, per:
* http://spreadsheets.google.com/pub?key=t-EjyzEfh0t39hoQbf-a5fw
2009-08-28 17:46:19 +00:00
Siebrand Mazeland
9e968c0bfa Re-revert r46344 because of crossing commits (r46346) 2009-01-27 15:20:31 +00:00
Siebrand Mazeland
4b9b399711 Revert r46344. PHP Fatal error: Class 'MWTidy' not found in /var/www/w/includes/parser/Parser.php on line 378 2009-01-27 15:17:45 +00:00
Alexandre Emsenhuber
c119961f31 Per Brion's comment on http://www.mediawiki.org/wiki/Special:Code/MediaWiki/46145#c1445 :
* Refactored Tidy function in a new class, MWTidy
* Only added Parser::tidy() for b/c, Parser::internalTidy() and Parser::externalTidy() were marked as private and are unused in core and extensions
* Added RELEASE-NOTES entry
2009-01-27 15:09:19 +00:00
Alexandre Emsenhuber
da85e17316 Tweaks for the "Whole HTML Validation" feature:
* Allow to use external tidy
* Accept application/xhtml+xml mime type
* Fix XHTML errors on errors reports :)
2009-01-24 16:26:05 +00:00
Tim Starling
4b04f1a2eb Fixed excessive memory usage in PCRE in wfMangleFlashPolicy(). Was causing OOM on various big pages. Possible upstream regression, deserves investigation. 2008-05-30 14:58:29 +00:00
Siebrand Mazeland
79d5225c0e * remove end of line whitespace
* remove empty lines at end of file
* remove "?>" where still present
2008-04-14 07:45:50 +00:00
Tim Starling
377561cd1e * Introduced OutputPage::addWikiMsg() and OutputPage::wrapWikiMsg(), to make it easier to avoid double-parsing. Double-parsing introduces differences between the old and new parsers.
* Used the new functions in the relevant places throughout the core. Where this was not possible, used wfMsgNoTrans() to avoid double-parsing.
* Calling wfEscapeWikiText() on a title before passing it to a message is unnecessary and causes bugs. The best idea is to let the message do its own escaping. Removed wfEscapeWikiText() from the caller of addedwatchtext, removedwatchtext, deletedtext, protect-text, nosuchusershort and movepage-moved. Updated all message files to use <nowiki>$1</nowiki> where appropriate in these messages. 
* Removed unnecessary empty message handling from semiprotectedpagewarning
* Removed nonsense warning about the output of wfMsg() not being safe for inclusion in HTML. 
* Changed wfShellExec() to use passthru/ob_get_contents instead of exec(). This avoids corruption of whitespace in the response. 
* Added $wgValidateAllHtml feature, to optionally validate HTML on output. 
* Fixed missing newline in cascadeprotected in MessagesEn.php
* Belatedly updated addedwatchtext to take account of the new "monobook" skin. No unwatch link in the sidebar anymore.
2008-02-18 07:25:35 +00:00