r109723 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109722‎ | r109723 | r109724 >
Date:05:58, 22 January 2012
Author:daniel
Status:reverted (Comments)
Tags:
Comment:
Introducing optional support for <a> tags, to be used with microdata resp. RDFa, as originally suggested in r58694.
This is reintroduced after a discussion with TimStarling considering the discussion about r58717.
Note that a change to the parser will be needed to cause links from <a> tags to be recorded in the externallink table.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/Sanitizer.php (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -26,6 +26,9 @@
2727 * (bug 32239) Removed wgEnableTooltipsAndAccesskeys.
2828 * Removed $wgVectorShowVariantName.
2929 * Removed $wgExtensionAliasesFiles. Use wgExtensionMessagesFiles.
 30+* Introduced $wgAllowATag to allow <a> tags to be used for external links,
 31+ so rel and ref attributes can be used with microdata resp RDFa.
 32+ Defaults is false.
3033
3134 === New features in 1.19 ===
3235 * (bug 19838) Possibility to get all interwiki prefixes if the interwiki
Index: trunk/phase3/includes/Sanitizer.php
@@ -407,6 +407,11 @@
408408 $htmlsingleonly[] = 'img';
409409 }
410410
 411+ global $wgAllowATag;
 412+ if ( $wgAllowATag ) {
 413+ $htmlpairsStatic[] = 'a';
 414+ }
 415+
411416 $htmlsingleallowed = array_unique( array_merge( $htmlsingle, $tabletags ) );
412417 $htmlelementsStatic = array_unique( array_merge( $htmlsingle, $htmlpairsStatic, $htmlnest ) );
413418
@@ -797,6 +802,23 @@
798803 }
799804 }
800805
 806+ if ( $attribute === 'href' || $attribute === 'src' ) {
 807+ if ( !preg_match( $hrefExp, $value ) ) {
 808+ continue; //drop any href or src attributes not using an allowed protocol.
 809+ //NOTE: this also drops all relative URLs
 810+ }
 811+ }
 812+
 813+ //RDFa properties allow URIs. check them
 814+ if ( $attribute === 'rel' || $attribute === 'rev' ||
 815+ $attribute === 'about' || $attribute === 'property' || $attribute === 'resource' ||
 816+ $attribute === 'datatype' || $attribute === 'typeof' ) {
 817+ //Paranoia. Allow "simple" values but suppress javascript
 818+ if ( preg_match( '/(^|\s)javascript\s*:/i', $value ) ) {
 819+ continue;
 820+ }
 821+ }
 822+
801823 // If this attribute was previously set, override it.
802824 // Output should only have one attribute of each name.
803825 $out[$attribute] = $value;
@@ -1572,7 +1594,7 @@
15731595 'td' => array_merge( $common, $tablecell, $tablealign ),
15741596 'th' => array_merge( $common, $tablecell, $tablealign ),
15751597
1576 - # 12.2 # NOTE: <a> is not allowed directly, but the attrib whitelist is used from the Parser object
 1598+ # 12.2
15771599 'a' => array_merge( $common, array( 'href', 'rel', 'rev' ) ), # rel/rev esp. for RDFa
15781600
15791601 # 13.2
Index: trunk/phase3/includes/DefaultSettings.php
@@ -2242,11 +2242,13 @@
22432243
22442244 /**
22452245 * Enabled HTML5 microdata attributes for use in wikitext, if $wgHtml5 is also true.
 2246+ * See also $wgAllowATag.
22462247 */
22472248 $wgAllowMicrodataAttributes = false;
22482249
22492250 /**
22502251 * Cleanup as much presentational html like valign -> css vertical-align as we can
 2252+ * See also $wgAllowATag.
22512253 */
22522254 $wgCleanupPresentationalAttributes = true;
22532255
@@ -2979,6 +2981,14 @@
29802982 $wgAllowImageTag = false;
29812983
29822984 /**
 2985+ * Allow <a> tags for specifying external links, so it becomes possible to
 2986+ * provide ref and rel attributes. This allows for microdata/microformats/RDFa
 2987+ * annotations to be embedded on wiki pages. See also $wgAllowRdfaAttributes
 2988+ * and $wgAllowMicrodataAttributes.
 2989+ */
 2990+$wgAllowATag = false;
 2991+
 2992+/**
29832993 * $wgUseTidy: use tidy to make sure HTML output is sane.
29842994 * Tidy is a free tool that fixes broken HTML.
29852995 * See http://www.w3.org/People/Raggett/tidy/

Follow-up revisions

RevisionCommit summaryAuthorDate
r109756reverting r109723 because of slush.daniel20:46, 22 January 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r58694allow <a> tags and RDFa attributes to support RDFa output from license templa...daniel09:43, 7 November 2009
r58717adding support for <a> tags as a parser tag hook, in order to support rdfa ou...daniel16:46, 7 November 2009

Comments

#Comment by Siebrand (talk | contribs)   12:37, 22 January 2012

Slush in progress for 1.19. Please revert and re-introduce after 1.19 has been branched.

#Comment by 😂 (talk | contribs)   22:30, 31 January 2012

When this is reintroduced it should definitely include some test cases.

#Comment by Duesentrieb (talk | contribs)   22:45, 31 January 2012

I have submitted this to bugzilla for now, see https://bugzilla.wikimedia.org/show_bug.cgi?id=33886

The second patch includes parser tests.

Status & tagging log