Difference between revisions of "Extension:ListView.php"
(DBKey not title) |
(Add select list for record types) |
||
Line 7: | Line 7: | ||
if (!defined('MEDIAWIKI')) die('Not an entry point.'); | if (!defined('MEDIAWIKI')) die('Not an entry point.'); | ||
− | define('LISTVIEW_VERSION','0.0.0, 2008-04- | + | define('LISTVIEW_VERSION','0.0.0, 2008-04-29'); |
+ | |||
+ | $egRecordTemplatesCat = 'Record_templates'; # DBkey of category that valid record templates are members of | ||
$wgExtensionFunctions[] = 'wfSetupListView'; | $wgExtensionFunctions[] = 'wfSetupListView'; | ||
Line 39: | Line 41: | ||
function wfListViewUnknownAction($action,&$article) { | function wfListViewUnknownAction($action,&$article) { | ||
− | global $wgOut,$wgUser,$wgTitle,$wgParser; | + | global $wgOut,$wgUser,$wgTitle,$wgParser,$egRecordTemplatesCat; |
if ($action != 'listview') return true; | if ($action != 'listview') return true; | ||
− | + | ||
+ | # Read the valid links into $links array | ||
$title = $article->getTitle(); | $title = $article->getTitle(); | ||
if ($title->getNamespace() == NS_CATEGORY) { | if ($title->getNamespace() == NS_CATEGORY) { | ||
Line 64: | Line 67: | ||
} | } | ||
+ | # Render a generic selection form (a dropdown of all the record types found in Category:Record templates) | ||
+ | $select = '<option selected>Select record type</option>'; | ||
+ | $dbr = &wfGetDB(DB_SLAVE); | ||
+ | $cl = $dbr->tableName('categorylinks'); | ||
+ | $res = $dbr->select($cl,'cl_from',"cl_to = '$egRecordTemplatesCat'",__METHOD__,array('ORDER BY' => 'cl_sortkey')); | ||
+ | while ($row = $dbr->fetchRow($res)) $select .= '<option>'.(Title::newFromID($row[0])->getText()).'</option>'; | ||
+ | $select = "<select name=\"template\">\n$select\n</select>"; | ||
+ | $wgOut->addHtml($select); | ||
+ | |||
+ | # Render the list | ||
$wgOut->setPageTitle($title); | $wgOut->setPageTitle($title); | ||
$wgOut->addHtml("<table>\n"); | $wgOut->addHtml("<table>\n"); | ||
− | |||
$class = 'even'; | $class = 'even'; | ||
foreach ($links as $link) { | foreach ($links as $link) { | ||
Line 74: | Line 86: | ||
$wgOut->addHtml("<td>$link[1]</td>"); | $wgOut->addHtml("<td>$link[1]</td>"); | ||
$wgOut->addHtml("</tr>\n"); | $wgOut->addHtml("</tr>\n"); | ||
− | } | + | } |
− | |||
$wgOut->addHtml("</table>\n"); | $wgOut->addHtml("</table>\n"); | ||
return false; | return false; | ||
} | } |
Revision as of 02:32, 29 April 2008
<?php
- Extension:ListView
- - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
- - Author: User:NadCategory:Extensions created with Template:Extension
- - Started: 2008-04-16
if (!defined('MEDIAWIKI')) die('Not an entry point.');
define('LISTVIEW_VERSION','0.0.0, 2008-04-29');
$egRecordTemplatesCat = 'Record_templates'; # DBkey of category that valid record templates are members of
$wgExtensionFunctions[] = 'wfSetupListView'; $wgExtensionCredits['other'][] = array( 'name' => 'ListView', 'author' => 'User:Nad', 'description' => 'Allows categories or articles containing lists of article links to be rendered as a sortable list', 'url' => 'http://www.organicdesign.co.nz/Extension:ListView.php', 'version' => LISTVIEW_VERSION );
function wfSetupListView() { global $wgHooks,$wgOut,$wgUser; $wgHooks['SkinTemplateTabs'][] = 'wfListViewUpdateActions'; $wgHooks['UnknownAction'][] = 'wfListViewUnknownAction'; }
function wfListViewUpdateActions(&$skin,&$actions) { global $wgTitle,$wgRequest; $selected = $wgRequest->getText('action') == 'listview' ? 'selected' : false; $url = $wgTitle->getLocalURL("action=listview"); if (is_object($wgTitle)) { $actions['listview'] = array( 'text' => 'view as list', 'class' => $selected, 'href' => $url ); } return true; }
function wfListViewUnknownAction($action,&$article) { global $wgOut,$wgUser,$wgTitle,$wgParser,$egRecordTemplatesCat; if ($action != 'listview') return true;
# Read the valid links into $links array $title = $article->getTitle(); if ($title->getNamespace() == NS_CATEGORY) { $links = array(); $dbr = &wfGetDB(DB_SLAVE); $cl = $dbr->tableName('categorylinks'); $to = $title->getDbKey(); $res = $dbr->select($cl,'cl_from',"cl_to = '$to'",__METHOD__,array('ORDER BY' => 'cl_sortkey')); while ($row = $dbr->fetchRow($res)) { $t = Title::newFromID($row[0]); $u = $t->getLocalURL(); $t = $t->getPrefixedText(); $links[] = array(1 => "<a title=\"$t\" href=\"$u\">$t</a>"); } } else { if (is_object($wgParser)) { $psr = $wgParser; $opt = $wgParser->mOptions; } else { $psr = new Parser; $opt = NULL; } if (!is_object($opt)) $opt = ParserOptions::newFromUser($wgUser); $html = $psr->parse($article->fetchContent(),$title,$opt,true,true)->getText();
preg_match_all("|
<input type=\"checkbox\" /> | $link[1] |
return false; }