Difference between revisions of "Extension:Workflow.php"

From Organic Design wiki
(start from template)
 
(start fillin' in)
Line 12: Line 12:
 
$wgExtensionFunctions[]        = 'wfSetupWorkflow';
 
$wgExtensionFunctions[]        = 'wfSetupWorkflow';
 
$wgHooks['LanguageGetMagic'][] = 'wfWorkflowLanguageGetMagic';
 
$wgHooks['LanguageGetMagic'][] = 'wfWorkflowLanguageGetMagic';
 +
$wgAjaxExportList[]            = 'wfWorkflowUpdateTag';
  
 
$wgExtensionCredits['parserhook'][] = array(
 
$wgExtensionCredits['parserhook'][] = array(
Line 21: Line 22:
 
);
 
);
  
class Workflow {
+
# Expand the #tags to reveal the current state and hide the others and add javascript
 +
function wfWorkflowExpandTag(&$parser) {
  
# Constructor
+
# Populate $argv with both named and numeric parameters
function Workflow() {
+
$argv  = array();
global $wgParser,$wgWorkflowMagic;
+
$items = array();
$wgParser->setFunctionHook($wgWorkflowMagic,array($this,'magic'));
+
foreach (func_get_args() as $arg) if (!is_object($arg)) {
 +
if (preg_match('/^(.+?)\\s*=\\s*(.+)$/',$arg,$match)) $argv[$match[1]] = $match[2]; else $items[] = $arg;
 
}
 
}
  
# Expand the tag-magic
+
# Build the container and all the states
function magic(&$parser) {
+
$text = '';
 +
foreach ($items as $k => $v) $text .= "<div class='workflow-item' id='$k'>$v</div>\n";
 +
$text = "<div class='workflow-tag' id='$id'>\n$text</div>";
  
# Populate $argv with both named and numeric parameters
+
return $text;
$argv = array();
+
}
foreach (func_get_args() as $arg) if (!is_object($arg)) {
 
if (preg_match('/^(.+?)\\s*=\\s*(.+)$/',$arg,$match)) $argv[$match[1]] = $match[2]; else $argv[] = $arg;
 
}
 
  
# Return result with available parser flags
+
# Called by the AjaxDispatcher, updates the state of the specified title/tag
return array(
+
function wfWorkflowUpdateTag($pagename,$tag,$state) {
$text,
+
# if (!$title = Title::newFromText($pagename)) return 'invalid title!';
found  => true,
+
# $id      = $title->getArticleID()
nowiki  => false,
+
# $db      = &wfGetDB(DB_SLAVE);
noparse => false,
+
# $cl      = $db->tableName('categorylinks');
noargs => false,
+
# $result = $db->query("SELECT cl_to FROM $cl WHERE cl_from = $id");
isHTML  => false
+
# if ($result instanceof ResultWrapper) $result = $result->result;
);
+
# $db->fetchRow($result);
 
+
global $wgUser;
}
+
$skin = $wgUser->getSkin();
 
+
$catlinks = is_object($skin) ? $skin->getCategoryLinks() : 'no catlinks';
# Needed in some versions to prevent Special:Version from breaking
+
return $catlinks;
function __toString() { return 'Workflow'; }
+
}
}
 
  
 
# Called from $wgExtensionFunctions array when initialising extensions
 
# Called from $wgExtensionFunctions array when initialising extensions
 
function wfSetupWorkflow() {
 
function wfSetupWorkflow() {
global $wgWorkflow;
+
global $wgParser,$wgWorkflowMagic;
$wgWorkflow = new Workflow();
+
$wgParser->setFunctionHook($wgWorkflowMagic,'wfWorkflowExpandTag');
 
}
 
}
  

Revision as of 07:49, 6 October 2007

<?php

  1. Extension:Workflow
Info.svg These are the MediaWiki extensions we're using and/or developing. Please refer to the information on the mediawiki.org wiki for installation and usage details. Extensions here which have no corresponding mediawiki article are either not ready for use or have been superseded. You can also browse our extension code in our local Subversion repository or our GitHub mirror.

Template:Php

  1. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
  2. - Author: User:NadCategory:Extensions created with Template:Extension
  3. - Started: 2007-10-06

if (!defined('MEDIAWIKI')) die('Not an entry point.');

define('WORKFLOW_VERSION','0.0.0, 2007-10-06');

$wgWorkflowMagic = "tag"; $wgExtensionFunctions[] = 'wfSetupWorkflow'; $wgHooks['LanguageGetMagic'][] = 'wfWorkflowLanguageGetMagic'; $wgAjaxExportList[] = 'wfWorkflowUpdateTag';

$wgExtensionCredits['parserhook'][] = array( 'name' => 'Workflow', 'author' => 'User:Nad', 'description' => 'Allows dynamic content areas called tags which can be switched between pre-selected states by clicking. The states can contain normal content such as images and categorisation links.', 'url' => 'http://www.mediawiki.org/wiki/Extension:Workflow', 'version' => WORKFLOW_VERSION );

  1. Expand the #tags to reveal the current state and hide the others and add javascript

function wfWorkflowExpandTag(&$parser) {

# Populate $argv with both named and numeric parameters $argv = array(); $items = array(); foreach (func_get_args() as $arg) if (!is_object($arg)) { if (preg_match('/^(.+?)\\s*=\\s*(.+)$/',$arg,$match)) $argv[$match[1]] = $match[2]; else $items[] = $arg; }

# Build the container and all the states $text = ;

foreach ($items as $k => $v) $text .= "

$v

\n"; $text = "

\n$text

";

return $text; }

  1. Called by the AjaxDispatcher, updates the state of the specified title/tag

function wfWorkflowUpdateTag($pagename,$tag,$state) {

  1. if (!$title = Title::newFromText($pagename)) return 'invalid title!';
  2. $id = $title->getArticleID()
  3. $db = &wfGetDB(DB_SLAVE);
  4. $cl = $db->tableName('categorylinks');
  5. $result = $db->query("SELECT cl_to FROM $cl WHERE cl_from = $id");
  6. if ($result instanceof ResultWrapper) $result = $result->result;
  7. $db->fetchRow($result);

global $wgUser; $skin = $wgUser->getSkin(); $catlinks = is_object($skin) ? $skin->getCategoryLinks() : 'no catlinks'; return $catlinks; }

  1. Called from $wgExtensionFunctions array when initialising extensions

function wfSetupWorkflow() { global $wgParser,$wgWorkflowMagic; $wgParser->setFunctionHook($wgWorkflowMagic,'wfWorkflowExpandTag'); }

  1. Needed in MediaWiki >1.8.0 for magic word hooks to work properly

function wfWorkflowLanguageGetMagic(&$magicWords,$langCode = 0) { global $wgWorkflowMagic; $magicWords[$wgWorkflowMagic] = array(0,$wgWorkflowMagic); return true; } ?>