Commit graph

1476 commits

Author SHA1 Message Date
Florian Schmidt
2d52e36018 Don't use Config as an access method for global objects
The Config interface (and it's implementation(s)) was never thought
to be an access method for objects saved in the global state, even
if it works with the current implementation GlobalVarConfig.

Imagine, that MediaWiki core switches to another file-based configuratiion
storage or a a database based one, we wouldn't be able to provide
access to global objects anymore, without weird hacks in the new
config-backend implementation or serializing objects to store in
the database or something else. This all isn't the idea with the Config
interface, as far as I know, so don't use it at all.

This commit changes the access to wgContLang to use the global keyword,
instead of accessing it through Config.

Follow up: Ice4f40911c3761c2542430935bc1898bc4e7a4d4
Follow up: I46f376a82205a5c99b98c9e971f9e9d7868ce9fb

Change-Id: I7a08b3bb649898abd445317a523051b07420b211
2016-10-04 17:40:35 +02:00
Amir Sarabadani
9850c542c6 Clean up array() syntax in docs, part VII
Last part

Change-Id: I38f015e2122ef4fd2d2141718bd889794c29f06c
2016-09-27 06:53:25 +03:30
Fomafix
e101fa901b Add <!DOCTYPE html> to HTML responses
Change-Id: I080040913c4c9750104bc88b643a1ffdfd222502
2016-09-25 17:36:41 +02:00
Timo Tijhof
1b462e24f6 Clean up misuse of wfTimestampOrNull()
It's primarily meant for nullable timestamps in the database.
And for the mere purpose of an is_null() check, it's more confusion
than useful to cause this function since in these two cases its return
value is not used as-is but further conditionalized.

* Also fix fragile link between getRegistration()'s false return
  value never being passed to wfTimestamp (to mean "now") because
  of the isLoggedIn() guard. The ternary would now make those
  follow the 'else' branch toward null.

Change-Id: I9a1ee2a56e1767bfb750e27b1f37bdaeb5e6378d
2016-09-24 00:09:51 +00:00
Max Semenik
cadd370a4d Remove OutputPage->mDebugtext
Deprecated since 1.20, unused anywhere.

Change-Id: I4316b77c48e65faf788de60be28fc9cf65c785f1
2016-09-20 14:58:04 -07:00
Fomafix
e53ff931ab Apply wfBCP47() to HTTP response header Content-Language
See https://tools.ietf.org/html/rfc7231#section-3.1.3 for Content-Language.
This references https://tools.ietf.org/html/rfc5646 aka BCP 47.

Example:
curl -I https://crh.wikipedia.org/wiki/Ba%C5%9F_Saife | grep -i '^content-language:'
	should contain
Content-language: crh-Latn
	instead of
Content-language: crh-latn

Change-Id: Ice4f40911c3761c2542430935bc1898bc4e7a4d4
2016-09-16 17:43:27 +02:00
Timo Tijhof
dbbc3c2329 OutputPage: Don't set 'user' module state if filtered out
On pages where the 'user' module is filtered out (e.g.
on Special:Preferences) it would export state 'loading' (or state
'ready') eventhough the actual call to makeResourceLoader() later
in getBottomScripts() would be a no-op due to filtering.

This would cause either an indefinite state of "loading" or a
state "ready" that wasn't true.

This restores status quo as it was before 80e5b160 and 3e7a50d5f.

Test plan:
* Logged-in with non-empty user page common.js.
* View Special:Preferences.
* Verify in <head> source code, or via mw.loader.getState('user')
  that it has state "registered" (the default initial state) and
  not state "loading" or "ready".

Change-Id: I9b360d7e12703bddb80793aef47296fd63032c3d
2016-09-14 05:02:22 +00:00
Aaron Schulz
a3dacac90f Support masking the WRITE_SYNC latency from ChronologyProtector
* Use OutputPage::output() as the method to mask latency, since it
  takes a good while to run. By the time it runs, cache replication
  should have caught up, so the reap call will likely not block.
* For redirects emitted after changes in POST, instead of masking
  with OutputPage, add a parameter to the redirect and block on
  the positions appearing. This uses the redirection RTT to mask
  the replication latency.

Change-Id: Ib23690c302e8033610fef9a0ef451dafe8a5803e
2016-09-12 23:58:49 +00:00
Aaron Schulz
6f8dc27ca2 Preload ResourceLoaderWikiModule::getTitleInfo in OutputPage
This avoids a separate query for each module.

Bug: T46362
Change-Id: Ie109a8776cbdcd5928cbb59351f2cf94088c0c95
2016-09-08 14:46:18 -07:00
Aaron Schulz
950cf6016c Rename DB_SLAVE constant to DB_REPLICA
This is more consistent with LoadBalancer, modern, and inclusive
of master/master mysql, NDB cluster, and MariaDB galera cluster.

The old constant is an alias now.

Change-Id: I0b37299ecb439cc446ffbe8c341365d1eef45849
2016-09-05 22:55:53 -07:00
Aaron Schulz
16266edff3 Change "slave" => "replica DB" in /includes
Change-Id: Icb716219c9335ff8fa447b1733d04b71d9712bf9
2016-09-05 21:01:01 +00:00
Timo Tijhof
ee52872baf OutputPage: Ensure setupSkinUserCss() always applies to headElement()
Follows-up 80e5b160e0, which had to move this call out of the
headElement() and buildCssLinks() methods as it was no longer
allowed to modify the module queue after it was created.

It was moved to OutputPage::output(), right before Skin::outputPage()
is called, which ends up calling headElement().

The point in time was effectively unchanged for page views.

However for the caller in ApiParse() this meant setupSkinUserCss()
no longer got called at all as it never calls output(), but instead
calls headElement() directly.

Move it to getRlClient(), which is where we set all other 
OutputPage-specific things relating to module loading already.

* For page views this has no impact.
* For ApiParse it means headElement(), which calls getRlClient(),
  will once again include skin stylesheets.

Bug: T144301
Change-Id: I5fd4a27fb2d70b98ce9161dc050788d8ac364110
2016-09-03 18:38:49 +00:00
jenkins-bot
4b282b3ffa Merge "Floor slave lag before display" 2016-08-29 23:16:54 +00:00
Timo Tijhof
471adc7ef9 resourceloader: Make 'site.styles' actually in group 'site'
Before 93ed259cf and 7bb7315d4, 'site' and 'site.styles' module were one module
loaded in two parts. One part via the general queue (not in a separate request),
and the other part in the stylesheet queue (in a separate request).

This was achieved by hacking the stylesheet queue handler to hardcode the group
to be 'site' for a module named 'site' (later 'site.styles' in c20a76ee)
eventhough the module as a whole was not actually in that group.

Now that these modules are separated, this hack is no longer needed
and the module can be registered as being in group 'site' properly.

Change-Id: If193f556be211749b115f3808ee46536b578fb22
2016-08-25 13:39:01 -07:00
Fomafix
23fccd2708 OutputPage.php: Reuse existing variable $user
Follows-up to 81c291f2

Change-Id: Id32daf74549c8af886a46119b30ff29ab2a6ac94
2016-08-23 07:12:35 +00:00
Timo Tijhof
3955415f20 Remove redundant isLoggedIn() call
Follows-up 3e7a50d5, 81c291f26.

Change-Id: I76f71f92ed8f2f57b871fa359c469f83357d8025
2016-08-22 21:08:23 -07:00
Chad Horohoe
81c291f265 SECURITY: Require login to preview user CSS pages
Anon users have predictable edit tokens, hence someone could
force an anon to execute arbitrary CSS by means of a CSRF.

Bug: T133147
Change-Id: I442b2b46cadb967aaa1f35648eff183fc7eaa475
2016-08-23 03:18:51 +00:00
umherirrender
99cbd7d54b Floor slave lag before display
Seeing slave lags like 15.309758901596 looks scary

Change-Id: Ie564670448311364b8492af6b82943312118dc29
2016-08-21 17:01:04 +02:00
Timo Tijhof
3e7a50d5fd OutputPage: Make ResourceLoader position exemption more generic
Follows-up 80e5b160e which moved queue formatting out of OutputPage into a
a separate ResourceLoaderClientHtml class.

The special handling for 'user' and 'user.styles' modules, and the exempt
module groups was kept in OutputPage. However the handling for it was
hardcoded for the modules in that group by default. It did not account for
modules with a group of 'user' loaded by an extension (e.g. GlobalCssJs).
GlobalCssJs modules were wrongly loaded in the regular style queue
(still in a separate request group, but not in the right cascading order
below the DynamicSyles marker).

This commit generalises the handling previously put in buildExemptModules
and moves it to getRlClient() so that it may apply to all style modules.

This commit should be a no-op besides the moving of any <link rel=stylesheet>
for non-core modules in group 'site' or 'user' now being one line lower
in the <head> HTML (after the DynamicStyles marker).

Bug: T143357
Change-Id: I1d6ea10b42293acfc535578172ad7ab2369f6299
2016-08-18 19:18:29 -07:00
Bartosz Dziewoński
22857ee2fe Revert "Work around T87871 to avoid double-loading OOjs UI PHP styles"
We no longer need this workaround after T87871 was fixed.

This reverts commit e65186c443.

Change-Id: Ieba46fb07e1e92d9a6a86cb84d0ecaf208312baa
2016-08-18 19:01:34 +00:00
Timo Tijhof
4ed96c1dde OutputPage: Apply target and origin filter to exempt modules
Follows-up 80e5b160e, which moved filter logic to getRlClient()
so that ResourceLoaderClientHtml doesn't have to deal with this.

While that worked fine for most modules (including 'site'),
it no longer applied the filter for exempt/hardcoded modules
(such as 'site.styles' and 'startup').

Bug: T143066
Change-Id: Iec924003873bc47484a0dc2f1a215f87aa4afdfb
2016-08-16 15:56:02 -07:00
jenkins-bot
3cfcd55011 Merge "resourceloader: Move queue formatting out of OutputPage" 2016-08-11 14:09:58 +00:00
Timo Tijhof
80e5b160e0 resourceloader: Move queue formatting out of OutputPage
HTML formatting of the queue was distributed over several OutputPage methods.
Each method demanding a snippet of HTML by calling makeResourceLoaderLink()
with a limited amount of information. As such, makeResourceLoaderLink() was
unable to provide the client with the proper state information.

Centralising it also allows it to better reduce duplication in HTML output
and maintain a more accurate state.

Problems fixed by centralising:

1. The 'user' module is special (due to per-user 'version' and 'user' params).
   It is manually requested via script-src. To avoid a separate (and wrong)
   request from something that requires it, we set state=loading directly.
   However, because the module is in the bottom, the old HTML formatter could
   only put state=loading in the bottom also. This sometimes caused a wrong
   request to be fired for modules=user if something in the top queue
   triggered a requirement for it.

2. Since a464d1d4 (T87871) we track states of page-style modules, with purpose
   of allowing dependencies on style modules without risking duplicate loading
   on pages where the styles are loaded already. This didn't work, because the
   state information about page-style modules is output near the stylesheet,
   which is after the script tag with mw.loader.load(). That runs first, and
   mw.loader would still make a duplicate request before it learns the state.

Changes:

* Document reasons for style/script tag order in getHeadHtml (per 09537e83).

* Pass $type from getModuleStyles() to getAllowedModules(). This wasn't needed
  before since a duplicate check in makeResourceLoaderLink() verified the
  origin a second time.

* Declare explicit position 'top' on 'user.options' and 'user.tokens' module.
  Previously, OutputPage hardcoded them in the top. The new formatter doesn't.

* Remove getHeadScripts().
* Remove getInlineHeadScripts().
* Remove getExternalHeadScripts().
* Remove buildCssLinks().
* Remove getScriptsForBottomQueue().

* Change where Skin::setupSkinUserCss() is called. This methods lets the skin
  add modules to the queue. Previously it was called from buildCssLinks(),
  via headElement(), via prepareQuickTemplate(), via OutputPage::output().
  It's now in OutputPage::output() directly (slightly earlier). This is needed
  because prepareQuickTemplate() calls bottomScripts() before headElement().
  And bottomScript() would lazy-initialise the queue and lock it before
  setupSkinUserCss() is called from headElement().
  This makes execution order more predictable instead of being dependent on
  the arbitrary order of data extraction in prepareQuickTemplate (which varies
  from one skin to another).

* Compute isUserModulePreview() and isKnownEmpty() for the 'user' module early
  on so. This avoids wrongful loading and fixes problem 1.

Effective changes in output:

* mw.loader.state() is now before mw.loader.load(). This fixes problem 2.
* mw.loader.state() now sets 'user.options' and 'user.tokens' to "loading".
* mw.loader.state() now sets 'user' (as "loading" or "ready"). Fixes problem 1.

* The <script async src> tag for 'startup' changed position (slightly).
  Previously it was after all inline scripts and stylesheets. It's still after
  all inline scripts and after most stylesheets, but before any user styles.
  Since the queue is now formatted outside OutputPage, it can't inject the
  meta-ResourceLoaderDynamicStyles tag and user-stylesheet hack in the middle
  of existing output. This shouldn't have any noticable impact.

Bug: T87871
Change-Id: I605b8cd1e1fc009b4662a0edbc54d09dd65ee1df
2016-08-08 12:23:09 -07:00
Aaron Schulz
1255654ed5 Show wgPageParseReport on page previews too
Also make EditPage::getPreviewLimitReport return the same
output instead of using copy-pasted code from the old hook.

Bug: T142210
Bug: T142214
Change-Id: I16c3c2da067fd24bf7ae564cb1d61beaa3be58c1
2016-08-05 14:41:47 -07:00
jenkins-bot
5928784f99 Merge "OutputPage: Add addHeadItems() method" 2016-08-04 02:14:01 +00:00
Timo Tijhof
ae762b1157 resourceloader: Separate 'user.styles' module from 'user'
Fixes addModuleStyles() violation from T92459 (a464d1d41).

Similar to 93ed259cf and Id2342454b for the 'site' module.
Doesn't need to be in separate commits since per-user HTML isn't
cached the same way.

Bug: T92459
Bug: T108590
Change-Id: I195f67d061de1306c97413aada7919e9f1b1d12c
2016-08-02 22:07:07 +00:00
Aaron Schulz
28adc4d7ee Only pretty-print the parser report JS vars
Follow-up to b7c4c8717f.

Change-Id: I3030df4ed890d9d20daca31fbd33c6d9db91b94c
2016-07-26 17:16:56 -07:00
Aaron Schulz
b7c4c8717f Move NewPP limit report HTML comments to JS variables
* Instead of having messy code to create a hidden HTML
  comment of English strings at the bottom of the page,
  expose the structured data of the parse information
  to JS so tools can use it.
* Make makeConfigSetScript() use pretty output so these
  variables are also easy to read in "view source".
* Remove ParserLimitReportFormat hook, since the data
  is not formatted to HTML anymore.

Bug: T110763
Change-Id: I2783c46c6d80f828f9ecf5e71fc8f35910454582
2016-07-26 11:31:20 -07:00
Timo Tijhof
3600ad0e5b OutputPage: Add addHeadItems() method
Right now OutputPage requires head items to have a name when using
the addHeadItem() method.

This in contrary to most of the helper methods, which don't require
a name. ParserOutput::addHeadItem() also doesn't require a name.

Since the existing signature isn't easily changed without adding
confusion, add a separate method that allow numerical indexes
to be pushed.

This ability was already exposed via addParserOutputMetadata()
and its array_merge. This method exposes it directly.

Change-Id: I433afd124b57526caa13a540cda48ba2b99a9bde
2016-07-26 00:57:03 +01:00
Timo Tijhof
9093af0a28 Remove modulemessages from ApiParse and Output (deprecated in 1.26)
No uses of 'modulemessages', getModuleMessages() or addModuleMessages()
anywhere in Wikimedia Git.

Change-Id: I59420880f3545d1aabf9bcbea1e34b1475697d26
2016-07-26 00:13:04 +01:00
Timo Tijhof
1b6d9eeaea OutputPage: Remove 'mJQueryDone' property
Left by c27b36277b, unused since 32377424b9.

Change-Id: I475cd40fa83b81b817380e981af0cbdd2e359fd0
2016-07-18 19:28:48 +01:00
jenkins-bot
4d0d2dd136 Merge "Hide marked empty elements by default (stage 1)" 2016-07-14 21:38:56 +00:00
Tim Starling
d3d682fb45 Hide marked empty elements by default (stage 1)
We originally imagined rolling out the display of empty elements
simultaneously with the Html5Depurate, but now we have added support for
marking empty elements to Html5Depurate and plan on having some sort of
longer migration period. So, move the relevant CSS to content.css, and
remove the concept of CSS dependant on tidy driver.

Add a body class which will allow the effect to be toggled in a gadget or
extension. Actual toggling in the CSS will be in the stage 2 patch, to be
deployed after the varnish cache and parser cache have expired.

I originally imagined that there would be a gadget that overrides the
rule with an !important selector, but that method does not allow you to
recover the original display property, which is often overridden by the
style attribute or site CSS to be "inline".

Also, in RaggettWrapper, switch to the new class mw-empty-elt, following
Html5Depurate, instead of mw-empty-li. The old class will be removed in
the stage 2 patch.

Change-Id: Ic0f432c43a006629ca5a1a7c2dda3552ceb4dc4f
2016-07-14 14:24:27 -07:00
Timo Tijhof
a464d1d41d resourceloader: Track state of page-style modules
This allows dynamically loaded modules to depend on page-style modules
without it causing the page-style module to be loaded a second time.

* New method Module::getType() indicates whether a module is
  a page-style module or supposed to be dynamically loaded.

* Emit warning from addModuleStyles() when given a module that is
  not a page-style module (to be enforced later)

Bug: T92459
Bug: T87871
Change-Id: I8b6c6a10d965e73965f877c42e995d04202524f3
2016-07-14 20:28:40 +01:00
Timo Tijhof
7f26cff2cc OutputPage: Make use of WrappedStringList in headElement()
Right now, getInlineHeadScripts(), buildCssLinks() and getExternalHeadScripts()
all return WrappedString::join(). But because they don't know about each other
and because they need to return strings (not arrays), headElement() has no way
of merging them.

WrappedStringList allows this array to be kept, whilst still being backward-compatible
with code that calls these methods and assumig a string (since it will lazy-join
the array if the object is treated like a string).

To be used by I8b6c6a10d965e7396. Output is not changed in this commit.
Merely refactoring.

Change-Id: Iae08345473bd93cc0948d51b62c48aeb1ea460a3
2016-07-12 18:56:48 +00:00
Timo Tijhof
46df493ac0 Remove incomplete and dated 'wgUseETag' experiment
Follows-up:
* 8ff36ebd (r9793) Set ETag header on article views.
* 8167b89e (r16205) Add $wgUseETag, false by default (broke Squid; T9098).

ETag is a useful alternative for If-Modified-Since (see T33639, T49529 about
use cases and bugs it may fix). However the current incomplete implementation
isn't useful.

It's a feature flag that has been disabled since 2006. Enabling it stores
ParserCache::getETag in OutputPage and sends it out as a response header.
It's ignored on incoming requests. We don't check If-None-Match for
'304 Not Modified' anywhere.

ResourceLoader has a working implementation that could be leveraged.

To be re-evaluated in the future. ParserCache::getETag() could use
improvement as well.

Change-Id: I37fd9d0ce1ce9bffb79243c6ae340403fdfd769f
2016-06-27 12:43:54 +00:00
Timo Tijhof
c20a76ee0a Restore load position override for 'site.styles' module
Follows-up 93ed259 which changed the module to be 'site.styles', but
the override was still looking for a module called 'site' (which isn't
listed in that queue anymore).

Bug: T138586
Change-Id: I3052a2e378f804d0d4d117f8ed446fe9b4b59f99
2016-06-24 21:43:11 +00:00
Timo Tijhof
93ed259cf3 resourceloader: Create 'site.styles' module
First step in migration for 'site' module per T92459.

Bug: T92459
Change-Id: Ic137cb494ba238facba4033f9c68a35e64f4916c
2016-06-15 23:06:50 -07:00
Kunal Mehta
c704ec36c8 Use LinkCache::getSelectFields() in OutputPage::addCategoryLinks()
Change-Id: I71d95cbb6c22ae92586c883e7de5353d26c4838f
2016-06-07 16:37:27 -07:00
Timo Tijhof
06ab9c0942 resourceloader: Merge 'user.groups' into 'user' module
This is with T92459 in mind to simplify the process of splitting
the 'user' module for the styles-only queue.

Consequences:

* Cached HTML isn't relevant in practice since there is no caching for logged-in
  users and this module is only for logged-in users. Even then, cached HTML will
  work and may happen as browsers re-use HTML responses when revisiting a
  privately cached page (after 304 Not Modified).
  Note that OutputPage (via isKnownEmpty) only actually tries to load 'user.groups'
  if the wiki has 'MediaWiki:Group-*.{js,css}' pages for the current user's groups.

  - Old style queue request will continue to ask for user.groups which is now a
    FileModule with no styles (simply concats the empty string to the bundle)
  - Old load() request will resolve with an empty function.

* The are no known dependants of 'user.groups'. If there are, they will work
  by proxy of it now being an empty module that just ensures 'user' is loaded.

* The security origin of 'user.groups' was USER_SITEWIDE. The origin of 'user'
  is lower (USER_INDIVIDUAL). Pages that are restricted to USER_SITEWIDE
  previously received user.groups, but won't anymore. This should be fine as
  OutputPage::reduceAllowedModules() is mainly used to either allow everything
  or restrict all the way down to CORE. The only exception is disallowUserJs()
  if $wgAllowSiteCSSOnRestrictedPages is enabled (T73621) but that edge case was
  made for Common.css, not Group-*.css.

Change-Id: I74cd2368ebd2989c5e1c22bea491a80beb0319dc
2016-05-26 04:15:33 +00:00
Brad Jorsch
af3b10287e SECURITY: RawAction: Vary on the usual headers
This avoids edge cases where the user isn't logged in but we still need
varying for proper cache behavior.

Bug: T125283
Change-Id: I43cde3a48371e62a16bda1291b1b51986e60fe4c

Signed-off-by: Chad Horohoe <chadh@wikimedia.org>
2016-05-20 09:48:26 -07:00
Roan Kattouw
6ce974f95f Pass the OutputPage object to the OutputPageCheckLastModified hook
So that the hook function has a ContextSource.

Change-Id: I044a5920b703a2d61a74c2d83d184b77caebb8f3
2016-05-10 21:11:33 -07:00
jenkins-bot
a00cef7d9f Merge "Avoid double-rendering on late exceptions" 2016-03-29 22:31:00 +00:00
Ori Livneh
5360a3497f Provide a unique request identifier
When MediaWiki encounters an unhandled exception, the error message it produces
includes a randomly-generated token, which allows the exception details to be
looked up in the error logs. This is useful but narrow: would it not be useful
to have the ability to retrieve all log records associated with a particular
request, rather than just exception details? (Hint: yes.)

So: introduce the notion of a request-global unique ID, retrievable via
WebRequest::getRequestId(). When MediaWiki is behind Apache + mod_unique_id
(which provides the same facility) or some other software which sets a
UNIQUE_ID envvar, the value of that envvar is used as the request ID.
Otherwise, it is a randomly-generated 24-character string.

The request ID supplants exception-specific IDs; MWExceptionHandler::getLogId()
is deprecated, accordingly. The request ID is also added as an annotation to
all Monolog-processed log records, and is exposed client-side as 'wgRequestId'.
This allows developers to associate a page view with log records even when the
page view does not result in an unhandled exception. (For the WMF, I also
intend to add it as an annotation to profiling data).

The request ID is not a tracking token; it does not persist, and it is
associated with a backend request, not with a particular user or a particular
session. Like the data in the NewPP report, the request ID is designed to be
cacheable, so that if, for example, a developer notices something weird in the
HTML, s/he can associate the output with a backend request regardless of
whether the response was served from the cache or directly from the backend.

Some prior art:
* https://httpd.apache.org/docs/2.4/mod/mod_unique_id.html
* http://api.rubyonrails.org/classes/ActionDispatch/RequestId.html
* https://github.com/dabapps/django-log-request-id
* https://packagist.org/packages/php-middleware/request-id
* https://github.com/rhyselsmore/flask-request-id

Change-Id: Iaf90c20c330e0470b9b98627a0228cadefd301d1
2016-03-25 16:09:05 +00:00
Timo Tijhof
dd2d7d0ffc OutputPage: Minor clean up of <head> and HTML
* Remove trailing space in self-closing tag.
  Brings parserTest output of Parser and Parsoid closer together.

* Remove various line breaks at begin and end of script contents.

* Remove FILTER_NOMIN from makeConfigSetScript() output.
  This isn't part of any user- or page-dependent module and not minified.
  And Xml::encodeJsCall already ensures compact output for prod mode.

Bug: T127328
Change-Id: I85a5a59fd0955c1a112e8b24b933f0d9e983a156
2016-03-24 03:24:31 +00:00
Reedy
b5656b6953 Many more function case mismatches
Change-Id: I5d3a5eb8adea1ecbf136415bb9fd7a162633ccca
2016-03-19 00:20:58 +00:00
Aaron Schulz
4d673afd75 Avoid double-rendering on late exceptions
Bug: T129657
Change-Id: I86af834b842bc056b57b2a55a9e1385481d5781d
2016-03-18 12:11:45 -07:00
jenkins-bot
989feebb73 Merge "OutputPage: Set wgPageContentLanguage to pageViewLang instead of pageLang" 2016-03-11 08:45:15 +00:00
Timo Tijhof
44725333ff OutputPage: Set wgPageContentLanguage to pageViewLang instead of pageLang
Follows-up 80a090ea7 (r104483).

I'm assuming the difference is that pageLanguage will be the canonical variant
for the page (as authored in wikitext, presumably the wiki's default), whereas
pageViewLanguage will be the variant of the pageLanguage based on the current
user-interface language (if and only if the user interface is related).

Viewing zh by default has:
* userLanguage: zh
* pageLanguage: zh
* pageViewLanguage: zh

Viewing zh-cn by default has:
* userLanguage: zh
* pageLanguage: zh
* pageViewLanguage: zh-cn

Viewing zh-cn with uselang=en has:
* userLanguage: en
* pageLanguage: zh
* pageViewLanguage: zh-cn

Viewing zh-cn with uselang=zh-tw has:
* userLanguage: zh-tw
* pageLanguage: zh
* pageViewLanguage: zh-cn

The main use case behind wgPageContentLanguage in 80a090ea7 was tablesorter
which should match the language and variant of the rendered wikipage content.

The parser output and div#mw-content-text element use pageViewLanguage, so
let's set wgPageContentLanguage to that as well.

Change-Id: Ibf399dfe5ca60fb55e7acd75a5c0238d8b903807
2016-03-11 09:35:41 +01:00
Siebrand Mazeland
4c619be17b OutputPage::out() was removed
Deprecated since 1.22. Six use remain in Gerrit extension
SemanticPageMaker, that's been unmaintained since MediaWiki 1.17. They
were not replaced.

Change-Id: I8d68657562f683a4933cc5321d5df04c80cdfc29
2016-03-08 23:55:39 +01:00
Siebrand Mazeland
07e48ac5e8 OutputPage::setAllowedModules() was removed
Deprecated since 1.24. No uses in core or Gerrit extensions remaining.

Change-Id: I58af2d94f31a3d5eecc21dab2813d4f27789b511
2016-03-08 23:46:53 +01:00
Siebrand Mazeland
7fbae3d18b OutputPage::getHeadItems() was removed
Deprecated since 1.24. No uses in core or extensions remaining.

Change-Id: Ic038a287dab00468b08f41f31b0c8aedffc03c64
2016-03-08 23:45:36 +01:00
Siebrand Mazeland
b7a4ad1ddc OutputPage::getScript() was removed
Deprecated since 1.24. One use remains in Gerrit extension
SemanticPageMaker, that's been unmaintained since MediaWiki 1.17. It was
not replaced.

Change-Id: I50afa8217e7bf1b47aef3951ef2ee7295d6db21e
2016-03-08 23:41:17 +01:00
Siebrand Mazeland
5b119a0e44 Replace uses of join() by implode()
All of core uses implode() consistently now.

Change-Id: Iba50898c64c43f356d1caf8869f484e90d9ff651
2016-03-08 18:24:16 +00:00
Bryan Davis
8b413431d7 Guard against allowing intermediate caching when cookies are present
Output cache-control headers that disable intermediate caching even if
OutputPage->mEnableClientCache is true when the response includes
set-cookie headers as well. This change mirrors logic that has been in
use on the Wikimedia Foundation production cluster's Varnish cache
system for over 2 years to guard against accidentally caching backend
responses which include Set-Cookie headers.

Co-Author: Max Semenik <maxsem.wiki@gmail.com>
Bug: T127993
Change-Id: I1a0d38a5b9dba754b91a7832371b3dc0df51bd5a
2016-02-29 15:29:58 -07:00
Tim Starling
a2530a9fb8 Fix resource path check when ResourceBasePath is an empty string
If you have MediaWiki installed in the root of the domain, then
$wgScriptPath and $wgResourceBasePath is an empty string. In HHVM and
PHP, passing an empty string as the second parameter of strpos() causes
a warning and returns false, which will cause the condition to fail, as
if the path were not within the base path.

So, normalize such paths. Using substr() instead of strpos() for a
"starts with" check would have worked except that RelPath also fails
when given an empty string.

Bug: T127652
Change-Id: If7e94ae638d6834f7cc0f31f67a5fe6a2f74771c
2016-02-23 09:19:26 +11: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
Florian
d237380021 Fix not-loaded DbPageLanguage when Title::getPageLanguage() get's called
If the Title object isn't the title of the current viewed WikiPage, the page_lang
field of the database isn't requested. This results in the problem, that
Title::getPageLanguage() always returns the default content language, even if
the page language is different (changed with Special:PageLanguage, if
wgPageLanguageUseDB is true). That is problematic for the Translate extension,
which relies on the correct page language.

This change makes sure, that getPageLanguage() always return the correct page
language. If the page language isn't loaded already, Title::getPageLanguage()
now does a database lookup (if $wgPageLanguageUseDB is true) to get the correct
page language. It will use LinkCache for the page_lang field.

Bug: T121666
Change-Id: I0ae5ea39f7a124ed427ca5dfb26c1a116b27a94e
2016-02-16 20:37:40 +00:00
jenkins-bot
afa2e1e660 Merge "OutputPage.php: Remove misleading comment" 2016-02-11 04:06:13 +00:00
jenkins-bot
42fe7284cd Merge "Work around T87871 to avoid double-loading OOjs UI PHP styles" 2016-02-11 03:51:16 +00:00
Brad Jorsch
b435e659b5 OutputPage: Don't get a ParserOptions for $wgUser before the end of Setup.php
Until Setup.php completes, we can't access the "current" user and
trying to do so logs a warning. So don't try.

Bug: T124367
Change-Id: I1acc82760c368a24448f3c90e268b24414e43a30
2016-02-08 13:17:37 -05:00
Fomafix
ebf7d58258 OutputPage.php: Remove misleading comment
The whole comment was added in fc359e16f1 together with a strtolower().
In dcd44cdf7d the strtolower() and a part of the comment was removed.
The rest of the comment makes no sense without a strtolower().

Change-Id: Ifa0d88a618e31f4a558bc93a098aabad35761569
2016-02-06 16:30:30 +00:00
Bartosz Dziewoński
e65186c443 Work around T87871 to avoid double-loading OOjs UI PHP styles
Use a <meta> tag added when enabling OOUI, and a skipFunction that
looks for it, to avoid double-loading the modules: oojs-ui.styles,
oojs-ui.styles.icons, oojs-ui.styles.indicators, oojs-ui.styles.textures.

This saves us loading of around 200K of CSS (20K when gzipped) on pages
that both use OOjs UI PHP server-side and load OOjs UI client-side.
(For example, all MediaWiki special pages using OOUIHTMLForm.)

Interesting caveat: this causes the aforementioned modules to no
longer appear in the output of `mw.loader.inspect()` on such pages.

Bug: T125292
Change-Id: Ia7e2256cd239841e1f78c4a6bf666dd939c0d2c7
2016-02-03 23:47:14 +01:00
Brad Jorsch
2257fe4228 Revert "Remove SessionManager, temporarily"
This reverts commit 823db5d63dd5200d04c63da50ba6bf16f928e70b.

Change-Id: Ibb3e023e4eb6715295586dea87d0725c344a8271
2016-02-03 21:44:59 +00:00
Bartosz Dziewoński
1f49b66c6f resources: Load OOjs UI from its four parts
See the task for more details. This is a backwards-compatible change.
If your script only needs a subset of OOjs UI functionality, you can
use one of the new smaller modules instead of the old big one.

New modules:
  oojs-ui-core
    The core JavaScript library.
  oojs-ui-widgets
    Additional widgets and layouts module.
  oojs-ui-toolbars
    Toolbar and tools module.
  oojs-ui-windows
    Windows and dialogs module.

Changed modules:
  oojs-ui.styles
    Now correctly only loads the styles needed by OOjs UI PHP.
  oojs-ui
    Now just loads core+widgets+toolbars+windows as dependencies.

Using the new modules in I58799e22f9c0a2f78c1b4a02c4b7af576157883a.

Bug: T113677
Change-Id: I0a3bf8fb25fb82325705a473cebd883e20b3ab8d
2016-02-03 19:27:12 +00:00
Timo Tijhof
419db58c8b Centralise url handling for urls to static resources
Keep in CSSMin as-is for back-compat and to ensure library remains
independent of MediaWiki.

Moved down a few lines as there is no need to compute the md5 hash when we're
returning a data URI. Previously md5_file was called twice during module builds
(once for the fallback url, and another time when producing the embedded data uri).

Applied to logo in SkinModule as example. To be applied elsewhere as needed.
Without it, fallback is current behaviour (no cache invalidation).

Bug: T99096
Change-Id: I7f38bfc1bea5c241bc4f8ec4f4b640fd65f2c04f
2016-02-02 23:26:16 +00:00
Brad Jorsch
5083e810eb Remove SessionManager, temporarily
The plan here is to take it out of 1.27.0-wmf.12 and put it back in
1.27.0-wmf.13.

Since BotPasswords depends on SessionManager, that's getting temporarily
removed too.

This reverts the following commits:
* 6acd424e0d SessionManager: Notify AuthPlugin before calling hooks
* 4d1ad32d8a Close a loophole in CookieSessionProvider
* fcdd643a46 SessionManager: Don't save non-persisted sessions to backend storage
* 058aec4c76 MessageCache: Don't get a ParserOptions for $wgUser before the end of Setup.php
* b5c0c03bb7 SessionManager: Save user name to metadata even if the user doesn't exist locally
* 13f2f09a19 SECURITY: Fix User::setToken() call on User::newSystemUser
* 305bc75b27 SessionManager: Don't generate user tokens when checking the tokens
* 7c4bd85d21 RequestContext::exportSession() should only export persisted session IDs
* 296ccfd4a9 SessionManager: Save 'persisted' flag in session metadata
* 94ba53f677 Move CSRF token handling into MediaWiki\Session\Session
* 46a565d6b0 Avoid false "added in both Session and $_SESSION" when value is null
* c00d0b5d94 Log backtrace for "User::loadFromSession called before the end of Setup.php"
* 4eeff5b559 Use $wgSecureCookie to decide whether to actually mark secure cookies as 'secure'
* 7491b52f70 Call session_cache_limiter() before starting a session
* 2c34aeea72 SessionManager: Abstract forceHTTPS cookie setting
* 9aa53627a5 Ignore auth cookies with value 'deleted'
* 43f904b51a SessionManager: Kill getPersistedSessionId()
* 50c5256352 SessionManager: Add SessionBackend::setProviderMetadata()
* f640d40315 SessionManager: Notify AuthPlugin when auto-creating accounts
* 70b05d1ac1 Add checks of $wgEnableBotPasswords in more places
* bfed32eb78 Do not raise a PHP warning when session write fails
* 722a7331ad Only check LoggedOut timestamp on the user loaded from session
* 4f5057b84b SessionManager: Change behavior of getSessionById()
* 66e82e614e Fix typo in [[MediaWiki:Botpasswords-editexisting/en]]
* f9fd9516d9 Add "bot passwords"
* d7716f1df0 Add missing argument for wfDebugLog
* a73c5b7395 Add SessionManager

Change-Id: I2389a8133e25ab929e9f27f41fa9a05df8147a50
2016-02-01 22:06:49 +00:00
Brad Jorsch
a73c5b7395 Add SessionManager
SessionManager is a general-purpose session management framework, rather
than the cookie-based sessions that PHP wants to provide us.

While fallback is provided for using $_SESSION and other PHP session
management functions, they should be avoided in favor of using
SessionManager directly.

For proof-of-concept extensions, see OAuth change Ib40b221 and
CentralAuth change I27ccabdb.

Bug: T111296
Change-Id: Ic1ffea74f3ccc8f93c8a23b795ecab6f06abca72
2016-01-12 21:57:01 +00:00
Florian
01caf147b6 Remove not used private member variable mParserWarnings from OutputPage
Change-Id: I2ccc96671a2ae9c10235da19a4341aa6c30f841e
2016-01-03 01:57:59 +01:00
Reedy
c27b36277b Removed OutputPage::includeJQuery()
All callers use method_exists() to call it

Then include ancient jquery themselves...

Change-Id: I7e270abc7b052156ed1e1793269595a647797526
2016-01-02 19:38:50 +00:00
Reedy
7c9b049d3f OutputPage::blockedPage() was removed
Change-Id: Ie25b69e14155869ff0374a49f1ec3806f026da9d
2016-01-02 19:19:08 +00:00
Reedy
dc0dd31776 OutputPage::permissionRequired() was removed
Change-Id: I9ff1d601cf5fc3402f22bdaf829ae2e287652d31
2016-01-02 17:34:22 +00:00
Bryan Davis
0affda7edf Remove use of $dest = 'log' for wfDebugLog
The functionality for marking a debug log message for delivery to a log
file but not to MWDebug was removed in 1.25 with the introduction of
the PSR-3 logging system. Convert the messages that were marked for this
special handling in a7a0883 to use 'private' instead.

Bug: T122644
Change-Id: Iefaac07a5922c16c2899904c7b678199c5b1efe9
2015-12-30 13:03:14 -07:00
Florian
eb343c847f Add a new hook AfterBuildFeedLinks to manipulate feed links
Some extensions may want to replace, remove or manipulate a specific
feed link after it was build. For this purpose: Add a new hook to enable
this. The hook isn't meant for adding new feed links, this is already
easily possible using OutputPage::addFeedLink().

Bug: T121774
Change-Id: If48bd07a0e7e67fd1c1a94ebaa28ca9dae146c55
2015-12-18 20:09:34 +01:00
Ori Livneh
4e0762c70a Remove OutputPage::loginToUse(): deprecated since 1.19 & unused
* https://github.com/search?utf8=%E2%9C%93&q=%40wikimedia+logintouse&type=Code&ref=searchresults

Change-Id: I5bdef4b518cd66a2b195aeb443e66136a06f816a
2015-12-15 11:13:12 -08:00
Ori Livneh
827d8dc028 Remove OutputPage::appendSubtitle(); deprecated since 1.19 & unused
* https://github.com/search?q=%40wikimedia+appendSubtitle&type=Code&utf8=%E2%9C%93

Change-Id: Ic09479cf04f00cf1f8764efe747edacd6aa2140d
2015-12-15 11:13:12 -08:00
Albert221
f1d8e12c50 Resolve code invoking Title::newFromURL
Bug: T65424
Change-Id: I6c97245faccd8b34557eb3be4150867fd9b37992
2015-12-12 12:00:37 +01:00
Aaron Schulz
6af3c39c07 Replace "squid" with "CDN" in various comments
Change-Id: Idcc528daf28e119349155d36e30a9bcf61b2e7d5
2015-12-09 17:35:37 -08:00
Aaron Schulz
f606fd8d5c Rename setSquidMaxage() => setCdnMaxage()
Also updated the OutputPage member variable.

Change-Id: I0b41c66da58c6126c1bd96170c02d084a067383c
2015-12-09 17:11:23 -08:00
addshore
9992e6adb3 Cast numeric cat names back to string in api output
This could be considered a breaking change even
though it unifies behaviour.

Change-Id: Ib6bc7386f689cc6c2812e9e9406f18b20caa8fee
2015-12-03 15:15:59 +01:00
Roan Kattouw
710b532d5a Don't "preview" (i.e. execute) user JS on non-preview requests
If you edit your user JS page, change the JS, and click Show preview,
the new JS will be loaded ("previewed"). However, this "preview"
is also engaged when you click Show changes, or click "Save page"
and fail to save. Don't do that: only "preview" JS when the user
has actually chosen to preview it.

Change-Id: Id9bcd235d3414b68de6e5d491b7b0c4f9b16e05f
2015-11-14 17:28:25 -08:00
Derk-Jan Hartman
d51d228c55 OutputPage: documentation for (semi-)deprecated methods
Deprecated: addExtensionStyle, getExtStyle
These had been deprecated unofficially for a while now. ResourceLoader
is preferred.

Internal/Unpreferred: addHeadItem, addScript, addScriptFile,
addInlineScript, addStyle, addInlineStyle.
All should be used as littel as possible, in favor of ResourceLoader
and a few other higher level accessors. They are not truly deprecated,
but should not really be used unless you have a really good reason.

Also added a few missing wfDeprecated calls to methods marked as
deprecated in the phpdoc.

Bug: T89955
Change-Id: I472d906b6de16257fa34a2f9bfe9e4eb284d02b4
2015-11-01 01:43:03 +01:00
Timo Tijhof
afcfc3290c resourceloader: Consistently refer to the framework as ResourceLoader
Change-Id: Ia59e4eac9662723e80d62f7cfcb9e4292e3ee4de
2015-10-28 03:24:40 +00:00
Timo Tijhof
9435cd81b0 resoureloader: Consolidate styles-only queue at the top
This effectively reverts d6b4d3c537 and declines T97420.
This was previously attempted in b7c0e537eb.

Drop support for position "bottom" for addModuleStyles().
This feature was only recently introduced with the intent
to optimise page load performance, but had an adverse effect.

It increases chances of FOUC due to late discovery of these styles.
It also caused minor problems for some gadgets and extensions
that did not or were unable to set these flags. Some mobile
code was introduced around the same time as this feature and
was never given position=top.

Stylesheets that don't affect initial render or are only needed
on interaction should be loaded via addModules() instead; which
is handled by the asynchronous loader in JavaScript.

Change-Id: Ib9821b7b87cfc8a59062bb6ca358974fdb01ced1
2015-10-27 03:39:34 +00:00
umherirrender
2320f5cfe2 Change some line comments to multi line comments
This allows empty lines inside the comment as found by the
MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.EmptyComment sniff

Change-Id: Iac155bbda4a84562db2b452baeae9b8973899453
2015-10-14 09:40:50 +02:00
Kunal Mehta
c48d88e7b9 OutputPage: Fix typo in documentation
Change-Id: If89f249de3049eb37c261a7417910637b7464961
2015-10-10 11:52:58 -04:00
Aaron Schulz
25c23331e3 Fix broken min() call in OutputPage
Change-Id: Ia2d895371f6f114c1cb821dd1d2aaaef7935033f
2015-10-10 03:56:12 +00:00
Ori Livneh
a69eac16aa Small clean-ups for OutputPage::userCanPreview
Change-Id: Ibd973750b60cbcc8d1289686de6cabcfdca5c5d9
2015-10-07 23:04:59 -07:00
Ori Livneh
15adbabc3a Fix-up for I949fc289d: handle falsy cookie values correctly
Ensure that OutputPage::haveVaryCacheCookies() handles falsey values correctly,
and that it requires a cookie to have a nonempty value before it declares a
match.

Change-Id: I2afe54b62c940187a427498cb4037e1dd0e78dd9
2015-10-07 22:19:47 -07: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
Aaron Schulz
c7b932af6b Lower CDN cache TTL when slave lag is high
* $wgCdnMaxageLagged controls exactly what that TTL is
  and the usual "max lag" settings determine what "high"
  is for lag (which already makes the site read-only).
* This helps avoids stale content getting stuck in CDN
  for a month just because a slave was lagged for a minute.
  Of course race conditions with normal slave lag and WAN
  cache relay purges can still lead to this problem, though
  the scope of it is reduced.

Bug: T113204
Change-Id: I7ff0a8d88665f4e557566e7b412e75edee2627fe
2015-10-06 18:49:49 -07:00
Amir E. Aharoni
a0f33b188a Make lines short to pass phpcs in OutputPage.php
Bug: T102614
Change-Id: I5528fdbcf3d0a4832db1a94ced3d282fcf3e901f
2015-09-27 14:39:32 +00:00
umherirrender
c572d18661 Fixed spacing
- Removed space after cast
- Removed spaces in array index
- Removed double spaces
- Added spaces around string concat
- Fixed mixed tabs and spaces at begin of line

Change-Id: I38e849723f055d2d4c05cba72f5c245a28e8d5da
2015-09-26 20:44:54 +00:00
jenkins-bot
69e3367224 Merge "Revert "Load 'mediawiki.legacy.commonPrint' styles with a media type property"" 2015-09-10 18:13:07 +00:00
Bartosz Dziewoński
b75017e32c Revert "Load 'mediawiki.legacy.commonPrint' styles with a media type property"
Nested media queries are not allowed in CSS 2 and not supported
in older browsers.

This reverts commit 11e47561e4.

Bug: T108727
Change-Id: Ibef40e79a5d5e229df8f874b7dea5b590f3f7320
2015-09-10 17:58:58 +00:00
Gergő Tisza
6af306afa8 Rewrite OutputPage::addVaryHeader
Rewrite OutputPage::addVaryHeader which had a very confusing
structure.

There is one breaking change: the $option argument was declared
as array|null, but the function accepted everything and showed
inconsistent behavior; e.g.

    $op->addVaryHeader( 'Foo', 'bar' )

resulted in 'X-Vary-Options: Foo;bar' but

    $op->addVaryHeader( 'Foo' )
    $op->addVaryHeader( 'Foo', 'bar' )

resulted in 'X-Vary-Options: Foo'. With the patch, non-array
arguments (other than null) result in an error.

Change-Id: Id31d95fe27b01b00ec8a1d7a3996275fc0aacf3c
2015-09-09 15:01:45 -07:00
jenkins-bot
150651197b Merge "Document OutputPage::addVaryHeader()" 2015-09-08 21:08:23 +00:00
Brad Jorsch
242ca95565 Document OutputPage::addVaryHeader()
The $options parameter to OutputPage::addVaryHeader() is undocumented as
to what exactly is supposed to be passed to it. Fix that.

Change-Id: I5fcbb8cf6219c6ab001962a4c2170e1733732426
2015-09-08 16:33:56 -04:00
jeroendedauw
6a8c834206 Remove unused private field in OutputPage
Change-Id: I5d70886d67d4c1b2a3a176eace2fd545ca842aa3
2015-09-07 21:44:57 +02:00
jenkins-bot
f27c7c3a2e Merge "Revert "Load all CSS in the top queue"" 2015-08-27 17:54:35 +00:00