Issue:Category option that does AND operation to multiple parameters

From FollowTheScore
Revision as of 13:59, 2 March 2008 by Gero (talk | contribs)
Jump to: navigation, search
Description:
Extension / Version: DPL   /   1.6.7
Type / Status: Change Request   /   open

Problem

I made a small enhancement to DPL to support a 'categoryall' option. Given multiple parameters it does an AND operation on them instead of an OR. The reason for doing this is I'm generating the DPL query dynamically and I couldn't see a way of creating multiple 'category' options - it's much easier working with a simple list.

It's a bit simplified compared to 'category' - it doesn't handle the '+', '-' or '*' modifiers, but for your consideration please find the patch below ...

Eclecticdave 14:59, 1 March 2008 (CET)

diff --git a/DynamicPageList2.php b/DynamicPageList2.php
index bc02203..6d391b2 100644
--- a/DynamicPageList2.php
+++ b/DynamicPageList2.php
@@ -344,6 +344,7 @@ class ExtDynamicPageList2
          * @todo define 'category' options (retrieve list of categories from 'categorylinks' table?)
          */
         'category'             => NULL,
+        'categoryall'          => NULL,
         'categorymatch'        => NULL,
         'categoryregexp'       => NULL,
         /**
@@ -1371,6 +1372,17 @@ class ExtDynamicPageList2
                         $bConflictsWithOpenReferences=true;
                     }    
                     break;
+                case 'categoryall':
+                    $aParams = explode('|', $sArg);
+                    foreach($aParams as $sParam) {
+                        $sParam=trim($sParam);
+                        if($sParam == '') {
+                            // Include uncategorized pages
+                            $bIncludeUncat = true;
+                        }
+                        $aIncludeCategories[] = array($sParam);
+                    }
+                    break;
                     
                 case 'notcategoryregexp':
                     $sNotCategoryComparisonMode = ' REGEXP ';
@@ -3933,4 +3945,4 @@ class DPL2Logger {
 
 }
 
-?>
\ No newline at end of file
+?>

Reply

As the manual states (see category) you can have multiple lines with "category="; together they will act as an AND condition. It looks to me as if your change tries to do the same?

Gero 21:32, 1 March 2008 (CET)

Yes, absolutely. The problem comes when I'm trying to autogenerate multiple category= lines using StringFunctions (your modified version with regexp support).

I started with a (non-escaped) template invocation where the category= lines should go and tried using #replace to create them. But you can't put a pipe character in the replacement string of a #replace statement which was causing me headaches with this approach. (Later it occurred to me it might work if #replace supported the \p escape used by CharacterEscapes, but I'd already written categoryall by then :-)

I'm trying to build up a DPL query through the user clicking on a succession of category links. If a concrete example will help, you're welcome to take a look at my website-in-development [1]. Click on one of the categories at the top right of the Main Page to get to the "Category Browser".

Eclecticdave 12:32, 2 March 2008 (CET)
Just a short hint: Putting a pipe in the replacement character of #replace is possible if you use a template to create the pipe symbol:
replacing in 'a,,b,,,c' one or more commas by a single pipe yields: {{#replace:a,b,c|/,+/||}}
source is {{#replace:a,b,c|/,+/|{{!}}}}
Have you seen Template:Catlist? Maybe you can use tghis as a starting point for your category browser ...
Gero 12:52, 2 March 2008 (CET)