Difference between revisions of "Extension:ListView.php"

From Organic Design wiki
(New page: <?php # Extension:ListView{{Category:E...)
 
Line 53: Line 53:
 
$u = $t->getLocalURL();
 
$u = $t->getLocalURL();
 
$t = $t->getPrefixedText();
 
$t = $t->getPrefixedText();
$links[] = array("<a title=\"$t\" href=\"$u\">$t</a>");
+
$links[] = array(1 => "<a title=\"$t\" href=\"$u\">$t</a>");
 
}
 
}
 
}
 
}
Line 61: Line 61:
 
if (!is_object($opt)) $opt = ParserOptions::newFromUser($wgUser);
 
if (!is_object($opt)) $opt = ParserOptions::newFromUser($wgUser);
 
$html = $psr->parse($article->fetchContent(),$title,$opt,true,true)->getText();
 
$html = $psr->parse($article->fetchContent(),$title,$opt,true,true)->getText();
preg_match_all("|<li>\\s*(<a title=[\"'](.*?)[\"'].+?>(.+?)</a>)\\s*<\\/li>|s",$html,$links,PREG_SET_ORDER);
+
preg_match_all("|<li>\\s*(<a[^>]+title=[\"'](.*?)[\"'][^>]*>(.+?)</a>)|s",$html,$links,PREG_SET_ORDER);
 
}
 
}
  
Line 72: Line 72:
 
$wgOut->addHtml("<tr class=\"$class\">");
 
$wgOut->addHtml("<tr class=\"$class\">");
 
$wgOut->addHtml("<td><input type=\"checkbox\" /></td>");
 
$wgOut->addHtml("<td><input type=\"checkbox\" /></td>");
$wgOut->addHtml("<td>$link[0]</td>");
+
$wgOut->addHtml("<td>$link[1]</td>");
 
$wgOut->addHtml("</tr>\n");
 
$wgOut->addHtml("</tr>\n");
 
}
 
}

Revision as of 10:26, 16 April 2008

<?php

  1. Extension:ListView
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: 2008-04-16

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

define('LISTVIEW_VERSION','0.0.0, 2008-04-16');

$wgExtensionFunctions[] = 'wfSetupListView'; $wgExtensionCredits['other'][] = array( 'name' => 'ListView', 'author' => 'User:Nad', 'description' => 'Replaces the "view source" action with "edit" which links to login page.', '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; if ($action != 'listview') return true;

$title = $article->getTitle(); if ($title->getNamespace() == NS_CATEGORY) { $links = array(); $dbr = &wfGetDB(DB_SLAVE); $cl = $dbr->tableName('categorylinks'); $to = $title->getText(); $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("|

  • \\s*(<a[^>]+title=[\"'](.*?)[\"'][^>]*>(.+?)</a>)|s",$html,$links,PREG_SET_ORDER); } $wgOut->setPageTitle($title); $wgOut->addHtml("\n"); $class = 'even'; foreach ($links as $link) { $class = $class == 'even' ? 'odd' : 'even'; $wgOut->addHtml(""); $wgOut->addHtml(""); $wgOut->addHtml(""); $wgOut->addHtml("\n"); } $wgOut->addHtml("
    <input type=\"checkbox\" />$link[1]
    \n");

    return false; }