Commit graph

1856 commits

Author SHA1 Message Date
Alexander Vorwerk
0ca55105dd Fix @since of Title::getId()
Follow-Up: Iaed4871e0d32c67d4fb13e487625527f6a21e9c5

Bug: T303871
Change-Id: I37e7711c01ec7844476872af08d7d57b339512cf
2022-03-15 22:29:06 +01:00
jenkins-bot
5ce113a799 Merge "title: Restore boolean false Title::getTouched() for nonexistent page" 2022-03-09 15:16:34 +00:00
daniel
00c489cd18 title: Restore boolean false Title::getTouched() for nonexistent page
Feeding the return value of the DB query through timstamp conversion
made it so that false was turned into the current timestamp, causing
confusion and cache churn.

Bug: T298520
Change-Id: I6e10b21f6b0e40ce7e3403ffc9a41a307e945354
2022-03-09 14:56:23 +00:00
Reedy
11cc2d6993 Consistently use @deprecated since rather @deprecated
Change-Id: I301786f35cd6eb9c63fb72e0b64cffa9efd7b86b
2022-03-06 02:55:54 +00:00
Umherirrender
b126dbe3f2 Fix various documentation related to null types
The functions returning null or the class property is set explict null

Found by phan strict checks

Change-Id: I4a271093fb6526564d8083a08249c64cb21f2453
2022-02-26 10:31:24 +01:00
Ammarpad
7a85d17d52 Title: Optimize invoking newFromText() with empty string
Title::newFromText with empty string will always yields null.

But the decision to return null is only made after applying
various normalization and filtering routines, which will
eventually have zero effect on the return value. So we may
just return the null early as we do with null itself.

Change-Id: Ic277a6e8c8c0b2a0b6af78f6524b80574c4602af
2022-02-09 18:22:52 +00:00
Tim Starling
b90d2dd5c2 Optimise Skin::getLanguages()
Skin::getLanguages() was consuming 4% of index.php CPU time. In local
testing, it was called three times per page view. So:

* Memoize it, analogous to the nonfunctional code in SkinVector.
* Simplify ClassicInterwikiLookup by removing the option to pass a CDB
  file path. This was only ever supported by a WikimediaMaintenance
  script. In the unlikely event that someone is using this feature, they
  have the same motivation to switch to PHP as we did in T122362.
* Increase the size of ClassicInterwikiLookup's MapCacheLRU from 100 to
  1000. This helps greatly in the case when $wgInterwikiCache is false
  and more than 100 interwikis are requested and seems harmless
  otherwise.
* Optimise Title::getNsText() by assuming that the canonical name of
  NS_MAIN is the empty string.
* Rearrange Message::__construct() to avoid duplicate type checks.

Change-Id: I736cb74efc267fd2473a3267471735238217251c
2022-02-08 22:34:15 +00:00
Bartosz Dziewoński
2ab402323d Title: Set context page for {{PAGENAME}} etc. in getEditNotices()
The main call to Title::getEditNotices is in EditPage, where the global
title used by the message parser is correct. In other Action like
DeleteAction this would also be correct.

However, when called in API context (eg. ApiVisualEditor), or from a
special page that acts as a page action (such as
Special:EditMassMessageList or Special:Undelete) then the global title
is wrong (somewhat akin to wgPageName vs wgRelevantPageName).

Bug: T300184
Change-Id: I242e042317a1e16c8d51edbf7800c8b7d70d468e
2022-02-02 23:31:54 +00:00
Umherirrender
68808e5832 Replace deprecated JobQueueGroup::singleton()
Change-Id: Icdb301d352d302f70fefba9b40df2368cb217fd2
2022-01-27 21:37:50 +01:00
Timo Tijhof
1f34ac4526 title: Remove dated comment about inNamespace(), overall doc cleanup
* The Title::inNamespace() method discouraged use of getNamespace()
  for comparison.

  This was added 10 years ago in r103893 (commit 3414e91bae),
  however no such "change" has been made, and the new LinkTarget
  stable interface and TitleValue class contains the same getNamespace()
  method, and no warning against its use.

  My main reason for removing this comment is so that avoid fear
  against using `in_array()` with TitleValue->getNamespace() which
  this comment seems to discourage. While Title has plural
  inNamespaces(), TitleValue does not. This seems fine, as one can
  simply use in_array for more complex use cases where a range or
  list is compared against.

* Fix Doxygen warnings about invalid or unsupported XML tags
  such as `<a>`, `<siteinfo>` etc. Rephase or use backtics,.

* Fix useless IDE tooltips and Doxygen output by removing empty stubs
  from method overrides that add no new information, yet obscured
  the otherwise inherited parent destination which does have useful
  information.

* Clarify that `renderForComment` must not be mixed with other ones.
  This seems to be how it is intended. Upon realizing that, I think
  this is unreasonable and should perhaps be removed. For now, I've
  documented the hack that it seems to exist for.

* Consistently use imperative mood when phrasing method docs, and
  consistently use a brief first line description, and
  consistently separate it from other paragraphs and annotations
  with one line break.

Change-Id: I7e1819a5d7124c635de84bc64d2371a122195928
2022-01-18 22:25:09 +00:00
daniel
972dde7107 DeprecationHelper: avoid closures
The cost of creating closures adds up, so avoid it if we can be using
method names instead.

Bug: T297236
Change-Id: Ifb78d5f310fe45db58fd450c9db3c7af295ae399
2021-12-10 17:15:13 +00:00
jenkins-bot
0aef7a462b Merge "Hard deprecate TitleFactory::newFromIDs and Title::newFromIDs" 2021-11-29 21:28:11 +00:00
TChin
8371b19662 Hard deprecate TitleFactory::newFromIDs and Title::newFromIDs
Bug: T291288
Change-Id: I1789bccc276ec7c01928775f9bcb8ff301af54ff
2021-11-29 14:23:26 -05:00
jenkins-bot
daddb105a3 Merge "PageStore: avoid getPageById, since it bypasses caching." 2021-11-23 15:41:32 +00:00
daniel
de63ad823a PageStore: avoid getPageById, since it bypasses caching.
Calling getPageById when the page ID is known was supposed to improve
query performance, but since it bypasses LinkCache, it ended up causing a
spike in database queries.

This optimization can be re-introduced once we also cache PageRecords by ID.

Bug: T296063
Change-Id: Ia4ee75b7b5a71d7d858f818d6467793bc642697b
2021-11-22 17:24:13 +01:00
Derick Alangi
45c692eeef Stop accessing members of the Title class publicly
For now, let's just proxy the title object and set the
interwiki but to make things nicer, we should not provide
a title via setUp(), we should use providers.

Bug: T275763
Change-Id: I761de85ae5a839e8a695b85ce0fd7200b498da22
2021-11-22 14:22:51 +00:00
daniel
fd3a695230 Title: use PageStore instead of LinkCache
This causes Title to no longer look up fields in the database
individually, but use LinkCache instead to load an entire row from the
page table at once.

This patch also causes Title to use in-process caching for some
getters that did not use caching before, such as isNewPage()
and getTouched(). These methods do not appear to be used on critical
code paths that involve database updates.

Note that getTouched() used to take an options $db parametr. This
appears to be unused, and has been deprecated in favor of a $flags
parameter, for consistency with other getters on the class.

DEPLOY: Risky! This re-implements the internal caching logic of Title
and slightly modifies caching semantics in some cases. This may have
unforeseen consequences.

Bug: T285389
Depends-On: I103b9e1d2bf594bfc1b0ea12b980dd20bb911c3a
Change-Id: I2df81df7186025e001520f24fd498623c7184772
2021-11-02 23:12:47 +01:00
jenkins-bot
a4b5426e4c Merge "Type-hint LinkTarget" 2021-10-25 14:53:17 +00:00
Petr Pchelko
cee52db33d Type-hint LinkTarget
These type-hints are definitely correct, but it's still
a relatively risky patch cause of how messy Title is.
I did some manual review of Title, all tests are passing,
but even still if this is approved, I'll add it to phab
as a risky deployment.

Change-Id: I1ed98ddae30066956e7adbde6780d6bab54dec04
2021-10-21 00:12:51 +00:00
Cindy Cicalese
b0c0a934e4 Remove hard deprecated Watchlist methods in User, Title, and WatchAction
Bug: T292464
Change-Id: Ie9cb3036a69810344971c49c424a76c7fa1cba07
2021-10-04 15:14:24 -04:00
Petr Pchelko
d334de960a Expand local URLs to absolute URLs in ParserOutput
New option 'absoluteURLs' was added to getText method
of the ParserOutput object that replaces all links
in the page HTML with absolute URLs.

Removing the action=render special case from Title
seems safe cause we will end up replacing the result
with absolute URL if we're in a render action no matter
where Title::getLocalUrl was called from.

This change is safely revertable from the perspective
of ParserCache.

Bug: T263581
Change-Id: Id660e1026192f40181587199d3418568f0fdb6d3
2021-09-23 11:48:51 -07:00
Daimona Eaytoy
a8200aa5a8 Deprecate WikiPage methods replaced by DeletePage
Also remove the "@unstable" annotation from DeletePage.

Methods without known usages were hard-deprecated, the others
soft-deprecated.

Bug: T288758
Bug: T288759
Change-Id: I30c62572fd533526779a8ade3ab178f35bebb522
2021-09-16 20:17:45 +00:00
jenkins-bot
7ece0e7afd Merge "Title: Make use of BacklinkCacheFactory service" 2021-09-10 14:31:23 +00:00
jenkins-bot
df6ac88519 Merge "title: Avoid calling TitleArray::current on empty iterator" 2021-09-09 21:35:27 +00:00
jenkins-bot
1efeefe017 Merge "PageStore: Use LinkCache" 2021-09-09 20:04:47 +00:00
jenkins-bot
150a589ecf Merge "Title: restore behavior of getCascadeStrictionSources" 2021-09-09 19:41:48 +00:00
Umherirrender
6241125a52 title: Avoid calling TitleArray::current on empty iterator
Simplify setting of the class property

Bug: T290642
Change-Id: I0ed383532876bfbe33e07263202d908cffb39786
2021-09-09 19:16:06 +02:00
Derick Alangi
db43511e6a Title: Make use of BacklinkCacheFactory service
Change-Id: I48161585de6f329ec4037156234e0b07b3b837e6
2021-09-09 14:04:02 +01:00
daniel
abc2179820 Title: restore behavior of getCascadeStrictionSources
The behavior of getCascadeStrictionSources was changed by Ia73ea587586cb69eb5
to conform to the documented behavior: it would always return false as the
first element of the return value if there were no cascading restriction sources,
as specified in the documentation.

Hopwever, the previous behavior was to return an empty array in that
case, unless the $getPages parameter was false. That behavior seems more
senible, and there is existing code that relies on it.

This patch restores the previous behavior and updates the documentation
instead.

Bug: T218395
Needed-By: I31ca0a8987f9694bc3b312a48c2c111ceda6fa3e
Change-Id: I1f24703b80566220ac6fe8ee500e838ed7fd29af
2021-09-08 17:22:17 +02:00
Derick A
afb44d34db Title: Deprecate Title::getDefaultNamespace()
There are no callers of this method anywhere in our codebases. Seems
like a relic from past refactoring. But maybe I'm wrong.

Change-Id: Id8296ca28518a54d1712bca6b9770b918c92e0c2
2021-09-08 14:16:11 +01:00
Umherirrender
07b499fbcf build: Update mediawiki/mediawiki-phan-config to 0.11.0
Addition and remove of suppression needs to be done with the version
update.

Change-Id: I3288b3cefa744b507eadebb67b8ab08c86517c1c
2021-09-07 17:19:05 +02:00
daniel
3b6345ca16 PageStore: Use LinkCache
This makes the data stored by LinkCache compatible with PageStoreRecord,
so we can use LinkCache inside PageStore.

This causes PageStore to make use of local caching as well as WANObjectCache.

Note that getPageById() does not yet benefit from cache, but does
populate the cache.

Bug: T278940
Change-Id: Icc27a0d9299a3e4ce45521daef87ad06ec06f064
2021-09-01 08:24:34 +00:00
jenkins-bot
d66e428747 Merge "New RestrictionStore service" 2021-09-01 08:20:29 +00:00
Daimona Eaytoy
9cca05a8e8 Add typehints to several methods
These not only make the code more robust, but also help a lot when
writing unit tests: if a method is return-typehinted and its class is
mocked, the mock method will automatically return a mock of its declared
return type. Otherwise it will return null, and developers are forced to
manually mock the method if the return value is used by the SUT in a way
that doesn't accept null.

Depends-On: I628fcb1807133390c7b9b47984f512f5b1ae58d0
Depends-On: I7080bc505f5838b2f51a368da562104e206063b0
Change-Id: I59068cfed10aabf6c6002f9e9312a6ef6e7e9441
2021-08-31 16:19:13 +00:00
Aryeh Gregor
cf818256fb New RestrictionStore service
This allows checking restrictions without a dependency on Title, based
only on a PageIdentity.

Additional fixes along the way:

* Correctly return false instead of 'infinity' for
  getRestrictionExpiry( 'create' ) on an existing page
* Correctly handle non-special pages that can't exist (like media pages)
  in listApplicableRestrictionTypes() (return empty array instead of
  'create')
* Improve readability of isProtected()

The expectation change in TitleTest::testIsProtected() is because the
test was formerly broken, since it set mRestrictions without setting
mRestrictionsLoaded. (Which illustrates how this approach to testing is
essentially broken.)

Co-authored-by: Vedmaka <god.vedmaka@gmail.com>
Bug: T218395
Change-Id: Ia73ea587586cb69eb53265b2f8f7a296a2573dd0
2021-08-28 16:01:06 +00:00
Timo Tijhof
e387cd9c35 Change trivial use of getVal('action') to getRawVal
Per docs added in I18767cd809f67b, these don't need normalization
as they are only compared against predefined strings, and besides
are generally entered manually in a form, and even then would not
require the kinds of Unicode chars that have multiple/non-normalized
forms.

In nearby areas to also fix some trivial cases:

* getVal('title') obviously needs normalization.
  Use getText() to make this more obvious.

* getVal() compared against simple string literals within the code
  obviously don't need normalization (e.g. printable === 'no').

* Change hot code in MediaWiki checking for whether 'diff' or 'oldid'
  are set to getCheck (which uses getRawVal) instead of getVal.
  As a bonus this means it now handles values like "0" correctly,
  which could theoretically have caused bad behaviour before.

Change-Id: Ied721cfdf59c7ba11d1afa6f4cc59ede1381238e
2021-08-26 22:11:58 +01:00
Umherirrender
b4bd3d4ee8 Remove dead variables and functions and unneeded parenthesis
Found by sonarqube

Change-Id: I3464d25e94d98aaca55d9209d5175542b335f994
2021-08-13 21:41:59 +02:00
Thiemo Kreuz
69242b0876 Various updates and fixes to PHPDoc documentation
Some minor updates I collected in my local dev environment the
past months.

Change-Id: I30d5339bc262d54ba76e2860a3a3e9e5f002fdc3
2021-08-09 09:26:23 +02:00
Aryeh Gregor
af97e72e76 Don't needlessly reset article ID
Title::resetArticleID() clears various caches and is meant for when a
page was inserted or moved or similar. I can't see any reason that it
needs to be called by Title::castFromPageIdentity. Doing so wastes
resources and prevents use of the method in unit tests. It is also
surprising for a cast to have side effects.

Change-Id: I71c523e7406d493c52199c3a5a9ca7cd414bb5eb
2021-08-02 17:35:25 +03:00
Aryeh Gregor
b19db60c70 Hard-deprecate Title::isNamespaceProtected
No callers, deprecated in 1.34.

Change-Id: If2e1c762f91e3c8255fbb58b7c9f01e8929a7fa2
2021-07-29 17:15:33 +03:00
wikitrent
a19be13f7f Update the todo on Title.php
Changed format to TODO: so modern IDEs
will be able to guide developers to the
TODO

Change-Id: I40c47d5dfe976752812a986a3284d978b794f144
2021-07-22 08:25:06 -05:00
libraryupgrader
5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00
Derick A
9a5d4fd585 Title: Avoid accessing class members directly & use accessor methods
First step here is to avoid accessing the Title class members directly.
Instead, use their corresponding accessor methods. Affected members are,

$mTextform, $mUrlform, $mDbkeyform, $mNamespace, $mInterwiki, and $mFragment.

TODO: The next step from here would be to find usage of direct access and
replace them with calls to accessor methods while making the members
private.

Bug: T275763
Change-Id: I9b3efe7a43597f14e19d5db8e824f65aeb169d0b
2021-07-12 16:11:59 +01:00
Petr Pchelko
9d6403f9fc Consistently normalize Title::mFragment before setting
Bug: T285951
Change-Id: Ifa04da54da8acdede6258330110d49453a8fffc3
2021-07-01 11:20:05 -07:00
DannyS712
4f9970f30b Fix a bunch of random typos
* yeild -> yield
* paramter -> parameter
* seperator -> separator
* neccesary -> necessary
* inital -> initial
* intial -> initial
* repsonse -> response
* retreived -> retrieved

Bug: T201491
Change-Id: I461941b027590997448f3bdd8a137a48bb338beb
2021-06-29 11:32:04 +00:00
Thiemo Kreuz
2ba01c7ee7 Remove some more comments that literally repeat the code
… including PHPDoc tags like `@return <type> $variableName`.
A return value doesn't have a variable name. I can see that
some people do this intentionally, repeating the variable
name that was used in the final `return $var;` at the end
of a method. This can indeed be helpful. I leave a lot of
these untouched and removed them only when it's obviously
wrong, or does not provide any additional information in
addition to what the code already says.

Change-Id: Ia18cd9f25ef658b08ad25b97a744897e2a8deffc
2021-06-18 21:23:56 +00:00
James D. Forrester
f2f9345e39 Replace uses of DB_MASTER with DB_PRIMARY in documentation and local variables
This is just a start.

Bug: T254646
Change-Id: I9213aad4660e27afe7ff9e5d2e730cbf03911068
2021-05-14 12:40:34 -07:00
Petr Pchelko
695e61ce14 Clean up hard deprecated Title methods
Depends-On: If27bb6b5142d09bc9293d080e97b6642462219f4
Change-Id: I37f012e53d1c881292a19aac87eb107636c6bfbe
2021-05-11 07:41:18 -07:00
daniel
1823345c52 Title: avoid instance cache pollution
Bug: T281337
Change-Id: I2e8d18b2fc10509097f66287b2543217f4eb9b6a
2021-05-07 11:37:54 +02:00
DannyS712
f60ea069ba Remove remaining non-test uses of Revision objects
The following methods no longer support Revision parameters:
- CategoryMembershipChange::__construct
- ContentHandler::getUndoContent
- DerivedPageDataUpdater::prepareUpdate
- DifferenceEngine::getRevisionHeader

The following methods were removed entirely:
- Title::countAuthorsBetween

The following methods return arrays that formerly include
a 'revision' key that would emit deprecation warnings when
accessed and return a Revision object. The Revision object
has been removed from the arrays, and the 'revision-record'
key should be used to get the relevant RevisionRecord instead:
- PageUpdater::doModify
- PageUpdater::doCreate
- Parser::statelessFetchTemplate

The ParserOptions `templateCallback` option is a callback
that is called in Parser::fetchTemplateAndTitle() and should
return an array - the 'revision' key to that array used to
be a Revision object and was used if no 'revision-record'
was returned - it is now ignored.

Bug: T247143
Change-Id: I163ada88d649c75697aff4fa31a3a3c0bdef78b7
2021-05-04 13:10:22 -07:00