Esempio n. 1
0
 /**
  * @todo Maybe translate block durations.  Note that this function is somewhat misnamed: it
  * deals with translating the *duration* ("1 week", "4 days", etc), not the expiry time
  * (which is an absolute timestamp). Please note: do NOT add this blindly, as it is used
  * on old expiry lengths recorded in log entries. You'd need to provide the start date to
  * match up with it.
  *
  * @param string $str The validated block duration in English
  * @return string Somehow translated block duration
  * @see LanguageFi.php for example implementation
  */
 function translateBlockExpiry($str)
 {
     $duration = SpecialBlock::getSuggestedDurations($this);
     foreach ($duration as $show => $value) {
         if (strcmp($str, $value) == 0) {
             return htmlspecialchars(trim($show));
         }
     }
     if (wfIsInfinity($str)) {
         foreach ($duration as $show => $value) {
             if (wfIsInfinity($value)) {
                 return htmlspecialchars(trim($show));
             }
         }
     }
     // If all else fails, return a standard duration or timestamp description.
     $time = strtotime($str, 0);
     if ($time === false) {
         // Unknown format. Return it as-is in case.
         return $str;
     } elseif ($time !== strtotime($str, 1)) {
         // It's a relative timestamp.
         // $time is relative to 0 so it's a duration length.
         return $this->formatDuration($time);
     } else {
         // It's an absolute timestamp.
         if ($time === 0) {
             // wfTimestamp() handles 0 as current time instead of epoch.
             return $this->timeanddate('19700101000000');
         } else {
             return $this->timeanddate($time);
         }
     }
 }
Esempio n. 2
0
 /**
  * @todo Maybe translate block durations.  Note that this function is somewhat misnamed: it
  * deals with translating the *duration* ("1 week", "4 days", etc), not the expiry time
  * (which is an absolute timestamp). Please note: do NOT add this blindly, as it is used
  * on old expiry lengths recorded in log entries. You'd need to provide the start date to
  * match up with it.
  *
  * @param $str String: the validated block duration in English
  * @return Somehow translated block duration
  * @see LanguageFi.php for example implementation
  */
 function translateBlockExpiry($str)
 {
     $duration = SpecialBlock::getSuggestedDurations($this);
     foreach ($duration as $show => $value) {
         if (strcmp($str, $value) == 0) {
             return htmlspecialchars(trim($show));
         }
     }
     // Since usually only infinite or indefinite is only on list, so try
     // equivalents if still here.
     $indefs = array('infinite', 'infinity', 'indefinite');
     if (in_array($str, $indefs)) {
         foreach ($indefs as $val) {
             $show = array_search($val, $duration, true);
             if ($show !== false) {
                 return htmlspecialchars(trim($show));
             }
         }
     }
     // If all else fails, return the original string.
     return $str;
 }
 /**
  * @todo Maybe translate block durations.  Note that this function is somewhat misnamed: it
  * deals with translating the *duration* ("1 week", "4 days", etc), not the expiry time
  * (which is an absolute timestamp). Please note: do NOT add this blindly, as it is used
  * on old expiry lengths recorded in log entries. You'd need to provide the start date to
  * match up with it.
  *
  * @param string $str The validated block duration in English
  * @return string Somehow translated block duration
  * @see LanguageFi.php for example implementation
  */
 function translateBlockExpiry($str)
 {
     $duration = SpecialBlock::getSuggestedDurations($this);
     foreach ($duration as $show => $value) {
         if (strcmp($str, $value) == 0) {
             return htmlspecialchars(trim($show));
         }
     }
     // Since usually only infinite or indefinite is only on list, so try
     // equivalents if still here.
     $indefs = array('infinite', 'infinity', 'indefinite');
     if (in_array($str, $indefs)) {
         foreach ($indefs as $val) {
             $show = array_search($val, $duration, true);
             if ($show !== false) {
                 return htmlspecialchars(trim($show));
             }
         }
     }
     // If all else fails, return a standard duration or timestamp description.
     $time = strtotime($str, 0);
     if ($time === false) {
         // Unknown format. Return it as-is in case.
         return $str;
     } elseif ($time !== strtotime($str, 1)) {
         // It's a relative timestamp.
         // $time is relative to 0 so it's a duration length.
         return $this->formatDuration($time);
     } else {
         // It's an absolute timestamp.
         if ($time === 0) {
             // wfTimestamp() handles 0 as current time instead of epoch.
             return $this->timeanddate('19700101000000');
         } else {
             return $this->timeanddate($time);
         }
     }
 }