Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
PFDefaultForm | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
30 | |
0.00% |
0 / 1 |
run | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | |
3 | /** |
4 | * '#default_form' is called as: |
5 | * {{#default_form:formName}} |
6 | * |
7 | * This function sets the specified form to be the default form for pages |
8 | * in that category, namespace or page. If called without an argument, |
9 | * it specifies that the relevant page(s) should have no form. |
10 | */ |
11 | |
12 | class PFDefaultForm { |
13 | public static function run( Parser $parser ) { |
14 | $curTitle = $parser->getTitle(); |
15 | |
16 | $params = func_get_args(); |
17 | if ( !isset( $params[1] ) ) { |
18 | return true; |
19 | } |
20 | $defaultForm = $params[1]; |
21 | |
22 | $parserOutput = $parser->getOutput(); |
23 | if ( method_exists( $parserOutput, 'setPageProperty' ) ) { |
24 | // MW 1.38+ |
25 | $parserOutput->setPageProperty( 'PFDefaultForm', $defaultForm ); |
26 | } else { |
27 | $parserOutput->setProperty( 'PFDefaultForm', $defaultForm ); |
28 | } |
29 | |
30 | // Display information on the page, if this is a category. |
31 | if ( $curTitle->getNamespace() == NS_CATEGORY ) { |
32 | $defaultFormPage = Title::makeTitleSafe( PF_NS_FORM, $defaultForm ); |
33 | if ( $defaultFormPage == null ) { |
34 | return '<div class="error">Error: No form found with name "' . $defaultForm . '".</div>'; |
35 | } |
36 | $defaultFormPageText = $defaultFormPage->getPrefixedText(); |
37 | $defaultFormPageLink = "[[$defaultFormPageText|$defaultForm]]"; |
38 | $text = wfMessage( 'pf_category_hasdefaultform', $defaultFormPageLink )->text(); |
39 | return $text; |
40 | } |
41 | |
42 | // It's not a category - display nothing. |
43 | } |
44 | } |