Commit graph

99 commits

Author SHA1 Message Date
Tim Starling
9c3c0b704b Use array_fill_keys() instead of array_flip() if that reflects the developer's intention
array_fill_keys() was introduced in PHP 5.2.0 and works like
array_flip() except that it does only one thing (copying keys) instead
of two things (copying keys and values). That makes it faster and more
obvious.

When array_flip() calls were paired, I left them as is, because that
pattern is too cute. I couldn't kill something so cute.

Sometimes it was hard to figure out whether the values in array_flip()
result were used. That's the point of this change. If you use
array_fill_keys(), the intention is obvious.

Change-Id: If8d340a8bc816a15afec37e64f00106ae45e10ed
2021-06-15 00:11:10 +00: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
Timo Tijhof
ed9870d317 SiteConfiguration: Remove by-ref return from getLocalDatabases()
This is most likely a micro-optimisation from a time where MW
still ran mainly on PHP 4, during which copy-on-write wasn't as
well implemented (or not as well understood).

Nowadays, this actually makes the method slower, and also makes
the internals hard to reason about due to the side effects a
downstream mutation could cause.

Remove this undocumented feature, and also make the method
explicitly public.

Bug: T169821
Change-Id: I1887021282bbc4ab619a46e80a8c54bf1fc794ab
2020-03-17 18:29:43 +00:00
Timo Tijhof
44cf36b50f SiteConfiguration: Remove deprecated 'localVHosts' member
Deprecated since 1.25 and not used anywhere in Codesearch.

Interestingly, this probably didn't need to go through deprecation
as the ability to set and get members on a foreign object the class
itself doesn't use, is available on all PHP objects by default.

Change-Id: If2230d1806e5540b616cd28d993ab473c0036d05
2020-03-04 16:39:03 +00:00
Timo Tijhof
8fa48fc9d4 SiteConfiguration: Optimise arrayMerge()
* Remove the outer loop and with that, the (unused) variadic
  arguments feature. It is only ever called with exactly two arrays.

* Make it private.

* Refactor the loop body to not evaluate the same conditions
  multiple times.

* Document what this thing does and doesn't do.
  In particular, the fact that its "merge by appending" behaviour
  kicks in based on key conflicts, not just based on keys being
  numerical. This means numerical keys are generally preserved,
  which is quite important for namespace-related settings.

* Also two minor changes I forgot to commit as part of 268759c154:
  - Remove the obsolete null check at the end of processSetting(),
    the doReplace() function already checks for string and arrays,
    which means it can't be null anyhow.
  - Inline it because it's only a few lines of code and used in
    one place.

Bug: T169821
Change-Id: I2b90e8e9b0a38c0ac3d4b3d480923c3279b781cc
2020-03-04 16:36:55 +00:00
Timo Tijhof
15f6e986eb SiteConfiguration: Optimise getSetting() internals for getAll()
* getSetting() was retreiving the overrides array from $this->settings
  by settingName. But, the getAll() caller already had this array
  locally available from its foreach loop as "$stuff" which was
  previously unused.

  The protected getSetting() was renamed to processSetting(),
  and now takes this array directly.

* Remove the code duplication in processSetting() for handling
  of 'tags' and handling of 'suffix'. Instead, treat the 'suffix'
  as an extra tag internally, which is exactly how it was behaving
  already. This happens in mergeParmas(), which now documents this
  feature and what it means practically.

  This means for WMF that it can remove the duplication between
  $wgConf->suffices and wikifamily dblist files. These are redundant
  given the suffix for those wikis is identical to the tag name.
  This will save about a dozen dblist file reads in production,
  once we utilize this decade-old feature.

* Rewrite the internal do-while in processSetting() in a more
  procedural fashion. The only reason it used do-while was to
  perform an "early return" from the given block in two places.
  One was rewritten with a simple if/else that devides before/after,
  and the other was rewritten by explicitly tracking the action it
  wanted to skip (which is: applying of 'default' value').

* Document this scary code, including the various anti-features
  I found along the way (such as 'default' overridding '+wiki').
  No changes in behaviour for now.

Bug: T169821
Bug: T246858
Bug: T246213
Change-Id: I723133e6814a5d15c3b0b9e785921505ec7b9a69
2020-03-04 02:12:16 +00:00
Timo Tijhof
268759c154 SiteConfiguration: Optimise getAll() and doReplace() loops
The runtime numbers in each bullet point are based on a local
benchmark that use a copy of WMF's InitialiseSettings.php file
to compute enwiki's $globals via SiteConfiguration::getAll().
Source code and results can be found at
<https://gist.github.com/Krinkle/2ef2fe72218b5f5cea91679df56a0b18>.

* The getSetting() method (called by getAll) was iterating over
  each find/replace pair and performing a separate call to str_replace()
  via doReplace().

  Instead, iterate the pairs only to create a replacements array
  (this array differs from the pairs in that it has a leading "$" in the
  search keys), and then call doReplace() once for each setting value,
  instead of multiple times.

  Also, switch from str_replace() to strtr() while at it (which promises
  to only search the string once, instead of repeatedly until it no
  longer finds any of the search patterns).

  Also also, generate the replacements array outside the getSetting()
  method and do this in the mergeParams() method instead, which is called
  before the getSetting-loop in getArray begins, thus further reducing
  identically repeated work.

  In my local benchmark for WMF/enwiki this reduced runtime from
  ~7.5-8.1ms to ~6.9-7.3ms.

* The getSetting() method was using a by-reference assignment
  for a local variable that would hold a read-only copy a class member
  `$thisSetting =& $this->settings[$settingName];`.

  This was presumably a PHP4 or PHP5 era optimisation to avoid
  an eager memory copy given the promise to only read the data.
  However, in PHP5/PHP7 this is redundant given that PHP
  does copy-on-write.

  Removing the "&" symbol here made a drastic perf improvement,
  reducing my WMF/enwiki benchmark runtime from ~6ms to ~1ms.

Bug: T169821
Change-Id: I0e8b395920c143f2b42f9d87c1afaffa2bfdaf2e
2020-03-03 00:59:51 +00:00
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08:00
Thiemo Kreuz
b39a56d74e Make use of existing array value variables in foreach loops
In all these cases, the foreach() loop specifies a variable for the
current value. We don't need two ways to access the same value. This
makes the code harder to read.

Change-Id: I6ed7a518439963b7091057194de993a7e977be32
2019-12-29 12:04:29 +00:00
Aryeh Gregor
7b4489e019 Get rid of unnecessary func_get_args() and friends
HHVM does not support variadic arguments with type hints.  This is
mostly not a big problem, because we can just drop the type hint, but
for some reason PHPUnit adds a type hint of "array" when it creates
mocks, so a class with a variadic method can't be mocked (at least in
some cases).  As such, I left alone all the classes that seem like
someone might like to mock them, like Title and User.  If anyone wants
to mock them in the future, they'll have to switch back to
func_get_args().  Some of the changes are definitely safe, like
functions and test classes.

In most cases, func_get_args() (and/or func_get_arg(), func_num_args() )
were only present because the code was written before we required PHP
5.6, and writing them as variadic functions is strictly superior. In
some cases I left them alone, aside from HHVM compatibility:

* Forwarding all arguments to another function. It's useful to keep
  func_get_args() here where we want to keep the list of expected
  arguments and their meanings in the function signature line for
  documentation purposes, but don't want to copy-paste a long line of
  argument names.
* Handling deprecated calling conventions.
* One or two miscellaneous cases where we're basically using the
  arguments individually but want to use them as an array as well for
  some reason.

Change-Id: I066ec95a7beb7c0665146195a08e7cce1222c788
2019-04-12 20:17:01 +00:00
Thiemo Kreuz
5833dda61d Replace strlen() calls with strict string comparisons
Note there is an important difference between the two ways to express
this: strlen() does a string cast, but the `=== ''` and `!== ''`
comparisons will only detect empty strings, but not null, false, or any
other falsy value that becomes an empty string when cast to be one.

I am only touching code where I'm sure the variable is guaranteed to be
a string.

This change is done because I find the strict comparisons much more
readable. The code does exactly one thing now, and no magic casts any
more.

Change-Id: I3e908a0c7c7b6c29b0e5a1414f2ba9062a215b93
2019-03-28 12:32:39 +01:00
Aaron Schulz
51945dbca3 Use DB domain in JobQueueGroup and make WikiMap domain ID methods stricter
Using domains means thats JobQueueDB has the right value to use for calls
like LoadBalancer::getConnection(). The full domain includes the schema in
the case of Postgres. This makes calls to getConnection() less awkward by
not relying on the fallback logic in reallyOpenConnection() for null schemas.

Make getWikiIdFromDomain/isCurrentWikiDomain account for the schema if it
is both defined and is not simply the generic "mediawiki" schema MediaWiki
uses by default. If all wikis use the default schema, the wiki IDs can get
by with DB/prefix alone, which various config and methods may be built around.
Otherwise, the config callbacks must account for schema and the config must
include it in various wiki domain ID lists to properly disambiguate wikis.

Also, clean up SiteConfiguration::siteFromDB() since it is not meant
to handle schemas unless the callback method was taylored to do so.

Finally, add more comments to DefaultSettings.php about already existing
limitations of wiki domain IDs and their components.

Change-Id: I8d94a650e5c99a19ee50551c5be9544318eb05b1
2018-11-07 04:46:56 +00:00
Aaron Schulz
dcd0a3d534 Add isCurrentWikiId()/isCurrentWikiDomain()/getCurrentWikiDomain() to WikiMap
Use these in place of various wfWikiID() calls.

Also cleanup UserRightsProxy wiki ID variable names and removed unused
and poorly named getDBname() method.

Change-Id: Ib28889663989382d845511f8d34712b08317f60e
2018-10-29 14:53:37 -07:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00:00
Max Semenik
1e680456b4 Get rid of call_user_func(_array)(), part 3
Also cleaned up nearby code in a couple places.

Change-Id: Ibf44ee7c0ceb739d7e79406e4ff39303c316e285
2018-06-10 02:21:24 +00:00
Max Semenik
5cf4575ea3 Deprecate wfShellWikiCmd()
Bug: T184339

Change-Id: Ic86a451e0e9d609e06865a4969560d151efa844c
2018-04-16 16:38:05 +00:00
Tim Starling
b0af2fbe42 Do not limit filesize when running a maintenance script
Starting HHVM may require writing very large files, so it can't have the
same file size limit as image scaling etc. The memory limit was already
disabled for much the same reason.

This is the only caller of wfShellWikiCmd() in core which proceeds to
call wfShellExec().

Bug: T145819
Change-Id: I1ab35edbbdb63c2d6f5f578cba2547be79a965ef
2017-11-14 20:45:24 +11:00
Umherirrender
a9007e8baf Add missing & to @param documentation to match functon call
Change-Id: I81e68310abcbc59964b22e0e74842d509f6b1fb9
2017-08-11 18:47:46 +02:00
Erik Bernhardson
d67197fa11 Cleanup some incorrect return annotations
Most of these are simply changing annotations to reflect
reality. If a function can return false to indicate failure
the @return should indicate it.

Some are fixing preg_match calls, preg match returns 1, 0 or false,
but the functions all claim to return booleans.

This is far from all the incorrect return types in mediawiki, there
are around 250 detected by phan, but have to start somewhere.

Change-Id: I1bbdfee6190747bde460f8a7084212ccafe169ef
2016-12-12 10:15:05 -08:00
jenkins-bot
532364d46f Merge "Clean up array() in docs, Part I" 2016-07-29 00:19:45 +00:00
jenkins-bot
ef06c85d9b Merge "Improve WikiMap::getWikiReferenceFromWgConf()" 2016-07-27 23:33:27 +00:00
Amir Sarabadani
7fd83c2102 Clean up array() in docs, Part I
Change-Id: Ia6bb3944c05b056677979035cb38385554ee8a4f
2016-07-25 17:15:18 +04:30
Chad Horohoe
53830e84ed SiteConfiguration: Remove isLocalVHost(), deprecated since 1.25
No callers anywhere anymore.

Change-Id: I5f85b3cf60a59d28206bf56a0f8e33c812248d5d
2016-07-19 23:44:22 +00:00
Brad Jorsch
010410265a Improve WikiMap::getWikiReferenceFromWgConf()
If we don't have a valid canonical server and path to pass, there's no
point in returning a WikiReference that will fail in strange and unusal
ways.

This also documents that $wgServer/$wgCanonicalServer and $wgArticlePath
are required in SiteConfiguration.

Change-Id: Ib08011e9f1d0817a5d1bb165aba6b424785eaa6a
2016-07-06 14:20:07 -04: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
Alexandre Emsenhuber
3114dbea04 Replace $wgConf->localVHosts by $wgLocalVirtualHosts
The former is independent of the remaining of the SiteConfiguration
class, and as thus makes more sense to be defined as an explicit
configuration setting rather that being hidden in $wgConf.

Change-Id: I25204d37c5cfffb6953fe53e14316dc3df5b5b10
2014-10-03 03:54:44 -07:00
Alex Monk
1a25787699 When getting remote config, if the caller requested a single setting without an array, always do that
Even if it comes from the cache. See Idfec62d5 review comments for PS43.

Change-Id: I67ceef7fec61b7f37728f120354bd886018d244e
2014-09-06 22:44:07 +01:00
jenkins-bot
7edab4aa73 Merge "Force array parameters in SiteConfiguration" 2014-07-04 19:49:44 +00:00
Alexandre Emsenhuber
a7de863d3a Don't use isset to check for null
Change isset() checks for variables that are always defined.

Change-Id: Ic96b9661d94742909c0d6b62a8eb2f6a038a774f
2014-07-04 21:20:22 +02:00
Alexandre Emsenhuber
5ef43924c9 Force array parameters in SiteConfiguration
Now that we require PHP 5.1 (for quite some time actually)
we can force method parameters to be array.

Change-Id: Ia4a262320344e05cc1625c041a3aa4ec41034ad7
2014-07-03 21:48:08 +02:00
Siebrand Mazeland
49cffd699c Make phpcs-strict pass on includes/ (2/~10)
Change-Id: I59fa9af7b16e0a5a4eb8a5cc764a605b18137316
2014-05-11 19:22:05 +00:00
umherirrender
23bb3d1cb4 Follow-Ups to "Fixed some @params documentation"
Fix of inline comments of the following patch sets:
Follow-Up: I0056b4a8df243cfc0c5f25378de48f7a35170aca
Follow-Up: I7f605aa9e117b5fd80d9b1440864fe526d2b14a5
Follow-Up: I3622f216a2ca8ac1b5e51892be9f98665f65bc36
Follow-Up: I6627ba0e76d3577c40bf2473e0f78a5ad7368634
Follow-Up: Id75b5ecf648ca50f955b3bde3307c82c4366b102
Follow-Up: I4ca5231119f33039d91da3b57a41cd40719a576b

Change-Id: Id9bbe84b2820e9db44af5783411e955f55f643d4
2014-04-23 13:39:49 +02:00
umherirrender
a3983418d5 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: I0056b4a8df243cfc0c5f25378de48f7a35170aca
2014-04-22 13:07:02 +02:00
Liangent
bc2915b722 Attempt to remove a hard-coded "wikipedia".
Change-Id: I3c1567929eaa11a6ca0f3e8d7fe73653375b595b
2013-08-09 09:32:13 +00:00
umherirrender
15ff79312d Fixed spacing and removed unneeded parenthesis
Added spaces after/before parenthesis
Removed unneeded parenthesis around some statements
Broke a long line

Change-Id: I7fbe129f7bbf524dd0598ece2a9708643f08453b
2013-05-17 16:12:08 +00: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
umherirrender
6c278b6d7e fix some spacing
* Removed spaces around array index
* Removed double spaces or added spaces to begin or end of function
  calls, method signature, conditions or foreachs
* Added braces to one-line ifs
* Changed multi line conditions to one line conditions
* Realigned some arrays

Change-Id: Ia04d2a99d663b07101013c2d53b3b2e872fd9cc3
2013-03-25 22:22:46 +00:00
Tyler Anthony Romeo
4dcc7961df Fixed @param tags to conform with Doxygen format.
Doxygen expects parameter types to come before the
parameter name in @param tags. Used a quick regex
to switch everything around where possible. This
only fixes cases where a primitve variable (or a
primitive followed by other types) is the variable
type. Other cases will need to be fixed manually.

Change-Id: Ic59fd20856eb0489d70f3469a56ebce0efb3db13
2013-03-11 13:15:01 -04:00
Aaron Schulz
04e0d75f86 [JobQueue] Use target wiki configuration for some key functions.
* getQueueTypes() now gets the config of the target wiki.
  Previously, for WMF, if an extension using jobs was not
  on aawiki, those job queues would not be seen by nextJobDB.
* Also fixed nextJobDB.php so that it no longer only considers
  jobs types known to aawiki for picking a DB for default jobs.
* Note that $wgJobTypesExcludedFromDefaultQueue should be global.
* This adds a SiteConfiguration::getConfig() function, which calls
  a new getConfiguration.php script.

Change-Id: I7e6904ead17efa407291f423a2b18e3c866d55fd
2013-02-21 05:34:42 +00:00
umherirrender
1044b0b8df fix some spacing
Change-Id: I8f976013f33c5818e4402604fe8610aa3f43b0c6
2013-02-04 20:18:33 +00:00
umherirrender
6fbbbd17ca fix some spacing
Change-Id: Ie7bb35871cc99237f3a655f7db22ca1f0646df5e
2013-01-27 14:21:50 +01:00
Antoine Musso
cb60d72be1 misc style fix
* makes booleans lower case
* add spaces before open braces

Change-Id: Id88884e08bc23d7730361ee91646f54f5e16920b
2012-12-20 16:09:25 +01:00
Reedy
7e386ab639 Minor stylize, add some braces
Couple of bits of member variable docs

Change-Id: Iccf861b1b93543f21f43c50864107ec6bb233bd1
2012-07-05 23:53:57 +01:00
Antoine Musso
f7ea837eb5 (bug 1) doc for SiteConfiguration
SiteConfiguration was lacking some basic example and a very basic
introduction.

Change-Id: I306f7427ca17b0e271784f4a3e959ca8848dabea
2012-05-31 10:16:16 +02:00
Alexandre Emsenhuber
bc9d9f1f9c Added missing GPLv2 headers in some places.
Also made file/class documentation more consistent and removed a duplicate comment from SpecialPageFactory.php in SpecialPage.php.

Change-Id: I99dd2de7fe461f2fad4e0bd315ebc2899958a90f
2012-05-10 17:51:44 +02:00
Sam Reed
0a626db6e1 Fixing some of the "@return true" or "@return false", need to be "@return bool" and then the metadata can say true if foo, false if bar
Other documentation improvements
2012-02-09 19:29:36 +00:00
Chad Horohoe
daacd1b3d3 Remove no-op initialise from configuration. Nothing outside of Ext:Configure needs/uses it 2011-08-04 20:55:20 +00:00
Aaron Schulz
19d66a6668 Fixed typo. w/s cleanup. 2011-07-28 07:27:40 +00:00
Chad Horohoe
ab99b52bd1 Followup r91224: stupid syntax error 2011-06-30 21:32:55 +00:00
Chad Horohoe
226b5730a3 Remove superfluous inclusion of SiteConfiguration in doMaintenance. It's in the AutoLoader and has already been initialized by DefaultSettings by this point.
As a result: rm DIY inclusion protection, since this was the only reason it was still needed.
2011-06-30 21:25:52 +00:00