このページは2008年 2月 25日, 14:39に更新されました by stanaka

@gui

From $1

Deki Wiki 1.8.3cから,  /@gui/ URL が第二のPHPのエントリーポイントとして利用可能になりました。

Normally, all URLs passed to your Deki Wiki are rewritten by Apache to access index.php, which loads all of Deki Wiki (which can be a slow operation). With the advent of UI features which require many asyncronous calls, utilizing the main application entry point was a performance drag. Consider /@gui/ a blank slate which isn't greedily handled by Deki Wiki where you can expose any simple PHP functionality you'd like.

Caveats

This functionality was grown organically to solve a specific UI need, and thus may not be a silver bullet in running PHP applications on the same domain as Deki Wiki. /@gui/'s usage is subject to change in future releases.

Overview

You can pass in any path and parameters to the /@gui/ URL. For example:

/@gui/myfeature/

/@gui/myfeature/?param=value

All calls are rewritten by mod_rewrite to /proxy.php

Proxy.php

Proxy.php itself includes 3 files from Deki Wiki: LocalSettings.php, includes/GlobalFunctions.php, and includes/dream.php. These three files are considered the bare minimum overhead to allow /@gui/ to operate on the API. With these three files, you can use Deki Wiki's Plug methods to access all features inside the API.

Creating your own functionality

When you load up proxy.php, you'll see this code path: (this doc is being generated after 1.8.3c, so this code may not exactly  match what's below)

 switch ($requestType)
{
	// default api formatter
	case 'deki':
	
	//extension list
	case 'extensions': 
	//<iframe> for rss updates, so we don't slow down control panel
	case 'updates': 
	// page/file moving functions
	case 'move':
	// editor calls
	case 'editor':
	// link dialog related formatters
	case 'linknavigate':
	case 'linksearch':
		require_once(sprintf('%s/%s.php', FORMATTERS_DIR, $requestType));
		$formatterClass = sprintf('%sFormatter', $requestType);
		$Formatter = new $formatterClass;

		// process request formatter
		$Formatter->format($paths, $params);
		$Formatter->output();
		break;

	default:
		exit();
}

Each of the switch statements corresponds to a feature in /@gui/. For example, using this codepath, we currently have the following features:

  • /@gui/deki/
  • /@gui/extensions/
  • /@gui/updates/
  • /@gui/move/
  • /@gui/editor/
  • /@gui/linknavigate/
  • /@gui/linksearch/

If you want to add your own feature, simply add another "case yourfeature:" after one of the existing case values.

Mapping functionality

There is an abstract class RequestFormatter in proxy.php which shows the base class you extend to add functionality. You extend your class by creating a new PHP file in /includes/gui/yourfeature.php.

The simplest way to simply print out some values is to use this PHP file in yourfeature.php:

 
class MyFeatureFormatter extends RequestFormatter
{
	public function MyFeatureFormatter()
	{
		$this->contentType = 'text/html';
	}
	public function format(&$path, &$params) 
	{
		echo('<p>Paths you sent in:</p>');
		echo('<pre>'.print_r($path, true).'</pre>');
		echo('<p>Parameters you sent in:</p>');
		echo('<pre>'.print_r($params, true).'</pre>');
	}
}

Anything you send to the output buffer inside your MyFeatureFormatter will be sent to the browser; you can easily test this by going to /@gui/myfeature/mypath/?myquery=foo. This will output two arrays which will contain the path as well as your query params.

Real Usage

An example of /@gui/ usage is the /deki/ formatter - this will remap anything from the API in a format you'd like. This allows you to remix the data coming back in an optimal format for any functionality you'd like to create in the front-end.

An example /deki/ formatter is the printr formatter: http://wiki.opengarden.org/@gui/deki....format=printr does a print_r() to all data returned from http://wiki.opengarden.org/@api/deki/pages/HOME

Inside Deki Wiki

We make extensive use of this functionality in the link dialogs; move.php is a formatter which is used to validate pages on move. Instead of writing functionality in Javascript, this formatter takes POST data, sends it to the API, does error checking, and returns data in JSON format to the front-end. This simplifies UI development for Deki Wiki, as it allows a PHP developer to use one set of tools to develop most of the logic required for API interaction (thus minimizing logic duplication in two languages).

タグ:
 
コメント(0)
あなたはコメントを投稿するには ログイン しなければなりません。