Commit graph

1636 commits

Author SHA1 Message Date
Taavi Väänänen
eab7fc0618 Hard deprecate wfIncrStats
Bug: T250316
Change-Id: I49b62cdad5e70ef2e96bfec3bd589ca285406564
2021-04-20 18:05:20 +00:00
Reedy
fb771021ea Use some more neutral language
Bug: T277987
Change-Id: Ieceb01f7a61693a0f03cc331213cb8f93163b8e9
2021-04-18 16:49:36 +01: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
cce3fb49d0 Use more neutral or alternative language
Bug: T277987
Change-Id: Iafc4b3e3137936046487119b7e17635f4e560277
2021-03-20 19:47:18 +00:00
Ammarpad
a0d6a4ccd1 wfDeprecated: Use InvalidArgumentException for invalid arguments
Change-Id: I0bf84810cee8c8aa4ca15b7f94fa9467a52b0278
2021-03-12 02:11:04 +00:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
Tim Starling
2697837fd8 RequestTimeout library integration
* Add $wgRequestTimeLimit. If it is non-null, it starts a time limit,
  using Excimer with a fallback to set_time_limit().
* Add pretty formatting of timeout exceptions thrown by the library.
  Related refactoring.
* Expose the library's critical section feature in MediaWikiServices
* In Setup.php, call warnIfHeadersSent() before sending session headers.
  This helped to debug a related issue I had.
* In wfTransactionalTimeLimit() use the new library, and respect the
  existing library time limit if it is larger than
  $wgTransactionalTimeLimit.

Bug: T269326
Depends-On: I6409ad8a5cba775c27b0d5a79d3300c4dac4c91a
Change-Id: I2e6f6351c451407c06cc7e20932548f7b62e36b6
2021-02-08 11:58:45 +11:00
jenkins-bot
c8b1375fb9 Merge "Use short array syntax to add array element" 2021-01-02 09:55:52 +00:00
Ammarpad
9efb07c9d2 Use short array syntax to add array element
The short syntax is faster and recommended over the method call

Change-Id: I18a3adcfa66abe5eadb834c0b23b54c6853b8c91
2021-01-02 08:20:24 +01:00
jenkins-bot
72ab56471d Merge "Soft deprecate wfIncrStats()" 2020-12-30 16:15:46 +00:00
Taavi Väänänen
c572e6f0ee Soft deprecate wfIncrStats()
Bug: T250316
Change-Id: I10c4f476392a933ac53ac4379edf60477ede1261
2020-12-29 16:12:45 +02:00
Taavi Väänänen
b8d9f54028 Remove hard deprecated wfIsBadImage()
Bug: T249459
Change-Id: I363ec383295aff8a2d6cc89b1f0df5369a537473
2020-12-29 15:55:10 +02:00
DannyS712
f4e21014ce Deprecate a bunch of global functions
* wfAcceptToPrefs
* wfClearOutputBuffers
* wfConfiguredReadOnlyReason
* wfDebugMem
* wfGetPrecompiledData
* wfNegotiateType

Bug: T264976
Bug: T264979
Bug: T264981
Bug: T264983
Bug: T264984
Bug: T264985
Change-Id: Ia05bc84e4d1be7c8a02472f32e2c009e4bb32032
2020-12-18 21:34:50 +00:00
Umherirrender
2579ca623a build: Updating mediawiki/mediawiki-codesniffer to 34.0.0
Change-Id: I2fb18ddd4c144655a665792901e59f88bcd906dc
2020-12-07 14:55:24 +01:00
Ammar Abdulhamid
e69efdaaca Deprecate wfAppendToArrayIfNotDefault
No known remaining caller. Last usage removed in I1ce51f6

Change-Id: Ife783173fb777c7fc8f33478e80b52a09168373e
2020-12-03 08:58:01 +01:00
Timo Tijhof
ea586cfa2e GlobalFunctions: Unbreak handling of '?0' query in wfAssembleUrl()
Follows-up Ief9c15cc8fe0fcae07d2c.

Bug: T268852
Change-Id: I5ddac943aad4d634ea20cd4d4cb21d1c857c05fd
2020-11-26 23:45:45 +00:00
Máté Szabó
44516c671c wfAssembleUrl: Handle empty query field in URL bits
parse_url() on PHP >= 8 will include an empty 'query' bit for input URLs that
end in '?' and have no query string, such as 'http://www.example.com/foo?'.
This causes the parser test for T4372 to break. Accordingly, fix wfAssembleUrl()
to not generate a query string if the input query field is empty.

Bug: T268852
Change-Id: Ief9c15cc8fe0fcae07d2cc3120db9ca95573324c
2020-11-26 22:47:25 +01:00
Aaron Schulz
d1d952473c Remove deprecated wfMemcKey() function
Bug: T266502
Change-Id: I1e4b20cc30fa3ef4671d8b80e660b2ac3f469d80
2020-11-23 16:57:06 -08:00
Thiemo Kreuz
1fc8d79ac6 Remove documentation that literally repeats the code
For example, documenting the method getUser() with "get the User
object" does not add any information that's not already there.
But I have to read the text first to understand that it doesn't
document anything that's not already obvious from the code.

Some of this is from a time when we had a PHPCS sniff that was
complaining when a line like `@param User $user` doesn't end
with some descriptive text. Some users started adding text like
`@param User $user The User` back then. Let's please remove
this.

Change-Id: I0ea8d051bc732466c73940de9259f87ffb86ce7a
2020-10-27 19:20:26 +00:00
Aaron Schulz
369a953e85 Remove deprecated wfForeignMemcKey()
Bug: T250407
Change-Id: Ie9352d297382689a2fc2634e1160d7fe7b91e89b
2020-10-26 19:33:29 +00:00
Ammar Abdulhamid
c0c8dad053 Deprecate Skin::makeVariablesScript()
Bug: T257995
Change-Id: I9789bb1a209a8f07cb2bb07140f2cc4fd778436a
2020-09-21 20:02:13 +00:00
jenkins-bot
2cc3d4f0ba Merge "Hard-deprecate global function wfDiff" 2020-08-19 15:13:12 +00:00
C. Scott Ananian
29546bf612 Hard-deprecate global function wfDiff
Code search: https://codesearch.wmcloud.org/search/?q=wfDiff&i=nope&files=&repos=

Bug: T249061
Followup-To: Ib20a9fbcc2b40e21bc9e99c1197991569b149b00
Change-Id: I2232f7964333c825d80d039fe3a77940fa7271ff
2020-08-19 05:57:59 -04:00
Gergő Tisza
918bab5f1d
Improve wfParseUrl docs
One of the possible fields was omitted.

Change-Id: I18477a515f91acc273017507414d947ce15ded89
2020-08-15 22:18:19 +02:00
Umherirrender
ba216e52e7 includes: Use expression assignment operator += or |= where possible
It is easier to read.

Change-Id: Ia3965b80153d64f95b415c6c30f526efa252f554
2020-07-31 22:26:42 +00:00
jenkins-bot
c64b405758 Merge "GlobalFunctions: Add documentation for replacing wfGetDB" 2020-07-16 12:46:45 +00:00
Amir Sarabadani
e4e81778fa Drop wfWaitForSlaves()
It has been soft deprecated since 1.27 and hard deprecated since 1.35
After the branch cut, this can be removed now.

Bug: T254646
Change-Id: I01e3267de50508e272a56302aae7809d06b66073
2020-07-16 11:26:16 +01:00
Thalia
4a265deb5d GlobalFunctions: Add documentation for replacing wfGetDB
Add a note about the difference between LoadBalancer methods
::getMaintenanceConnectionRef, which wfGetDB returns and
::getConnectionRef, which is more commonly needed when replacing
wfGetDB.

Change-Id: Ic14dcdf7c8af6f20b3a4a697a6c5fbe9a7eb6f2e
2020-07-13 18:00:00 +01:00
Timo Tijhof
ee4819418f GlobalFunctions,WebRequest: Remove use of AtEase for parse_url()
According to php.net docs, the warnings this used to emit have
been removed in PHP 5.3.
<https://www.php.net/manual/en/function.parse-url.php>

Thanks Ammarpad for showing this during development of
Ib829afc7b33419b0.

Change-Id: Ia078049c34f5fc6b1534f0ea0551ecc2c1fc3388
2020-07-08 20:35:16 +00:00
daniel
f59bf8a22f Use @internal instead of @private per policy
https://www.mediawiki.org/wiki/Stable_interface_policy mandates the use
of @internal. The semantics of @private was never properly defined.

Bug: T247862
Change-Id: I4c7c6e7b5a80e86456965521f88d1dfa7d698f84
2020-06-26 14:14:23 +02:00
Tim Starling
d459add63d Introduce wfDeprecatedMsg()
Deprecating something means to say something nasty about it, or to draw
its character into question. For example, "this function is lazy and good
for nothing". Deprecatory remarks by a developer are generally taken as a
warning that violence will soon be done against the function in question.
Other developers are thus warned to avoid associating with the deprecated
function.

However, since wfDeprecated() was introduced, it has become obvious that
the targets of deprecation are not limited to functions. Developers can
deprecate literally anything: a parameter, a return value, a file
format, Mondays, the concept of being, etc. wfDeprecated() requires
every deprecatory statement to begin with "use of", leading to some
awkward sentences. For example, one might say: "Use of your mouth to
cough without it being covered by your arm is deprecated since 2020."

So, introduce wfDeprecatedMsg(), which allows deprecation messages to be
specified in plain text, with the caller description being optionally
appended. Migrate incorrect or gramatically awkward uses of wfDeprecated()
to wfDeprecatedMsg().

Change-Id: Ib3dd2fe37677d98425d0f3692db5c9e988943ae8
2020-06-22 14:34:39 +10:00
DannyS712
733872afda wfLogProfilingData: Remove $request, created but never used
Change-Id: I5c6937c939c699681976e230124a00af10e2cbd0
2020-06-21 07:23:39 +00:00
Timo Tijhof
76b6cfeca9 GlobalFunctions: Use php_uname instead of posix_uname
* posix_uname() is only available when PHP is compiled with
  ext-posix, which MW installer and composer.json do not currently
  require. That's why it was conditionally used (good), but
  we can simply use php_uname() instead and not worry about this.

* php_uname uses POSIX on *nix systems whenever possible
  (even if compiled without ext-posix), and has a C-level fallback
  to ComputerName on Windows built-in as well.

* Remove the fallback to SERVER_NAME was imho quite poor because:
  - The domain name used as virtual host (e.g. on Apache) isn't
    relevant to what wfHostname() is about.
  - It can change from request to request, even influenced by
    end-users, thus could be problematic, poison caches, or behave
    in other unexpected ways.
  - It is unreliable because it is only expected to be set
    on web requests. Even on POSIX or Windows, it would be
    unset when on the command-line, so this would need to use
    an additional fallback either way.

Bug: T172060
Change-Id: I6251122f38db1edf5f85aecc8d8733b56c8222ee
2020-06-14 22:27:45 +00:00
Timo Tijhof
b547aa6396 Use PHP_OS_FAMILY instead of substr(PHP_OS,0,3) for Windows checks
This is new in PHP 7.2, and has a documented set of values at
<https://www.php.net/manual/en/reserved.constants.php>.

Change-Id: If732a652f091c26d7d645766ba6e76fbf464f755
2020-06-13 19:44:00 +00:00
Reedy
567e1bbb5d Hard deprecate wfIsBadImage()
Bug: T249459
Depends-On: Iec58118198864704b1860aeb630476391e3a2c23
Change-Id: I939ded72427adc973739e7b376ea85cbf4b3e258
2020-06-09 19:27:16 +00:00
Reedy
dc5fc0301a wfIsBadImage: Remove deprecated $blacklist parameter
wfIsBadImage still used in Flow\Parsoid\Fixer\BadImageRemover

Bug: T254646
Change-Id: Ieb1ba83593da5c7789b9da5b6a931eedcd391bf3
2020-06-09 00:14:42 +00:00
Amir Sarabadani
80780a3965 Hard deprecate wfWaitForSlaves()
Bug: T181673
Change-Id: Iedb5c4eff8920d3209c0fc516a47688d9306d6e0
2020-06-06 21:39:03 +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
Max Semenik
2a21e99633 GlobalFunctions: Fix wfPercent() with negative accuracy
Format strings like "%.-1f" have never been valid, however
while previously it would have resulted in output being "1f",
in PHP 8 it's an exception. The existing unit test failed because
(float)"1f" evaluates to 1, which was rounded down to an expected 0.
Adding another test case to make sure it can return anything other
than "0%" on PHP 7.

While I'm at it, fix wrong phpdoc and add parameter types to this
function.

Bug: T248925
Change-Id: I018bc17a563c58535f6c84644d707251ab19cd0a
2020-05-04 18:48:08 +03:00
jenkins-bot
af990ab38b Merge "Drop wfIsHHVM, deprecated in 1.34" 2020-05-02 00:01:30 +00:00
jenkins-bot
094e93b629 Merge "Drop wfSetupSession, deprecated in 1.27" 2020-05-02 00:01:23 +00:00
James D. Forrester
6f51591d72 Drop wfIsHHVM, deprecated in 1.34
Change-Id: Ie006b9ac52e2ab83626ac6178a048637851827a3
2020-05-01 17:17:18 +00:00
James D. Forrester
8c2fdd04ab Drop wfSetupSession, deprecated in 1.27
Bug: T232864
Change-Id: Ia0b6e45c08ca7e9bb37a73d52853407ffd9dc26c
2020-05-01 10:16:53 -07:00
Max Semenik
3781f4113b tests: Refactor GlobalTest to use a data provider
Change-Id: Iba800edd9ca35650f79b933db48eb8f95bd09f04
2020-05-01 17:02:27 +03:00
Aaron Schulz
0d933c6760 Deprecate wfForeignMemcKey() and remove the last call
Bug: T250407 
Change-Id: I82ca5a8a5d04166263eb19c4c99d72321bbbcdec
2020-04-17 09:57:37 +00:00
MusikAnimal
2d21ee58ec Add expiry type to ParamValidator
This commit also changes ApiWatch to make use of the new parameter type.
Other APIs will be updated to use it in a separate patch (T248196).

In doing this, we are for the first using logic within a TypeDef outside
the API. This seems acceptable given TypeDefs chiefly appear to serve as
a validation method, with otherwise no particular logic tied to the
concept of APIs.

wfIsInfinity() now uses ExpiryDef::INFINITY_VALS

Bug: T248508
Change-Id: If8f0df059eafb73ec9f39cc076b3a9ce2412d60a
2020-04-08 16:21:04 -04:00
Tim Starling
507501d6ee Stop using SCRIPT_NAME where possible, rely on statically configured routing
It has become apparent that $_SERVER['SCRIPT_NAME'] may contain the same
thing as REQUEST_URI, for example in WMF production. PATH_INFO is not
set, so there is no way to split the URL into SCRIPT_NAME and PATH_INFO
components apart from configuration.

* Revert the fix for T34486, which added a route for SCRIPT_NAME to the
  PathRouter for the benefit of img_auth.php. In T235357, the route thus
  added contained $1, breaking everything.
* Remove calls to WebRequest::getPathInfo() from everywhere other than
  index.php. Dynamic modification of $wgArticlePath in order to make
  PathRouter work was weird and broken anyway. All that is really needed
  is a suffix of REQUEST_URI, so I added a function which provides that.
* Add $wgImgAuthPath, for use as a last resort workaround for T34486.
* Avoid the use of $_SERVER['SCRIPT_NAME'] to detect the currently
  running script.
* Deprecated wfGetScriptUrl(), a fairly simple wrapper for SCRIPT_NAME.
  Apparently no callers in core or extensions.

Bug: T235357
Change-Id: If2b82759f3f4aecec79d6e2d88cd4330927fdeca
2020-04-01 12:33:38 -04:00
Timo Tijhof
95ec909e52 WikiMap: Add WikiMap::getCurrentWikiId() to make common use case easier
Change-Id: Ie225ebfc37c824e3167742137bbbc9f64aca5f5e
2020-03-03 16:04:21 +00:00
Timo Tijhof
8dfa162439 profiler: Remove support for $wgDebugLogGroups['profileoutput']
Profiler outputs should instead be configured via $wgProfiler.

Bug: T245835
Change-Id: Ib27ce8d066bde27596e61491750c508b259746f4
2020-02-29 18:24:55 +00:00