Commit graph

107 commits

Author SHA1 Message Date
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
Tyler Anthony Romeo
4dcc7961df Fixed @param tags to conform with Doxygen format.
Doxygen expects parameter types to come before the
parameter name in @param tags. Used a quick regex
to switch everything around where possible. This
only fixes cases where a primitve variable (or a
primitive followed by other types) is the variable
type. Other cases will need to be fixed manually.

Change-Id: Ic59fd20856eb0489d70f3469a56ebce0efb3db13
2013-03-11 13:15:01 -04:00
umherirrender
ca31ebad3f fix some spacing
Added/removed spaces after opening/before closing parentheses

Added a space after a comma

Removed unneeded parentheses in condition

Change-Id: I306091347ccaaf11dee0cdfda3019cb0c12be51b
2013-02-09 23:03:53 +01:00
umherirrender
1044b0b8df fix some spacing
Change-Id: I8f976013f33c5818e4402604fe8610aa3f43b0c6
2013-02-04 20:18:33 +00:00
Tim Landscheidt
6dc4039270 (bug 40585) Don't drop 'step="any"' in HTML input fields.
The default value for "step" is "1" which effectively bans any decimal
number from being entered into an 'type="number"' field and makes
HTMLFloatField unusable.

Change-Id: I103fd4047814a7fb0dfdc174f36badd5b660b7a4
2012-12-07 19:26:29 +00:00
Anomie
a62274a157 Merge "Set default type attribute for button html elements" 2012-11-13 23:08:16 +00:00
jeroendedauw
558de0edea replace # by // for comments
Change-Id: Ifd60bc086023a6cb06d9f5aff3ae857eed6ea4d7
2012-11-04 19:17:04 +01:00
Stephan Gambke
514bdd184d Set default type attribute for button html elements
According to standard the default type for <button> elements is "submit". Depending on compatibility mode IE might use "button", instead.
To work around the IE bug this patch forces the standard "submit", if nothing is specified explicitly.

See remarks on http://msdn.microsoft.com/en-us/library/ie/ms535211%28v=vs.85%29.aspx :
-----
The default value of the type attribute depends on the current document compatibility mode. The default value is submit. In other compatibility modes the default value is button.
...
Windows Internet Explorer 8 and later. The default value of the type attribute depends on the current document compatibility mode. In IE8 Standards mode, the default value is submit.
In other compatibility modes and earlier versions of Windows Internet Explorer, the default value is button.
-----

Change-Id: I3b97a8cac74bbfca63699dfcbf1cc5e9a2cef193
2012-10-30 21:45:17 +01:00
umherirrender
9d19d7342a Remove a bunch of trailing spaces and unneeded newlines
Change-Id: I7db616db8c969567d420c0161fa207b366e292b6
2012-10-19 22:03:05 +02:00
Brion Vibber
966cda2f80 Initial stab at responsive images for screen densities.
* adds $wgResponsiveImages setting, defaulting to true, to enable the feature
* adds 'srcset' attribute with 1.5x and 2x URLs to image links and image thumbs
* adds jquery.hidpi plugin to check pixel density and implement partial 'srcset' polyfill
** $.devicePixelRatio() returns window.devicePixelRatio, with compat fallback for IE 10
** $().hidpi() performs a 'srcset' polyfill for browsers with no native 'srcset' support
* adds mediawiki.hidpi RL script to trigger hidpi loads after main images load

Note that this is a work in progress. There will be places where this doesn't yet work which output their imgs differently. If moving from a low to high-DPI screen on a MacBook Pro Retina display, you won't see images load until you reload.

Confirmed basic images and thumbs in wikitext appear to work in Safari 6, Chrome 21, Firefox 18 nightly on MacBook Pro Retina display, and IE 10 in Windows 8 at 150% zoom, 200% zoom, and 140% and 180%-ratio Metro tablet sizes.

Internally this is still a bit of a hack; Linker::makeImageLink and Linker::makeThumbLink explicitly ask for 1.5x and 2x scaled versions and insert their URLs, if different, into the original thumbnail object which (in default handler) outputs the srcset. This means that a number of places that handle images differently won't see the higher-resolution versions, such as <gallery> and the large thumbnail on the File: description page.

At some point we may wish to redo some of how the MediaHandler stuff works so that requesting a single thumbnail automatically produces the extra sizes in all circumstances. We might also consider outputting a 'srcset' or multiple src sizes in 'imageinfo' API requests, which would make ApiForeignRepo/InstantCommons more efficient. (Currently it has to make three requests for each image to get the three sizes.)

Change-Id: Id80ebd07a1a9f401a2c2bfeb21aae987e5aa863b
2012-10-11 10:54:21 -07:00
Liangent
b9f7fe0bcf Display converted namespace names in Html::namespaceSelector().
By the way, the code to get converted titles and namespaces
has been cleaned up.

Change-Id: Ifcbd56c989d83b9d32dfa99e0b2f06d01e17a2bd
2012-10-10 16:53:17 +11:00
jeroendedauw
37d9c1a6dc Fix behaviour of namespaceSelector to match the documentation
Change-Id: I3d1bb232905095ae2d5177adc225025178d5f5a3
2012-10-05 16:19:03 +02:00
jeroendedauw
fdfe87fbd6 Change Array to array
Change-Id: I22fd8b2aad037a12546d7c5f5167add1eec96c30
2012-10-05 15:55:52 +02:00
robin
5a59d9b8bb Maintenance in Html::openElement regarding input types
Followup to c22000

Remove unset() for 'search' type, it will now simply be unset through the regular checking (removed it in the validTypes for that, but it is still in validTypes in HTML5 mode).

Update / remove outdated code comments.

Change-Id: I452462b81360b67b76dd8baa732d52113b6aafe6
2012-09-17 03:30:56 +02:00
Antoine Musso
1a7da4f625 test: full coverage of Html::dropDefaults()
This closely match Html::dropDefaults() logic and hopefully test out
all default dropping.

Introduce a test case that match a failure in f34547ab where attribute
default values passed in an array are not cleaned up.

Change-Id: If8d16b066015ed1bcaf38408511ac3713eaa6540
2012-09-14 21:26:56 -07:00
Daniel Friesen
81f1cace4c Fix broken value="" stripping for HTML5
The default value for value="" on <input> elements is not always an
empty string.

In particular the default value for type="radio" is "on" and by
stripping value="" out of the attributes a "" becomes "on" and our
cleanup code ends up breaking forms.

Change-Id: Ibe5a3be3f45a2f93ef95dbe42729b8f8c94a41cb
2012-09-14 21:26:56 -07:00
Antoine Musso
a45e20ff11 HTML5 new types for input element
HTML5 introduced new types for the input element. For some reasons we
never added them to Html::openElement which would thus strip them even
in HTML5 mode.

The issue is:
 $wgHtml5 = true;
 Html::element( 'input', array( 'type' => 'color' );
 # -> "<input />"

With this patch, we returns: <input type="color" />

Change-Id: I7de373635d0eb47f788d1d664c3a913c8801efd6
2012-09-14 21:26:55 -07:00
Tyler Anthony Romeo
f34547ab44 (bug 39875) Fixed conversion of array attributes in Html.
Changed Html::dropDefaults() so that when an array is
passed as an attribute value, it does not call strval(),
thus triggering a PHP notice. Instead arrays are
imploded with a space as the separator.

Change-Id: I2521b78c7de94c183b7de7e7d4b2b510ab0c7770
2012-08-31 21:25:27 -04:00
Alex Monk
2fabea7eea Use wfMessage instead of deprecated wfMsg*
Or $this->msg in special pages.

Change-Id: I774a89d646615053c8424050e42ad95601f92543
2012-08-18 14:11:05 +02:00
Antoine Musso
aab43dd495 escape tags and entity in doxygen comments
When inserting XML elements inline <such as this one>, doxygen chokes
about it not being known. Simply enclosing the tag in double quotes
prevents doxygen from emitting a warning.

Also enclosed a few invalid functions calls such as \. and double quoted
the HTML entities such as &foobar;

Change-Id: I4019637145e683c2bec3d17b2fd98b0c50a932f1
2012-07-10 17:08:32 +02:00
Krinkle
1e5689852b [Html::namespaceSelector] Remove default id/name attributes
* Remove default id/name attributes
* Remove now redundant tests introduced in r110274
* Add tests to make sure label has no 'for' attribute when label isn't null but name/id are unset
* Update tests to not include id="" and name="" when calling with no arguments
* Updating calls to add name/id if needed, and while at it remove useless 'null' params


* Context:
-- Introduced in r109990, r111376, r111315
-- No callers exist that assume these defaults. Forcing an ID that should be unique is annoying and redundant. The name used in the query when submitting a form should be mentioned in the same file where it is used from the submission, never assume what name="" is from unrelated code
-- Same for ID, this is often used in CSS or JavaScript, shouldn't be assumed. (It should be simple to but two simple namespace selectors on a page without getting DOM conflicts)
2012-03-07 19:14:20 +00:00
Krinkle
78c157faf9 [Html] Follow-up r109990: Add support for excluding and disabling options 2012-02-13 15:08:26 +00:00
Krinkle
9815dff76f [Html.php] Follow-up r110275, comment fixes.
* $options does not contain <option> elements, but associative array between option-values and option-labels
2012-02-12 18:58:28 +00:00
Antoine Musso
fc6bc233be Fix doxygen docs before REL1_19 branching 2012-02-01 20:53:38 +00:00
Antoine Musso
11c166bf92 comment / style for Html::namespaceSelector()
Xml.php:
* align array values. Easier to the eyes.

Html.php:
* Various comments
* Switched the way the HTML is forged

Ping r109990
2012-01-30 11:02:56 +00:00
Krinkle
3c9d05055b [Html] Unit test + bugfix Html::namespaceSelector
* Previously it was passing $selectAttribs['name'] to Xml::label, which uses its value for the <label for=""> attribute. This works as long as $selectAttribs['id'] and $selectAttribs['name'] match, but when they don't it fails. <label for=""> always corresponds with <{input,text area,select} id=""> in browsers, never with "name".
* Make name/id match eachother by default to avoid backwards compatibility breakages (they used to match in the Xml class method as well)
* Add HtmlTest.php entries similar to the ones in XmlTest
* Fix E_NOTICE about $params['selected'], default to ''

-- Follows-up r109974, r109698, r109990
-- Bug originally introduced in r41425
-- XmlTest.php still runs successfully
-- HtmlTest.php runs successfully
2012-01-25 03:25:54 +00:00
Krinkle
11b0b2e7d3 [Xml/Html] new method Html::namespaceSelector
* Using params and option arrays instead of 4 random parameters like Xml::namespaceSelector did
* Right now it's passing $selectAttribs['name'] to Xml::label, this is done because that's what Xml::namespaceSelector did. However it's wrong since labels associate over ID not NAME. Will fix in the next commit, making sure unit tests stay functional first. This bug has been in Xml::namespaceSelector for a long time but usually unnoticed as people kept either defaults. Although it was easy to get wrong as the NAME was configurable but the ID was hardcoded in Xml::namespaceSelector.
* Deprecated Xml::namespaceSelector and made it cal Html::namespaceSelector

* Follows-up r109974, r109698
* XmlTest.php still runs successfully
2012-01-25 03:01:20 +00:00
Antoine Musso
b4913d5b96 makes HTML5 five only attributes a global property
This patch move an array hidden in Html::expandAttributes() to the top of
the class definition as self::$HTMLFiveOnlyAttribs.
That also make the Html::expandAttributes() method a bit more concise.
2011-10-24 13:58:03 +00:00
Brion Vibber
969cec9322 * (bug 12130) Initial newlines are now preserved correctly during editing
HTML browsers strip the first newline from the literal contents of a <textarea>, but keep any additional newlines beyond that.

Prepending an extra newline in Html::textarea() when the contained text started with a newline makes our output basically look like this:

<textarea>             <-- (this added newline is ignored)
                       <-- (any original newline here is preserved)
blah blah</textarea>

This seems to consistently resolve the stripping of single initial newlines from every edit operation as seen on bug 12130; as noted on comments there <https://bugzilla.wikimedia.org/show_bug.cgi?id=12130#c17> this had deleterious effects on Wikisource, where transcription/proofreading tends to involve breaking up lots of little pages, which may have a significant newline at the start of a page boundary.

Text that didn't have initial newlines won't see any difference in the HTML output.

Followup to test cases in r98576, which confirm that supported browsers consistently have this behavior.
2011-09-30 22:50:48 +00:00
Jeroen De Dauw
3c4a3f16a0 Follow up to r97128; 2011-09-15 16:07:40 +00:00
Krinkle
fc226de996 Add documentation for r96170 and r96188. 2011-09-04 21:18:27 +00:00
Daniel Friesen
cebad72f95 Expand r96170's support for space separated attributes with support for boolean keys such as array( 'class' => array( 'selected' => true ) ) to match our array( 'checked' => false ) support.
As per discussion with Krinkle make sure that in array( 'foo', 'foo' => false, 'foo' ) the 'foo' key is authoritive.
2011-09-03 14:36:58 +00:00
Krinkle
73db9698a3 Html.php: The "future"[1] is here. Add features for space-separated value attributes of html elements.
* Has been suggested since August 2009 in r54767 (doc-comment from rawElement/element function)
* Implements normalization for these attributes (removal of duplicates and redundant space)
* Adds support for arrays (instead of just string) for these attributes. 
* String are still supported, and are converted to arrays to get the same normalization.
* Wrote unit tests (which pass locally: $ php phpunit.php includes/HtmlTest.php)
* Not trigger for the media-attribute. Reason: Although some people think it's space-separated, it's actually comma-separated. Treating them as space separated might even destroy the value. [2] [3]. Neither the html4 or html5 spec documents media-attribute as space-separated, and as of HTML5/CSS3 the media attribute may contain "media queries".


[1] "In the future, other HTML-specific features might be added, like allowing arrays for the values of attributes like class= and media=" in r54767 by Simetrical.
[2] http://www.w3.org/TR/1999/REC-html401-19991224/types.html#h-6.13
[3] http://dev.w3.org/csswg/css3-mediaqueries/#background

Implementation note: I choose to have a single list of attributes that trigger this feature. Some of these attributes only support multiple values and/or are documented as space-separated as of html5 (such as accesskey), but since those attributes in general have existed in html4 as well (just different w3c spec), they are not stripped if wgHtml5 is not true. So if this feature would (eg. for accesskey) would only be done if wgHtml5=true, then people could get output like <a accesskey=Array /> depending on a configuration variable, which will get messy and make developers' life hard.
2011-09-03 03:55:23 +00:00
Krinkle
bc1532c31c Html.php: Move html5-validation blacklist check to *AFTER* the check the might continue (and skip this loop entirely) if we're not in HTML5 with an html5-only attribute.
* Performance :)
2011-09-03 00:35:08 +00:00
Daniel Friesen
30d1962eed Add html5 microdata's itemscope to the list of boolean attributes. 2011-08-28 23:03:19 +00:00
Derk-Jan Hartman
69bde7f3ae Update the Html5 void elements and boolean attributes, in accordance with the latest draft. 2011-08-12 21:04:25 +00:00