mirror of
https://github.com/Universal-Omega/PortableInfobox.git
synced 2024-11-15 20:09:44 +00:00
move sanitizing to PortableInfoboxRenderService
This commit is contained in:
parent
0de509246f
commit
ed73d4f525
|
@ -47,8 +47,8 @@ class PortableInfoboxRenderServiceHelper {
|
|||
/**
|
||||
* check if infobox item is a title, title inside the hero module or a label
|
||||
* and if so, remove from it HTML tags.
|
||||
* If label after sanitization is empty- contains only image- do not
|
||||
* sanitize it.
|
||||
* If data - label after sanitization became empty because contained only image
|
||||
* - do not sanitize it.
|
||||
*
|
||||
* @param string $type type of infobox item
|
||||
* @param array $data infobox item data
|
||||
|
@ -70,6 +70,9 @@ class PortableInfoboxRenderServiceHelper {
|
|||
}
|
||||
} else if ( $type === 'title' ) {
|
||||
$data[ 'value' ] = $this->sanitizeElementData( $data[ 'value' ] );
|
||||
} else if ( $type === 'image' ) {
|
||||
|
||||
$data[ 'caption' ] = $this->sanitizeElementData( $data[ 'caption' ], '<a>' );
|
||||
} else if ( $type === 'hero-mobile' && !empty( $data[ 'title' ][ 'value' ] ) ) {
|
||||
$data[ 'title' ][ 'value' ] = $this->sanitizeElementData( $data[ 'title' ][ 'value' ] );
|
||||
}
|
||||
|
@ -84,7 +87,7 @@ class PortableInfoboxRenderServiceHelper {
|
|||
* @param string $allowedTags
|
||||
* @return string
|
||||
*/
|
||||
public function sanitizeElementData( $elementText, $allowedTags = null ) {
|
||||
private function sanitizeElementData( $elementText, $allowedTags = null ) {
|
||||
$elementTextAfterTrim = trim( strip_tags( $elementText, $allowedTags ) );
|
||||
|
||||
if ( $elementTextAfterTrim !== $elementText ) {
|
||||
|
|
|
@ -136,7 +136,7 @@ class NodeImage extends Node {
|
|||
|
||||
/**
|
||||
* @desc prepare infobox image node data.
|
||||
* Sanitize image caption to contain only wikitext and links.
|
||||
*
|
||||
* @param $title
|
||||
* @param $alt
|
||||
* @param $caption
|
||||
|
@ -145,7 +145,6 @@ class NodeImage extends Node {
|
|||
private function getImageData( $title, $alt, $caption ) {
|
||||
$titleObj = $this->getImageAsTitleObject( $title );
|
||||
$fileObj = $this->getFilefromTitle( $titleObj );
|
||||
$caption = (new PortableInfoboxRenderServiceHelper())->sanitizeElementData( $caption, '<a>' );
|
||||
|
||||
if ( $titleObj instanceof \Title ) {
|
||||
$this->getExternalParser()->addImage( $titleObj->getDBkey() );
|
||||
|
|
|
@ -169,13 +169,17 @@ class PortableInfoboxRenderService extends WikiaService {
|
|||
|
||||
if ( $type === 'image' ) {
|
||||
$images = array();
|
||||
|
||||
for ( $i = 0; $i < count($data); $i++ ) {
|
||||
$data[$i][ 'context' ] = self::MEDIA_CONTEXT_INFOBOX;
|
||||
$data[$i] = $helper->extendImageData( $data[$i] );
|
||||
$data[$i] = $helper->sanitizeInfoboxFields( $type, $data[$i] );
|
||||
|
||||
if ( !!$data[$i] ) {
|
||||
$images[] = $data[$i];
|
||||
}
|
||||
}
|
||||
|
||||
if ( count ( $images ) === 0 ) {
|
||||
return false;
|
||||
} else if ( count ( $images ) === 1 ) {
|
||||
|
@ -186,6 +190,7 @@ class PortableInfoboxRenderService extends WikiaService {
|
|||
$data = array( 'images' => $images );
|
||||
$templateName = 'image-collection';
|
||||
}
|
||||
|
||||
if ( $helper->isWikiaMobile() ) {
|
||||
$templateName = $templateName . self::MOBILE_TEMPLATE_POSTFIX;
|
||||
}
|
||||
|
|
|
@ -287,12 +287,18 @@ class PortableInfoboxRenderServiceHelperTest extends WikiaBaseTest {
|
|||
3 => '$50'
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
['image',
|
||||
[ 'caption' => 'Test <a>Title with</a> <span><small>small</small></span> tag, span tag and <img src="sfefes"/>tag' ],
|
||||
[ 'caption' => 'Test <a>Title with</a> small tag, span tag and tag' ]
|
||||
],
|
||||
['image',
|
||||
[ 'caption' => '<a href="http://vignette-poz.wikia-dev.com//images/9/95/All_Stats_%2B2.png/revision/latest?cb=20151222111955" class="image image-thumbnail"><img src="abc" alt="All Stats +2" class="thumbimage" /></a>' ],
|
||||
[ 'caption' => '<a href="http://vignette-poz.wikia-dev.com//images/9/95/All_Stats_%2B2.png/revision/latest?cb=20151222111955" class="image image-thumbnail"></a>' ],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param array $item
|
||||
* @param array $heroData
|
||||
|
|
Loading…
Reference in a new issue