Commit graph

71 commits

Author SHA1 Message Date
Fomafix
3ee1560232 No yoda conditions
Replace
  if ( 42 === $foo )
by
  if ( $foo === 42 )

Change-Id: Ice320ef1ae64a59ed035c20134326b35d454f943
2018-11-21 17:54:39 +01:00
Kunal Mehta
d0f56e873d Optimize TitleFormatter::getPrefixedText() to Title performance
...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
2018-08-17 17:43:52 -07:00
Kunal Mehta
63b2003520 TitleFormatter: Implement fbc1449653 and unify prefix logic
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
2018-08-17 17:43:52 -07:00
Kunal Mehta
e4e3e64f3a TitleFormatter: Remove indirection from getText()
At the end of the day, the output is identical to LinkTarget::getText().

Change-Id: Ifddafb79d7602ba5e368cc40f99c56e22a56d506
2018-08-17 17:10:46 -07:00
Kunal Mehta
c7cd323c6b TitleFormatter: Don't look up namespace name for ns 0
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
2018-08-17 17:10:46 -07:00
Kunal Mehta
1acbfef521 TitleValue: Avoid function call for internal property
Change-Id: I16342469a8122bd46cada11fd1f1d3f88d2e8d1e
2018-08-17 17:10:46 -07:00
Kunal Mehta
9b4567f414 TitleValue: Don't use Assert for basic type checks
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
2018-08-14 21:09:44 -07:00
Kunal Mehta
f339c90851 Have TitleParser::parseTitle() default to NS_MAIN to match Title
Matches the default parameters of Title::newFromText().

Change-Id: Id08312d424be9ae7e64688bb21687204ae77c560
2018-08-14 20:58:34 -07: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
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00:00
Jforrester
9befbd38dc Revert "Strip soft hyphens (U+00AD) from title"
This reverts commit 6b8a5a137d.

Change-Id: Ica5abe69c316792aa2f7eafad9b1d63183b282a8
2018-05-31 10:45:11 -07:00
Jforrester
722ff7b1fc Revert "Strip Unicode 6.3.0 directional formatting characters from title"
This reverts commit 7564624d1c.

Change-Id: I5d596f8f3c784920829de6ae50b270b0396369e0
2018-05-31 10:45:11 -07:00
Fomafix
7564624d1c Strip Unicode 6.3.0 directional formatting characters from title
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
2018-05-10 08:58:23 +02:00
Fomafix
6b8a5a137d Strip soft hyphens (U+00AD) from title
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
2018-05-10 08:56:29 +02:00
Timo Tijhof
bee9f4db96 Remove various redundant '@license' tags in file headers
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
2018-01-12 18:15:11 +00:00
addshore
d5330cf2a8 Deprecate access to TitleValue properties
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
2017-11-20 19:03:06 +00:00
addshore
e1ec62a00b @since tags & private class properties for TitleValue
Change-Id: I3d8315ade6aa70bda43d90b0b32b730d8c9cbd2e
2017-11-18 20:23:32 +00:00
Arlo Breault
51d3cc80f1 Remove outdated comment
* Presumably, should have been part of 3f7615be.

Change-Id: I096c65e72e07c2e1f5a8cd96f6cb930508db8568
2017-09-05 18:30:24 -04:00
Arlo Breault
0e1b52a40e Make multiple colons escaping interlanguage links invalid, consistently
* 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
2017-07-06 17:09:25 -04: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
Lucas Werkmeister
4d04f91c83 Make MalformedTitleException errorMessage non-null
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
2017-06-21 15:22:05 +02:00
jenkins-bot
22806b0a45 Merge "Handle missing namespace prefix in XML dumps more gracefully" 2017-03-08 05:07:57 +00:00
Yuri Astrakhan
3f7615be58 Add custom InterwikiLookup to MediaWikiTitleCodec
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
2017-01-14 18:55:42 +00:00
Yuriy Shnitkovskiy
85a52faa37 Removed deprecated usages of Interwiki methods in core
Change-Id: Ibd25968660466c44189ccb01df1d8bec6e1b207c
2017-01-10 12:19:31 +02:00
This, that and the other
ef8bc825c6 Handle missing namespace prefix in XML dumps more gracefully
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
2017-01-01 09:11:45 +00:00
This, that and the other
100bebdbfa TitleValue: Include the invalid DB key in the message when throwing
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
2016-12-31 16:30:32 +11:00
Brad Jorsch
a90bbf1a48 Add ILocalizedException interface
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
2016-12-08 13:53:24 -05:00
Kunal Mehta
25ea70f437 Remove unused MediaWikiPageLinkRenderer class and interface
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
2016-06-23 14:15:21 +00:00
Kunal Mehta
a22ab0eab0 TitleParser: In formatTitle(), don't throw exceptions on bad namespaces
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
2016-05-26 13:34:18 -07:00
Kunal Mehta
147ec4cad8 TitleFormatter: Match Title behavior for non-existent namespaces
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
2016-05-12 11:36:30 -07:00
Kunal Mehta
ab623befc5 Add LinkTarget::inNamespace() helper function
And implementation for TitleValue, plus tests

Change-Id: I42c301e28938dcd55580e20b7c1ddefcbf5a2bef
2016-05-12 08:28:26 +00:00
Kunal Mehta
7688e781b1 Add TitleFormatter::getPrefixedDBkey() and implementation
Matches the expected result of Title::getPrefixedDBkey(), and will be
used in LinkCache.

Change-Id: I5ca65d07e2ae28778d060208e2bfe3fc0529992a
2016-05-11 17:54:40 +00:00
Kunal Mehta
9b1f8b4ca3 Add interwiki support to LinkTarget and TitleValue
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
2016-04-26 22:25:28 -07:00
Kunal Mehta
c9d885f3b4 Namespace LinkTarget under MediaWiki\Linker
And add a GPL file header while we're at it.

Change-Id: I15a6f240124c879b21fb655ade1baaebf4f34ffd
2016-04-21 17:19:10 -07:00
Kunal Mehta
59d838caea Add LinkTarget::createFragmentTarget() function
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
2016-04-21 17:19:04 -07:00
Kunal Mehta
55ec9f2e4d Add LinkTarget::hasFragment() helper function
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
2016-04-20 15:51:39 -07:00
Kunal Mehta
aa21cf32fa Specially handle Title objects in Title::newFromLinkTarget()
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
2016-04-19 22:21:09 -07: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
jenkins-bot
920c06e42c Merge "Use LinkTarget in TitleValue only methods" 2016-02-03 13:36:59 +00:00
jenkins-bot
9a3a412f86 Merge "Add LinkTarget interface" 2016-02-03 13:23:08 +00:00
addshore
ab66a4427a Use LinkTarget in TitleValue only methods
Change-Id: Iee4b183ae54457d0c6cd3473f9fed3207742b54f
2016-01-29 12:51:52 +01:00
addshore
1c63abcda3 Add LinkTarget interface
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
2016-01-29 12:48:21 +01:00
addshore
94528ec9fe Make ForeignTitle properties private
Change-Id: If9ea22f412a378aa1090ba761c19f77c97da7df0
2016-01-26 19:36:52 +01:00
umherirrender
df48508ef6 Fix typo: mapp -> map
Change-Id: Id5cad30a3a83aa0da4ef2c608510c66cea06d7d0
2015-11-22 17:49:03 +01:00
umherirrender
96473ea6e4 phpcs: Fix some "Assignment expression not allowed"
Found by new version of mediawiki/codesniffer
https://integration.wikimedia.org/ci/job/mediawiki-core-phpcs/1939/consoleFull

Change-Id: I673f71fd0dfc8d6ba1ce6c3d5da21787ff95cb32
2015-11-01 21:07:00 +01:00
Siebrand Mazeland
b77eaa1a1a Fix two PHPCS warnings in NaiveForeignTitleFactory.php
Change-Id: I61f1e1beab7e6fdd6e817b728a837d4ea57f435f
2015-09-28 14:19:29 +02:00
Vivek Ghaisas
c54766586a Fix issues identified by SpaceBeforeSingleLineComment sniff
Change-Id: I048ccb1fa260e4b7152ca5f09b053defdd72d8f9
2015-09-26 23:06:52 +00:00
Amir E. Aharoni
870dbf0659 Make lines short to pass phpcs in six files under includes/
Bug: T102614
Change-Id: I91a2d4f4bf86a22c8bb466da0e2f95ea27c571a3
2015-09-26 18:41:01 +00:00
Jackmcbarn
c4f69827bc Fix some PHPCS issues
Change-Id: I6289ce362f8dfde7baf2b665f082820898844973
2015-06-26 01:32:28 -04:00
umherirrender
2b368515ec Format number for message 'title-invalid-too-long'
Follow-Up: I4da8ecb457a77473e32d745ba48ab8505b35e45f
Change-Id: I30ebf2a21bb09d992140baa2bd8707a674da6d51
2015-05-23 15:05:38 +02:00