Difference between revisions of "Transclusionism"

From Mondothèque

Line 12: Line 12:
 
The section code is used by the 'Labeled Section Transclusion' extension, which looks for the tagged sections in a text, to transclude them into another text based on the assigned labels.
 
The section code is used by the 'Labeled Section Transclusion' extension, which looks for the tagged sections in a text, to transclude them into another text based on the assigned labels.
 
The <code><nowiki>{{RT|rawdata}}<section begin=rawdata /> </nowiki></code> instead, transcludes the RT Template, substituting the word <code>rawdata</code> in its internal code, in place of <code>{{{1}}}</code>. This is the commented content of Template:RT:
 
The <code><nowiki>{{RT|rawdata}}<section begin=rawdata /> </nowiki></code> instead, transcludes the RT Template, substituting the word <code>rawdata</code> in its internal code, in place of <code>{{{1}}}</code>. This is the commented content of Template:RT:
<pre><nowiki><div class="side">                                         #  Puts the trancluded sections on its own div;
+
<pre><nowiki><div class="side">                                   #  Puts the trancluded sections on its own div;
{{#ask:[[Category:{{{1}}}]] |format=array |name=results}}  # Searches semantically for all the pages in
+
                                                    #
                                                            # the requested category, puts them in an array;  
+
{{#ask:                                             #  Searches semantically for all the pages in
{{#loop: looper                                             #  Starts a loop,
+
  [[Category:{{{1}}}]]|format=array | name=results  # the requested category, puts them in an array;  
  | 0                                                       #  Going from 0 to
+
}}                                                  #
  | {{#arraysize: results}}                                 #  the amount of pages of the array, that:
+
{{#loop: looper                                     #  Starts a loop,
  | {{#ifeq: {{FULLPAGENAME:                               Checks if the pagename
+
| 0                                                 #  Going from 0 to
       {{#arrayindex: results | {{#var:looper}}  }}         #   Of the current element of the array
+
| {{#arraysize: results}}                           #  the amount of pages of the array, that:
            }}  
+
| {{#ifeq: {{FULLPAGENAME:                         If the pagename
  |   {{FULLPAGENAME}}                                     #   Is the same as the page calling the loop,
+
       {{#arrayindex: results | {{#var:looper}}  }} #   of the current element of the array
  |     #   In that case it skips it (no selfreference);
+
            }}                                       #
  |   {{#lst: {{#arrayindex: results | {{#var:looper}}  }} #   Searches through the page in the loop for
+
|         {{FULLPAGENAME}}                         #   is the same as the page calling the loop,
  | {{{1}}} }}                                             #   All the occurrences of labeled sections
+
|                     #     It will skip the page (no self-reference);
([[{{#arrayindex: results | {{#var:looper}}  }}]])<br /><br />  
+
|           {{#lst:                                 #    Otherwise it searches through the
}}
+
{{#arrayindex: results | {{#var:looper}}  }} #     current page in the loop for
}}</div>[[category:{{{1}}}]]
+
| {{{1}}}   }}                                     #     all the occurrences of labeled sections
 +
([[{{#arrayindex: results | {{#var:looper}}  }}]])   #    Adds the name of the current page in loop;
 +
<br /><br />                                         #    Adds some space after the page;
 +
}}                                                   #  End of pagename check;
 +
}}                                                   #  End of loop;
 +
</div>                                               #  Closes div;
 +
[[category:{{{1}}}]]                                 #  Adds the page to the label category.
 
</nowiki></pre>
 
</nowiki></pre>
  

Revision as of 10:41, 27 February 2016

This page documents some of the contraptions at work in this wiki.


How to transclude labeled sections between texts:

To create links between different pages, based on some selection of text that somehow connects the pages on the bases of some common ground:

  • Think of a category that is the common ground for the link. (eg. 'rawdata'), formulate it without spaces or using underscores (eg. 'raw_data', not 'raw data' );
  • Edit the page and add {{RT|rawdata}}<section begin=rawdata /> before the text selection, and <section end=rawdata /> at the end (take care of the '/', without it doesn't work);
  • All the other text selections in other pages which are selected along the same common ground will be transcluded on the side of the text.


How it works:

The section code is used by the 'Labeled Section Transclusion' extension, which looks for the tagged sections in a text, to transclude them into another text based on the assigned labels. The {{RT|rawdata}}<section begin=rawdata /> instead, transcludes the RT Template, substituting the word rawdata in its internal code, in place of {{{1}}}. This is the commented content of Template:RT:

<div class="side">                                   #  Puts the trancluded sections on its own div;
                                                     #
{{#ask:                                              #  Searches semantically for all the pages in 
   [[Category:{{{1}}}]]|format=array | name=results  # the requested category, puts them in an array; 
}}                                                   #
{{#loop: looper                                      #  Starts a loop,
 | 0                                                 #  Going from 0 to
 | {{#arraysize: results}}                           #  the amount of pages of the array, that:
 | {{#ifeq: {{FULLPAGENAME:                          #   If the pagename
       {{#arrayindex: results | {{#var:looper}}  }}  #    of the current element of the array
            }}                                       #
 |          {{FULLPAGENAME}}                         #    is the same as the page calling the loop,
 | 				                     #     It will skip the page (no self-reference);
 |           {{#lst:                                 #     Otherwise it searches through the 
	{{#arrayindex: results | {{#var:looper}}  }} #      current page in the loop for
 | {{{1}}}   }}                                      #      all the occurrences of labeled sections
([[{{#arrayindex: results | {{#var:looper}}  }}]])   #     Adds the name of the current page in loop;
<br /><br />                                         #     Adds some space after the page;
}}                                                   #   End of pagename check;
}}                                                   #  End of loop;
</div>                                               #  Closes div;
[[category:{{{1}}}]]                                 #  Adds the page to the label category.


Necessaire:

Currently on top of MediaWiki and SemanticMediaWiki, the following extensions needed to be installed for the contraption to work:

  • Labeled Section Transclusion to be able to select specific sections of the texts and make connections between them;
  • Parser Functions to be able to operate statements like if in the wiki pseudo-language;
  • Arrays to create lists of objects, for example as a result of semantic queries;
  • Loops to loop between the arrays above;
  • Variables as it's needed by some of the above.

What links here