本文整理汇总了PHP中Sanitizer::fixTagAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP Sanitizer::fixTagAttributes方法的具体用法?PHP Sanitizer::fixTagAttributes怎么用?PHP Sanitizer::fixTagAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sanitizer
的用法示例。
在下文中一共展示了Sanitizer::fixTagAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
function __construct($listmode, $secseparators, $multisecseparators, $inlinetext, $listattr = '', $itemattr = '', $listseparators, $iOffset, $dominantSection)
{
// default for inlinetext (if not in mode=userformat)
if ($listmode != 'userformat' && $inlinetext == '') {
$inlinetext = ' - ';
}
$this->name = $listmode;
$_listattr = $listattr == '' ? '' : ' ' . Sanitizer::fixTagAttributes($listattr, 'ul');
$_itemattr = $itemattr == '' ? '' : ' ' . Sanitizer::fixTagAttributes($itemattr, 'li');
$this->sSectionTags = $secseparators;
$this->aMultiSecSeparators = $multisecseparators;
$this->iDominantSection = $dominantSection - 1;
// 0 based index
switch ($listmode) {
case 'inline':
if (stristr($inlinetext, '<BR />')) {
//one item per line (pseudo-inline)
$this->sListStart = '<DIV' . $_listattr . '>';
$this->sListEnd = '</DIV>';
}
$this->sItemStart = '<SPAN' . $_itemattr . '>';
$this->sItemEnd = '</SPAN>';
$this->sInline = $inlinetext;
break;
case 'ordered':
if ($iOffset == 0) {
$this->sListStart = '<OL start=1 ' . $_listattr . '>';
} else {
$this->sListStart = '<OL start=' . ($iOffset + 1) . ' ' . $_listattr . '>';
}
$this->sListEnd = '</OL>';
$this->sItemStart = '<LI' . $_itemattr . '>';
$this->sItemEnd = '</LI>';
break;
case 'unordered':
$this->sListStart = '<UL' . $_listattr . '>';
$this->sListEnd = '</UL>';
$this->sItemStart = '<LI' . $_itemattr . '>';
$this->sItemEnd = '</LI>';
break;
case 'definition':
$this->sListStart = '<DL' . $_listattr . '>';
$this->sListEnd = '</DL>';
// item html attributes on dt element or dd element ?
$this->sHeadingStart = '<DT>';
$this->sHeadingEnd = '</DT><DD>';
$this->sItemEnd = '</DD>';
break;
case 'H2':
case 'H3':
case 'H4':
$this->sListStart = '<DIV' . $_listattr . '>';
$this->sListEnd = '</DIV>';
$this->sHeadingStart = '<' . $listmode . '>';
$this->sHeadingEnd = '</' . $listmode . '>';
break;
case 'userformat':
switch (count($listseparators)) {
case 4:
$this->sListEnd = $listseparators[3];
case 3:
$this->sItemEnd = $listseparators[2];
case 2:
$this->sItemStart = $listseparators[1];
case 1:
$this->sListStart = $listseparators[0];
}
$this->sInline = $inlinetext;
break;
}
}
示例2: removeHTMLtags
//.........这里部分代码省略.........
if ($ot != $t) {
if (isset($htmlsingleallowed[$ot])) {
# Pop all elements with an optional close tag
# and see if we find a match below them
$optstack = array();
array_push($optstack, $ot);
$ot = @array_pop($tagstack);
while ($ot != $t && isset($htmlsingleallowed[$ot])) {
array_push($optstack, $ot);
$ot = @array_pop($tagstack);
}
if ($t != $ot) {
# No match. Push the optional elements back again
$badtag = true;
while ($ot = @array_pop($optstack)) {
array_push($tagstack, $ot);
}
}
} else {
@array_push($tagstack, $ot);
# <li> can be nested in <ul> or <ol>, skip those cases:
if (!isset($htmllist[$ot]) || !isset($listtags[$t])) {
$badtag = true;
}
}
} else {
if ($t == 'table') {
$tagstack = array_pop($tablestack);
}
}
$newparams = '';
} else {
# Keep track for later
if (isset($tabletags[$t]) && !in_array('table', $tagstack)) {
$badtag = true;
} elseif (in_array($t, $tagstack) && !isset($htmlnest[$t])) {
$badtag = true;
# Is it a self closed htmlpair ? (bug 5487)
} elseif ($brace == '/>' && isset($htmlpairs[$t])) {
$badtag = true;
} elseif (isset($htmlsingleonly[$t])) {
# Hack to force empty tag for uncloseable elements
$brace = '/>';
} elseif (isset($htmlsingle[$t])) {
# Hack to not close $htmlsingle tags
$brace = null;
} elseif (isset($tabletags[$t]) && in_array($t, $tagstack)) {
// New table tag but forgot to close the previous one
$text .= "</{$t}>";
} else {
if ($t == 'table') {
array_push($tablestack, $tagstack);
$tagstack = array();
}
array_push($tagstack, $t);
}
# Replace any variables or template parameters with
# plaintext results.
if (is_callable($processCallback)) {
call_user_func_array($processCallback, array(&$params, $args));
}
# Strip non-approved attributes from the tag
$newparams = Sanitizer::fixTagAttributes($params, $t);
}
if (!$badtag) {
$rest = str_replace('>', '>', $rest);
$close = $brace == '/>' && !$slash ? ' /' : '';
$text .= "<{$slash}{$t}{$newparams}{$close}>{$rest}";
continue;
}
}
$text .= '<' . str_replace('>', '>', $x);
}
# Close off any remaining tags
while (is_array($tagstack) && ($t = array_pop($tagstack))) {
$text .= "</{$t}>\n";
if ($t == 'table') {
$tagstack = array_pop($tablestack);
}
}
} else {
# this might be possible using tidy itself
foreach ($bits as $x) {
preg_match('/^(\\/?)(\\w+)([^>]*?)(\\/{0,1}>)([^<]*)$/', $x, $regs);
@(list(, $slash, $t, $params, $brace, $rest) = $regs);
if (isset($htmlelements[$t = strtolower($t)])) {
if (is_callable($processCallback)) {
call_user_func_array($processCallback, array(&$params, $args));
}
$newparams = Sanitizer::fixTagAttributes($params, $t);
$rest = str_replace('>', '>', $rest);
$text .= "<{$slash}{$t}{$newparams}{$brace}{$rest}";
} else {
$text .= '<' . str_replace('>', '>', $x);
}
}
}
wfProfileOut(__METHOD__);
return $text;
}
示例3: testAttributeSupport
/**
* @dataProvider provideAttributeSupport
*/
function testAttributeSupport($tag, $attributes, $expected, $message)
{
$this->assertEquals($expected, Sanitizer::fixTagAttributes($attributes, $tag), $message);
}
示例4: doTableStuff
/**
* parse the wiki syntax used to render tables
*
* @private
*/
function doTableStuff($text)
{
wfProfileIn(__METHOD__);
# RTE (Rich Text Editor) - begin
# Used to determine whether the Parser running in RTE mode or not
global $wgRTEParserEnabled;
# RTE - end
$lines = StringUtils::explode("\n", $text);
$out = '';
$td_history = array();
# Is currently a td tag open?
$last_tag_history = array();
# Save history of last lag activated (td, th or caption)
$tr_history = array();
# Is currently a tr tag open?
$tr_attributes = array();
# history of tr attributes
$has_opened_tr = array();
# Did this table open a <tr> element?
$indent_level = 0;
# indent level of the table
foreach ($lines as $outLine) {
$line = trim($outLine);
# RTE (Rich Text Editor) - begin
# @author: Inez Korczyński
# Initialize this variable regardless of the RTE mode being on/off,
# then it can be used in next batch of code without checking RTE mode.
$RTEcomment = null;
if (!empty($wgRTEParserEnabled)) {
# Check if there is a wikitext comment placholder at the beginning of given line,
# then cut it off - to have proper MediaWiki table processing - and store in variable for later recovery
$RTEdataIdx = RTEMarker::getDataIdx(RTEMarker::PLACEHOLDER, $line, false);
if ($RTEdataIdx != null) {
$RTEdata = RTEData::get('placeholder', $RTEdataIdx);
if ($RTEdata && $RTEdata['type'] == 'comment') {
$RTEcomment = substr($line, 0, 9);
$line = substr($line, 9);
}
}
}
# RTE - end
if ($line === '') {
# empty line, go to next line
$out .= $outLine . "\n";
continue;
}
$first_character = $line[0];
$matches = array();
if (preg_match('/^(:*)\\{\\|(.*)$/', $line, $matches)) {
# First check if we are starting a new table
$indent_level = strlen($matches[1]);
$attributes = $this->mStripState->unstripBoth($matches[2]);
# RTE (Rich Text Editor) - begin
# @author: Inez Korczyński
if (!empty($wgRTEParserEnabled)) {
# Throw an RTE edgacase if there is RTR marker (\x7f) in table attributes
# Example: {| {{some template call}}
if (strpos($attributes, "") !== false) {
RTE::$edgeCases[] = 'COMPLEX.04';
}
}
# RTE - end
$attributes = Sanitizer::fixTagAttributes($attributes, 'table');
$outLine = str_repeat('<dl><dd>', $indent_level) . "<table{$attributes}>";
# RTE (Rich Text Editor) - begin
$outLine = $RTEcomment . $outLine;
$RTEcomment = null;
# RTE - end
array_push($td_history, false);
array_push($last_tag_history, '');
array_push($tr_history, false);
array_push($tr_attributes, '');
array_push($has_opened_tr, false);
} elseif (count($td_history) == 0) {
# Don't do any of the following
$out .= $outLine . "\n";
continue;
} elseif (substr($line, 0, 2) === '|}') {
# We are ending a table
$line = '</table>' . substr($line, 2);
$last_tag = array_pop($last_tag_history);
if (!array_pop($has_opened_tr)) {
$line = "<tr><td></td></tr>{$line}";
}
if (array_pop($tr_history)) {
$line = "</tr>{$line}";
}
if (array_pop($td_history)) {
$line = "</{$last_tag}>{$line}";
}
array_pop($tr_attributes);
$outLine = $line . str_repeat('</dd></dl>', $indent_level);
} elseif (substr($line, 0, 2) === '|-') {
# Now we have a table row
$line = preg_replace('#^\\|-+#', '', $line);
//.........这里部分代码省略.........
示例5: removeHTMLtags
//.........这里部分代码省略.........
if (isset($htmlsingleallowed[$ot])) {
# Pop all elements with an optional close tag
# and see if we find a match below them
$optstack = array();
array_push($optstack, $ot);
while (($ot = @array_pop($tagstack)) != $t && isset($htmlsingleallowed[$ot])) {
array_push($optstack, $ot);
}
if ($t != $ot) {
# No match. Push the optinal elements back again
$badtag = 1;
while ($ot = @array_pop($optstack)) {
array_push($tagstack, $ot);
}
}
} else {
@array_push($tagstack, $ot);
# <li> can be nested in <ul> or <ol>, skip those cases:
if (!(isset($htmllist[$ot]) && isset($listtags[$t]))) {
$badtag = 1;
}
}
} else {
if ($t == 'table') {
$tagstack = array_pop($tablestack);
}
}
$newparams = '';
} else {
# Keep track for later
if (isset($tabletags[$t]) && !in_array('table', $tagstack)) {
$badtag = 1;
} else {
if (in_array($t, $tagstack) && !isset($htmlnest[$t])) {
$badtag = 1;
# Is it a self closed htmlpair ? (bug 5487)
} else {
if ($brace == '/>' && isset($htmlpairs[$t])) {
$badtag = 1;
} elseif (isset($htmlsingleonly[$t])) {
# Hack to force empty tag for uncloseable elements
$brace = '/>';
} else {
if (isset($htmlsingle[$t])) {
# Hack to not close $htmlsingle tags
$brace = NULL;
} else {
if ($t == 'table') {
array_push($tablestack, $tagstack);
$tagstack = array();
}
array_push($tagstack, $t);
}
}
}
}
# Replace any variables or template parameters with
# plaintext results.
if (is_callable($processCallback)) {
call_user_func_array($processCallback, array(&$params, $args));
}
# Strip non-approved attributes from the tag
$newparams = Sanitizer::fixTagAttributes($params, $t);
}
if (!$badtag) {
$rest = str_replace('>', '>', $rest);
$close = $brace == '/>' ? ' /' : '';
$text .= "<{$slash}{$t}{$newparams}{$close}>{$rest}";
continue;
}
}
$text .= '<' . str_replace('>', '>', $x);
}
# Close off any remaining tags
while (is_array($tagstack) && ($t = array_pop($tagstack))) {
$text .= "</{$t}>\n";
if ($t == 'table') {
$tagstack = array_pop($tablestack);
}
}
} else {
# this might be possible using tidy itself
foreach ($bits as $x) {
preg_match('/^(\\/?)(\\w+)([^>]*?)(\\/{0,1}>)([^<]*)$/', $x, $regs);
@(list($qbar, $slash, $t, $params, $brace, $rest) = $regs);
if (isset($htmlelements[$t = strtolower($t)])) {
if (is_callable($processCallback)) {
call_user_func_array($processCallback, array(&$params, $args));
}
$newparams = Sanitizer::fixTagAttributes($params, $t);
$rest = str_replace('>', '>', $rest);
$text .= "<{$slash}{$t}{$newparams}{$brace}{$rest}";
} else {
$text .= '<' . str_replace('>', '>', $x);
}
}
}
wfProfileOut(__METHOD__);
return $text;
}
示例6: removeHTMLtags
/**
* Cleans up HTML, removes dangerous tags and attributes, and
* removes HTML comments
* @access private
* @param string $text
* @param callback $processCallback to do any variable or parameter replacements in HTML attribute values
* @param array $args for the processing callback
* @return string
*/
function removeHTMLtags($text, $processCallback = null, $args = array())
{
global $wgUseTidy, $wgUserHtml;
$fname = 'Parser::removeHTMLtags';
wfProfileIn($fname);
if ($wgUserHtml) {
$htmlpairs = array('b', 'del', 'i', 'ins', 'u', 'font', 'big', 'small', 'sub', 'sup', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'cite', 'code', 'em', 's', 'strike', 'strong', 'tt', 'var', 'div', 'center', 'blockquote', 'ol', 'ul', 'dl', 'table', 'caption', 'pre', 'ruby', 'rt', 'rb', 'rp', 'p', 'span');
$htmlsingle = array('br', 'hr', 'li', 'dt', 'dd');
$htmlsingleonly = array('br', 'hr');
$htmlnest = array('table', 'tr', 'td', 'th', 'div', 'blockquote', 'ol', 'ul', 'dl', 'font', 'big', 'small', 'sub', 'sup', 'span');
$tabletags = array('td', 'th', 'tr', 'tbody');
} else {
$htmlpairs = array();
$htmlsingle = array();
$htmlnest = array();
$tabletags = array();
}
$htmlsingle = array_merge($tabletags, $htmlsingle);
$htmlelements = array_merge($htmlsingle, $htmlpairs);
# Remove HTML comments
$text = Sanitizer::removeHTMLcomments($text);
$bits = explode('<', $text);
$text = array_shift($bits);
if (!$wgUseTidy) {
$tagstack = array();
$tablestack = array();
foreach ($bits as $x) {
$prev = error_reporting(E_ALL & ~(E_NOTICE | E_WARNING));
preg_match('/^(\\/?)(\\w+)([^>]*?)(\\/{0,1}>)([^<]*)$/', $x, $regs);
list($qbar, $slash, $t, $params, $brace, $rest) = $regs;
error_reporting($prev);
$badtag = 0;
if (in_array($t = strtolower($t), $htmlelements)) {
# Check our stack
if ($slash) {
# Closing a tag...
if (in_array($t, $htmlsingleonly)) {
$badtag = 1;
} elseif (!in_array($t, $htmlsingle) && ($ot = @array_pop($tagstack)) != $t) {
@array_push($tagstack, $ot);
$badtag = 1;
} else {
if ($t == 'table') {
$tagstack = array_pop($tablestack);
}
$newparams = '';
}
} else {
# Keep track for later
if (in_array($t, $tabletags) && !in_array('table', $tagstack)) {
$badtag = 1;
} else {
if (in_array($t, $tagstack) && !in_array($t, $htmlnest)) {
$badtag = 1;
} elseif (in_array($t, $htmlsingleonly)) {
# Hack to force empty tag for uncloseable elements
$brace = '/>';
} else {
if (!in_array($t, $htmlsingle)) {
if ($t == 'table') {
array_push($tablestack, $tagstack);
$tagstack = array();
}
array_push($tagstack, $t);
}
}
}
# Replace any variables or template parameters with
# plaintext results.
if (is_callable($processCallback)) {
call_user_func_array($processCallback, array(&$params, $args));
}
# Strip non-approved attributes from the tag
$newparams = Sanitizer::fixTagAttributes($params, $t);
}
if (!$badtag) {
$rest = str_replace('>', '>', $rest);
$close = $brace == '/>' ? ' /' : '';
$text .= "<{$slash}{$t}{$newparams}{$close}>{$rest}";
continue;
}
}
$text .= '<' . str_replace('>', '>', $x);
}
# Close off any remaining tags
while (is_array($tagstack) && ($t = array_pop($tagstack))) {
$text .= "</{$t}>\n";
if ($t == 'table') {
$tagstack = array_pop($tablestack);
}
}
//.........这里部分代码省略.........
示例7: doTableStuff
/**
* parse the wiki syntax used to render tables
*
* @private
*/
function doTableStuff($t)
{
$fname = 'Parser::doTableStuff';
wfProfileIn($fname);
$t = explode("\n", $t);
$td = array();
# Is currently a td tag open?
$ltd = array();
# Was it TD or TH?
$tr = array();
# Is currently a tr tag open?
$ltr = array();
# tr attributes
$has_opened_tr = array();
# Did this table open a <tr> element?
$indent_level = 0;
# indent level of the table
foreach ($t as $k => $x) {
$x = trim($x);
$fc = substr($x, 0, 1);
if (preg_match('/^(:*)\\{\\|(.*)$/', $x, $matches)) {
$indent_level = strlen($matches[1]);
$attributes = $this->unstripForHTML($matches[2]);
$t[$k] = str_repeat('<dl><dd>', $indent_level) . '<table' . Sanitizer::fixTagAttributes($attributes, 'table') . '>';
array_push($td, false);
array_push($ltd, '');
array_push($tr, false);
array_push($ltr, '');
array_push($has_opened_tr, false);
} else {
if (count($td) == 0) {
} else {
if ('|}' == substr($x, 0, 2)) {
$z = "</table>" . substr($x, 2);
$l = array_pop($ltd);
if (!array_pop($has_opened_tr)) {
$z = "<tr><td></td></tr>" . $z;
}
if (array_pop($tr)) {
$z = '</tr>' . $z;
}
if (array_pop($td)) {
$z = '</' . $l . '>' . $z;
}
array_pop($ltr);
$t[$k] = $z . str_repeat('</dd></dl>', $indent_level);
} else {
if ('|-' == substr($x, 0, 2)) {
# Allows for |---------------
$x = substr($x, 1);
while ($x != '' && substr($x, 0, 1) == '-') {
$x = substr($x, 1);
}
$z = '';
$l = array_pop($ltd);
array_pop($has_opened_tr);
array_push($has_opened_tr, true);
if (array_pop($tr)) {
$z = '</tr>' . $z;
}
if (array_pop($td)) {
$z = '</' . $l . '>' . $z;
}
array_pop($ltr);
$t[$k] = $z;
array_push($tr, false);
array_push($td, false);
array_push($ltd, '');
$attributes = $this->unstripForHTML($x);
array_push($ltr, Sanitizer::fixTagAttributes($attributes, 'tr'));
} else {
if ('|' == $fc || '!' == $fc || '|+' == substr($x, 0, 2)) {
# Caption
# $x is a table row
if ('|+' == substr($x, 0, 2)) {
$fc = '+';
$x = substr($x, 1);
}
$after = substr($x, 1);
if ($fc == '!') {
$after = str_replace('!!', '||', $after);
}
// Split up multiple cells on the same line.
// FIXME: This can result in improper nesting of tags processed
// by earlier parser steps, but should avoid splitting up eg
// attribute values containing literal "||".
$after = wfExplodeMarkup('||', $after);
$t[$k] = '';
# Loop through each table cell
foreach ($after as $theline) {
$z = '';
if ($fc != '+') {
$tra = array_pop($ltr);
if (!array_pop($tr)) {
$z = '<tr' . $tra . ">\n";
//.........这里部分代码省略.........
示例8: testDeprecatedAttributesDisabled
function testDeprecatedAttributesDisabled()
{
global $wgCleanupPresentationalAttributes;
$wgCleanupPresentationalAttributes = false;
$this->assertEquals(' clear="left"', Sanitizer::fixTagAttributes('clear="left"', 'br'), 'Deprecated attributes are not converted to styles when enabled.');
}
示例9: parse_tables
/**
* Parse tables
*
* @param string Content
* @return string Content
*/
function parse_tables($content)
{
$lines = explode("\n", $content);
$out = '';
$td_history = array();
// Is currently a td tag open?
$last_tag_history = array();
// Save history of last lag activated (td, th or caption)
$tr_history = array();
// Is currently a tr tag open?
$tr_attributes = array();
// history of tr attributes
$has_opened_tr = array();
// Did this table open a <tr> element?
$indent_level = 0;
// indent level of the table
foreach ($lines as $outLine) {
$line = trim($outLine);
if ($line === '') {
// empty line, go to next line
$out .= $outLine . "\n";
continue;
}
$first_character = $line[0];
$matches = array();
if (preg_match('/^(:*)\\{\\|(.*)$/', $line, $matches)) {
// First check if we are starting a new table
$indent_level = strlen($matches[1]);
$attributes = Sanitizer::fixTagAttributes($matches[2], 'table');
$outLine = str_repeat('<dl><dd>', $indent_level) . "<table{$attributes}>";
array_push($td_history, false);
array_push($last_tag_history, '');
array_push($tr_history, false);
array_push($tr_attributes, '');
array_push($has_opened_tr, false);
} elseif (count($td_history) == 0) {
// Don't do any of the following
$out .= $outLine . "\n";
continue;
} elseif (substr($line, 0, 2) === '|}') {
// We are ending a table
$line = '</table>' . substr($line, 2);
$last_tag = array_pop($last_tag_history);
if (!array_pop($has_opened_tr)) {
$line = "<tr><td></td></tr>{$line}";
}
if (array_pop($tr_history)) {
$line = "</tr>{$line}";
}
if (array_pop($td_history)) {
$line = "</{$last_tag}>{$line}";
}
array_pop($tr_attributes);
$outLine = $line . str_repeat('</dd></dl>', $indent_level);
} elseif (substr($line, 0, 2) === '|-') {
// Now we have a table row
$line = preg_replace('#^\\|-+#', '', $line);
// Whats after the tag is now only attributes
$attributes = Sanitizer::fixTagAttributes($line, 'tr');
array_pop($tr_attributes);
array_push($tr_attributes, $attributes);
$line = '';
$last_tag = array_pop($last_tag_history);
array_pop($has_opened_tr);
array_push($has_opened_tr, true);
if (array_pop($tr_history)) {
$line = '</tr>';
}
if (array_pop($td_history)) {
$line = "</{$last_tag}>{$line}";
}
$outLine = $line;
array_push($tr_history, false);
array_push($td_history, false);
array_push($last_tag_history, '');
} elseif ($first_character === '|' || $first_character === '!' || substr($line, 0, 2) === '|+') {
// This might be cell elements, td, th or captions
if (substr($line, 0, 2) === '|+') {
$first_character = '+';
$line = substr($line, 1);
}
$line = substr($line, 1);
if ($first_character === '!') {
$line = str_replace('!!', '||', $line);
}
// Split up multiple cells on the same line.
$cells = explode('||', $line);
$outLine = '';
// Loop through each table cell
foreach ($cells as $cell) {
$previous = '';
if ($first_character !== '+') {
$tr_after = array_pop($tr_attributes);
if (!array_pop($tr_history)) {
//.........这里部分代码省略.........
示例10: testDeprecatedAttributesUnaltered
/**
* @dataProvider provideDeprecatedAttributes
*/
function testDeprecatedAttributesUnaltered($inputAttr, $inputEl)
{
$this->assertEquals(" {$inputAttr}", Sanitizer::fixTagAttributes($inputAttr, $inputEl));
}
示例11: testDeprecatedAttributes
function testDeprecatedAttributes()
{
$GLOBALS['wgCleanupPresentationalAttributes'] = true;
$this->assertEquals(Sanitizer::fixTagAttributes('clear="left"', 'br'), ' style="clear: left;"', 'Deprecated attributes are converted to styles when enabled.');
$this->assertEquals(Sanitizer::fixTagAttributes('clear="all"', 'br'), ' style="clear: both;"', 'clear=all is converted to clear: both; not clear: all;');
$this->assertEquals(Sanitizer::fixTagAttributes('CLEAR="ALL"', 'br'), ' style="clear: both;"', 'clear=ALL is not treated differently from clear=all');
$this->assertEquals(Sanitizer::fixTagAttributes('width="100"', 'td'), ' style="width: 100px;"', 'Numeric sizes use pixels instead of numbers.');
$this->assertEquals(Sanitizer::fixTagAttributes('width="100%"', 'td'), ' style="width: 100%;"', 'Units are allowed in sizes.');
$this->assertEquals(Sanitizer::fixTagAttributes('WIDTH="100%"', 'td'), ' style="width: 100%;"', 'Uppercase WIDTH is treated as lowercase width.');
$this->assertEquals(Sanitizer::fixTagAttributes('WiDTh="100%"', 'td'), ' style="width: 100%;"', 'Mixed case does not break WiDTh.');
$this->assertEquals(Sanitizer::fixTagAttributes('nowrap="true"', 'td'), ' style="white-space: nowrap;"', 'nowrap attribute is output as white-space: nowrap; not something else.');
$this->assertEquals(Sanitizer::fixTagAttributes('nowrap=""', 'td'), ' style="white-space: nowrap;"', 'nowrap="" is considered true, not false');
$this->assertEquals(Sanitizer::fixTagAttributes('NOWRAP="true"', 'td'), ' style="white-space: nowrap;"', 'nowrap attribute works when uppercase.');
$this->assertEquals(Sanitizer::fixTagAttributes('NoWrAp="true"', 'td'), ' style="white-space: nowrap;"', 'nowrap attribute works when mixed-case.');
$GLOBALS['wgCleanupPresentationalAttributes'] = false;
$this->assertEquals(Sanitizer::fixTagAttributes('clear="left"', 'br'), ' clear="left"', 'Deprecated attributes are not converted to styles when enabled.');
}
示例12: externalTableHelper
//.........这里部分代码省略.........
$t[$k] = $table_foot;
unset($table_head, $table_foot);
}
$in_table--;
$ltx_caption = '';
} else {
if ('|-' == substr($x, 0, 2)) {
# Allows for |---------------
if (strpos($x, '----') == 1) {
$add_hline = '\\hline';
} else {
$add_hline = '';
}
$x = substr($x, 1);
while ($x != '' && substr($x, 0, 1) == '-') {
$x = substr($x, 1);
}
$z = '';
$l = array_pop($ltd);
array_pop($has_opened_tr);
array_push($has_opened_tr, true);
if (array_pop($tr)) {
$t[$k - 1] = $t[$k - 1] . '\\tabularnewline \\hline' . $add_hline;
}
array_pop($ltr);
$t[$k] = $z;
array_push($tr, false);
array_push($ltd, '');
// end-of-row
$cellcount_max[$in_table] = max($cellcount_max[$in_table], $cellcount_current[$in_table]);
// start-of-row
$cellcount_current[$in_table] = 0;
$attributes = $this->unstripForHTML($x);
array_push($ltr, Sanitizer::fixTagAttributes($attributes, 'tr'));
$firstCellOfRow = true;
$add_hline = '';
//$cellcounter[] = 0;
} else {
if (('|' === $fc || '!' === $fc || '|+' === substr($x, 0, 2)) && $in_table != 0) {
# Caption
# $x is a table row
if ('|+' == substr($x, 0, 2)) {
$fc = '+';
$x = substr($x, 1);
}
$after = substr($x, 1);
if ($fc == '!') {
$after = str_replace('!!', '||', $after);
}
// Split up multiple cells on the same line.
// FIXME: This can result in improper nesting of tags processed
// by earlier parser steps, but should avoid splitting up eg
// attribute values containing literal "||".
$cells = StringUtils::explodeMarkup('||', $after);
$t[$k] = '';
# Loop through each table cell
foreach ($cells as $theline) {
$z = '';
if ($fc != '+') {
$tra = array_pop($ltr);
if (!array_pop($tr)) {
$z = "\n";
}
// has been: "\n"
array_push($tr, true);
array_push($ltr, '');
示例13: testDeprecatedAttributes
/**
* @dataProvider provideDeprecatedAttributes
*/
function testDeprecatedAttributes($input, $tag, $expected, $message = null)
{
$GLOBALS['wgCleanupPresentationalAttributes'] = true;
$this->assertEquals($expected, Sanitizer::fixTagAttributes($input, $tag), $message);
}
示例14: removeHTMLtags
//.........这里部分代码省略.........
MediaWiki\restoreWarnings();
}
}
} else {
MediaWiki\suppressWarnings();
array_push($tagstack, $ot);
MediaWiki\restoreWarnings();
# <li> can be nested in <ul> or <ol>, skip those cases:
if (!isset($htmllist[$ot]) || !isset($listtags[$t])) {
$badtag = true;
}
}
} else {
if ($t == 'table') {
$tagstack = array_pop($tablestack);
}
}
$newparams = '';
} else {
# Keep track for later
if (isset($tabletags[$t]) && !in_array('table', $tagstack)) {
$badtag = true;
} elseif (in_array($t, $tagstack) && !isset($htmlnest[$t])) {
$badtag = true;
# Is it a self closed htmlpair ? (bug 5487)
} elseif ($brace == '/>' && isset($htmlpairs[$t])) {
$badtag = true;
} elseif (isset($htmlsingleonly[$t])) {
# Hack to force empty tag for unclosable elements
$brace = '/>';
} elseif (isset($htmlsingle[$t])) {
# Hack to not close $htmlsingle tags
$brace = null;
# Still need to push this optionally-closed tag to
# the tag stack so that we can match end tags
# instead of marking them as bad.
array_push($tagstack, $t);
} elseif (isset($tabletags[$t]) && in_array($t, $tagstack)) {
// New table tag but forgot to close the previous one
$text .= "</{$t}>";
} else {
if ($t == 'table') {
array_push($tablestack, $tagstack);
$tagstack = array();
}
array_push($tagstack, $t);
}
# Replace any variables or template parameters with
# plaintext results.
if (is_callable($processCallback)) {
call_user_func_array($processCallback, array(&$params, $args));
}
if (!Sanitizer::validateTag($params, $t)) {
$badtag = true;
}
# Strip non-approved attributes from the tag
$newparams = Sanitizer::fixTagAttributes($params, $t);
}
if (!$badtag) {
$rest = str_replace('>', '>', $rest);
$close = $brace == '/>' && !$slash ? ' /' : '';
$text .= "<{$slash}{$t}{$newparams}{$close}>{$rest}";
continue;
}
}
$text .= '<' . str_replace('>', '>', $x);
}
# Close off any remaining tags
while (is_array($tagstack) && ($t = array_pop($tagstack))) {
$text .= "</{$t}>\n";
if ($t == 'table') {
$tagstack = array_pop($tablestack);
}
}
} else {
# this might be possible using tidy itself
foreach ($bits as $x) {
if (preg_match(self::ELEMENT_BITS_REGEX, $x, $regs)) {
list(, $slash, $t, $params, $brace, $rest) = $regs;
$badtag = false;
if (isset($htmlelements[$t = strtolower($t)])) {
if (is_callable($processCallback)) {
call_user_func_array($processCallback, array(&$params, $args));
}
if (!Sanitizer::validateTag($params, $t)) {
$badtag = true;
}
$newparams = Sanitizer::fixTagAttributes($params, $t);
if (!$badtag) {
$rest = str_replace('>', '>', $rest);
$text .= "<{$slash}{$t}{$newparams}{$brace}{$rest}";
continue;
}
}
}
$text .= '<' . str_replace('>', '>', $x);
}
}
return $text;
}
示例15: testDeprecatedAttributesUnaltered
/**
* @dataProvider provideDeprecatedAttributes
* @covers Sanitizer::fixTagAttributes
*/
public function testDeprecatedAttributesUnaltered($inputAttr, $inputEl, $message = '')
{
$this->assertEquals(" {$inputAttr}", Sanitizer::fixTagAttributes($inputAttr, $inputEl), $message);
}