Index: trunk/extensions/intersection/DynamicPageList2.php |
— | — | @@ -1,9 +1,8 @@ |
2 | 2 | <?php |
3 | | - |
4 | 3 | /* |
5 | 4 | |
6 | 5 | Version: |
7 | | - Hack v0.4 (DynamicPageList2 is based on DynamicPageList) |
| 6 | + Hack v0.5 (DynamicPageList2 is based on DynamicPageList) |
8 | 7 | |
9 | 8 | Purpose:outputs a union of articles residing in a selection |
10 | 9 | of categories and namespaces using configurable output- and |
— | — | @@ -33,27 +32,29 @@ |
34 | 33 | http://www.gnu.org/copyleft/gpl.html |
35 | 34 | |
36 | 35 | 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"); |
39 | 38 | */ |
40 | 39 | |
41 | 40 | |
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 | | - |
49 | 41 | $wgExtensionFunctions[] = "wfDynamicPageList2"; |
50 | 42 | $wgExtensionCredits['parserhook'][] = array( |
51 | 43 | 'name' => 'DynamicPageList2', |
52 | 44 | '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]', |
53 | 45 | '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' |
56 | 48 | ); |
57 | 49 | |
| 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 | + |
58 | 59 | function wfDynamicPageList2() { |
59 | 60 | global $wgParser, $wgMessageCache; |
60 | 61 | |
— | — | @@ -68,12 +69,14 @@ |
69 | 70 | 'dpl2_catoutputwithwrongordermethod' => "DynamicPageList2: You have to use 'ordermethod=title' or 'ordermethod=category' when using category-style output!", |
70 | 71 | 'dpl2_addpagetoucheddatewithwrongordermethod' => "DynamicPageList2: You cannot use 'addpagetoucheddate=true' with 'ordermethod=firstedit' or 'ordermethod=lastedit' or 'ordermethod=categoryadd'.", |
71 | 72 | '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 | + /* |
73 | 77 | TODO: allow 'adduser=true' for other order methods. |
74 | 78 | 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 | + */ |
78 | 81 | $wgParser->setHook( "DPL", "DynamicPageList2" ); |
79 | 82 | } |
80 | 83 | |
— | — | @@ -83,25 +86,19 @@ |
84 | 87 | function DynamicPageList2( $input, $params, &$parser ) { |
85 | 88 | |
86 | 89 | error_reporting(E_ALL); |
87 | | - |
| 90 | + |
| 91 | + global $wgUser, $wgContLang, $wgDPL2MaxCategoryCount, $wgDPL2MinCategoryCount, $wgDPL2MaxResultCount, $wgDPL2AllowUnlimitedCategories, $wgDPL2AllowUnlimitedResults; |
| 92 | + |
88 | 93 | // INVALIDATE CACHE |
89 | 94 | $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; |
98 | 95 | |
99 | 96 | $aParams = array(); |
100 | | - $bCountSet = false; |
101 | 97 | |
102 | 98 | // Default Values |
103 | 99 | $sOrderMethod = 'title'; |
104 | 100 | $sOrder = 'descending'; |
105 | | - $sOutputMode = 'unordered'; |
| 101 | + $sPageOutputMode = 'unordered'; |
| 102 | + $sCatOutputMode = 'unordered'; |
106 | 103 | $sRedirects = 'exclude'; |
107 | 104 | $sInlSymbol = '-'; |
108 | 105 | $bShowNamespace = true; |
— | — | @@ -111,18 +108,18 @@ |
112 | 109 | $bAddEditDate = false; |
113 | 110 | $bAddUser = false; |
114 | 111 | $bAddCategories = false; |
115 | | - |
| 112 | + $bCountSet = false; |
116 | 113 | $aaIncludeCategories = array(); // $aaIncludeCategories is a two 2-dimensional array: Memberarrays are linked using 'AND' |
117 | 114 | $aExcludeCategories = array(); |
118 | 115 | $aNamespaces = array(); |
119 | 116 | |
| 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 | + |
120 | 121 | // ###### PARSE PARAMETERS ###### |
121 | | - |
122 | 122 | $aParams = explode("\n", $input); |
123 | 123 | |
124 | | - $parser = new Parser; |
125 | | - $poptions = new ParserOptions; |
126 | | - |
127 | 124 | foreach($aParams as $sParam) { |
128 | 125 | |
129 | 126 | $aParam = explode("=", $sParam); |
— | — | @@ -137,7 +134,7 @@ |
138 | 135 | $aParams = explode("|", $sArg); |
139 | 136 | foreach($aParams as $sParam) { |
140 | 137 | $sParam=trim($sParam); |
141 | | - $title = Title::newFromText( $parser->transformMsg($sParam, $poptions) ); |
| 138 | + $title = Title::newFromText($localParser->transformMsg($sParam, $poptions)); |
142 | 139 | if( $title != NULL ) |
143 | 140 | $aCategories[] = $title; |
144 | 141 | } |
— | — | @@ -146,7 +143,7 @@ |
147 | 144 | break; |
148 | 145 | |
149 | 146 | case 'notcategory': |
150 | | - $title = Title::newFromText( $parser->transformMsg($sParam, $poptions) ); |
| 147 | + $title = Title::newFromText($localParser->transformMsg($sArg, $poptions)); |
151 | 148 | if( $title != NULL ) |
152 | 149 | $aExcludeCategories[] = $title; |
153 | 150 | break; |
— | — | @@ -158,7 +155,7 @@ |
159 | 156 | $sNS = $wgContLang->getNsIndex($sParam); |
160 | 157 | if ( $sNS != NULL ) |
161 | 158 | $aNamespaces[] = $sNS; |
162 | | - elseif (intval($sParam)>=0) |
| 159 | + elseif (intval($sParam) >= 0) |
163 | 160 | $aNamespaces[] = intval($sParam); |
164 | 161 | } |
165 | 162 | break; |
— | — | @@ -169,12 +166,20 @@ |
170 | 167 | $bCountSet = true; |
171 | 168 | break; |
172 | 169 | |
| 170 | + //mode for list of pages (possibly within a category if 'ordermethod=category', see 'categorymode' parameter) |
173 | 171 | //TODO: solve the issue: addpagetoucheddate, addeditdate, adduser, addcategories have no effect with 'mode=category' |
174 | 172 | case 'mode': |
175 | 173 | if ( in_array($sArg, array('none','ordered','unordered','category','inline')) ) |
176 | | - $sOutputMode = $sArg; |
| 174 | + $sPageOutputMode = $sArg; |
177 | 175 | break; |
178 | 176 | |
| 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 | + |
179 | 184 | case 'inlinesymbol': |
180 | 185 | $sInlSymbol = strip_tags($sArg); |
181 | 186 | break; |
— | — | @@ -265,7 +270,7 @@ |
266 | 271 | return htmlspecialchars( wfMsg( 'dpl2_addmorethanonetypeofdate' ) ); |
267 | 272 | |
268 | 273 | // category-style output requested but not ordermethod=title!! |
269 | | - if ($sOutputMode == 'category' && $sOrderMethod != 'title' && $sOrderMethod != 'category') |
| 274 | + if ($sPageOutputMode == 'category' && $sOrderMethod != 'title' && $sOrderMethod != 'category') |
270 | 275 | return htmlspecialchars( wfMsg( 'dpl2_catoutputwithwrongordermethod' ) ); |
271 | 276 | |
272 | 277 | // addpagetoucheddate=true with unappropriate order methods |
— | — | @@ -303,12 +308,17 @@ |
304 | 309 | $sPageTable = $dbr->tableName( 'page' ); |
305 | 310 | $sSqlPage_touched = ''; |
306 | 311 | $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 = ''; |
310 | 319 | $sRevisionTable = $dbr->tableName( 'revision' ); |
311 | 320 | $sSqlRevision = ''; |
312 | | - $sSqlRev_timestamp = ''; $sSqlRev_user = ''; |
| 321 | + $sSqlRev_timestamp = ''; |
| 322 | + $sSqlRev_user = ''; |
313 | 323 | $sSqlCond_page_rev = ''; |
314 | 324 | |
315 | 325 | switch ($sOrderMethod) { |
— | — | @@ -331,7 +341,7 @@ |
332 | 342 | |
333 | 343 | if ($bAddFirstCategoryDate) |
334 | 344 | //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" |
336 | 346 | $sSqlCl_timestamp = ", DATE_FORMAT( c1.cl_timestamp, '%Y%m%d%H%i%s' ) AS cl_timestamp"; |
337 | 347 | if ($bAddPageTouchedDate) |
338 | 348 | $sSqlPage_touched = ', page_touched'; |
— | — | @@ -344,10 +354,7 @@ |
345 | 355 | } |
346 | 356 | |
347 | 357 | // 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; |
352 | 359 | |
353 | 360 | // JOIN ... |
354 | 361 | if($bAddCategories || $sOrderMethod=='category') { |
— | — | @@ -430,11 +437,10 @@ |
431 | 438 | // ###### PROCESS SQL QUERY ###### |
432 | 439 | $output = ''; |
433 | 440 | //DEBUG: output SQL query |
434 | | - //$output = 'QUERY: [' . $sSqlSelectFrom . $sSqlWhere . "]<br />"; |
| 441 | + //$output .= 'QUERY: [' . $sSqlSelectFrom . $sSqlWhere . "]<br/>"; |
435 | 442 | //echo 'QUERY: [' . $sSqlSelectFrom . $sSqlWhere . "]<br />"; |
436 | 443 | |
437 | 444 | $res = $dbr->query($sSqlSelectFrom . $sSqlWhere); |
438 | | - $sk =& $wgUser->getSkin(); |
439 | 445 | if ($dbr->numRows( $res ) == 0) { |
440 | 446 | if (!$bSuppressErrors) |
441 | 447 | return htmlspecialchars( wfMsg( 'dpl2_noresults' ) ); |
— | — | @@ -442,182 +448,212 @@ |
443 | 449 | return ''; |
444 | 450 | } |
445 | 451 | |
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(); |
451 | 453 | // 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' ); |
456 | 458 | |
| 459 | + $aCategories = array(); |
| 460 | + $aArticles = array(); |
| 461 | + $aArticles_start_char =array(); |
| 462 | + $aAddDates = array(); |
| 463 | + $aAddUsers = array(); |
| 464 | + $aAddCategories = array(); |
457 | 465 | 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; |
463 | 470 | } 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())); |
467 | 473 | } |
468 | | - $aCategories[$row_idx] = "<h2>$catLink</h2>"; // add row index as key where category starts |
469 | | - } |
| 474 | + } else |
| 475 | + $aCategories[] = ''; |
470 | 476 | |
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); |
473 | 479 | if ($bShowNamespace) |
474 | | - $sLink = $sk->makeKnownLinkObj($title); |
| 480 | + $aArticles[] = $sk->makeKnownLinkObj($title); |
475 | 481 | 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())); |
480 | 483 | //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)); |
482 | 485 | |
483 | 486 | //SHOW "PAGE_TOUCHED" DATE, "FIRSTCATEGORYDATE" OR (FIRST/LAST) EDIT DATE |
484 | 487 | if($bAddPageTouchedDate) |
485 | | - $aAddDates[] = $wgLang->date($row->page_touched) . ': '; |
| 488 | + $aAddDates[] = $row->page_touched; |
486 | 489 | elseif ($bAddFirstCategoryDate) |
487 | | - $aAddDates[] = $wgLang->date($row->cl_timestamp) . ': '; |
| 490 | + $aAddDates[] = $row->cl_timestamp; |
488 | 491 | elseif ($bAddEditDate) |
489 | | - $aAddDates[] = $wgLang->date($row->rev_timestamp) . ': '; |
| 492 | + $aAddDates[] = $row->rev_timestamp; |
490 | 493 | else |
491 | 494 | $aAddDates[] = ''; |
492 | 495 | |
493 | 496 | //USER/AUTHOR |
494 | 497 | 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); |
497 | 500 | } 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())); |
500 | 508 | } |
501 | 509 | } else |
502 | 510 | $aAddUsers[] = ''; |
503 | 511 | |
504 | | - //CATEGORY LINKS PER ARTICLE |
| 512 | + //CATEGORY LINKS PER PAGE |
505 | 513 | if(!$bAddCategories || empty($row->cats)) |
506 | 514 | $aAddCategories[] = ''; |
507 | 515 | else { |
508 | 516 | $artCatNames = explode(' | ', $row->cats); |
509 | 517 | $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())); |
513 | 524 | } |
514 | | - $aAddCategories[] = $catsLink.': '.implode(' | ', $artCatLinks); |
| 525 | + $aAddCategories[] = $artCatLinks; |
515 | 526 | } |
516 | | - $row_idx++; |
517 | 527 | } |
518 | 528 | $dbr->freeResult( $res ); |
519 | 529 | |
520 | 530 | |
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)); |
526 | 551 | 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 | + |
529 | 554 | return $output; |
530 | 555 | } |
531 | 556 | |
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; |
533 | 560 | |
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')); |
565 | 565 | |
| 566 | + $mode = new DPL2OutputMode($sOutputMode, $sInlSymbol); |
566 | 567 | //process results of query, outputing equivalent of <li>[[Article]]</li> for each result, |
567 | 568 | //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; |
581 | 581 | } |
582 | | - $r .= $sEndList . "\n"; |
583 | | - |
| 582 | + $r .= $mode->sEndList; |
584 | 583 | return $r; |
585 | 584 | } |
586 | 585 | |
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); |
590 | 592 | 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 | +} |
591 | 601 | |
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 | + } |
618 | 657 | } |
619 | 658 | } |
620 | | - |
621 | | - return $ret; |
622 | 659 | } |
623 | | - |
624 | 660 | ?> |