Difference between revisions of "Issue:Subpages as sublists"

From FollowTheScore
Jump to: navigation, search
(New page: {{Issue |Type = Change Request |Extension = DPL |Version = ? |Description = How to list subpages as sublists |Status = open }} == Problem == I have a statement lik...)
 
(Reply)
 
(6 intermediate revisions by 2 users not shown)
Line 15: Line 15:
  
 
Now some of the pages in the category are subpages so I get a display like this
 
Now some of the pages in the category are subpages so I get a display like this
 
+
<pre><nowiki>
 
     * [[Greek/Mycenean]]
 
     * [[Greek/Mycenean]]
 
     * [[Greek/Mycenean/Texts]]
 
     * [[Greek/Mycenean/Texts]]
 
     * [[Greek/Mycenean/Writing]]
 
     * [[Greek/Mycenean/Writing]]
 
     * [[Greek/Mycenean/Writing/Syllabary]]
 
     * [[Greek/Mycenean/Writing/Syllabary]]
 
+
</nowiki></pre>
 
* [[Greek/Mycenean]]
 
* [[Greek/Mycenean]]
 
* [[Greek/Mycenean/Texts]]
 
* [[Greek/Mycenean/Texts]]
Line 27: Line 27:
  
 
I would like them to appear as an hierarchical listing
 
I would like them to appear as an hierarchical listing
 
+
<pre><nowiki>
 
     * [[Greek]]
 
     * [[Greek]]
 
     ** [[Greek/Mycenean|Mycenean]]
 
     ** [[Greek/Mycenean|Mycenean]]
     ** [[Greek/Mycenean/Texts|Texts]]
+
     *** [[Greek/Mycenean/Texts|Texts]]
     ** [[Greek/Mycenean/Writing|Writing]]
+
     *** [[Greek/Mycenean/Writing|Writing]]
     *** [[Greek/Mycenean/Writing/Syllabary|Syllabary]]
+
     **** [[Greek/Mycenean/Writing/Syllabary|Syllabary]]
 
+
</nowiki></pre>
 
* [[Greek]]
 
* [[Greek]]
 
** [[Greek/Mycenean|Mycenean]]
 
** [[Greek/Mycenean|Mycenean]]
** [[Greek/Mycenean/Texts|Texts]]
+
*** [[Greek/Mycenean/Texts|Texts]]
** [[Greek/Mycenean/Writing|Writing]]
+
*** [[Greek/Mycenean/Writing|Writing]]
*** [[Greek/Mycenean/Writing/Syllabary|Syllabary]]
+
**** [[Greek/Mycenean/Writing/Syllabary|Syllabary]]
  
N.B. That [[Category:Greek]] would have further subpages [[Greek/Writing]], [[Greek/Dialects]] and whatever which shouldn't appear in a listing of <code>category=Mycenean</code>, but [[Greek]] itself should, as the top page in the category=Mycenean hierarchy is itself a subpage of that page.
+
N.B. That <code><nowiki>[[Category:Greek]]</nowiki></code> would have further subpages <code><nowiki>[[Greek/Writing]]</nowiki></code>, <code><nowiki>[[Greek/Dialects]]</nowiki></code> and whatever which shouldn't appear in a listing of <code>category=Mycenean</code>, but <code><nowiki>[[Greek]]</nowiki></code> itself should, as the top page in the category=Mycenean hierarchy is itself a subpage of that page.
  
As for constructing code which translates the current wikitext into the desired one this Perl regex does the trick:
+
As for constructing code which translates the current wikitext into the desired one this Perl regex does the trick,
 +
except that they don't add the <code><nowiki>[[Greek]]</nowiki></code> top node (There would need to be some check to see if the category named in a <code>category=</code> parameter is itself a subcategory and if so add the supercategory/-ies):
  
 
<pre><nowiki>
 
<pre><nowiki>
 
s{^\*[ ](\[\[.+?([^/]+)\]\])}{  
 
s{^\*[ ](\[\[.+?([^/]+)\]\])}{  
 
     $l = $1;  
 
     $l = $1;  
     $c = ($l =~ s#/#/#g)+1; ## Count the number of slashes in the link and add 1.
+
     $c = ($l =~ s#/#/#g); ## Count the number of slashes in the link and add 1.
 
     $l =~ s#([^/]+)\]\]$#$1\|$1\]\]#;  ## Copy link text
 
     $l =~ s#([^/]+)\]\]$#$1\|$1\]\]#;  ## Copy link text
 
     "\*" x $c  ." ".$l;  ## Print out the right number of asterisks and the link
 
     "\*" x $c  ." ".$l;  ## Print out the right number of asterisks and the link
Line 58: Line 59:
  
 
== Reply ==
 
== Reply ==
 +
 +
May be someone (you??) could write a separate little extension which takes the wiki text of a flat enumeration list and transforms it into an indented enumeration list; the symbol which is being used to recognize the hierarchy (in your case the '/') could be an optional parameter. If there was such an extension it could easily be used from within DPL I think. [[User:Gero|Gero]] 06:51, 22 April 2009 (UTC)
 +
 +
: I guess I could if I was as comfortable with PHP as I am with Perl.  I'm a scholar who has learned to use some Perl to explore my data, not a programmer.  There is also still the problem of superpages (which I mistyped as supercategories) which are not themselves included in the search match.  I think it is not ''really'' so easy as my example regex to modify the wikitext makes it appear.  To get a proper output one still has to gather the hierarchy into a datastructure (I'm thinking a hash of hashes) from which the new HTML list can be constructed, so that one doesn't have to trust that he input is a well-formed, sorted list of pages which all belong to the same subpage hierarchy. I'll write a proof-of concept in Perl and then see if I can translate it into PHP or find someone to do it for me. [[User:Melroch|Melroch]] 11:51, 22 April 2009 (UTC)

Latest revision as of 12:51, 22 April 2009

Description: How to list subpages as sublists
Extension / Version: DPL   /   ?
Type / Status: Change Request   /   open

Problem

I have a statement like this

   <dpl>
   category=Mycenean
   </dpl>

Now some of the pages in the category are subpages so I get a display like this

    * [[Greek/Mycenean]]
    * [[Greek/Mycenean/Texts]]
    * [[Greek/Mycenean/Writing]]
    * [[Greek/Mycenean/Writing/Syllabary]]

I would like them to appear as an hierarchical listing

    * [[Greek]]
    ** [[Greek/Mycenean|Mycenean]]
    *** [[Greek/Mycenean/Texts|Texts]]
    *** [[Greek/Mycenean/Writing|Writing]]
    **** [[Greek/Mycenean/Writing/Syllabary|Syllabary]]

N.B. That [[Category:Greek]] would have further subpages [[Greek/Writing]], [[Greek/Dialects]] and whatever which shouldn't appear in a listing of category=Mycenean, but [[Greek]] itself should, as the top page in the category=Mycenean hierarchy is itself a subpage of that page.

As for constructing code which translates the current wikitext into the desired one this Perl regex does the trick, except that they don't add the [[Greek]] top node (There would need to be some check to see if the category named in a category= parameter is itself a subcategory and if so add the supercategory/-ies):

s{^\*[ ](\[\[.+?([^/]+)\]\])}{ 
    $l = $1; 
    $c = ($l =~ s#/#/#g); ## Count the number of slashes in the link and add 1.
    $l =~ s#([^/]+)\]\]$#$1\|$1\]\]#;  ## Copy link text
    "\*" x $c  ." ".$l;  ## Print out the right number of asterisks and the link
}egm;

This is the concept. A bit harder of course if done on HTML rather than wikitext.

Melroch 10:51, 21 April 2009 (UTC)

Reply

May be someone (you??) could write a separate little extension which takes the wiki text of a flat enumeration list and transforms it into an indented enumeration list; the symbol which is being used to recognize the hierarchy (in your case the '/') could be an optional parameter. If there was such an extension it could easily be used from within DPL I think. Gero 06:51, 22 April 2009 (UTC)

I guess I could if I was as comfortable with PHP as I am with Perl. I'm a scholar who has learned to use some Perl to explore my data, not a programmer. There is also still the problem of superpages (which I mistyped as supercategories) which are not themselves included in the search match. I think it is not really so easy as my example regex to modify the wikitext makes it appear. To get a proper output one still has to gather the hierarchy into a datastructure (I'm thinking a hash of hashes) from which the new HTML list can be constructed, so that one doesn't have to trust that he input is a well-formed, sorted list of pages which all belong to the same subpage hierarchy. I'll write a proof-of concept in Perl and then see if I can translate it into PHP or find someone to do it for me. Melroch 11:51, 22 April 2009 (UTC)