Difference between revisions of "MediaWiki/archive/embedding/1.16/index.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
(latest code)
 
m (Woozle moved page MediaWiki/embedding/1.16/index.php to MediaWiki/archive/embedding/1.16/index.php without leaving a redirect: obsolete, keeps changing)
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
==About==
 
==About==
 
This works with MediaWiki v1.16.x.
 
This works with MediaWiki v1.16.x.
 +
 +
The "FIXED title" example in the "CONFIGURATION PART 2" section of the code only displays one page from your wiki, but could probably be expanded to display only a specified set of pages. The advantage is that it will never pull up a "this page has not been created yet" message with edit-links pointing to your (possibly hidden/secret) wiki. There's probably a way to suppress that message (and return a [[http/404|404 code]]) while still allowing new pages to be created/displayed without modifying code.
 
==Instructions==
 
==Instructions==
* Set $wpWikiBase to the folder containing your MediaWiki installation
+
* Modify the settings inside the CONFIGURATION block to match your site's configuration
* Change YOUR SITE TITLE to whatever you want to show up as the title in the brower's titlebar
 
 
* 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]] (not needed if you are only serving one title)
 
* 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==
* It should be simple enough to have a base title plus the page title, or even a title defined within the wikitext.
+
* 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==
 +
* '''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
 +
** now universalized -- can serve fixed or dynamic title set by changes to configuration
 
==Code==
 
==Code==
 
<php><?php
 
<php><?php
$wpWikiBase = '/wiki';
+
// comment these lines out for production use
?>
 
<!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>YOUR SITE NAME</title>
 
<!---
 
<link rel="stylesheet" href="<?= $wpWikiBase; ?>/skins/vector/main-ltr.css?269" media="screen" />
 
<link rel="stylesheet" href="<?= $wpWikiBase; ?>/skins/common/shared.css?269" media="screen" />
 
<link rel="stylesheet" href="<?= $wpWikiBase; ?>/skins/common/commonPrint.css?269" media="print" />
 
-->
 
<link rel="StyleSheet" href="/tools/styles/home.css">
 
</head>
 
<body class="mediawiki ltr ns-0 ns-subject page-Whiteboard skin-vector">
 
<div>
 
 
 
<?php
 
 
$fErrLevel = E_ALL | E_STRICT;
 
$fErrLevel = E_ALL | E_STRICT;
 
error_reporting($fErrLevel);
 
error_reporting($fErrLevel);
 
ini_set('display_errors', 1);
 
ini_set('display_errors', 1);
  
$preIP = dirname( __FILE__ ).'/wiki';
+
// ++++ CONFIGURATION PART 1
 +
$wpWiki = '/wiki';
 +
$wpSkins = "$wpWiki/skins";
 +
$strTitleBase = 'YOUR SITE NAME HERE';
 +
 
 +
$arCSS = array(
 +
  $wpSkins.'/vector/main-ltr.css' => 'screen',
 +
  $wpSkins.'/common/shared.css' => 'screen',
 +
  $wpSkins.'/common/commonPrint.css' => 'print');
 +
// ---- CONFIGURATION PART 1
 +
 
 +
$preIP = dirname( __FILE__ ).$wpWiki;
 
//$preIP = dirname( '../index.html' ).'/wiki';
 
//$preIP = dirname( '../index.html' ).'/wiki';
 
chdir($preIP);
 
chdir($preIP);
Line 43: Line 44:
 
OutputPage::setEncodings(); # Not really used yet
 
OutputPage::setEncodings(); # Not really used yet
  
$title = 'project:Transclude/'.$wgRequest->GetText('title');
+
// ++++ CONFIGURATION PART 2
$action = 'view';
+
 
 +
// (example 1) DYNAMIC titles:
 +
$strTitleReq = $wgRequest->GetText('title');
 +
$wpPage = 'project:Transclude/'.$strTitleReq;
 +
 
 +
// (example 2) FIXED title:
 +
$wpPage = 'project:Transclude/home';
 +
 
 +
// ---- CONFIGURATION PART 2
  
$wgTitle = $mediaWiki->checkInitialQueries( $title, $action );
+
$wgTitle = $mediaWiki->checkInitialQueries( $wpPage, 'view' );
//$wgArticle = MediaWiki::articleFromTitle( $wgTitle );
+
 
 +
// load $wgArticle
 +
$wgArticle = MediaWiki::articleFromTitle( $wgTitle );
 
//$wgArticle = $mediaWiki->initialize ( $wgTitle, $wgOut, $wgUser, $wgRequest );
 
//$wgArticle = $mediaWiki->initialize ( $wgTitle, $wgOut, $wgUser, $wgRequest );
$mediaWiki->performRequestForTitle( $wgTitle, $wgArticle, $wgOut, $wgUser, $wgRequest );
+
//$mediaWiki->performRequestForTitle( $wgTitle, $wgArticle, $wgOut, $wgUser, $wgRequest );
  
require_once( "$preIP/includes/Article.php" );
+
// create appropriate title string
global $wgParser;
+
$strPageName = $wgTitle->getText();
$txtPage = $wgArticle->getContent();
+
$strTitlePage = substr($strPageName,strrpos($strPageName,'/')+1);
 +
if (empty($strTitlePage)) {
 +
    $strTitle = $strTitleBase;
 +
} else {
 +
    $strTitle = $strTitlePage.' - '.$strTitleBase;
 +
}
 
//$out = $wgParser->recursiveTagParse($txtPage);
 
//$out = $wgParser->recursiveTagParse($txtPage);
$objOptions = new ParserOptions();
+
 
$objPOut = $wgParser->parse( $txtPage, $wgTitle, $objOptions );
+
if (is_object($wgArticle)) {
$out = $objPOut->getText();
+
    // 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">
 +
<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>

Latest revision as of 00:08, 15 December 2017

About

This works with MediaWiki v1.16.x.

The "FIXED title" example in the "CONFIGURATION PART 2" section of the code only displays one page from your wiki, but could probably be expanded to display only a specified set of pages. The advantage is that it will never pull up a "this page has not been created yet" message with edit-links pointing to your (possibly hidden/secret) wiki. There's probably a way to suppress that message (and return a 404 code) while still allowing new pages to be created/displayed without modifying code.

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 (not needed if you are only serving one title)
  • 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
    • now universalized -- can serve fixed or dynamic title set by changes to configuration

Code

<php><?php // comment these lines out for production use $fErrLevel = E_ALL | E_STRICT; error_reporting($fErrLevel); ini_set('display_errors', 1);

// ++++ CONFIGURATION PART 1 $wpWiki = '/wiki'; $wpSkins = "$wpWiki/skins"; $strTitleBase = 'YOUR SITE NAME HERE';

$arCSS = array(

 $wpSkins.'/vector/main-ltr.css' => 'screen',
 $wpSkins.'/common/shared.css' => 'screen',
 $wpSkins.'/common/commonPrint.css' => 'print');

// ---- CONFIGURATION PART 1

$preIP = dirname( __FILE__ ).$wpWiki; //$preIP = dirname( '../index.html' ).'/wiki'; chdir($preIP); require_once( "$preIP/includes/WebStart.php" );

  1. Initialize MediaWiki base class

require_once( "$preIP/includes/Wiki.php" ); $mediaWiki = new MediaWiki(); OutputPage::setEncodings(); # Not really used yet

// ++++ CONFIGURATION PART 2

// (example 1) DYNAMIC titles: $strTitleReq = $wgRequest->GetText('title'); $wpPage = 'project:Transclude/'.$strTitleReq;

// (example 2) FIXED title: $wpPage = 'project:Transclude/home';

// ---- CONFIGURATION PART 2

$wgTitle = $mediaWiki->checkInitialQueries( $wpPage, 'view' );

// load $wgArticle $wgArticle = MediaWiki::articleFromTitle( $wgTitle ); //$wgArticle = $mediaWiki->initialize ( $wgTitle, $wgOut, $wgUser, $wgRequest ); //$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"> $strTitle$htHdr

__END__; echo $out; echo '

';</php>