Exemplo n.º 1
0
 public function fetchValuesFromRequest(WebRequest $r, $values = false)
 {
     if (!$values) {
         $values = array_keys($this->options);
     }
     foreach ($values as $name) {
         $default = $this->options[$name]['default'];
         $type = $this->options[$name]['type'];
         switch ($type) {
             case self::BOOL:
                 $value = $r->getBool($name, $default);
                 break;
             case self::INT:
                 $value = $r->getInt($name, $default);
                 break;
             case self::STRING:
                 $value = $r->getText($name, $default);
                 break;
             case self::INTNULL:
                 $value = $r->getIntOrNull($name);
                 break;
             default:
                 throw new MWException('Unsupported datatype');
         }
         if ($value !== null) {
             $this->options[$name]['value'] = $value === $default ? null : $value;
         }
     }
 }
 /**
  * Guess the rev ID the text of this form is based off
  * Note: baseRevId trusted for Reviewers - check text for others.
  * @return int
  */
 protected static function getBaseRevId(EditPage $editPage, WebRequest $request)
 {
     if (!isset($editPage->fr_baseRevId)) {
         $article = $editPage->getArticle();
         // convenience
         $latestId = $article->getLatest();
         // current rev
         $undo = $request->getIntOrNull('undo');
         # Undoing consecutive top edits...
         if ($undo && $undo === $latestId) {
             # Treat this like a revert to a base revision.
             # We are undoing all edits *after* some rev ID (undoafter).
             # If undoafter is not given, then it is the previous rev ID.
             $revId = $request->getInt('undoafter', $article->getTitle()->getPreviousRevisionID($latestId, Title::GAID_FOR_UPDATE));
             # Undoing other edits...
         } elseif ($undo) {
             $revId = $latestId;
             // current rev is the base rev
             # Other edits...
         } else {
             # If we are editing via oldid=X, then use that rev ID.
             # Otherwise, check if the client specified the ID (bug 23098).
             $revId = $article->getOldID() ? $article->getOldID() : $request->getInt('baseRevId');
             // e.g. "show changes"/"preview"
         }
         # Zero oldid => draft revision
         if (!$revId) {
             $revId = $latestId;
         }
         $editPage->fr_baseRevId = $revId;
     }
     return $editPage->fr_baseRevId;
 }
 /**
  * Guess the alternative rev ID the text of this form is based off.
  * When undoing the top X edits, the base can be though of as either
  * the current or the edit X edits prior to the latest.
  * Note: baseRevId trusted for Reviewers - check text for others.
  * @param EditPage $editPage
  * @param WebRequest $request
  * @return int
  */
 protected static function getAltBaseRevId(EditPage $editPage, WebRequest $request)
 {
     if ($editPage->isConflict) {
         return 0;
         // throw away these values (bug 33481)
     }
     if (!isset($editPage->fr_altBaseRevId)) {
         $article = $editPage->getArticle();
         // convenience
         $latestId = $article->getLatest();
         // current rev
         $undo = $request->getIntOrNull('undo');
         # Undoing consecutive top edits...
         if ($undo && $undo === $latestId) {
             # Treat this like a revert to a base revision.
             # We are undoing all edits *after* some rev ID (undoafter).
             # If undoafter is not given, then it is the previous rev ID.
             $revId = $request->getInt('undoafter', $article->getTitle()->getPreviousRevisionID($latestId, Title::GAID_FOR_UPDATE));
         } else {
             $revId = $request->getInt('altBaseRevId');
         }
         $editPage->fr_altBaseRevId = $revId;
     }
     return $editPage->fr_altBaseRevId;
 }