Commit graph

1606 commits

Author SHA1 Message Date
Thiemo Kreuz
673dcee058 languages: Fix some soft type hints in the Language class
Change-Id: Ic9ffbc79c6932db97175d0a1da75df45ba3455e0
2019-01-31 19:21:54 +00:00
Thiemo Kreuz
d62f4688e8 Use the ?: shortcut from PHP 5.3 where it makes sense
Change-Id: Ieff70f23b19f0be3670c4ed3e2a5c30ef3792d7f
2019-01-12 21:56:41 +00:00
jenkins-bot
bd78869618 Merge "No yoda conditions" 2018-12-09 01:34:23 +00:00
jenkins-bot
36de1c7c81 Merge "Remove unused parameter" 2018-12-04 06:27:27 +00:00
Jakub Vrana
8625fcec2f Delete always-true condition
Found by PHPStan.

Change-Id: Ibefd9d5d1b374448650a36702db18144f5feddae
2018-12-02 09:59:17 +01:00
Jakub Vrana
758caf7f93 Remove unused parameter
Found by PHPStan.

Change-Id: I8ed0561c18e2af4ee146123b534a864d5ab7f975
2018-12-01 09:47:28 +01:00
Fomafix
3ee1560232 No yoda conditions
Replace
  if ( 42 === $foo )
by
  if ( $foo === 42 )

Change-Id: Ice320ef1ae64a59ed035c20134326b35d454f943
2018-11-21 17:54:39 +01:00
James D. Forrester
77ddd5faf0 Drop the LanguageGetSpecialPageAliases and LanguageGetMagic hooks
Deprecated since 1.16 and unused in known git.

Bug: T199291
Change-Id: Idcaf1b2c24c64653f700be4fe810ed124ba4ab7c
2018-10-29 15:09:20 -07:00
Fomafix
512aa4e551 Use PHP 7 '??' operator instead of if-then-else
Change-Id: Ia86f8433f30a166d38ee63d0d1745b26740767b9
2018-10-27 23:46:13 +02:00
jenkins-bot
954b695a85 Merge "Remove old "bulletin board style toolbar" from core" 2018-10-24 05:30:14 +00:00
C. Scott Ananian
fcbde8ae4e Make Language::hasVariant() more strict
In d59f27aeab we made
LanguageConverter::validateVariant() try harder to convert a variant
into an acceptable MediaWiki-internal form, looking at deprecated
codes and BCP 47 aliases.  However, this misled Language::hasVariant()
into thinking that bogus names (like all-uppercase strings) were
acceptable variant names, which then led exceptions when they were
passed to the various conversion methods.

This is a belt-and-suspenders patch for T207433 -- in that case we
shouldn't have created a Language object with code 'sr-cyrl' in the
first place, but once one was created we shouldn't have tried to
ask LanguageSr to convert texts to 'sr-cyrl'.  The latter problem
is fixed by this patch.

Bug: T207433
Change-Id: Id993bc7989144b5031a551662e8e492bd23f698a
2018-10-22 16:35:26 -04:00
C. Scott Ananian
a1b894cc42 Remove Language::truncate(), deprecated in MW 1.31
Bug: T197492
Change-Id: I7a3f7a33270402f4b16b286f5d6ed65fee920fcc
2018-10-17 13:13:00 -04:00
James D. Forrester
cfa70ea6d0 Remove old "bulletin board style toolbar" from core
With this change, MediaWiki will no longer have a 'JavaScript-powered'
wikitext toolbar, and instead sysadmins will be required to choose one
(or more) of the several extensions available for this purpose if they
need the functionality. For over half a decade MediaWiki's tarball has
included the 2010-era replacement for this feature, WikiEditor. We are
now working on replacing even that, with the 2013-era visual editor, a
mode of which is the forthcoming 2017-era wikitext editor, and several
more specialised editors like CodeEditor.

Beyond this, the core editor toolbar is ancient, un-loved, and is used
only exceptionally rarely, mostly by accident. It is unhelpful to give
implicitly this as the primary editor for MediaWiki just because we've
not removed it from core when it is not a very good experience for any
kind of user, and has not received the attention that users deserve to
be worth retaining in core.

The old core preference, which was intended to govern whether this old
toolbar should be shown, has since mutated into whether the to run the
EditPageBeforeEditToolbar hook. The hook is used by several extensions
to provide toolbars in lieu of the core one. This preference has been,
in practice, a very confusing preference for MediaWiki users, who have
to interact with quite similar preferences to toggle their real editor
which sit next to this one on the preferences page. Consequently, this
preference is also removed.

The code could be made into an extension for those (very few) users of
MediaWiki who might want to keep on using it. However, the author will
offer their services but not their encouragement in said undertaking.

Bug: T30856
Bug: T32795
Change-Id: I2b05f0ca25873ad8e0b33a5e4938bef52c4e9347
2018-10-16 20:08:32 -07:00
Fomafix
50944a1410 Deprecate Language::setCode as public method
setCode changes the language code for the Language object but it also
replaces the whole language codes for all Language objects.

> $lang = Language::factory( 'fr' )

> $lang2 = Language::factory( 'fr' )

> $lang->setCode( 'it' )

> print $lang2->getCode()
it
> $lang3 = Language::factory( 'fr' )

> print $lang3->getCode()
it

Better assign a new Language object.

Also add more tests for Language::equals.

Depends-On: I61439bac82021344c3f9a6056cccd937b3450af2
Depends-On: I2d9e551d6eb33f28f42aeaf48160eba21b83881f
Change-Id: I201b479f58e63c9c40fb8a3ec9575a551fb35235
2018-10-02 23:48:53 -07:00
Brad Jorsch
0adc109608 Language: Don't return aliases to namespaces that don't exist
On a multi-wiki server using a l10n cache, the cache will probably
include aliases from all extensions enabled for any wiki while the
namespaces themselves will only be defined on the wikis where the
extension is loaded.

Bug: T206030
Change-Id: I985dfa3eb17944d5fc0c5be0979be21504fb1341
2018-10-02 17:18:38 -04:00
Ed Sanders
8477d4a6f5 Define which languages explicitly fallback to 'en'
In the message store, all messages fall through to English,
but only a few languages should actually explicitly fallback
to English (English variants and dialects).

These new explicit fallbacks are used by ResourceLoaderImageModule,
and this change doesn't affect the message fall through system.

Bug: T203350
Change-Id: I6b68a17f4d69341bccdae748727b5133a600d8bc
2018-09-19 15:55:38 -07:00
jenkins-bot
97af92da48 Merge "Introduce constants for fetchLanguageName(s)" 2018-09-13 06:24:09 +00:00
Niklas Laxström
d2838e7894 Introduce constants for fetchLanguageName(s)
Before:
 Language::fetchLanguageNames( null, 'mwfile' );
After:
 Language::fetchLanguageNames( self::AS_AUTONYMS, self::SUPPORTED );

The latter is much more readable and doesn't require knowing the
method definition by heart when seeing it in the code.

I did not add a constant for 'mw' because:
* It is the default value for a last parameter, so it can be left out
* In the long run I expect it will be folded into 'all', see T190129

I did not update any callers; that can be done in follow-ups after
the naming is agreed upon.

Change-Id: Ia9bbb525f213046487f08bcd196876befe87cae8
2018-09-05 21:29:27 +02:00
Brian Wolff
8dbf6a7b31 Add taint annotation and warnings to Language::convert() et al
If you feed this method unescaped data, it can cause later calls
to be an XSS, which is something I think deserves a warning.

Bug: T202571
Change-Id: I34cb3da9232a22defffb80466263c2f2233822ef
2018-09-01 18:10:55 +00:00
Kunal Mehta
2c30dadafc Document expected input and return value for Language::convert()
Bug: T202571
Change-Id: I1598f8a83d9cb2ab9d9e9ba96acd90f70edd59ad
2018-08-29 22:06:39 -07:00
Timo Tijhof
dbe89abb9e languages: Add coverage for 'ar' and 'ml' normalize()
* Exclude the data files from PHPUnit coverage.
* Add tests covering the normalize() implementations.
* Fix a small todo about using data providers.
* Set explicit visibility.

Change-Id: Ib104cc3215a36901cff853ad5969d92a6e0cf6a0
2018-08-14 23:19:35 +00: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
Aryeh Gregor
63d7f2ad13 Automatically reset namespace caches when needed
This avoids error-prone code written separately in every test.  In
addition to no existing tests resetting the TitleFormatter (more
services probably need to be reset as well), they mostly reset only the
namespace cache on $wgContLang, which wouldn't help for any other
language.

The parser test runner still doesn't do this, but maybe it should.

Change-Id: I44b7a1aec48f14b0950907fa14bd0df80f674296
2018-08-01 16:30:08 +03:00
Mark A. Hershberger
2fb1ec2a75 Language::listToText: Avoid PHP warnings from E_STRICT
Language::listToText() uses for(;;) which assumes the index in a list
starts at 0 and following keys are consecutive integers.

This assumption fails (and results in warnings with E_STRICT) when
SpecialListGroupRights::formatPermissions() uses the key-preserving
array_intersect() to create a subset of $allGroups.

Bug: T199559
Change-Id: I4eb03a95509d69653156a2764d58c0c5d0d1dfbc
2018-07-19 17:16:21 +00:00
jenkins-bot
5fc5d3cc59 Merge "Hard deprecate Language::truncate()" 2018-07-13 17:58:03 +00:00
jenkins-bot
8c96aec32c Merge "Fix the bug for dates between 1912 and 1941 in Thai language" 2018-07-10 08:55:56 +00:00
jenkins-bot
0360889671 Merge "Language: compare on same object in equals()" 2018-07-10 01:19:44 +00:00
Fomafix
b1336fc2a8 Language: compare on same object in equals()
Change-Id: I8a47a8500922906bd4e4936b59b657de3bb9abdc
2018-07-10 01:02:30 +00:00
C. Scott Ananian
b93394bd15 Hard deprecate Language::truncate()
This was split into Language::truncateForVisual() (which measures characters)
and Language::truncateForDatabase() (which measures bytes) in 1.31.

Bug: T197492
Change-Id: I949eab4ceb8dcb707b45edf7623e496eb99fe33b
2018-07-09 14:07:23 -04:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00:00
Niklas Laxström
f14c6bb54e Prevent fatal error when {{#translation:}} is placed on subpage named code
Bug: T198518
Change-Id: Ia202e78adc53a54f95597b8701304c7f3832bf9c
2018-07-02 17:07:58 +02:00
C. Scott Ananian
d79428b785 Hard deprecate a trio of functions from Language.php
These have been soft deprecated since 1.28; let's start the process of
actually removing them.

Change-Id: I33bb6f501e5df419683d06fb9e4516fddc03741b
2018-06-13 13:48:02 -04:00
C. Scott Ananian
7de2c566dd Deprecate Language::markNoConversion, which confuses readers
Language::markNoConversion is used only within Parser.php and differs
from LanguageConverter::markNoConversion in that, contrary to its name
and its namesake, it only protects *things which look like URLs* from
language conversion.

This wasted several days of my time before I realized what was going on.
It's needless; just hoist the "looks like a URL" special casing inline
to the single place where that functionality is used.  (And I wonder
if the "looks like a URL" case is actually needed at all any more,
since most of those cases are probably free external links, which
go through a different code path, not bracketed external links.)

This is a clean-up to the clean-up that liangent performed in 2012
with e01adbfc0b.

Change-Id: I80479600f34170651732b032e8881855aa1204d8
2018-06-13 13:26:58 -04:00
James D. Forrester
fd4a49e1a7 Follow-up 23cfebd3d2: Hard-deprecate LanguageGetMagic hook
Change-Id: I7e442e20744a196644d6be186158fd901f9db1ce
2018-06-12 15:45:29 +00:00
James D. Forrester
f511719957 Follow-up 23cfebd3d2: Hard-deprecate LanguageGetSpecialPageAliases hook
Change-Id: I543c2ff9e9d82869a4b443410528a179f65e3d02
2018-06-12 07:53:18 -07:00
Erik Bernhardson
764f5c7a02 Resolve required parameter after optional in language
Change-Id: I6e0c3b14f1bcea112be7ab694efff5a67622d637
2018-06-08 21:48:24 +00:00
Bartosz Dziewoński
0313128b10 Use PHP 7 "\u{NNNN}" Unicode codepoint escapes in string literals
In cases where we're operating on text data (and not binary data),
use e.g. "\u{00A0}" to refer directly to the Unicode character
'NO-BREAK SPACE' instead of "\xc2\xa0" to specify the bytes C2h A0h
(which correspond to the UTF-8 encoding of that character). This
makes it easier to look up those mysterious sequences, as not all
are as recognizable as the no-break space.

This is not enforced by PHP, but I think we should write those in
uppercase and zero-padded to at least four characters, like the
Unicode standard does.

Note that not all "\xNN" escapes can be automatically replaced:
* We can't use Unicode escapes for binary data that is not UTF-8
  (e.g. in code converting from legacy encodings or testing the
  handling of invalid UTF-8 byte sequences).
* '\xNN' escapes in regular expressions in single-quoted strings
  are actually handled by PCRE and have to be dealt with carefully
  (those regexps should probably be changed to use the /u modifier).
* "\xNN" referring to ASCII characters ("\x7F" and lower) should
  probably be left as-is.

The replacements in this commit were done semi-manually by piping
the existing "\xNN" escapes through the following terrible Ruby
script I devised:

  chars = eval('"' + ARGV[0] + '"').force_encoding('utf-8')
  puts chars.split('').map{|char|
    '\\u{' + char.ord.to_s(16).upcase.rjust(4, '0') + '}'
  }.join('')

Change-Id: Idc3dee3a7fb5ebfaef395754d8859b18f1f8769a
2018-06-04 16:20:13 +00:00
Bartosz Dziewoński
485f66f174 Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
Find: /isset\(\s*([^()]+?)\s*\)\s*\?\s*\1\s*:\s*/
Replace with: '\1 ?? '

(Everywhere except includes/PHPVersionCheck.php)
(Then, manually fix some line length and indentation issues)

Then manually reviewed the replacements for cases where confusing
operator precedence would result in incorrect results
(fixing those in I478db046a1cc162c6767003ce45c9b56270f3372).

Change-Id: I33b421c8cb11cdd4ce896488c9ff5313f03a38cf
2018-05-30 18:06:13 -07:00
jenkins-bot
d8a144d38e Merge "languages: Use static array files for normalizer data" 2018-05-25 23:03:18 +00:00
Fomafix
384dc90874 Avoid sorting the language array twice
Language::fetchLanguageNames returns already a sorted array. An
additional ksort is only needed when inserting a new value.

Change-Id: If8c7b16fa6e7dfe1545f72ac9c742a2f43eaee57
2018-05-22 23:02:34 -07:00
Timo Tijhof
4f22361759 languages: Use static array files for normalizer data
This reduces the number of '.ser' files to 1 (we still have
first-letters-root.ser).

Change-Id: Ib0ee0d826da34b1825fd5bb74563c6bbadeec75c
2018-05-22 21:38:43 +00:00
Fomafix
d65ac78277 Replace HTTP by HTTPS
* https://www.unicode.org/ instead of http://www.unicode.org/ or
  http://unicode.org/
* https://secure.php.net/ instead of http://www.php.net/ or
  http://php.net/
* https://hhvm.com/ instead of http://hhvm.com/
* https://www.iis.net/ instead of http://www.iis.net/

Change-Id: I84d818a7e0ced5ffb9485ec89a75efb28a77c1e0
2018-05-22 12:14:14 +02:00
Kunal Mehta
230958d97c Autofix MediaWiki.Commenting.FunctionComment.SpacingDoc* errors
Change-Id: I63761ebce04c03b9b13237919c27cc10180f198f
2018-05-19 14:07:03 -07:00
superyetkin
3aaa2367b2 Fix the bug for dates between 1912 and 1941 in Thai language
Added an if-else block to see if the parameters passed to the function
designate a year between 1912 and 1941 or not. Resulting month values
are also adjusted.
Added a unit test for the related formatting.

Bug: T68648
Change-Id: Ic676b5c140de8878971a786a1a1811770a848016
2018-05-12 15:10:13 +00:00
Michael Holloway
e6e9a8279b Add varianttitles parameter to API query prop=info
Returns the displaytitle (if present) or title->getPrefixedText for a
page, converted for each language variant configured on the wiki.

Bug: T178446
Change-Id: I35100af3824ca65c4fe5c106d4a6fbe4e5f75046
2018-04-09 22:03:19 +00:00
Umherirrender
52338150c8 Fix return type for html strings
Change-Id: Ifc1ae7740ad1b130186b4b970d3d84651b016177
2018-04-06 13:07:01 +02:00
jenkins-bot
e46d0694ac Merge "Truncate tag filter descriptions" 2018-02-21 12:52:23 +00:00
Reedy
39f0f919c5 Update suppressWarning()/restoreWarning() calls
Bug: T182273
Change-Id: I9e1b628fe5949ca54258424c2e45b2fb6d491d0f
2018-02-10 08:50:12 +00:00
petarpetkovic
2d2575852c Truncate tag filter descriptions
Introduce truncateInternal() method in Language class, based on
existing truncate() method. New method abstracts string truncation,
allowing users to specify callable functions for text length measurement
and string truncation.

New method, truncateInternal(), is used to provide two options for
text truncation:
* For DB usage: truncateForDatabase() method is truncating text by
number of bytes.
* For UI usage: truncateForVisual() method is truncating text by number
of characters, using multibyte string PHP methods.

Old truncate() method is deprecated and just returns the results of
truncateForDatabase() method.

Newly introduced truncateForVisual() method is used for
truncation of long tag descriptions in RCFilters menu.

Bug: T179626
Change-Id: Ib01a8c303304064dde3ce983b817d93a88a5affd
2018-02-09 22:45:20 +01:00
Jesús Martínez Novo
92e74356e2 Performance: Shortcut Language::truncate if there's no need to truncate
Return the unmodified string if there's no need to truncate it without
doing a not-so-trivial round of getting a message from the message
cache.

Change-Id: I11ac88672aeb9d1c4f5709b79ad2d17223bd64d8
2018-01-12 21:05:17 +00:00