Extension:PagePolice
If you need per-page or partial page access restrictions, you are advised to install an appropriate content management package. 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. We are not responsible for anything being leaked.
For further details, see Security issues with authorisation extensions |
This extension stores its source code on a wiki page. Please be aware that this code may be unreviewed or maliciously altered. They may contain security holes, outdated interfaces that are no longer compatible etc. Note: No localisation updates are provided for this extension by translatewiki.net . |
This extension is currently not actively maintained! Although it may still work, any bug reports or feature requests will more than likely be ignored. |
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> |
|
The PagePolice extension allows individual user access control to pages.
Installation
[edit]- Copy the code into a file called "PagePolice.php" and place the file(s) in a directory called
PagePolice
in yourextensions/
folder. - Add the following code at the bottom of your LocalSettings.php file:
require_once "$IP/extensions/PagePolice/PagePolice.php";
- Configure as required
Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.
Configuration
[edit]Example:
$wgPPError = "ACCESS DENIED"; $wgPPMessage = "SECURE ZONE (access only for %s)";
Code
[edit]<?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_PRIMARY );
$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;
}