Issues (166)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

formats/gallery/Gallery.php (4 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace SRF;
4
5
use Html;
6
use SMW\ResultPrinter;
7
use SMWDataItem;
8
use SMWOutputs;
9
use SMWPrintRequest;
10
use SMWQueryResult;
11
use SRFUtils;
12
use Title;
13
use TraditionalImageGallery;
14
15
/**
16
 * Result printer that outputs query results as a image gallery.
17
 *
18
 * @author Jeroen De Dauw < [email protected] >
19
 * @author mwjames
20
 * @author Rowan Rodrik van der Molen
21
 */
22
class Gallery extends ResultPrinter {
23
24
	/**
25
	 * @see SMWResultPrinter::getName
26
	 *
27
	 * @return string
28
	 */
29
	public function getName() {
30
		return $this->msg( 'srf_printername_gallery' )->text();
31
	}
32
33
	/**
34
	 * @see SMWResultPrinter::buildResult
35
	 *
36
	 * @since 1.8
37
	 *
38
	 * @param SMWQueryResult $results
39
	 *
40
	 * @return string
41
	 */
42 1
	protected function buildResult( SMWQueryResult $results ) {
43
44
		// Intro/outro are not planned to work with the widget option
45 1
		if ( ( $this->params['intro'] !== '' || $this->params['outro'] !== '' ) && $this->params['widget'] !== '' ) {
46
			$results->addErrors(
47
				[
48
					$this->msg( 'srf-error-option-mix', 'widget' )->inContentLanguage()->text()
49
				]
50
			);
51
52
			return '';
53
		};
54
55 1
		return $this->getResultText( $results, $this->outputMode );
56
	}
57
58
	/**
59
	 * @see SMWResultPrinter::getResultText
60
	 *
61
	 * @param $results SMWQueryResult
62
	 * @param $outputmode integer
63
	 *
64
	 * @return string | array
65
	 */
66 1
	public function getResultText( SMWQueryResult $results, $outputmode ) {
67
68 1
		$ig = new TraditionalImageGallery();
69
70 1
		$ig->setShowBytes( false );
71 1
		$ig->setShowFilename( false );
72
73 1
		if ( method_exists( $ig, 'setShowDimensions' ) ) {
74 1
			$ig->setShowDimensions( false );
75
		}
76
77 1
		$ig->setCaption( $this->mIntro ); // set caption to IQ header
78
79
		// No need for a special page to use the parser but for the "normal" page
80
		// view we have to ensure caption text is parsed correctly through the parser
81 1
		if ( !$this->isSpecialPage() ) {
82 1
			$ig->setParser( $GLOBALS['wgParser'] );
83
		}
84
85 1
		$html = '';
86 1
		$processing = '';
87
88 1
		if ( $this->params['widget'] == 'carousel' ) {
89
			// Carousel widget
90
			$ig->setAttributes( $this->getCarouselWidget() );
91 1
		} elseif ( $this->params['widget'] == 'slideshow' ) {
92
			// Slideshow widget
93
			$ig->setAttributes( $this->getSlideshowWidget() );
94
		} else {
95
96
			// Standard gallery attributes
97
			$attribs = [
98 1
				'id' => uniqid(),
99 1
				'class' => $this->getImageOverlay(),
100
			];
101
102 1
			$ig->setAttributes( $attribs );
103
		}
104
105
		// Only use redirects where the overlay option is not used and redirect
106
		// thumb images towards a different target
107 1
		if ( $this->params['redirects'] !== '' && !$this->params['overlay'] ) {
108
			SMWOutputs::requireResource( 'ext.srf.gallery.redirect' );
109
		}
110
111
		// For the carousel widget, the perrow option should not be set
112 1
		if ( $this->params['perrow'] !== '' && $this->params['widget'] !== 'carousel' ) {
113
			$ig->setPerRow( $this->params['perrow'] );
114
		}
115
116 1
		if ( $this->params['widths'] !== '' ) {
117
			$ig->setWidths( $this->params['widths'] );
118
		}
119
120 1
		if ( $this->params['heights'] !== '' ) {
121
			$ig->setHeights( $this->params['heights'] );
122
		}
123
124 1
		$printReqLabels = [];
125 1
		$redirectType = '';
126
127
		/**
128
		 * @var SMWPrintRequest $printReq
129
		 */
130 1
		foreach ( $results->getPrintRequests() as $printReq ) {
131 1
			$printReqLabels[] = $printReq->getLabel();
132
133
			// Get redirect type
134 1
			if ( $this->params['redirects'] === $printReq->getLabel() ) {
135 1
				$redirectType = $printReq->getTypeID();
136
			}
137
		}
138
139 1
		if ( $this->params['imageproperty'] !== '' && in_array( $this->params['imageproperty'], $printReqLabels ) ||
140 1
			$this->params['redirects'] !== '' && in_array( $this->params['redirects'], $printReqLabels ) ) {
141
142
			$this->addImageProperties(
143
				$results,
144
				$ig,
145
				$this->params['imageproperty'],
146
				$this->params['captionproperty'],
147
				$this->params['redirects'],
148
				$outputmode
149
			);
150
		} else {
151 1
			$this->addImagePages( $results, $ig );
152
		}
153
154
		// SRF Global settings
155 1
		SRFUtils::addGlobalJSVariables();
156
157
		// Display a processing image as long as the DOM is no ready
158 1
		if ( $this->params['widget'] !== '' ) {
159
			$processing = SRFUtils::htmlProcessingElement();
160
		}
161
162
		// Beautify the class selector
163 1
		$class = $this->params['widget'] ? '-' . $this->params['widget'] . ' ' : '';
164 1
		$class = $this->params['redirects'] !== '' && $this->params['overlay'] === false ? $class . ' srf-redirect' . ' ' : $class;
165 1
		$class = $this->params['class'] ? $class . ' ' . $this->params['class'] : $class;
166
167
		// Separate content from result output
168 1
		if ( !$ig->isEmpty() ) {
169
			$attribs = [
170 1
				'class' => 'srf-gallery' . $class,
171 1
				'data-redirect-type' => $redirectType,
172 1
				'data-ns-text' => $this->getFileNsTextForPageLanguage()
173
			];
174
175 1
			$html = Html::rawElement( 'div', $attribs, $processing . $ig->toHTML() );
176
		}
177
178
		// If available, create a link that points to further results
179 1
		if ( $this->linkFurtherResults( $results ) ) {
180
			$html .= $this->getLink( $results, SMW_OUTPUT_HTML )->getText( SMW_OUTPUT_HTML, $this->mLinker );
181
		}
182
183 1
		// If available and no results, return default message
184
185
		if ( $results == '' && $this->params[ 'default' ] !== '' ) {
186
			$html = $this->params[ 'default' ];
187
		}
188
189
190
		return [ $html, 'nowiki' => true, 'isHTML' => true ];
191
	}
192
193
	/**
194
	 * Handles queries where the images (and optionally their captions) are specified as properties.
195
	 *
196
	 * @since 1.5.3
197
	 *
198
	 * @param SMWQueryResult $results
199
	 * @param TraditionalImageGallery $ig
200
	 * @param string $imageProperty
201
	 * @param string $captionProperty
202
	 * @param string $redirectProperty
203
	 * @param $outputMode
204
	 */
205
	protected function addImageProperties( SMWQueryResult $results, &$ig, $imageProperty, $captionProperty, $redirectProperty, $outputMode ) {
206
		while ( /* array of SMWResultArray */
207
		$rows = $results->getNext() ) { // Objects (pages)
208
			$images = [];
209
			$captions = [];
210
			$redirects = [];
211
212
			for ( $i = 0, $n = count( $rows ); $i < $n; $i++ ) { // Properties
213
				/**
214
				 * @var \SMWResultArray $resultArray
215
				 * @var \SMWDataValue $dataValue
216
				 */
217
				$resultArray = $rows[$i];
218
219
				$label = $resultArray->getPrintRequest()->getMode() == SMWPrintRequest::PRINT_THIS
220
					? '-' : $resultArray->getPrintRequest()->getLabel();
221
222
				// Make sure always use real label here otherwise it results in an empty array
223
				if ( $resultArray->getPrintRequest()->getLabel() == $imageProperty ) {
224
					while ( ( $dataValue = $resultArray->getNextDataValue() ) !== false ) { // Property values
225
						if ( $dataValue->getTypeID() == '_wpg' ) {
226
							$images[] = $dataValue->getDataItem()->getTitle();
227
						}
228
					}
229
				} elseif ( $label == $captionProperty ) {
230
					while ( ( $dataValue = $resultArray->getNextDataValue() ) !== false ) { // Property values
231
						$captions[] = $dataValue->getShortText( $outputMode, $this->getLinker( true ) );
232
					}
233
				} elseif ( $label == $redirectProperty ) {
234
					while ( ( $dataValue = $resultArray->getNextDataValue() ) !== false ) { // Property values
235
						if ( $dataValue->getDataItem()->getDIType() == SMWDataItem::TYPE_WIKIPAGE ) {
236
							$redirects[] = $dataValue->getTitle();
237
						} elseif ( $dataValue->getDataItem()->getDIType() == SMWDataItem::TYPE_URI ) {
238
							$redirects[] = $dataValue->getURL();
239
						}
240
					}
241
				}
242
			}
243
244
			// Check available matches against captions
245
			$amountMatches = count( $captions ) == count( $images );
246
			$hasCaption = $amountMatches || count( $captions ) > 0;
247
248
			// Check available matches against redirects
249
			$amountRedirects = count( $redirects ) == count( $images );
250
			$hasRedirect = $amountRedirects || count( $redirects ) > 0;
251
252
			/**
253
			 * @var Title $imgTitle
254
			 */
255
			foreach ( $images as $imgTitle ) {
256
				if ( $imgTitle->exists() ) {
257
					$imgCaption = $hasCaption ? ( $amountMatches ? array_shift( $captions ) : $captions[0] ) : '';
258
					$imgRedirect = $hasRedirect ? ( $amountRedirects ? array_shift( $redirects ) : $redirects[0] ) : '';
259
					$this->addImageToGallery( $ig, $imgTitle, $imgCaption, $imgRedirect );
260
				}
261
			}
262
		}
263
	}
264
265
	/**
266 1
	 * Handles queries where the result objects are image pages.
267 1
	 *
268
	 * @since 1.5.3
269
	 *
270
	 * @param SMWQueryResult $results
271 1
	 * @param TraditionalImageGallery $ig
272
	 */
273
	protected function addImagePages( SMWQueryResult $results, &$ig ) {
274 1
		while ( $row = $results->getNext() ) {
275
			/**
276 1
			 * @var \SMWResultArray $firstField
277 1
			 */
278 1
			$firstField = $row[0];
279
280
			/** @var \SMWDataValue $nextObject */
281 1
			$nextObject = $firstField->getNextDataValue();
282 1
283
			if ( $nextObject !== false ) {
284
				$dataItem = $nextObject->getDataItem();
285 1
				$imgTitle = method_exists( $dataItem, 'getTitle' ) ? $dataItem->getTitle() : null;
286 1
287 1
				// Ensure the title belongs to the image namespace
288 1
				if ( $imgTitle instanceof Title && $imgTitle->getNamespace() === NS_FILE ) {
0 ignored issues
show
The class Title does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
289
					$imgCaption = '';
290
291
					// Is there a property queried for display with ?property
292 1
					if ( isset( $row[1] ) ) {
293
						$imgCaption = $row[1]->getNextDataValue();
294
						if ( is_object( $imgCaption ) ) {
295
							$imgCaption = $imgCaption->getShortText( $this->outputMode, $this->getLinker( true ) );
296 1
						}
297
					}
298
299
					$this->addImageToGallery( $ig, $imgTitle, $imgCaption );
300
				}
301
			}
302
		}
303
	}
304
305
	/**
306
	 * Adds a single image to the gallery.
307
	 * Takes care of automatically adding a caption when none is provided and parsing it's wikitext.
308
	 *
309 1
	 * @since 1.5.3
310
	 *
311 1
	 * @param TraditionalImageGallery $ig The gallery to add the image to
312
	 * @param Title $imgTitle The title object of the page of the image
313
	 * @param string $imgCaption An optional caption for the image
314
	 * @param string $imgRedirect
315
	 */
316
	protected function addImageToGallery( &$ig, Title $imgTitle, $imgCaption, $imgRedirect = '' ) {
317
318
		if ( empty( $imgCaption ) ) {
319
			if ( $this->params['autocaptions'] ) {
320
				$imgCaption = $imgTitle->getBaseText();
321
322 1
				if ( !$this->params['fileextensions'] ) {
323 1
					$imgCaption = preg_replace( '#\.[^.]+$#', '', $imgCaption );
324
				}
325
			} else {
326
				$imgCaption = '';
327 1
			}
328 1
		} else {
329 1
			if ( $imgTitle instanceof Title && $imgTitle->getNamespace() == NS_FILE && !$this->isSpecialPage() ) {
0 ignored issues
show
The class Title does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
330
				$imgCaption = $ig->mParser->recursiveTagParse( $imgCaption );
331
			}
332
		}
333
		// Use image alt as helper for either text
334
		$imgAlt = $this->params['redirects'] === '' ? $imgCaption : ( $imgRedirect !== '' ? $imgRedirect : '' );
335
		$ig->add( $imgTitle, $imgCaption, $imgAlt );
336
	}
337
338 1
	/**
339 1
	 * Returns the overlay setting
340
	 *
341
	 * @since 1.8
342
	 *
343 1
	 * @return string
344
	 */
345
	private function getImageOverlay() {
346
		if ( array_key_exists( 'overlay', $this->params ) && $this->params['overlay'] == true ) {
347
			SMWOutputs::requireResource( 'ext.srf.gallery.overlay' );
348
			return ' srf-overlay';
349
		} else {
350
			return '';
351
		}
352
	}
353
354
	/**
355
	 * Init carousel widget
356
	 *
357
	 * @since 1.8
358
	 *
359
	 * @return string[]
360
	 */
361
	private function getCarouselWidget() {
362
363
		// Set attributes for jcarousel
364
		$dataAttribs = [
365
			'wrap' => 'both', // Whether to wrap at the first/last item (or both) and jump back to the start/end.
366
			'vertical' => 'false', // Orientation: vertical = false means horizontal
367
			'rtl' => 'false', // Directionality: rtl = false means ltr
368
		];
369
370
		// Use the perrow parameter to determine the scroll sequence.
371
		if ( empty( $this->params['perrow'] ) ) {
372
			$dataAttribs['scroll'] = 1;  // default 1
373
		} else {
374
			$dataAttribs['scroll'] = $this->params['perrow'];
375
			$dataAttribs['visible'] = $this->params['perrow'];
376
		}
377
378
		$attribs = [
379
			'id' => uniqid(),
380
			'class' => 'jcarousel jcarousel-skin-smw' . $this->getImageOverlay(),
381
			'style' => 'display:none;',
382
		];
383
384
		foreach ( $dataAttribs as $name => $value ) {
385
			$attribs['data-' . $name] = $value;
386
		}
387
388
		SMWOutputs::requireResource( 'ext.srf.gallery.carousel' );
389
390
		return $attribs;
391
	}
392
393
	/**
394
	 * Init slideshow widget
395
	 *
396
	 * @since 1.8
397
	 *
398
	 * @return string[]
399
	 */
400
	private function getSlideshowWidget() {
401
402
		$attribs = [
403
			'id' => uniqid(),
404
			'class' => $this->getImageOverlay(),
405
			'style' => 'display:none;',
406
			'data-nav-control' => $this->params['navigation']
407
		];
408
409
		SMWOutputs::requireResource( 'ext.srf.gallery.slideshow' );
410
411
		return $attribs;
412
	}
413
414
	/**
415
	 * @see SMWResultPrinter::getParamDefinitions
416 1
	 *
417 1
	 * @since 1.8
418
	 *
419 1
	 * @param $definitions array of IParamDefinition
420
	 *
421
	 * @return array of IParamDefinition|array
422
	 */
423
	public function getParamDefinitions( array $definitions ) {
424
		$params = parent::getParamDefinitions( $definitions );
425 1
426
		$params['class'] = [
427
			'type' => 'string',
428
			'message' => 'srf-paramdesc-class',
429
			'default' => ''
430
		];
431
432 1
		$params['widget'] = [
433
			'type' => 'string',
434
			'default' => '',
435
			'message' => 'srf-paramdesc-widget',
436
			'values' => [ 'carousel', 'slideshow', '' ]
437
		];
438
439 1
		$params['navigation'] = [
440
			'type' => 'string',
441
			'default' => 'nav',
442
			'message' => 'srf-paramdesc-navigation',
443
			'values' => [ 'nav', 'pager', 'auto' ]
444
		];
445 1
446
		$params['overlay'] = [
447
			'type' => 'boolean',
448
			'default' => false,
449
			'message' => 'srf-paramdesc-overlay'
450
		];
451 1
452
		$params['perrow'] = [
453
			'type' => 'integer',
454
			'default' => '',
455
			'message' => 'srf_paramdesc_perrow'
456
		];
457 1
458
		$params['widths'] = [
459
			'type' => 'integer',
460
			'default' => '',
461
			'message' => 'srf_paramdesc_widths'
462
		];
463 1
464
		$params['heights'] = [
465
			'type' => 'integer',
466
			'default' => '',
467
			'message' => 'srf_paramdesc_heights'
468
		];
469 1
470
		$params['autocaptions'] = [
471
			'type' => 'boolean',
472
			'default' => true,
473
			'message' => 'srf_paramdesc_autocaptions'
474
		];
475 1
476
		$params['fileextensions'] = [
477
			'type' => 'boolean',
478
			'default' => false,
479
			'message' => 'srf_paramdesc_fileextensions'
480
		];
481 1
482
		$params['captionproperty'] = [
483
			'type' => 'string',
484
			'default' => '',
485
			'message' => 'srf_paramdesc_captionproperty'
486
		];
487 1
488
		$params['imageproperty'] = [
489
			'type' => 'string',
490
			'default' => '',
491
			'message' => 'srf_paramdesc_imageproperty'
492
		];
493 1
494
		$params['redirects'] = [
495
			'type' => 'string',
496
			'default' => '',
497
			'message' => 'srf-paramdesc-redirects'
498
		];
499 1
500 1
		return $params;
501 1
	}
502
503
	/**
504
	 * @return bool
505
	 */
506
	private function isSpecialPage() {
507 1
		$title = $GLOBALS['wgTitle'];
508 1
		return $title instanceof Title && $title->isSpecialPage();
0 ignored issues
show
The class Title does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
509 1
	}
510
511
	/**
512
	 * @return bool|null|string
513
	 */
514
	private function getFileNsTextForPageLanguage() {
515
		$title = $GLOBALS['wgTitle'];
516
		return $title instanceof Title ? $title->getPageLanguage()->getNsText( NS_FILE ) : null;
0 ignored issues
show
The class Title does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
517
	}
518
519
}
520