Extension:SubPageFunctions

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced.svg
SubPages
Release status: unmaintained
Implementation Parser function
Description Automatically creates subpage links in parent page.
Author(s) Peter Gostelow (PeterMGtalk)
Latest version 0.0.3
MediaWiki 1.14+
License GNU General Public License 2.0
Download LibrePlanet
The parent page may need to be dummy edited to reflect subpage name changes. This may be an optimization issue.
Example {{#subpages: Help}}
Translate the SubPageFunctions extension if it is available at translatewiki.net
Check usage and version matrix.

The SubPageFunctions extension automatically creates subpage links in parent page.

When creating a tree of subpages, this extension will provide navigation links from a parent page to its immediate subpages. It is the counterpart to the wiki's parent page links.

You may slice and dice subpage names to select parts of the name using the pathname function.

When compiling educational documents, you may create a table linking to them, using the calendar function.

The user function returns the current user name, useful when creating personalised pages.

Usage[edit]

subpages[edit]

The syntax is

{{#subpages: [NAMESPACE | 0]}}

Where

NAMESPACE
is an optional namespace name, e.g. Project, Help, MyNamespace, etc.
0 (numerical zero)
is the main namespace, often called Article.

The default is to use the page's namespace, so you can omit the argument. You may use the function more than once for different namespaces.

You may add the function anywhere on the page. It will create a centered title and a three column list of subpage links. If there are no subpages, the function will output nothing.

pathname[edit]

The syntax is

{{#pathname: start [|length]}}

Where

start
An integer representing the first component in the pathname.
length
An integer representing the number of components.

The pathname can be trimmed from both the front or back. The length is similarly selected from either the front or back.

Given the page name

foo/bar/baz/widget/fee/fie/foe/fum
// front of name
{{#pathname: 0|1}} // returns foo
{{#pathname: 0|3}} // returns foo/bar/baz
{{#pathname: 1|3}} // returns bar/baz/widget
// back of name
{{#pathname:-1}}   // returns fum
{{#pathname:-3}}   // returns fie/foe/fum
{{#pathname:-3|2}} // returns fie/foe
// back length
{{#pathname:3|-2}} // returns baz/widget (not widget/fee)
{{#pathname:-3|-2}} // returns fee/fie (not fie/foe)

It only operates on the current page name in a similar way to {{BASEPAGENAME}} and {{SUBPAGENAME}}, so you cannot pass it arbitary text. It becomes useful when using more than three subpage levels.

calendar[edit]

The syntax is

{{#calendar: [namespace][|pageprefix]}}

Where

namespace
The namespace of the target pages.
pageprefix
The parent page in the namespace.

Returns a table where the columns are subpages of pageprefix and the rows are sub-subpages of pageprefix. If pageprefix is omitted, the current page name is used. If the namespace is omitted, the current page's namespace is used.

Given the following pages:

Extension:SubPageFunctions/example/101/intro
Extension:SubPageFunctions/example/101/examples
Extension:SubPageFunctions/example/102/intro
Extension:SubPageFunctions/example/103/examples

the function in the Extension:SubPageFunctions page

{{#calendar: |SubPageFunctions/example}}

will produce the following table:

Calendar
Module/Level 101 102 103
examples Available N/A Available
intro Available Available N/A

If a page is a redirect, it is marked as Redirect instead of Available. The row names examples and intro are composite names taken from the sub-subpages.

user[edit]

The syntax is

{{#user:}}

This function takes no arguments and returns the current logged in user name. This is useful when creating user subpages, for example, given the current user is Foo:

[[doc/example/101/examples/{{#user:}}/tutorial]]

will link to:

[[doc/example/101/examples/Foo/tutorial]]

The actual link will vary from user to user, creating multiple unique pages by user name, but each user will only see their link. The function can be used anywhere text is allowed, not just links. Most useful with SemanticMediaWiki and SemanticForms.

Instllation[edit]

  • Download, extract and place the file(s) in a directory called SubPageFunctions in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    require_once "$IP/extensions/SubPageFunctions/SubPageFunctions.php";
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

See also[edit]