问题描述:

Problem

I would like to examine the http headers from within a media wiki extension. Specifically if one of the headers exists, I will take an action.

Background

I am a newbie to php and mediawiki. I am working on my second extension in mediawiki. I want to take a specific action if a particular http header is part of the page request. I am now confident that the hook is being called at the correct time, but unfortunately I cannot seem to get hold of the http headers.

$extensionObject = new MyExtension;

$wgHooks['ArticlePageDataBefore'][] = array($extensionObject, 'onArticlePageDataBefore');

class MyExtension{

public function onArticlePageDataBefore( &$article, &$fields ) {

$headers =mygetallheaders();

...do something with the headers

return true;

}

public function mygetallheaders() {

...this is the function I am trying to write

return $headers;

}

Software stack

  • MediaWiki: 1.20.2
  • PHP: 5.3.3 (apache2handler)
  • MySQL: 5.1.61

Tried so far.

The following two methods both return an empty array

  • apache_request_headers
  • getallheaders

The $_SERVER variable is empty

Thanks for any help

网友答案:
public function onArticlePageDataBefore( &$article, &$fields ) {
    global $wgRequest;
    if ( $wgRequest->getHeader( 'My-Cool-Header' ) == 42 {
            PROFIT!
    }
    return true;
}
相关阅读:
Top