|
|
(55 intermediate revisions by 3 users not shown) |
Line 1: |
Line 1: |
− | <?php
| + | {{svn|extensions|Workflow/Workflow.php}} |
− | # Extension:Workflow{{Category:Extensions|Workflow}}{{php}}
| |
− | # - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
| |
− | # - Author: [http://www.organicdesign.co.nz/nad User:Nad]{{Category: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';
| |
− | $wgAjaxExportList[] = 'wfWorkflowUpdateTag';
| |
− | | |
− | $wgExtensionCredits['parserhook'][] = array(
| |
− | 'name' => 'Workflow',
| |
− | 'author' => '[http://www.organicdesign.co.nz/nad 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
| |
− | );
| |
− | | |
− | # 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 .= "<div class='workflow-item' id='$k'>$v</div>\n";
| |
− | $text = "<div class='workflow-tag' id='$id'>\n$text</div>";
| |
− | | |
− | return $text;
| |
− | }
| |
− | | |
− | # Called by the AjaxDispatcher, updates the state of the specified title/tag
| |
− | function wfWorkflowUpdateTag($pagename,$tag,$state) {
| |
− | # if (!$title = Title::newFromText($pagename)) return 'invalid title!';
| |
− | # $id = $title->getArticleID()
| |
− | # $db = &wfGetDB(DB_SLAVE);
| |
− | # $cl = $db->tableName('categorylinks');
| |
− | # $result = $db->query("SELECT cl_to FROM $cl WHERE cl_from = $id");
| |
− | # if ($result instanceof ResultWrapper) $result = $result->result;
| |
− | # $db->fetchRow($result);
| |
− | global $wgUser;
| |
− | $skin = $wgUser->getSkin();
| |
− | $catlinks = is_object($skin) ? $skin->getCategoryLinks() : 'no catlinks';
| |
− | return $catlinks;
| |
− | }
| |
− | | |
− | # Called from $wgExtensionFunctions array when initialising extensions
| |
− | function wfSetupWorkflow() {
| |
− | global $wgParser,$wgWorkflowMagic;
| |
− | $wgParser->setFunctionHook($wgWorkflowMagic,'wfWorkflowExpandTag');
| |
− | }
| |
− | | |
− | # 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;
| |
− | }
| |
− | ?>
| |