Actions

Developer Area/Pagetop Constants: Difference between revisions

From Mahara Wiki

< Developer Area
 
(14 intermediate revisions by 2 users not shown)
Line 33: Line 33:
=== ADMIN ===
=== ADMIN ===


define('ADMIN', 1);
<source lang="php" container="div">
define('ADMIN', 1);
</source>


Indicates that this page should only be accessible to [http://manual.mahara.org/en/1.8/administration/users.html#index-16 Site Administrators].
Indicates that this page should only be accessible to [http://manual.mahara.org/en/1.8/administration/users.html#index-16 Site Administrators].
Line 39: Line 41:
=== STAFF ===
=== STAFF ===


define('STAFF', 1);
<source lang="php" container="div">
define('STAFF', 1);
</source>


Indicates that this page should only be accessible to [http://manual.mahara.org/en/1.8/administration/users.html#index-15 Site Staff] (and Site Admins).
Indicates that this page should only be accessible to [http://manual.mahara.org/en/1.8/administration/users.html#index-15 Site Staff] (and Site Admins).
Line 45: Line 49:
=== INSTITUTIONALADMIN ===
=== INSTITUTIONALADMIN ===


define('INSTITUTIONALADMIN', 1);
<source lang="php" container="div">
define('INSTITUTIONALADMIN', 1);
</source>


Indicates that this page should only be accessible to [http://manual.mahara.org/en/1.8/administration/institutions.html#institution-administrators Institution Admins] (and Site Admins).
Indicates that this page should only be accessible to [http://manual.mahara.org/en/1.8/administration/institutions.html#institution-administrators Institution Admins] (and Site Admins).
Line 51: Line 57:
=== INSTITUTIONALSTAFF ===
=== INSTITUTIONALSTAFF ===


define('INSTITUTIONALSTAFF', 1);
<source lang="php" container="div">
define('INSTITUTIONALSTAFF', 1);
</source>


Indicates that this page should be accessible to [http://manual.mahara.org/en/1.8/staff/staff.html Institution Staff] (and Site Admins, Site Staff, and Institutional Admins).
Indicates that this page should be accessible to [http://manual.mahara.org/en/1.8/staff/staff.html Institution Staff] (and Site Admins, Site Staff, and Institutional Admins).
Line 59: Line 67:
=== PUBLIC ===
=== PUBLIC ===


define('PUBLIC', 1);
<source lang="php" container="div">
define('PUBLIC', 1);
</source>


Indicates that this page may be accessible to non-logged-in users. If this flag is not set, then any non-logged-in user will be sent to the transient login page when they try to access it.
Indicates that this page may be accessible to non-logged-in users. If this flag is not set, then any non-logged-in user will be sent to the transient login page when they try to access it.
Line 67: Line 77:
=== CRON ===
=== CRON ===


define('CRON', 1);
<source lang="php" container="div">
define('CRON', 1);
</source>


This flag should only be set by the main Mahara cron job. Its presence indicates that the method is being called by the Mahara cron job. This causes authentication checks to be bypassed and some display measures to be avoided.
This flag should only be set by the main Mahara cron job. Its presence indicates that the method is being called by the Mahara cron job. This causes authentication checks to be bypassed and some display measures to be avoided.
Line 73: Line 85:
=== INSTALLER ===
=== INSTALLER ===


define('INSTALLER', 1);
<source lang="php" container="div">
define('INSTALLER', 1);
</source>


Indicates that this page is part of the Mahara installation process. Causes some parts of the normal page-load to be skipped, because the data for them will not yet be present.
Indicates that this page is part of the Mahara installation process. Causes some parts of the normal page-load to be skipped, because the data for them will not yet be present.
Line 79: Line 93:
=== CLI ===
=== CLI ===


define('CLI', 1);
<source lang="php" container="div">
define('CLI', 1);
</source>


Indicates that this script is meant to be executed as a [https://wiki.mahara.org/index.php/Developer_Area/CLI_Framework command-line script]. This causes Mahara to skip authentication checks and other things incompatible with the command-line interface.
Indicates that this script is meant to be executed as a [https://wiki.mahara.org/index.php/Developer_Area/CLI_Framework command-line script]. This causes Mahara to skip authentication checks and other things incompatible with the command-line interface.
Line 85: Line 101:
=== JSON ===
=== JSON ===


define('JSON', 1);
<source lang="php" container="div">
define('JSON', 1);
</source>


Indicates that this script is meant to be called by a web service, and its only output should be well-formatted JSON. This prevents certain automated responses from being printed to the HTTP output, as that would break the JSON.
Indicates that this script is meant to be called by a web service, and its only output should be well-formatted JSON. This prevents certain automated responses from being printed to the HTTP output, as that would break the JSON.
Line 91: Line 109:
==== NOSESSKEY ====
==== NOSESSKEY ====


define('NOSESSKEY', 1);
<source lang="php" container="div">
define('NOSESSKEY', 1);
</source>


A flag to use in conjunction with the JSON flag. Most JSON requests require a "sesskey" variable to passed along with them. This is a unique key used in Mahara forms and other operations that cause data to be changed, and is used in order to prevent attacks based on sending a user to a URL.
A flag to use in conjunction with the JSON flag. Most JSON requests require a "sesskey" variable to passed along with them. This is a unique key used in Mahara forms and other operations that cause data to be changed, and is used in order to prevent attacks based on sending a user to a URL.
Line 99: Line 119:
=== XMLRPC ===
=== XMLRPC ===


define('XMLRPC', 1);
<source lang="php" container="div">
define('XMLRPC', 1);
</source>


Indicates that this script is meant to be called by a web service using XMLRPC, and its output should consist entirely of well-formatted XMLRPC.
Indicates that this script is meant to be called by a web service using XMLRPC, and its output should consist entirely of well-formatted XMLRPC.
Line 105: Line 127:
=== TESTSRUNNING ===
=== TESTSRUNNING ===


define ('TESTSRUNNING', 1);
<source lang="php" container="div">
define ('TESTSRUNNING', 1);
</source>


Indicates that this script is a PHPUnit test, allowing for different behavior to support unit tests.
Indicates that this script is a PHPUnit test, allowing for different behavior to support unit tests.
== Layout / Headings ==
=== TITLE ===
<source lang="php" container="div">
define ('TITLE', 1);
</source>
Indicates both the title of the page (what appears in the titlebar of the browser) and the page's &lt;h1> heading. The &lt;h1> heading can be overwritten by defining <code>$smarty->assign('PAGEHEADING', get_string('somenewheading', 'mahara'));</code>
All PHP pages that call <code>$smarty->display()</code> should have a TITLE defined.
=== SUBSECTIONHEADING ===
<source lang="php" container="div">
define ('SUBSECTIONHEADING', 1);
</source>
Indicates a subtitle of the page (where appropiate) for the page's &lt;h1> heading. For example the pages list page for "Group 1" would have the SUBSECTIONHEADING and TITLE pairing of "Pages | Group 1".


== And more... ==
== And more... ==


This list is incomplete and is a work in progress. Please feel free to document other pagetop constants here as well. There are also some used for navigation and help files, for instance.
This list is incomplete and is a work in progress. Please feel free to document other pagetop constants here as well. There are also some used for navigation and help files, for instance.

Latest revision as of 14:13, 10 February 2016


Mahara uses a diverse range of PHP constants defined at the beginning of the script, to define the script's behavior or provide metadata. This page attempts to be a comprehensive list of these constants and what they do.

Note: By all means make use of the existing set of page-top constants, but please avoid creating new ones whenever possible. They're a form of global variable, and as such they bring all the associated problems with them. They also tend not to be well-documented, because there's no central place in the code where they have to be used.

General purpose

INTERNAL

This backwards-named constant tells Mahara that it's okay to access this page externally.

Every Mahara script that is meant to be addressed directly by a web browser (or other HTTP client) should define it as its very first PHP statement, even before including init.php.

define('INTERNAL', 1);

Conversely, every "library" script which is not meant to be addressed directly by a web browser, should begin with this:

defined('INTERNAL') || die();

Admin pages

These constants control who can access the page. If any of them is set, the logged-in user will be checked for appropriate access control in the auth_setup() method called by init.php. If they lack appropriate credentials, they'll see a warning message.

Note that you can only set one of these values on any page. If more than one is defined, only the most restrictive one will have effect and the others will be ignored. (See the auth_check_admin_section() method for the actual implementatoin.)

Setting any of these constants also tells the Mahara main_nav() method that you are in Mahara's "admin section", and it will then show you the appropriate admin menu depending on whether you are a site admin, site staff, institution admin, or institution staff. It also sets a smarty flag with the same name as the constant, which can be used to style the admin section differently than normal pages.

ADMIN

define('ADMIN', 1);

Indicates that this page should only be accessible to Site Administrators.

STAFF

define('STAFF', 1);

Indicates that this page should only be accessible to Site Staff (and Site Admins).

INSTITUTIONALADMIN

define('INSTITUTIONALADMIN', 1);

Indicates that this page should only be accessible to Institution Admins (and Site Admins).

INSTITUTIONALSTAFF

define('INSTITUTIONALSTAFF', 1);

Indicates that this page should be accessible to Institution Staff (and Site Admins, Site Staff, and Institutional Admins).

Script type

PUBLIC

define('PUBLIC', 1);

Indicates that this page may be accessible to non-logged-in users. If this flag is not set, then any non-logged-in user will be sent to the transient login page when they try to access it.

A page that might sometimes be visible to the public (for instance, view/view.php, which shows a single portfolio page) should set this flag and manually throw an AccessDeniedException if it turns out the particular data requested is not publicly visible.

CRON

define('CRON', 1);

This flag should only be set by the main Mahara cron job. Its presence indicates that the method is being called by the Mahara cron job. This causes authentication checks to be bypassed and some display measures to be avoided.

INSTALLER

define('INSTALLER', 1);

Indicates that this page is part of the Mahara installation process. Causes some parts of the normal page-load to be skipped, because the data for them will not yet be present.

CLI

define('CLI', 1);

Indicates that this script is meant to be executed as a command-line script. This causes Mahara to skip authentication checks and other things incompatible with the command-line interface.

JSON

define('JSON', 1);

Indicates that this script is meant to be called by a web service, and its only output should be well-formatted JSON. This prevents certain automated responses from being printed to the HTTP output, as that would break the JSON.

NOSESSKEY

define('NOSESSKEY', 1);

A flag to use in conjunction with the JSON flag. Most JSON requests require a "sesskey" variable to passed along with them. This is a unique key used in Mahara forms and other operations that cause data to be changed, and is used in order to prevent attacks based on sending a user to a URL.

For JSON operations that are not changing data (for instance, displaying Help pop-ups), this flag should be set so that the sesskey will not be checked for.

XMLRPC

define('XMLRPC', 1);

Indicates that this script is meant to be called by a web service using XMLRPC, and its output should consist entirely of well-formatted XMLRPC.

TESTSRUNNING

define ('TESTSRUNNING', 1);

Indicates that this script is a PHPUnit test, allowing for different behavior to support unit tests.

Layout / Headings

TITLE

define ('TITLE', 1);

Indicates both the title of the page (what appears in the titlebar of the browser) and the page's <h1> heading. The <h1> heading can be overwritten by defining $smarty->assign('PAGEHEADING', get_string('somenewheading', 'mahara'));

All PHP pages that call $smarty->display() should have a TITLE defined.

SUBSECTIONHEADING

define ('SUBSECTIONHEADING', 1);

Indicates a subtitle of the page (where appropiate) for the page's <h1> heading. For example the pages list page for "Group 1" would have the SUBSECTIONHEADING and TITLE pairing of "Pages | Group 1".

And more...

This list is incomplete and is a work in progress. Please feel free to document other pagetop constants here as well. There are also some used for navigation and help files, for instance.