Extension:PagePolice
Appearance
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, when in use with MediaWiki, may not work in all cases, 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 editable wiki page rather than in a code repository. As a result, this code may be maliciously altered. It may contain security vulnerabilities, and will not receive localisation updates from translatewiki.net. Developers are strongly encouraged to host their code in a code repository rather than a wiki page so that the extension can be properly maintained, reviewed, and kept secure. |
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
PagePolicein 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; } 