/** * This function does all the initialization work for the extension. * Persistent data is unserialized from a record in the objectcache table * which is set in the Special page. It will change the permissions for * various functions for anonymous and registered users based on the data * in the array. The data expires after the set amount of time, just like * a block. */ function wfSetupProtectsite() { /* Globals */ global $wgOut, $wgMessageCache, $wgUser, $wgGroupPermissions, $wgVersion; /* Set Page Name/Title */ $wgMessageCache->addMessages(array('protectsite' => 'Protect site', 'protectsite-text-protect' => '<!-- Instructions/Comments/Policy for use -->', 'protectsite-text-unprotect' => '<!-- Instructions/Comments when protected -->', 'protectsite-title' => 'Site protection settings', 'protectsite-allowall' => 'All users', 'protectsite-allowusersysop' => 'Registered users and sysops', 'protectsite-allowsysop' => 'Sysops only', 'protectsite-createaccount' => 'Allow creation of new accounts by', 'protectsite-createpage' => 'Allow creation of pages by', 'protectsite-edit' => 'Allow editing of pages by', 'protectsite-move' => 'Allow moving of pages by', 'protectsite-upload' => 'Allow file uploads by', 'protectsite-timeout' => 'Timeout: ', 'protectsite-timeout-error' => "'''Invalid Timeout.'''", 'protectsite-maxtimeout' => 'Maximum: ', 'protectsite-comment' => 'Comment: ', 'protectsite-ucomment' => 'Unprotect comment: ', 'protectsite-until' => 'Protected until: ', 'protectsite-protect' => 'Protect', 'protectsite-unprotect' => 'Unprotect')); /* Initialize Object */ $persist_data = new MediaWikiBagOStuff('objectcache'); /* Get data into the prot hash */ $prot = $persist_data->get('protectsite'); /* Chop a single named value out of an array and return the new array. * This is required for 1.7 compatibility. * Remove from source once 1.8+ is required for use of this extension. */ function chop_array($arr, $value) { if (in_array($value, $arr)) { foreach ($arr as $val) { if ($val != $value) { $ret[] = $val; } } return $ret; } else { return $arr; } } /* Logic to disable the selected user rights */ if (is_array($prot)) { /* MW doesn't timout correctly, this handles it */ if (time() >= $prot['until']) { $persist_data->delete('protectsite'); } /* Protection-related code */ if (version_compare($wgVersion, '1.8', '>=')) { /* Code for MediaWiki 1.8 */ $wgGroupPermissions['*']['createaccount'] = !($prot['createaccount'] >= 1); $wgGroupPermissions['user']['createaccount'] = !($prot['createaccount'] == 2); $wgGroupPermissions['*']['createpage'] = !($prot['createpage'] >= 1); $wgGroupPermissions['*']['createtalk'] = !($prot['createpage'] >= 1); $wgGroupPermissions['user']['createpage'] = !($prot['createpage'] == 2); $wgGroupPermissions['user']['createtalk'] = !($prot['createpage'] == 2); $wgGroupPermissions['*']['edit'] = !($prot['edit'] >= 1); $wgGroupPermissions['user']['edit'] = !($prot['edit'] == 2); $wgGroupPermissions['sysop']['edit'] = true; $wgGroupPermissions['user']['move'] = !($prot['move'] == 1); $wgGroupPermissions['user']['upload'] = !($prot['upload'] == 1); $wgGroupPermissions['user']['reupload'] = !($prot['upload'] == 1); $wgGroupPermissions['user']['reupload-shared'] = !($prot['upload'] == 1); } else { /* Code for MediaWiki 1.7 (and possibly below) */ if (!in_array('sysop', $wgUser->mGroups) && !in_array('bureaucrat', $wgUser->mGroups)) { if ($wgUser->mId == 0) { if ($prot['createaccount'] >= 1) { $wgUser->mRights = chop_array($wgUser->mRights, 'createaccount'); } if ($prot['createpage'] >= 1) { $wgUser->mRights = chop_array($wgUser->mRights, 'createpage'); $wgUser->mRights = chop_array($wgUser->mRights, 'createtalk'); } if ($prot['edit'] >= 1) { $wgUser->mRights = chop_array($wgUser->mRights, 'edit'); } } else { if ($prot['createaccount'] == 2) { $wgUser->mRights = chop_array($wgUser->mRights, 'createaccount'); } if ($prot['createpage'] == 2) { $wgUser->mRights = chop_array($wgUser->mRights, 'createpage'); $wgUser->mRights = chop_array($wgUser->mRights, 'createtalk'); } if ($prot['edit'] == 2) { $wgUser->mRights = chop_array($wgUser->mRights, 'edit'); } if ($prot['move'] == 1) { $wgUser->mRights = chop_array($wgUser->mRights, 'move'); } if ($prot['upload'] == 1) { $wgUser->mRights = chop_array($wgUser->mRights, 'upload'); $wgUser->mRights = chop_array($wgUser->mRights, 'reupload'); $wgUser->mRights = chop_array($wgUser->mRights, 'reupload-shared'); } } } } } }
/** * Persistent data is unserialized from a record in the objectcache table * which is set in the Special page. It will change the permissions for * various functions for anonymous and registered users based on the data * in the array. The data expires after the set amount of time, just like * a block. */ function wfSetupProtectsite() { /* Globals */ global $wgGroupPermissions, $wgMemc, $wgProtectSiteExempt, $wgCommandLineMode; // macbre: don't run code below when running in command line mode (memcache starts to act strange) if ( !empty( $wgCommandLineMode ) ) { return; } /* Initialize Object */ $persist_data = new MediaWikiBagOStuff(); /* Get data into the prot hash */ $prot = $wgMemc->get( wfMemcKey( 'protectsite' ) ); if( !$prot ) { $prot = $persist_data->get( 'protectsite' ); if( !$prot ) { $wgMemc->set( wfMemcKey( 'protectsite' ), 'disabled' ); } } /* Logic to disable the selected user rights */ if( is_array( $prot ) ) { /* MW doesn't timeout correctly, this handles it */ if( time() >= $prot['until'] ) { $persist_data->delete( 'protectsite' ); } /* Protection-related code for MediaWiki 1.8+ */ $wgGroupPermissions['*']['createaccount'] = !( $prot['createaccount'] >= 1 ); $wgGroupPermissions['user']['createaccount'] = !( $prot['createaccount'] == 2 ); $wgGroupPermissions['*']['createpage'] = !( $prot['createpage'] >= 1 ); $wgGroupPermissions['*']['createtalk'] = !( $prot['createpage'] >= 1 ); $wgGroupPermissions['user']['createpage'] = !( $prot['createpage'] == 2 ); $wgGroupPermissions['user']['createtalk'] = !( $prot['createpage'] == 2 ); $wgGroupPermissions['*']['edit'] = !( $prot['edit'] >= 1 ); $wgGroupPermissions['user']['edit'] = !( $prot['edit'] == 2 ); $wgGroupPermissions['sysop']['edit'] = true; $wgGroupPermissions['user']['move'] = !( $prot['move'] == 1 ); $wgGroupPermissions['user']['upload'] = !( $prot['upload'] == 1 ); $wgGroupPermissions['user']['reupload'] = !( $prot['upload'] == 1 ); $wgGroupPermissions['user']['reupload-shared'] = !( $prot['upload'] == 1 ); // are there any groups that should not get affected by ProtectSite's lockdown? if( !empty( $wgProtectSiteExempt ) && is_array( $wgProtectSiteExempt ) ) { // there are, so loop over them, and force these rights to be true // will resolve any problems from inheriting rights from 'user' or 'sysop' foreach( $wgProtectSiteExempt as $exemptGroup ) { $wgGroupPermissions[$exemptGroup]['edit'] = 1; $wgGroupPermissions[$exemptGroup]['createpage'] = 1; $wgGroupPermissions[$exemptGroup]['createtalk'] = 1; $wgGroupPermissions[$exemptGroup]['move'] = 1; $wgGroupPermissions[$exemptGroup]['upload'] = 1; $wgGroupPermissions[$exemptGroup]['reupload'] = 1; $wgGroupPermissions[$exemptGroup]['reupload-shared'] = 1; } } } }