Commit graph

16 commits

Author SHA1 Message Date
Umherirrender
e662614f95 Use explicit nullable type on parameter arguments
Implicitly marking parameter $... as nullable is deprecated in php8.4,
the explicit nullable type must be used instead

Created with autofix from Ide15839e98a6229c22584d1c1c88c690982e1d7a

Break one long line in SpecialPage.php

Bug: T376276
Change-Id: I807257b2ba1ab2744ab74d9572c9c3d3ac2a968e
2024-10-16 20:58:33 +02:00
James D. Forrester
bc662aec9b Move Language and friends into Language namespace
Bug: T353458
Change-Id: Id3202c0c4f4a2043bf97b7caee081acab684155c
2024-08-10 13:36:30 +02:00
James D. Forrester
8e940c4f21 Standardise all our class alias deprecation comments for ease of grepping
Change-Id: I7f85d931d3b79da23e87b4e5692b2e14be8fcaa0
2024-03-19 20:11:29 +00:00
Tim Starling
bd6ed0acdf Fix some spelling errors
Change-Id: I3632ce1ae00527f806652deb96cafb473aed3dcf
2024-03-18 20:58:11 +11:00
Timo Tijhof
08ddbf3465 parser: deprecate unused MagicWord::getId, improve docs and tests
* MagicWord::getId was added in r24808 (164bb322f2) but never used.
  At the time, access modifiers like 'private' were not yet in use.
  Deprecate the method with warnings, for removal in a future release.

* Fix zero coverage for MagicWord, due to constructor being
  internal, this is only intended to be created via array and
  factory classes. Let their tests cover this class.

* Remove redundant file-level description and ensure the class desc
  and ingroup tag are on the class block instead.
  Ref https://gerrit.wikimedia.org/r/q/owner:Krinkle+message:ingroup

* Mark constructor `@internal` (was already implied by
  stable interface policy), and explain where to get the object
  instead.

* Mark load() `@internal`. Method was introduced in 1.1 when the
  class (and PHP) did not yet use visibility modifiers for private
  methods. The only way to get an instance of MagicWord
  (MagicWordFactory::get) already calls load(), the method is not
  a no-op if called a second time, and (fortunately) there exist no
  callers to this outside this class that I could find.

* MagicWordArray::getBaseRegex was marked as internal
  in change I17f1b7207db8d2203c904508f3ab8a64b68736a8.

Change-Id: I4084f858bb356029c142fbdb699f91cf0d6ec56f
2023-10-26 16:07:20 +01:00
thiemowmde
6447dbc37b parser: Use more specific exceptions in MagicWord classes
… instead of the generic MWException and even more generic Exception.
Most, if not all of these should be unreachable anyway. I.e. these
are what we call "unchecked" exceptions, see T240672.

We also have a polyfill for preg_last_error_msg. No need to wrap it
in a function_exists (any more).

Change-Id: Ie26bef3b4371d011ec3f1874986072605692f486
2023-10-25 15:34:03 +02:00
thiemowmde
2e0301e634 parser: Add strict type constraints to MagicWord… classes
This patch is intentionally "incomplete". It's limited to places
where we can be 100% sure about the type just from looking at the
code. More to be done in later patches.

Change-Id: Ideea49ea9603127038ef08c6a9805f40a0b86b6d
2023-10-16 10:36:36 +02:00
thiemowmde
0a453b6c37 Remove meaningless /** #@- */ comments
Some of these comments are more than 20 years old. Almost all of them
are copy pasted from somewhere else, most certainly without knowing
what they mean. I can only guess that they have been part of some
ancient code folding feature that's not supported any more. Even if,
almost all of them are misplaced by now because the surrounding code
changed without updating the comments.

Change-Id: I53c37f050574a530ec772b7a07b67d84b31bb7a0
2023-10-15 12:30:28 +02:00
thiemowmde
7e83aa07d0 Don't cache trivial strings in the MagicWord class
4 strings are currently cached. But 3 are trivial derivatives from
the base one. This makes the code look more complicated than it is.
And we are wasting memory without knowing if the other strings are
ever needed.

These methods are not "hot", i.e. they are not called in a loop or
so.

Note the "initRegex" method removed in this patch was marked as
@internal. This means we really don't need to mention it in the
release notes. It makes zero sense to call it from the outside anyway.

Change-Id: I8606daaebc0dd5a8c7da5333841599c80763d75d
2023-10-06 16:58:32 +00:00
thiemowmde
7662dfeddc MagicWord: Make use of native count feature in preg_replace
The only reason for the callback was to check if a replacement
happened. We can do the same with the native $count feature.

Also inline a trivial sort() callback. It was effectively @internal
as it was obviously never meant to be used from outside of the class.

Both methods have been marked as public in I3588d9d. I think this
was just a mistake.

Change-Id: Ie33d4347f710fe227f9cbd8833c192c11d6e7c89
2023-10-05 17:05:38 +00:00
thiemowmde
231a562c37 Remove unused public methods from MagicWord & MagicWordArray
Remove unused methods:
https://codesearch.wmcloud.org/search/?q=%5CbmatchStart%5Cb
https://codesearch.wmcloud.org/search/?q=%5CbmatchVariableStartToEnd%5Cb
https://codesearch.wmcloud.org/search/?q=%5CbsubstituteCallback%5Cb
https://codesearch.wmcloud.org/search/?q=%5CbgetVariableRegex%5Cb
https://codesearch.wmcloud.org/search/?q=%5CbgetVariableStartToEndRegex%5Cb
https://codesearch.wmcloud.org/search/?q=%5CbgetWasModified%5Cb
https://codesearch.wmcloud.org/search/?q=%5CbaddArray%5Cb
https://codesearch.wmcloud.org/search/?q=%5CbgetVariableRegex%5Cb

Mark internal methods as private:
https://codesearch.wmcloud.org/search/?q=%5CbgetRegex%5Cb
https://codesearch.wmcloud.org/search/?q=%5CbgetRegexStart%5Cb
https://codesearch.wmcloud.org/search/?q=%5CbgetVariableStartToEndRegex%5Cb
https://codesearch.wmcloud.org/search/?q=%5CbparseMatch%5Cb

There is probably more, e.g. the "add" method, but this is much
harder to prove.

Change-Id: I4093489b309105d2272535fb92135f5052f96ab6
2023-10-04 02:24:37 +02:00
thiemowmde
4aa645573d Remove meaningless "brionmademeputthishere" from MagicWord class
The line is there since commit bf63ffaa from 2006, see
https://phabricator.wikimedia.org/rMWbf63ffaa
The idea is to have at least one synonym, even if it's meaningless.
Without this later code that expects at least one synonym would fail
or produce unexpected results.

… except exactly that happens with a non-sensical synonym like this.

The line is obsolete at least since I229e87a from 2012. Since then we
stop execution with an exception.

This patch is split from the larger refactoring I943842c to make that
easier to review.

Change-Id: Ic715b9f7b0cb7919f74d33a260edddd3158cffe9
2023-10-03 20:00:36 +02:00
thiemowmde
4a4b969bdd Remove MagicWord::addToArray without deprecation
Not used anywhere:
https://codesearch.wmcloud.org/search/?q=addToArray%5Cb

The motivation is to remove one of the two remaining uses of the
internal $this->contLang service to possibly remove it entirely in
a later patch.

Change-Id: I62982e6e329cc4a38a80b85eb4cb8eda97984dc3
2023-10-01 14:59:59 +02:00
James D. Forrester
14ab1a5276 Follow-up a1b4699: Add in-code comment on aliases for when they were added
Change-Id: I84266fd02edff7002c765f53d3ddee6085d922d4
2023-08-28 14:39:35 -04:00
thiemowmde
8a2b869945 Fix incomplete/broken ParserFactoryTest & ParserTest
Some details:
* Just use a real MagicWord object. It doesn't do anything that
  needs mocking.
* Add missing methods to mocks.
* Remove not needed details from mocks.
* Remove duplicate test that does the same.
* Remove pointless assertions that are impossible to ever fail.

Change-Id: I177242429a528d2c7109ca757840b538b772711c
2023-07-28 14:22:46 +00:00
Amir Sarabadani
a1b4699fea Reorg: Move MagicWord related files to under parser/
This is approved as part of T166010 RFC.

Bug: T321882
Change-Id: Ia4498c0a20e38a6a288dc14065ea8242c84fbc49
2022-12-09 13:48:35 +01:00
Renamed from includes/MagicWord.php (Browse further)