Commit graph

102 commits

Author SHA1 Message Date
Derick Alangi
9c13ab45b1 Use SelectQueryBuilder instead of IDatabase::select()
Bug: T311866
Change-Id: I5fa509e78ab18b003d67fd7c84ba2fcd857b0bde
2022-08-01 15:56:20 +01:00
Alexander Vorwerk
8846700ef0 Stop merging LinkCache select fields with page_title and page_namespace
LinkCache::getSelectFields() includes page_title and page_namespace
since If77c2f9879d7bae71eb59944efd8b3798d16aa46, so we don't need
to add those two specifically.

Change-Id: I8fa9d563af3f9da90fb96369dab0ee5bde860081
2022-07-05 22:28:53 +00:00
jenkins-bot
a4a8bd53ee Merge "mediawiki.action.styles: Bundle in categoryPage.less" 2022-05-23 04:43:59 +00:00
daniel
552ec41814 Use name constants to access config settings.
Use name constants instead of string literals in calls to Config::get
and ServiceOptions::get, when referring to core configuration variables.
This protects against typos and makes the decumentation and schema
declaration of the config settings discoverable.

This is the first batch, only touching files directly under /includes/

Change-Id: I7252e636c7c86d950d9257b33491af492c6dd5eb
2022-04-07 13:02:28 +02:00
Umherirrender
1f71eccf63 phan: Disable null_casts_as_any_type setting
Make phan stricter about null types by setting null_casts_as_any_type to
false (the default in mediawiki-phan-config)
Remaining false positive issues are suppressed.
The suppression and the setting change can only be done together

Bug: T242536
Bug: T301991
Change-Id: I0f295382b96fb3be8037a01c10487d9d591e7e01
2022-03-21 18:25:07 +00:00
jenkins-bot
c29d5b3ab5 Merge "Add various null checks when null is not possible to use as argument" 2022-03-14 20:06:20 +00:00
Umherirrender
c259c37033 Add various null checks when null is not possible to use as argument
Also check for false if needed

Found by phan strict checks

Change-Id: I298204653dfb788515a87978dd8705b6e4f9c775
2022-03-14 17:17:17 +00:00
Umherirrender
4de76550a3 Fix various real types related to scalar types
Swap null/false or use real strings if needed

Found by phan strict checks

Change-Id: Id82ea609f05a76c5cb8c661d5cf2b7922d6cfbc1
2022-03-10 19:35:34 +00:00
Timo Tijhof
bb5237d278 mediawiki.action.styles: Bundle in categoryPage.less
This tiny stylesheet isn't worth keeping a separate bundle entrypoint
for. Document a basic budget for mediawiki.action.styles and move it
in there.

Given that category pages are cached in the CDN the same way as
article pages are, keep the old module around for a week as its cached
pages will still be loading that module, and those page did not load
the "mediawiki.action.styles" module yet.

Another way could have been to first add "mediawiki.action.styles"
to CategoryViewer.php, and have that load alongside the old module
for a week (without moving any styles). Then the week after, move
the styles over and delete the old module. The cached pages will
be referencing both and finding the new styles under the new module,
and the old module would simply be ignored as no longer existing.

Change-Id: If406ce2ae38eb165758add6099b2106794bf225c
2022-02-24 21:32:24 +00:00
jenkins-bot
2becc606d3 Merge "Try not to discard Excimer timeout exceptions" 2022-02-03 00:28:16 +00:00
Tim Starling
ca71e69fc6 Try not to discard Excimer timeout exceptions
Don't catch and discard exceptions from the RequestTimeout library,
except when the exception is properly handled and the code seems to be
trying to wrap things up.

In most cases the exception is rethrown. Ideally it should instead be
done by narrowing the catch, and this was feasible in a few cases. But
sometimes the exception being caught is an instance of the base class
(notably DateTime::__construct()). Often Exception is the root of the
hierarchy of exceptions being thrown and so is the obvious catch-all.

Notes on specific callers:

* In the case of ResourceLoader::respond(), exceptions were caught for API
  correctness, but processing continued. I added an outer try block for
  timeout handling so that termination would be more prompt.
* In LCStoreCDB the Exception being caught was Cdb\Exception not
  \Exception. I added an alias to avoid confusion.
* In ImageGallery I added a special exception class.
* In Message::__toString() the rationale for catching disappears
  in PHP 7.4.0+, so I added a PHP version check.
* In PoolCounterRedis, let the shutdown function do its thing, but
  rethrow the exception for logging.

Change-Id: I4c3770b9efc76a1ce42ed9f59329c36de04d657c
2022-02-02 16:27:44 +11:00
Ammarpad
c7734cbb9f Add getMemberCount() to Category to supersede getPageCount()
getPageCount() method return `cat_pages`, a value that makes sense
on database table but is currently non-intuitve in object context
where there's a value that better deserves the name. This makes it
necessary for callers to repeat same logic to get the content pages
count and a comment to explain the behavior.

In this patch, getMemberCount() is added. It returns the total
member count as getPageCount(), by default, does now.

getPageCount() now takes a parameter and two public constants are
provided for that; Category::COUNT_CONTENT_PAGES return count of all
memebers to retain existing behavior, Category::COUNT_CONTENT_PAGES
will return only content pages.

In future there'd be no need for the parameter. Content pages will
be returned always. Total member count is already accessible with
getMemberCount().

Also improve return type doc of getId() and getName()

Bug: T299350
Change-Id: I63c711ebc697c1a131a50910c854f956d4021254
2022-01-31 13:59:34 +01:00
Bartosz Dziewoński
e213e574e9 CategoryViewer: Use the same markup whether displaying in columns or not
Change-Id: I9a9c8c73526e9ce4c628368189c8c7d3e5103c30
2022-01-28 10:32:29 -05:00
Reedy
c054b10423 Remove or replace usages of "sane"
Bug: T254646
Change-Id: Ia660ab95353cd8f05c50e60f30d29fd22b018a43
2021-11-22 15:48:03 +00:00
Aryeh Gregor
ceda8ac60e Remove Title from signatures in CategoryViewer
Co-authored-by: Daniel Kinzler <dkinzler@wikimedia.org>
Change-Id: Ie880482fe58b96809fdfd08ebf0825bdcf1d19d1
2021-09-13 16:14:06 +00:00
Umherirrender
5b3d3ef802 collation: Create CollationFactory service
Use ObjectFactory specs for collation classes
Avoid the language construction in the factory class,
make it a detail of the implementation of each class

Follow-Up of Ifc96f851e6091ce834dbaf0e91695c648a42169c

Bug: T286079
Change-Id: Ib581f64aec8619986fb8dd49ceee0524d59a1b84
2021-09-04 02:46:06 +02:00
DannyS712
3d7ef1762c Make use of Html class utility methods in a few places
Each files' changes can be reviewed independently

There may be places in the files that I didn't catch -
this is not meant to be an exhaustive replacement

Even where it may make sense to use Html::element,
Html::rawElement is used in this patch to avoid changing
any behavior.

Change-Id: I26eaacc65106f10a5066c31d82f6594a59ff1281
2021-08-12 08:49:37 +00:00
Umherirrender
e9e784a09e build: Enable phan-taint-check-plugin and suppress issues
Taint check checks for possible security issues by tracking html
escaping and more by using phan.
This slows done the phan-job a bit and requires more ram

Keep the DoubleEscaped issues out to make reviewer easier

Adds suppression for false positives
Adds taint-annotation to help taint-check
Removes suppression for code phan now understand better by the tracking
of keys in taint-check
Fix some small issues by adding int cast or htmlspecialchars calls

Bug: T216348
Bug: T268920
Change-Id: I849ac4f120fd15b483e8939d4db45c98dc351259
2020-12-30 19:02:22 +01:00
Umherirrender
cb9ad7ae10 Replace deprecated Language::convert in CategoryViewer
Change-Id: I6652aa3de60575830c1b5dce70687d0c85bd5b55
2020-11-03 18:11:13 +01:00
Ed Sanders
7683f7d839 Use strict (in)equality with namespaces constants when LHS is definitely an integer
Change-Id: I8fede00dfe1270d93c5d78d3c36e788cddfc8a99
2020-07-31 18:03:28 +01:00
daniel
f59bf8a22f Use @internal instead of @private per policy
https://www.mediawiki.org/wiki/Stable_interface_policy mandates the use
of @internal. The semantics of @private was never properly defined.

Bug: T247862
Change-Id: I4c7c6e7b5a80e86456965521f88d1dfa7d698f84
2020-06-26 14:14:23 +02: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
Reedy
1af2020739 Fix numerous Squiz.Scope.MethodScope.Missing
Change-Id: I7a5aa8555e94a0bcb97b37ec6f8ca854de7c5575
2020-05-15 21:12:30 +00:00
Thiemo Kreuz
c05bdcee8b Remove unreachable null checks after isset()
isset() does two things: It checks if a variable (or array element)
is declared, *and* it checks if it is null. If a variable is null,
isset() fails as if the variable was not set. All these additional
null checks are dead code.

Change-Id: I71e8cc26dac839c9d081bf00b4164b7b5147e586
2020-02-28 21:40:48 +00:00
Umherirrender
0688dd7c6d Set method visibility for various constructors
Change-Id: Id3c88257e866923b06e878ccdeddded7f08f2c98
2019-12-03 20:17:30 +01:00
Fomafix
f17c297624 Use short assignment operator in PHP
Use
  $var .= $foo
instead of
  $var = $var . $foo

Change-Id: I5dcdd7278e618c14968e5ac1fb8ea43ac2200deb
2019-03-07 09:55:49 +01:00
Aaron Schulz
cb15755e92 Normalize use of "INNER JOIN" to "JOIN" in database queries
The ANSI SQL default join type is INNER and this might save
some line breaks here and there.

Change-Id: Ibd39976f46ca3f9b71190d3b60b76ca085787a00
2019-03-06 09:17:30 -08:00
Niklas Laxström
d89704bc4c Improve page display title handling for category pages
One use case of display title is to localise page names with Translate
extension or without. While the page title changes, the subheadings still
say something like "Pages in category Foo/de".

Also converted one raw HTML message to be a parsed message.

First version of this patch caused an issue when previewing
because page title in h1 is not the same as page display title.

This issue is fixed by promoting page display title as it's own member
in OutputPage. Also added getUnprefixedDisplayTitle that attempts to
strip away the namespace prefix to mimic Title::getText() but which
works with display title instead.

Bug: T43720
Bug: T46197
Change-Id: I6097a873297eb57759252fc56ad6d02c44e4c366
2018-09-10 08:29:48 +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
Fomafix
125cbd8c01 Use \u{00A0} instead of &#160; or &nbsp;
Directly use the UTF-8 encoding of the 'NO-BREAK SPACE' (U+00A0) instead of
the HTML/XML entities &#160; or &#xa0; or &nbsp;.

With the UTF-8 character the generated HTML is shorter and better to read.

Also change the special value for the label in HTMLForm from &#160; to
U+00A0 but also support &#160; for backward compability.

Bug: T154300
Change-Id: I882599ac1120789bb4e524c4394870680caca4f4
2018-06-24 01:20:13 +00:00
Aaron Schulz
de75c4e63b Avoid triggering Category::refreshCounts() on HTTP GET requests
Trigger count refreshes more often during updates instead.

Change-Id: I0f4575e648109befb86a2c8f08b491a132fe56c3
2018-04-19 04:45:24 +00:00
Brian Wolff
0ea88136d8 Fix inconsistent i18n escaping in category paging links.
prev-page and next-page were being escaped when they were a
link, but not when they were plain text. They should be escaped
in both cases.

This issue was discovered with an experimental phan plugin I'm
working on.

Change-Id: I6caac76299b21a54cd7cb732ad93187e3d37c99e
2017-10-11 20:29:05 +00:00
Umherirrender
b5cddfb27b Remove empty lines at begin of function, if, foreach, switch
Organize phpcs.xml a bit

Change-Id: Ifb767729b481b4b686e6d6444cf48b1f580cc478
2017-07-01 11:34:16 +00:00
Aaron Schulz
52c3a50028 Fix bogus field reference in Category::getCountMessage() callback
Follows-up 922e68f739. (T162121)

Bug: T162941
Change-Id: I40623203e97f7155c2af171a37b1128a59415315
2017-04-19 21:25:37 -07:00
Aaron Schulz
922e68f739 Reduce contention during view-based category count refreshes
Bug: T162121
Change-Id: I05b539922508d5e73979ccc8ea1c148b16dd13db
2017-04-05 17:34:57 -07:00
Yuriy Shnitkovskiy
55667f024d Replaced all deprecated Linker methods with proper ones in core(1)
Change-Id: Ie3a718dc1eae1507f8829fcf419c64c6846d2cb6
2017-01-20 11:46:13 +02:00
divadsn
f90634a6a7 Fix wrong class name for ImageGalleryBase in comments
This change is part of change 329773.

Change-Id: I2766e2ff3e64a84f52a5d7fa065bbc38280866c1
2016-12-31 13:39:11 +00:00
Yuriy Shnitkovskiy
b0bd03fb13 Replace Linker::link() with LinkRenderer in includes directory
* CategoryViewer
* OutputPage
* Preferences

Bug: T149346
Change-Id: I9f9bcd9b461884817e8ceefbc6757c436221e331
2016-12-01 09:57:05 +02:00
jenkins-bot
7874fc4bec Merge "Revert "Use display name in category page subheadings if provided"" 2016-11-08 23:55:35 +00:00
Liuxinyu970226
59280c4c92 Revert "Use display name in category page subheadings if provided"
This reverts commit 8ccde89849.

For the reason, see T43720#2531092

Bug: T149510
Change-Id: Id1ace9599642a36b333c63eaeebab0537466e7bd
2016-11-08 22:50:56 +00:00
Kunal Mehta
8e5d90f13f Fix display of categories
Fixes regression from 1885a1ac46, which accidentally removed
page_namespace and page_title as select fields.

Bug: T146873
Change-Id: I19cff0cf5bc015da7311196749a9201a8e458b49
2016-09-28 02:17:49 -07:00
Aaron Schulz
1885a1ac46 Reduce queries in CategoryViewer via addGoodLinkObjFromRow()
Change-Id: Id782b50f166efbee6c9f8b9b263f09fc5fb5e3f2
2016-09-22 19:53:58 -07:00
Aaron Schulz
950cf6016c Rename DB_SLAVE constant to DB_REPLICA
This is more consistent with LoadBalancer, modern, and inclusive
of master/master mysql, NDB cluster, and MariaDB galera cluster.

The old constant is an alias now.

Change-Id: I0b37299ecb439cc446ffbe8c341365d1eef45849
2016-09-05 22:55:53 -07:00
jenkins-bot
bbb705a0b1 Merge "Use display name in category page subheadings if provided" 2016-07-28 03:30:55 +00:00
Kaldari
3f9c5710c8 Improving some function documentation in CategoryViewer.php
Change-Id: Ic4ad35d95aa157db627ef9b213007691f465c260
2016-07-14 22:05:02 -07:00
Niklas Laxström
8ccde89849 Use display name in category page subheadings if provided
One use case of display title is to localise page names with Translate
extension or without. While the page title changes, the subheadings still
say something like "Pages in category Foo/de".

A display title is now used if provided. There is one questionable thing
what to do with namespaces and display title. In this case I think it is
better to have the namespace prefix displayed (or not) according to what
the site admin wants, because we cannot safely strip the namespace prefix
from display title.

By using the page title from OutputPage, we already get a name which is
safe for HTML with no further processing. The name is passed as a raw
parameter which breaks magic words (if any) trying to access the value.
It is easy to fix this by using FULLPAGENAME magic word instead.

Also converted one raw HTML message to be a parsed message.

Bug: T43720
Change-Id: Ide7d4a9ee5c76b6360b53aefd76a2e17a139173f
2016-06-08 22:20:48 +00:00
Ed Sanders
2fa533bfad Add class to div wrapper around category lists
Allows VE to target non-editable content to keep on the page.

Change-Id: If687b84d9ad33a0315a8ba4260bc3532691f05ed
2016-04-29 22:30:57 +01:00
Bartosz Dziewoński
ce5a36ab59 CategoryViewer: Do opportunistic category recounts for mismatched file counts, too
There are some categories on Commons that have no files, but are
recorded to have some, e.g. [1] appears to have 15 files [2]. We have
logic to fix these, but it wasn't being checked for file counts (only
pages and subcats).

[1] https://commons.wikimedia.org/wiki/Category:Police_of_Mexico,_D._F._vehicles
[2] https://commons.wikimedia.org/w/index.php?title=Category:Police_of_Mexico,_D._F._vehicles&action=info

Change-Id: If88fc15347eb592e957452884c2179d7c237bd2c
2016-02-29 23:05:32 +01: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
Aaron Schulz
43118240b5 Move category refreshes to a deferred update
Bug: T92357
Change-Id: Ic0d53c0ca01195cc5dd1f5a28602b3d4403e9fa5
2015-12-29 20:22:54 -08:00