Commit graph

691 commits

Author SHA1 Message Date
Umherirrender
1b29f07440 Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: I73fb416573f5af600e529d224b5beb5d2e3d27d3
2024-10-21 20:41:20 +02:00
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
thiemowmde
b1c9ec74fa Remove meaningless @var documentation from constants
A constant is not a variable. The type is hard-coded via the value
and can never change. While the extra @var probably doesn't hurt much,
it's redundant and error-prone and can't provide any additional
information.

Change-Id: Iee1f36a1905d9b9c6b26d0684b7848571f0c1733
2024-10-09 09:33:12 +02:00
James D. Forrester
9e5c1e8ac7 Add namespace to IDBAccessObject and DBAccessObjectUtils
Bug: T353458
Change-Id: I23cf7991f8792d4d000d1780463d8ce76dc0aee0
2024-09-27 16:19:10 -04:00
Adam Wight
188d2cbbb0 Remove unchecked exception annotations
Callers should not catch an unchecked exception, so it doesn't belong
in a function signature.  Unchecked exceptions indicate a coding error,
which by definition the code will not be able to handle correctly.

If any of these exceptions were supposed to be in response to an edge
case, user input, or initial conditions, then they should be changed
to a runtime error.  If the exception class cannot be changed, then
the annotation should include a comment explaining its purpose and
prognosis.

Bug: T240672
Change-Id: I2e640b9737cb68090a8e1cb70067d1b74037d647
2024-09-17 22:20:58 +02:00
James D. Forrester
2b11d61577 Migrate all uses of deprecated URL global functions to use wfGetUrlUtils()
wfGetUrlUtils() is also deprecated, but less so, so we can do this first
and then properly replace the individual uses with dependency injection
in local pieces of work.

Also:
* Switching Parser::getExternalLinkRel to UrlUtils::matchesDomainList
  exposed a type error in media.txt where $wgNoFollowDomainExceptions
  was set to a string (which is invalid) instead of an array.

Bug: T319340
Change-Id: Icb512d7241954ee155b64c57f3782b86acfd9a4c
2024-09-10 16:50:02 -07:00
jenkins-bot
0de8854427 Merge "Avoid use of deprecated wfExpandUrl in various places" 2024-09-10 12:57:54 +00:00
Ebrahim Byagowi
aa16b5e7e6 Avoid use of deprecated wfExpandUrl in various places
Bug: T319340
Change-Id: I98e8e3a8fd135a554a85f6399033756c88ea415f
2024-09-09 20:55:52 +00:00
jenkins-bot
7de2cb299f Merge "search: Simplify host name logic in InterwikiSearchResultSetWidget" 2024-09-09 14:58:38 +00:00
Umherirrender
6c81485143 search: Add missing documentation to class properties
Add doc-typehints to class properties found by the PropertyDocumentation
sniff to improve the documentation.

Once the sniff is enabled it avoids that new code is missing type
declarations. This is focused on documentation and does not change code.

Change-Id: I2606072015d71b4bdda70a7c149d9f55ac205a3c
2024-09-07 21:56:00 +02:00
Timo Tijhof
85cca4408e search: Simplify host name logic in InterwikiSearchResultSetWidget
* footerHtml() contained seemingly unused logic for extracting
  the host name for use in the "search-interwiki-resultset-link"
  message.

  This was added during in change I9498a070da (T307468, 0d1184e501).
  It seems to be a left-over from the "search-interwiki-default"
  message that Special:Search used previously.

  Overrides for specific wikis are now in the heading based on the
  the "search-interwiki-custom" message, which feeds customCaptions
  which takes precedence over the entire message, instead of requiring
  wikis to e.g. switch/if-case inside wikitext based on "$1" or something.

  The qqq.json entry for "search-interwiki-resultset-link" mentions
  no parameters, and none of the translations use it either. I've
  also checked WikimediaMessages extension, en.wikipedia.org, Commons,
  and Wikidata in case they use the parameter there, but found nothing.

* headerHtml() used wfExpandUrl() combined with wfParseUrl().

  This is problematic for Phan analysis since both can fail and
  technically require a fallback. This is currently tolerated by Phan
  because it doesn't yet understand that `false[key]` yields the
  same kind of warning PHP as `null[key]`.
  https://github.com/phan/phan/issues/4879

  It seems this code has evolved over the years into what it is
  now, and it's not clear that this is all intentional or by design.

  In 2011, r95011 (92ff782a9) changed this code from parse_url to
  wfParseUrl to handle protocol-relative URLs, which has long been
  fixed in PHP: https://3v4l.org/sSkfX.

  In 2017, If78cb0c29a (6e155624fa) changed further switched from
  Title->getUrl() to Interwiki->getURL() with wfExpandUrl() to handle
  same-site destinations, e.g. when an interwiki is on the same
  domain, and defined on Special:Interwiki without any hostname.

  The code had a note saying:
  "hostname of the other wiki which might suck if there are many wikis
  on one hostname" which appears to remain true today.

  I've changed this all back to parse_url(), with an explicit fallback
  to $iwPrefix for invalid urls or same-site interwikis. If we
  want to display the current domain name there instead, we can do
  that explicitly by falling back go $wgServerName instead.

* Fix potential escaping problem by pasing $caption to element()
  instead of rawElement() since in headerHtml() at least one of the
  values in the assignment chain caption is plain text, not escaped
  HTML. Move escaping down to the last mile by storing plain text
  instead.

  Idem for footerHtml(), although that one is safe and simple as-is,
  I've switched it similarly to plain text and let Html::element do
  the escaping.

Change-Id: I3281e12ee52af168f85cdb12ac4d53fc25c9f38d
2024-09-07 12:30:03 -07:00
Umherirrender
cfa2cf73ff search: Replace IResultWrapper::fetchObject()/next() with foreach loop
Avoid assigment in conditions
foreach starts at begin of iterator, the while loop can process the next
from within the result, but all the iterator in search are rewinded
before iterator starts

Change-Id: I38b2729418e8389c681c6cd84858f5e5ed25bd3e
2024-08-31 23:58:02 +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
Ebrahim Byagowi
697e19e461 Add MediaWiki\Registration namespace to registration classes
Bug: T353458
Change-Id: Ifa3b6a6e0353bb4ce21a3f4456f1fc696c8d377c
2024-08-10 10:08:22 +00:00
Bartosz Dziewoński
c045fa0291 Replace gettype() with get_debug_type() in exception messages
get_debug_type() does the same thing but better (spelling type names
in the same way as in type declarations, and including names of
object classes and resource types). It was added in PHP 8, but the
symfony/polyfill-php80 package provides it while we still support 7.4.

Also remove uses of get_class() and get_resource_type() where the new
method already provides the same information.

For reference:
https://www.php.net/manual/en/function.get-debug-type.php
https://www.php.net/manual/en/function.gettype.php

To keep this safe and simple to review, I'm only changing cases where
the type is immediately used in an exception message.

Change-Id: I325efcddcb58be63b1592b9c20ac0845393c15e2
2024-07-31 19:24:39 +02:00
Umherirrender
fc9e42823b rdbms: Create IReadableDatabase::andExpr() / ::orExpr()
Avoid the call to internal constructor of AndExpressionGroup and
OrExpressionGroup by creating a factory function similiar as the
IReadableDatabase::expr function for Expression objects.

This is also a replacement for calls to ISQLPlatform::makeList with
LIST_AND or LIST_OR argument to reduce passing sql as string to the
query builders.

Created two functions to allow the return type to be set for both
expression group to allow further calls of ->and() or ->or() on the
returned object.
Depending on the length of the array argument to makeList() it is
sometimes hard to see if the list gets converted to AND or OR, having
the operator in the function name makes it easier to read, so two
functions are helpful in this case as well.

Bug: T358961
Change-Id: Ica29689cbd0b111b099bb09b20845f85ae4c3376
2024-07-11 15:29:20 +00:00
Daimona Eaytoy
6469955810 Replace User, Title, and WikiPage in more signatures
Change-Id: I04e408e734edc5498c32c4433f02da613bbfafa6
2024-07-10 01:25:57 +02:00
Lucas Werkmeister
1bf941ea4c PrefixSearch: Make sure $prefix is a string
PHP always turns numeric array keys into integers.

Bug: T365565
Change-Id: I74b878f8212a6d6647f5236e85e30982ff18b48e
2024-05-22 12:35:28 +02:00
Ebrahim Byagowi
b5727d94b5 Import InvalidArgumentException at top of the source
It was asked in a patch review to apply fully import
InvalidArgumentException where possible. I was guessing some
of my other already merged patches have but turned out such
thing exists other places style so for the sake of consistency
I've turned rest of inline import of the specific exception at
top of the file.

There are instances of source files that aren't in any namespace but
have fully qualified import which this patch doesn't touch.

Change-Id: I4071fc698b65746d9594cf4d5f45bae82843d436
2024-05-19 23:57:44 +03:30
Func
4e6158a6fb Use constants provided by MainConfigNames for config names
Change-Id: I2f29ea8227da64b79b70fcce3decb6e34ea8da5b
2024-05-18 01:26:46 +08:00
Ebrahim Byagowi
14b4269d83 Add namespace and deprecation alias to Xml and XmlSelect
This patch introduces a new namespace declaration,
MediaWiki\Xml and adds Xml and XmlSelect to it
and establishes class aliases marked as deprecated
since version 1.43.

Bug: T353458
Change-Id: I45cccd540b6e15f267d3ab588a064fbeb719d921
2024-05-16 15:23:14 +03:30
Derk-Jan Hartman
0370a340f5 Search: Remove layout table from search results with images
Using tables for layout is no longer necessary so replace with some
flex based divs

Bug: T320295
Change-Id: I012ef8446505b4ae1b73362fde0293659d91926e
2024-05-04 07:40:45 +00:00
James D. Forrester
8f6939f594 docs: Adjust all @deprecated tags to use 'since…' for consistency
This skips ones that have been marked but were never in the then
RELEASE-NOTES and later HISTORY file, and so weren't properly
deprecated ever.

Change-Id: I31df2d7e83182b5bf9524237fc4a1862356bfd5a
2024-05-01 07:41:18 +01:00
Umherirrender
8d97313f81 Fix some line indent
Change-Id: I8f82724197d20f9289d80e138d80310f1eab29f2
2024-04-20 00:25:15 +02:00
Derick Alangi
791cb9f676
search: Use ServiceOptions not full config object
This patch uses the recommended MW practice for injecting
settings into MW services. Instead of passing in the full
config object, pass in service options which MW service wiring
will use to lookup settings/options from config sources.

So in this patch, the various options have been identified
and put into `CONSTRUCTOR_OPTIONS` constant and inject via
service wiring.

Test plan
=========
Ensure that the special page: `Special:Search` still works
with this patch checkout on your local test wiki.

When you visit `Special:Search` on your local wiki, you should
see a search form view. Type in something like: "Main Page" and
then hit search. If everything works well, then local test passes.

NOTE
====
This patch also resolves a TODO which mentions the removal of
the `getConfig()` method from the SearchEngineConfig class.

Change-Id: Ib5dfc10f3f210c6c35247f4f30f9549dd60e0af7
2024-04-16 15:50:43 +01:00
Umherirrender
96ecf0f528 Fix use of ReplaceQueryBuilder::rows
Follow-Up: I446f7a09cfc0ee37c2e016052d452751f7333e27
Change-Id: Id8c56b1479860f4d8903e626b337362d10d6a8e0
2024-04-01 23:57:03 +02:00
jenkins-bot
2611aa6e86 Merge "search: Exclude unlisted special pages from search completion" 2024-03-28 09:43:37 +00:00
Peter Fischer
64e6a78af3 search: Exclude unlisted special pages from search completion
Pages that are "unlisted", i.e. SpecialPage::isListed returns false,
are now excluded from auto-completion. These are essentially pages
that are for scripted/non-human purposes (e.g. Special:RunJobs) and
redirect pages (e.g. Special:AllMyUploads).

Note that redirect pages can opt-in to being listed, and thus do
appear on Special:SpecialPages and thus remain included in search
suggestions, such as Special:Diff.

This patch creates a getListedPages utility instead of re-using
SpecialPageFactory::getRegularPages for two reasons:

1. Consistency with Special:SpecialPages.
2. Avoid hiding major and popular user-facing features that require
   logging in and/or some user right, such as Special:Watchlist,
   Special:Block, and Special:Upload.

This patch doesn't use SpecialPageFactory::getUsablePages because it
is unsafe outside index.php page views (invokes user session), and
make the results incompatible with HTTP caching of OpenSearch API.

Bug: T358938
Change-Id: I1cb5f4c3cedb02eb41fcac3b8f785616ce54d73c
2024-03-26 17:52:33 -07:00
Umherirrender
21f0934037 Type hint IReadableDatabase on IConnectionProvider::getReplicaDatabase
Only docs needs adjust, but phan is using this needs changes in the
search related classes.
Doc change in IForeignRepoWithDB is needed, the implementation in
LocalRepo returns the value from IConnectionProvider::getReplicaDatabase

Change-Id: I01a1aa0ddbc756226d8e3404ac1cc3350ad5df64
2024-03-16 16:02:11 +00:00
Umherirrender
6cd2182169 Combine the expressions in PrefixSearch::defaultSearchBackend
Avoid use of array

Bug: T358961
Change-Id: I1ef1e815a087ad323727b1fcbe38cde1cfd3cdaa
2024-03-02 20:00:51 +00:00
jenkins-bot
8c867a6944 Merge "db: Better Error messaging when Title search query not compatible with db Engine" 2024-02-21 19:42:38 +00:00
Atieno
4833dc0fb2 db: Better Error messaging when Title search query not compatible with db Engine
Bug: T355096
Change-Id: I7aba39fd3c19522b576ad38d69479e109e645538
2024-02-21 21:06:08 +03:00
James D. Forrester
eeb5a740b3 Namespace Message, move to appropriate directory
Bug: T353458
Change-Id: I088cbc53fbcdb974e5b05b45a62e91709dacc024
2024-02-14 15:10:36 -05:00
Amir Sarabadani
ea268ddcfd Move away from wfGetDB() calls
If we are serious about getting rid of wfGetDB(), we should start
replcing callers with proper replacement.

These classes don't have any injection so it doesn't make sense to
introduce it for this specific usecase.

Bug: T330641
Change-Id: I645f67324d441288c63787c7e42390b59106c585
2024-02-12 21:23:38 +01:00
Brooke Vibber
dcd9c3ae26 Update name & email for bvibber
Updating name & email addresses for Brooke Vibber.

Re-ran updateCredits.php as well so there are some new entries in
there as well.

There are a couple of files in resources/libs that will have to
be changed upstream to keep tests happy, I will do patches
later. :D

Change-Id: I2f2e75d3fa42e8cf6de19a8fbb615bac28efcd54
2024-02-08 17:02:16 -08:00
jenkins-bot
144203093a Merge "Remove more indirect calls to IDBAccessObject::READ_* constants" 2024-01-23 15:07:51 +00:00
Amir Sarabadani
014bc61006 Remove more indirect calls to IDBAccessObject::READ_* constants
Found via (?<!IDBAccessObject)::READ_

We are planning to deprecate and remove implementing IDBAccessObject
interface just to use the constants.

Bug: T354194
Change-Id: I89d442fa493b8e5332ce118e5bf13f13b8dd3477
2024-01-23 15:42:38 +01:00
Derick Alangi
4e468b49e0 title: Make TitleArrayFromResult via TitleFactory service
The TitleFactory should really be where TitleArrayFromResult should
live as it's a place where Title objects are created based on certain
specifications.

This patch tries to consolidate the creation of TitleArrayFromResult
via the TitleFactory services and in the future, we will consolidate
more of the logic and kill TitleArrayFromResult.

Follow up on: a99ec1b and e54665d.

Change-Id: I98215af3252d756de4435b77d1280dacda8e85dc
2024-01-23 14:07:07 +00:00
Dogu
137d046c12 Replace all the OOUI qualifiers with imports
List of affected classes:
- TablePager
- DefaultPreferencesFactory
- SignatureValidator
- SearchFormWidget
- SpecialUndelete

Change-Id: I63ba23108adb16ee4f8b0f965b05605c70ff7957
2024-01-07 21:17:57 +00:00
Dogu
28be134023 Add parent constructor call in FauxSearchResult
This patch amends the FauxSearchResult class by
adding a call to the parent constructor within its own
constructor method. Previously, the FauxSearchResult
class was not calling the parent's constructor, which
could lead to initialization issues.

Change-Id: Ib3d569daa49605e32b3bf2675d41ab20c6a000eb
2024-01-02 18:46:20 +01:00
Dogu
4e42db6b74 Replace OutputPage qualifier with import
Change-Id: I4f5b5e5953ac1910bb1abb0052160ee75d6f35f0
2024-01-02 11:47:32 +01:00
James D. Forrester
9bfb75ff90 Namespace ParserOutput
Most used non-namespaced class!

Bug: T353458
Change-Id: I4c2cbb0a808b3881a4d6ca489eee5d8c8ebf26cf
2023-12-14 14:57:34 -05:00
Martin Urbanec
29af4dd074 Move user options related classes into its own namespace
There are a couple of user options related classes already,
and the T321527 work on dynamic defaults is going to add
even more. Let's move them into a separate namespace
to make core a bit more organized.

Old name is kept as an alias for compatibility purposes.

Bug: T321527
Bug: T352284
Change-Id: I9822eb1553870b876d0b8a927e4e86c27d83bd52
2023-11-29 13:27:13 +01:00
Theodore Dubois
efe862a8f2 Prioritize search index over page namespace index
I was getting terrible performance on searches, and discovered that the
query planner was first using the page namespace index to quickly find
pages with the right namespaces, then doing a separate full text search
for each page. To fix this durably, use CROSS JOIN instead of "," for
the join, which is semantically the same but acts as a hint to the query
planner that indexes on the first table listed should be searched first.
https://www.sqlite.org/optoverview.html#manual_control_of_query_plans_using_cross_join

Change-Id: I756f6b43f84894c76e46b3a3221107d9834a493a
2023-11-28 19:47:39 -08:00
Tim Starling
f0464fbe78 Fix exception from SearchPostgres when slot_roles is empty
Change-Id: Ie36bbbc1d091fdb3942e5822ce65346980640278
Needed-By: Ie2f1809dac243ef06ba0c34f039ce4e62cbf99cf
2023-11-21 10:35:54 +11:00
Amir Sarabadani
8fcd7726e9 Migrate all non-API code to use expression builder instead of buildLike
Bug: T210206
Change-Id: Icf3a2c5e5fb40ff31c65ba182937510d44186e46
2023-11-07 18:53:18 +01:00
David Causse
02a9ab7833 search: prefer user typed form when re-ranking a redirect to the top
When the search engine returns a match to a redirect R1 pointing to a
page P1 as part of its results, if the user typed an exact match to
another redirect R2 that targets the same P1 we should:
- rerank R1 to the top (what was done)
- replace R1 with R2 as the preferred form (what is done now)

Bug: T346920
Change-Id: I77c4870aacb9c3ffa215cc0b0f3c417484cc98fd
2023-10-25 10:59:52 +02:00
David Causse
81b69df5ea SearchSuggestionSet: update pageMap when shrinking
the pageMap is a cache of page ids often used to quickly verify the
presence of a page in the set.
When shrinking this map should be updated to properly reflect the set of
page ids.
Not keeping pageMap updated caused a bug to appear when the exact match
is found by the underlying search engine at position limit+1 (overfetch
technique). Shrinking the set to limit did not properly remove the exact
match entry from pageMap which prevented the prepend method from adding
the exact match as part of the SearchExactMatchRescorer.

Bug: T347786
Change-Id: Id524cc5af8e62e64f0a680b8e08078d14872f97d
2023-10-11 16:16:01 +02:00
jenkins-bot
c7fe8a109d Merge "Revert "Revert "Remove unused class_alias deprecated in MW 1.40""" 2023-10-03 17:03:31 +00:00
Derick Alangi
a99ec1b4fa
Title: Use TitleArrayFromResult instead of TitleArray
TitleArray is just a tiny little wrapper to TitleArrayFromResult,
so use the latter instead of the former. I have plans of killing
the former soon.

Change-Id: Ia06a6bb370ce313f38d3ec9a221ed7296aec0ee2
2023-10-03 11:18:53 +01:00