Difference between revisions of "MediaWiki/archive/embedding"
m (Reverted edits by 211.90.242.210 (Talk); changed back to last version by Woozle) |
|||
Line 1: | Line 1: | ||
− | == | + | wefgrhtn http://planar.se/forum/viewtopic.php?f=1&t=704 |
− | + | http://planar.se/forum/viewtopic.php?f=1&t=706 http://planar.se/forum/viewtopic.php?f=1&t=707 http://go2tennisladder.com/modules.php?name=Forums&file=viewtopic&t=1068&highlight= http://go2tennisladder.com/modules.php?name=Forums&file=viewtopic&t=1071&highlight= | |
+ | |||
==Embedding within PHP== | ==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. | 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. |
Revision as of 19:12, 3 May 2009
wefgrhtn http://planar.se/forum/viewtopic.php?f=1&t=704 http://planar.se/forum/viewtopic.php?f=1&t=706 http://planar.se/forum/viewtopic.php?f=1&t=707 http://go2tennisladder.com/modules.php?name=Forums&file=viewtopic&t=1068&highlight= http://go2tennisladder.com/modules.php?name=Forums&file=viewtopic&t=1071&highlight=
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.