---------- Forwarded Message ----------
Subject: [Wikitech-l] Multiple categories
Date: Sun, 30 May 2004 12:07:09 +0200
From: Nikola Smolenski <smolensk(a)EUnet.yu>
To: Wikimedia developers <wikitech-l(a)Wikipedia.org>
I have made a patch which enables display of all articles that belong to
multiple categories. Thus, for example, Category:Female/Orthodox/Saint would
return all female orthodox saints (that is, all articles which are
categorised with at least [[Category:Female]], [[Category:Orthodox]] and
[[Category:Saint]]).
I am not sure would this make for much greater database load, but that
remains to be seen in practice. Line if(strchr($t,"/")) { and corresponding
else block are actually not needed but I have left them because I figure
that display of a single category is slightly faster this way, and that at
that point it would be easier to turn off this feature if needed. It should
also be easy to limit to number of categories if that turns out to be
neccesary.
Index: Parser.php
===================================================================
RCS file: /cvsroot/wikipedia/phase3/includes/Parser.php,v
retrieving revision 1.135
diff -u -3 -p -r1.135 Parser.php
--- Parser.php 15 May 2004 00:29:07 -0000 1.135
+++ Parser.php 30 May 2004 09:11:00 -0000
@@ -318,7 +318,21 @@ class Parser
# FIXME: add limits
$t = wfStrencode( $this->mTitle->getDBKey() );
- $sql = "SELECT DISTINCT cur_title,cur_namespace FROM
cur,categorylinks WHERE cl_to='$t' AND cl_from=cur_id ORDER BY cl_sortkey" ;
+ $t = preg_replace("'/+'","/",$t);
+ if(strchr($t,"/")) {
+ $ta = explode("/",$t);
+ $tt="cur"; $tw="";
+
+ $i=0;
+ foreach($ta as $v) {
+ $tt.=",categorylinks as cl$i";
+ $tw.="cl$i.cl_to='$v' AND
cl$i.cl_from=cl".++$i.".cl_from AND ";
+ }
+ $tw=preg_replace("' AND
cl[0-9]+[.]cl_from=cl[0-9]+[.]cl_from AND $'U","",$tw);
+ $sql="SELECT DISTINCT cur_title,cur_namespace FROM
$tt WHERE $tw AND cl0.cl_from=cur_id ORDER BY cl0.cl_sortkey";
+ } else {
+ $sql = "SELECT DISTINCT cur_title,cur_namespace FROM
cur,categorylinks WHERE cl_to='$t' AND cl_from=cur_id ORDER BY cl_sortkey" ;
+ }
$res = wfQuery ( $sql, DB_READ ) ;
while ( $x = wfFetchObject ( $res ) ) $data[] = $x ;
_______________________________________________
Wikitech-l mailing list
Wikitech-l(a)Wikipedia.org
http://mail.wikipedia.org/mailman/listinfo/wikitech-l
-------------------------------------------------------