Difference between revisions of "MediaWiki/archive/embedding"

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
m (Reverted edits by 211.90.242.210 (Talk); changed back to last version by Woozle)
(moved a referenced page; some spam got in here that I never noticed, too)
 
(40 intermediate revisions by 17 users not shown)
Line 1: Line 1:
==Languages other than PHP==
+
==Overview==
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, [http://search.cpan.org/~gschloss/PHP-Interpreter-1.0.1/lib/PHP/Interpreter.pm 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.
+
This page is about embedding [[MediaWiki]] content within <span class="plainlinks">[https://www.proposable.com/ <span style="color:black;font-weight:normal; text-decoration:none!important; background:none!important; text-decoration:none;">proposal software</span>] non-MediaWiki sites, or as standalone pages without the standard navigation and control links provided by most [[MediaWiki/archive/skins|MediaWiki skin]]s.
==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 [[extract.php for embedding MediaWiki contents|these contents]]
 
* Add the following code wherever you want to include an extract:
 
define('kPathToMediaWiki','<u>/path/to/your/MediaWiki/installation/</u>');
 
define('kEmbeddedPagePrefix','<u>prefix for all your embedded page titles</u>');
 
$page = '<u>name_of_page_to_display</u>';
 
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.
+
==non-PHP==
 +
This is easiest to do if the host application is also written in [[PHP]], but it is possible to do this using other languages as well. [[Perl]] has a library, [http://search.cpan.org/~gschloss/PHP-Interpreter-1.0.1/lib/PHP/Interpreter.pm PHP::Interpreter], that allows it to execute PHP code; other languages may have similar capabilities.
  
<u>name_of_page_to_display</u> must use the canonical URL pagename format with underlines for spaces and all URL-safe characters.
+
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. (This method is not recommended if you have any alternatives, as it is slow and wasteful of CPU resources.)
  
''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. --[[User:Woozle|Woozle]] 18:52, 15 October 2006 (EDT)''
+
==PHP==
 +
This works with MediaWiki v'''1.16''':
 +
* [[/1.16/index.php]]
 +
These have been tested with MediaWiki v'''1.14'''.
 +
* [[/1.14/index.php]] is a usage example; as given, it provides a standalone page, but it also shows the code needed to retrieve page content
 +
* [[/1.14/extract.php]] is the code which actually does the work of extraction; the function GetWikiPage($iTitle) returns the page's contents as a string.
 +
Configuration info is in index.php. Note that this has not been tested ''very much''; I got it working on my server, then posted it.
  
===The Slightly Less Elegant Method===
+
Works on MW '''1.10''':
* 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):
+
* [[/old/extract.php/v2]]
<?php
 
 
// Adapted from extract2.php.html by Aero for use with SluggySquad site
 
// Cleaned up slightly for htyp.org by [[User:Woozle|Woozle]]
 
 
$pathtowiki = '<u>/path/to/main/MediaWiki/folder</u>';
 
 
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://<u>your.wiki's.base.url</u>/",getWikiPage('WWW_Wiki_Intro'));
 
  
The str_replace will need some tweaking depending on the URL form your wiki uses. This example assumes <nowiki>http://your.wiki.domain/index.php/Page_title</nowiki>
+
Based on MW somewhere around '''1.7''':
===Remaining Issues===
+
* [[/old/extract.php/v1]]
* 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.
+
===To Do===
 +
* 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. --[[User:Woozle|Woozle]] 18:52, 15 October 2006 (EDT)''
 +
* 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. (It's probably a configuration thing -- $wgArticlePath, I'd guess. Don't know if link URLs get cached, though, so that might not work reliably. --[[User:Woozle|Woozle]] 19:29, 6 June 2009 (EDT))

Latest revision as of 00:19, 15 December 2017

Overview

This page is about embedding MediaWiki content within proposal software non-MediaWiki sites, or as standalone pages without the standard navigation and control links provided by most MediaWiki skins.

non-PHP

This is easiest to do if the host 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. (This method is not recommended if you have any alternatives, as it is slow and wasteful of CPU resources.)

PHP

This works with MediaWiki v1.16:

These have been tested with MediaWiki v1.14.

  • /1.14/index.php is a usage example; as given, it provides a standalone page, but it also shows the code needed to retrieve page content
  • /1.14/extract.php is the code which actually does the work of extraction; the function GetWikiPage($iTitle) returns the page's contents as a string.

Configuration info is in index.php. Note that this has not been tested very much; I got it working on my server, then posted it.

Works on MW 1.10:

Based on MW somewhere around 1.7:

To Do

  • 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)
  • 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. (It's probably a configuration thing -- $wgArticlePath, I'd guess. Don't know if link URLs get cached, though, so that might not work reliably. --Woozle 19:29, 6 June 2009 (EDT))