Commit graph

30 commits

Author SHA1 Message Date
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
Umherirrender
49efbfe2fb Improve documentation about object to be stdClass or specific type
Some classes still needs exclude for the sniff

Change-Id: I9536c2ee84f6fb4c83cf862a152cf6b00344cb97
2020-11-20 14:47:56 +00:00
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08:00
Timo Tijhof
480b7341f8 Setup: Move wgArticlePath validation to its main consumer (PathRouter)
The variable is also read in a few other places, such as to
export the value from api.php (siteinfo) and load.php (mw.config)
but those requests don't need to be held back by this extra
logic.

Alternatively, if we really want to require this for all consumption,
we should probably let PathRouter provide the value and require
consumers to use it. E.g. services->getPathRouter->getArticlePath,
or something like that.

As easy first step, I'm moving it to PathRouter, called from
WebRequest::getPathInfo which is still called on all index.php
requests for any wiki page action in any namespace (incl Special)
when the wiki uses anything other than the default 'index.php?title='
article path.

Test Plan:
* Set '$wgArticlePath = 'bla';`
* View /mediawiki/index.php/Main_Page, and observe the fatal
  error message (same as before this change).

Bug: T189966
Change-Id: Id06c2557e2addb58faeef0b6f7767a65b8de55a5
2019-09-25 23:06:52 +00:00
Timo Tijhof
64281b6c52 Setup: Move wgActionPath logic to PathRouter
This is only relevant when processing page views or when constructing
Title urls with an 'action' query. Pretty important stuff, and worth
optimising for if we had to choose, but we can defer it in this case
without slowing it down, which is better for everything else.

It also means we don't mutate configuration (beyond setting whole values
as dynamic defaults), which seems desirable, and makes the overall behaviour
easier to test. Handling absence of 'view' should be PathRouter's
responsibility, not Setup.

Bug: T189966
Change-Id: I9c1eea2dcea74be0e283eb2b175268315ced1793
2019-09-04 20:29:03 +00:00
Fomafix
110a5877e9 Use [...] instead of array(...) in PHP comments and documentation
Change-Id: I0c83783051bf35fe785bc01644eeb2946902b6b2
2019-06-17 21:15:09 +02:00
Reedy
c13fee87d4 Collapse some nested if statements
Change-Id: I9a97325d738d09370d29d35d5254bc0dadc57ff4
2019-04-04 19:02:22 +00:00
Thiemo Kreuz
d1a497a9f4 Avoid a few overly complicated is_null() checks
We can use the ?? syntax introduced with PHP 7.0 because it is already
supported by HHVM, even when HHVM is set to be compatible with PHP 5.6.

This was inspired by Ib117e05.

Change-Id: If980839fe6f86f2b4e86bbe99905a796e4708c7c
2019-03-11 10:29:20 +01:00
Tim Starling
f6d582a91e Avoid a redirect loop when the request URL is not normalized
If the request URL was not normalized, for example having a double slash
in it, this could cause it to fail to match in the PathRouter. But the
canonicalizing redirect was using the normalized URL, causing a redirect
loop exception.

So:

* If the PathRouter fails to match with the original URL, try matching
  against the normalized URL. This allows it to still work for
  normalized URLs with a double slash in the title part of the path.
* Have WebRequest::getFullRequestURL() always return the URL without
  removing dot segments or interpreting double slashes. Just append
  the path to the server.
* Make MediaWikiTest.php use WebRequest instead of FauxRequest, allowing
  it to reproduce the exception in question. Add relevant test.
* Add tests for the new PathRouter behaviour.

Bug: T100782
Change-Id: Ic0f3a0060904abc364f75dae920480b81175d52f
2018-07-16 15:55:59 +10:00
Tim Starling
8943c22221 Use a closure instead of PathRouterPatternReplacer
In PHP 5.3+ it's simpler to use closures rather than a replacer class to
pass parameters through to the preg_replace_callback() callback.

Remove without deprecation internal class PathRouterPatternReplacer,
unused in core and Gerrit-hosted extensions.

The new implementation is very similar, except that I renamed some
variables for clarity.

Also fixed an incorrect doc comment parameter type.

Change-Id: I4cd3c0162acdb02d51ab5b7f03b0a16e0a818d99
2018-07-11 10:54:35 +10:00
Erik Bernhardson
d67197fa11 Cleanup some incorrect return annotations
Most of these are simply changing annotations to reflect
reality. If a function can return false to indicate failure
the @return should indicate it.

Some are fixing preg_match calls, preg match returns 1, 0 or false,
but the functions all claim to return booleans.

This is far from all the incorrect return types in mediawiki, there
are around 250 detected by phan, but have to start somewhere.

Change-Id: I1bbdfee6190747bde460f8a7084212ccafe169ef
2016-12-12 10:15:05 -08:00
Amir Sarabadani
d56829dca8 Clean up array() syntax from docs, part VI
Change-Id: Ib0eea494e2065c7ab356dc45fd174544a9c1c942
2016-09-12 14:36:37 +04:30
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
a3983418d5 Fixed some @params documentation (includes/*)
Swapped some "$var type" to "type $var" or added missing types
before the $var. Changed some other types to match the more common
spelling. Makes beginning of some text in captial.
Also added some missing @param.

Change-Id: I0056b4a8df243cfc0c5f25378de48f7a35170aca
2014-04-22 13:07:02 +02:00
Timo Tijhof
fc2d3c59f1 PathRouter: Fix documentation typo
Change-Id: Ib8021c721e7438163d65ddf6b83ecee8fc1639c6
2014-03-07 23:50:06 +00:00
umherirrender
ef2f507d23 Fixed spacing in files direct in includes folder
Added spaces before if, foreach
Added some braces for one line statements

Change-Id: Ibb8dd102db045522d12ff939075ba7420d95ab6b
2013-04-21 06:38:49 +00:00
Tyler Anthony Romeo
4dcc7961df Fixed @param tags to conform with Doxygen format.
Doxygen expects parameter types to come before the
parameter name in @param tags. Used a quick regex
to switch everything around where possible. This
only fixes cases where a primitve variable (or a
primitive followed by other types) is the variable
type. Other cases will need to be fixed manually.

Change-Id: Ic59fd20856eb0489d70f3469a56ebce0efb3db13
2013-03-11 13:15:01 -04:00
umherirrender
1044b0b8df fix some spacing
Change-Id: I8f976013f33c5818e4402604fe8610aa3f43b0c6
2013-02-04 20:18:33 +00:00
Alexandre Emsenhuber
d1f8640a3b Added missing GPLv2 headers in some places.
Also made file/class documentation more consistent.

Change-Id: Ia45d0756cd84138da267bf1cbd1a58be7f28c6d1
2012-05-11 10:34:29 +02:00
Reedy
24ec253b67 Parameter documentation for PathRouter
Explicitly define member variable

Change-Id: Iae2cffbb299d587d9a48b3b3255a0b49501cabac
2012-04-25 00:27:14 +01:00
Reedy
cea5c5937c Fix documentation to match potential code
Change-Id: Ibaaa2e82777178d8b25a19c4bec7aaed0239a277
2012-04-07 20:21:29 +01:00
Daniel Friesen
d0a51ee5a4 Fix bug 34684 in my PathRouter code:
- Update the tests to test extra characters and patterns like like \\ and $1
- Also update the tests to make sure that matches that don't have enough data to work fail
- Replace the str_replace and preg_match based code with code based on preg_replace_callback.
2012-02-24 11:31:36 +00:00
Sam Reed
85bbb0b080 Fixing some of the "@return true" or "@return false", need to be "@return bool" and then the metadata can say true if foo, false if bar
Other documentation improvements
2012-02-09 18:01:10 +00:00
Daniel Friesen
8ddf933100 Followup r104676, r104688:
- Update our woefully out of date doc comment for WebRequest::getPathInfo (we haven't simply been extracting a PATH_INFO for ages)
- Make PathRouter::makeWeight protected
- Add more comments to the PathRouter code
- Add two more edge case tests to the PathRouter tests.
2011-12-09 00:28:34 +00:00
Aaron Schulz
d5f08196e1 FU r104688:
* Removed a bit of cruft in from a comment (c&p error)
* Clarified 'value' params comment (AFAIK)
* Broke some long lines and made some other w/s cleanups
2011-12-08 02:02:21 +00:00
Daniel Friesen
d6cf8c57b4 Followup r104274, r104676. Fix the bug that broke fr. Forgot to rawurldecode path contents.
Also add /u just for sanity sake.
Add new tests for url encoding, unicode, and length edge cases.
2011-11-30 15:09:08 +00:00
Daniel Friesen
8f8d8e4dfc Recommit PathRouter code from r104274, r104284, r104285 without the WebRequest.php and hooks.txt code so we can start to add tests and fix the bug in it. 2011-11-30 13:37:22 +00:00
Brion Vibber
73b6bd244a Revert r104274, r104284, r104285 -- breaks special pages on non-english 2011-11-28 19:55:49 +00:00
Daniel Friesen
7ce9a83f20 Followup r104274; Add '$key' to the $data array as well. 2011-11-26 17:43:45 +00:00
Daniel Friesen
63e93db2d8 Implement path routing code.
- Makes extending paths with extensions simpler.
- Should fix bug 32621 by parsing paths based on pattern weight rather than pattern order.
2011-11-26 16:29:25 +00:00