Commit graph

142 commits

Author SHA1 Message Date
Brian Wolff
ee4d5c6eed Remove support for $wgWellFormedXml=false
tl;dr: Having unnessary complexity in security critical code is bad.

* Extra options add extra complexity and maintenance burden
** Thus we should only have one html output mode. well formed = false
     was already vetoed in T52040, so lets go with WellFormed=true.
* Options which are used by very few people tend to get tested less
* Escaping is an area of code where we should be very conservative
* Having escaping rules depend on making assumptions about which
    characters various browsers consider "whitespace" is scary
* $wgWellFormedXml=false has had a negative security impact in the
    past (Usually not directly its fault, but has made other bugs
    more exploitable)
* Saving a couple bytes (even less bytes after gzip taken into
    account) is really not worth it in this context (imho).

Change-Id: I5c922e0980d3f9eb39adb5bb5833e158afda42ed
2016-05-12 17:40:01 -04:00
Timo Tijhof
dd2d7d0ffc OutputPage: Minor clean up of <head> and HTML
* Remove trailing space in self-closing tag.
  Brings parserTest output of Parser and Parsoid closer together.

* Remove various line breaks at begin and end of script contents.

* Remove FILTER_NOMIN from makeConfigSetScript() output.
  This isn't part of any user- or page-dependent module and not minified.
  And Xml::encodeJsCall already ensures compact output for prod mode.

Bug: T127328
Change-Id: I85a5a59fd0955c1a112e8b24b933f0d9e983a156
2016-03-24 03:24:31 +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
Ori Livneh
268da96291 Remove redundant 'type' attributes from style and script tags
Already stripped by Html::element before actual output, but
remove them from the attribute arrays as well.

Change-Id: I8699ca7bf40df07e9d4c370f6863003c095ced0e
2015-12-09 20:07:13 +00:00
Edward Chernenko
088f01bbe6 Typo in comment of Html::radio()
Incorrectly copied documentation from Html::check().

Change-Id: I508e4beedb01b62989a7f37466c47ddd37091b49
2015-10-16 13:51:00 +00:00
umherirrender
977c810302 Remove empty line comments
Remove empty line comments as found by the
MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.EmptyComment sniff

Change-Id: I5d694f7a7d3bc97e16300ba03c60ad17f3c912a5
2015-10-14 09:46:44 +02:00
umherirrender
c572d18661 Fixed spacing
- Removed space after cast
- Removed spaces in array index
- Removed double spaces
- Added spaces around string concat
- Fixed mixed tabs and spaces at begin of line

Change-Id: I38e849723f055d2d4c05cba72f5c245a28e8d5da
2015-09-26 20:44:54 +00:00
Bartosz Dziewoński
53b012ce2a OOUIHTMLForm: Implement HTMLSelectNamespace
* Extracted some common code between this and Html::namespaceSelector
  into a new method Html::namespaceSelectorOptions().

Change-Id: I5e97e5c661582f726153533ad00695b450caed46
2015-07-13 19:20:09 +02:00
Bartosz Dziewoński
1996e35ec7 Html: Add buttonAttributes() more diligently
It was done only for elements generated with linkButton() or
submitButton(), and not input().

Change-Id: Idd7e01d596997bd5cade5a7851daf64bee10bb49
2015-06-05 01:15:14 +00:00
kaldari
f74b88311b Fixing definition and use of $attrs parameter in Html::buttonAttributes
Also clarifying definition of $modifiers parameter.

Also simplifying code for case where $attrs['class'] is not set.

Change-Id: I425211681ba75cb71c1ccc3b3c038c075ea9acb9
2015-06-01 18:53:15 -07:00
Thiemo Mättig
bf1341985b Add array type hints to minor methods in the Html class
I'm aware that adding these type hints does have the potential of beeing
a breaking change if a caller misuses it. Note that it really is a misuse
in this case because all these parameters are documented as "array" and
nothing else.

I double-checked the usages of all methods I touched and could not find
any caller that does not fulfill the contract of these methods - in other
words, all callers I can find in my local code base (which includes all
major extensions like Echo, Flow, Parsoid, VisualEditor and so on) pass
arrays to these parameters.

I left the main methods openElement, rawElement and so on untouched
because they are called way to often (500 times and more).

Change-Id: I5ca13b26fb08d732ce4cadc4ee3d38314e606fd3
2015-04-08 20:26:24 +00:00
Ori Livneh
6333fa6191 Html::srcSet: allow density to be specified either with or without trailing 'x'
$wgLogoHD is meant to contain high-density alternatives for $wgLogo, but its
keys include the trailing 'x' (e.g., '1.5x'), making it unusable with
Html::srcSet(). Fix that by normalizing all density values to have a
single trailing 'x'.

Change-Id: I62cc3a9e4aeff3a7cb102de2965b8b40fd106c37
2015-04-05 05:22:47 +00:00
csteipp
125ed0e5ff SECURITY: Escape > in Html::expandAttributes
Escape > characters in attributes, so we don't confuse post-processing,
like LanguageConverter.

Bug: T73394
Change-Id: I768e2a12c7b6ba635e6c8571676b8c776b16bf72
2015-04-01 09:56:12 -07:00
Thiemo Mättig
5a84fbf457 Replace Html::... with self::... in the Html class
How cool is that, I can call a patch "SelfHTML". ;-)

Change-Id: I17d36bc45a349c92715b88004aaae046d4f7be1c
2015-03-27 17:47:31 +00:00
Thiemo Mättig
7ff53f8e07 Fix misleading $class = false default in Html::infoBox
I found this because my PHPStorm complains about the type mismatch.
I could have changed the @param tag to "string|bool", but when looking
at the code, the $class variable is casted to a string anyway and
never used as a bool.

Change-Id: I3450fa8a898923bbae26830ed3be0017685020d3
2015-03-26 10:43:01 +01:00
Thiemo Mättig
afe08307d6 More specific types in doc tags in the Html class
This is a pure inline-documentation patch. It fixes a few actual
mistakes in documentation tags and makes some generic "array" types
more specific, if that's possible.

Change-Id: Id02e1e936624b845316b8ce99f8b8d2a1f829e97
2015-03-26 10:38:35 +01:00
Bartosz Dziewoński
98ef0a2f5d Remove a hack, and a hack for the hack, for MediaWiki UI input fields
Hack #1: We were ignoring the 'size' attribute of input fields when
  $wgUseMediaWikiUIEverywhere was true. Let's not do that.

Hack #2: We were setting a min-width for MediaWiki UI input fields,
  because fields which were supposed to be full-line were becoming
  tiny because of hack #1. Let's not do that either.

Bug: T92498
Change-Id: I1d2c6c9eb60b52a7267c122a719cfdaa1f74f815
2015-03-14 15:18:31 +00:00
Bartosz Dziewoński
896fdb3d97 Html: Make addition of 'mw-ui-input' conditional on $wgUseMediaWikiUIEverywhere
We were always adding it previously, which seemed harmless since
'mediawiki.ui.input' RL module, providing the styling, was only loaded
if $wgUseMediaWikiUIEverywhere was true… unless someone loaded it
manually to have specific input fields styled. Whoops.

There are a lot more unconditional additions like this in tons of
places in the code, and someone should check whether each one is
intentional or not, but probably no one will. Oh well.

Bug: T92496
Change-Id: I5e91a3852a76ebbbfe64485bccb4c30ddee28b66
2015-03-13 19:02:34 +00:00
Amir E. Aharoni
4cae45a5a6 Shorten long lines in Html.php to make phpcs pass
Change-Id: I5060b510105aa08f1cb4804e2c33d8e1b00ef390
2015-03-03 21:41:20 +00:00
Ricordisamoa
55fc61c474 Html::openElement: Don't omit closing tags.
Logic added with commit eefe1b13a3
for both openElement and closeElement, removed with commit
d950da075d but only from closeElement.

Reported by Petr Bena on Wikitech-l:
https://lists.wikimedia.org/pipermail/wikitech-l/2015-February/080861.html

Change-Id: I6ed45763f7e95f7f39b73432e4f6152431891963
2015-02-18 22:35:22 +01:00
Federico Leva
5e93f83758 Don't discourage usage of Html::element()
Old advice from 2009 (7aa4a8f9), not quite useful nowadays. The preceding
sentence already says that in absence of attributes the function may not
do much.

Change-Id: I4d276d6f42394fc09662ddfd7e1ffd13fb197bf6
2015-01-09 08:02:42 +01:00
Ricordisamoa
12dec5d85d Fix some stuttering in comments and documentation
Change-Id: I9c0088b9aab37335203cad45a1d6fa8ac3f43321
2014-12-17 19:44:10 +00:00
Bartosz Dziewoński
3e85dfb8ad Standardize indentation of multiline 'if'/'elseif' conditions
Always indent the continuation one level deeper, and always place the
closing parenthesis on the next line, per coding conventions.
https://www.mediawiki.org/wiki/Manual:Coding_conventions#Indenting_and_alignment
https://www.mediawiki.org/wiki/Manual:Coding_conventions#Line_continuation

Regexp used: (\t+)(if|while|\} elseif|foreach).+(?<![;}])\n\1\S

Also:
* Change to just one line if line length stays under 100 characters.
* Add "// Do nothing" comment in empty 'if' bodies.
* Change '#' comments to '//' comments near affected code.

Change-Id: I4f62658fddb5a0ed18bbf9b2231cd794683d6402
2014-11-17 15:33:34 +00:00
Prateek Saxena
b7b74ec8ec Html: Use https for @see url of buttonAttributes()
Follows up I61bb3c358f755ed9f2153d94b744c1a9da02c456.

Change-Id: I46be4249bdfde1b801e798e732617077f71f983d
2014-10-03 22:12:41 +00:00
jdlrobson
a155ac55ea Hygiene: Make construction of buttons easier
Stop littering MediaWiki with globals, provide a common
api for generating them similar to how we do text input
attributes before things get out of control.

Adds
* submitButton
* linkButton

Change-Id: I61bb3c358f755ed9f2153d94b744c1a9da02c456
2014-09-30 14:54:56 -07:00
Bartosz Dziewoński
6ff6ded2fc Html: Don't accept paths relative to skins/common/images/ in infoBox()
There are no files worth referencing there anymore.

No usages found in extensions, only one usage in core already didn't
depend on that behavior.

Change-Id: If1fd68a3a7355c8195fd2aad86e7584a5772bd4c
2014-09-08 21:03:23 +02:00
umherirrender
7c6a25856c Add missing @return to function docs
Change-Id: I45b9d02f94ecc58372268ec5e6a0b572a0b7e2a9
2014-08-23 23:14:57 +02:00
jdlrobson
aa15d5287d Add blanket support for mediawiki ui via globals
This provides better mobile experiences on various pages
and a more consistent UI across both mobile and desktop.

It does this in two ways.

1) Forces HTMLForms to not use table based layouts so as
not to interfere with responsive nature of mediawiki ui elements

2) Applies MediaWiki.UI classes to most pages
If a page is created via Xml or Html classes it will use mediawiki ui
Where possible I've added classes unconditionally, but for cases of buttons
this is behind the $wgUseMediaWikiUIEverywhere global since button styling is
enabled on pages by default and for checkboxes since it is changes HTML markup.

3) Adds all MediaWiki.UI styles to pages which can use it
When enabled:
* Apply these styles to all pages which use HTMLForms
* Apply to EditPage
* Apply to anything that uses certain elements outputted by the
Xml or HTML helper classes
* Apply to History page
* Apply to protection page
* Apply to move page
* Apply to deletion page

Currently kept behind a global to allow us time to finetune
existing elements. After further testing we will look to kill the
globals and make mediawiki.ui the default

See: I430c0fbb79d2a33bb828b2427bda0ee01115d73f
Change-Id: I47db5eab4569514d039261d11b6dedb0eeae17b5
2014-08-15 14:48:00 -07:00
Matthew Flaschen
9553bd02a5 Fix documentation for Html::closeElement
Follow-up to d950da075d

Change-Id: I916052cf924dd3c6664b6d7d02175fd74a71527b
2014-08-09 22:23:27 -04:00
jenkins-bot
3dcf7c09b4 Merge "Html::closeElement: Don't omit closing tags." 2014-08-08 00:43:31 +00:00
rillke
c31fbf073e Unify the spelling of MIME in documentation
Writing MIME as written in Wikipedia and some documentation clean up.

Change-Id: I9dfc36d2bf55d72d9374c4075bd6d45eef0415a4
2014-08-07 23:38:45 +02:00
Matthew Flaschen
d950da075d Html::closeElement: Don't omit closing tags.
Although it's allowed by the HTML Living Standard in particular
circumstances, the rules are non-trivial and can not be enforced
by this method since it has no context.

For example, as of http://web.archive.org/web/20140807160955/http://www.whatwg.org/specs/web-apps/current-work/multipage/syntax.html#optional-tags
it says:

"A head element's end tag may be omitted if the head element is not
immediately followed by a space character or a comment."

Html::closeElement has no way of knowing whether there is a space
character or comment after the tag.

There are similar issues with some other tags (e.g. body).  Also,
even when the rule should be followed anyway (e.g. lists can only
contain li elements), there is evidence of browser issues (bug 52210).

Use closing tags for all elements for simplicity.

Bug: 52210
Change-Id: I97ce415288300e40c4d0aa0442bdf4ee3dedb30f
2014-08-07 12:26:59 -04:00
Tyler Anthony Romeo
5edf25e2e6 Added Html::radio, Html::check, and Html::label.
Migrated some convenience functions from the Xml
class to Html so they can be used. Only added
functions that acted as more than just a wrapper
for another function.

Change-Id: I4cc5876d4be6e04ec554444242cc049a3cff0f58
2014-07-29 19:41:20 +00:00
umherirrender
1c68a1ee86 Cleanup some docs (includes/*.php)
- Swap "$variable type" to "type $variable"
- Added missing types
- Fixed spacing inside docs
- Makes beginning of @param/@return/@var/@throws in capital
- Changed some types to match the more common spelling

Change-Id: I783e4dbfe5f6f98b32b9a03ccf6439e13e132bcc
2014-07-24 19:42:24 +02:00
umherirrender
2b021dc48a Fixed spacing
- Added/removed spaces around parenthesis
- Added space after switch/if/foreach
- changed else if to elseif

Change-Id: I99cda543e0e077320091addd75c188cb6e3a42c2
2014-07-19 23:12:10 +02:00
Thiemo Mättig
4aeb08ef18 Html: Throw exception if array is used for an attribute not supporting it
Previously the behavior was more or less undefined for most attributes
except for the ones in $spaceSeparatedListAttributes (currently 'class',
'accesskey' and 'rel'). If an other attribute is set to an array (no
matter what it contains) the method produces broken HTML like
'key=' and only triggers a warning if error_reporting is enabled. If
error_reporting is not enabled a developer may overlook this.

To clarify: The method always *ALLOWS* array values. This is *NOT*
about unexpected types in the call signature but unexpected
combinations of nested values. These combinations are already
checked in the method but the check was incomplete.

I considered several solutions:
* Simply use the first array element. But we can't know if the first
  element is what the caller expected.
* Silently drop all arrays if the attribute doesn't allow lists. This
  is close to the current behavior of always returning 'key=' but is a
  breaking change for boolean attributes like 'checked' and 'selected'.
  Browsers accept the current 'checked=' as true while omiting the
  attribute means false.

Choosing to always throw an exception. As above, this is a
breaking change in some cases.

Change-Id: Id5fcbdef2696d0a81a91d54338939ee678475ca3
2014-07-10 16:46:35 +00:00
Siebrand Mazeland
e9eb00b203 Make phpcs-strict pass on includes/ (1/~10)
Change-Id: Ib51381a2261d064988ba2f39b71c0252f2458faf
2014-05-11 19:14:17 +00:00
umherirrender
a3983418d5 Fixed some @params documentation (includes/*)
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: I0056b4a8df243cfc0c5f25378de48f7a35170aca
2014-04-22 13:07:02 +02:00
umherirrender
725d9d125d Removed unneeded spaces and colons in @param and friends
Also 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.

Change-Id: Ic36c8c7820a6c2d603f1138130670c6bf6a1ca59
2014-04-08 16:02:49 +00:00
umherirrender
047c86f26e Fix spacing between two functions
Added and removed some new lines to have one new line between two
functions

Change-Id: I1ccfbd575dd26b160396ef3d3e2e079f5cdbe196
2014-03-15 20:57:23 +00:00
umherirrender
5ca5672aac Fixed spacing
- Place commas correct
- Moved comments
- Add space after if/foreach/catch
- Reformat some conditions
- Removed trailing spaces/tabs

Change-Id: I40ccda72c418c4a33fcd675773cb08d971510cdb
2013-12-01 20:58:51 +01:00
Bartosz Dziewoński
489a33c6d3 Html: Fix a copy-paste error in docs
Change-Id: I262f27574335cf8f4d72a5bb3a28a77ef402c252
2013-11-23 16:02:12 +00:00
Bartosz Dziewoński
ac0dc24064 Add a line of explanation to Html::expandAttributes
Change-Id: I7ad453638075a5e875c6c97df10690747c2488f0
2013-10-16 17:42:07 +02:00
MatmaRex
df8ec1e216 No spaces after (casts)
Also removed some unnecessary ones. I think I've caught them all.

The spaceless version already appears in core ~300 times (after
accounting for false positives when grepping). Some consistency would
be nice.

Change-Id: I607655b5f4366e66dc78730d5fd2f57ed8776cae
2013-09-04 20:05:43 +02:00
Daniel Friesen
a4ce59a4a0 Followup If21705c2, Shorten remaining urls to the whatwg HTML spec.
Finish up with the /specs/web-apps/current-work/multipage/ urls that
haven't been updated to /html/.

Change-Id: I4dbee0477eea440b0e8f113b1d393c6e0c739c4c
2013-06-08 04:48:01 -07:00
Daniel Friesen
db44d7308e Shorten our in-comment urls to the whatwg HTML spec.
whatwg.org has a redirect to /specs/web-apps/current-work/multipage/ from /html/.

Change-Id: If21705c214ca8f14db5a0c6dda3c43c22f9ca811
2013-06-05 14:21:06 +00:00
Daniel Friesen
97caae596d Drop support for XHTML 1.0
* $wgHtml5 = false; is now ignored completely.
* $wgDocType and $wgDTD have been removed.
* $wgXhtmlDefaultNamespace is now ignored.
* XHTML5 will be output if $wgMimeType is set to an XML mime type (according to HTML5's rules).
* For backwards compatibility with extensions $wgHtml5 and $wgXhtmlDefaultNamespace are set
  in Setup.php but depending on them is deprecated.

Change-Id: Iad9634e2ee420b5a3bbffe550421fde4fa1819b0
2013-05-15 23:09:25 -07:00
umherirrender
ef2f507d23 Fixed spacing in files direct in includes folder
Added spaces before if, foreach
Added some braces for one line statements

Change-Id: Ibb8dd102db045522d12ff939075ba7420d95ab6b
2013-04-21 06:38:49 +00:00
umherirrender
15abcf71ca Added/Removed spaces around string concatenation
And added/removed spaces around some other tokens,
like +, -, *, /, <, >, =, !

Fixed windows newline style

Change-Id: I0b9c8c408f3f6bfc0d685a074d7ec468fb848fc8
2013-04-13 13:36:24 +02:00
Yuri Astrakhan
9506e3d812 Spellchecked /includes directory
* Ran spell-checker over code comments in /includes/
* A few spellchecking fixes for wfDebug() calls

Found one very strange (NOOP?) line in Linker.php - see "TODO: BUG?"

Change-Id: Ibb86b51073b980eda9ecce2cf0b8dd33f058adbf
2013-03-13 03:42:41 -04:00