Difference between revisions of "MediaWiki/archive/embedding/1.16/index.php"
(bug fix for restricted wikis) |
(code all better now) |
||
Line 2: | Line 2: | ||
This works with MediaWiki v1.16.x. | This works with MediaWiki v1.16.x. | ||
==Instructions== | ==Instructions== | ||
− | * | + | * Modify the settings inside the CONFIGURATION block to match your site's configuration |
− | |||
* Put this file (index.php) in the folder where you want the pages to appear. (I've only tested this in "/", however.) | * Put this file (index.php) in the folder where you want the pages to appear. (I've only tested this in "/", however.) | ||
* Modify [[Apache/.htaccess]] -- see [[/.htaccess]] | * Modify [[Apache/.htaccess]] -- see [[/.htaccess]] | ||
* Whatever is in <nowiki>[[project:Transclude/]]</nowiki> will appear (without the wiki skin) at <nowiki>http://yourdomain.com</nowiki>, <nowiki>[[project:Transclude/a page]]</nowiki> will appear at <nowiki>http://yourdomain.com/a_page</nowiki>, and so on. | * Whatever is in <nowiki>[[project:Transclude/]]</nowiki> will appear (without the wiki skin) at <nowiki>http://yourdomain.com</nowiki>, <nowiki>[[project:Transclude/a page]]</nowiki> will appear at <nowiki>http://yourdomain.com/a_page</nowiki>, and so on. | ||
==Future== | ==Future== | ||
− | + | * I haven't tested to see if a trailing "/" brings up a different page or not; if it does, then trimming off trailing "/"s from the request should fix that, if it's a problem. | |
− | * I haven't tested to see if a trailing "/" brings up a different page or not; if it does, then trimming off trailing "/"s from the request should fix that. | ||
==History== | ==History== | ||
* '''2011-03-17''' changed $wgArticle creation method -- other method returns fully-skinned error page when user does not have read access to the requested page | * '''2011-03-17''' changed $wgArticle creation method -- other method returns fully-skinned error page when user does not have read access to the requested page | ||
** also added some debug code in case of other unanticipated problems | ** also added some debug code in case of other unanticipated problems | ||
+ | * '''2011-03-18''' several small improvements; configuration is now in one block, browser-title now includes the page's title | ||
==Code== | ==Code== | ||
<php><?php | <php><?php | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
$fErrLevel = E_ALL | E_STRICT; | $fErrLevel = E_ALL | E_STRICT; | ||
error_reporting($fErrLevel); | error_reporting($fErrLevel); | ||
Line 46: | Line 28: | ||
OutputPage::setEncodings(); # Not really used yet | OutputPage::setEncodings(); # Not really used yet | ||
− | $ | + | // ++++ CONFIGURATION |
− | $ | + | $wpWiki = '/wiki'; |
+ | $wpSkins = "$wpWiki/skins"; | ||
+ | $strTitleReq = $wgRequest->GetText('title'); | ||
+ | $strTitleBase = 'YOUR SITE NAME'; | ||
+ | $wpPage = 'project:Transclude/'.$strTitleReq; | ||
− | $wgTitle = $mediaWiki->checkInitialQueries( $ | + | $arCSS = array( // MediaWiki skins |
− | $wgArticle = MediaWiki::articleFromTitle( $wgTitle ); | + | $wpSkins.'/vector/main-ltr.css' => 'screen', |
+ | $wpSkins.'/common/shared.css' => 'screen', | ||
+ | $wpSkins.'/common/commonPrint.css' => 'print'); | ||
+ | // ---- CONFIGURATION | ||
+ | |||
+ | $wgTitle = $mediaWiki->checkInitialQueries( $wpPage, 'view' ); | ||
+ | //$wgArticle = MediaWiki::articleFromTitle( $wgTitle ); | ||
//$wgArticle = $mediaWiki->initialize ( $wgTitle, $wgOut, $wgUser, $wgRequest ); | //$wgArticle = $mediaWiki->initialize ( $wgTitle, $wgOut, $wgUser, $wgRequest ); | ||
− | |||
− | + | // load $wgArticle | |
+ | $mediaWiki->performRequestForTitle( $wgTitle, $wgArticle, $wgOut, $wgUser, $wgRequest ); | ||
+ | |||
+ | // create appropriate title string | ||
+ | $strPageName = $wgTitle->getText(); | ||
+ | $strTitlePage = substr($strPageName,strrpos($strPageName,'/')+1); | ||
+ | if (empty($strTitlePage)) { | ||
+ | $strTitle = $strTitleBase; | ||
+ | } else { | ||
+ | $strTitle = $strTitlePage.' - '.$strTitleBase; | ||
+ | } | ||
+ | //$out = $wgParser->recursiveTagParse($txtPage); | ||
+ | |||
if (is_object($wgArticle)) { | if (is_object($wgArticle)) { | ||
+ | // fetch the page contents and parse it | ||
+ | require_once( "$preIP/includes/Article.php" ); | ||
+ | global $wgParser; | ||
$txtPage = $wgArticle->getContent(); | $txtPage = $wgArticle->getContent(); | ||
− | |||
$objOptions = new ParserOptions(); | $objOptions = new ParserOptions(); | ||
$objPOut = $wgParser->parse( $txtPage, $wgTitle, $objOptions ); | $objPOut = $wgParser->parse( $txtPage, $wgTitle, $objOptions ); | ||
$out = $objPOut->getText(); | $out = $objPOut->getText(); | ||
} else { | } else { | ||
− | $out = " | + | $out = "could not load page from database"; |
+ | } | ||
+ | |||
+ | $htHdr = ''; | ||
+ | foreach ($arCSS as $fs => $medium) { | ||
+ | $htHdr .= "\n".'<link rel="stylesheet" href="'.$fs.'" media="'.$medium.'" />'; | ||
} | } | ||
+ | |||
+ | echo <<<__END__ | ||
+ | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
+ | <html lang="en" dir="ltr"> | ||
+ | <head> | ||
+ | <title>$strTitle</title>$htHdr | ||
+ | </head> | ||
+ | <body class="mediawiki ltr ns-0 ns-subject page-Whiteboard skin-vector"> | ||
+ | <div> | ||
+ | __END__; | ||
+ | |||
echo $out; | echo $out; | ||
echo '</div></body></html>';</php> | echo '</div></body></html>';</php> |
Revision as of 13:42, 18 March 2011
About
This works with MediaWiki v1.16.x.
Instructions
- Modify the settings inside the CONFIGURATION block to match your site's configuration
- Put this file (index.php) in the folder where you want the pages to appear. (I've only tested this in "/", however.)
- Modify Apache/.htaccess -- see /.htaccess
- Whatever is in [[project:Transclude/]] will appear (without the wiki skin) at http://yourdomain.com, [[project:Transclude/a page]] will appear at http://yourdomain.com/a_page, and so on.
Future
- I haven't tested to see if a trailing "/" brings up a different page or not; if it does, then trimming off trailing "/"s from the request should fix that, if it's a problem.
History
- 2011-03-17 changed $wgArticle creation method -- other method returns fully-skinned error page when user does not have read access to the requested page
- also added some debug code in case of other unanticipated problems
- 2011-03-18 several small improvements; configuration is now in one block, browser-title now includes the page's title
Code
<php><?php $fErrLevel = E_ALL | E_STRICT; error_reporting($fErrLevel); ini_set('display_errors', 1);
$preIP = dirname( __FILE__ ).'/wiki'; //$preIP = dirname( '../index.html' ).'/wiki'; chdir($preIP); require_once( "$preIP/includes/WebStart.php" );
- Initialize MediaWiki base class
require_once( "$preIP/includes/Wiki.php" ); $mediaWiki = new MediaWiki(); OutputPage::setEncodings(); # Not really used yet
// ++++ CONFIGURATION $wpWiki = '/wiki'; $wpSkins = "$wpWiki/skins"; $strTitleReq = $wgRequest->GetText('title'); $strTitleBase = 'YOUR SITE NAME'; $wpPage = 'project:Transclude/'.$strTitleReq;
$arCSS = array( // MediaWiki skins
$wpSkins.'/vector/main-ltr.css' => 'screen', $wpSkins.'/common/shared.css' => 'screen', $wpSkins.'/common/commonPrint.css' => 'print');
// ---- CONFIGURATION
$wgTitle = $mediaWiki->checkInitialQueries( $wpPage, 'view' ); //$wgArticle = MediaWiki::articleFromTitle( $wgTitle ); //$wgArticle = $mediaWiki->initialize ( $wgTitle, $wgOut, $wgUser, $wgRequest );
// load $wgArticle $mediaWiki->performRequestForTitle( $wgTitle, $wgArticle, $wgOut, $wgUser, $wgRequest );
// create appropriate title string $strPageName = $wgTitle->getText(); $strTitlePage = substr($strPageName,strrpos($strPageName,'/')+1); if (empty($strTitlePage)) {
$strTitle = $strTitleBase;
} else {
$strTitle = $strTitlePage.' - '.$strTitleBase;
} //$out = $wgParser->recursiveTagParse($txtPage);
if (is_object($wgArticle)) {
// fetch the page contents and parse it require_once( "$preIP/includes/Article.php" ); global $wgParser; $txtPage = $wgArticle->getContent(); $objOptions = new ParserOptions(); $objPOut = $wgParser->parse( $txtPage, $wgTitle, $objOptions ); $out = $objPOut->getText();
} else {
$out = "could not load page from database";
}
$htHdr = ; foreach ($arCSS as $fs => $medium) {
$htHdr .= "\n".'<link rel="stylesheet" href="'.$fs.'" media="'.$medium.'" />';
}
echo <<<__END__ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
';</php>