Commit graph

127 commits

Author SHA1 Message Date
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
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08:00
jenkins-bot
cab00f54ab Merge "Return HtmlArmor for Search ResultSet snippets" 2019-12-13 08:27:35 +00:00
Erik Bernhardson
0c8289e5db Return HtmlArmor for Search ResultSet snippets
Passing around strings that are expected to be safe html and are
known to be based on user input is a fairly unsafe operation. Make
it harder to do the wrong thing by requiring HtmlArmor to be returned
from the ResultSet snippets. This does not address the snippets on
individual result objects as the api surface is larger and requires
more bc handling.

Change-Id: I76231d6fc53c4982eb4cd174d2e6a75eb2740497
2019-12-12 10:14:50 -08:00
Umherirrender
c7ad21c25f Improve param docs
Change-Id: I746a69f6ed01c3ff000da125457df62b02d13b34
2019-11-28 19:08:59 +01:00
David Causse
6af636fb03 Add ISearchResultSet
Bug: T228626
Change-Id: I3306bf6107c97dd58adf578fd965bd11a422627d
2019-07-22 18:27:39 +00:00
David Causse
92c20832f1 Deprecate SearchResult::termMatches()
And start indicating that hooks relying on this data might become
unreliable as this data is only populated by SearchDatabase search
engines.

This information was only populated by SearchDatabase implementations
and due to bad initial design of SearchResult[Set] (now fixed) it forced
users of these classes to carry this information for the sole purpose of
highlighting.
Because SearchEngine can now own their SearchResult[Set] implementations
nothing that is engine specific should be exposed outside of these
specific implementations.
If there are some logic that still requires access to such list of terms
they should be made engine specific by guarding their code against
instanceof SqlSearchResult.

Change-Id: I38b82c5e4c35309ee447edc3ded60ca6a18b247a
Depends-On: I53fe37c65c7940f696c1e184125e01e592a976e4
2019-06-27 08:44:06 -07:00
Derick Alangi
f9f2809a38 SearchEngine: Hard deprecate SearchEngine::transformSearchTerm()
As a follow up of it's soft deprecation in 1.32, this method should
be hard deprecated and removed. Also, remove related code that calls
this method.

Usage:

https://codesearch.wmflabs.org/search/?q=(%3A%3A%7C-%3E)transformSearchTerm&i=nope&files=&repos=

Bug: T221431
Change-Id: I623b39e7ec791a66c4cf40178edb80b2ebf4bb06
2019-04-26 19:24:02 +00:00
Max Semenik
e6818e6c64 Fix unused vars/pointless assignments
Change-Id: If475c738b4af7208024c866594d4c0048af053dd
2019-03-29 16:52:48 -07:00
Umherirrender
40d3ce8d17 Reduce calls to MediaWikiServices::getInstance()
In some functions MediaWikiServices::getInstance() was called twices or
in loops. Extract the variable to reduce calls.

Change-Id: I2705db11d7a9ea73efb9b5a5c40747ab0b3ea36f
2018-08-18 06:02:39 +02:00
Aryeh Gregor
90d4f56fe4 Mass conversion of $wgContLang to service
Brought to you by vim macros.

Bug: T200246
Change-Id: I79e919f4553e3bd3eb714073fed7a43051b4fb2a
2018-08-11 22:44:29 -06:00
David Causse
cf41c48f8d Deprecate SearchEngine::replacePrefixes
This should be handled internally by SearchEngine implementations.

Bug: T198860
Change-Id: Ifbfd0fcb81fcacf5228bd2ffcac7b80fca872b2a
Depends-On: I7d4ff9498fa1f4ea66835c634b8931f4c29993fb
2018-07-17 21:56:14 +00:00
David Causse
46c17ddb1f Deprecate usage of SearchEngine:transformSearchTerm
This method was introduced in 4115586000
to support the prefix URI param introduced by the InputBox extension.
There are no reasons that this logic is exposed to SearchEngine users
and should be handled internally by SearchEngine implementations
that supports it.
Previously the search query was updated, now the prefix param will passed
along using SpecialSearch::$extraParams.

Bug: T198318
Change-Id: I33518d3f3ddee741ff4f3b47eb4928009bea66d1
Depends-On: I67c7f1886dd6a2d07c12015e2711c138e9f140e9
2018-07-17 14:41:08 -07:00
jenkins-bot
1abed55d47 Merge "Expose sort orders from search engine in ApiQuerySearch" 2018-06-13 16:29:36 +00:00
Erik Bernhardson
7bf3c40506 Expose sort orders from search engine in ApiQuerySearch
Selectable sort orders were added to search some time ago, but never
appear to have been used.  Expose them in ApiQuerySearch.

There is one large problem here, but it's not easily solvable.
Specifically supported sort orders vary per search engine, but the
available api parameters are calculated with the default search
engine. This is already a problem with search profiles so it's
nothing new, just continuing the existing problem. Much like
search profiles we hide the functionality when multiple engines
are available.

Bug: T195071
Change-Id: I187a530bc973c08386d2c2126e02a85b952d9022
2018-06-13 08:57:16 -07:00
Erik Bernhardson
2a43939ffb Push pagination decision for search into SearchEngine
Various code using the search engine shouldn't need to implement it's
own methods, such as over-fetching, to determine if there are more
results available. This should be knowledge internal to search that is
exposed by a boolean.

Change-Id: Ica094428700637dfdedb723b03f6aeadfe12b9f4
2018-06-11 13:35:44 -07:00
Erik Bernhardson
c2a308075f Convert SearchResultSet to typical iteration
The funky iteration here was at best annoying. Switch
it over to an iterator based approach with appropriate
BC code to simulate the old iteration style.

Depends-On: I19a8d6621a130811871dec9335038797627d9448
Change-Id: I9fccda15dd58a0dc35771d3b5cd7a6e8b02514a0
2018-06-11 13:35:41 -07:00
Umherirrender
c9d303d39e Remove "Created on" from file header comments
It is the job of git and svn to provide this information/metadata.
The form was different, some with short, some with long month name
some with leading zero at the day, some without.
The year is also present in the Copyright clause

Change-Id: If006907b82b9e45f13cfa2e45d41107a95570e1a
2018-01-26 23:12:40 +00:00
Stanislav Malyshev
769d8a6262 Add parameter for query/search to fetch augmented data.
Bug: T182145
Change-Id: I54b50a1474b885ebe52900fd50729d6353e07807
2017-12-07 14:49:07 -08:00
Mako Bates
c30ef98293 Add page id to the API representation of pages in search results
'pageid' is now an always-on property returned by API:Search.
Change made in ApiQuerySearch.php::getSearchResultData().

Bug: T172700
Change-Id: I9d856efdd1d72c70bf9fb72c82b1f276abef8b16
2017-08-09 21:54:44 +00:00
Brad Jorsch
e2c949677e API: Add the ability to flag parameter values as deprecated
This has a number of implications:
* A deprecation warning is automatically generated if the value is used.
* action=paraminfo can list it in a machine-readable manner.
* It is automatically flagged in the help when message-per-value mode is
  used.
* In values lists in the help, it's specially marked (currently
  strike-through).
* ApiSandbox will mark it in the widgets (currently strike-through).

Deprecation of submodules is not automatically detected here, that's
left for a later patch.

Bug: T123931
Change-Id: Idad6377063e457f9352a99df5c7cc15b1563579e
2017-06-20 11:41:26 -04:00
Baha
036b9c4167 Make API documentation links language aware
Links generated by the API are now aware of the user's preferred
language and will show documents in that language if available.

To test, log in to mediawiki.org and set your language preference to 'es',
then on an MediaWiki installation with this patch view the generated
expanded API help at `api.php?action=help&recursivesubmodules=1&modules=main`.
Each link to documentation on mediawiki.org should take you to its
translated /es subpage, if one exists.

Bug: T104518
Change-Id: I339a1f3ae1bce9d759cf251899d57c32b1def91e
2017-04-05 11:08:25 -04:00
David Causse
99a20f06d7 Do not exit the run method in case of a missing rev
We should ignore broken/missing titles and not stop the whole process.

Change-Id: Ib4acb739c28c5f3278430b43b6304af3a513085e
2016-12-19 19:02:30 +01:00
jenkins-bot
4721eb350a Merge "Enable supplying inline interwiki results" 2016-12-15 19:22:39 +00:00
Brad Jorsch
4e6810e4a2 API: i18n for warnings and errors
API warnings and error messages are currently hard-coded English
strings. This patch changes that.

With a few exceptions, this patch should be compatible with non-updated
extensions:
* The change to ApiBase::$messageMap will blow up anything trying to
  mess with it.
* The changes to the 'ApiCheckCanExecute' hook will cause a wrong
  (probably unparsed) error message to be emitted for extensions not
  already using an ApiMessage. Unless they're currently broken like
  Wikibase.

Bug: T37074
Bug: T47843
Depends-On: Ia2b66b57cd4eaddc30b3ffdd7b97d6ca3e02d898
Depends-On: I2e1bb975bb0045476c03ebe6cdec00259bae22ec
Depends-On: I53987bf87c48f6c00deec17a8e957d24fcc3eaa6
Depends-On: Ibf93a459eb62d30f7c70d20e91ec9faeb80d10ed
Depends-On: I3cf889811f44a15935e454dd42f081164d4a098c
Depends-On: Ieae527de86735ddcba34724730e8730fb277b99b
Depends-On: I535344c29d51521147c2a26c341dae38cec3e931
Change-Id: Iae0e2ce3bd42dd4776a9779664086119ac188412
2016-12-06 10:20:48 -05:00
Stanislav Malyshev
bf054f7602 Enable supplying inline interwiki results
"Inline" interwiki results are added as "additionalsearch" section to the results,
if enablerewrites are turned on.

Bug: T142795
Change-Id: I1c14179ee4fb72b6b84772074b6d231d1129ac14
2016-12-05 19:11:13 -08:00
Erik Bernhardson
362be5bb90 Accept 'OK' status results from search engine
Historically code that talks to the SearchEngine has been treating
anything other than a 'Good' result, such as results but with a warning
(perhaps the query timed out and only gave partial results) as a
complete failure. Adjust the handling to report results from an 'OK'
status response while attaching any warnings to the api response, or
in a notiable red box on Special:Search.

Bug: T134157
Change-Id: Ic5e0db727790f4fd189caa54ea5f01672d6a8ea4
2016-11-29 15:24:52 -08:00
dcausse
179979c323 Pass interwiki option to SearchEngine
Currently interwiki result are always computed even if the client does
not request them.
Pass the option via featureData to allow SearchEngine not to run
interwiki searches when not needed.

Bug: T147003
Change-Id: I55067bc7e5d926a3e37f4d24fb8e085bd252c376
2016-09-30 16:53:03 +02:00
Max Semenik
068e0e6ca0 Remove/actualize unused imports
Change-Id: I6ef19d5d982aa45dbf5554107ad9ee720442f466
2016-09-26 17:03:26 -07:00
Max Semenik
2b51bd1847 Fix function name case
Change-Id: Ibd4f682d2ed8500a50d85aae38f17281646f7c2d
2016-09-26 15:32:54 -07:00
jenkins-bot
d1ac58cd85 Merge "Push common search api parameters into SearchApi class" 2016-07-27 09:18:33 +00:00
Erik Bernhardson
5da2c4197d Push common search api parameters into SearchApi class
We have a number of parameters that are pretty much the same between
these different search api's. Lets make them actually the same by
sharing the definitions, and then letting individual classes tweak them
as needed by removing the offset, or adjusting the max limits as
necessary.

Change-Id: I6f987db8ecb63dc943b4d2518bfe3703c677448e
2016-07-26 08:56:00 -07:00
Erik Bernhardson
5a25b01376 Repair interwiki search via api
This was throwing exceptions, probably for many months now, when
requesting and finding interwiki search results. Probably this went
unnoticed due to interwiki search only being enabled on itwiki, and
the requirement to pass a special parameter to turn it on.

Change-Id: I68ec35bb072b5ad62dd66789936bc2ae47d5256f
2016-06-30 15:55:20 -07:00
Erik Bernhardson
af6e349f67 Don't reuse variable names
This code was rather hard to follow due to reusing the same variable
multiple times. Lets give them unique names.

Change-Id: I8f134b6314d593a3e40b19765c7b71496b8e524d
2016-06-30 15:17:21 -07:00
dcausse
31680aaddc Expose SearchEngine specific profiles
This patch introduces a way for SearchEngine implementations to expose
specific search profiles useful to fine-tune the various behaviors related to
search.

A SearchEngine can expose a list of profiles by overriding
SearchEngine::getProfiles( $profileType ), profileType stands for the type of
profile being customized. Two types are added in this patch:
- completion: exposed by ApiQueryPrefixSearch and ApiOpenSearch to control
  the behavior of the algorithm behind "search as you type" suggestions.
- fulltext query independent profiles: exposed by ApiQuerySearch to customize
  query indpendent ranking profiles (e.g. boost by templates/incoming
  links/popularity/...)

This patch allows api consumers that might have been confused by fuzzy
suggestions to switch to stricter profiles and to officialize the behavior
behind the hidden param cirrusUseCompletionSuggester. Or to control the
fulltext ranking behaviors like cirrusBoostLinks=(yes|no).

The list of profiles can be discovered by using ApiSandbox/ApiHelp and is totally
controlled by search engine implementations.

Bug: T132477
Change-Id: I66be724d8975976c98c91badbf421f237e014f89
2016-05-30 20:43:53 +02:00
Stanislav Malyshev
34b02d87ac Convert SearchEngine to service containers
Change-Id: Icef1ecbed3d831557e0256fdfa53743b194007cc
2016-04-25 16:25:17 -07:00
umherirrender
932c37e3cb Use english messages for background use of Status::getWikiText
Status::getWikiText is used for internal logging, api error messages and
maintenance scripts. All this places are usually in english, so pass an
english language to getWikiText.

Change-Id: I3010fca8eb5740a3a851c55a8b12e171714c78f7
2016-04-12 20:01:44 +02:00
Brad Jorsch
ce3d55d6b7 ApiQuerySearch: Match limits to those in Special:Search
The limits were decreased in r55615, but no one seems to remember why.

Bug: T119189
Change-Id: I622203195ed5dbed9548bb4a9a6acdab8e3bc3ed
2016-02-24 16:22:39 -05: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
jenkins-bot
376879ee06 Merge "ApiBase::PARAM_DFLT => null is the default anyway" 2015-10-26 19:02:33 +00:00
Erik Bernhardson
1ded833de1 Implement ApiPageSet::setRedirectMergePolicy()
This allows generator implementations to define how generator data
about a redirect gets merged into the redirect destination.  This
does not change any defaults, only modules that explicitly set a
merge policy will have a change in their results.

This functionality is initially used for the search api modules to
retain search positions within the final result set.

Bug: T92796
Change-Id: If2f49e0fc3176288c95e870240754ee320a6bf91
2015-10-08 11:36:02 -07:00
Thiemo Mättig
3ecd418501 ApiBase::PARAM_DFLT => null is the default anyway
Change-Id: Ic3deeb6b3d7cacbdb85da9ba3cb19051c1182b8f
2015-10-05 10:56:32 +02:00
Erik Bernhardson
23acf6e70f Move query rewriting into search backend
Special:Search recently gained query rewriting behavior when the
original query returned no results.  We want to expose this query
rewriting behavior to both api and web requests.  Additionally we
want to be able to test different configurations of the query
suggestions.  This patch allows for both by moving the rewriting
from core into the search backend.

This defaults to enabled for Special:Search, and disabled for
ApiQuerySearch. Internal code that talks to the search backend
needs to specifically enable this feature.

Bug: T106888
Change-Id: I0a8f75759f9148f53358707369b8a7128215de86
2015-08-31 22:41:05 -07:00
umherirrender
ff7327720d API: Use message-per-value for apihelp-query+search-param-prop
Use message-per-value for message
apihelp-query+search-param-prop to allow smaller strings
for translation.
Each prop in a message also will show up a new parameter on the help
page without the adjust of the translation (but than in english instead
of fully skip it).

Change-Id: Id2088213f4577c8cb88e479e8fca0e6bd3d619f4
2015-08-06 09:38:57 +02:00
Vivek Ghaisas
9f5b6f5aeb Fix whitespace issues around parentheses
Fix issues found by MediaWiki.WhiteSpace.SpaceyParenthesis sniff.

Bug: T102617
Change-Id: Iec7f71e64081659fba373ec20d9d2006306a98f4
2015-06-16 22:14:02 +03:00
Erik Bernhardson
2a4675a17f Make api nearmatch search work same as 'go' feature
The 'nearmatch' feature of the api is the same as the 'go' feature of on-wiki
search. This makes the nearmatch api feature return the same results as the user
would have gotten in 'go', bringing more parity between api and browser based
searching. Without this change asking for a nearmatch within a namespace fails.

Bug: T37719
Change-Id: I715326242b63c558572ce9bf69b70bd650c2bc95
2015-05-05 16:31:17 -04:00
Erik Bernhardson
87558fc80b Increase parity between api search and on-wiki search
The on wiki search indicates more information than is currently
available by api.  Adds two more props to improve parity:

* categorysnippet: similar to the other snippets, about the category
  that triggered the match
* isfilematch: indicates if the match was part of file content

Additionally when 'suggestion' is included as part of the searchinfo,
'suggestionsnippet' is now also returned.

Change-Id: Ibf18905775a79caed213aca1bdebcffe3644c23b
2015-04-30 08:52:04 -07:00
Brad Jorsch
1c57794e37 API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.

ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.

So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
  arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
  Formatters are responsible for stripping it if necessary. "raw mode"
  is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
  question, and so on.
* New class for formatting warnings and errors using i18n messages, and
  support for multiple errors and a more machine-readable format for
  warnings. For the moment, though, the actual output will not be changing
  yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
  between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
  modules currently returning booleans will need to use
  ApiResult::META_BC_BOOLS to preserve their current output.

Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.

Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2015-04-10 16:57:15 -04:00
Brad Jorsch
d43e51a42c API: Don't dump Title object into API result
The intention here is to return the title as a text string, not to dump
all the internal fields of Title.

Bug: T88397
Change-Id: I43ad3c98bc1fc056a13f57e2e95a122108049334
2015-02-03 10:01:08 -05:00
Chad
a04e11786c Revert "Keep backend param to search API as long as there's a backend"
Actually on second thought, having the parameter disappear is 
a better option than keeping it around with only one possible 
value.

This reverts commit 7a79b017a0.

Change-Id: Ia67fa1425e0aa1ee95e0a1733f89d29f94f1eeee
2015-01-06 18:50:14 +00:00