Commit graph

66 commits

Author SHA1 Message Date
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
Umherirrender
1f71eccf63 phan: Disable null_casts_as_any_type setting
Make phan stricter about null types by setting null_casts_as_any_type to
false (the default in mediawiki-phan-config)
Remaining false positive issues are suppressed.
The suppression and the setting change can only be done together

Bug: T242536
Bug: T301991
Change-Id: I0f295382b96fb3be8037a01c10487d9d591e7e01
2022-03-21 18:25:07 +00:00
Timo Tijhof
f8ecea1e5c rcfeed: Deprecate $wgRCEngines and RCFeedEngine
Follows-up 39a6e3dc4d (I8be497c623c5d92).

* Improve documentation all around and advertise 'class'
  everywhere instead of 'uri'.

* Add test coverage for RCFeed::factory().

* Deprecate the $wgRCEngines "uri to class" mapping in favour
  of specifying "class" directly in $wgRCFeeds.

* Deprecate RCFeedEngine in favour of FormattedRCFeed.
  Convert to class_alias so that UDPRCFeedEngine no longer has
  to extend the deprecated class name explicitly (for instanceof compat).

* Hard-deprecate RecentChange::getEngine.

Bug: T250628
Depends-On: Ie939e1d06b9ee2d841ec7256c8d24cc4e7e386dd
Change-Id: Ib6758d724c7200404c89c7ab157aa55f1cad9763
2022-03-08 19:50:19 +00:00
Timo Tijhof
780930fa6b rcfeed: Allow easy mocking of RCFeed::factory objects
This matches what the RecentChange::getEngine method provides,
which is deprecated and replaced by this. However, in order to
update tests (such as those in EventBus) to the new method, that
method first has to support mocking of this kind.

Bug: T250628
Change-Id: I126f7c8b117b5d2e66a41ebb314523083e764547
2022-03-03 18:26:26 +00:00
C. Scott Ananian
9e033de4f2 Don't double-escape the ellipses in Language::truncateForVisual()
It turns out this gets rid of a bunch of suppressed
"SecurityCheck-DoubleEscaped" that appear to have been accurate
warnings.

There seems to have been some confusion about how ::truncateForVisual()
is supposed to be used; in particular it is to be passed *unescaped*
output, because it is not (generally speaking) safe to truncate
HTML-escaped strings.  The goal of ::truncateForVisual() is to have
a specific number of codepoints in the output for display purposes,
the encoding of those codepoints is not an issue (htmlspecialchars
can be applied to the *return value*.)  If you need a specific number
of *bytes* you should be using ::truncateForDatabase().  If you want
a certain number of *HTML bytes* then the ::truncateHtml() method
is probably what you want.

Slightly refactor some code in RevDelLogItem to avoid a false positive.

Bug: T301205
Bug: T290624
Change-Id: I893362e049aedfa699043fcf27caf4815196f748
2022-02-10 17:09:18 -05:00
TChin
47adb6d65a Refactor global variables to use MediaWikiServices instead
Automatically refactors wg prefixed globals to use MediaWikiServices config using Rector. Doesn't include files that set globals or files that fail CI.

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

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

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

Change-Id: I1a691f01cd82e60bf41207d32501edb4b9835e37
2022-01-10 13:55:53 -05:00
vladshapik
9b92c1088f Drop User methods which were deprecated since 1.35
The following User methods, deprecated in 1.35, have been removed:
  - ::isIP,
  - ::isIPRange,
  - ::isValidUserName,
  - ::isUsableName,
  - ::isCreatableName,
  - ::getCanonicalName,
  - ::addAutopromoteOnceGroups,
  - ::getDefaultOptions,
  - ::getDefaultOption,
  - ::getOptions,
  - ::getBoolOption,
  - ::getIntOption,
  - ::setOption
  - ::listOptionKinds
  - ::getOptionKinds,
  - ::resetOptions,
  - ::getEffectiveGroups,
  - ::getAutomaticGroups,
  - ::getFormerGroups
User::GETOPTIONS_EXCLUDE_DEFAULTS has been removed, since it is used only in the description of User::getOptions.

Bug: T277511
Depends-On: Ida05c22f81b30d9b46678e8ede3d531c38855d83
Change-Id: I72bbc2336f8ddbc66ce67226cd2d5baaa2f807d8
2021-11-12 15:35:50 +02:00
DannyS712
b0ab985420 Fix some @stable for ... annotations to use @stable to ...
Bug: T257789
Change-Id: I3ba94a9d6b739cd57cd57afe5d397963127160a8
2021-07-08 02:54:59 +00:00
Kosta Harlan
38be8c389b rcfeed: Remove reference assignment
It's unclear why this was used but it doesn't seem necessary now.

Bug: T281226
Change-Id: I900c6188281862a6bde0c6b061ee7e174a2cac42
2021-04-27 11:14:41 +02:00
daniel
2e57447c58 Document hook names in hook interfaces.
Bug: T258665
Change-Id: Ifddbf57f8aa2e3eb0d5845601376cbafa08ed407
2020-09-27 12:03:12 +02:00
daniel
e6e0ad2472 Replace "@stable for implementation" with "@stable to implement"
For compliance with the new version of the table interface policy
(T255803).

This patch was created by an automated search & replace operation
on the includes/ directory.

Bug: T257789
Change-Id: I17e5e92e24c708ffc846945a136347670a3a20c7
2020-07-13 11:05:49 +02:00
daniel
442fb30ce1 Stability annotations for interfaces.
Per the Stable Interface Policy, PHP interfaces should not be
directly implemented by extensions, unless they are marked to be safe
for that purpose.

Bug: T247862
Change-Id: Idd5783b70fc00c03d57f5b1a887f0e47c4d7b146
2020-07-07 22:01:29 +00: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
apaskulin
c44488f725 docs: Hook interface doc comment review
Edited doc comments for hook interfaces to improve
consistency and add type hints.

Bug: T246855
Change-Id: I38fa802463cd6f39bf5946dbbeb1b3ebaea604b2
2020-04-21 09:10:08 +10:00
Tim Starling
f5aaf75ad1 Automatically generated hook interfaces
Add hook interfaces which were generated by a script which parses
hooks.txt and identifies caller namespaces and directories.

Hook interfaces are mostly placed in a Hook/ subdirectory
relative to the caller location. When there are callers in multiple
directories, a "primary" caller was manually selected. The exceptions to
this are:

* The source root, maintenance and tests, which use includes/Hook. Test
  hooks need to be autoloadable in a non-test request so that
  implementing test interfaces in a generic handler will not fail.
* resources uses includes/resourceloader/Hook
* The following third-level subdirectories had their hooks placed in
  the parent ../Hook:
    * includes/filerepo/file
    * includes/search/searchwidgets
    * includes/specials/forms
    * includes/specials/helpers
    * includes/specials/pagers

Parameters marked as legacy references in hooks.txt are passed
by value in the interfaces.

Bug: T240307
Change-Id: I6efe2e7dd1f0c6a3d0f4d100a4c34e41f8428720
2020-04-20 13:31:05 +10:00
Reedy
3855600c11 Remove hack comment from IRCLineURL
We don't use the hook for this reason anymore, only Flow seems to
use it

Change-Id: If0cd2a05d469131875bead85da49fb3a1ba3c1e9
2020-03-28 00:56:50 +00: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
Daimona Eaytoy
41ee2f2c61 Upgrade phan to 0.9.1
Released just now.

Many old suppressions can now be removed. Enabling the issue for
undeclared variables is left to do later, given that there are
roughly 200 warning.

Change-Id: I99462a1e9232d6e75022912e2df82bc2038476ef
2020-01-25 10:53:26 +00:00
Daimona Eaytoy
b5cbb5ab3f Upgrade phan config to 0.7.1
This allows us to remove many suppressions for phan false positives.

Bug: T231636
Depends-On: I82a279e1f7b0fdefd3bb712e46c7d0665429d065
Change-Id: I5c251e9584a1ae9fb1577afcafb5001e0dcd41c7
2019-09-04 08:20:53 +00:00
Daimona Eaytoy
fb3428eb8f Unsuppress other phan issues with low count
And also update approximated counts, which for the most part are lower
than reported (hooray!)

Bug: T231636
Depends-On: Ica50297ec7c71a81ba2204f9763499da925067bd
Change-Id: I78354bf5f0c831108c8f606e50c87cf6bc00d8bd
2019-08-30 09:42:15 +00:00
Zoranzoki21
ea40cc2dcb Fix entites typos
Bug: T201491
Change-Id: I241fda87b0e53e804f6bdd48eb975a79e9f176d2
2019-08-28 06:36:04 +02:00
Fomafix
110a5877e9 Use [...] instead of array(...) in PHP comments and documentation
Change-Id: I0c83783051bf35fe785bc01644eeb2946902b6b2
2019-06-17 21:15:09 +02:00
James D. Forrester
460bcf81e7 build: Upgrade mediawiki/mediawiki-phan-config from 0.5.0 to 0.6.0 and make pass
Fix five instances of PhanPluginDuplicateConditionalNullCoalescing;
escape the rest for now.

Bug: T219114
Change-Id: Ic4bb30c43c5315ce6b878b37b432c6e219414f8b
2019-05-13 14:57:07 +00:00
Derick Alangi
0001b213e5 rcfeed: Replace usage of deprecated class RCFeedEngine (in comments)
Doing the replacement for code logic for where it's used is breaking
compatibility, the first change set did this but as adviced, let's wait
for a while until the class is removed.

Change-Id: I3cc0593080f0d51b380c9cdbabc646459e6798e1
2019-04-30 12:07:37 +00:00
Derick Alangi
5f11f09d70 rcfeed: Replace usage of deprecated CommentStore::getStore()
Change-Id: Icaa475a86becb7ef95304f5df31d3fdcf93168e9
2019-04-19 06:51:56 +01:00
Kunal Mehta
4ef179e335 Fix/suppress misc phan errors (#5)
Add lots of missing return statements, or remove incorrect doc blocks.

Change-Id: I0881e98fbb9d0d4cf79ecc824064d24538055d3f
2019-04-05 15:53:37 -07:00
Derick Alangi
82d4947fcb rcfeed: Avoid extending/inheriting from a deprecated class
Also, fix if...else syntax with return statement in the if block.

Change-Id: If14f0835731f264622cf90fcfd5c7cc850f63050
2019-03-25 14:27:22 +01:00
Aaron Schulz
5196ac32c6 Rename WikiMap DB domain ID methods to reduce confusion with web domains
Those added in this same release do not need alias methods.

Change-Id: I05feeb9b0b13afe43aea1f95551965489cdbe094
2019-02-06 12:28:45 -08:00
Aaron Schulz
dbccb3a361 Use WikiMap methods for wiki ID logic in more places
Change-Id: I25b53576a8fecb7cfb0e4d684f064bebf6c968fc
2018-10-29 22:02:00 +00:00
addshore
e5879da149 Pass $key into CommentStore methods and use MediawikiServices
This allows CommentStore to be added to MediaWikiServices
without the need of an aditional Factory.

This change includes a compatability layer to allow the behaviour
from 1.30 to continue to be used while deprecated.

CommentStore::newKey has been deprecated.
Keys are now passed into the public methods of CommentStore
where needed.
The following CommentStore methods have had their signatures changed
to introduced a $key parameter, but when used in conjunction with
CommentStore::newKey behaviour will remain unchanged:
  * CommentStore::getFields
  * CommentStore::getJoin
  * CommentStore::getComment
  * CommentStore::getCommentLegacy
  * CommentStore::insert
  * CommentStore::insertWithTemplate

Change-Id: I3abb62a5cfb0dcd456da9f4eb35583476ae41cfb
2018-02-05 15:34:12 +00:00
jenkins-bot
03cd9495a4 Merge "Fix a few minor mistakes in PHPDoc tags" 2017-09-15 19:18:17 +00:00
Thiemo Mättig
7301b2514e Fix a few minor mistakes in PHPDoc tags
Change-Id: I2d5f876c9945ba21f8748562230170e3c7ea2ff2
2017-09-15 11:17:17 +02:00
Umherirrender
f739a8f368 Improve some parameter docs
Add missing @return and @param to function docs and fixed some @param

Change-Id: I810727961057cfdcc274428b239af5975c57468d
2017-09-10 20:32:31 +02:00
Kunal Mehta
0cb2a09b6d Always put type information before variable name for @var tags
Like other tags, @var should have the type information before the
variable name.

<https://docs.phpdoc.org/references/phpdoc/tags/var.html>

Change-Id: I9eca6957b1990fa8cc687103dc02ee38af5f9086
2017-09-04 11:06:51 -07:00
Brad Jorsch
11cf01dd9a Add comment table and code to start using it
A subsequent patch will remove the old columns.

Bug: T166732
Change-Id: Ic3a434c061ed6e443ea072bc62dda09acbeeed7f
2017-08-30 15:05:00 +10:00
Timo Tijhof
c689fd2e4c doc: Fix a few Example docs for PHP classes
* "@example" is specifically for creating entries on the "Examples"
  page produced by Doxygen, which is not specific to individual classes
  or methods, but rather is meant to be about the software as a whole.
  There are currently four entries produced there, and they are all broken:
  - .../src/includes/rcfeed/RedisPubSubFeedEngine.php (unnamed example, broken)
  - .../src/tests/phpunit/MediaWikiTestCase.php (unnamed example)
  - 42 (empty page named "42")
  - user (empty page named "user")

* Remove usage and replace with either a regular paragraph that is
  part of the member/method/class description, or for code examples,
  use "@par" to create a sub heading, and then a @code-@endcode block.

Change-Id: I52c937fef4b377173f6c4dbad9dc4a9f8beae4ee
2017-07-17 20:29:58 -05:00
Timo Tijhof
2e37dc5b3c rcfeed: Ensure formatter (and other params) is passed to RCFeedEngine
Follows-up 39a6e3dc4d. Class-based feeds are always given their parameters
by RCFeed::factory. However because the old getEngine() method insists
on creating its own object, the constructor parameters were not given.

Add it as optional parameter and pass it through there.

This is backwards-compatible still because before the 39a6e3dc4d refactor,
an RCFeedEngine also was not given information about any formatter and it
was the callers responsibility to format the line before calling send().
CentralAuth still uses it this way and that works fine. The core-caller
that expected the construction parameters since 39a6e3dc4d is hereby fixed.

The test couldn't catch this because it constructed the class instance there,
since PHPUnit does not support a mock class that is instantiated by foreign
code, and the parameter is passed there.

Bug: T156996
Bug: T157106
Change-Id: I83433cf57b6e040cdb69f3ad8807a999c4f931a5
2017-02-04 03:31:44 +00:00
Timo Tijhof
7c0b549301 rcfeed: FormattedRCFeed constructor should match parent class
I intentionally made the constructor parameter optional in the
new RCFeed class from 39a6e3dc4d, however it was not optional
in the subclass, which the older classes are now based on top
of.

Bug: T156996
Change-Id: I05b9e15920bc39f27c402b023d1463cfbdd2efb8
2017-02-02 21:23:36 +00:00
Timo Tijhof
39a6e3dc4d Refactor RCFeed configuration (backwards compatible)
Previously:
* Engines had to be registered in $wgRCEngines.
* The RCFeedEngine classes took no constructor arguments and
  were expected to send whatever text is previously formatted
  without any information about it. This generic design was
  flexible in allowing one to use any formatter with any engine
  with minimal configuration and no need for additional classes.
* Each feed configured their destination by setting a 'uri'
  option that encodes the name of the engine in PHP as the uri
  scheme. Other uri components had to be used for any other
  parameters to the engine (host, port, path). While fairly
  limited, it was sufficient for the default engines in core.

Changes:
* Allow feed classes to be directly associated with a feed in $wgRCFeeds
  via a new 'class' option - without the indirection of 'uri' and
  $wgRCEngines. All options are passed to the given class constructor.
  This matches the design used elsewhere in MediaWiki. (ObjectCache,
  FileRepo, FileBackend, JobQueue, LBFactory, etc.)

  This means we no longer enforce a 1:1 mapping of internet protocols
  to a specific feed engine, and it allows settings to be passed
  without being encoded as a URI neccecarily.

  Main use case for this refactor is EventBus (see I7edc4d57fa),

  Interestingly, this matches the (then incorrect) documentation
  written for $wgRCFeeds in 2961884b43 (which mentions an 'engine'
  property that would do the same thing).

* Move the default 'omit' filters and unrestricted 'formatter' handling
  to a new FormattedRCFeed class, which remains the default.

* Deprecate RecentChange::getEngine() in favour of RCFeed::factory().

* Document wgRCEngines as "@since 1.22". Follows 2961884b43, ffc71cb6af.

Change-Id: I8be497c623c5d928762e3d3406a388f4d91add9a
2017-02-01 04:23:38 +00:00
Kunal Mehta
0ec0fa4028 Don't send RC_CATEGORIZE events to the IRC feed
Bug: T127360
Change-Id: I21e4c0edf25fc0b7f16ef3029de879d3b7a2923d
2016-02-18 12:19:08 -08: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
Ryan Schmidt
afcfb1d1fb Properly escape \n and \r in IRCColourfulRCFeedFormatter
Right now it is possible to emit a raw \n or \r to the UDP feed by
encoding it as an HTML entity, e.g. &#10; This could be used for
arbitrary IRC command execution in bots which do not subsequently
perform their own escaping. This commit changes it so that entities are
decoded first before \n and \r are stripped.

Change-Id: I3f7005abded3fbafb586754d763a00a4018f0954
2016-01-20 11:10:14 -06:00
Matthew Flaschen
047fc253d0 RC: Handle getLine returning null, which breaks Redis engine (at least HHVM)
Bug: T109544
Change-Id: I02dcfc7a10a74571232a898f1ef348f8dbc48b45
2015-08-18 23:08:36 -04:00
Stephane Bisson
62961558a5 Encapsulate rc_params handling in RecentChange::parseParams
* Make MachineReadableRCFeedFormatter use it

* Some unit tests

* Also fixed some line-too-long warnings in RecentChange.php

Change-Id: I443d14f5d4cdac0945cb9c03608d55745bbb865b
2015-06-10 15:11:37 -04:00
Bryan Davis
dad7abd9ce Create a generic UDP transport class
Code moved from MWLoggerLegacyLogger::emit(), which was formerly
in wfErrorLog().

Bug: T74572
Bug: T78599
Change-Id: I9e0e63d41bed6ccb468f3a9f1d52f156acc355a8
2014-12-15 15:06:43 -07: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
Bryan Davis
78695ada64 Use safe attribute accessor for RecentChange
The RecentChange does not guarantee that all attributes are populated.
Handily it provides a safe getter function in
RecentChange::getAttribute() that will return null with out triggering
an undefined index warning for missing attributes. Protects against log
spam like "Notice: Undefined index: rc_id".

Change-Id: Idee844f0d40a2a084e17f201b5e1501d59a0464d
2014-09-13 05:02:33 +00:00
withoutaname
557b2cf3ef Remove various functions and globals deprecated since 1.22 from RecentChange
Change-Id: I5200892e75ffa894133e2e386d53c09536547de9
2014-08-12 22:19:36 -07:00
umherirrender
dd8921c9d9 Cleanup some docs (includes/[m-r])
- Swap "$variable type" to "type $variable"
- Added missing types
- Fixed spacing inside docs
- Makes beginning of @param/@return/@var/@throws in capital
- Changed some types to match the more common spelling

Change-Id: I8ebfbcea0e2ae2670553822acedde49c1aa7e98d
2014-07-24 19:43:25 +02:00
Kunal Mehta
e8ab2deb0f RCFeed: Add log_id property (exposes rc_logid attribute)
Bug: 20394
Change-Id: I005be8e41a5cbea934d4dac27184f03e9af7c648
2014-06-11 22:27:13 +00:00