Extension:ListView.php
<?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-16');
$egListViewAction = 'list'; $egRecordTemplatesCat = 'Record_templates'; # DBkey of category that valid record templates are members of
$wgExtensionFunctions[] = 'efSetupListView'; $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 efSetupListView() { global $wgHooks,$wgOut,$wgUser; $wgHooks['SkinTemplateTabs'][] = 'efListViewUpdateActions'; $wgHooks['UnknownAction'][] = 'efListViewUnknownAction'; }
function efListViewUpdateActions(&$skin,&$actions) { global $wgTitle,$wgRequest,$egListViewAction; $selected = $wgRequest->getText('action') == $egListViewAction ? 'selected' : false; $url = $wgTitle->getLocalURL("action=$egListViewAction"); if (is_object($wgTitle)) { $actions[$egListViewAction] = array( 'text' => 'list', # todo: should use wfMsg($egListViewAction) 'class' => $selected, 'href' => $url ); } return true; }
function efListViewUnknownAction($action,&$article) { global $wgOut,$wgUser,$wgTitle,$wgParser,$wgRequest,$egRecordTemplatesCat,$egListViewAction; if ($action != $egListViewAction) return true;
# Get the list of titles if ($wgRequest->getText('template')) {
# Template was specified, list comes from template and query if specified # - also other parameters incl. query=DPL|SMW
} else {
# 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] |
$wgOut->addHtml($pager); return false; }