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

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 (→‎Notes: link to examples page)
(current version of extract.php -- apparently completely rewritten)
Line 2: Line 2:
 
[[computing]]: [[software]]: [[MediaWiki]]: [[embedding MediaWiki content in external pages|embedding content]]: [[extract.php for embedding MediaWiki contents|extract.php]]
 
[[computing]]: [[software]]: [[MediaWiki]]: [[embedding MediaWiki content in external pages|embedding content]]: [[extract.php for embedding MediaWiki contents|extract.php]]
 
==Notes==
 
==Notes==
The following contents are based on index.php from MediaWiki 1.7.1. Some code may be redundant, but I was trying to make the fewest possible changes in order to avoid breaking anything. I got it to work but have not tested it much or used it in working code (yet). --[[User:Woozle|Woozle]] 18:38, 15 October 2006 (EDT)
+
The following contents are based on index.php from MediaWiki (I'm not sure which version, but probably later than 1.7.1). Some code may be redundant, but I was trying to make the fewest possible changes in order to avoid breaking anything. It's currently in use as the front page for [http://outside-life.com Outside Life], a [[webcomic]].
  
* [[/examples]]
+
* [[/examples]] - also from Outside Life
  
 
==Contents==
 
==Contents==
 
<php>
 
<php>
<?php
+
<?php
/**
+
/*
  * Main wiki script; see docs/design.txt
+
This is essentially index.php with some minor tweaks
  * @package MediaWiki
+
TWEAKS:
  */
+
these lines commented out:
$wgRequestTime = microtime(true);
+
$action = $wgRequest->getVal( 'action', 'view' );
+
$title = $wgRequest->getVal( 'title' );
# getrusage() does not exist on the Microsoft Windows platforms, catching this
+
this line commented out
if ( function_exists ( 'getrusage' ) ) {
+
$wgTitle = $mediaWiki->checkInitialQueries( $title,$action,$wgOut, $wgRequest, $wgContLang );
$wgRUstart = getrusage();
+
this line inserted immediately after:
} else {
+
$wgTitle = Title::newFromURL( $title );
$wgRUstart = array();
+
*/
}
+
# Initialise common code
+
require_once( './includes/WebStart.php' );
unset( $IP );
+
 
@ini_set( 'allow_url_fopen', 0 ); # For security...
+
# Initialize MediaWiki base class
+
require_once( "includes/Wiki.php" );
if ( isset( $_REQUEST['GLOBALS'] ) ) {
+
$mediaWiki = new MediaWiki();
die( '<a '.'href="http://www.hardened-php.net/index.76.html">$GLOBALS overwrite vulnerability</a>');
+
 
}
+
wfProfileIn( 'main-misc-setup' );
+
OutputPage::setEncodings(); # Not really used yet
# Valid web server entry point, enable includes.
+
 
# Please don't move this line to includes/Defines.php. This line essentially
+
$maxLag = $wgRequest->getVal( 'maxlag' );
# defines a valid entry point. If you put it in includes/Defines.php, then
+
if ( !is_null( $maxLag ) ) {
# any script that includes it becomes an entry point, thereby defeating
+
if ( !$mediaWiki->checkMaxLag( $maxLag ) ) {
# its purpose.
+
exit;
define( 'MEDIAWIKI', true );
+
}
+
}
# Load up some global defines.
+
 
# >> 2006-10-15 Wzl: kPathToMediaWiki must be defined before this line << (externally is probably best)
+
# Query string fields
require_once( kPathToMediaWiki.'includes/Defines.php' );
+
//$action = $wgRequest->getVal( 'action', 'view' );
+
//$title = $wgRequest->getVal( 'title' );
# LocalSettings.php is the per site customization file. If it does not exit
+
 
# the wiki installer need to be launched or the generated file moved from
+
//$wgTitle = $mediaWiki->checkInitialQueries( $title,$action,$wgOut, $wgRequest, $wgContLang );
# ./config/ to ./
+
$wgTitle = Title::newFromURL( $title );
if( !file_exists( kPathToMediaWiki.'LocalSettings.php' ) ) {
+
if ($wgTitle == NULL) {
    echo "Can't access LocalSettings.php";
+
unset( $wgTitle );
}
+
}
+
 
# Include this site setttings
+
#
require_once( kPathToMediaWiki.'LocalSettings.php' );
+
# Send Ajax requests to the Ajax dispatcher.
# Prepare MediaWiki
+
#
require_once( kPathToMediaWiki.'includes/Setup.php' );
+
/*
+
if ( $wgUseAjax && $action == 'ajax' ) {
# Initialize MediaWiki base class
+
require_once( $IP . '/includes/AjaxDispatcher.php' );
require_once( kPathToMediaWiki."includes/Wiki.php" );
+
 
$mediaWiki = new MediaWiki();
+
$dispatcher = new AjaxDispatcher();
+
$dispatcher->performAction();
wfProfileIn( 'main-misc-setup' );
+
$mediaWiki->restInPeace( $wgLoadBalancer );
OutputPage::setEncodings(); # Not really used yet
+
exit;
+
}
+
*/
$title = kEmbeddedPagePrefix.$page;
+
 
$action = 'render'; // (2006-10-15 Wzl) this may be redundant; check.
+
wfProfileOut( 'main-misc-setup' );
//$wgTitle = $mediaWiki->checkInitialQueries( $title,$action,$wgOut, $wgRequest, $wgContLang );
+
 
$wgTitle = Title::newFromURL( $title );
+
# Setting global variables in mediaWiki
if ($wgTitle == NULL) {
+
$mediaWiki->setVal( 'Server', $wgServer );
unset( $wgTitle );
+
$mediaWiki->setVal( 'DisableInternalSearch', $wgDisableInternalSearch );
}
+
$mediaWiki->setVal( 'action', $action );
wfProfileOut( 'main-misc-setup' );
+
$mediaWiki->setVal( 'SquidMaxage', $wgSquidMaxage );
+
$mediaWiki->setVal( 'EnableDublinCoreRdf', $wgEnableDublinCoreRdf );
# Setting global variables in mediaWiki
+
$mediaWiki->setVal( 'EnableCreativeCommonsRdf', $wgEnableCreativeCommonsRdf );
$mediaWiki->setVal( 'Server', $wgServer );
+
$mediaWiki->setVal( 'CommandLineMode', $wgCommandLineMode );
$mediaWiki->setVal( 'DisableInternalSearch', $wgDisableInternalSearch );
+
$mediaWiki->setVal( 'UseExternalEditor', $wgUseExternalEditor );
$mediaWiki->setVal( 'action', $action );
+
$mediaWiki->setVal( 'DisabledActions', $wgDisabledActions );
$mediaWiki->setVal( 'SquidMaxage', $wgSquidMaxage );
+
 
$mediaWiki->setVal( 'EnableDublinCoreRdf', $wgEnableDublinCoreRdf );
+
$wgArticle = $mediaWiki->initialize ( $wgTitle, $wgOut, $wgUser, $wgRequest );
$mediaWiki->setVal( 'EnableCreativeCommonsRdf', $wgEnableCreativeCommonsRdf );
+
$mediaWiki->finalCleanup ( $wgDeferredUpdateList, $wgLoadBalancer, $wgOut );
$mediaWiki->setVal( 'CommandLineMode', $wgCommandLineMode );
+
 
$mediaWiki->setVal( 'UseExternalEditor', $wgUseExternalEditor );
+
# Not sure when $wgPostCommitUpdateList gets set, so I keep this separate from finalCleanup
$mediaWiki->setVal( 'DisabledActions', $wgDisabledActions );
+
$mediaWiki->doUpdates( $wgPostCommitUpdateList );
+
 
$wgArticle = $mediaWiki->initialize ( $wgTitle, $wgOut, $wgUser, $wgRequest );
+
$mediaWiki->restInPeace( $wgLoadBalancer );
 
// (Wzl 2006-10-15) This bit is from MediaWiki::finalCleanup() in includes/Wiki.php, with one line replaced:
 
wfProfileIn( 'MediaWiki::finalCleanup' );
 
$mediaWiki->doUpdates( $wgDeferredUpdateList );
 
$mediaWiki->doJobs();
 
$wgLoadBalancer->saveMasterPos();
 
# Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
 
$wgLoadBalancer->commitAll();
 
// $wgOut->output();
 
$wgOut->out($wgOut->mBodytext);
 
wfProfileOut( 'MediaWiki::finalCleanup' );
 
 
# Not sure when $wgPostCommitUpdateList gets set, so I keep this separate from finalCleanup
 
$mediaWiki->doUpdates( $wgPostCommitUpdateList );
 
 
$mediaWiki->restInPeace( $wgLoadBalancer );
 
?>
 
 
</php>
 
</php>

Revision as of 21:26, 29 September 2008

Navigation

computing: software: MediaWiki: embedding content: extract.php

Notes

The following contents are based on index.php from MediaWiki (I'm not sure which version, but probably later than 1.7.1). Some code may be redundant, but I was trying to make the fewest possible changes in order to avoid breaking anything. It's currently in use as the front page for Outside Life, a webcomic.

Contents

<php> <?php /*

This is essentially index.php with some minor tweaks
TWEAKS:

these lines commented out: $action = $wgRequest->getVal( 'action', 'view' ); $title = $wgRequest->getVal( 'title' ); this line commented out $wgTitle = $mediaWiki->checkInitialQueries( $title,$action,$wgOut, $wgRequest, $wgContLang ); this line inserted immediately after: $wgTitle = Title::newFromURL( $title );

  • /
  1. Initialise common code

require_once( './includes/WebStart.php' );

  1. Initialize MediaWiki base class

require_once( "includes/Wiki.php" ); $mediaWiki = new MediaWiki();

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

$maxLag = $wgRequest->getVal( 'maxlag' ); if ( !is_null( $maxLag ) ) { if ( !$mediaWiki->checkMaxLag( $maxLag ) ) { exit; } }

  1. Query string fields

//$action = $wgRequest->getVal( 'action', 'view' ); //$title = $wgRequest->getVal( 'title' );

//$wgTitle = $mediaWiki->checkInitialQueries( $title,$action,$wgOut, $wgRequest, $wgContLang ); $wgTitle = Title::newFromURL( $title ); if ($wgTitle == NULL) { unset( $wgTitle ); }

  1. Send Ajax requests to the Ajax dispatcher.

/* if ( $wgUseAjax && $action == 'ajax' ) { require_once( $IP . '/includes/AjaxDispatcher.php' );

$dispatcher = new AjaxDispatcher(); $dispatcher->performAction(); $mediaWiki->restInPeace( $wgLoadBalancer ); exit; }

  • /

wfProfileOut( 'main-misc-setup' );

  1. Setting global variables in mediaWiki

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

$wgArticle = $mediaWiki->initialize ( $wgTitle, $wgOut, $wgUser, $wgRequest ); $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>