-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optionally load headers and footers asynchronously (#18)
- Loading branch information
1 parent
95c5a5c
commit 314dc59
Showing
5 changed files
with
204 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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->dieUsage( "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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
{ | ||
"headerfooter-desc": "Enables per-page/per-namespace headers and footers" | ||
"headerfooter-desc": "Enables per-page/per-namespace headers and footers", | ||
"apihelp-getheaderfooter-description": "Retrieve the parsed output of a header or footer in the context of a certain page.", | ||
"apihelp-getheaderfooter-summary": "Retrieve the parsed output of a header or footer in the context of a certain page.", | ||
"apihelp-getheaderfooter-param-contexttitle": "The title of the page that the header or footer is being added to.", | ||
"apihelp-getheaderfooter-param-messageid": "Which header or footer is being requested (e.g. a namespace header)", | ||
"apihelp-getheaderfooter-example-1": "Get the NS_MAIN footer for Main Page" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
var egHeaderFooter = mw.config.get( 'egHeaderFooter' ); | ||
|
||
if ( egHeaderFooter.enableAsyncHeader ) { | ||
var extHeaderFooterBlocks = [ "hf-nsheader", "hf-header" ]; | ||
} | ||
else { | ||
var extHeaderFooterBlocks = []; | ||
} | ||
extHeaderFooterBlocks = extHeaderFooterBlocks.concat( [ "hf-footer", "hf-nsfooter" ] ); | ||
|
||
for ( var i = 0; i < extHeaderFooterBlocks.length; i++ ) { | ||
var block = extHeaderFooterBlocks[i]; | ||
|
||
$( "." + block ).each( function( i, e ) { | ||
|
||
// FIXME: At some point, put some method of indicating unloaded content here | ||
|
||
// FIXME: At some point, add method to further delay loading of dynamic | ||
// footers. Headers should be loaded right away, but footers should | ||
// only be loaded if the user can see them (or is scrolling toward | ||
// them). | ||
|
||
// Message ID of block (header or footer) is in the HTML ID. hf-nsheader | ||
// will have an ID like hf-nsheader-Help for the help namespace. | ||
var msgId = $(e).attr('id'); | ||
|
||
$.get( | ||
mw.config.get("wgScriptPath") + "/api.php", | ||
{ | ||
action: "getheaderfooter", | ||
messageid: msgId, | ||
contexttitle: mw.config.get('wgPageName'), | ||
format: "json" | ||
}, | ||
function ( response ) { | ||
// var blockText = response.query.allmessages[0]["*"]; | ||
var blockText = response.getheaderfooter.result; | ||
$( "#" + msgId ).html( blockText ); | ||
$( "#" + msgId ).find( "#headertabs" ).each( function(i,e) { | ||
$(e).tabs(); | ||
}); | ||
} | ||
) | ||
|
||
} ); | ||
|
||
} |