[Mediawiki-l] Including MW via a function call

Andrew Fabian afabian at anjero.com
Wed Aug 1 02:28:39 UTC 2007

Hey all,

I'm trying to use MediaWiki in a pretty non-standard way, and I'm hoping 
someone can give me a definitely answer about what works / wont work:

The site is a collection of a few different open-source document, chat, 
and database tools.  As such, it has it's own PHP code that drives the 
site, and includes MediaWiki and other systems to generate parts of 
pages where required.

As a simple example, I'm trying to do something like this:

function renderWiki($title)
    $_R = $_REQUEST; $_G = $_GET; $_P = $_POST;
    $_REQUEST = array(); $_POST = array();

    $_GET = array( 'action' => 'render', 'title' => $title );


    require('index.php'); // run MediaWiki here
    $output = ob_get_contents();

    $_REQUEST = $_R; $_GET = $_G; $_POST = $_P;



The first result I get is something like this:

require(/includes/WebRequest.php) [function.require 
<http://drmvt.anjero.com/function.require>]: failed to open stream: No 
such file or directory in 
*/storage/websites/test/docs/includes/AutoLoader.php* on line *362

*I played around a bit, and found out that by making $IP global, either 
in my function or in LocalSettings, I'd get a bit further, but then hit 
this error:

*Fatal error*: Call to a member function incr() on a non-object in 
*/storage/websites/drmvt/docs/includes/GlobalFunctions.php* on line *1679

*My hypothesis is that MediaWiki relies on many variables being in the 
global scope, due to their being defined outside of any MW functions 
(for example, anything defined by LocalSettings).  Since I'm running MW 
from inside my own function, variables not explicitly defined as global 
inherit my function's variable scope.  Thus later references to those 
same variables, in subroutines where they are explicitly made global, 
actually reference a different (and empty) variable scope.

1) Does this theory sound correct?

2) Assuming I need to use functions in my site's framework, what's the 
best way to make this work?



More information about the MediaWiki-l mailing list