MediaWiki/embedding/1.14/extract.php

To Do

 * Does not properly replace internal links with full URLs to main site

Code
<?php /* SOURCE: Adapted from MediaWiki's index.php HISTORY: 2009-06-06 Now works with MediaWiki 1.14 2009-06-07 Fixed one or two warning messages $wgRequestTime = microtime(true);

if ( function_exists ( 'getrusage' ) ) { $wgRUstart = getrusage; } else { $wgRUstart = array; }
 * 1) getrusage does not exist on the Microsoft Windows platforms, catching this

unset( $IP ); @ini_set( 'allow_url_fopen', 0 ); # For security...

if ( isset( $_REQUEST['GLOBALS'] ) ) { // breaking up the string is just to get past the spam filter at htyp die( '$GLOBALS overwrite vulnerability'); }

require_once( kfpMediaWiki.'includes/Defines.php' );
 * 1) Load up some global defines.
 * 2) 2006-10-15 Wzl: kfpMediaWiki must be defined before this line (externally is probably best)

if( !file_exists( kfpMediaWiki.'LocalSettings.php' ) ) { echo "Can't access LocalSettings.php"; } global $wgNoOutputBuffer; $wgNoOutputBuffer = true;	# prevents partial compression of output, which confuses everything
 * 1) LocalSettings.php is the per site customization file. If it does not exit
 * 2) the wiki installer need to be launched or the generated file moved from
 * 3) ./config/ to ./

$isExtract = true;
 * 1) Include this site's settings, so we can access the wiki db:

//chdir(KFP_WIKI); chdir(kfpMediaWiki); require_once( 'includes/WebStart.php' ); require_once( 'includes/Wiki.php' );
 * 1) Initialise common code
 * 1) Initialize MediaWiki base class

function GetWikiPage($iTitle) { global $wgArticle,$wgTitle,$wgOut,$wgUser,$wgRequest,$wgContLang;

$mediaWiki = new MediaWiki;

wfProfileIn( 'main-misc-setup' ); OutputPage::setEncodings; # Not really used yet

$title = kEmbeddedPagePrefix.$iTitle; $wgTitle = Title::newFromURL( $title ); //	$wgTitle = $mediaWiki->checkInitialQueries( $title,'render',$wgOut, $wgRequest, $wgContLang );

if (is_null($wgTitle)) { $hasPage = FALSE; } else { $hasPage = ($wgTitle->getArticleID != 0); }	if ($hasPage) { wfProfileOut( 'main-misc-setup' );

$action = 'render';	// this is just local, but sets global below $mediaWiki->setVal( 'Server', $wgServer ); $mediaWiki->setVal( 'DisableInternalSearch', $wgDisableInternalSearch ); $mediaWiki->setVal( 'action', $action ); $mediaWiki->setVal( 'SquidMaxage', $wgSquidMaxage ); $mediaWiki->setVal( 'EnableDublinCoreRdf', $wgEnableDublinCoreRdf ); $mediaWiki->setVal( 'EnableCreativeCommonsRdf', $wgEnableCreativeCommonsRdf ); $mediaWiki->setVal( 'CommandLineMode', $wgCommandLineMode ); $mediaWiki->setVal( 'UseExternalEditor', $wgUseExternalEditor ); $mediaWiki->setVal( 'DisabledActions', $wgDisabledActions );
 * 1) Setting global variables in mediaWiki

// NOTE: This call *creates* $wgArticle $wgArticle = $mediaWiki->initialize ( $wgTitle, $wgArticle, $wgOut, $wgUser, $wgRequest ); //		$wgArticle->render;	// redundant; gets called somewhere based on $action, but not sure where $txtWiki = $wgOut->getHTML; $wgOut->clearHTML;

// strip unnecessary stuff from wiki text: if (strpos($txtWiki,' ') == 0) { $txtWiki = substr($txtWiki,3); } else { //			$txtWiki .= 'POS='.strpos($txtWiki,' '); }		if (strrpos($txtWiki,' ') == strlen($txtWiki)-4) { $txtWiki = substr($txtWiki,0,-3); }	// replace local links with absolute links to wiki base if (defined('KW_WIKI_ROOT')) { $txtWiki = str_replace('href="/','href="'.KW_WIKI_ROOT,$txtWiki); }		return $txtWiki; } else { // no wiki page found unset( $wgTitle ); echo 'Could not find page for URL ['.$iTitle.']'; return NULL; } // 2007-07-15 copied from MW 1.10.1 index.php //	$mediaWiki->finalCleanup ( $wgDeferredUpdateList, $wgLoadBalancer, $wgOut );

//	$mediaWiki->doUpdates( $wgPostCommitUpdateList ); //	$mediaWiki->restInPeace( $wgLoadBalancer ); }
 * 1) Not sure when $wgPostCommitUpdateList gets set, so I keep this separate from finalCleanup