public function checkPermissions(User $user, $reason) { $status = new Status(); $errors = wfMergeErrorArrays($this->oldTitle->getUserPermissionsErrors('move', $user), $this->oldTitle->getUserPermissionsErrors('edit', $user), $this->newTitle->getUserPermissionsErrors('move-target', $user), $this->newTitle->getUserPermissionsErrors('edit', $user)); // Convert into a Status object if ($errors) { foreach ($errors as $error) { call_user_func_array(array($status, 'fatal'), $error); } } if (EditPage::matchSummarySpamRegex($reason) !== false) { // This is kind of lame, won't display nice $status->fatal('spamprotectiontext'); } # The move is allowed only if (1) the target doesn't exist, or # (2) the target is a redirect to the source, and has no history # (so we can undo bad moves right after they're done). if ($this->newTitle->getArticleID()) { # Target exists; check for validity if (!$this->isValidMoveTarget()) { $status->fatal('articleexists'); } } else { $tp = $this->newTitle->getTitleProtection(); if ($tp !== false) { if (!$user->isAllowed($tp['permission'])) { $status->fatal('cantmove-titleprotected'); } } } Hooks::run('MovePageCheckPermissions', array($this->oldTitle, $this->newTitle, $user, $reason, $status)); return $status; }
protected function getFormFields() { $that = $this; $fields = array('pagetitle' => array('type' => 'text', 'name' => 'pagetitle', 'default' => $this->par, 'label-message' => 'changecontentmodel-title-label', 'validation-callback' => array($this, 'validateTitle'))); if ($this->title) { $fields['pagetitle']['readonly'] = true; $fields += array('model' => array('type' => 'select', 'name' => 'model', 'options' => $this->getOptionsForTitle($this->title), 'label-message' => 'changecontentmodel-model-label'), 'reason' => array('type' => 'text', 'name' => 'reason', 'validation-callback' => function ($reason) use($that) { $match = EditPage::matchSummarySpamRegex($reason); if ($match) { return $that->msg('spamprotectionmatch', $match)->parse(); } return true; }, 'label-message' => 'changecontentmodel-reason-label')); } return $fields; }
protected function getFormFields() { $fields = ['pagetitle' => ['type' => 'title', 'creatable' => true, 'name' => 'pagetitle', 'default' => $this->par, 'label-message' => 'changecontentmodel-title-label', 'validation-callback' => [$this, 'validateTitle']]]; if ($this->title) { $options = $this->getOptionsForTitle($this->title); if (empty($options)) { throw new ErrorPageError('changecontentmodel-emptymodels-title', 'changecontentmodel-emptymodels-text', $this->title->getPrefixedText()); } $fields['pagetitle']['readonly'] = true; $fields += ['model' => ['type' => 'select', 'name' => 'model', 'options' => $options, 'label-message' => 'changecontentmodel-model-label'], 'reason' => ['type' => 'text', 'name' => 'reason', 'validation-callback' => function ($reason) { $match = EditPage::matchSummarySpamRegex($reason); if ($match) { return $this->msg('spamprotectionmatch', $match)->parse(); } return true; }, 'label-message' => 'changecontentmodel-reason-label']]; } return $fields; }
public function checkPermissions(User $user, $reason) { $status = new Status(); $errors = wfMergeErrorArrays($this->oldTitle->getUserPermissionsErrors('move', $user), $this->oldTitle->getUserPermissionsErrors('edit', $user), $this->newTitle->getUserPermissionsErrors('move-target', $user), $this->newTitle->getUserPermissionsErrors('edit', $user)); // Convert into a Status object if ($errors) { foreach ($errors as $error) { call_user_func_array(array($status, 'fatal'), $error); } } if (EditPage::matchSummarySpamRegex($reason) !== false) { // This is kind of lame, won't display nice $status->fatal('spamprotectiontext'); } $tp = $this->newTitle->getTitleProtection(); if ($tp !== false && !$user->isAllowed($tp['permission'])) { $status->fatal('cantmove-titleprotected'); } Hooks::run('MovePageCheckPermissions', array($this->oldTitle, $this->newTitle, $user, $reason, $status)); return $status; }
/** * Check whether a given move operation would be valid. * Returns true if ok, or a getUserPermissionsErrors()-like array otherwise * * @param $nt Title the new title * @param $auth Bool indicates whether $wgUser's permissions * should be checked * @param $reason String is the log summary of the move, used for spam checking * @return Mixed True on success, getUserPermissionsErrors()-like array on failure */ public function isValidMoveOperation(&$nt, $auth = true, $reason = '') { global $wgUser; $errors = array(); if (!$nt) { // Normally we'd add this to $errors, but we'll get // lots of syntax errors if $nt is not an object return array(array('badtitletext')); } if ($this->equals($nt)) { $errors[] = array('selfmove'); } if (!$this->isMovable()) { $errors[] = array('immobile-source-namespace', $this->getNsText()); } if ($nt->getInterwiki() != '') { $errors[] = array('immobile-target-namespace-iw'); } if (!$nt->isMovable()) { $errors[] = array('immobile-target-namespace', $nt->getNsText()); } $oldid = $this->getArticleID(); $newid = $nt->getArticleID(); if (strlen($nt->getDBkey()) < 1) { $errors[] = array('articleexists'); } if ($this->getDBkey() == '' || !$oldid || $nt->getDBkey() == '') { $errors[] = array('badarticleerror'); } // Image-specific checks if ($this->getNamespace() == NS_FILE) { $errors = array_merge($errors, $this->validateFileMoveOperation($nt)); } if ($nt->getNamespace() == NS_FILE && $this->getNamespace() != NS_FILE) { $errors[] = array('nonfile-cannot-move-to-file'); } if ($auth) { $errors = wfMergeErrorArrays($errors, $this->getUserPermissionsErrors('move', $wgUser), $this->getUserPermissionsErrors('edit', $wgUser), $nt->getUserPermissionsErrors('move-target', $wgUser), $nt->getUserPermissionsErrors('edit', $wgUser)); } $match = EditPage::matchSummarySpamRegex($reason); if ($match !== false) { // This is kind of lame, won't display nice $errors[] = array('spamprotectiontext'); } $err = null; if (!wfRunHooks('AbortMove', array($this, $nt, $wgUser, &$err, $reason))) { $errors[] = array('hookaborted', $err); } # The move is allowed only if (1) the target doesn't exist, or # (2) the target is a redirect to the source, and has no history # (so we can undo bad moves right after they're done). if (0 != $newid) { # Target exists; check for validity if (!$this->isValidMoveTarget($nt)) { $errors[] = array('articleexists'); } } else { $tp = $nt->getTitleProtection(); $right = $tp['pt_create_perm'] == 'sysop' ? 'protect' : $tp['pt_create_perm']; if ($tp and !$wgUser->isAllowed($right)) { $errors[] = array('cantmove-titleprotected'); } } if (empty($errors)) { return true; } return $errors; }
/** * Check if the merge is possible * @param User $user * @param string $reason * @return Status */ public function checkPermissions(User $user, $reason) { $status = new Status(); // Check if user can edit both pages $errors = wfMergeErrorArrays($this->source->getUserPermissionsErrors('edit', $user), $this->dest->getUserPermissionsErrors('edit', $user)); // Convert into a Status object if ($errors) { foreach ($errors as $error) { call_user_func_array(array($status, 'fatal'), $error); } } // Anti-spam if (EditPage::matchSummarySpamRegex($reason) !== false) { // This is kind of lame, won't display nice $status->fatal('spamprotectiontext'); } // Check mergehistory permission if (!$user->isAllowed('mergehistory')) { // User doesn't have the right to merge histories $status->fatal('mergehistory-fail-permission'); } return $status; }