Runphp

From Meta, a Wikimedia project coordination wiki
Jump to navigation Jump to search
Ambox outdated content.svg

This extension is obsolete!
It has been replaced by Runphp page.

MediaWiki logo

Runphp is a very simple extension which allows you to run custom PHP-Code from an Article.

ONLY USE THIS IN AN TRUSTED ENVIRONMENT

Sourcecode of "extensions/runphp.php":

 
<?php
# runphp Mediawiki Extension

# CAUTION CAUTION CAUTION
# ONLY USE THIS IN AN TRUSTED ENVIRONMENT 
# CAUTION CAUTION CAUTION
 
# This extension allows you to run PHP-Code from Wiki-Articles using the following syntax:

# <php> phpcode; </php>

# To activate the extension, include it from your LocalSettings.php
# with: include("extensions/runphp.php");

# Author: Matthias Zirngibl - http://masterbootrecord.de

$wgExtensionFunctions[] = "wfRunPHP";

function wfRunPHP() {
    global $wgParser;
    $wgParser->setHook( "php", "parsePHP" );
}


function parsePHP( $input, $argv, &$parser ) {
    ob_start();
    eval($input);
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
?>


Some notes[edit]

  1. On my Linux system, I had to set the permissions of the runphp.php file to allow "execute", i.e. rwxr-xr-x
  2. I tried this:
<php>echo "Hello";</php>

and got the correct output, but it displayed in the upper left corner of my screen behind the wiki logo. How to get it to display in the usual area where wiki articles are shown? (by Srumberg 04:37, 12 June 2006 (UTC))

I had the same problem. Phil Boswell at irc.freenode.net #mediawiki helped me on that. Nisus 10:46, 20 June 2006 (UTC)
So, I guess that the obvious question is, what was the fix for the problem?
68.124.131.140 17:53, 5 July 2006 (UTC)