W3TPL/recipes: Difference between revisions

From Woozle Writes Code
Jump to navigation Jump to search
(→‎Wikitext: drop-down list example; changed pre to xml)
(another recipe)
Line 1: Line 1:
==Listing Pages in a Category==
==Pages and Categories==
This bit is for a feature-in-development. I'll probably be adding full SQL capability at some point, but I want to make sure it is secure (and can be disabled in LocalSettings) before putting it in; for now, W3 is going to have data access only by filtering tables -- which can also be data views, i.e. potentially very complex SQL but only if you have db permission to create views.
List all categorized Titles without defining any VIEWs:
===Wikitext===
<xml>
<hide>
  <for sql="SELECT * FROM categorylinks AS cl LEFT JOIN page AS p ON cl_from=page_id">
    <let name=pg_title val=@row.page_title />
    <let name=out append>
* [[</let>
    <let name=out append copy=pg_title />
    <let name=out append>|</let>
 
    <let load page=$pg_title name=data />
    <let name=out append copy=data[summary] />
    <let name=out append>]]</let>
</hide><get name=out />
</xml>
 
List all Titles in a specific category:
===SQL===
===SQL===
<mysql>CREATE OR REPLACE VIEW qryW3_Titles_Catgs AS
<mysql>CREATE OR REPLACE VIEW qryW3_Titles_Catgs AS

Revision as of 00:48, 11 September 2015

Pages and Categories

List all categorized Titles without defining any VIEWs:

Wikitext

<xml> <hide>

 <for sql="SELECT * FROM categorylinks AS cl LEFT JOIN page AS p ON cl_from=page_id">
   <let name=pg_title val=@row.page_title />
   <let name=out append>
  • [[</let>
   <let name=out append copy=pg_title />
   <let name=out append>|</let>
   <let load page=$pg_title name=data />
   <let name=out append copy=data[summary] />
   <let name=out append>]]</let>

</hide><get name=out /> </xml>

List all Titles in a specific category:

SQL

<mysql>CREATE OR REPLACE VIEW qryW3_Titles_Catgs AS

 SELECT * FROM
 categorylinks AS cl LEFT JOIN page AS p ON cl_from=page_id;</mysql>

Wikitext

<xml> <let name=including val="1" /> </hide><for table="qryW3_Titles_Catgs" where="(cl_to='Data/target') AND (page_namespace=0)" name=pg hide>

 <let name=pg_title val="@row.pg.page_title" />
 <load page=$pg_title />
 <let name=title_link>[[</let>
 <let name=title_link append copy=pg_title />
 <let name=title_link append>|</let>
 <let name=title_link append copy=keyname />
 <let name=title_link append>]]</let>
 <echo>
  • <get name=title_link />: "<get name=title />": <get name=source /></echo>

</for> </xml>

  • Replace "Data/target" with the name of the category you want to list
  • Alter the line which begins with Template:Xmltag (i.e. everything between the Template:Xmltag tags) to display what you want; "title" and "source" are from an actual live installation (PsyCrit) and are defined within the pages in that category, so each output line gives a little information about the page (effectively a mini-"report")
  • The "including" variable tells the included pages not to show their category, so that this page won't think it is also in that same category.

To use the same data to generate a form with a drop-down list of all titles returned: <xml><func xmltag contents>

 <let name=out chr=60 />
 <let name=out append copy=contents />
 <let name=out append chr=62 />
 <echo><get name=out raw /></echo>

</func>

<call xmltag contents="form" /> <call xmltag contents="SELECT NAME=target" /> <for table="qryW3_Titles_Catgs" where="(cl_to='Data/target') AND (page_namespace=0)" sort="page_title DESC" name=pg hide>

 <let name=pg_title val="@row.pg.page_title" />
 <load page=$pg_title />
 <echo><call xmltag contents="OPTION" /><get name=keyname /> - <get name=title /><call xmltag contents="/OPTION" /></echo>

</for> <call xmltag contents="/SELECT" /> <call xmltag contents="/form" /> </xml>