$article: the page the form is shown for
$out: OutputPage object
+'ProtectionFormGetApplicableTypes': Allows extensions to modify the types of protection
+ that can be applied.
+$title: The title in question.
+&$types: The types of protection available.
+
'RawPageViewBeforeOutput': Right before the text is blown out in action=raw
&$obj: RawPage object
&$text: The text that's going to be the output
* @return bool true on success
*/
public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
- global $wgUser, $wgRestrictionTypes, $wgContLang;
+ global $wgUser, $wgContLang;
+
+ $restrictionTypes = $this->mTitle->getProtectionTypes();
$id = $this->mTitle->getArticleID();
if ( $id <= 0 ) {
$current = array();
$updated = Article::flattenRestrictions( $limit );
$changed = false;
- foreach( $wgRestrictionTypes as $action ) {
+ foreach( $restrictionTypes as $action ) {
if( isset( $expiry[$action] ) ) {
# Get current restrictions on $action
$aLimits = $this->mTitle->getRestrictions( $action );
var $mExistingExpiry = array();
function __construct( Article $article ) {
- global $wgRequest, $wgUser;
- global $wgRestrictionTypes, $wgRestrictionLevels;
+ global $wgUser;
+ // Set instance variables.
$this->mArticle = $article;
$this->mTitle = $article->mTitle;
- $this->mApplicableTypes = $this->mTitle->exists() ? $wgRestrictionTypes : array('create');
-
- $this->mCascade = $this->mTitle->areRestrictionsCascading();
-
- // The form will be available in read-only to show levels.
+ $this->mApplicableTypes = $this->mTitle->getProtectionTypes();
+
+ // Check if the form should be disabled.
+ // If it is, the form will be available in read-only to show levels.
$this->mPermErrors = $this->mTitle->getUserPermissionsErrors('protect',$wgUser);
$this->disabled = wfReadOnly() || $this->mPermErrors != array();
$this->disabledAttrib = $this->disabled
? array( 'disabled' => 'disabled' )
: array();
+
+ $this->loadData();
+ }
+
+ // Loads the current state of protection into the object.
+ function loadData() {
+ global $wgRequest, $wgUser;
+ global $wgRestrictionLevels;
+
+ $this->mCascade = $this->mTitle->areRestrictionsCascading();
$this->mReason = $wgRequest->getText( 'mwProtect-reason' );
$this->mReasonSelection = $wgRequest->getText( 'wpProtectReasonSelection' );
foreach( $this->mApplicableTypes as $action ) {
// Fixme: this form currently requires individual selections,
// but the db allows multiples separated by commas.
+
+ // Pull the actual restriction from the DB
$this->mRestrictions[$action] = implode( '', $this->mTitle->getRestrictions( $action ) );
if ( !$this->mRestrictions[$action] ) {
Xml::openElement( 'tbody' );
foreach( $this->mRestrictions as $action => $selected ) {
- // Special case: apply upload protection only on images
- if ( $action == 'upload' && $this->mTitle->getNamespace() != NS_FILE )
- continue;
-
/* Not all languages have V_x <-> N_x relation */
$msg = wfMsg( 'restriction-' . $action );
if( wfEmptyMsg( 'restriction-' . $action, $msg ) ) {
/**
* Does the title correspond to a protected article?
* @param $what \type{\string} the action the page is protected from,
- * by default checks move and edit
+ * by default checks all actions.
* @return \type{\bool}
*/
public function isProtected( $action = '' ) {
- global $wgRestrictionLevels, $wgRestrictionTypes;
+ global $wgRestrictionLevels;
+
+ $restrictionTypes = $this->getProtectionTypes();
# Special pages have inherent protection
if( $this->getNamespace() == NS_SPECIAL )
return true;
# Check regular protection levels
- foreach( $wgRestrictionTypes as $type ){
+ foreach( $restrictionTypes as $type ){
if( $action == $type || $action == '' ) {
$r = $this->getRestrictions( $type );
foreach( $wgRestrictionLevels as $level ) {
* The restriction array is an array of each type, each of which contains an array of unique groups.
*/
public function getCascadeProtectionSources( $get_pages = true ) {
- global $wgRestrictionTypes;
-
- # Define our dimension of restrictions types
$pagerestrictions = array();
- foreach( $wgRestrictionTypes as $action )
- $pagerestrictions[$action] = array();
if ( isset( $this->mCascadeSources ) && $get_pages ) {
return array( $this->mCascadeSources, $this->mCascadingRestrictions );
$sources[$page_id] = Title::makeTitle($page_ns, $page_title);
# Add groups needed for each restriction type if its not already there
# Make sure this restriction type still exists
- if ( isset($pagerestrictions[$row->pr_type]) && !in_array($row->pr_level, $pagerestrictions[$row->pr_type]) ) {
+
+ if ( !isset( $pagerestrictions[$row->pr_type] ) ) {
+ $pagerestrictions[$row->pr_type] = array();
+ }
+
+ if ( isset($pagerestrictions[$row->pr_type]) &&
+ !in_array($row->pr_level, $pagerestrictions[$row->pr_type]) ) {
$pagerestrictions[$row->pr_type][]=$row->pr_level;
}
} else {
}
public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = NULL ) {
- global $wgRestrictionTypes;
$dbr = wfGetDB( DB_SLAVE );
+
+ $restrictionTypes = $this->getProtectionTypes();
- foreach( $wgRestrictionTypes as $type ){
+ foreach( $restrictionTypes as $type ){
$this->mRestrictions[$type] = array();
$this->mRestrictionsExpiry[$type] = Block::decodeExpiry('');
}
foreach( $rows as $row ) {
# Cycle through all the restrictions.
- // Don't take care of restrictions types that aren't in $wgRestrictionTypes
- if( !in_array( $row->pr_type, $wgRestrictionTypes ) )
+ // Don't take care of restrictions types that aren't allowed
+
+ if( !in_array( $row->pr_type, $restrictionTypes ) )
continue;
// This code should be refactored, now that it's being used more generally,
return !in_array( $this->mNamespace, $bannedNamespaces );
}
+
+ public function getProtectionTypes() {
+ global $wgRestrictionTypes;
+ $types = $this->exists() ? $wgRestrictionTypes : array('create');
+
+ if ( $this->getNamespace() == NS_FILE ) {
+ $types[] = 'upload';
+ }
+
+ wfRunHooks( 'ProtectionFormGetApplicableTypes',
+ array( $this, &$types ) );
+
+ return $types;
+ }
}
else
$this->dieUsageMsg(array('toofewexpiries', count($expiry), count($params['protections'])));
}
+
+ $restrictionTypes = $titleObj->getProtectionTypes();
$protections = array();
$expiryarray = array();
$this->dieUsageMsg(array('create-titleexists'));
if(!$titleObj->exists() && $p[0] != 'create')
$this->dieUsageMsg(array('missingtitles-createonly'));
- if(!in_array($p[0], $wgRestrictionTypes) && $p[0] != 'create')
+ if(!in_array($p[0], $restrictionTypes) && $p[0] != 'create')
$this->dieUsageMsg(array('protect-invalidaction', $p[0]));
if(!in_array($p[1], $wgRestrictionLevels) && $p[1] != 'all')
$this->dieUsageMsg(array('protect-invalidlevel', $p[1]));