-
Notifications
You must be signed in to change notification settings - Fork 18
/
ApiGetHeaderFooter.php
79 lines (62 loc) · 1.6 KB
/
ApiGetHeaderFooter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* API module for MediaWiki's HeaderFooter extension.
*
* @author James Montalvo
* @since Version 3.0
*/
/**
* API module to review revisions
*/
class ApiGetHeaderFooter extends ApiBase {
public function execute() {
$params = $this->extractRequestParams();
$contextTitle = Title::newFromDBkey( $params['contexttitle'] );
if ( ! $contextTitle ) {
$this->dieWithError( "Not a valid contexttitle.", 'notarget' );
}
$messageId = $params['messageid'];
$messageText = wfMessage( $messageId )->title( $contextTitle )->text();
// don't need to bother if there is no content.
if ( empty( $messageText ) ) {
$messageText = '';
}
if ( wfMessage( $messageId )->inContentLanguage()->isBlank() ) {
$messageText = '';
}
global $wgParser;
$messageText = $wgParser->parse(
$messageText,
$contextTitle,
ParserOptions::newFromUser( $this->getUser() )
)->getText();
$this->getResult()->addValue( null, $this->getModuleName(), array( 'result' => $messageText ) );
}
public function getAllowedParams() {
return array(
'contexttitle' => array(
ApiBase::PARAM_REQUIRED => true,
ApiBase::PARAM_TYPE => 'string'
),
'messageid' => array(
ApiBase::PARAM_REQUIRED => true,
ApiBase::PARAM_TYPE => 'string'
)
);
}
/**
* @see ApiBase::getExamplesMessages()
*/
protected function getExamplesMessages() {
return array(
'action=getheaderfooter&contexttitle=Main_Page&messageid=Hf-nsfooter-'
=> 'apihelp-getheaderfooter-example-1',
);
}
public function mustBePosted() {
return false;
}
public function isWriteMode() {
return false;
}
}