Difference between revisions of "Extension:Workflow.php"
m |
(ready for article update code) |
||
Line 12: | Line 12: | ||
$wgExtensionFunctions[] = 'wfSetupWorkflow'; | $wgExtensionFunctions[] = 'wfSetupWorkflow'; | ||
$wgHooks['LanguageGetMagic'][] = 'wfWorkflowLanguageGetMagic'; | $wgHooks['LanguageGetMagic'][] = 'wfWorkflowLanguageGetMagic'; | ||
− | |||
$wgExtensionCredits['parserhook'][] = array( | $wgExtensionCredits['parserhook'][] = array( | ||
Line 23: | Line 22: | ||
# If it's a workflow-related ajax call, don't use dispatcher (because we need the catlinks generated by normal page render) | # If it's a workflow-related ajax call, don't use dispatcher (because we need the catlinks generated by normal page render) | ||
− | if ($wgUseAjax && $_REQUEST['action'] == 'ajax' && $_REQUEST['rs'] == 'wfWorkflowUpdateTag') { | + | if ($wgUseAjax && $_REQUEST['action'] == 'ajax' && $_REQUEST['rs'] == 'wfWorkflowUpdateTag' && is_array($_REQUEST['rsargs'])) { |
+ | list($_REQUEST['title'],$wgWorkflowTagID,$wgWorkflowTagState) = $_REQUEST['rsargs']; | ||
+ | $wgHooks['OutputPageBeforeHTML'][] = 'wfWorkflowReturnCatlinks'; | ||
+ | $wgWorkflowUpdateTag = true; | ||
$_REQUEST['action'] = 'render'; | $_REQUEST['action'] = 'render'; | ||
− | $ | + | } else $wgWorkflowUpdateTag = false; |
− | |||
− | |||
− | |||
− | |||
− | |||
# Expand the #tags to reveal the current state and hide the others and add javascript | # Expand the #tags to reveal the current state and hide the others and add javascript | ||
+ | # - note the hidden states mustn't be rendered because they contain categorisation links which shouldn't be processed | ||
function wfWorkflowExpandTag(&$parser) { | function wfWorkflowExpandTag(&$parser) { | ||
Line 42: | Line 40: | ||
} | } | ||
− | # | + | # Render the visible item |
$text = ''; | $text = ''; | ||
foreach ($items as $k => $v) $text .= "<div class='workflow-item' id='$k'>$v</div>\n"; | foreach ($items as $k => $v) $text .= "<div class='workflow-item' id='$k'>$v</div>\n"; | ||
Line 50: | Line 48: | ||
} | } | ||
− | # | + | # Update a tag state in an article |
− | function wfWorkflowUpdateTag() { | + | function wfWorkflowUpdateTag($title,$id,$state) { |
+ | } | ||
+ | |||
+ | # Return just the catlinks to the client after updating a tag state | ||
+ | function wfWorkflowReturnCatlinks() { | ||
global $wgUser,$wgOut; | global $wgUser,$wgOut; | ||
$skin = $wgUser->getSkin(); | $skin = $wgUser->getSkin(); | ||
Line 64: | Line 66: | ||
# Called from $wgExtensionFunctions array when initialising extensions | # Called from $wgExtensionFunctions array when initialising extensions | ||
function wfSetupWorkflow() { | function wfSetupWorkflow() { | ||
− | global $wgParser,$wgWorkflowMagic; | + | global $wgHooks,$wgParser,$wgWorkflowMagic,$wgWorkflowUpdateTag; |
+ | |||
+ | # Install the #tag parser-function | ||
$wgParser->setFunctionHook($wgWorkflowMagic,'wfWorkflowExpandTag'); | $wgParser->setFunctionHook($wgWorkflowMagic,'wfWorkflowExpandTag'); | ||
+ | |||
+ | # If updating a tag from an ajax request, update the article and set a hook to return only the catlinks | ||
+ | if ($wgWorkflowUpdateTag) wfWorkflowUpdateTag($_REQUEST['title'],$wgWorkflowTagID,$wgWorkflowTagState); | ||
+ | |||
} | } | ||
Revision as of 09:03, 6 October 2007
<?php
- Extension:Workflow
- - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
- - Author: User:NadCategory:Extensions created with Template:Extension
- - 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';
$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 );
- If it's a workflow-related ajax call, don't use dispatcher (because we need the catlinks generated by normal page render)
if ($wgUseAjax && $_REQUEST['action'] == 'ajax' && $_REQUEST['rs'] == 'wfWorkflowUpdateTag' && is_array($_REQUEST['rsargs'])) { list($_REQUEST['title'],$wgWorkflowTagID,$wgWorkflowTagState) = $_REQUEST['rsargs']; $wgHooks['OutputPageBeforeHTML'][] = 'wfWorkflowReturnCatlinks'; $wgWorkflowUpdateTag = true; $_REQUEST['action'] = 'render'; } else $wgWorkflowUpdateTag = false;
- Expand the #tags to reveal the current state and hide the others and add javascript
- - note the hidden states mustn't be rendered because they contain categorisation links which shouldn't be processed
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; }
# Render the visible item $text = ;
foreach ($items as $k => $v) $text .= "
\n"; $text = "
";
return $text; }
- Update a tag state in an article
function wfWorkflowUpdateTag($title,$id,$state) { }
- Return just the catlinks to the client after updating a tag state
function wfWorkflowReturnCatlinks() { global $wgUser,$wgOut; $skin = $wgUser->getSkin(); $catlinks = is_object($skin) ? $skin->getCategoryLinks() : 'Error: no skin!'; $wgOut->disable(); while(@ob_end_clean()); if (in_array('Content-Encoding: gzip',headers_list())) $catlinks = gzencode($catlinks); echo($catlinks); return false; }
- Called from $wgExtensionFunctions array when initialising extensions
function wfSetupWorkflow() { global $wgHooks,$wgParser,$wgWorkflowMagic,$wgWorkflowUpdateTag;
# Install the #tag parser-function $wgParser->setFunctionHook($wgWorkflowMagic,'wfWorkflowExpandTag');
# If updating a tag from an ajax request, update the article and set a hook to return only the catlinks if ($wgWorkflowUpdateTag) wfWorkflowUpdateTag($_REQUEST['title'],$wgWorkflowTagID,$wgWorkflowTagState);
}
- 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; } ?>