Example #1
0
 /**
  * @param integer|Status $status
  */
 public function __construct($status)
 {
     if ($status instanceof self) {
         $this->status = $status->getValue();
     } else {
         $this->status = (int) $status;
     }
 }
 /**
  * @param Status $status
  * @return bool
  */
 public function equals(Status $status)
 {
     if ($this == $status) {
         return true;
     }
     if ($this->status == $status->getValue()) {
         return true;
     }
     return false;
 }
Example #3
0
 /**
  * Restore the given (or all) text and file revisions for the page.
  * Once restored, the items will be removed from the archive tables.
  * The deletion log will be updated with an undeletion notice.
  *
  * This also sets Status objects, $this->fileStatus and $this->revisionStatus
  * (depending what operations are attempted).
  *
  * @param array $timestamps Pass an empty array to restore all revisions,
  *   otherwise list the ones to undelete.
  * @param string $comment
  * @param array $fileVersions
  * @param bool $unsuppress
  * @param User $user User performing the action, or null to use $wgUser
  * @param string|string[] $tags Change tags to add to log entry
  *   ($user should be able to add the specified tags before this is called)
  * @return array(number of file revisions restored, number of image revisions
  *   restored, log message) on success, false on failure.
  */
 function undelete($timestamps, $comment = '', $fileVersions = [], $unsuppress = false, User $user = null, $tags = null)
 {
     // If both the set of text revisions and file revisions are empty,
     // restore everything. Otherwise, just restore the requested items.
     $restoreAll = empty($timestamps) && empty($fileVersions);
     $restoreText = $restoreAll || !empty($timestamps);
     $restoreFiles = $restoreAll || !empty($fileVersions);
     if ($restoreFiles && $this->title->getNamespace() == NS_FILE) {
         $img = wfLocalFile($this->title);
         $img->load(File::READ_LATEST);
         $this->fileStatus = $img->restore($fileVersions, $unsuppress);
         if (!$this->fileStatus->isOK()) {
             return false;
         }
         $filesRestored = $this->fileStatus->successCount;
     } else {
         $filesRestored = 0;
     }
     if ($restoreText) {
         $this->revisionStatus = $this->undeleteRevisions($timestamps, $unsuppress, $comment);
         if (!$this->revisionStatus->isOK()) {
             return false;
         }
         $textRestored = $this->revisionStatus->getValue();
     } else {
         $textRestored = 0;
     }
     // Touch the log!
     if ($textRestored && $filesRestored) {
         $reason = wfMessage('undeletedrevisions-files')->numParams($textRestored, $filesRestored)->inContentLanguage()->text();
     } elseif ($textRestored) {
         $reason = wfMessage('undeletedrevisions')->numParams($textRestored)->inContentLanguage()->text();
     } elseif ($filesRestored) {
         $reason = wfMessage('undeletedfiles')->numParams($filesRestored)->inContentLanguage()->text();
     } else {
         wfDebug("Undelete: nothing undeleted...\n");
         return false;
     }
     if (trim($comment) != '') {
         $reason .= wfMessage('colon-separator')->inContentLanguage()->text() . $comment;
     }
     if ($user === null) {
         global $wgUser;
         $user = $wgUser;
     }
     $logEntry = new ManualLogEntry('delete', 'restore');
     $logEntry->setPerformer($user);
     $logEntry->setTarget($this->title);
     $logEntry->setComment($reason);
     $logEntry->setTags($tags);
     Hooks::run('ArticleUndeleteLogEntry', [$this, &$logEntry, $user]);
     $logid = $logEntry->insert();
     $logEntry->publish($logid);
     return [$textRestored, $filesRestored, $reason];
 }
 /**
  * Process the form.  At this point we know that the user passes all the criteria in
  * userCanExecute(), and if the data array contains 'Username', etc, then Username
  * resets are allowed.
  * @param array $data
  * @throws MWException
  * @throws ThrottledError|PermissionsError
  * @return Status
  */
 public function onSubmit(array $data)
 {
     if (isset($data['Capture']) && !$this->getUser()->isAllowed('passwordreset')) {
         // The user knows they don't have the passwordreset permission,
         // but they tried to spoof the form. That's naughty
         throw new PermissionsError('passwordreset');
     }
     $username = isset($data['Username']) ? $data['Username'] : null;
     $email = isset($data['Email']) ? $data['Email'] : null;
     $capture = !empty($data['Capture']);
     $this->method = $username ? 'username' : 'email';
     $this->result = Status::wrap($this->passwordReset->execute($this->getUser(), $username, $email, $capture));
     if ($capture && $this->result->isOK()) {
         $this->passwords = $this->result->getValue();
     }
     if ($this->result->hasMessage('actionthrottledtext')) {
         throw new ThrottledError();
     }
     return $this->result;
 }
 /**
  * @covers Status::merge
  */
 public function testMergeWithOverwriteValue()
 {
     $status1 = new Status();
     $status2 = new Status();
     $message1 = $this->getMockMessage('warn1');
     $message2 = $this->getMockMessage('error2');
     $status1->warning($message1);
     $status2->error($message2);
     $status2->value = 'FooValue';
     $status1->merge($status2, true);
     $this->assertEquals(2, count($status1->getWarningsArray()) + count($status1->getErrorsArray()));
     $this->assertEquals('FooValue', $status1->getValue());
 }
 /**
  * Update newsletter-draft with selected recipients in newsletter object. Only possible with draft.
  *
  * @param $newsletter object
  * @return \Newsletter2Go\Status
  */
 public function updateNewsletter($newsletter)
 {
     $params = array();
     if ($newsletter instanceof Newsletter && $newsletter->getId() > 0) {
         $params['id'] = $newsletter->getId();
     }
     $params['name'] = $newsletter->getName();
     $params['subject'] = $newsletter->getSubject();
     if ($newsletter->getHtml()) {
         $params['html'] = $newsletter->getHtml();
     }
     if ($newsletter->getText()) {
         $params['text'] = $newsletter->getText();
     }
     $params['from'] = $newsletter->getFrom();
     $params['reply'] = $newsletter->getReply();
     if ($newsletter->getRef()) {
         $params['reference'] = $newsletter->getRef();
     }
     $result = new Status($this->handleSendRequest('/de/api/set/newsletter/', $params));
     $nId = $result->getValue();
     foreach ($newsletter->getRecipients() as $rcp) {
         $this->addRecipient2Newsletter($nId, $rcp);
     }
     return $result;
 }
 protected static function getRevision(Status $s)
 {
     $value = $s->getValue();
     return $value['revision'];
 }