Commit graph

167 commits

Author SHA1 Message Date
Umherirrender
41984162af Improve type hints to special page related classes
Change-Id: I96e2ff2fbd6f69e83212b22cf107417014b665e1
2019-06-03 21:11:10 +02:00
James D. Forrester
871d947ca4 i18n: Rename 11 messages for case-compliance
Can't yet enforce due to the API.

* allmessagesnotsupportedDB
* rcfilters-filtergroup-userExpLevel
* rcfilters-filtergroup-lastRevision
* number_of_watching_users_RCview
* apihelp-query+allfileusages-example-B
* apihelp-query+allimages-example-B
* apihelp-query+alllinks-example-B
* apihelp-query+allpages-example-B
* apihelp-query+allredirects-example-B
* apihelp-query+alltransclusions-example-B
* apihelp-query+allusers-example-Y
* apiwarn-wgDebugAPI

Change-Id: I95961dfeb43e9cfadc867a48866af6335022572a
2019-05-18 16:39:49 +02:00
Reedy
9f2ffdfbd4 Remove "Squiz.WhiteSpace.FunctionSpacing" from phpcs exclusions
Change-Id: I78b3315f26ab91b6b443f5b028a635552f82f5a3
2019-05-11 02:44:26 +01:00
Aryeh Gregor
2e1ac38485 Mass conversion to NamespaceInfo
Change-Id: I2fef157ceec772f304c0923a1cd8c0eef2e82a0f
2019-05-07 22:44:56 +02:00
Aryeh Gregor
18ec468633 Don't pass Config to service constructors
We don't want to depend on the entire site configuration when we only
need a few specific settings.

This change additionally means that these services no longer see a live
version of the settings, but rather a copy. This means in tests you
really do have to call overrideMwServices() if you want services to pick
up your config changes.

ResourceLoader and SearchEngineConfig will need more work to port,
because they expose their member Config in a getter, and the getter is
actually used.

Parser and NamespaceInfo are also relatively complicated, so I split
them into separate patches.

Tested with 100% code coverage. \o/

Depends-On: If6534b18f6657ec1aba7327463f2661037f995b3
Change-Id: I1a3f358e8659b49de4502dc8216ecb6f35f4e02a
2019-05-02 11:33:56 +03:00
Kunal Mehta
7592e1068b Fix phan errors in ChangesListSpecialPage (#6)
Specifically in registerFiltersFromDefinitions(), phan was unable to
tell that $groupDefinition['class'] was a string. I think it assumed it
was an integer because the earlier $groupDefinition['priority'] was an
integer.

Use phan's more advanced type documentation system to instruct it that
$className will be a string.

Change-Id: I09f41366b713d6159b57e798cfd1720f42ba30ef
2019-04-05 23:20:02 -07:00
Kunal Mehta
7bd9073c4b Fix/suppress misc phan errors (#2)
* Title: phan false positive
* McrUndoAction: fixed improper use of @param
* UploadSourceAdapter: fixed wrong type
* XmlTypeCheck: Use null so phan doesn't think we're trying to call the
function ''
* Database: phan false positive
* SpecialBlock: Use phan's advanced type documentation so phan knows
specifically what's being returned
* ChangesListSpecialPage: phan false positive
* BatchRowUpdate: Have default callback take a parameter so phan doesn't
think too many arguments are being passed
* MimeAnalyzer: left FIXME for relying on PHP 7.1 unpack() signature
* LanguageConverter: Specify types for $mTables since phan couldn't
determine it automatically
* preprocessorFuzzTest: Implement User::load() method signature

Change-Id: I08080ab636c5fe67ea6a4e14b2212d7523606e21
2019-04-05 16:12:18 -07:00
Thiemo Kreuz
16847b4031 specials: Fix incomplete documentation of execute() param
The parameter passed to the execute() method of each special page can
be null, and usually is. In some of these files this fact was already
mentioned in the comment, but not listed as a type.

In this patch I also remove comments that do not explain much. Saying
that the execute() method of a special page "executes a special page" or
is the "main entry point to a special page" is not super helpful. That's
usually what the documentation in the parent class shoudl explain.
We can add @inheritDoc tags in all these cases if you prefer. Please
tell me.

Change-Id: I1d811ab0c6d5c956e36f6a74120a425abc4332e6
2019-03-28 16:26:42 +00:00
Aaron Schulz
a26eee40e0 Avoid use of deprecated ObjectCache::getMainWANInstance method
Change-Id: I429e68c8642a00afa812f5ae900c1fb4f8308528
2019-03-01 02:38:55 +00:00
jenkins-bot
19aa197cf2 Merge "Apply the pseudo-css selector rules to diff and changelist pages" 2019-02-22 00:32:52 +00:00
jdlrobson
0e1edec723 Apply the pseudo-css selector rules to diff and changelist pages
The styles that we are applying on changelist pages should also
apply on diff pages. This generalises the rules into a new
module.

To avoid problems with cached HTML mediawiki.special.changeslist
temporarily loads resources/src/mediawiki.interface.helpers.styles.
This will be removed after the change has been in production for a
week.

Bug: T212613
Change-Id: I6aad563e48f41c783df8b176a4f437e60a1255cc
2019-02-21 15:54:46 -08:00
jenkins-bot
c32087b1ef Merge "RCFilters: Export config vars in the RL modules where possible (take 2)" 2019-02-21 21:57:49 +00:00
Catrope
9ba1d8f526 RCFilters: Export config vars in the RL modules where possible (take 2)
This reverts commit 492969e12b
and reinstates commit bf4f9d0313.

Bug: T201574
Depends-On: I58901657daf3e82229a303d8fe7a2c051ffe7634
Change-Id: I1b0a777760d4c2a149415da0d2068e6bfea5b917
2019-02-20 16:24:01 -08:00
Roan Kattouw
a064c57f51 RCFilters: Don't show tags with 0 hits in tag menu
Bug: T182219
Change-Id: Id6b4c6fe652c15388f0d6b37912cb582ea205a47
2019-02-19 12:53:53 -08:00
Catrope
492969e12b Revert "RCFilters: Export config vars in the RL modules where possible"
This reverts commit bf4f9d0313.

Reason for revert: causes issues with OAuth extension

The OAuth extension uses a hook to override certain tag messages, and
that hook uses RequestContext::getMain()->msg(), which tries to load
the current user. That's not allowed in load.php requests, so we get a
"Sessions are disabled for this entry point" error.

Change-Id: If58b7edfca116cd7a11f38556f74bed82609d96a
2019-02-12 01:02:27 +00:00
Roan Kattouw
bf4f9d0313 RCFilters: Export config vars in the RL modules where possible
Right now there are only a few settings that don't depend on the request
context, but we can at least export those. The tag data in
particular can get pretty big.

Downgrade the type hint for ChangeTags::tagDescription() and
tagLongDescriptionMessage() from IContextSource to MessageLocalizer, so
we can pass a ResourceLoaderContext to these functions. (Since
IContextSource extends MessageLocalizer, this won't break any callers.)

truncateTagDescription() can't be downgraded to MessageLocalizer because
it needs a Language object, so hack up a fake RequestContext when
calling it. It would be nice if this weren't necessary; perhaps we can
move getLanguage() from IContextSource up into MessageLocalizer?

Bug: T201574
Change-Id: I9b66e35de826a07aa9551ba285e64e4852293229
2019-02-10 03:36:16 +00:00
Kosta Harlan
55e3c5831a Revert "ChangesListSpecialPage: Make maximum limit consistent (1000)"
This reverts commit ac2837c9b3.

Reason for revert: See T210897#4821559

Bug: T210897
Change-Id: Ifb6debe3eaddb4a2cb62ace5cfea59c06e77d141
2018-12-13 19:45:29 +00:00
Roan Kattouw
ac2837c9b3 ChangesListSpecialPage: Make maximum limit consistent (1000)
The maximum value for the rclimit and wllimit preferences is 1000, so
make the maximum value for the ?limit= query parameter also 1000.

Bug: T206233
Change-Id: I244ab2896875391f9676c8127033a0b76568157f
2018-11-16 14:06:02 -08:00
jenkins-bot
13dba84b6f Merge "Fix PHPDoc type for instance variables and methods" 2018-10-24 21:17:02 +00:00
Alangi Derick
b4ecf374fe Fix PHPDoc type for instance variables and methods
Should be "string" not "String" and "array" not "Array" in
@param, @return and @var use cases. Also, minor typo fixes.

Change-Id: I9d5ebc5b741c6560907b95f7c0c4039da2861f4a
2018-10-21 13:00:25 +01:00
C. Scott Ananian
c0ed262053 Use OutputPage::addWikiTextAsInterface() instead of untidy addWikiText()
This change ensures that the output is tidy, and is necessary to support
future parsers which will not be able to produce untidy output.

Bug: T198214
Change-Id: I743f4185a03403f8d9b9db010ff1ee4e9342e062
2018-10-17 10:35:28 -04:00
Fomafix
1472f02b36 Phabricator: Use Tddddd instead of Bug ddddd in comments
Change-Id: Ic9fe03cab270bd6be738af346164ad5d31a0d780
2018-10-04 09:15:02 +02:00
Stephane Bisson
f52d16148e Remove unused function: isStructuredFilterUiEnabledByDefault
Follow up Id3799fefd21cd9bea0e089a5e12576ee9ea1085e

Bug: T196033
Change-Id: Ib2ad41be8648f7ff8b4a218fd66c328dee3924d9
2018-10-01 20:34:55 -04:00
Stephane Bisson
2e8512c7d0 Remove temporary rcfilters variables
wgStructuredChangeFiltersShowPreference, wgStructuredChangeFiltersShowWatchlistPreference,
and wgStructuredChangeFiltersOnWatchlist were introduced for progressive rollout
of the RCFilters app on RC and WL.

These variables and their related conditional code is no longer needed.

Bug: T196033
Change-Id: Id3799fefd21cd9bea0e089a5e12576ee9ea1085e
2018-09-27 13:39:05 -04:00
James D. Forrester
b5ce7632c7 hooks: Drop Special{Watchlist|RecentChanges}Filters, deprecated in 1.23
Neither SpecialWatchlistFilters nor SpecialRecentChangesFilters are used in any
code known to Wikimedia code search. The related code to use these hooks was
only ever used within the MediaWiki repo.

Change-Id: Ib631d49d7b5835c665171dbad3e8a646b80827ef
2018-09-12 12:43:01 -07:00
Roan Kattouw
2dd6342b64 RCFilters: Export i18n messages as a config var instead of inline script
We used to generate an inline script tag with an mw.messages.set(...)
call to export these i18n messages, but there are no guarantees that
this script tag will run before mw.rcfilters.init does and tries to
access these messages. This race condition doesn't seem to be happening
in practice right now, but dec800968e makes it more probable.

Instead, export the messages object as a config var in mw.config, and
import it into mw.messages at the start of mw.rcfilters.init. This just
moves the blob from one inline script tag to another, but mw.config is
guaranteed to be populated before any modules execute.

Longer term, we should move these messages, as well as the filter
definitions, to a ResourceLoader module rather than embedding them in
every page view. I filed T201574 for that.

Bug: T192623
Change-Id: I2d58f55701b28876a6491432cee0fc56f97ff00b
2018-08-08 18:31:04 -07:00
Moriel Schottlender
232deffd81 RCFilters: Preserve collapsed state and adjust display
When collapsed, make sure we are adjusting the 'min-height' on the
'rcfilters-head' div so that it actually takes the space it should.

Make sure the preference of whether the area is collapsed or not is
preserved for the user, per RC or WL pages, and that it is loaded
properly with the correct minimum height dimensions depending on
which state is in the preferences, so to prevent "jump" of the
result list after load.

Bug: T177206
Change-Id: I82c3042cd1bb85dedcd6b5458b157fed94def808
2018-06-20 11:12:00 -07:00
Max Semenik
6e956d55aa Replace call_user_func_array(), part 2
Uses new PHP 5.6 syntax like ...parameter unpacking and
calling anything looking like a callback to make the code more readable.
There are much more occurrences but this commit is intentionally limited
to an easily reviewable size.

In one occurrence, a simple conditional instead of trickery was much more readable.

This patch finishes all the easy stuf in the core, the remainder is either unobvious
or would result in smaller readability gains. It will be carefully dealt with in
further commits.

Change-Id: I79a16c48bfb98b75e5b99f2f6f4fa07b3ae02c5b
2018-06-07 20:19:26 -07:00
Bartosz Dziewoński
485f66f174 Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
Find: /isset\(\s*([^()]+?)\s*\)\s*\?\s*\1\s*:\s*/
Replace with: '\1 ?? '

(Everywhere except includes/PHPVersionCheck.php)
(Then, manually fix some line length and indentation issues)

Then manually reviewed the replacements for cases where confusing
operator precedence would result in incorrect results
(fixing those in I478db046a1cc162c6767003ce45c9b56270f3372).

Change-Id: I33b421c8cb11cdd4ce896488c9ff5313f03a38cf
2018-05-30 18:06:13 -07:00
Bartosz Dziewoński
b191e5e860 Use PHP 7 '<=>' operator in 'sort()' callbacks
`$a <=> $b` returns `-1` if `$a` is lesser, `1` if `$b` is lesser,
and `0` if they are equal, which are exactly the values 'sort()'
callbacks are supposed to return.

It also enables the neat idiom `$a[x] <=> $b[x] ?: $a[y] <=> $b[y]`
to sort arrays of objects first by 'x', and by 'y' if they are equal.

* Replace a common pattern like `return $a < $b ? -1 : 1` with the
  new operator (and similar patterns with the variables, the numbers
  or the comparison inverted). Some of the uses were previously not
  correctly handling the variables being equal; this is now
  automatically fixed.
* Also replace `return $a - $b`, which is equivalent to `return
  $a <=> $b` if both variables are integers but less intuitive.
* (Do not replace `return strcmp( $a, $b )`. It is also equivalent
  when both variables are strings, but if any of the variables is not,
  'strcmp()' converts it to a string before comparison, which could
  give different results than '<=>', so changing this would require
  careful review and isn't worth it.)
* Also replace `return $a > $b`, which presumably sort of works most
  of the time (returns `1` if `$b` is lesser, and `0` if they are
  equal or `$a` is lesser) but is erroneous.

Change-Id: I19a3d2fc8fcdb208c10330bd7a42c4e05d7f5cf3
2018-05-30 18:05:20 -07:00
Brian Wolff
70941efd35 Initial support for Content Security Policy, disabled by default
The primary goal here is a defense in depth measure to
stop an attacker who found a bug in the parser allowing
them to insert malicious attributes.

This wouldn't stop someone who could insert a full
script tag (since at current it can't distinguish between
malicious and legit user js). It also would not prevent
DOM-based or reflected XSS for anons, as the nonce value
is guessable for anons when receiving a response cached
by varnish. However, the limited protection of just stopping
stored XSS where the attacker only has control of attributes,
is still a big win in my opinion. (But it wouldn't prevent
someone who has that type of xss from abusing things like
data-ooui attribute).

This will likely break many gadgets. Its expected that any
sort of rollout on Wikimedia will be done very slowly, with
lots of testing and the report-only option to begin with.

This is behind feature flags that are off by default, so
merging this patch should not cause any change in default
behaviour.

This may break some extensions (The most obvious one
is charinsert (See fe648d41005), but will probably need
some testing in report-only mode to see if anything else breaks)

This uses the unsafe-eval option of CSP, in order to
support RL's local storage thingy. For better security,
we may want to remove some of the sillier uses of eval
(e.g. jquery.ui.datepicker.js).

For more info, see spec: https://www.w3.org/TR/CSP2/
Additionally see:
https://www.mediawiki.org/wiki/Requests_for_comment/Content-Security-Policy

Bug: T135963
Change-Id: I80f6f469ba4c0b608385483457df96ccb7429ae5
2018-05-13 21:01:11 -07:00
Amir Sarabadani
6a2cd1c5c2 Use constants for rc_patrolled values instead of numbers
These are recently introduced, better to use them

Change-Id: Id904ff09081cb5a1fe2f1c24c5d415da18fd2294
2018-04-13 23:56:35 +02:00
jenkins-bot
008062c87c Merge "RCFilters: Convert patrolled filter to three states" 2018-04-12 16:07:07 +00:00
Roan Kattouw
d9c360e0a4 RCFilters: Convert patrolled filter to three states
Unpatrolled, manual and auto.

This moves the old hidepatrolled/hideunpatrolled filters to a legacy
group, and adds a new string options group with three options.
Also adds code mapping the old parameters to the new ones, and handling
for the hidepatrolled preference.

Bug: T190408
Change-Id: Ic1f181d3704c1d998696617a0d10270a87f22a62
2018-04-11 10:59:06 -07:00
jenkins-bot
d13aa39760 Merge "ChangesListSpecialPageTest: Use Database::makeList() instead of makeshift DIY code" 2018-04-10 13:08:20 +00:00
Roan Kattouw
e8cc356786 ChangesListSpecialPageTest: Use Database::makeList() instead of makeshift DIY code
Otherwise these tests break completely when you add conditions like
$conds['rc_patrolled'] = [ 1, 2 ];
That maps to 'rc_patrolled IN (1,2)', but the DIY code in
normalizeCondition() was too simplistic to generate that.

Change-Id: I449317185f98e20b3e17f1b13610d872ae828171
2018-04-06 10:20:32 -07:00
Umherirrender
a3da44c7df Change ResultWrapper to IResultWrapper in pagers and special pages
There is no need for a specific type, the interface implementation is
enough

Change-Id: I22ec4d3a9a19fc86efc9a2deb06f810695d38c85
2018-04-04 14:52:10 +02:00
Amir Sarabadani
e4277f170b Do not assume rc_patrolled is binary in ChangesListSpecialPage
Bug: T184791
Change-Id: Idd9fc4b37da2d862f84d3aacd9966872958bc9eb
2018-03-22 14:21:45 +01:00
Brad Jorsch
27c61fb1e9 Add actor table and code to start using it
Storing the user name or IP in every row in large tables like revision
and logging takes up space and makes operations on these tables slower.
This patch begins the process of moving those into one "actor" table
which other tables can reference with a single integer field.

A subsequent patch will remove the old columns.

Bug: T167246
Depends-On: I9293fd6e0f958d87e52965de925046f1bb8f8a50
Change-Id: I8d825eb02c69cc66d90bd41325133fd3f99f0226
2018-02-23 10:06:20 -08:00
Stephane Bisson
82622146f8 RCLFilters specific message for invalid target page
* always hide the big red .errorbox when rcfilters
  is enabled

* always identify the changes-list section with
  .mw-changeslist or .mw-changeslist-empty

* conditionally add .mw-changeslist-empty-<reason>
  to the changeslist section when the reason for it
  being empty is known

* handle RCL being empty because the specified title
  is invalid or inter-wiki

Bug: T184952
Change-Id: I5dd974f5f769503e89301dd22bdfd3d49b0dd11f
2018-02-23 06:02:22 +00:00
petarpetkovic
2d2575852c Truncate tag filter descriptions
Introduce truncateInternal() method in Language class, based on
existing truncate() method. New method abstracts string truncation,
allowing users to specify callable functions for text length measurement
and string truncation.

New method, truncateInternal(), is used to provide two options for
text truncation:
* For DB usage: truncateForDatabase() method is truncating text by
number of bytes.
* For UI usage: truncateForVisual() method is truncating text by number
of characters, using multibyte string PHP methods.

Old truncate() method is deprecated and just returns the results of
truncateForDatabase() method.

Newly introduced truncateForVisual() method is used for
truncation of long tag descriptions in RCFilters menu.

Bug: T179626
Change-Id: Ib01a8c303304064dde3ce983b817d93a88a5affd
2018-02-09 22:45:20 +01:00
petarpetkovic
8dab1125cf Revert legend when results are grouped
Since Ifecaaff572, legend was using position: absolute when results are
grouped by page. Most users found such behavior annoying and unexpected,
so positioning is being reverted to previous state.

Only change besides reverting is preventing collapsed legend to push
away the surrounding results. Without that, we would have scenarios
where legend is expanded and collapsed, but results are pushed away as
if legend is still expanded.

Bug: T182156
Bug: T184165
Change-Id: I5adb7e1cb793ec30fba9d5d9674a7fa294d9a3a5
2018-02-06 23:33:02 +01:00
Thiemo Mättig
ef470ebf7f Remove @param comments that literally repeat what the code says
These comments do not add anything. I argue they are worse than having
no comments, because I have to read them first to understand they
actually don't explain anything. Removing them makes room for actual
improvements in the future (if needed).

Change-Id: Iee70aad681b3385e9af282d5581c10addbb91ac4
2018-01-10 14:14:26 +01:00
Stephane Bisson
21c7cd7109 RecentChangesLinked: Include title without subpage in form
When the 'title' hidden field contains the subpage, the 'target'
input field is never taken into account since the subpage always
takes precedence in ChangesListSpecialPage->setup()

I75cfb2b56a4da6357e6117b3f34f3178bfb2c90c introduced
SpecialRecentChangesLinked->getPageTitle which overrides
SpecialPage->getPageTitle to include the subpage by default.

This helped with redirecting to the right page when parsing
a saved query on the server but changed the behavior everywhere
that function was used in the context of RCL. That includes
SpecialRecentChanges.php:545 where the option form is built.

Bug: T183437
Change-Id: Id39d1887719ecb6900b25fefbb133dff9c4d0456
2017-12-21 11:30:22 -05:00
jenkins-bot
46fa949b8b Merge "RCFilters: Don't load JS or redirect when transcluding" 2017-12-20 19:08:02 +00:00
Roan Kattouw
783299963a RCFilters: Don't load JS or redirect when transcluding
We were changing the URL on every page that contained
{{Special:Recentchanges}}.

Bug: T181032
Change-Id: Ib4a0d3c1733da0bd0076aa43b91fc06939c51b75
2017-12-13 18:04:12 -08:00
petarpetkovic
708f1cdfba Fix how "Live updates" behave when user logs out
If user enables "Live updates" on one tab/browser and logs out from
different tab/browser, reload the page.

Bug: T177717
Change-Id: Ifeeb7d50eaec8f733a94a36711f1c4541af1cef9
2017-12-13 23:00:50 +01:00
Stephane Bisson
21a12a96d0 WLFilters: Correctly check if RCFilters should be enabled on WL
Side-effect of Ib933de3a3f9e876924386e80f315506f60f8af54

ChangesListSpecialPage#isStructuredFilterUiEnabled needs
to call static::checkStructuredFilterUiEnabled() to reach
the implementation from SpecialWatchlist.

Bug: T182318
Change-Id: I1e90d7e29f9e7fc5acece6466ed818210058dd2c
2017-12-07 08:26:02 -05:00
jenkins-bot
10b6b154f7 Merge "Absolutely position "legend" on grouped results" 2017-12-05 17:24:49 +00:00
petarpetkovic
bc3f4d1b18 Absolutely position "legend" on grouped results
- When results are grouped by page, on pages where new RC filters
are enabled, apply position: absolute to legend, to avoid top
result entries being pushed too much.

Bug: T174728
Change-Id: Ifecaaff5727905b3c4e860555ba094f71aac6f80
2017-12-04 13:57:34 +01:00