r15480 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r15479‎ | r15480 | r15481 >
Date:00:56, 10 July 2006
Author:cdangerville
Status:old
Tags:
Comment:
Release 0.5
+ Renamed $wgDPL2MaxCategoryShortListResultCount to $wgDPL2CategoryStyleListCutoff.
+ Added 'categorymode' option for output mode of category items when pages sorted by category ('ordermethod=category')
Possible values: unordered list (default) (resp. HTML <ul>), ordered list (resp. <ol>), definition list (resp <dd>), section (resp. <h2>), subsection (resp. <h3>), sub-subsection, etc.
+ Fixed bug: use a local parser (not the global one) to parse (if not, 'UNIQ????'-like errors generated) category names given with '(not)category' option
+ Optimization: use of Linker::makeKnownLinkObj() instead of makeLinkObj() whenever possible
+ Changed the way page list is generated with 'ordermethod=category'
+ Added adapted versions of CategoryPage::formatCount() and CategoryPage::formatList()
+ Created DPL2OutputMode class for more flexibility
+ Renamed a few variables to avoid ambiguousness
+ Some code reformatting, simplification
Modified paths:
  • /trunk/extensions/intersection/DynamicPageList2.php (modified) (history)

Diff [purge]

Index: trunk/extensions/intersection/DynamicPageList2.php
@@ -1,9 +1,8 @@
22 <?php
3 -
43 /*
54
65 Version:
7 - Hack v0.4 (DynamicPageList2 is based on DynamicPageList)
 6+ Hack v0.5 (DynamicPageList2 is based on DynamicPageList)
87
98 Purpose:outputs a union of articles residing in a selection
109 of categories and namespaces using configurable output- and
@@ -33,27 +32,29 @@
3433 http://www.gnu.org/copyleft/gpl.html
3534
3635 Installation:
37 - To install, add following to LocalSettings.php
38 - include("extensions/intersection/DynamicPageList2.php");
 36+ Add following to LocalSettings.php:
 37+ include("extensions/intersection/DynamicPageList2.php");
3938 */
4039
4140
42 -$wgDPL2MaxCategoryCount = 4; // Maximum number of categories allowed in the Query
43 -$wgDPL2MinCategoryCount = 0; // Minimum number of categories needed in the Query
44 -$wgDPL2MaxResultCount = 50; // Maximum number of results to allow
45 -$wgDPL2MaxCategoryShortListResultCount = 10; // Maximum number of results to allow for a short list with mode=category, if max exceed, results output in a column list
46 -$wgDPL2AllowUnlimitedCategories = true; // Allow unlimited categories in the Query
47 -$wgDPL2AllowUnlimitedResults = true; // Allow unlimited results to be shown
48 -
4941 $wgExtensionFunctions[] = "wfDynamicPageList2";
5042 $wgExtensionCredits['parserhook'][] = array(
5143 'name' => 'DynamicPageList2',
5244 'author'=>'[http://en.wikinews.org/wiki/User:IlyaHaykinson IlyaHaykinson], [http://en.wikinews.org/wiki/User:Amgine Amgine], [http://de.wikipedia.org/wiki/Benutzer:Unendlich Unendlich], [http://meta.wikimedia.org/wiki/User:Dangerman Cyril Dangerville]',
5345 'url'=>'http://meta.wikimedia.org/wiki/DynamicPageList2',
54 - 'description'=>'hack of the original [http://meta.wikimedia.org/wiki/DynamicPageList DynamicPageList] extension from DynamicPageList featuring many Improvements',
55 - 'version'=>'0.4'
 46+ 'description'=>'hack of the original [http://meta.wikimedia.org/wiki/DynamicPageList DynamicPageList] extension from DynamicPageList featuring many Improvements (requires the [http://meta.wikimedia.org/wiki/User:Joncutrer/Extensions/absHTML AbsHTML extension])',
 47+ 'version'=>'0.5'
5648 );
5749
 50+$wgDPL2MaxCategoryCount = 4; // Maximum number of categories allowed in the Query
 51+$wgDPL2MinCategoryCount = 0; // Minimum number of categories needed in the Query
 52+$wgDPL2MaxResultCount = 50; // Maximum number of results to allow
 53+$wgDPL2CategoryStyleListCutoff = 6; //Max length to format a list of articles chunked by letter as bullet list, if list bigger, columnar format user (same as cutoff arg for CategoryPage::formatList())
 54+// Maximum number of results to allow for a short list with mode=category, if max exceed, results output in a column list
 55+$wgDPL2AllowUnlimitedCategories = true; // Allow unlimited categories in the Query
 56+$wgDPL2AllowUnlimitedResults = true; // Allow unlimited results to be shown
 57+
 58+
5859 function wfDynamicPageList2() {
5960 global $wgParser, $wgMessageCache;
6061
@@ -68,12 +69,14 @@
6970 'dpl2_catoutputwithwrongordermethod' => "DynamicPageList2: You have to use 'ordermethod=title' or 'ordermethod=category' when using category-style output!",
7071 'dpl2_addpagetoucheddatewithwrongordermethod' => "DynamicPageList2: You cannot use 'addpagetoucheddate=true' with 'ordermethod=firstedit' or 'ordermethod=lastedit' or 'ordermethod=categoryadd'.",
7172 'dpl2_addeditdatewithwrongordermethod' => "DynamicPageList2: You have to use 'ordermethod=firstedit' or 'ordermethod=lastedit' when using 'addeditdate=true'.",
72 - 'dpl2_adduserwithwrongordermethod' => "DynamicPageList2: You have to use 'ordermethod=firstedit' or 'ordermethod=lastedit' when using 'adduser=true'.\n
 73+ 'dpl2_adduserwithwrongordermethod' => "DynamicPageList2: You have to use 'ordermethod=firstedit' or 'ordermethod=lastedit' when using 'adduser=true'."
 74+ )
 75+ );
 76+ /*
7377 TODO: allow 'adduser=true' for other order methods.
7478 In fact, a page may be edited by multiple users. Which user(s) should we show? all? the first or the last one?
75 - Suggested solution: use values such as 'all', 'first' or 'last' for the adduser parameter."
76 - )
77 - );
 79+ Suggested solution: use values such as 'all', 'first' or 'last' for the adduser parameter.
 80+ */
7881 $wgParser->setHook( "DPL", "DynamicPageList2" );
7982 }
8083
@@ -83,25 +86,19 @@
8487 function DynamicPageList2( $input, $params, &$parser ) {
8588
8689 error_reporting(E_ALL);
87 -
 90+
 91+ global $wgUser, $wgContLang, $wgDPL2MaxCategoryCount, $wgDPL2MinCategoryCount, $wgDPL2MaxResultCount, $wgDPL2AllowUnlimitedCategories, $wgDPL2AllowUnlimitedResults;
 92+
8893 // INVALIDATE CACHE
8994 $parser->disableCache();
90 -
91 - global $wgTitle;
92 - global $wgOut;
93 - global $wgUser;
94 - global $wgLang;
95 - global $wgContLang;
96 - global $wgDPL2MaxCategoryCount, $wgDPL2MinCategoryCount, $wgDPL2MaxResultCount;
97 - global $wgDPL2AllowUnlimitedCategories, $wgDPL2AllowUnlimitedResults;
9895
9996 $aParams = array();
100 - $bCountSet = false;
10197
10298 // Default Values
10399 $sOrderMethod = 'title';
104100 $sOrder = 'descending';
105 - $sOutputMode = 'unordered';
 101+ $sPageOutputMode = 'unordered';
 102+ $sCatOutputMode = 'unordered';
106103 $sRedirects = 'exclude';
107104 $sInlSymbol = '-';
108105 $bShowNamespace = true;
@@ -111,18 +108,18 @@
112109 $bAddEditDate = false;
113110 $bAddUser = false;
114111 $bAddCategories = false;
115 -
 112+ $bCountSet = false;
116113 $aaIncludeCategories = array(); // $aaIncludeCategories is a two 2-dimensional array: Memberarrays are linked using 'AND'
117114 $aExcludeCategories = array();
118115 $aNamespaces = array();
119116
 117+ //Local parser created. See http://meta.wikimedia.org/wiki/MediaWiki_extensions_FAQ#How_do_I_render_wikitext_in_my_extension.3F
 118+ $localParser = new Parser();
 119+ $poptions = $parser->mOptions;
 120+
120121 // ###### PARSE PARAMETERS ######
121 -
122122 $aParams = explode("\n", $input);
123123
124 - $parser = new Parser;
125 - $poptions = new ParserOptions;
126 -
127124 foreach($aParams as $sParam) {
128125
129126 $aParam = explode("=", $sParam);
@@ -137,7 +134,7 @@
138135 $aParams = explode("|", $sArg);
139136 foreach($aParams as $sParam) {
140137 $sParam=trim($sParam);
141 - $title = Title::newFromText( $parser->transformMsg($sParam, $poptions) );
 138+ $title = Title::newFromText($localParser->transformMsg($sParam, $poptions));
142139 if( $title != NULL )
143140 $aCategories[] = $title;
144141 }
@@ -146,7 +143,7 @@
147144 break;
148145
149146 case 'notcategory':
150 - $title = Title::newFromText( $parser->transformMsg($sParam, $poptions) );
 147+ $title = Title::newFromText($localParser->transformMsg($sArg, $poptions));
151148 if( $title != NULL )
152149 $aExcludeCategories[] = $title;
153150 break;
@@ -158,7 +155,7 @@
159156 $sNS = $wgContLang->getNsIndex($sParam);
160157 if ( $sNS != NULL )
161158 $aNamespaces[] = $sNS;
162 - elseif (intval($sParam)>=0)
 159+ elseif (intval($sParam) >= 0)
163160 $aNamespaces[] = intval($sParam);
164161 }
165162 break;
@@ -169,12 +166,20 @@
170167 $bCountSet = true;
171168 break;
172169
 170+ //mode for list of pages (possibly within a category if 'ordermethod=category', see 'categorymode' parameter)
173171 //TODO: solve the issue: addpagetoucheddate, addeditdate, adduser, addcategories have no effect with 'mode=category'
174172 case 'mode':
175173 if ( in_array($sArg, array('none','ordered','unordered','category','inline')) )
176 - $sOutputMode = $sArg;
 174+ $sPageOutputMode = $sArg;
177175 break;
178176
 177+ //mode at the category level, used with ordermethod=category only:
 178+ //ordered, unordered, definition list, or section, subsection, sub-subsection, etc.
 179+ case 'categorymode':
 180+ if ( in_array($sArg, array('ordered','unordered','definition')) || preg_match('/^((sub-)*sub)?section$/', $sArg))
 181+ $sCatOutputMode = $sArg;
 182+ break;
 183+
179184 case 'inlinesymbol':
180185 $sInlSymbol = strip_tags($sArg);
181186 break;
@@ -265,7 +270,7 @@
266271 return htmlspecialchars( wfMsg( 'dpl2_addmorethanonetypeofdate' ) );
267272
268273 // category-style output requested but not ordermethod=title!!
269 - if ($sOutputMode == 'category' && $sOrderMethod != 'title' && $sOrderMethod != 'category')
 274+ if ($sPageOutputMode == 'category' && $sOrderMethod != 'title' && $sOrderMethod != 'category')
270275 return htmlspecialchars( wfMsg( 'dpl2_catoutputwithwrongordermethod' ) );
271276
272277 // addpagetoucheddate=true with unappropriate order methods
@@ -303,12 +308,17 @@
304309 $sPageTable = $dbr->tableName( 'page' );
305310 $sSqlPage_touched = '';
306311 $sCategorylinksTable = $dbr->tableName( 'categorylinks' );
307 - $sSqlCl_to = ''; $sSqlCats = ''; $sSqlCl_timestamp = '';
308 - $sSqlCl1Table = ''; $sSqlCond_page_cl1 = '';
309 - $sSqlCl2Table = ''; $sSqlCond_page_cl2 = '';
 312+ $sSqlCl_to = '';
 313+ $sSqlCats = '';
 314+ $sSqlCl_timestamp = '';
 315+ $sSqlCl1Table = '';
 316+ $sSqlCond_page_cl1 = '';
 317+ $sSqlCl2Table = '';
 318+ $sSqlCond_page_cl2 = '';
310319 $sRevisionTable = $dbr->tableName( 'revision' );
311320 $sSqlRevision = '';
312 - $sSqlRev_timestamp = ''; $sSqlRev_user = '';
 321+ $sSqlRev_timestamp = '';
 322+ $sSqlRev_user = '';
313323 $sSqlCond_page_rev = '';
314324
315325 switch ($sOrderMethod) {
@@ -331,7 +341,7 @@
332342
333343 if ($bAddFirstCategoryDate)
334344 //format cl_timestamp field (type timestamp) to string in same format as rev_timestamp field
335 - //to make it compatible with $wgLang->date() function used later to show "firstcategorydate"
 345+ //to make it compatible with $wgLang->date() function used in function DPL2OutputListStyle() to show "firstcategorydate"
336346 $sSqlCl_timestamp = ", DATE_FORMAT( c1.cl_timestamp, '%Y%m%d%H%i%s' ) AS cl_timestamp";
337347 if ($bAddPageTouchedDate)
338348 $sSqlPage_touched = ', page_touched';
@@ -344,10 +354,7 @@
345355 }
346356
347357 // SELECT ... FROM
348 - if ($iTotalIncludeCatCount == 1)
349 - $sSqlSelectFrom = "SELECT DISTINCT " . $sSqlCl_to . "page_namespace, page_title" . $sSqlPage_touched . $sSqlRev_timestamp . $sSqlRev_user . $sSqlCats . $sSqlCl_timestamp . " FROM " . $sSqlRevision . $sPageTable;
350 - else
351 - $sSqlSelectFrom = "SELECT DISTINCT " . $sSqlCl_to . "page_namespace, page_title" . $sSqlPage_touched . $sSqlRev_timestamp . $sSqlRev_user . $sSqlCats . " FROM " . $sSqlRevision . $sPageTable;
 358+ $sSqlSelectFrom = "SELECT DISTINCT " . $sSqlCl_to . "page_namespace, page_title" . $sSqlPage_touched . $sSqlRev_timestamp . $sSqlRev_user . $sSqlCats . $sSqlCl_timestamp . " FROM " . $sSqlRevision . $sPageTable;
352359
353360 // JOIN ...
354361 if($bAddCategories || $sOrderMethod=='category') {
@@ -430,11 +437,10 @@
431438 // ###### PROCESS SQL QUERY ######
432439 $output = '';
433440 //DEBUG: output SQL query
434 - //$output = 'QUERY: [' . $sSqlSelectFrom . $sSqlWhere . "]<br />";
 441+ //$output .= 'QUERY: [' . $sSqlSelectFrom . $sSqlWhere . "]<br/>";
435442 //echo 'QUERY: [' . $sSqlSelectFrom . $sSqlWhere . "]<br />";
436443
437444 $res = $dbr->query($sSqlSelectFrom . $sSqlWhere);
438 - $sk =& $wgUser->getSkin();
439445 if ($dbr->numRows( $res ) == 0) {
440446 if (!$bSuppressErrors)
441447 return htmlspecialchars( wfMsg( 'dpl2_noresults' ) );
@@ -442,182 +448,212 @@
443449 return '';
444450 }
445451
446 - // generate link to Special:Contributions (used if adduser=true)
447 - $contribsPage =& Title::makeTitle( NS_SPECIAL, 'Contributions' );
448 - // generate link to Special:Categories (used if addcategories=true)
449 - $catsPage = & Title::makeTitle( NS_SPECIAL, 'Categories' );
450 - $catsLink = $sk->makeLinkObj( $catsPage, $catsPage->getText() );
 452+ $sk =& $wgUser->getSkin();
451453 // generate link to Special:Uncategorizedpages (used if ordermethod=category)
452 - $uncatPage = & Title::makeTitle( NS_SPECIAL, 'Uncategorizedpages' );
453 - $uncatLink = $sk->makeLinkObj( $uncatPage, wfMsg('uncategorizedpages') );
454 - $aCategories = array(); //maps index of category start (in page list) to category link/heading (string)
455 - $row_idx = 0;
 454+ $tSpecUncat = & Title::makeTitle( NS_SPECIAL, 'Uncategorizedpages' );
 455+ $sSpecUncatLnk = $sk->makeKnownLinkObj( $tSpecUncat, wfMsg('uncategorizedpages') );
 456+ // generate title for Special:Contributions (used if adduser=true)
 457+ $tSpecContribs =& Title::makeTitle( NS_SPECIAL, 'Contributions' );
456458
 459+ $aCategories = array();
 460+ $aArticles = array();
 461+ $aArticles_start_char =array();
 462+ $aAddDates = array();
 463+ $aAddUsers = array();
 464+ $aAddCategories = array();
457465 while( $row = $dbr->fetchObject ( $res ) ) {
458 - //CATEGORY LINKS IN HEADINGS IF ORDER BY CATEGORY
459 - if ( ($sOrderMethod=='category') && ( !isset($curCat) || (!empty($row) && ($row->cl_to!=$curCat)) ) ) { //first line (no current category) or new category (or uncategorized) begins -> get category link
460 - if(empty($row->cl_to)) { //uncategorized pages
461 - $curCat= '';
462 - $catLink = $uncatLink;
 466+ //CATEGORY LINKED TO (per page) IF ORDER BY CATEGORY
 467+ if($sOrderMethod == 'category') {
 468+ if(empty($row->cl_to)) { //uncategorized page
 469+ $aCategories[] = $sSpecUncatLnk;
463470 } else {
464 - $curCat = $row->cl_to;
465 - $catPage = & Title::makeTitle(NS_CATEGORY, $curCat);
466 - $catLink = $sk->makeLinkObj( $catPage, $catPage->gettext() );
 471+ $tCat = & Title::makeTitle(NS_CATEGORY, $row->cl_to);
 472+ $aCategories[] = $sk->makeKnownLinkObj($tCat, $wgContLang->convertHtml($tCat->getText()));
467473 }
468 - $aCategories[$row_idx] = "<h2>$catLink</h2>"; // add row index as key where category starts
469 - }
 474+ } else
 475+ $aCategories[] = '';
470476
471 - //NAMESPACE IN ARTICLE LINK
472 - $title = Title::makeTitle( $row->page_namespace, $row->page_title);
 477+ //PAGE LINK
 478+ $title = & Title::makeTitle($row->page_namespace, $row->page_title);
473479 if ($bShowNamespace)
474 - $sLink = $sk->makeKnownLinkObj($title);
 480+ $aArticles[] = $sk->makeKnownLinkObj($title);
475481 else
476 - $sLink = $sk->makeKnownLinkObj($title, $wgContLang->convertHtml($title->getText()));
477 -
478 - //ARTICLE LINK
479 - $aArticles[] = $sLink;
 482+ $aArticles[] = $sk->makeKnownLinkObj($title, $wgContLang->convertHtml($title->getText()));
480483 //get first char used for category-style output
481 - $aArticles_start_char[] = $wgContLang->convert( $wgContLang->firstChar($row->page_title) );
 484+ $aArticles_start_char[] = $wgContLang->convert($wgContLang->firstChar($row->page_title));
482485
483486 //SHOW "PAGE_TOUCHED" DATE, "FIRSTCATEGORYDATE" OR (FIRST/LAST) EDIT DATE
484487 if($bAddPageTouchedDate)
485 - $aAddDates[] = $wgLang->date($row->page_touched) . ': ';
 488+ $aAddDates[] = $row->page_touched;
486489 elseif ($bAddFirstCategoryDate)
487 - $aAddDates[] = $wgLang->date($row->cl_timestamp) . ': ';
 490+ $aAddDates[] = $row->cl_timestamp;
488491 elseif ($bAddEditDate)
489 - $aAddDates[] = $wgLang->date($row->rev_timestamp) . ': ';
 492+ $aAddDates[] = $row->rev_timestamp;
490493 else
491494 $aAddDates[] = '';
492495
493496 //USER/AUTHOR
494497 if($bAddUser) {
495 - if ( 0 == $row->rev_user ) {
496 - $aAddUsers[] = ' . . ' . $sk->makeLinkObj( $contribsPage, $row->rev_user_text, 'target=' . $row->rev_user_text );
 498+ if($row->rev_user == 0) { //anonymous user
 499+ $aAddUsers[] = $sk->makeKnownLinkObj($tSpecContribs, $row->rev_user_text, 'target=' . $row->rev_user_text);
497500 } else {
498 - $userPage =& Title::makeTitle( NS_USER, $row->rev_user_text );
499 - $aAddUsers[] = ' . . ' . $sk->makeLinkObj( $userPage, htmlspecialchars( $row->rev_user_text ) );
 501+ $tUser =& Title::makeTitle( NS_USER, $row->rev_user_text );
 502+ /*
 503+ The user's page may not exist (->"bad" red link), makeLinkObj() executes a DB query to check that out
 504+ TODO: optimize with a LinkBatch on the user titles to get good (user page exists) and bad links,
 505+ then use makeKnownLinkObj() for good links (user page exists), makeBrokenLinkObj() on bad ones
 506+ */
 507+ $aAddUsers[] = $sk->makeLinkObj($tUser, $wgContLang->convertHtml($tUser->getText()));
500508 }
501509 } else
502510 $aAddUsers[] = '';
503511
504 - //CATEGORY LINKS PER ARTICLE
 512+ //CATEGORY LINKS PER PAGE
505513 if(!$bAddCategories || empty($row->cats))
506514 $aAddCategories[] = '';
507515 else {
508516 $artCatNames = explode(' | ', $row->cats);
509517 $artCatLinks = array();
510 - foreach($artCatNames as $catName) {
511 - $catPage = & Title::makeTitle(NS_CATEGORY, $catName);
512 - $artCatLinks[] = $sk->makeLinkObj( $catPage, $catPage->getText() );
 518+ foreach($artCatNames as $artCatName) {
 519+ $tArtCat = & Title::makeTitle(NS_CATEGORY, $artCatName);
 520+ /*
 521+ TODO: see TODO comment for user pages above
 522+ */
 523+ $artCatLinks[] = $sk->makeLinkObj($tArtCat, $wgContLang->convertHtml($tArtCat->getText()));
513524 }
514 - $aAddCategories[] = $catsLink.': '.implode(' | ', $artCatLinks);
 525+ $aAddCategories[] = $artCatLinks;
515526 }
516 - $row_idx++;
517527 }
518528 $dbr->freeResult( $res );
519529
520530
521 -// ###### SHOW OUTPUT ######
522 -//(String concatenation for output in case the lines for debugging SQL query are used.
523 -//See above for these lines.)
524 - if ($sOutputMode == 'category')
525 - $output .= DPL2OutputCategoryStyle( $aCategories, $aArticles, $aArticles_start_char );
 531+// ###### SHOW OUTPUT ######
 532+ if($sOrderMethod == 'category') {
 533+ $catMode = new DPL2OutputMode($sCatOutputMode);
 534+ $aCatCounts = array_count_values($aCategories); //count articles per category
 535+ $output .= $catMode->sStartList;
 536+ $catStart = 0;
 537+ foreach($aCatCounts as $cat => $catCount) {
 538+ $output .= $catMode->sStartItem;
 539+ $output .= $catMode->sStartHeading . $cat . $catMode->sEndHeading;
 540+ $output .= '<p>' . DPL2FormatCount($catCount, 'categoryarticlecount') . '</p>';
 541+ if ($sPageOutputMode == 'category')
 542+ $output .= DPL2OutputCategoryStyle($aArticles, $aArticles_start_char, $catStart, $catCount);
 543+ else
 544+ $output .= DPL2OutputListStyle($aArticles, $aAddDates, $aAddUsers, $aAddCategories, $sPageOutputMode, $sInlSymbol, $catStart, $catCount);
 545+ $output .= $catMode->sEndItem;
 546+ $catStart += $catCount;
 547+ }
 548+ $output .= $catMode->sEndList;
 549+ } elseif($sPageOutputMode == 'category')
 550+ $output .= DPL2OutputCategoryStyle($aArticles, $aArticles_start_char, 0, count($aArticles));
526551 else
527 - $output .= DPL2OutputListStyle( $aCategories, $aArticles, $aAddDates, $aAddUsers, $aAddCategories, $sOutputMode, $sInlSymbol );
528 -
 552+ $output .= DPL2OutputListStyle($aArticles, $aAddDates, $aAddUsers, $aAddCategories, $sPageOutputMode, $sInlSymbol, 0, count($aArticles));
 553+
529554 return $output;
530555 }
531556
532 -function DPL2OutputListStyle ($aCategories, $aArticles, $aAddDates, $aAddUsers, $aAddCategories, $sOutputMode, $sInlSymbol ) {
 557+
 558+function DPL2OutputListStyle ($aArticles, $aAddDates, $aAddUsers, $aAddCategories, $sOutputMode, $sInlSymbol, $iStart, $iCount) {
 559+ global $wgUser, $wgLang;
533560
534 - switch ($sOutputMode) {
535 - case 'none':
536 - $sStartList = '';
537 - $sEndList = '';
538 - $sStartItem = '';
539 - $sEndItem = '<br />';
540 - $bAddLastEndItem = false;
541 - break;
542 - case 'inline':
543 - $sStartList = '';
544 - $sEndList = '';
545 - $sStartItem = '';
546 - $sEndItem = ' ' . $sInlSymbol . ' ';
547 - $bAddLastEndItem=false;
548 - break;
549 - case 'ordered':
550 - $sStartList = '<ol>';
551 - $sEndList = '</ol>';
552 - $sStartItem = '<li>';
553 - $sEndItem = '</li>';
554 - $bAddLastEndItem=true;
555 - break;
556 - case 'unordered':
557 - default:
558 - $sStartList = '<ul>';
559 - $sEndList = '</ul>';
560 - $sStartItem = '<li>';
561 - $sEndItem = '</li>';
562 - $bAddLastEndItem=true;
563 - break;
564 - }
 561+ $sk = & $wgUser->getSkin();
 562+ // generate link to Special:Categories (used if addcategories=true)
 563+ $tSpecCats = & Title::makeTitle( NS_SPECIAL, 'Categories' );
 564+ $sSpecCatsLnk = $sk->makeKnownLinkObj( $tSpecCats, wfMsg('categories'));
565565
 566+ $mode = new DPL2OutputMode($sOutputMode, $sInlSymbol);
566567 //process results of query, outputing equivalent of <li>[[Article]]</li> for each result,
567568 //or something similar if the list uses other startlist/endlist;
568 - $r = $sStartList . "\n";
569 - for ($i=0; $i<count($aArticles); $i++) {
570 - if(isset($aCategories[$i])) //if this is index of category start
571 - $r .= $sEndList."\n".$aCategories[$i]."\n".$sStartList . "\n";
572 - $r .= $sStartItem . $aAddDates[$i] . $aArticles[$i] . $aAddUsers[$i];
573 - if(!empty($aAddCategories[$i])) {
574 - if($sOutputMode=='inline' || $sOutputMode=='none')
575 - $r .= '<font size=-2> ('.$aAddCategories[$i].')</font>';
576 - else $r .= '<font size=-2><br />'.$aAddCategories[$i].'</font>';
577 - }
578 - if ($i<count($aArticles)-1 || $bAddLastEndItem==true)
579 - $r .= $sEndItem;
580 - $r .= "\n";
 569+ $r = $mode->sStartList;
 570+ for ($i = $iStart; $i < $iStart+$iCount; $i++) {
 571+ $r .= $mode->sStartItem;
 572+ if(!empty($aAddDates[$i]))
 573+ $r .= $wgLang->date($aAddDates[$i]) . ': ';
 574+ $r .= $aArticles[$i];
 575+ if(!empty($aAddUsers[$i]))
 576+ $r .= ' . . ' . $aAddUsers[$i];
 577+ if(!empty($aAddCategories[$i]))
 578+ $r .= ' . . <small>' . $sSpecCatsLnk . ': ' . implode(' | ', $aAddCategories[$i]) . '</small>';
 579+ if( (($mode->name != 'inline') && ($mode->name != 'none')) || ($i < $iCount-1)) //no inline symbol (inline mode) at end of list
 580+ $r .= $mode->sEndItem;
581581 }
582 - $r .= $sEndList . "\n";
583 -
 582+ $r .= $mode->sEndList;
584583 return $r;
585584 }
586585
587 -function DPL2OutputCategoryStyle($aCategories, $aArticles, $aArticles_start_char) {
588 -
589 - global $wgDPL2MaxCategoryShortListResultCount;
 586+//slightly different from CategoryPage::formatList() (no need to instantiate a CategoryPage object)
 587+function DPL2OutputCategoryStyle($aArticles, $aArticles_start_char, $iStart, $iCount) {
 588+ global $wgDPL2CategoryStyleListCutoff;
 589+
 590+ $subaArticles = array_slice($aArticles, $iStart, $iCount);
 591+ $subaArticles_start_char = array_slice($aArticles_start_char, $iStart, $iCount);
590592 require_once ('CategoryPage.php');
 593+ if ( count ( $subaArticles ) > $wgDPL2CategoryStyleListCutoff ) {
 594+ return CategoryPage::columnList( $subaArticles, $subaArticles_start_char );
 595+ } elseif ( count($subaArticles) > 0) {
 596+ // for short lists of articles in categories.
 597+ return CategoryPage::shortList( $subaArticles, $subaArticles_start_char );
 598+ }
 599+ return '';
 600+}
591601
592 - if(empty($aCategories)) {
593 - $ret = count ($aArticles).' article(s) listed.';
594 - //You can decide to uncomment the line below and use it instead of the previous one, more generic.
595 - //However, this message makes sense only if category parameter is used, and with one category.
596 - // $ret = CategoryPage::formatCount( $aArticles, 'categoryarticlecount' );
597 - if ( count ($aArticles) > $wgDPL2MaxCategoryShortListResultCount )
598 - $ret .= CategoryPage::columnList( $aArticles, $aArticles_start_char );
599 - elseif ( count($aArticles) > 0)
600 - $ret .= CategoryPage::shortList( $aArticles, $aArticles_start_char );
601 - } else {
602 - $aCatStarts = array_keys($aCategories);
603 - $ret = '';
604 - foreach($aCatStarts as $i => $catStart) {
605 - $ret .= $aCategories[$catStart]."\n";
606 - if($i==count($aCatStarts)-1) {
607 - $aCatArticles = array_slice($aArticles, $catStart);
608 - $aCatArticles_start_char = array_slice($aArticles_start_char, $catStart);
609 - } else {
610 - $aCatArticles = array_slice($aArticles, $catStart, $aCatStarts[$i+1] - $catStart);
611 - $aCatArticles_start_char = array_slice($aArticles_start_char, $catStart, $aCatStarts[$i+1] - $catStart);
612 - }
613 - $ret .= CategoryPage::formatCount( $aCatArticles, 'categoryarticlecount' );
614 - if ( count ($aCatArticles) > $wgDPL2MaxCategoryShortListResultCount )
615 - $ret .= CategoryPage::columnList( $aCatArticles, $aCatArticles_start_char );
616 - elseif ( count($aCatArticles) > 0)
617 - $ret .= CategoryPage::shortList( $aCatArticles, $aCatArticles_start_char );
 602+
 603+//slightly different from CategoryPage::formatCount() (first argument is the number not an array)
 604+function DPL2FormatCount( $numart, $message ) {
 605+ global $wgContLang;
 606+ if( $numart == 1 ) {
 607+ # Slightly different message to avoid silly plural
 608+ $message .= '1';
 609+ }
 610+ return wfMsg( $message, $wgContLang->formatNum( $numart ) );
 611+}
 612+
 613+
 614+class DPL2OutputMode {
 615+ var $name;
 616+ var $sStartList = '';
 617+ var $sEndList = '';
 618+ var $sStartHeading = '';
 619+ var $sEndHeading = '';
 620+ var $sStartItem = '';
 621+ var $sEndItem = '';
 622+
 623+ function DPL2OutputMode($outputmode, $inlinesymbol = '-') {
 624+ $this->name = $outputmode;
 625+ switch ($outputmode) {
 626+ case 'none':
 627+ $this->sEndItem = '<br/>';
 628+ break;
 629+ case 'inline':
 630+ $this->sEndItem = ' ' . $inlinesymbol . ' ';
 631+ break;
 632+ case 'ordered':
 633+ $this->sStartList = '<ol>';
 634+ $this->sEndList = '</ol>';
 635+ $this->sStartItem = '<li>';
 636+ $this->sEndItem = '</li>';
 637+ break;
 638+ case 'unordered':
 639+ $this->sStartList = '<ul>';
 640+ $this->sEndList = '</ul>';
 641+ $this->sStartItem = '<li>';
 642+ $this->sEndItem = '</li>';
 643+ break;
 644+ case 'definition':
 645+ $this->sStartList = '<dl>';
 646+ $this->sEndList = '</dl>';
 647+ $this->sStartHeading = '<dt>';
 648+ $this->sEndHeading = '</dt><dd>';
 649+ $this->sEndItem = '</dd>';
 650+ break;
 651+ default:
 652+ if(preg_match('/^((sub-)*sub)?section$/', $outputmode)) {
 653+ $level = 2 + preg_match_all('/sub/', $outputmode, $matches);
 654+ $this->sStartHeading = '<h' . $level . '>';
 655+ $this->sEndHeading = '</h' . $level . '>';
 656+ }
618657 }
619658 }
620 -
621 - return $ret;
622659 }
623 -
624660 ?>

Status & tagging log