Commit graph

79 commits

Author SHA1 Message Date
Kunal Mehta
9e5edca6c5 Title: Fix isRawHtmlMessage() for messages with underscores
Title::getRootText() uses the text form (spaces) of the title, while
$wgRawHtmlMessages was specifying them in dbkey form (underscores).

And add tests while we're at it. Which spotted that the existing
code didn't work. Whoops. Fixed.

Change-Id: I05eea553c588e0f99f862e07ad15386507ed0728
2018-08-31 09:45:01 -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
Kunal Mehta
c4e5a9dd97 Avoid deprecated LinkCache::singleton()
Change-Id: Ie0e5c4ef0fe6ec896378bb2433af0898655dd907
2018-06-10 23:55:11 -07:00
Umherirrender
45da581551 Use ::class to resolve class names in tests
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: Ie541a7baae10ab6f5c13f95ac2ff6598b8f8950c
2018-01-26 22:49:13 +01:00
Kunal Mehta
0c77841534 Add @covers tags to miscellaneous tests
Change-Id: I7e65c1734aef01cd6395ee65204a0158d1635b0c
2017-12-24 23:29:00 -08:00
Max Semenik
4d8b064fae Title: Use a more proper way of detecting whether interwikis are local
Bug: T181575
Change-Id: Ifcfe609ce01b174120b81b8c0bf82c4ed6077641
2017-11-30 23:32:50 +00:00
addshore
e6e59bb425 Remove method level @group Database tags
MessageTest did not have the group at class level
either so that is added in this patch.

Change-Id: Idb6213282d6854044f374c9df51ea32d0a5523e1
2017-11-23 19:20:44 +00:00
daniel
fdf83070cd Add Title::isValid method
Make the notion of Title objects representing invalid titles explicit.

Bug: T165149
Change-Id: I89aaabdff9614fe63bd1244784a1d677dbc26f9e
2017-09-08 22:56:42 +00:00
daniel
f284dffc21 Introduce Title::getTalkPageIfDefined.
This is part of the effort to remove the assumption that every page
can have a talk page. Before we can merge Icee208dc4 which makes
Title::getTalkPage() throw an exception of no corresponding talk
namespace is defined, all extensions that call getTalkPage() must
be changed to either check canHaveTalkPage() first, or to use
the conveniance function getTalkPageIfDefined() instead.

Bug: T165149
Bug: T172146
Change-Id: I6d2613d8f7105048022f8093186dc57f1f8173ab
2017-08-01 19:09:13 +02:00
daniel
f8ac44cca5 Rename canTalk methods
This renames Title::canTalk to Title::canHaveTalkPage
and MWNamespace::canTalk to MWNamespace::hasTalkNamespace.

Bug: T165149
Change-Id: I342a273a497b31282388b13bf76dadfb1122dcbb
2017-06-25 10:15:30 +00:00
daniel
fbc1449653 Make Titles with an unknown namespace ID refer to Special:Badtitle.
Without this patch, Title::getPrefixedText() would return ":Foo"
if the namespace was unknown, potentially creating a misleading
link to the main namespace. With this change, getPrefixedText()
will return something like "Special:Badtitle/NS12345:Foo".

Note that round trip behavior is broken either way.

Bug: T165149
Change-Id: I0d491a2b58ff45f207f83ee62ca6e7e6ffbf790a
2017-06-14 04:31:07 +00:00
James D. Forrester
1e9c361960 tests: Replace implicit Bugzilla bug numbers with Phab ones
It's unreasonable to expect newbies to know that "bug 12345" means "Task T14345"
except where it doesn't, so let's just standardise on the real numbers.

Change-Id: I46261416f7603558dceb76ebe695a5cac274e417
2017-02-21 02:14:34 +00:00
Bartosz Dziewoński
71ec883cb3 mw.Title: Correct handling of Unicode whitespace and bidi control characters
MediaWiki titles may not contain Unicode bidi control characters, e.g.
U+200E LEFT-TO-RIGHT MARK. They are silently stripped and such a
title is considered valid.

MediaWiki titles may not contain any whitespace other than a regular
space. Most of them are silently replaced with a regular space and
such a title is considered valid, but there are some (e.g. the tab
character) which make the title invalid. I'm not sure if this is an
intentional behavior, but I added a test case to verify it.

Bug: T143759
Change-Id: If8fad1f896027c5d93a62b0785923a39136c6a36
2016-08-31 00:04:29 +00:00
Kunal Mehta
f3d0fa6b79 Add tests for Title::getPrefixedText()
Change-Id: I2afd7ef8b6fd733dd2928a82e89b158fc6fab56d
2016-05-12 11:36:30 -07:00
Kunal Mehta
f1e8d27a91 Add TitleParser and TitleFormatter to MediaWikiServices
Depends-On: Ibfd0a7f98f50506cd8402f966682f320bf715c8a
Change-Id: I81d48616afd1ab2bde1a5f1d12f4aefb1c866d43
2016-05-11 10:18:40 -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
Timo Tijhof
ecb47bfb8f phpunit: Abstract user-lang override in MediaWikiTestCase
Removed redundant set up in these classes (same as their paren
class MediaWikiLangTestCase does already).
* BlockTest
* ExportTest
* MWTimestampTest
* TitlePermissionTest

Change-Id: I28d18cb797bb249981727b02dffce4f0d8682b02
2016-03-09 16:55:50 +00: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
Amir E. Aharoni
f9d0c98e16 Make lines short to pass phpcs in 2 files under tests/phpunit/includes/
Bug: T102614
Change-Id: I21a7cbc40a3015c3d6cbea1b9d7df58a358beb6a
2015-09-30 16:17:35 +00:00
Vivek Ghaisas
c54766586a Fix issues identified by SpaceBeforeSingleLineComment sniff
Change-Id: I048ccb1fa260e4b7152ca5f09b053defdd72d8f9
2015-09-26 23:06:52 +00:00
Vivek Ghaisas
9f5b6f5aeb Fix whitespace issues around parentheses
Fix issues found by MediaWiki.WhiteSpace.SpaceyParenthesis sniff.

Bug: T102617
Change-Id: Iec7f71e64081659fba373ec20d9d2006306a98f4
2015-06-16 22:14:02 +03:00
Matthew Flaschen
ba03c0139a Support Title::GAID_FOR_UPDATE for Title->exists
Without this, you have to call:

getArticleID( Title::GAID_FOR_UPDATE )

then either use that directly (bypassing the TitleExists hook) or
call exists afterwards.

Change-Id: Ieec5579e4de2a289795364e7001028932535e435
2015-05-05 03:13:26 +00:00
Bartosz Dziewoński
708918ccbf Provide detailed information about invalid titles
includes/Title.php
* The private method Title::secureAndSplit() now throws a
  MalformedTitleException instead of returning false on invalid
  titles.
* Added Title::newFromTextThrow(), which behaves exactly like
  Title::newFromText() but throws MalformedTitleException instead of
  returning null on invalid titles.

includes/title/MediaWikiTitleCodec.php
* Provide more information with the thrown MalformedTitleExceptions.

includes/MediaWiki.php
* Use the new Title::newFromTextThrow() to get detailed error
  information, display it.

Change-Id: I4da8ecb457a77473e32d745ba48ab8505b35e45f
2015-04-30 23:50:07 +02:00
aude
9d60ec5a4f Add @group Database tags to tests that need it
These tests all involve database access in some way,
and thus need @group Database tags.

These failed when setting a bogus database password
and then running the tests.

Change-Id: I7f113a79ac44d09d88ec607f76b8ec22bc1ebcf1
2015-04-01 11:20:23 +02:00
Kunal Mehta
37ef4c4ad4 Simplify TitleTest::testWgWhitelistReadRegexp()
* Use setMwGlobals instead of doing it manually
* Give user no rights to avoid a database query

Change-Id: I3ab20972314e39bb81bc97c89fce7a4c0d331fe6
2015-03-27 22:22:51 -07:00
umherirrender
6b2729ced9 Set wgMetaNamespace on TitleTest.php
Also added it to the MediaWikiTitleCodecTest.php (which seems not exists
at time of bug creation)

Bug: T67879
Change-Id: I8411d46320201b594ebaa56953dc355d863d0500
2014-11-26 18:05:30 +01:00
umherirrender
0731f52e9e Use setMwGlobals in TitleTest::testGetPageViewLanguage
Change-Id: I42cb31bf7c1fa1b77f2e8465e7e1e316972fec09
2014-10-16 19:44:39 +02:00
Kunal Mehta
b3dd0fb560 Improve test coverage of Title::isValidMoveOperation
Change-Id: Ifd81b0a894714ca94ab3e627ba83c881d96c3377
2014-09-19 19:23:19 +00:00
Timo Tijhof
96771e3a65 test: Clean up data providers that should be static
Follows-up b36d883.

By far most data providers are static (and PHPUnit expects them
to be static and calls them that way).

Most of these classes already had their data providers static
but additional commits sloppily introduced non-static ones.

* ResourceLoaderWikiModuleTest, 8968d8787f.
* TitleTest, 545f1d3a73.
  Odd unused method 'dataTestIsValidMoveOperation' was introduced
  in 550b878e63.
* GlobalVarConfigTest, a3e18c3670.

Change-Id: I5da99f7cd3da68c550ae507ffe1f725d31e7666f
2014-09-18 12:52:44 -07:00
Chad Horohoe
545f1d3a73 TitleTest: Break secure and split test into two tests with providers
Change-Id: Ib33819c3e8828c154951ab76db2a283e3a549ea0
2014-09-05 10:52:51 -07:00
Chad Horohoe
6c50c0cb9e TitleTest: fix minor todo about test naming
Change-Id: I1aa29b859cb1dcf0ff3c30c23f5d4c6b412f72f9
2014-08-28 11:38:18 -07:00
Antoine Musso
e5eb717d25 tests: avoid sql queries in TitleTest
testIsAlwaysKnown was invoked on an interwiki link. To have the test
pass, we used addDBData() to inject the interwiki in the database.  This
end up being execute on each test when it is only needed for a single
assertion.

Instead of creating a Title, use Title::makeTitle() to populate the
interwiki, thus letting us avoid the database hits.

Random timing: 1.20s -> 150ms.

Change-Id: I63a4e7b9af5eacb7dc1de4b33b8e631e6c3f1fa6
2014-08-22 23:16:01 +00:00
umherirrender
7ff005407e Remove colon after @deprecated/@param/@todo/@note
Change-Id: I4e66dad85eecf7e8e03ac760af900395e1bc11b6
2014-07-24 11:30:25 +02:00
Max Semenik
062cfffeb2 Integrate Special:MyLanguage from the Translate extension
In practice, this means the MediaWiki canonical way to uniquely and
humanly name translation pages on a multilingual wiki becomes
$source_page_title + '/' + $target_language_code, irrespective of
the enabling of the navigational subtitle and of the relative
titles (..) syntax for linking and transcluding, which are unrelated
and keep being controlled by $wgNamespacesWithSubpages.

This syntax has been prevalent on most wikis including mediawiki.org
since at least 2009, also thanks to #titleparts in ParserFunctions.

The part of the special page's functionality that made links to it red
when destination page wasn't present will be integrated with a follow-up
commit because they require more performance work.

I'm also including some Title tests that were written for testing the
redlinking functionality but are useful in general.

Bug: 66762
Change-Id: I520077c931431b5919e0208f75c20b5b25f3159d
2014-07-22 11:33:15 -07:00
jenkins-bot
01da3da43d Merge "Allow local interwiki links with an empty title part" 2014-07-03 17:46:48 +00:00
Timo Tijhof
c8c4056551 Title: Add unit test to assert ":A" is a valid title value
Mostly to catch regressions. While this is an invalid title,
it is valid as syntax when creating a Title *object*, the actual
page title itself does not allow leading colons.

Change-Id: Idbe8a3bfe487926c5fc8bdcfa69a957fc9d0bc49
2014-04-28 19:50:32 +02:00
Siebrand Mazeland
4916e08d8e Pass phpcs-strict on some test files (4/x)
Change-Id: Ifdbb431a6018c514b15ae71cc0c21b653a5e466d
2014-04-24 18:51:42 +02:00
This, that and the other
c815f959d6 Allow local interwiki links with an empty title part
For example, [[en:]] on enwiki. These links were for some reason considered
invalid. However, to support use-cases such as cross-wiki transclusion and
the importing of templates across wikis, this type of link should be
allowed.

I can't see that this would break anything. If anything, it will "un-break"
some links.

Should MediaWikiTitleCodec depend on Title::newMainPage? Almost certainly
not, but I note that splitTitleString is earmarked for demolition, so I
expect that the confusing dependency-web will be cleaned up in the future.
I also note that MediaWikiTitleCode already uses various static methods of
the Title class.

Bug: 64167
Change-Id: I27495aa62e6059c7725387135ae0358d7e6fb35b
2014-04-21 13:20:24 +10:00
jenkins-bot
79ebb4b028 Merge "Allow additional interwiki prefixes on local interwiki links" 2014-04-20 14:00:22 +00:00
umherirrender
092cd8ee31 Fixed some @params documentation (tests)
Swapped some "$var type" to "type $var" or added missing types
before the $var. Changed some other types to match the more common
spelling. Makes beginning of some text in captial.
Also added some missing @param.

Change-Id: Ic8aaf0a93796b97d0fa4617c1f86ff59f4b36131
2014-04-17 20:43:42 +02:00
Aude
1b0e883698 Revert "Temporarily remove tests added in I8eef5a165"
this was to be temporary, right? we need the tests in.

If there are issues with jenkins, this is not the *best*
way to fix them.

This reverts commit 44a1968531.

Change-Id: I5dd60a9818c28155d96a6642c588781667e682c3
2014-04-06 13:18:07 +00:00
This, that and the other
5461fd3f28 Allow additional interwiki prefixes on local interwiki links
This code was added by Brion back in 2004 as part of r6398.

According to Brion, links like [[en:wikt:foo]] on English Wikipedia are
"just crazy!", but I can't see any reason to disallow them.

Bug: 61357
Change-Id: If449e60a0ef95cfe3dd6f4b1809ac012be62a0ea
2014-04-05 13:34:34 +11:00
Ori Livneh
44a1968531 Temporarily remove tests added in I8eef5a165
Although the tests themselves pass, their introduction to the codebase pushed
the total number of tests past some threshold at which Jenkins starts
segfaulting. So remove the tests as a temporary workaround, and revert this
patch once the bug with Wikimedia's Jenkins deployment (bug 43972) is resolved.

Change-Id: I5722faf0e4216e1c1f98ecc1f2dba744b240b7d3
2014-03-28 13:36:26 -07:00
daniel
154bcdc63f Introducing TitleValue
TitleValue is intended to be a light weight alternative to the Title
class. Any operations on TitleValue are implemented in separate
service classes, like TitleFormatter and PageLinkRenderer. See
<https://www.mediawiki.org/wiki/Requests_for_comment/TitleValue>
for more information.

This change updates SpecialCategories and SpecialLinkSearch to use
TitleValue instead of Title, to demonstrate how TitleValue would be
used, and how the necessary services can be injected and applied.

The intention is to improve testability and reusability; these
advantages will however only become apparent with further refactoring
of the respective special pages. This will be done in follow-up
changes.

More work will be needed to migrate essential functionality from
Title and Linker classes into the respective service classes,
MediaWikiTitleCodec and MediaWikiPageLinkRenderer.

Change-Id: I8eef5a165de4ffcacfbc4911fdacdb15d502fff4
2014-03-28 18:42:17 +00:00
jenkins-bot
97a4ad455f Merge "Cleanup a bunch of tests and add todos" 2014-03-17 09:34:02 +00:00
This, that and the other
6cbdf65b4f Add $wgLocalInterwikis to handle multiple local prefixes
This is akin to $wgSkipSkin/$wgSkipSkins. It is quite plausible for a wiki
to have more than one self prefix (e.g. enwiki has w: en: wikipedia: and
maybe others).

Some recent changes code seems to use $wgLocalInterwiki for quite unclear
purposes:
- I removed the line using $wgLocalInterwiki from the RecentChange
  class, as the 'lang' field of $mExtra is not used anywhere in core code.
  Extensions may use it, but it would seem more appropriate for them to
  use something like $wgDBname (or indeed to consult $wgLocalInterwikis
  directly) if they need to identify a particular wiki.
- In the IRC formatter, the first prefix in the array is used (if set).
  Appropriate documentation is added to DefaultSettings.php.

Related to bug 954 comment 3.

Bug: 954
Bug: 955
Change-Id: I9dbb566385b464402c5e78510b95dd2ffb4d9489
2014-03-12 13:32:07 +01:00
addshore
9e85aabe52 Cleanup a bunch of tests and add todos
Change-Id: Iae44427edee3ed2a62abdb5a8f5d9f1ed2e7d660
2014-03-09 15:12:45 +01:00
umherirrender
b176b5b8ac Add title tests about interwiki prefix
Also test $wgLocalInterwiki.
The js part does not respect interwikis,
so there is no need to add tests for that.

Change-Id: I407355295b65bc67eb171da435c1505797569d3e
2014-02-04 14:53:54 +00:00
umherirrender
60b764796a Remove hints to fixed bug 54044
Change-Id: I119a2ec4114fd7939ef2d74e614b4a8ff8e257ac
2013-12-27 12:57:26 +01:00
umherirrender
c42684cca9 Make a single colon an invalid title in php and js
When secureAndSplit gets a single colon as input, the leading colon
is stripped and produces a title with a empty string. This change makes
that impossible by moving the empty string check to after the substring
removal of the colon.

Bug: 54044
Change-Id: I574168c9ed281c535901c36dea7c179a4e794d20
2013-12-06 17:44:43 +00:00