Extension:PagePolice
![]() | MediaWiki was not designed to support per-page or partial-page access restrictions. If you require this level of control, you are strongly advised to use a content management system that supports it natively.
Patches or third-party extensions claiming to provide access control may contain security flaws, potentially exposing confidential data. Use them at your own risk. Neither the MediaWiki developers nor the Wikimedia Foundation are responsible for any data leaks that may result. This message is added to all extensions of this nature and may not reflect the actual security status of this extension. For more information, see Security issues with authorization extensions . |
![]() | This extension stores its source code on a wiki page rather than a code repository. 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: unmaintainedCategory:Unmaintained extensions |
|
---|---|
Implementation | User rightsCategory:User rights extensions, TagCategory:Tag extensions |
Description | Individual user access control to pages |
Author(s) | Ury Yakovlev (Ury.Yakovlevtalk) |
Latest version | 0.1 (2012-11-26) |
MediaWiki | Category:Extensions without MediaWiki version |
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
- 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.Category:Extensions not using extension registration
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_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;
}