Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| PFDefaultForm | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 1 |
| run | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
20 | |||
| 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 | use MediaWiki\Title\Title; |
| 13 | |
| 14 | class PFDefaultForm { |
| 15 | public static function run( Parser $parser ) { |
| 16 | $curTitle = $parser->getTitle(); |
| 17 | |
| 18 | $params = func_get_args(); |
| 19 | if ( !isset( $params[1] ) ) { |
| 20 | return true; |
| 21 | } |
| 22 | $defaultForm = $params[1]; |
| 23 | |
| 24 | $parser->getOutput()->setPageProperty( 'PFDefaultForm', $defaultForm ); |
| 25 | |
| 26 | // Display information on the page, if this is a category. |
| 27 | if ( $curTitle->getNamespace() == NS_CATEGORY ) { |
| 28 | $defaultFormPage = Title::makeTitleSafe( PF_NS_FORM, $defaultForm ); |
| 29 | if ( $defaultFormPage == null ) { |
| 30 | return '<div class="error">Error: No form found with name "' . $defaultForm . '".</div>'; |
| 31 | } |
| 32 | $defaultFormPageText = $defaultFormPage->getPrefixedText(); |
| 33 | $defaultFormPageLink = "[[$defaultFormPageText|$defaultForm]]"; |
| 34 | $text = wfMessage( 'pf_category_hasdefaultform', $defaultFormPageLink )->text(); |
| 35 | return $text; |
| 36 | } |
| 37 | |
| 38 | // It's not a category - display nothing. |
| 39 | } |
| 40 | } |