Commit graph

44 commits

Author SHA1 Message Date
Timo Tijhof
217d47d46e Replace direct use of $wgRestPath with wfScript()
Follows-up Idb5b0d21adc6. Avoid hardcoded references to REST internal
configuration variables, which create awkward "APIs" in the long run.
These are hard to deprecate or detect use of, and even harder to
normalize/support once variations exist. E.g. in T189966 and T233886,
I've been working to remove the concept of dynamic config in favour of
the uncomputed values being only valid as configuration for the
component that owns the variable, instead of using Config as public
API to read non-normalized information that belongs to a different
component.

By making the recipient responsible for any dynamic computation, it
also becomes clear that these are in fact not normalized or validated,
which can expose any number of unpredictable behaviours if used
directly. Consider special values like `false` or `null` and the
responsibility for interpreting that. Accessing these from a stable
function also gives a natural place for deprecation to happen. The
alternative, is for dynamic computation to happen in Setup.php for
all variabls, and only ever grow and become an append-only dumping
ground for every thing that we feel at some point needs validation,
normalization or expansion, which doesn't scale well, hence I reversed
this trend in T189966/T233886.

As it happens, RestPath actually is already computed, albeit very
trivially. This patch opens the way for someone to remove that in
favour of PathRouter accept `false` directly and expanding (and testing)
that code there instead.

As for REST API, the only stable and universally supported entrypoint
is /w/rest.php. Unlike some older entry points, we don't support
moving or removing the rest.php file. We do support routing/aliasing
additional paths to it.

Change-Id: I589a8aed8db3b8e7b72e4505749bb7ef25a755d9
2024-07-01 22:01:32 +00:00
daniel
879846b29c REST: introduce OpenSearchDescriptionHandler
Move open search description endpoint from /w/opensource_desc.php
to /w/rest.php/v1/search.

Bug: T363984
Change-Id: Idb5b0d21adc6152ef77e6d17846b6acc6a904e01
2024-05-18 17:29:07 +00: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
Umherirrender
72d6b46339 Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statements and changes to docs done manually

Change-Id: I443aada1c18c8628b02671aa9fd6f441961e5c2e
2023-12-11 16:07:18 +01:00
James D. Forrester
fa55ec4c24 Replace some deprecated wfExpandUrl calls with UrlUtils::expand
Bug: T319340
Change-Id: I2d81c2d7fd31bb07a2d2057361f1670cdeb8b8d0
2023-05-30 19:48:01 +00:00
Umherirrender
e04d3a28f6 Replace internal Hooks::runner
The Hooks class contains deprecated functions and the whole class is
going to get removed, so remove the convenience function and inline the
code.

Bug: T335536
Change-Id: I8ef3468a64a0199996f26ef293543fcacdf2797f
2023-05-11 06:17:38 +00:00
Tim Starling
63b0fa3590 In Web entry points, move file scope code into a main function
Avoid leaking local variables into the global scope by accident, by
moving the entry point code to a function.

In index.php, document the intentional $mediaWiki global so that
nobody removes it by accident.

Change-Id: Ie1a181ae3ebdda90cd2321f0c1b50e31fb0d586e
2020-06-25 11:31:45 +01: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
Timo Tijhof
bc1f601382 docs: Improve "Entry points" documentation page
Turn this into a doc group, and let the descriptions come
directly from the files in question. This makes the list easier
to maintain, and alsom means that the overview page becomes
discoverable whenever one is looking at the entry point file
as well. Previously the doc page pointed to the entry points,
but not the other way around. This is also fixed.

Bug: T244294
Change-Id: I891c5a37e17592edc1136d7367949927121c8bc8
2020-02-04 21:44:38 +00:00
Tim Starling
b7ce7aacb0 Add MW_REST_API and MW_ENTRY_POINT
Define the global constant MW_REST_API in rest.php, by analogy with
MW_API. Also generalize this by adding MW_ENTRY_POINT, which contains
the entry script name, "cli" or "unknown". This allows tests such as

  if ( MW_ENTRY_POINT !== 'index' )

which is probably what is really intended by defined('MW_API') in many
cases.

Change-Id: I24099f4cdd170de17afd6e1bbad67c9b204071fc
2019-09-03 11:43:18 +10:00
Timo Tijhof
da31eba45f entrypoint: Avoid random Doxygen block from api.php and opensearch_desc.php
These two entry points have themselves partly indexed by Doxygen
in a very strange way where these two comments cause part of an
if-statement to be seen as the name of a local variable.
Probably due to some kind of bad interaction with the
maintenance/mwdoc-filter.php filter applied to the file before
it gets indexed.

Fix it for now by avoiding use of /** blocks for something that
isn't a class, function, class member or documented global var.

Change-Id: I4903069e704c3283e6ec7a39999a489d0117cc71
2019-07-08 21:24:45 +01:00
James D. Forrester
f9f8dff40f Rename CDN config variables to be generic, deprecating the old names
Hook, methods, classes still to rename where appropriate.

Bug: T104148
Depends-On: Id34339dff88bc6d1863378ac94b96b2d590b891d
Depends-On: I4e2938395bcbf7956b83fff00978f09c61dcfa36
Change-Id: I7a725dae551c867a4fa7c213838d52c7fb862756
2019-05-24 21:09:22 +00:00
Brad Jorsch
dcf75c4f9d Enforce no-session constraint in opensearch_desc.php and profileinfo.php
Attempts to use session data via these endpoints will now cause
exceptions to be thrown.

Bug: T127233
Change-Id: I28b080a84e7b928e4336a5a1ec770bb57b05d009
2018-10-03 15:08:06 -04:00
Lucas Werkmeister
b045f1d9e7 Restore original OpenSearch namespaces
Though that URL may no longer resolve, the correct XML namespace for
OpenSearch remains http://a9.com/-/spec/opensearch/1.1/ – see [1] and
[2] for some discussion clarifying this.

Similarly, the canonical namespace URL for MozSearch uses HTTP, not
HTTPS, as can be seen when visiting it (via either protocol) [3].

This reverts commit 3b86cf03c1.

[1]: https://github.com/dewitt/opensearch/issues/3
[2]: https://groups.google.com/d/msg/opensearch/8ecuX35-lEs/JR_cs0N6k68J
[3]: https://www.mozilla.org/2006/browser/search/

Bug: T196643
Change-Id: I8d14660550a5c67cefc421a334502963bfd6ed3c
2018-06-07 18:54:20 +02:00
Suriyaa Kudo
3b86cf03c1
Update 'OpenSearchDescription' links
* a9.com OpenSearch website doesn't exist anymore. I replaced it with OpenSearch.org.
* Change HTTP protocol for the xmlns:moz website. I removed the website redirection.

Change-Id: I2c261cd654f009a9316510f2cf80944235c1af82
2018-04-29 18:59:14 +02:00
James D. Forrester
225b462a50 Drop deprecated EnableAPI and EnableWriteAPI settings
The siteinfo API response's 'writeapi' value is now hard-set to true,
as are the ResourceLoader variables wgEnableAPI and wgEnableWriteAPI,
to be deprecated later.

Bug: T115414
Change-Id: I54ff9428b247ba203d67aba079149393f323d5a9
2018-04-18 00:30:34 +00:00
Brad Jorsch
53b4892ffb Warn on session access in profileinfo.php and opensearch_desc.php
These are so simple there will probably be no problems, but let's set
them to 'warn' for a week just to be sure.

Bug: T127233
Change-Id: I04007faaf541f30dcaf2085fa86b45bea1ecb754
2016-05-05 11:35:10 -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
umherirrender
2320f5cfe2 Change some line comments to multi line comments
This allows empty lines inside the comment as found by the
MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.EmptyComment sniff

Change-Id: Iac155bbda4a84562db2b452baeae9b8973899453
2015-10-14 09:40:50 +02:00
Chad Horohoe
63c7b003c4 wfRunHooks() -> Hooks::run() in remaining entry point files
Change-Id: I074deaa7dabc9512812a0ec76a8cc2ea4535a484
2015-04-27 21:37:20 -07:00
Brad Jorsch
28e37f55c9 Merge OpenSearchXml extension into core
There's really no reason for the extension to exist separately from
core, and merging it reduces the risks of bitrot in both the extension
(lots of deprecated functions there) and core (missing integration with
PageImages and TextExtracts, for example).

Change-Id: Ie0ab90902ede9499879402290006466efba479e9
2014-11-26 21:07:22 -08:00
Timo Tijhof
beb1c4a0ec phpcs: More require/include is not a function
Follows-up I1343872de7, Ia533aedf63 and I2df2f80b81.

Also updated usage in text in documentation and the
installer LocalSettingsGenerator.

Most of them were handled by this regex:
- find: (require|include|require_once|include_once)\s*\(\s*(.+?)\s*\)\s*;$
- replace: $1 $2;

Change-Id: I6b38aad9a5149c9c43ce18bd8edbab14b8ce43fa
2013-05-21 23:26:28 +02:00
Siebrand Mazeland
655f5c6b48 Update code formatting
Change-Id: I8741b5b979e55f38a666961a16c387586a92410e
2013-02-14 13:38:19 +00:00
Antoine Musso
7006e1df93 style: fix up commas in function arguments
Fix up spaces in our function calls, we do not want spaces before a
comma and try to avoid multiple commas whenever possible.

Errors:

* No space found after comma in function call
* Space found before comma in function call

Change-Id: I51aec02016f742422fa60b92ad35ba3f0ef59ba3
2013-02-06 19:30:39 +01:00
Hoo man
8ffbb077b3 Use __DIR__ instead of dirname( __FILE__ )
Removed left over uses of dirname( __FILE__ ) to __DIR__, even in comments.
Running the PHP version test in maintenance/Maintenance.php earlier, so that
we no longer have to stay PHP < 5.3 compatible in there.

Change-Id: I5a00bd5c6af44b7f826c4e5576a7b3de7b5026d8
2012-08-27 23:58:28 +02:00
Alex Monk
2fabea7eea Use wfMessage instead of deprecated wfMsg*
Or $this->msg in special pages.

Change-Id: I774a89d646615053c8424050e42ad95601f92543
2012-08-18 14:11:05 +02:00
Alexandre Emsenhuber
f27ff698fb Added missing GPLv2 headers in some places.
Also made file documentation more consistent.

Change-Id: I30e124514396f110a572467b94ca06cefd5f7b46
2012-05-23 13:41:30 +02:00
Roan Kattouw
1c92b1463e Use canonical URLs (introduced in r94995) in the OpenSearch discovery thingy 2011-08-19 14:39:37 +00:00
Alexandre Emsenhuber
ce9c8bf686 Same as r48631; added "@file" when needed, also added doc in redirect.php and install-utils.inc 2009-03-21 16:48:09 +00:00
Brion Vibber
52fedd8044 Revert r37272 "Send $wgMimeType mime type for Special:Search template"
Clients will expect text/html specifically, and would not necessarily know that say application/xhtml+xml means the regular search page.
2008-07-07 18:59:49 +00:00
Alexandre Emsenhuber
4cd2a11708 Send $wgMimeType mime type for Special:Search template 2008-07-07 17:39:13 +00:00
Brion Vibber
add8c926ac OpenSearch cleanup; Firefox now sends you to the search page for empty searches instead of the domain root (which may not even be a wiki).
This is done by adding the <moz:SearchForm> extension element with the Special:Search URL.

Removed the 24-character truncation on ShortName... neither Firefox nor IE seems to care about longer names, but both expect the ShortName and <link> title to match, and will think you have a duplicate search provider if they don't match because only one was truncated. (Besides, 24 was longer than the spec's limit of 16 -- why bother limiting at all if not to spec?)

The JSON suggestions are now no longer included in the OpenSearch description if the API is disabled, since the interface won't work.

Generally removed some hardcoded escape-then-stick-vars-in-string-output eww... Extension hooks now have a more general opportunity to alter or replace the OpenSearch URLs by tying into the OpenSearchUrls hook.
2008-07-01 23:31:24 +00:00
Robert Stojnić
d6fd8e7c13 Ajax suggestions:
* check in a new ajax suggestion engine (mwsuggest.js) which uses 
  OpenSearch to fetch results (by default via API), this should
  deprecated the old ajaxsearch thingy
* extend PrefixSearchBackend hook to accept multiple namespaces for
  future lucene use (default implementation however can still 
  process only one)
* Added to preferences, also a feature to turn it on/off for every 
  input (disabled atm until I work out browser issues completely)
* WMF wikis probably won't be using API to fetch results, but a 
  custom php wrapper that just forwards the request to appropriate
  lucene daemon, added support for that

SpecialSearch:
* moved stuff out of SpecialSearch to SearchEngine, like snippet
  highlighting and such
* support for additional interwiki results, e.g. title matches
  from other projects shown in a separate box on the right
* todo: interwiki box doesn't have standard prev/next links to 
  avoid clutter and unintuitive interface
* support for related articles
2008-04-15 23:06:28 +00:00
Brion Vibber
44390ff7e8 Tweak up last commit about opensearch desc to be nicer. Cleaner message name, use wfMsgForContent, remove an obsolete line. 2008-02-27 04:56:29 +00:00
Brion Vibber
75b54c2bf6 * (bug 12723) OpenSearch description name now uses more compact language code
to avoid passing the length limit as often, is customizable per site via
  'opensearch-shortname' message.

Note that the spec actually says ShortName should be trimmed to *16* chars,
which is pretty awful -- 'Wikimedia Commons' doesn't even fit. I haven't
changed the current trimming (to 24 characters).

Note that Firefox uses the longer 'Description' field for its 'add' menu
item, but the ShortName for the actual item once you add it to the menu.

Possibly should have separate description and shortname thingies and do some
smarter trimming. Sigh.
2008-02-27 04:53:24 +00:00
Brion Vibber
8e476b31cc * (bug 12935, 12981) Fully-qualify archive URLs in delete, revert messages
Replaced a bunch of instances of 'if-this-is-not-fully-qualified-prepend-$wgServer' with a function, wfExpandUrl()
2008-02-13 05:59:14 +00:00
Brion Vibber
737a19d7a4 Apply live hack from Wikimedia codebase: bump HTTP cache expiry on OpenSearch results from 5 to 10 minutes, and send a Cache-Control header as well as Expires for better squid support 2008-01-29 00:26:13 +00:00
Tim Starling
a3b490d2c4 * Made special page names case-insensitive and localisable. Care has been taken to maintain backwards compatibility.
* Used special page subpages in a few more places, instead of query parameters
2006-10-30 06:25:31 +00:00
Yuri Astrakhan
cfff337cc6 fixed suggest URL 2006-10-16 02:41:41 +00:00
Yuri Astrakhan
5b3ca07293 * Added search suggestions link. 2006-10-16 02:31:28 +00:00
Jens Frank
4cce66a88b Add "title" to the opensearch link to allow automatic adding of the search engine in Firefox 2 2006-10-09 19:43:20 +00:00
Tim Starling
708474bb91 another minor fix 2006-08-20 05:18:57 +00:00
Tim Starling
2fd2b52633 favicon fix 2006-08-20 04:14:56 +00:00
Tim Starling
ab6222084d Experimental OpenSearch description 2006-08-20 03:45:47 +00:00