Commit graph

78 commits

Author SHA1 Message Date
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
Timo Tijhof
d6adb2a6e1 HTMLFileCache: Remove @throws for unchecked exception
While at it, move the array to a constant.

Bug: T321683
Change-Id: I46db0f4b01711ff7304918708efb7776300bbcc8
2023-07-24 05:08:58 +01:00
Umherirrender
e04d3a28f6 Replace internal Hooks::runner
The Hooks class contains deprecated functions and the whole class is
going to get removed, so remove the convenience function and inline the
code.

Bug: T335536
Change-Id: I8ef3468a64a0199996f26ef293543fcacdf2797f
2023-05-11 06:17:38 +00:00
Platonides
42fbc845b7 FileCache: Allow ?uselang= to utilize cache if set to content language
Previously the mere presence of uselang made it disable the FileCache,
even though requesting the wiki content language is equivalent
to not providing it at all.

The requested language being the content one is already checked
in lines 124-138.

This used to work but was broken with the 2008 refactoring of
isFileCacheable() in e29274ca (r41274).

Change-Id: I01320d36a3b31b7a69025d845b61d9eb05e9fca3
2022-09-07 16:35:19 +00:00
Umherirrender
49ad716948 Use User::isRegistered for readability instead of ::getId falsy check
Change-Id: I42aab149559e3e899cde6c77af76c66936ed0ef0
2022-04-29 21:15:57 +02:00
Aryeh Gregor
7b791474a5 Use MainConfigNames instead of string literals, #4
Now largely automated:

VARS=$(grep -o "'[A-Za-z0-9_]*'" includes/MainConfigNames.php | \
  tr "\n" '|' | sed "s/|$/\n/;s/'//g")
sed -i -E "s/'($VARS)'/MainConfigNames::\1/g" \
  $(grep -ERIl "'($VARS)'" includes/)

Then git add -p with lots of error-prone manual checking. Then
semi-manually add all the necessary "use" lines:

vim $(grep -L 'use MediaWiki\\MainConfigNames;' \
  $(git diff --cached --name-only --diff-filter=M HEAD^))

I didn't bother fixing lines that were over 100 characters unless they
were over 120 and triggered phpcs.

Bug: T305805
Change-Id: I74e0ab511abecb276717ad4276a124760a268147
2022-04-26 19:03:37 +03:00
Derick Alangi
d371cd942d
cache: Introduce member to expose service options for configs
There are some static methods in sub-classes of FileCacheBase
that use the service locator to get the main config object
which maybe I think we can just use DI in the methods to
pass this from the calling code.

That could be in a follow-up patch, for now, we can leave
things as they are here?

Change-Id: Ic75e1e5f867faee7fc71c34552f9f0a7a124d7ae
2022-04-13 20:17:30 +01:00
Siddharth VP
061ee25f7e Fix typos in comments (E-H)
Change-Id: I0748e0d5962fa909fdd6b7fcae4ab259bde4cdf1
2021-12-30 18:14:43 +05:30
daniel
185d535457 HTMLFileCache: replace Title in method signatures
Bug: T278459
Change-Id: I77fb37c1aec17d3e51056f85fdff59821f326cc3
2021-04-14 18:49:45 +02: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
Tim Starling
68c433bd23 Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.

General principles:
* Use DI if it is already used. We're not changing the way state is
  managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
  is a service, it's a more generic interface, it is the only
  thing that provides isRegistered() which is needed in some cases,
  and a HookRunner can be efficiently constructed from it
  (confirmed by benchmark). Because HookContainer is needed
  for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
  SpecialPage and ApiBase have getHookContainer() and getHookRunner()
  methods in the base class, and classes that extend that base class
  are not expected to know or care where the base class gets its
  HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
  getHookRunner() methods, getting them from the global service
  container. The point of this is to ease migration to DI by ensuring
  that call sites ask their local friendly base class rather than
  getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
  methods did not seem warranted, there is a private HookRunner property
  which is accessed directly. Very rarely (two cases), there is a
  protected property, for consistency with code that conventionally
  assumes protected=private, but in cases where the class might actually
  be overridden, a protected accessor is preferred over a protected
  property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
  global code. In a few cases it was used for objects with broken
  construction schemes, out of horror or laziness.

Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore

Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router

setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine

Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-05-30 14:23:28 +00:00
jenkins-bot
fedbf6ba82 Merge "Use new TalkPageNotificationManager" 2020-05-20 19:21:52 +00:00
Reedy
b1e515e36e Fix even more PSR12.Properties.ConstantVisibility.NotFound
Change-Id: I4a30a44bc33fc98479799438d65342f6529e14f9
2020-05-16 00:51:46 +01:00
Clara Andrew-Wani
b3a5c7c0d5 Use new TalkPageNotificationManager
Bug: T239640
Change-Id: I7c06d145854ab39faaef528e169f6b51de1c8d99
2020-05-15 12:35:45 -04:00
Reedy
12a3883a7b Fix SingleSpaceBeforeSingleLineComment
Change-Id: I285af438ce484af40741489797f20455726ec110
2020-05-11 00:57:11 +00:00
Ed Sanders
387f3c2a20 Fix typo: 'the the' -> 'the'
Change-Id: Ia57fb787b43c8e49da4f33a65c265cbc37ee1f77
2020-05-03 20:45:36 +01:00
Aaron Schulz
3c7f29a6b9 Add small HtmlCacheUpdater service class to normalize purging code (2)
This is a re-submit of 35da1bbd7c, which was accidentally merged before
CR (and reverted with aa4da3c2e8).

The purge() method handles purging of both file cache and CDN, using
a PRESEND deferred update. This avoids code duplication and missing
file cache purge calls.

Also:
* Migrate HTMLCacheUpdate callers to just directly using HTMLCacheUpdateJob
* Add HtmlFileCacheUpdate class and defer such updates just like with CDN
* Simplify HTMLCacheUpdate constructor parameters
* Remove BacklinkCache::clear() calls which do nothing since the backlink
  query does not actually happen until the job runs

Bug: T230025
Change-Id: Ic1005e70e2c22d5bd1ca36dcdb618108ebe290f3
2020-04-14 03:19:07 +00:00
Timo Tijhof
d18e76dbef Setup: Move MWDebug logic to MWDebug.php
* Remove checks in HTMLFileCache.php and Article.php.

  These haven't been needed since the same check was added to Setup.php,
  many years ago. When FileCache is enabled, The Setup.php code disables
  MWDebug. There is no reason for FileCache to then also disable itself
  based on unused config. That means both of them lose.
  We now handle this logic in one place: MWDebug::setup().

* In rebuildFileCache.php, turn it off explicitly, just in case.
  The previous code there didn't work because finalSetup()
  is called after doMaintenance.php includes Setup.php, which
  is what checked this config var to decide on MWDebug::init.
  On the other hand, it's also always off in CLI mode.
  But, let's not depend on that, maybe we decide to enable it on
  CLI one day! Just keep it off explicitly here.

Bug: T189966
Change-Id: I45a8f77092249751dc6f276aa5bb67ebf5b4f64c
2019-09-04 16:33:25 +00:00
Daniel Kinzler
aa4da3c2e8 Revert "Add small HtmlCacheUpdater service class to normalize purging code"
This reverts commit 35da1bbd7c.

Reason for revert: wrong tab, wrong patch. Ooops.

Change-Id: I5828fff6308d43460a3b2b10f60996409181f8b3
2019-08-07 13:56:30 +00:00
Aaron Schulz
35da1bbd7c Add small HtmlCacheUpdater service class to normalize purging code
The purge() method handles purging of both file cache and CDN, using
a PRESEND deferred update. This avoids code duplication and missing
file cache purge calls.

Also:
* Migrate HTMLCacheUpdate callers to just directly using HTMLCacheUpdateJob
* Add HtmlFileCacheUpdate class and defer such updates just like with CDN
* Simplify HTMLCacheUpdate constructor parameters
* Remove BacklinkCache::clear() calls which do nothing since the backlink
  query does not actually happen until the job runs

Change-Id: Ic453b189a40109a73a9426538608eea87a76befa
2019-08-06 13:45:27 -07:00
Reedy
c13fee87d4 Collapse some nested if statements
Change-Id: I9a97325d738d09370d29d35d5254bc0dadc57ff4
2019-04-04 19:02:22 +00:00
Aryeh Gregor
90d4f56fe4 Mass conversion of $wgContLang to service
Brought to you by vim macros.

Bug: T200246
Change-Id: I79e919f4553e3bd3eb714073fed7a43051b4fb2a
2018-08-11 22:44:29 -06:00
Fomafix
9926033b4f Use Language::equals to compare Language objects
With I8a47a8500922906bd4e4936b59b657de3bb9abdc Language::equals can
directly and faster compare the objects.

$wgLanguageCode can differ from $wgContLang->getCode() when a deprecated
language code is used. This change prevents this because Language
replaces deprecated language codes in Language::factory().

Change-Id: I07f47eceff8b3a4192278b1e9e1cfd9a41816a1c
2018-07-10 01:04:03 +00:00
Umherirrender
3f1a52805e Use short type bool/int in param documentation
Enable the phpcs sniffs for this and used phpcbf

Change-Id: Iaa36687154ddd2bf663b9dd519f5c99409d37925
2017-08-20 13:20:59 +02:00
addshore
af95474b62 Remove HTMLFileCache::newFromTitle()
Change-Id: I0076801aa7b9af5083c5a7a66f2d1c9884b70ee9
2017-01-28 17:31:18 +00:00
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
Aaron Schulz
dac2faee5c Restore Content-Language header change from e53ff931a
This was lost in a rebase at some point.

Change-Id: I46f376a82205a5c99b98c9e971f9e9d7868ce9fb
2016-10-03 17:56:45 +00:00
Aaron Schulz
108ccb0352 Make rebuildFileCache cover ?action=history
Also simplified the logic slightly

Change-Id: I6145d52b6b701735fa4bd8e41e07fb2bf6fdcee3
2016-09-20 00:53:26 -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
Aaron Schulz
3ad9e41be9 Fix $wgFileCache DB outage fallback
Change-Id: I5c41b4669ca29d119de5c08a2c61dbadae7cf55c
2016-09-16 02:18:12 +00:00
Timo Tijhof
b2585a95b2 filecache: Remove unused ObjectFileCache class
This was originally intended for use by ResourceLoader but it was
incomplete and not actually used by ResourceLoader at first.

Then 93d358cd added support for FileCache to ResourceLoader with
a separate ResourceFileCache class.

Also fixed typo in HTMLFileCache from 6559b8bf.

ObjectFileCache is not mentioned anywhere else in Wikimedia Git.

Change-Id: I69cca27ee7cd922da12f1793660432709c273be6
2016-09-06 17:09:50 -07:00
Aaron Schulz
017c9169e8 Unbreak file caching
This was totally broken by 796d62d0

Change-Id: I34ee08e926117b9472151d9fd415c1dfc6a57de1
2016-07-29 20:03:24 -07:00
Fomafix
796d62d034 Language: Introduce new method equals( Language $lang )
Use

 $lang->equals( $wgContLang )

instead of

 $lang->getCode() === $wgContLang->getCode()

Change-Id: Id7ed6a21ce5e2ea2887ec98c7bd9d3eba83d733b
2016-05-16 22:33:33 +00: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
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
This, that and the other
ea335eb55d Improved personal toolbar for logged-out users
Previously, logged-out users either only saw "Create account" and "Log in"
links in the personal area, or if $wgShowIPinHeader was true, they saw

  [icon] 127.0.0.1  Talk for this IP address  Create account  Log in

where the IP address itself linked to the IP user page.

Now, logged-out users by default see the following:

  [icon] Not logged in  Talk  Contributions  Create account  Log in

The old $wgShowIPinHeader feature is removed. It is very unfriendly to
show the user's IP address (in red, no less) at the top of every page,
since this will mean nothing to most visitors. Caching means that this
can't even be done reliably, anyway.

Another improvement is that the "talk" and "contributions" links are not
shown if anonymous users don't have the 'edit' right.

Modelled after the loggedOutTalkPage() function at Dutch Wikipedia
<https://nl.wikipedia.org/w/index.php?oldid=44706954>

Bug: T112724
Change-Id: I6f44e3e5d97ea917e4a03af47f3795792e4ca122
2015-12-01 18:44:52 +00:00
Seb35
ad0d70fd52 $wgUseGzip had no effect
Since MediaWiki 1.24 a constructor is defined in HTMLFileCache,
so the constructor of the parent class, FileCacheBase, is no more
called, and $wgUseGzip is no more used. This fix explicitely calls
the parent constructor.

Bug: T103237
Change-Id: I80c1871881049b9618c23aa76e6665867ecec2aa
2015-06-20 19:07:07 +02:00
Aaron Schulz
e369f66d00 Replace wfRunHooks calls with direct Hooks::run calls
* This avoids the overhead of an extra function call

Change-Id: I8ee996f237fd111873ab51965bded3d91e61e4dd
2014-12-10 12:26:59 -08:00
jenkins-bot
fca90adbd7 Merge "Deprecate HTMLFileCache::newFromTitle() in favor of constructor" 2014-09-19 00:24:16 +00:00
Max Semenik
0fddd42ca4 Deprecate HTMLFileCache::newFromTitle() in favor of constructor
Change-Id: I903e68fc1f486501d790ca69146ecb835d90c9cc
2014-09-19 00:07:51 +00:00
Max Semenik
bbc92a1433 Add a hook to allow extensions to prevent HTML file caching
Needed for MobileFrontend on third-party sites that use this feature.
Ideally, there should be a way to cache mobile requests too, but that's
a different issue requiring much more effort to do properly.

Bug: 68106
Change-Id: I01a76c571d9186b325f19a00cec136459707c791
2014-09-18 17:00:39 -07:00
umherirrender
fd66273c94 Fixed some @params documentation (includes/[cache|objectcache])
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: I86fd10e3f2d4bb80e7432533038d124693acfb3c
2014-04-19 01:19:46 +02:00
Alexandre Emsenhuber
a7a0883019 Enhance the destination control parameter of wfDebug() and wfDebugLog()
- The parameter is now a string, making is more understandable than
  boolean values
- It takes the same values in both wfDebug() and wfDebugLog() (except
  for 'private' which is only used in the latter)
- This adds a new possibility to wfDebugLog() to log the message either
  on the specific log or the general one, but not to the debug toolbar
- Old boolean values are still recognised for backward compatibility
- Also send the messages passed to wfDebugLog() to the debug toolbar
  when they are written to a specific log and not restricted to logs
- Updated the calls of and wfDebug() and wfDebugLog() with the last
  parameter to change it into a string
- Renamed MWDebug::sendWarning() to MWDebug::sendMessage() and added
  $group parameter to it; will not break anything since that method
  is marked as private
- Changed the call to wfDebug() from MWDebug::sendMessage() to use
  wfDebugLog() with 'log' as thrid parameter, so that those messages
  can be logged separately from the main log and they don't show up
  a second time on the "debug log" tab of the debug toolbar

Change-Id: I1be09d4c1d3408ed5b26a5db02691c17c0ec0926
2014-02-04 19:56:24 +00:00
Siebrand Mazeland
8251479984 Update formatting
Change-Id: I9aa56cbe0989d6f302ee0f47c4a6154101f73e90
2013-11-17 21:46:55 +01:00
Timo Tijhof
4bd5471ca3 docs: Remove odd colons after @todo
Most were this way already:
https://doc.wikimedia.org/mediawiki-core/master/php/html/todo.html

Ran a find/replace on the odd ones. Also made them all
lower case.

Change-Id: I70c6a69344ddebc603e9a1c1d87e3cc4f4f4c560
2013-05-15 06:23:40 +00:00
umherirrender
6f79eef473 Fixed spacing around parenthesis in includes
Change-Id: Ie8adc00f4ee8ecec4554e584c18d5d2073415397
2013-04-28 15:50:07 +00:00
umherirrender
ca31ebad3f fix some spacing
Added/removed spaces after opening/before closing parentheses

Added a space after a comma

Removed unneeded parentheses in condition

Change-Id: I306091347ccaaf11dee0cdfda3019cb0c12be51b
2013-02-09 23:03:53 +01:00
umherirrender
be90ce07b3 fix some spacing
Change-Id: I93f0a87ba7129bc336083e7289247d3150feb606
2013-02-04 19:54:07 +00:00
Siebrand Mazeland
d4b046a893 Update docs for return and exception info
* Removed some inline tabs in the process.
* IDE fixed some incorrect leading spaces, too.

Change-Id: Ic9303eff6db4424ac3f1fa2816839692b43e6190
2012-10-09 09:41:58 +00:00
Alexandre Emsenhuber
18786f4bdd Make HTMLFileCache also work when gzip is not enabled server-side.
In that case, it was just returning a blank page.

Change-Id: I08fbc5be37b5ee31504aae6af51b6cbebef44f29
2012-06-26 12:44:36 +02:00