...by instance caching the result on the LinkTarget object.
Title::getPrefixedText() is an extremely hot function that has been
fully optimized over the years due to its usage basically everywhere in
MediaWiki.
Apply the same treatment to TitleFormatter, but keep the caching as part
of the LinkTarget instance so we can share caches across Title and
TitleFormatter. Once Title is switched over to using TitleFormatter
internally, we can probably centralize the cache again, and get rid of
the public but marked @private member variables.
Bug: T201801
Change-Id: I4ae2d6b176f69f66720473aeae85e39a601a9781
fbc1449653 (Make Titles with an unknown namespace ID refer to
Special:Badtitle.) was never implemented in TitleFormatter, so let's do
that.
While we're at it, formatTitle() is now structured in the same format as
Title::prefix(), to make it easier to compare code between the two
implementations. The existing tests verify that this is a no-op. There's
a little extra indirection in getPrefixedDBkey(), which now goes through
dbkeyform -> textform -> dbkeyform, but reduces duplication of code,
which I think is worth it.
Bug: T165149
Change-Id: I4e43487a52663d2a647f9e71d487f58e25474f7a
It's hardcoded to empty string, so we can skip some code.
Profiling (after switching the benchmark script to use NS_MAIN) showed
no noticable improvements in getPrefixedText().
Change-Id: Id6b044a51648d0a3f58331ac0427f9d5cd9d8f0f
Previously, `new TitleValue()` was roughly twice as slow as
`Title::makeTitle()`. Switching to basic is_int/is_string checks
makes TitleValue roughly twice as fast as Title!
Tested with benchmarkTitleValue.php.
Bug: T201801
Change-Id: Idccf159983145c1c11af9182292e1d5f704ba077
Unicode 6.3.0 (September 2013) the added additional directional
formatting characters:
U+061C ARABIC LETTER MARK
U+2066 LEFT-TO-RIGHT ISOLATE
U+2067 RIGHT-TO-LEFT ISOLATE
U+2068 FIRST STRONG ISOLATE
U+2069 POP DIRECTIONAL ISOLATE
https://www.fileformat.info/info/unicode/version/6.3/index.htm
This change strips the new directional formatting characters from the
title like the directional formatting characters from Unicode 1.1.0
(June 1993).
Any existing titles containing the new Unicode directional formatting
characters get stripped by a run of maintenance/cleanupTitles.php after
deployment.
This change also allows to insert the new Unicode directional
formatting characters into the DISPLAYTITLE.
Change-Id: I2279f51048f5252c2e4280ec6a13f060ff9967cb
This change strips all soft hyphens from the title. This is already
done for Unicode bidi characters (T5696).
URLs with soft hyphens (%C2%AD) get redirected (301) to the URL without
soft hyphens (T145605):
https://de.wikipedia.org/wiki/Bosnatal%C2%ADbahn get redirected to
https://de.wikipedia.org/wiki/Bosnatalbahn
Links in wikitext containing soft hyphen "[[Bosnatal<AD>bahn]]" (the
"<AD>" stands here for a soft hyphen) links "Bosnatalbahn" but displays
"Bosnatal<AD>bahn".
This change also allows to insert soft hyphens into the displaytitle
(T66528). This allows to insert soft hyphens into the first heading for
manual hyphenation of titles with very long words.
This change prevents access to any existing articles containing soft
hyphens in the title. After deploying this change a run of
maintenance/cleanupTitles.php must performed to rename existing titles
with soft hyphens. Before deploying this change existing articles and
redirects with soft hyphens in the title can already renamed or
deleted.
Bug: T121979
Bug: T66528
Change-Id: Ie13626c433cdb460dbf00b3bba28d1bb5a7b6d6a
Redundant given this is the project-wide license already,
especially in file headers that already include the GPL license
header.
This and other minor fixups based on feedback from Ie0cea0ef5027c7e5.
* Add @file where missing.
* Move @ingroup and @deprecated from file to class doc where needed.
Change-Id: I7067abb7abee1f0c238cb2536e16192e946d8daa
This switches from private to protected access of TitleValue
properties, and marks them as deprecated instead as per the
deprecation policy.
Partial revert of I3d8315ade6aa70bda43d90b0b32b730d8c9cbd2e
Change-Id: Ie290b6a84635ebb5865e82ae24fe4b27224e601a
* Right now, one or two are permitted. This patch limits it to one.
The current behaviour seems more a byproduct of refactoring than an
explicit goal.
* Note that this will break links on a handful of pages surfaced in
Parsoid's roundtrip testing.
Change-Id: Icabd34bbf15781bb891bd8e0c079d1a65eb28595
A null $errorMessage constructor argument has not been supported since
I43d988602b, since wfMessage (via the Message constructor) throws an
exception if the message key is null. It follows that getErrorMessage()
can never return null.
Bug: T99818
Change-Id: I2cbf4909e7237b0a91d100cc5478fb4cfee1d748
This patch allows for a custom InterwikiLookup service
when constructing MediaWikiTitleCodec instances.
If not specified, it continues to get the service from
MediaWikiServices::getInstance()->getInterwikiLookup().
This patch will allow a fully customized instance
creation, without any global state.
Change-Id: Ica87aff5df4534aae0a32e307b27d88b3df023b4
If an XML dump of a wiki is exported using dumpBackup.php, and there are
pages in a namespace that is not registered (perhaps because of a missing
extension), they will appear in the dump in the form
<page> ... <title>PageTitle</title> <ns>1234</ns> ... </page>
This caused the ForeignTitle code to raise an undefined offset error,
because it assumed that the <title> element was of the form
"Namespace:PageTitle" when <ns> was nonzero. This assumption is not valid.
Now, the importation of such dumps will no longer throw errors and the
pages will be correctly imported, although possibly to unexpected
locations.
Bug: T114115
Change-Id: I0271435dc208e7ea118339584f8a0e359c96113a
The current output "Bad value for parameter $dbkey: invalid DB key" is
useless for actually working out which DB key is to blame.
Bug: T146778
Change-Id: Iaf57e25ab27b5065469c5dc5de0a1b881c48210c
We already throw around some exceptions that are localized
(ErrorPageError and its subclasses, MalformedTitleException), but
there's no standard way to recognize them. Let's change that.
Then let's use them in the API to be able to have internationalized
errors when such exceptions are caught, instead of wrapping the
English-language version.
Change-Id: Iac7c90f92a889f8de9dae373547c07b884addaea
The MediaWikiPageLinkRenderer interface was introduced with TitleValue
in 1.23, but was barely used outside of two special pages in MediaWiki
core. It has now been superceded by MediaWiki\Linker\LinkRenderer and
should be removed in favor of that.
Change-Id: Ib56d5731d4803aa417942aced7f3dedf2104bbde
This ocassionally happens for whatever reason, but it doesn't really
make sense to throw an exception when creating a broken-looking link
would also work. We already do this for TitleParser::getPrefixedDBkey(),
and this also matches the behavior of Title::getNsText().
Bug: T136352
Bug: T136356
Change-Id: Ic7eb17f8917f7fbb28b11d94b742dac1fe5582a1
In TitleFormatter::getPrefixedDBkey(), match the
Title::getPrefixedDBkey() behavior for non-existent namespaces by using
an empty string for the namespace and including a leading colon.
Change-Id: I195c36df69963c7409711dd97bece078f61faf77
This adds support to the LinkTarget interface and TitleValue
implementation for having an interwiki component, matching the function
names used in Title.
MediaWikiTitleCodec was updated accordingly.
The motivation behind this change is to be able to fully use LinkTarget
in the Linker rewrite instead of depending upon Title.
Change-Id: I6666b64f0e336aadc7261e7ca87ac2e498c61856
The createFragmentTarget function allows for switching the fragment on a
target in an easier way. TitleValue already had a now-renamed
createFragmentTitle function (no uses outside of tests), and an
implementation was added for Title.
This will also help with reducing the amount of public usage of
Title::setFragment(), which is deprecated.
Change-Id: I1e8ba2f85e748b1b4394fb2f2a1ccce69cf6e3c5
LinkTarget::hasFragment() is a helper function which returns a boolean
of whether the target has a fragment. Title already had such a function,
and one was added to TitleValue.
Co-Authored-By: addshore <addshorewiki@gmail.com>
Change-Id: I49e607ae5a58c3aef96d0246297740e7d88ac816
Every single caller of Title::newFromLinkTarget() already special cases
when the LinkTarget object is already a Title, so move that logic into
one function.
Change-Id: Iba5432ae01c87850e5b34893092427c5b1629188
To be used by things that do not care if they are
passed a Title or TitleValue so long as it has a
dbkey, namespace, possible fragment and text
Example uses include:
LinkBatch::addObj
MediaWikiPageLinkRenderer methods
MediaWikiTitleCodec methods
PageLinkRenderer methods
TitleFormatter methods
Change-Id: I2aa1a82129bb01155924a8e6a403c7a47391432f