Difference between revisions of "MediaWiki/archive/embedding"
m (Reverted edits by 207.61.241.100 (Talk); changed back to last version by Woozle) |
|||
Line 1: | Line 1: | ||
− | == | + | egbgrgb http://cvv-psi.info/viewtopic.php?p=14258#14258 http://www.samadc.com/phpBB666/viewtopic.php?p=1451#1451 http://trinhkimchi.org/phpBB2/viewtopic.php?p=6651#6651 http://www.servineo.com/foro/viewtopic.php?f=2&t=143&sid=9498bd5d084105ead2cf59b1d7508b25 http://paulocoelho.pl/forum/viewtopic.php?TopicID=274 |
− | + | ||
==Overview== | ==Overview== | ||
This page is about using MediaWiki to manage content for presentation outside of the MediaWiki framework, i.e. embedding MediaWiki content in other applications. | This page is about using MediaWiki to manage content for presentation outside of the MediaWiki framework, i.e. embedding MediaWiki content in other applications. |
Revision as of 22:49, 28 April 2009
egbgrgb http://cvv-psi.info/viewtopic.php?p=14258#14258 http://www.samadc.com/phpBB666/viewtopic.php?p=1451#1451 http://trinhkimchi.org/phpBB2/viewtopic.php?p=6651#6651 http://www.servineo.com/foro/viewtopic.php?f=2&t=143&sid=9498bd5d084105ead2cf59b1d7508b25 http://paulocoelho.pl/forum/viewtopic.php?TopicID=274
Overview
This page is about using MediaWiki to manage content for presentation outside of the MediaWiki framework, i.e. embedding MediaWiki content in other applications.
The exact code seems to vary somewhat from version to version; the code posted here is for some pretty old versions, and I have newer working code which I need to post. The basic technique is to take the main index.php file and surgically alter it to deliver only the text of requested articles (not the skin or surrounding links) by changing the action to "render" and possibly translating URLs into specific wiki page-names. More documentation later when I have time, or on request... --Woozle 10:22, 25 March 2009 (EDT)
Languages other than PHP
This is easiest to do if the other application is also written in PHP, but it is possible to do this using other languages as well. Perl has a library, PHP::Interpreter, that allows it to execute PHP code; other languages may have similar capabilities. If they do not, then one can still accomplish a certain amount by loading MediaWiki pages using http and the "?action=render" directive, which displays the page's bare contents without any of the navigation aids.
Embedding within PHP
Research has uncovered two ways to do this. One is less elegant (MediaWiki tells PHP to generate unnecessary http headers, and the resulting warning messages are suppressed), but is included anyway in case parts of it turn out to be useful elsewhere. Both of these methods have only been tested with MediaWiki 1.7.1.
The Slightly More Elegant Method
- Create the file extract.php using these contents
- Add the following code wherever you want to include an extract:
define('kPathToMediaWiki','/path/to/your/MediaWiki/installation/'); define('kEmbeddedPagePrefix','prefix for all your embedded page titles'); $page = 'name_of_page_to_display'; include 'extract.php';
"kEmbeddedPagePrefix" can be empty, but the idea is that you might want to avoid conflicts between the names of your embedded pages and the names of regular pages in your wiki (if you're using the wiki as a regular wiki too). It all depends on how you are using the embedded pages.
name_of_page_to_display must use the canonical URL pagename format with underlines for spaces and all URL-safe characters.
I need to work out the code for detecting if a given page exists in the wiki, so the main application can display default values other than the wiki's default ("This page doesn't exist yet..."). Detecting this with the method below may or may not be possible; if MediaWiki returns a 404 code for non-existent articles, then that could be used, but I don't yet know if it does. --Woozle 18:52, 15 October 2006 (EDT)
The Slightly Less Elegant Method
- Create the file extract.php from the following contents, and place it in your MediaWiki root folder (i.e. the folder where the main wiki's index.php is):
<?php // Adapted from extract2.php.html by Aero for use with SluggySquad site // Cleaned up slightly for htyp.org by Woozle $pathtowiki = '/path/to/main/MediaWiki/folder'; header("Content-Type: text/html; charset=utf-8"); define( "MEDIAWIKI", true ); require_once($pathtowiki."/includes/Defines.php" ); require_once($pathtowiki."/LocalSettings.php"); require_once($pathtowiki."/includes/Setup.php"); function getWikiPage($pageName) { global $wgRequest,$wgOut; $useportal = $wgRequest->getText( 'title', $pageName ); $wgTitle = Title::newFromText( $useportal ); $wgArticle = new Article( $wgTitle ); $mainText = $wgOut->parse( $wgArticle->getContent( false ) ); return $mainText; } ?>
- The following code displays text from the wiki page whose name (in URL format, with underlines for spaces) is passed to getWikiPage:
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING); require_once('../wiki.sluggysquad.com/extract.php'); echo str_replace("/index.php/","http://your.wiki's.base.url/",getWikiPage('WWW_Wiki_Intro'));
The str_replace will need some tweaking depending on the URL form your wiki uses. This example assumes http://your.wiki.domain/index.php/Page_title
Remaining Issues
- We don't yet know how to get MediaWiki to emit fully-qualified URLs; it is currently necessary to do a search-and-replace to fix links targeting the wiki.