Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
PFWikiPageTemplate | |
0.00% |
0 / 20 |
|
0.00% |
0 / 6 |
156 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
addParam | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
addUnhandledParam | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
20 | |||
addUnhandledParams | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
20 | |||
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getParams | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * @author Yaron Koren |
4 | * @file |
5 | * @ingroup PF |
6 | */ |
7 | |
8 | /** |
9 | * Represents a single template call within a wiki page. |
10 | */ |
11 | class PFWikiPageTemplate { |
12 | private $mName; |
13 | private $mParams = []; |
14 | private $mAddUnhandledParams; |
15 | |
16 | function __construct( $name, $addUnhandledParams ) { |
17 | $this->mName = $name; |
18 | $this->mAddUnhandledParams = $addUnhandledParams; |
19 | } |
20 | |
21 | function addParam( $paramName, $value ) { |
22 | $this->mParams[] = new PFWikiPageTemplateParam( $paramName, $value ); |
23 | } |
24 | |
25 | function addUnhandledParam( $paramName, $value ) { |
26 | // See if there's already a value for this parameter, and |
27 | // if it's blank, replace it. |
28 | // This only happens if values are coming in from both the |
29 | // page and the form submission, i.e. for #autoedit. |
30 | foreach ( $this->mParams as $i => $param ) { |
31 | if ( $param->getName() == $paramName ) { |
32 | if ( $param->getValue() == '' ) { |
33 | $this->mParams[$i]->setValue( $value ); |
34 | } |
35 | return; |
36 | } |
37 | } |
38 | |
39 | // All other cases, probably. |
40 | $this->addParam( $paramName, $value ); |
41 | } |
42 | |
43 | function addUnhandledParams() { |
44 | global $wgRequest; |
45 | |
46 | if ( !$this->mAddUnhandledParams ) { |
47 | return; |
48 | } |
49 | |
50 | $templateName = str_replace( ' ', '_', $this->mName ); |
51 | $prefix = '_unhandled_' . $templateName . '_'; |
52 | $prefixSize = strlen( $prefix ); |
53 | foreach ( $wgRequest->getValues() as $key => $value ) { |
54 | if ( strpos( $key, $prefix ) === 0 ) { |
55 | $paramName = urldecode( substr( $key, $prefixSize ) ); |
56 | $this->addUnhandledParam( $paramName, $value ); |
57 | } |
58 | } |
59 | } |
60 | |
61 | function getName() { |
62 | return $this->mName; |
63 | } |
64 | |
65 | function getParams() { |
66 | return $this->mParams; |
67 | } |
68 | } |