Hello all,
I intend to develop[*] a very simplified variant of the "stable version"
concept: If the editing user has no authorization, replace any sensitive
portions with a non-sensitive substitute - e.g. "{{Approved}}" becomes
"{{Approval Candidate}}".
[*] see "Re-inventing the wheel?" below
The following simple flowchart probably illustrates my idea better than
a verbose description would:
+--------------+
| save request |
+--------------+
|
V
/--------------------------------\ No
| article text contains $cue [1] |-------------------------------------+
\--------------------------------/ |
| |
Yes | |
V |
/------------------------\ No +------------------------------+ |
| user is authorized [2] |------->| replace $cue with $subst [1] | |
\------------------------/ +------------------------------+ |
| | |
Yes | | |
V | |
+--------------+ | |
| save article |<--------------------------------+---------------------+
+--------------+
[1] $cue and $subst are strings, read from an external TXT file
(in future version, these variables might be arrays of strings)
[2] authorization is handled via user rights (e.g. Bureaucrats, or
custom group "Editors"; might be read from an external TXT file)
Theoretically, this could all be very simple (maybe 10-20 LoC).
However, there are a few concerns:
#1 Re-inventing the wheel?
I'm probably not the first person to think of this on-save substitution.
However, I couldn't find an extension to build upon (which might be due
to a lack of unique keywords to search for).
#2 Preventing false positives
How can I prevent unparsed occurrences of $cue from being substituted?
For example, [[Template:Approval]] might contain usage notes with the
template call wrapped in PRE tags - this obviously should not be replaced.
Here's some very preliminary (pseudo-)code I quickly threw together -
maybe could help me fill in the blanks:
---------------
<?php
$wgHooks['ArticleSave'][] = 'wfCheckApprovalAuthorization';
function wfCheckApprovalAuthorization(&$article, &$user, &$text,
&$summary, $minor, $watch, $sectionanchor, &$flags) {
$cue = "foo"; // to be read from external TXT file
$subst = "bar"; // to be read from external TXT file
$auth = "editors"; // to be read from external TXT file
if( $text == $cue ) { // check for "contains", not "equals"
if( in_array( $auth, $user->$permissions ) ) { // nonsense?
str_ireplace( $cue, $subst, $text ); // nonsense?
}
}
}
?>
---------------
Sorry this message turned out to be so verbose.
For whoever has read this far, I'd greatly appreciate any feedback!
-- F.