Extension

TamblingCommon

From MusicTechWiki

Many of the extensions here have been designed exclusively for this wiki, and so there is a lot of common functionality amongst them. The TamblingCommon extension creates a class (also called TamblingCommon) which can be used to encapsulate all of this common functionality so that code doesn't need to be unnecessarily duplicated in multiple extensions. This article lists the settings and methods the TamblingCommon class provides.

Variables

TamblingCommon::$singleton

This is not required presently, but later if some methods need to be called non-statically then they can access the global singleton object version of the class using this static variable.

TamblingCommon::$downloadUrl

This is the URL that points to the downloads directory and will be set correctly independently of the server and domain the site is running on.

TamblingCommon::$downloadDir

This is the same thing but is the internal filesystem location, currently /var/www/downloads.

TamblingCommon::$studentRosterData

This points to the locations of the Student Roster settings files (currently in $IP/extensions/TamblingWikiExtensions/StudentRoster/data).

Methods

TamblingCommon::titleFromUrl( $path )

Returns a title object from a wiki URL. Note that this should really not be necessary because form values should contain the concise title rather than a path already, and the path be created server-side not the other way round.

For a solid example taken from the repo, this commit changes this:

$refTitle = preg_replace("%http.*/wiki/(.*)[#\?]?.*%", '$1', $refUrl);

to this:

$refTitle = TamblingCommon::titleFromUrl( $refUrl )->getPrefixedText();

TamblingCommon::extPath( $dir )

Returns an external path to the passed directory (needed because PHP5 doesn't offer any way to know the original symlink path)

TamblingCommon::notify( $msg, $type = 'success' )

Add a formatted message to the SiteNotice area to be used by forms after submission to indicate success or failure and provide the associated details. The default type of message is a success message which renders as a green box. For failure the type parameter should be set to "error" which will produce a red error box. These boxes can be formatted using the successbox and errorbox CSS classes which are part of the base MediaWiki stylesheet.