Extension:NSFileRepo/DOC
Functional Decision Process
editSpecifying Namespace
editThis extension will allow one, and only one, namespace in the Title/link specification, and that namespace must be the text version of a declared custom namespace (NS_INDEX >= 100). So if a custom namespace has been declared in the LocalSettings file, e.g.:
#
# Add namespace reference, must start with 100, standard usage is even for namespace and odd for talk namespace
#
define('NS_TEST', 100);
define('NS_TEST_talk', 101);
#
# Give the groups their names and add them to the custom namespaces
#
$wgExtraNamespaces[NS_TEST] = "TEST";
$wgExtraNamespaces[NS_TEST_talk] = "TEST_talk";
#
# Indicate these namespaces are actually elible to have content
#
$wgContentNamespaces[] = NS_TEST;
$wgContentNamespaces[] = NS_TEST_talk;
Then you could use the standard namespace protections (with some very specific capabilites if you use Extension:Lockdown).
For example:
[[File:Test:Somefile.pdf]]
Multiple NameSpaces?
editNope, sorry. If you tried to use multiple namespaces, the standard "replace : with _" rule would be applied.
Example:
[[File:Test:Testdenied:Somefile.pdf]]
Would be translated to:
[[File:Test:Testdenied_Somefile.pdf]]
Will this work with foreign repositories?
editForeign repositories will work the same way they always have. NameSpace protections will apply only to the local repository. Attempts to reference non-local repositories will be handled by those repositories' classes the same way they are now. This is for local repositories only, and I have no immediate plans for implementing a cross-system access protection vehicle.
Technically - How does this work?
editWhen Tim Starling redesigned the file repository system, he architected a solution that supported a single "local" repository with an additional array of "foreign" repositories. MW first looks in the Local repository, then using the foreign repository classes, searches sequentially through those repositories until the file is found. If you are interested in studying a brilliant concept and superb execution, this is a textbook case and studying the MS repo system is well worth a purely academic pursuit.
NSFileRepo is a class extension of LocalRepo and its associated LocalFile classes. All reference parsing is done within these classes so I was able to extend them to override and process as needed for this extension.
Additionally, the extension uses the Extension:Lockdown capabilities developed by Duesentrieb to give the same granular access protection to files/images as are provided through other NameSpace features.
Changes to the Local Directory Structure
editIn the default Local Repository, files are process/stored in the following structures:
{hash}/ temp/{hash}/ archive/{hash}/ . . .
If a valid custom namespace is specified for the file, the namespace index is prepended in the directory structure, e.g.
{ns}/{hash}/ temp/{ns}/{hash}/ archive/{ns}/{hash}/ . . .
The hook added to img_auth.php looks at the first directory in the hash structure and sees if it is an integer > 100 (as all custom namespaces must be). If so, it translates the index into text, builds a title with that namespace text, and checks to see if access is authorized.
An additional value to this would be the ability to set specific access restrictions on these directories (and sub directories) that could further restrict access by those with administrative access to the actual server.