'StubObject' => 'includes/StubObject.php',
'StubUserLang' => 'includes/StubObject.php',
'TablePager' => 'includes/Pager.php',
+ 'MWTimestamp' => 'includes/Timestamp.php',
'Title' => 'includes/Title.php',
'TitleArray' => 'includes/TitleArray.php',
'TitleArrayFromResult' => 'includes/TitleArray.php',
*/
$wgCopyUploadsDomains = array();
-/**
- * Enable copy uploads from Special:Upload. $wgAllowCopyUploads must also be
- * true. If $wgAllowCopyUploads is true, but this is false, you will only be
- * able to perform copy uploads from the API or extensions (e.g. UploadWizard).
- */
-$wgCopyUploadsFromSpecialUpload = false;
-
/**
* Max size for uploads, in bytes. If not set to an array, applies to all
* uploads. If set to an array, per upload type maximums can be set, using the
/**
* Get a timestamp string in one of various formats
*
+ * @deprecated
* @param $outputtype Mixed: A timestamp in one of the supported formats, the
* function will autodetect which format is supplied and act
* accordingly.
* @return Mixed: String / false The same date in the format specified in $outputtype or false
*/
function wfTimestamp( $outputtype = TS_UNIX, $ts = 0 ) {
- $uts = 0;
- $da = array();
- $strtime = '';
-
- if ( !$ts ) { // We want to catch 0, '', null... but not date strings starting with a letter.
- $uts = time();
- $strtime = "@$uts";
- } elseif ( preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)$/D', $ts, $da ) ) {
- # TS_DB
- } elseif ( preg_match( '/^(\d{4}):(\d\d):(\d\d) (\d\d):(\d\d):(\d\d)$/D', $ts, $da ) ) {
- # TS_EXIF
- } elseif ( preg_match( '/^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/D', $ts, $da ) ) {
- # TS_MW
- } elseif ( preg_match( '/^-?\d{1,13}$/D', $ts ) ) {
- # TS_UNIX
- $uts = $ts;
- $strtime = "@$ts"; // http://php.net/manual/en/datetime.formats.compound.php
- } elseif ( preg_match( '/^\d{2}-\d{2}-\d{4} \d{2}:\d{2}:\d{2}.\d{6}$/', $ts ) ) {
- # TS_ORACLE // session altered to DD-MM-YYYY HH24:MI:SS.FF6
- $strtime = preg_replace( '/(\d\d)\.(\d\d)\.(\d\d)(\.(\d+))?/', "$1:$2:$3",
- str_replace( '+00:00', 'UTC', $ts ) );
- } elseif ( preg_match( '/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.*\d*)?Z$/', $ts, $da ) ) {
- # TS_ISO_8601
- } elseif ( preg_match( '/^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})(?:\.*\d*)?Z$/', $ts, $da ) ) {
- #TS_ISO_8601_BASIC
- } elseif ( preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)\.*\d*[\+\- ](\d\d)$/', $ts, $da ) ) {
- # TS_POSTGRES
- } elseif ( preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)\.*\d* GMT$/', $ts, $da ) ) {
- # TS_POSTGRES
- } elseif (preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)\.\d\d\d$/', $ts, $da ) ) {
- # TS_DB2
- } elseif ( preg_match( '/^[ \t\r\n]*([A-Z][a-z]{2},[ \t\r\n]*)?' . # Day of week
- '\d\d?[ \t\r\n]*[A-Z][a-z]{2}[ \t\r\n]*\d{2}(?:\d{2})?' . # dd Mon yyyy
- '[ \t\r\n]*\d\d[ \t\r\n]*:[ \t\r\n]*\d\d[ \t\r\n]*:[ \t\r\n]*\d\d/S', $ts ) ) { # hh:mm:ss
- # TS_RFC2822, accepting a trailing comment. See http://www.squid-cache.org/mail-archive/squid-users/200307/0122.html / r77171
- # The regex is a superset of rfc2822 for readability
- $strtime = strtok( $ts, ';' );
- } elseif ( preg_match( '/^[A-Z][a-z]{5,8}, \d\d-[A-Z][a-z]{2}-\d{2} \d\d:\d\d:\d\d/', $ts ) ) {
- # TS_RFC850
- $strtime = $ts;
- } elseif ( preg_match( '/^[A-Z][a-z]{2} [A-Z][a-z]{2} +\d{1,2} \d\d:\d\d:\d\d \d{4}/', $ts ) ) {
- # asctime
- $strtime = $ts;
- } else {
- # Bogus value...
- wfDebug("wfTimestamp() fed bogus time value: TYPE=$outputtype; VALUE=$ts\n");
-
- return false;
- }
-
- static $formats = array(
- TS_UNIX => 'U',
- TS_MW => 'YmdHis',
- TS_DB => 'Y-m-d H:i:s',
- TS_ISO_8601 => 'Y-m-d\TH:i:s\Z',
- TS_ISO_8601_BASIC => 'Ymd\THis\Z',
- TS_EXIF => 'Y:m:d H:i:s', // This shouldn't ever be used, but is included for completeness
- TS_RFC2822 => 'D, d M Y H:i:s',
- TS_ORACLE => 'd-m-Y H:i:s.000000', // Was 'd-M-y h.i.s A' . ' +00:00' before r51500
- TS_POSTGRES => 'Y-m-d H:i:s',
- TS_DB2 => 'Y-m-d H:i:s',
- );
-
- if ( !isset( $formats[$outputtype] ) ) {
- throw new MWException( 'wfTimestamp() called with illegal output type.' );
- }
-
- if ( function_exists( "date_create" ) ) {
- if ( count( $da ) ) {
- $ds = sprintf("%04d-%02d-%02dT%02d:%02d:%02d.00+00:00",
- (int)$da[1], (int)$da[2], (int)$da[3],
- (int)$da[4], (int)$da[5], (int)$da[6]);
-
- $d = date_create( $ds, new DateTimeZone( 'GMT' ) );
- } elseif ( $strtime ) {
- $d = date_create( $strtime, new DateTimeZone( 'GMT' ) );
- } else {
- return false;
- }
-
- if ( !$d ) {
- wfDebug("wfTimestamp() fed bogus time value: $outputtype; $ts\n");
- return false;
- }
-
- $output = $d->format( $formats[$outputtype] );
- } else {
- if ( count( $da ) ) {
- // Warning! gmmktime() acts oddly if the month or day is set to 0
- // We may want to handle that explicitly at some point
- $uts = gmmktime( (int)$da[4], (int)$da[5], (int)$da[6],
- (int)$da[2], (int)$da[3], (int)$da[1] );
- } elseif ( $strtime ) {
- $uts = strtotime( $strtime );
- }
-
- if ( $uts === false ) {
- wfDebug("wfTimestamp() can't parse the timestamp (non 32-bit time? Update php): $outputtype; $ts\n");
- return false;
- }
-
- if ( TS_UNIX == $outputtype ) {
- return $uts;
- }
- $output = gmdate( $formats[$outputtype], $uts );
- }
-
- if ( ( $outputtype == TS_RFC2822 ) || ( $outputtype == TS_POSTGRES ) ) {
- $output .= ' GMT';
- }
-
- return $output;
+ $timestamp = new MWTimestamp( $ts );
+ return $timestamp->getTimestamp( $outputtype );
}
/**
--- /dev/null
+<?php
+
+/**
+ * Library for creating and parsing MW-style timestamps. Based on the JS
+ * library that does the same thing.
+ *
+ * @author Tyler Romeo, 2012
+ * @since 1.20
+ */
+class MWTimestamp {
+ /**
+ * Standard gmdate() formats for the different timestamp types.
+ */
+ private static $formats = array(
+ TS_UNIX => 'U',
+ TS_MW => 'YmdHis',
+ TS_DB => 'Y-m-d H:i:s',
+ TS_ISO_8601 => 'Y-m-d\TH:i:s\Z',
+ TS_ISO_8601_BASIC => 'Ymd\THis\Z',
+ TS_EXIF => 'Y:m:d H:i:s', // This shouldn't ever be used, but is included for completeness
+ TS_RFC2822 => 'D, d M Y H:i:s',
+ TS_ORACLE => 'd-m-Y H:i:s.000000', // Was 'd-M-y h.i.s A' . ' +00:00' before r51500
+ TS_POSTGRES => 'Y-m-d H:i:s',
+ TS_DB2 => 'Y-m-d H:i:s',
+ );
+
+ /**
+ * Different units for human readable timestamps.
+ * @see MWTimestamp::getHumanTimestamp
+ */
+ private static $units = array(
+ "milliseconds" => 1,
+ "seconds" => 1000, // 1000 milliseconds per second
+ "minutes" => 60, // 60 seconds per minute
+ "hours" => 60, // 60 minutes per hour
+ "days" => 24 // 24 hours per day
+ );
+
+ /**
+ * The actual timestamp being wrapped. Either a DateTime
+ * object or a string with a Unix timestamp depending on
+ * PHP.
+ */
+ private $timestamp;
+
+ /**
+ * Make a new timestamp and set it to the specified time,
+ * or the current time if unspecified.
+ *
+ * @param $timestamp Timestamp to set, or false for current time
+ */
+ public function __construct( $timestamp = false ) {
+ $this->setTimestamp( $timestamp );
+ }
+
+ /**
+ * Set the timestamp to the specified time, or the current time if unspecified.
+ *
+ * Parse the given timestamp into either a DateTime object or a Unix teimstamp,
+ * and then store it.
+ *
+ * @param $ts Timestamp to store, or false for now
+ */
+ public function setTimestamp( $ts = false ) {
+ $uts = 0;
+ $da = array();
+ $strtime = '';
+
+ if ( !$ts ) { // We want to catch 0, '', null... but not date strings starting with a letter.
+ $uts = time();
+ $strtime = "@$uts";
+ } elseif ( preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)$/D', $ts, $da ) ) {
+ # TS_DB
+ } elseif ( preg_match( '/^(\d{4}):(\d\d):(\d\d) (\d\d):(\d\d):(\d\d)$/D', $ts, $da ) ) {
+ # TS_EXIF
+ } elseif ( preg_match( '/^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/D', $ts, $da ) ) {
+ # TS_MW
+ } elseif ( preg_match( '/^-?\d{1,13}$/D', $ts ) ) {
+ # TS_UNIX
+ $uts = $ts;
+ $strtime = "@$ts"; // http://php.net/manual/en/datetime.formats.compound.php
+ } elseif ( preg_match( '/^\d{2}-\d{2}-\d{4} \d{2}:\d{2}:\d{2}.\d{6}$/', $ts ) ) {
+ # TS_ORACLE // session altered to DD-MM-YYYY HH24:MI:SS.FF6
+ $strtime = preg_replace( '/(\d\d)\.(\d\d)\.(\d\d)(\.(\d+))?/', "$1:$2:$3",
+ str_replace( '+00:00', 'UTC', $ts ) );
+ } elseif ( preg_match( '/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.*\d*)?Z$/', $ts, $da ) ) {
+ # TS_ISO_8601
+ } elseif ( preg_match( '/^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})(?:\.*\d*)?Z$/', $ts, $da ) ) {
+ #TS_ISO_8601_BASIC
+ } elseif ( preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)\.*\d*[\+\- ](\d\d)$/', $ts, $da ) ) {
+ # TS_POSTGRES
+ } elseif ( preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)\.*\d* GMT$/', $ts, $da ) ) {
+ # TS_POSTGRES
+ } elseif (preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)\.\d\d\d$/', $ts, $da ) ) {
+ # TS_DB2
+ } elseif ( preg_match( '/^[ \t\r\n]*([A-Z][a-z]{2},[ \t\r\n]*)?' . # Day of week
+ '\d\d?[ \t\r\n]*[A-Z][a-z]{2}[ \t\r\n]*\d{2}(?:\d{2})?' . # dd Mon yyyy
+ '[ \t\r\n]*\d\d[ \t\r\n]*:[ \t\r\n]*\d\d[ \t\r\n]*:[ \t\r\n]*\d\d/S', $ts ) ) { # hh:mm:ss
+ # TS_RFC2822, accepting a trailing comment. See http://www.squid-cache.org/mail-archive/squid-users/200307/0122.html / r77171
+ # The regex is a superset of rfc2822 for readability
+ $strtime = strtok( $ts, ';' );
+ } elseif ( preg_match( '/^[A-Z][a-z]{5,8}, \d\d-[A-Z][a-z]{2}-\d{2} \d\d:\d\d:\d\d/', $ts ) ) {
+ # TS_RFC850
+ $strtime = $ts;
+ } elseif ( preg_match( '/^[A-Z][a-z]{2} [A-Z][a-z]{2} +\d{1,2} \d\d:\d\d:\d\d \d{4}/', $ts ) ) {
+ # asctime
+ $strtime = $ts;
+ } else {
+ throw new TimestampException( __METHOD__ . " : Invalid timestamp - $ts" );
+ }
+
+ if( !$strtime ) {
+ $da = array_map( 'intval', $da );
+ $da[0] = "%04d-%02d-%02dT%02d:%02d:%02d.00+00:00";
+ $strtime = call_user_func_array( "sprintf", $da );
+ }
+
+ if( function_exists( "date_create" ) ) {
+ try {
+ $final = new DateTime( $strtime, new DateTimeZone( 'GMT' ) );
+ } catch(Exception $e) {
+ throw new TimestampException( __METHOD__ . 'Invalid timestamp format.' );
+ }
+ } else {
+ $final = strtotime( $strtime );
+ }
+
+ if( $final === false ) {
+ throw new TimestampException( __METHOD__ . 'Invalid timestamp format.' );
+ }
+ $this->timestamp = $final;
+ }
+
+ /**
+ * Get the timestamp represented by this object in a certain form.
+ *
+ * Convert the internal timestamp to the specified format and then
+ * return it.
+ *
+ * @param $style Output format for timestamp
+ * @return string The formatted timestamp
+ */
+ public function getTimestamp( $style = TS_UNIX ) {
+ if( !isset( self::$formats[$style] ) ) {
+ throw new TimestampException( __METHOD__ . ' : Illegal timestamp output type.' );
+ }
+
+ if( is_object( $this->timestamp ) ) {
+ // DateTime object was used, call DateTime::format.
+ $output = $this->timestamp->format( self::$formats[$style] );
+ } elseif( TS_UNIX == $style ) {
+ // Unix timestamp was used and is wanted, just return it.
+ $output = $this->timestamp;
+ } else {
+ // Unix timestamp was used, use gmdate().
+ $output = gmdate( self::$formats[$style], $this->timestamp );
+ }
+
+ if ( ( $style == TS_RFC2822 ) || ( $style == TS_POSTGRES ) ) {
+ $output .= ' GMT';
+ }
+
+ return $output;
+ }
+
+ /**
+ * Get the timestamp in a human-friendly relative format, e.g., "3 days ago".
+ *
+ * Determine the difference between the timestamp and the current time, and
+ * generate a readable timestamp by returning "<N> <units> ago", where the
+ * largest possible unit is used.
+ *
+ * @return string Formatted timestamp
+ */
+ public function getHumanTimestamp() {
+ $then = $this->getTimestamp( TS_UNIX );
+ $now = time();
+ $timeago = ($now - $then) * 1000;
+ $message = false;
+
+ foreach( self::$units as $unit => $factor ) {
+ $next = $timeago / $factor;
+ if( $next < 1 ) {
+ break;
+ } else {
+ $timeago = $next;
+ $message = array( $unit, floor( $timeago ) );
+ }
+ }
+
+ if( $message ) {
+ $initial = call_user_func_array( 'wfMessage', $message );
+ return wfMessage( 'ago', $initial );
+ } else {
+ return wfMessage( 'just-now' );
+ }
+ }
+
+ public function __toString() {
+ return $this->getTimestamp();
+ }
+}
+
+class TimestampException extends MWException {}
* @return Title the new object
*/
public static function newMainPage() {
- $title = Title::newFromText( wfMsgForContent( 'mainpage' ) );
+ $title = Title::newFromText( wfMessage( 'mainpage' )->inContentLanguage()->text() );
// Don't give fatal errors if the message is broken
if ( !$title ) {
$title = Title::newFromText( 'Main Page' );
* queries by skipping checks for cascading protections and user blocks.
* @param $ignoreErrors Array of Strings Set this to a list of message keys
* whose corresponding errors may be ignored.
- * @return Array of arguments to wfMsg to explain permissions problems.
+ * @return Array of arguments to wfMessage to explain permissions problems.
*/
public function getUserPermissionsErrors( $action, $user, $doExpensiveQueries = true, $ignoreErrors = array() ) {
$errors = $this->getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries );
# Check $wgNamespaceProtection for restricted namespaces
if ( $this->isNamespaceProtected( $user ) ) {
$ns = $this->mNamespace == NS_MAIN ?
- wfMsg( 'nstab-main' ) : $this->getNsText();
+ wfMessage( 'nstab-main' )->text() : $this->getNsText();
$errors[] = $this->mNamespace == NS_MEDIAWIKI ?
array( 'protectedinterface' ) : array( 'namespaceprotected', $ns );
}
$id = $user->blockedBy();
$reason = $user->blockedFor();
if ( $reason == '' ) {
- $reason = wfMsg( 'blockednoreason' );
+ $reason = wfMessage( 'blockednoreason' )->text();
}
$ip = $user->getRequest()->getIP();
* @param $user User to check
* @param $doExpensiveQueries Bool Set this to false to avoid doing unnecessary queries.
* @param $short Bool Set this to true to stop after the first permission error.
- * @return Array of arrays of the arguments to wfMsg to explain permissions problems.
+ * @return Array of arrays of the arguments to wfMessage to explain permissions problems.
*/
protected function getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries = true, $short = false ) {
wfProfileIn( __METHOD__ );
);
# Update the protection log
$log = new LogPage( 'protect' );
- $comment = wfMsgForContent( 'prot_1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
+ $comment = wfMessage(
+ 'prot_1movedto2',
+ $this->getPrefixedText(),
+ $nt->getPrefixedText()
+ )->inContentLanguage()->text();
if ( $reason ) {
- $comment .= wfMsgForContent( 'colon-separator' ) . $reason;
+ $comment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $reason;
}
// @todo FIXME: $params?
$log->addEntry( 'move_prot', $nt, $comment, array( $this->getPrefixedText() ) );
$formatter->setContext( RequestContext::newExtraneousContext( $this ) );
$comment = $formatter->getPlainActionText();
if ( $reason ) {
- $comment .= wfMsgForContent( 'colon-separator' ) . $reason;
+ $comment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $reason;
}
# Truncate for whole multibyte characters.
$comment = $wgContLang->truncate( $comment, 255 );
// Certain names may be reserved for batch processes.
foreach ( $reservedUsernames as $reserved ) {
if ( substr( $reserved, 0, 4 ) == 'msg:' ) {
- $reserved = wfMsgForContent( substr( $reserved, 4 ) );
+ $reserved = wfMessage( substr( $reserved, 4 ) )->inContentLanguage()->text();
}
if ( $reserved == $name ) {
return false;
# Local list
if ( self::isLocallyBlockedProxy( $ip ) ) {
$block = new Block;
- $block->setBlocker( wfMsg( 'proxyblocker' ) );
- $block->mReason = wfMsg( 'proxyblockreason' );
+ $block->setBlocker( wfMessage( 'proxyblocker' )->text() );
+ $block->mReason = wfMessage( 'proxyblockreason' )->text();
$block->setTarget( $ip );
} elseif ( $this->isAnon() && $this->isDnsBlacklisted( $ip ) ) {
$block = new Block;
- $block->setBlocker( wfMsg( 'sorbs' ) );
- $block->mReason = wfMsg( 'sorbsreason' );
+ $block->setBlocker( wfMessage( 'sorbs' )->text() );
+ $block->mReason = wfMessage( 'sorbsreason' )->text();
$block->setTarget( $ip );
}
}
if( $str !== null ) {
if( !$wgAuth->allowPasswordChange() ) {
- throw new PasswordError( wfMsg( 'password-change-forbidden' ) );
+ throw new PasswordError( wfMessage( 'password-change-forbidden' )->text() );
}
if( !$this->isValidPassword( $str ) ) {
$message = $valid;
$params = array( $wgMinimalPasswordLength );
}
- throw new PasswordError( wfMsgExt( $message, array( 'parsemag' ), $params ) );
+ throw new PasswordError( wfMessage( $message, $params )->text() );
}
}
if( !$wgAuth->setPassword( $this, $str ) ) {
- throw new PasswordError( wfMsg( 'externaldberror' ) );
+ throw new PasswordError( wfMessage( 'externaldberror' )->text() );
}
$this->setInternalPassword( $str );
$message = 'confirmemail_body_' . $type;
}
- return $this->sendMail( wfMsg( 'confirmemail_subject' ),
- wfMsg( $message,
+ return $this->sendMail( wfMessage( 'confirmemail_subject' )->text(),
+ wfMessage( $message,
$this->getRequest()->getIP(),
$this->getName(),
$url,
$wgLang->timeanddate( $expiration, false ),
$invalidateURL,
$wgLang->date( $expiration, false ),
- $wgLang->time( $expiration, false ) ) );
+ $wgLang->time( $expiration, false ) )->text() );
}
/**
$action = 'create2';
if ( $byEmail ) {
if ( $reason === '' ) {
- $reason = wfMsgForContent( 'newuserlog-byemail' );
+ $reason = wfMessage( 'newuserlog-byemail' )->inContentLanguage()->text();
} else {
$reason = $wgContLang->commaList( array(
- $reason, wfMsgForContent( 'newuserlog-byemail' ) ) );
+ $reason, wfMessage( 'newuserlog-byemail' )->inContentLanguage()->text() ) );
}
}
}
/*
if ( $wgMinimalPasswordLength > 1 ) {
$ret['pattern'] = '.{' . intval( $wgMinimalPasswordLength ) . ',}';
- $ret['title'] = wfMsgExt( 'passwordtooshort', 'parsemag',
- $wgMinimalPasswordLength );
+ $ret['title'] = wfMessage( 'passwordtooshort' )
+ ->numParams( $wgMinimalPasswordLength )->text();
}
*/
if ( $this->oldid ) {
// Always show a link to the diff which triggered the mail. See bug 32210.
- $keys['$NEWPAGE'] = wfMsgForContent( 'enotif_lastdiff',
- $this->title->getCanonicalUrl( 'diff=next&oldid=' . $this->oldid ) );
+ $keys['$NEWPAGE'] = wfMessage( 'enotif_lastdiff',
+ $this->title->getCanonicalUrl( 'diff=next&oldid=' . $this->oldid ) )
+ ->inContentLanguage()->text();
if ( !$wgEnotifImpersonal ) {
// For personal mail, also show a link to the diff of all changes
// since last visited.
- $keys['$NEWPAGE'] .= " \n" . wfMsgForContent( 'enotif_lastvisited',
- $this->title->getCanonicalUrl( 'diff=0&oldid=' . $this->oldid ) );
+ $keys['$NEWPAGE'] .= " \n" . wfMessage( 'enotif_lastvisited',
+ $this->title->getCanonicalUrl( 'diff=0&oldid=' . $this->oldid ) )
+ ->inContentLanguage()->text();
}
$keys['$OLDID'] = $this->oldid;
- $keys['$CHANGEDORCREATED'] = wfMsgForContent( 'changed' );
+ $keys['$CHANGEDORCREATED'] = wfMessage( 'changed' )->inContentLanguage()->text();
} else {
- $keys['$NEWPAGE'] = wfMsgForContent( 'enotif_newpagetext' );
+ $keys['$NEWPAGE'] = wfMessage( 'enotif_newpagetext' )->inContentLanguage()->text();
# clear $OLDID placeholder in the message template
$keys['$OLDID'] = '';
- $keys['$CHANGEDORCREATED'] = wfMsgForContent( 'created' );
+ $keys['$CHANGEDORCREATED'] = wfMessage( 'created' )->inContentLanguage()->text();
}
$keys['$PAGETITLE'] = $this->title->getPrefixedText();
$keys['$PAGETITLE_URL'] = $this->title->getCanonicalUrl();
- $keys['$PAGEMINOREDIT'] = $this->minorEdit ? wfMsgForContent( 'minoredit' ) : '';
+ $keys['$PAGEMINOREDIT'] = $this->minorEdit ?
+ wfMessage( 'minoredit' )->inContentLanguage()->text() : '';
$keys['$UNWATCHURL'] = $this->title->getCanonicalUrl( 'action=unwatch' );
if ( $this->editor->isAnon() ) {
# real anon (user:xxx.xxx.xxx.xxx)
- $keys['$PAGEEDITOR'] = wfMsgForContent( 'enotif_anon_editor', $this->editor->getName() );
- $keys['$PAGEEDITOR_EMAIL'] = wfMsgForContent( 'noemailtitle' );
+ $keys['$PAGEEDITOR'] = wfMessage( 'enotif_anon_editor', $this->editor->getName() )
+ ->inContentLanguage()->text();
+ $keys['$PAGEEDITOR_EMAIL'] = wfMessage( 'noemailtitle' )->inContentLanguage()->text();
} else {
$keys['$PAGEEDITOR'] = $wgEnotifUseRealName ? $this->editor->getRealName() : $this->editor->getName();
$emailPage = SpecialPage::getSafeTitleFor( 'Emailuser', $this->editor->getName() );
# Now build message's subject and body
- $subject = wfMsgExt( 'enotif_subject', 'content' );
+ $subject = wfMessage( 'enotif_subject' )->inContentLanguage()->plain();
$subject = strtr( $subject, $keys );
$subject = MessageCache::singleton()->transform( $subject, false, null, $this->title );
$this->subject = strtr( $subject, $postTransformKeys );
- $body = wfMsgExt( 'enotif_body', 'content' );
+ $body = wfMessage( 'enotif_body' )->inContentLanguage()->plain();
$body = strtr( $body, $keys );
$body = MessageCache::singleton()->transform( $body, false, null, $this->title );
$this->body = wordwrap( strtr( $body, $postTransformKeys ), 72 );
array( '$WATCHINGUSERNAME',
'$PAGEEDITDATE',
'$PAGEEDITTIME' ),
- array( wfMsgForContent( 'enotif_impersonal_salutation' ),
+ array( wfMessage( 'enotif_impersonal_salutation' )->inContentLanguage()->text(),
$wgContLang->date( $this->timestamp, false, false ),
$wgContLang->time( $this->timestamp, false, false ) ),
$this->body );
/** @return string */
function getMessage() {
// '$1 at line $2, col $3 (byte $4): $5',
- return wfMsgHtml( 'xml-error-string',
+ return wfMessage( 'xml-error-string',
$this->mMessage,
$this->mLine,
$this->mColumn,
$this->mByte . $this->mContext,
- xml_error_string( $this->mXmlError ) );
+ xml_error_string( $this->mXmlError ) )->escaped();
}
function _extractContext( $context, $offset ) {
* Create a WikiPage object of the appropriate class for the given title.
*
* @param $title Title
+ * @throws MWException
* @return WikiPage object of the appropriate type
*/
public static function factory( Title $title ) {
* Determine whether a page would be suitable for being counted as an
* article in the site_stats table based on the title & its content
*
- * @param $editInfo Object or false: object returned by prepareTextForEdit(),
+ * @param $editInfo Object|bool (false): object returned by prepareTextForEdit(),
* if false, the current database state will be used
* @return Boolean
*/
if ( $section == 'new' ) {
# Inserting a new section
- $subject = $sectionTitle ? wfMsgForContent( 'newsectionheaderdefaultlevel', $sectionTitle ) . "\n\n" : '';
+ $subject = $sectionTitle ? wfMessage( 'newsectionheaderdefaultlevel' )
+ ->rawParams( $sectionTitle )->inContentLanguage()->text() . "\n\n" : '';
if ( wfRunHooks( 'PlaceNewSection', array( $this, $oldtext, $subject, &$text ) ) ) {
$text = strlen( trim( $oldtext ) ) > 0
? "{$oldtext}\n\n{$subject}{$text}"
* edit-already-exists error will be returned. These two conditions are also possible with
* auto-detection due to MediaWiki's performance-optimised locking strategy.
*
- * @param $baseRevId int the revision ID this edit was based off, if any
+ * @param bool|int $baseRevId int the revision ID this edit was based off, if any
* @param $user User the user doing the edit
*
+ * @throws MWException
* @return Status object. Possible errors:
* edit-hook-aborted: The ArticleSave hook aborted the edit but didn't set the fatal flag of $status
* edit-gone-missing: In update mode, but the article didn't exist
if ( $restrictions != '' ) {
$protectDescription .= $wgContLang->getDirMark() . "[$action=$restrictions] (";
if ( $encodedExpiry[$action] != 'infinity' ) {
- $protectDescription .= wfMsgForContent( 'protect-expiring',
+ $protectDescription .= wfMessage(
+ 'protect-expiring',
$wgContLang->timeanddate( $expiry[$action], false, false ) ,
$wgContLang->date( $expiry[$action], false, false ) ,
- $wgContLang->time( $expiry[$action], false, false ) );
+ $wgContLang->time( $expiry[$action], false, false )
+ )->inContentLanguage()->text();
} else {
- $protectDescription .= wfMsgForContent( 'protect-expiry-indefinite' );
+ $protectDescription .= wfMessage( 'protect-expiry-indefinite' )
+ ->inContentLanguage()->text();
}
$protectDescription .= ') ';
}
# Prepare a null revision to be added to the history
- $editComment = $wgContLang->ucfirst( wfMsgForContent( $revCommentMsg, $this->mTitle->getPrefixedText() ) );
+ $editComment = $wgContLang->ucfirst(
+ wfMessage(
+ $revCommentMsg,
+ $this->mTitle->getPrefixedText()
+ )->inContentLanguage()->text()
+ );
if ( $reason ) {
$editComment .= ": $reason";
}
$editComment .= " ($protectDescription)";
}
if ( $cascade ) {
- $editComment .= ' [' . wfMsgForContent( 'protect-summary-cascade' ) . ']';
+ // FIXME: Should use 'brackets' message.
+ $editComment .= ' [' . wfMessage( 'protect-summary-cascade' )
+ ->inContentLanguage()->text() . ']';
}
# Insert a null revision
* Take an array of page restrictions and flatten it to a string
* suitable for insertion into the page_restrictions field.
* @param $limit Array
+ * @throws MWException
* @return String
*/
protected static function flattenRestrictions( $limit ) {
$target = Revision::newFromId( $s->rev_id );
if ( empty( $summary ) ) {
if ( $from == '' ) { // no public user name
- $summary = wfMsgForContent( 'revertpage-nouser' );
+ $summary = wfMessage( 'revertpage-nouser' )->inContentLanguage()->text();
} else {
- $summary = wfMsgForContent( 'revertpage' );
+ $summary = wfMessage( 'revertpage' )->inContentLanguage()->text();
}
}
$truncatedtext = $wgContLang->truncate(
str_replace( "\n", ' ', $newtext ),
max( 0, 255
- - strlen( wfMsgForContent( 'autoredircomment' ) )
+ - strlen( wfMessage( 'autoredircomment' )->inContentLanguage()->text() )
- strlen( $rt->getFullText() )
) );
- return wfMsgForContent( 'autoredircomment', $rt->getFullText(), $truncatedtext );
+ return wfMessage( 'autoredircomment', $rt->getFullText() )
+ ->rawParams( $truncatedtext )->inContentLanguage()->text();
}
# New page autosummaries
$truncatedtext = $wgContLang->truncate(
str_replace( "\n", ' ', $newtext ),
- max( 0, 200 - strlen( wfMsgForContent( 'autosumm-new' ) ) ) );
+ max( 0, 200 - strlen( wfMessage( 'autosumm-new' )->inContentLanguage()->text() ) ) );
- return wfMsgForContent( 'autosumm-new', $truncatedtext );
+ return wfMessage( 'autosumm-new' )->rawParams( $truncatedtext )
+ ->inContentLanguage()->text();
}
# Blanking autosummaries
if ( $oldtext != '' && $newtext == '' ) {
- return wfMsgForContent( 'autosumm-blank' );
+ return wfMessage( 'autosumm-blank' )->inContentLanguage()->text();
} elseif ( strlen( $oldtext ) > 10 * strlen( $newtext ) && strlen( $newtext ) < 500 ) {
# Removing more than 90% of the article
$truncatedtext = $wgContLang->truncate(
$newtext,
- max( 0, 200 - strlen( wfMsgForContent( 'autosumm-replace' ) ) ) );
+ max( 0, 200 - strlen( wfMessage( 'autosumm-replace' )->inContentLanguage()->text() ) ) );
- return wfMsgForContent( 'autosumm-replace', $truncatedtext );
+ return wfMessage( 'autosumm-replace' )->rawParams( $truncatedtext )
+ ->inContentLanguage()->text();
}
# If we reach this point, there's no applicable autosummary for our case, so our
if ( $blank ) {
// The current revision is blank and the one before is also
// blank. It's just not our lucky day
- $reason = wfMsgForContent( 'exbeforeblank', '$1' );
+ $reason = wfMessage( 'exbeforeblank', '$1' )->inContentLanguage()->text();
} else {
if ( $onlyAuthor ) {
- $reason = wfMsgForContent( 'excontentauthor', '$1', $onlyAuthor );
+ $reason = wfMessage(
+ 'excontentauthor',
+ '$1',
+ $onlyAuthor
+ )->inContentLanguage()->text();
} else {
- $reason = wfMsgForContent( 'excontent', '$1' );
+ $reason = wfMessage( 'excontent', '$1' )->inContentLanguage()->text();
}
}
/**
* @deprecated since 1.18
+ * @param $oldid int
* @return bool
*/
public function useParserCache( $oldid ) {
if ( !empty( $params['async'] ) ) { // deferred
$handle = $obj->write_async( $params['content'] );
$status->value = new SwiftFileOpHandle( $this, $params, 'Create', $handle );
- $status->value->affectedObjects[] = $obj;
+ if ( !empty( $params['overwrite'] ) ) { // file possibly mutated
+ $status->value->affectedObjects[] = $obj;
+ }
} else { // actually write the object in Swift
$obj->write( $params['content'] );
- $this->purgeCDNCache( array( $obj ) );
+ if ( !empty( $params['overwrite'] ) ) { // file possibly mutated
+ $this->purgeCDNCache( array( $obj ) );
+ }
}
} catch ( CDNNotEnabledException $e ) {
// CDN not enabled; nothing to see here
$handle = $obj->write_async( $fp, filesize( $params['src'] ), true );
$status->value = new SwiftFileOpHandle( $this, $params, 'Store', $handle );
$status->value->resourcesToClose[] = $fp;
- $status->value->affectedObjects[] = $obj;
+ if ( !empty( $params['overwrite'] ) ) { // file possibly mutated
+ $status->value->affectedObjects[] = $obj;
+ }
}
} else { // actually write the object in Swift
$obj->load_from_filename( $params['src'], true ); // calls $obj->write()
- $this->purgeCDNCache( array( $obj ) );
+ if ( !empty( $params['overwrite'] ) ) { // file possibly mutated
+ $this->purgeCDNCache( array( $obj ) );
+ }
}
} catch ( CDNNotEnabledException $e ) {
// CDN not enabled; nothing to see here
if ( !empty( $params['async'] ) ) { // deferred
$handle = $sContObj->copy_object_to_async( $srcRel, $dContObj, $dstRel );
$status->value = new SwiftFileOpHandle( $this, $params, 'Copy', $handle );
- $status->value->affectedObjects[] = $dstObj;
+ if ( !empty( $params['overwrite'] ) ) { // file possibly mutated
+ $status->value->affectedObjects[] = $dstObj;
+ }
} else { // actually write the object in Swift
$sContObj->copy_object_to( $srcRel, $dContObj, $dstRel );
- $this->purgeCDNCache( array( $dstObj ) );
+ if ( !empty( $params['overwrite'] ) ) { // file possibly mutated
+ $this->purgeCDNCache( array( $dstObj ) );
+ }
}
} catch ( CDNNotEnabledException $e ) {
// CDN not enabled; nothing to see here
$handle = $sContObj->move_object_to_async( $srcRel, $dContObj, $dstRel );
$status->value = new SwiftFileOpHandle( $this, $params, 'Move', $handle );
$status->value->affectedObjects[] = $srcObj;
- $status->value->affectedObjects[] = $dstObj;
+ if ( !empty( $params['overwrite'] ) ) { // file possibly mutated
+ $status->value->affectedObjects[] = $dstObj;
+ }
} else { // actually write the object in Swift
$sContObj->move_object_to( $srcRel, $dContObj, $dstRel );
- $this->purgeCDNCache( array( $srcObj, $dstObj ) );
+ $this->purgeCDNCache( array( $srcObj ) );
+ if ( !empty( $params['overwrite'] ) ) { // file possibly mutated
+ $this->purgeCDNCache( array( $dstObj ) );
+ }
}
} catch ( CDNNotEnabledException $e ) {
// CDN not enabled; nothing to see here
* @return Array: descriptor array
*/
protected function getSourceSection() {
- global $wgCopyUploadsFromSpecialUpload;
-
if ( $this->mSessionKey ) {
return array(
'SessionKey' => array(
);
}
- $canUploadByUrl = UploadFromUrl::isEnabled()
- && UploadFromUrl::isAllowed( $this->getUser() )
- && $wgCopyUploadsFromSpecialUpload;
+ $canUploadByUrl = UploadFromUrl::isEnabled() && UploadFromUrl::isAllowed( $this->getUser() );
$radio = $canUploadByUrl;
$selectedSourceType = strtolower( $this->getRequest()->getText( 'wpSourceType', 'File' ) );
--- /dev/null
+<?php
+
+/**
+ * Tests timestamp parsing and output.
+ */
+class TimestampTest extends MediaWikiTestCase {
+ /**
+ * Test parsing of valid timestamps and outputing to MW format.
+ * @dataProvider provideValidTimestamps
+ */
+ function testValidParse( $format, $original, $expected ) {
+ $timestamp = new MWTimestamp( $original );
+ $this->assertEquals( $expected, $timestamp->getTimestamp( TS_MW ) );
+ }
+
+ /**
+ * Test outputting valid timestamps to different formats.
+ * @dataProvider provideValidTimestamps
+ */
+ function testValidOutput( $format, $expected, $original ) {
+ $timestamp = new MWTimestamp( $original );
+ $this->assertEquals( $expected, (string) $timestamp->getTimestamp( $format ) );
+ }
+
+ /**
+ * Test an invalid timestamp.
+ * @expectedException TimestampException
+ */
+ function testInvalidParse() {
+ $timestamp = new MWTimestamp( "This is not a timestamp." );
+ }
+
+ /**
+ * Test requesting an invalid output format.
+ * @expectedException TimestampException
+ */
+ function testInvalidOutput() {
+ $timestamp = new MWTimestamp( '1343761268' );
+ $timestamp->getTimestamp( 98 );
+ }
+
+ /**
+ * Test human readable timestamp format.
+ */
+ function testHumanOutput() {
+ $timestamp = new MWTimestamp( time() - 3600 );
+ $this->assertEquals( "1 hour ago", $timestamp->getHumanTimestamp()->toString() );
+ }
+
+ /**
+ * Returns a list of valid timestamps in the format:
+ * array( type, timestamp_of_type, timestamp_in_MW )
+ */
+ function provideValidTimestamps() {
+ return array(
+ // Various formats
+ array( TS_UNIX, '1343761268', '20120731190108' ),
+ array( TS_MW, '20120731190108', '20120731190108' ),
+ array( TS_DB, '2012-07-31 19:01:08', '20120731190108' ),
+ array( TS_ISO_8601, '2012-07-31T19:01:08Z', '20120731190108' ),
+ array( TS_ISO_8601_BASIC, '20120731T190108Z', '20120731190108' ),
+ array( TS_EXIF, '2012:07:31 19:01:08', '20120731190108' ),
+ array( TS_RFC2822, 'Tue, 31 Jul 2012 19:01:08 GMT', '20120731190108' ),
+ array( TS_ORACLE, '31-07-2012 19:01:08.000000', '20120731190108' ),
+ array( TS_POSTGRES, '2012-07-31 19:01:08 GMT', '20120731190108' ),
+ array( TS_DB2, '2012-07-31 19:01:08', '20120731190108' ),
+ // Some extremes and weird values
+ array( TS_ISO_8601, '9999-12-31T23:59:59Z', '99991231235959' ),
+ array( TS_UNIX, '-62135596801', '00001231235959' )
+ );
+ }
+}
$this->assertEquals( '2020:07:14 01:36:05', $meta['DateTimeDigitized'] );
$this->assertEquals( '1997:03:02 00:01:02', $meta['DateTimeOriginal'] );
}
- /* File has an invalid time (+ one valid but really weird time)
+ /**
+ * File has an invalid time (+ one valid but really weird time)
* that shouldn't be included
+ * @expectedException TimestampException
*/
public function testIPTCDatesInvalid() {
$meta = BitmapMetadataHandler::Jpeg( $this->filePath .