MediaWiki/archive/embedding/1.16/index.php: Difference between revisions
from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
m moved MediaWiki/embedding/1.16/index.php to MediaWiki/embedding/1.16/portable/index.php: the non-portable code looks to have advantages too |
bug fix for restricted wikis |
||
| Line 10: | Line 10: | ||
* It should be simple enough to have a base title plus the page title, or even a title defined within the wikitext. | * 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. | * 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 | |||
==Code== | ==Code== | ||
<php><?php | <php><?php | ||
| Line 47: | Line 50: | ||
$wgTitle = $mediaWiki->checkInitialQueries( $title, $action ); | $wgTitle = $mediaWiki->checkInitialQueries( $title, $action ); | ||
$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" ); | require_once( "$preIP/includes/Article.php" ); | ||
if (is_object($wgArticle)) { | |||
$txtPage = $wgArticle->getContent(); | $txtPage = $wgArticle->getContent(); | ||
//$out = $wgParser->recursiveTagParse($txtPage); | //$out = $wgParser->recursiveTagParse($txtPage); | ||
$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 { | |||
$out = "internal error"; | |||
} | |||
echo $out; | echo $out; | ||
echo '</div></body></html>';</php> | echo '</div></body></html>';</php> | ||
Revision as of 23:32, 17 March 2011
About
This works with MediaWiki v1.16.x.
Instructions
- Set $wpWikiBase to the folder containing your MediaWiki installation
- 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.)
- 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
- 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.
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
Code
<php><?php $wpWikiBase = '/wiki'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
GetText('title');
$action = 'view';
$wgTitle = $mediaWiki->checkInitialQueries( $title, $action );
$wgArticle = MediaWiki::articleFromTitle( $wgTitle );
//$wgArticle = $mediaWiki->initialize ( $wgTitle, $wgOut, $wgUser, $wgRequest );
//$mediaWiki->performRequestForTitle( $wgTitle, $wgArticle, $wgOut, $wgUser, $wgRequest );
require_once( "$preIP/includes/Article.php" );
if (is_object($wgArticle)) {
$txtPage = $wgArticle->getContent();
//$out = $wgParser->recursiveTagParse($txtPage);
$objOptions = new ParserOptions();
$objPOut = $wgParser->parse( $txtPage, $wgTitle, $objOptions );
$out = $objPOut->getText();
} else {
$out = "internal error";
}
echo $out;
echo '
';</php>
