Difference between revisions of "MediaWiki/archive/embedding/old/extract.php/v1"

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
(New page: ==Note== This version is '''obsolete'''. Use only if newer code fails and you are looking for ideas. --~~~~ ==Instructions== Create the file '''extract.php''' from the code below, and plac...)
 
("the slightly less-elegant method")
Line 1: Line 1:
 
==Note==
 
==Note==
This version is '''obsolete'''. Use only if newer code fails and you are looking for ideas. --[[User:Woozle|Woozle]] 19:11, 6 June 2009 (EDT)
+
This version is '''obsolete'''. Use only if newer code fails and you are looking for ideas. This was formerly "the slightly less-elegant method", and actually was created ''before'' the "[[../old1|old1]]" code (I'll swap them around later). --[[User:Woozle|Woozle]] 19:11, 6 June 2009 (EDT)
 
==Instructions==
 
==Instructions==
 
Create the file '''extract.php''' from the code below, and place it in your MediaWiki root folder (i.e. the folder where the main wiki's index.php is).
 
Create the file '''extract.php''' from the code below, and place it in your MediaWiki root folder (i.e. the folder where the main wiki's index.php is).

Revision as of 23:15, 6 June 2009

Note

This version is obsolete. Use only if newer code fails and you are looking for ideas. This was formerly "the slightly less-elegant method", and actually was created before the "old1" code (I'll swap them around later). --Woozle 19:11, 6 June 2009 (EDT)

Instructions

Create the file extract.php from the code below, and place it in your MediaWiki root folder (i.e. the folder where the main wiki's index.php is).

The following code displays text from the wiki page whose name (in URL format, with underlines for spaces) is passed to getWikiPage: <php> 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')); </php>

  • 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

Code

<php><?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;

}

?></php>