ResultPrinter::handleNonFileResult()   F
last analyzed

Complexity

Conditions 25
Paths 1800

Size

Total Lines 89
Code Lines 49

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 24
CRAP Score 65

Importance

Changes 0
Metric Value
cc 25
eloc 49
nc 1800
nop 3
dl 0
loc 89
ccs 24
cts 40
cp 0.6
crap 65
rs 2.0166
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace SMW;
4
5
use Linker;
6
use ParamProcessor\ParamDefinition;
7
use ParserOptions;
8
use Sanitizer;
9
use SMWInfolink;
10
use SMWQuery;
11
use SMWQueryResult;
12
use Title;
13
14
/**
15
 * Abstract base class for printing query results.
16
 *
17
 * @since 1.9
18
 *
19
 * @ingroup SMWQuery
20
 *
21
 * @licence GNU GPL v2 or later
22
 * @author Markus Krötzsch
23
 * @author Jeroen De Dauw < [email protected] >
24
 * @author mwjames
25
 */
26
27
/**
28
 * This group contains all members that are relate to query formatting and
29
 * printing.
30
 *
31
 * @defgroup QueryPrinter QueryPrinter
32
 * @ingroup SMWQuery
33
 */
34
35
/**
36
 * Abstract base class for SMW's novel query printing mechanism. It implements
37
 * part of the former functionality of SMWInlineQuery (everything related to
38
 * output formatting and the corresponding parameters) and is subclassed by concrete
39
 * printers that provide the main formatting functionality.
40
 *
41
 * @ingroup SMWQuery
42
 */
43
abstract class ResultPrinter extends \ContextSource implements QueryResultPrinter {
44
45
	/**
46
	 * @deprecated Use $params instead. Will be removed in 1.10.
47
	 */
48
	protected $m_params;
49
50
	/**
51
	 * List of parameters, set by handleParameters.
52
	 * param name (lower case, trimmed) => param value (mixed)
53
	 *
54
	 * @since 1.7
55
	 *
56
	 * @var array
57
	 */
58
	protected $params;
59
60
	/**
61
	 * List of parameters, set by handleParameters.
62
	 * param name (lower case, trimmed) => IParam object
63
	 *
64
	 * @since 1.8
65
	 *
66
	 * @var \IParam[]
67
	 */
68
	protected $fullParams;
69
70
	/**
71
	 * @since 1.8
72
	 *
73
	 * @var
74
	 */
75
	protected $outputMode;
76
77
	/**
78
	 * The query result being displayed.
79
	 *
80
	 * @since 1.8
81
	 *
82
	 * @var SMWQueryResult
83
	 */
84
	protected $results;
85
86
	/**
87
	 * Text to print *before* the output in case it is *not* empty; assumed to be wikitext.
88
	 * Normally this is handled in SMWResultPrinter and can be ignored by subclasses.
89
	 */
90
	protected $mIntro = '';
91
92
	/**
93
	 * Text to print *after* the output in case it is *not* empty; assumed to be wikitext.
94
	 * Normally this is handled in SMWResultPrinter and can be ignored by subclasses.
95
	 */
96
	protected $mOutro = '';
97
98
	/**
99
	 * Text to use for link to further results, or empty if link should not be shown.
100
	 * Unescaped! Use @see SMWResultPrinter::getSearchLabel()
101
	 * and @see SMWResultPrinter::linkFurtherResults()
102
	 * instead of accessing this directly.
103
	 */
104
	protected $mSearchlabel = null;
105
106
	/** Default return value for empty queries. Unescaped. Normally not used in sub-classes! */
107
	protected $mDefault = '';
108
109
	// parameters relevant for printers in general:
110
	protected $mFormat; // a string identifier describing a valid format
111
	protected $mLinkFirst; // should article names of the first column be linked?
112
	protected $mLinkOthers; // should article names of other columns (besides the first) be linked?
113
	protected $mShowHeaders = SMW_HEADERS_SHOW; // should the headers (property names) be printed?
114
	protected $mShowErrors = true; // should errors possibly be printed?
115
	protected $mInline; // is this query result "inline" in some page (only then a link to unshown results is created, error handling may also be affected)
116
	protected $mLinker; // Linker object as needed for making result links. Might come from some skin at some time.
117
118
	/**
119
	 * List of errors that occurred while processing the parameters.
120
	 *
121
	 * @since 1.6
122
	 *
123
	 * @var array
124
	 */
125
	protected $mErrors = array();
126
127
	/**
128
	 * If set, treat result as plain HTML. Can be used by printer classes if wiki mark-up is not enough.
129
	 * This setting is used only after the result text was generated.
130
	 * @note HTML query results cannot be used as parameters for other templates or in any other way
131
	 * in combination with other wiki text. The result will be inserted on the page literally.
132
	 */
133
	protected $isHTML = false;
134
135
	/**
136
	 * If set, take the necessary steps to make sure that things like {{templatename| ...}} are properly
137
	 * processed if they occur in the result. Clearly, this is only relevant if the output is not HTML, i.e.
138
	 * it is ignored if SMWResultPrinter::$is_HTML is true. This setting is used only after the result
139
	 * text was generated.
140
	 * @note This requires extra processing and may make the result less useful for being used as a
141
	 * parameter for further parser functions. Use only if required.
142
	 */
143
	protected $hasTemplates = false;
144
	/// Incremented while expanding templates inserted during printout; stop expansion at some point
145
	private static $mRecursionDepth = 0;
146
	/// This public variable can be set to higher values to allow more recursion; do this at your own risk!
147
	/// This can be set in LocalSettings.php, but only after enableSemantics().
148
	public static $maxRecursionDepth = 2;
149
150
	/**
151
	 * Return serialised results in specified format.
152
	 * Implemented by subclasses.
153
	 */
154
	abstract protected function getResultText( SMWQueryResult $res, $outputMode );
155
156
	/**
157
	 * Constructor. The parameter $format is a format string
158
	 * that may influence the processing details.
159
	 *
160
	 * Do not override in deriving classes.
161
	 *
162
	 * @param string $format
163
	 * @param boolean $inline Optional since 1.9
164
	 * @param boolean $useValidator Deprecated since 1.6.2, removal in 1.10
165
	 */
166 140
	public function __construct( $format, $inline = true, $useValidator = false ) {
167 140
		global $smwgQDefaultLinking;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
168
169
		// Context aware since SMW 1.9
170
		//
171
		// If someone cleans the constructor, please add
172
		// IContextSource $context = null as for now we leave it
173
		// in order to keep compatibility with the original constructor
174 140
		$this->setContext( \RequestContext::getMain() );
175
176 140
		$this->mFormat = $format;
177 140
		$this->mInline = $inline;
178 140
		$this->mLinkFirst = ( $smwgQDefaultLinking != 'none' );
179 140
		$this->mLinkOthers = ( $smwgQDefaultLinking == 'all' );
180 140
		$this->mLinker = new Linker(); ///TODO: how can we get the default or user skin here (depending on context)?
181 140
	}
182
183
	/**
184
	 * @since 2.5
185
	 *
186
	 * @param integer $feature
187
	 *
188
	 * @return boolean
189
	 */
190
	public function isEnabledFeature( $feature ) {
0 ignored issues
show
Coding Style introduced by
isEnabledFeature uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
191
		return ( (int)$GLOBALS['smwgResultFormatsFeatures'] & $feature ) != 0;
192
	}
193
194
	/**
195 94
	 * @see SMWIResultPrinter::getResult
196 94
	 *
197 94
	 * @note: since 1.8 this method is final, since it's the entry point.
198
	 * Most logic has been moved out to buildResult, which you can override.
199 94
	 *
200
	 * @param $results SMWQueryResult
201
	 * @param $fullParams array
202
	 * @param $outputMode integer
203
	 *
204 94
	 * @return string
205 94
	 */
206
	public final function getResult( SMWQueryResult $results, array $fullParams, $outputMode ) {
0 ignored issues
show
Coding Style introduced by
As per PSR2, final should precede the visibility keyword.
Loading history...
207
		$this->outputMode = $outputMode;
208 94
		$this->results = $results;
209 94
210 94
		$params = array();
211
212 94
		/**
213 94
		 * @var \IParam $param
214
		 */
215 94
		foreach ( $fullParams as $param ) {
216
			$params[$param->getName()] = $param->getValue();
217
		}
218
219
		$this->params = $params;
220
		$this->m_params = $params; // Compat, change made in 1.6.3/1.7, removal in 1.10
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
221
		$this->fullParams = $fullParams;
222
223
		$this->postProcessParameters();
224
		$this->handleParameters( $this->params, $outputMode );
225
226
		return $this->buildResult( $results );
227 94
	}
228 94
229 94
	/**
230
	 * Build and return the HTML result.
231 94
	 *
232
	 * @since 1.8
233
	 *
234 94
	 * @param SMWQueryResult $results
235 25
	 *
236 17
	 * @return string
237 17
	 */
238 8
	protected function buildResult( SMWQueryResult $results ) {
239
		$this->isHTML = false;
240 8
		$this->hasTemplates = false;
241 1
242
		$outputMode = $this->outputMode;
243
244 7
		// Default output for normal printers:
245 7
		if ( $outputMode !== SMW_OUTPUT_FILE && $results->getCount() == 0 ) {
246
			if ( !$results->hasFurtherResults() ) {
247
				return $this->escapeText( $this->mDefault, $outputMode )
248
					. $this->getErrorString( $results );
249
			} elseif ( $this->mInline ) {
250 81
251
				if ( !$this->linkFurtherResults( $results ) ) {
252 81
					return '';
253 81
				}
254
255
				return $this->getFurtherResultsLink( $results, $outputMode )->getText( $outputMode, $this->mLinker )
256 81
					. $this->getErrorString( $results );
257
			}
258
		}
259
260
		// Get output from printer:
261
		$result = $this->getResultText( $results, $outputMode );
262
263
		if ( $outputMode !== SMW_OUTPUT_FILE ) {
264
			$result = $this->handleNonFileResult( $result, $results, $outputMode );
265
		}
266
267
		return $result;
268
	}
269
270 81
	/**
271
	 * Continuation of getResult that only gets executed for non file outputs.
272
	 *
273
	 * @since 1.6
274 81
	 *
275
	 * @param string $result
276 81
	 * @param SMWQueryResult $results
277
	 * @param integer $outputmode
278
	 *
279
	 * @return string
280
	 */
281 81
	protected function handleNonFileResult( $result, SMWQueryResult $results, $outputmode ) {
282 81
		/**
283 81
		 * @var \Parser $wgParser
284 81
		 */
285
		global $wgParser;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
286
287
		$result .= $this->getErrorString( $results ); // append errors
288
289 81
		// MW 1.21+
290 1
		// Block recursive import of annotations unless otherwise specified for
291 1
		// a specific use case
292
		if ( method_exists( $wgParser->getOutput(), 'setExtensionData' ) ) {
293
			$wgParser->getOutput()->setExtensionData(
294
				'smw-blockannotation',
295
				$this->params['format'] === 'embedded'
296
			);
297
		}
298 81
299 1
		// Apply intro parameter
300 1
		if ( ( $this->mIntro ) && ( $results->getCount() > 0 ) ) {
301
			if ( $outputmode == SMW_OUTPUT_HTML ) {
302
				$result = Message::get( array( 'smw-parse', $this->mIntro ), Message::PARSE ) . $result;
303
			} else {
304
				$result = $this->mIntro . $result;
305
			}
306
		}
307 81
308 13
		// Apply outro parameter
309 13
		if ( ( $this->mOutro ) && ( $results->getCount() > 0 ) ) {
310
			if ( $outputmode == SMW_OUTPUT_HTML ) {
311 13
				$result = $result . Message::get( array( 'smw-parse', $this->mOutro ), Message::PARSE );
312 13
			} else {
313
				$result = $result . $this->mOutro;
314 2
			}
315
		}
316
317 13
		// Preprocess embedded templates if needed
318
		if ( ( !$this->isHTML ) && ( $this->hasTemplates ) ) {
319
			if ( ( $wgParser->getTitle() instanceof Title ) && ( $wgParser->getOptions() instanceof ParserOptions ) ) {
0 ignored issues
show
Bug introduced by
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...
Bug introduced by
The class ParserOptions 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...
320
				self::$mRecursionDepth++;
321
322
				if ( self::$mRecursionDepth <= self::$maxRecursionDepth ) { // restrict recursion
323 81
					$result = isset( $this->params['import-annotation'] ) && $this->params['import-annotation'] ? $wgParser->recursivePreprocess( $result ) : '[[SMW::off]]' . $wgParser->replaceVariables( $result ) . '[[SMW::on]]';
324
				} else {
325 81
					$result = ''; /// TODO: explain problem (too much recursive parses)
326
				}
327
328
				self::$mRecursionDepth--;
329
			} else { // not during parsing, no preprocessing needed, still protect the result
330
				$result = isset( $this->params['import-annotation'] ) && $this->params['import-annotation'] ? $result : '[[SMW::off]]' . $result . '[[SMW::on]]';
331
			}
332
		}
333
334
		if ( ( $this->isHTML ) && ( $outputmode == SMW_OUTPUT_WIKI ) ) {
335
			$result = array( $result, 'isHTML' => true );
336
		} elseif ( ( !$this->isHTML ) && ( $outputmode == SMW_OUTPUT_HTML ) ) {
337
			self::$mRecursionDepth++;
338
339
			// check whether we are in an existing parse, or if we should start a new parse for $wgTitle
340
			if ( self::$mRecursionDepth <= self::$maxRecursionDepth ) { // retrict recursion
341
				if ( ( $wgParser->getTitle() instanceof Title ) && ( $wgParser->getOptions() instanceof ParserOptions ) ) {
0 ignored issues
show
Bug introduced by
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...
Bug introduced by
The class ParserOptions 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...
342
					$result = $wgParser->recursiveTagParse( $result );
343
				} else {
344
					global $wgTitle;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
345
346
					$popt = new ParserOptions();
347
					$popt->setEditSection( false );
348
					$pout = $wgParser->parse( $result . '__NOTOC__', $wgTitle, $popt );
349
350 81
					/// NOTE: as of MW 1.14SVN, there is apparently no better way to hide the TOC
351 81
					\SMWOutputs::requireFromParserOutput( $pout );
352 81
					$result = $pout->getText();
353 81
				}
354
			} else {
355
				$result = ''; /// TODO: explain problem (too much recursive parses)
356
			}
357 81
358
			self::$mRecursionDepth--;
359
		}
360
361
		if ( method_exists( $wgParser->getOutput(), 'setExtensionData' ) ) {
362
			$wgParser->getOutput()->setExtensionData(
363
				'smw-blockannotation',
364
				false
365
			);
366
		}
367
368
		return $result;
369
	}
370
371
	/**
372
	 * Does any additional parameter handling that needs to be done before the
373
	 * actual result is build. This includes cleaning up parameter values
374 94
	 * and setting class fields.
375
	 *
376 94
	 * Since 1.6 parameter handling should happen via validator based on the parameter
377
	 * definitions returned in getParameters. Therefore this method should likely
378
	 * not be used in any new code. It's mainly here for legacy reasons.
379
	 *
380
	 * @since 1.6
381
	 *
382
	 * @param array $params
383 94
	 * @param $outputMode
384 94
	 */
385
	protected function handleParameters( array $params, $outputMode ) {
386 94
		// No-op
387 94
	}
388
389 94
	/**
390
	 * Similar to handleParameters.
391 94
	 *
392 94
	 * @since 1.8
393 2
	 */
394 2
	protected function postProcessParameters() {
395 2
		$params = $this->params;
396 94
397 66
		$this->mIntro = str_replace( '_', ' ', $params['intro'] );
398 66
		$this->mOutro = str_replace( '_', ' ', $params['outro'] );
399 66
400 39
		$this->mSearchlabel = $params['searchlabel'] === false ? null : $params['searchlabel'];
401 39
402 39
		switch ( $params['link'] ) {
403 39
			case 'head': case 'subject':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
404
				$this->mLinkFirst = true;
405
				$this->mLinkOthers = false;
406 94
				break;
407
			case 'all':
408 94
				$this->mLinkFirst = true;
409 2
				$this->mLinkOthers = true;
410 94
				break;
411 10
			case 'none':
412
				$this->mLinkFirst = false;
413 88
				$this->mLinkOthers = false;
414
				break;
415 94
		}
416
417
		 $this->mDefault = str_replace( '_', ' ', $params['default'] );
418
419
		if ( $params['headers'] == 'hide' ) {
420
			$this->mShowHeaders = SMW_HEADERS_HIDE;
421
		} elseif ( $params['headers'] == 'plain' ) {
422
			$this->mShowHeaders = SMW_HEADERS_PLAIN;
423 79
		} else {
424 79
			$this->mShowHeaders = SMW_HEADERS_SHOW;
425 54
		}
426
	}
427 36
428
	/**
429
	 * Depending on current linking settings, returns a linker object
430
	 * for making hyperlinks or NULL if no links should be created.
431
	 *
432
	 * @param boolean $firstcol True of this is the first result column (having special linkage settings).
433
	 */
434
	protected function getLinker( $firstcol = false ) {
435
		if ( ( $firstcol && $this->mLinkFirst ) || ( !$firstcol && $this->mLinkOthers ) ) {
436
			return $this->mLinker;
437
		} else {
438
			return null;
439
		}
440
	}
441
442 11
	/**
443 11
	 * Gets a SMWInfolink object that allows linking to a display of the query result.
444
	 *
445 11
	 * @since 1.8
446 11
	 *
447
	 * @param SMWQueryResult $res
448
	 * @param $outputMode
449 11
	 * @param string $classAffix
450
	 *
451
	 * @return SMWInfolink
452
	 */
453
	protected function getLink( SMWQueryResult $res, $outputMode, $classAffix = '' ) {
454 11
		$link = $res->getQueryLink( $this->getSearchLabel( $outputMode ) );
0 ignored issues
show
Deprecated Code introduced by
The method SMWQueryResult::getQueryLink() has been deprecated with message: since SMW 1.8

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
455 11
456 11
		if ( $classAffix !== '' ){
457
			$link->setStyle(  'smw-' . $this->params['format'] . '-' . Sanitizer::escapeClass( $classAffix ) );
458
		}
459
460 11
		$link->setParameter( $this->params['format'], 'format' );
461
462
		/**
463
		 * @var \IParam $param
464
		 */
465
		foreach ( $this->fullParams as $param ) {
466
			if ( !$param->wasSetToDefault() && !( $param->getName() == 'limit' && $param->getValue() === 0 ) ) {
467
				$link->setParameter( $param->getOriginalValue(), $param->getName() );
468
			}
469
		}
470
471
		return $link;
472
	}
473 11
474 11
	/**
475 11
	 * Gets a SMWInfolink object that allows linking to further results for the query.
476 11
	 *
477
	 * @since 1.8
478
	 *
479
	 * @param SMWQueryResult $res
480
	 * @param $outputMode
481
	 *
482
	 * @return SMWInfolink
483
	 */
484
	protected function getFurtherResultsLink( SMWQueryResult $res, $outputMode ) {
485
		$link = $this->getLink( $res, $outputMode, 'furtherresults' );
486 106
		$link->setParameter( $this->params['offset'] + $res->getCount(), 'offset' );
487
		return $link;
488
	}
489 106
490
	/**
491
	 * @see SMWIResultPrinter::getQueryMode
492
	 *
493
	 * @param $context
494
	 *
495
	 * @return integer
496
	 */
497
	public function getQueryMode( $context ) {
498
		// TODO: Now that we are using RequestContext object maybe
499
		// $context is misleading
500
		return SMWQuery::MODE_INSTANCES;
501
	}
502
503
	/**
504
	 * @see SMWIResultPrinter::getName
505
	 *
506
	 * @return string
507
	 */
508
	public function getName() {
509
		return $this->mFormat;
510 93
	}
511 93
512
	/**
513
	 * Provides a simple formatted string of all the error messages that occurred.
514
	 * Can be used if not specific error formatting is desired. Compatible with HTML
515
	 * and Wiki.
516
	 *
517
	 * @param SMWQueryResult $res
518
	 *
519 4
	 * @return string
520 4
	 */
521 4
	protected function getErrorString( SMWQueryResult $res ) {
522
		return $this->mShowErrors ? smwfEncodeMessages( array_merge( $this->mErrors, $res->getErrors() ) ) : '';
523
	}
524
525
	/**
526
	 * @see SMWIResultPrinter::setShowErrors
527
	 *
528
	 * @param boolean $show
529
	 */
530
	public function setShowErrors( $show ) {
531
		$this->mShowErrors = $show;
532 28
	}
533 28
534
	/**
535
	 * If $outputmode is SMW_OUTPUT_HTML, escape special characters occuring in the
536
	 * given text. Otherwise return text as is.
537
	 *
538
	 * @param string $text
539
	 * @param $outputmode
540
	 *
541
	 * @return string
542
	 */
543
	protected function escapeText( $text, $outputmode ) {
544 11
		return $outputmode == SMW_OUTPUT_HTML ? htmlspecialchars( $text ) : $text;
545 11
	}
546
547
	/**
548
	 * Get the string the user specified as a text for the "further results" link,
549
	 * properly escaped for the current output mode.
550
	 *
551
	 * @param $outputmode
552
	 *
553
	 * @return string
554
	 */
555
	protected function getSearchLabel( $outputmode ) {
556
		return $this->escapeText( $this->mSearchlabel, $outputmode );
557 85
	}
558 85
559
	/**
560
	 * Check whether a "further results" link would normally be generated for this
561
	 * result set with the given parameters. Individual result printers may decide to
562
	 * create or hide such a link independent of that, but this is the default.
563
	 *
564
	 * @param SMWQueryResult $results
565
	 *
566
	 * @return boolean
567
	 */
568
	protected function linkFurtherResults( SMWQueryResult $results ) {
569
		return $this->mInline && $results->hasFurtherResults() && $this->mSearchlabel !== '';
570
	}
571
572
	/**
573
	 * Adds an error message for a parameter handling error so a list
574
	 * of errors can be created later on.
575
	 *
576
	 * @since 1.6
577
	 *
578
	 * @param string $errorMessage
579
	 */
580
	protected function addError( $errorMessage ) {
581
		$this->mErrors[] = $errorMessage;
582
	}
583
584
	/**
585
	 * Return an array describing the parameters of specifically text-based
586
	 * formats, like 'list' and 'table', for use in their getParameters()
587
	 * functions
588
	 *
589
	 * @deprecated since 1.8, removal in 1.10
590
	 *
591
	 * @since 1.5.0
592
	 *
593
	 * @return array
594
	 */
595
	protected function textDisplayParameters() {
596
		return array();
597
	}
598
599
	/**
600
	 * Return an array describing the parameters of the export formats
601
	 * like 'rss' and 'csv', for use in their getParameters() functions
602
	 *
603
	 * @deprecated since 1.8, removal in 1.10
604
	 *
605
	 * @since 1.5.0
606
	 *
607
	 * @return array
608
	 */
609
	protected function exportFormatParameters() {
610
		return array();
611
	}
612
613
	/**
614
	 * A function to describe the allowed parameters of a query using
615
	 * any specific format - most query printers should override this
616
	 * function.
617
	 *
618
	 * @deprecated since 1.8, use getParamDefinitions instead.
619
	 *
620
	 * @since 1.5
621
	 *
622
	 * @return array
623
	 */
624
	public function getParameters() {
625
		return array();
626 125
	}
627 125
628
	/**
629
	 * @see SMWIResultPrinter::getParamDefinitions
630
	 *
631
	 * @since 1.8
632
	 *
633
	 * @param ParamDefinition[] $definitions
634
	 *
635
	 * @return array
636
	 */
637
	public function getParamDefinitions( array $definitions ) {
638
		return array_merge( $definitions, $this->getParameters() );
0 ignored issues
show
Deprecated Code introduced by
The method SMW\ResultPrinter::getParameters() has been deprecated with message: since 1.8, use getParamDefinitions instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
639
	}
640
641
	/**
642
	 * Returns the parameter definitions as an associative array where
643
	 * the keys hold the parameter names and point to their full definitions.
644
	 * array( name => array|IParamDefinition )
645
	 *
646
	 * @since 1.8
647
	 *
648
	 * @param array $definitions List of definitions to prepend to the result printers list before further processing.
649
	 *
650
	 * @return array
651
	 */
652
	public final function getNamedParameters( array $definitions = array() ) {
0 ignored issues
show
Coding Style introduced by
As per PSR2, final should precede the visibility keyword.
Loading history...
653
		$params = array();
654
655
		foreach ( $this->getParamDefinitions( $definitions ) as $param ) {
656
			$params[is_array( $param ) ? $param['name'] : $param->getName()] = $param;
657
		}
658 4
659 4
		return $params;
660
	}
661
662
	/**
663
	 * @see SMWIResultPrinter::isExportFormat
664
	 *
665
	 * @since 1.8
666
	 *
667 106
	 * @return boolean
668 106
	 */
669
	public function isExportFormat() {
670
		return false;
671
	}
672
673
	/**
674
	 * @since 2.5
675
	 *
676
	 * @return string
677
	 */
678
	public function getDefaultSort() {
679
		return 'ASC';
680
	}
681
682
}
683