Extension:PagePolice
From Linux Web Expert
<translate> If you need per-page or partial page access restrictions, you are advised to install an appropriate content management package.</translate> <translate> MediaWiki was not written to provide per-page access restrictions, and almost all hacks or patches promising to add them will likely have flaws somewhere, which could lead to exposure of confidential data.</translate> <translate> We are not responsible for anything being leaked.</translate>
<translate> For further details, see [[<tvar name=1>Special:MyLanguage/Security issues with authorization extensions</tvar>|Security issues with authorisation extensions]]</translate> |
<translate> This extension stores its source code on a wiki page.</translate> <translate> Please be aware that this code may be unreviewed or maliciously altered.</translate> <translate> They may contain security holes, outdated interfaces that are no longer compatible etc.</translate> <translate> Note:</translate> <translate> No [[<tvar name=localisation>Special:MyLanguage/Localisation#Translation resources</tvar>|localisation]] updates are provided for this extension by <tvar name=twn>translatewiki.net </tvar>.</translate> |
<translate> This extension is currently not actively maintained!</translate> <translate> Although it may still work, any bug reports or feature requests will more than likely be ignored.</translate> |
PagePolice Release status: unmaintained |
|
---|---|
Implementation | User rights , Tag |
Description | Individual user access control to pages |
Author(s) | Ury Yakovlev (Ury.Yakovlevtalk) |
Latest version | 0.1 (2012-11-26) |
MediaWiki | |
PHP | 5.3+ |
Database changes | No |
License | GPL |
Download | No link |
Example | <permit>Pr0;Root;H1;127.0.0.1</permit> |
|
|
<permit> |
|
Quarterly downloads | Lua error in Module:Extension at line 172: bad argument #1 to 'inNamespace' (unrecognized namespace name 'skin'). |
Public wikis using | Lua error in Module:Extension at line 172: bad argument #1 to 'inNamespace' (unrecognized namespace name 'skin'). |
The PagePolice extension allows individual user access control to pages.
Installation
- <translate> <tvar name=1>Copy the code into a file called "PagePolice.php"</tvar> and place the file(s) in a directory called <tvar name=name>
PagePolice
</tvar> in your <tvar name=ext>extensions/
</tvar> folder.</translate> - <translate> Add the following code at the bottom of your <tvar name=1>LocalSettings.php </tvar> file:</translate>
require_once "$IP/extensions/PagePolice/PagePolice.php";
- Configure as required
- File:OOjs UI icon check-constructive.svg <translate> Done</translate> – <translate> Navigate to <tvar name=special>Special:Version</tvar> on your wiki to verify that the extension is successfully installed.</translate>
Configuration
Example:
$wgPPError = "ACCESS DENIED"; $wgPPMessage = "SECURE ZONE (access only for %s)";
Code
<?php
# Block Page content
#
# Tag:
# <permit>user_id</permit>
# Ex:
# <permit>Pr0;Root;H1;127.0.0.1</permit>
#
# Enjoy!
$wgExtensionCredits['parserhook'][] = array(
'name' => 'PagePolice',
'description' => 'Allows to block access to content',
'author' => 'Ury Yakovlev',
'url' => 'https://www.mediawiki.org/wiki/Extension:PagePolice'
);
$wgHooks['ArticlePageDataAfter'][] = 'check_permit';
$wgHooks['ParserFirstCallInit'][] = 'pp_setup';
function pp_setup( Parser $parser ) {
$parser->setHook( 'permit', 'permit_render' );
return true;
}
function check_permit( $article, $row ) {
global $wgUser;
global $wgPPError;
if (!$wgPPError) {
$wgPPError = "<h1>403 ACCESS DENIED</h1> <meta http-equiv='Refresh' content='5;url=/'>";
}
$dbw = wfGetDB( DB_MASTER );
$text_data_row = $dbw->selectRow( 'text',
array( 'old_text', 'old_flags' ),
array( 'old_id' => $row->page_latest ),
__METHOD__ );
$content = $text_data_row->old_text;
preg_match('|<permit>(.*)</permit>|Uis', $content, $users_str);
if ($users_str[1]) {
$input = $users_str[1];
} else {
return true;
}
$users = explode(";", $input);
$allow = false;
$i=0;
while ($users[$i]) {
if ($wgUser->getName() == $users[$i]) {
$allow = true;
break;
}
$i++;
}
if ($allow) {
return true;
} else {
echo $wgPPError;
exit;
return false;
}
return 0;
}
# The callback function for converting the input text to HTML output
function permit_render($input) {
global $wgPPMessage;
if (!$wgPPMessage) {
$wgPPMessage = "<div style='background: #FFCC00;'><b>Защита</b></br>
<b>Контент с защитой содержимого</b></br>
Доступ разрешен только следующим пользователям: '%s'</div>";
}
$output = sprintf($wgPPMessage, $input);
return $output;
}
See also
Categories:
- Pages with script errors
- Pages with broken file links
- Page specific user rights extensions
- Extensions which host their code in-wiki
- Unmaintained extensions
- Extensions without an image
- User rights extensions
- Tag extensions
- Extensions without a compatibility policy
- Extensions without MediaWiki version
- Extensions with unknown license
- ArticlePageDataAfter extensions
- ParserFirstCallInit extensions
- All extensions
- Extensions not in ExtensionJson
- Extensions not using extension registration