Page MenuHomePhabricator

DefaultRestrictions.php

Authored By
bzimport
Nov 21 2014, 8:27 PM
Size
1 KB
Referenced Files
None
Subscribers
None

DefaultRestrictions.php

<?php
$wgExtensionFunctions[] = "wfDefaultRestrictions";
function wfDefaultRestrictions()
{
global $IP, $wgMessageCache, $wgHooks;
require_once( "$IP/includes/SpecialPage.php" );
$wgExtensionCredits['other'][] = array(
'name' => 'Default restrictions',
'author' => 'Zhen Lin',
'description' => ''
);
$wgHooks['userCan'][] = 'wfDefaultRestrictionsHook1';
$wgHooks['ArticleInsertComplete'][] = 'wfDefaultRestrictionsHook2';
}
function wfDefaultRestrictionsHook1(&$title, &$user, $action, &$result)
{
global $wgDefaultRestrictions, $wgCreateRestrictions;
$id = $title->getArticleID();
if ($id != 0)
{
$result = null;
return;
}
$res = $wgDefaultRestrictions[$title->mNamespace];
if (! isset($res))
$res = '';
if (! $title->mRestrictionsLoaded)
$title->loadRestrictions($res);
if ($action == 'create')
{
$res = $wgCreateRestrictions[$title->mNamespace];
if (isset($res))
{
$result = $user->isAllowed($res);
return;
}
}
$result = null;
return;
}
function wfDefaultRestrictionsHook2(&$article, &$user, $text, $summary, $isminor, $iswatch, $section)
{
global $wgDefaultRestrictions;
$id = $article->mTitle->mArticleID;
if ($id == 0)
return;
$res = $wgDefaultRestrictions[$article->mTitle->mNamespace];
if (! isset($res))
return;
$dbw =& wfGetDB(DB_MASTER);
$dbw->update('page',
array(/* SET */
'page_restrictions' => $res
), array( /* WHERE */
'page_id' => $id
), 'Article::protect'
);
return;
}
?>

File Metadata

Mime Type
text/x-php
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1578
Default Alt Text
DefaultRestrictions.php (1 KB)

Event Timeline