Difference between revisions of "MediaWiki/archive/embedding/1.14/extract.php"

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
Jump to navigation Jump to search
m (Woozle moved page MediaWiki/embedding/1.14/extract.php to MediaWiki/archive/embedding/1.14/extract.php without leaving a redirect: obsolete, keeps changing)
 
(3 intermediate revisions by 2 users not shown)
(No difference)

Latest revision as of 00:08, 15 December 2017

To Do

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

Code

<php><?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);

  1. getrusage() does not exist on the Microsoft Windows platforms, catching this

if ( function_exists ( 'getrusage' ) ) { $wgRUstart = getrusage(); } else { $wgRUstart = array(); }

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( '<a'.' '.'href="http://www.hardened-php.net/index.76.html">$GLOBALS overwrite vulnerability</a>'); }

  1. Load up some global defines.
  2. 2006-10-15 Wzl: kfpMediaWiki must be defined before this line (externally is probably best)

require_once( kfpMediaWiki.'includes/Defines.php' );

  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 ./

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. Include this site's settings, so we can access the wiki db:

$isExtract = true;

//chdir(KFP_WIKI); chdir(kfpMediaWiki);

  1. Initialise common code

require_once( 'includes/WebStart.php' );

  1. Initialize MediaWiki base class

require_once( 'includes/Wiki.php' );

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' );

  1. Setting global variables in mediaWiki

$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 );

// 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 );

  1. Not sure when $wgPostCommitUpdateList gets set, so I keep this separate from finalCleanup

// $mediaWiki->doUpdates( $wgPostCommitUpdateList ); // $mediaWiki->restInPeace( $wgLoadBalancer ); }</php>