if ( $regex === '' ) {
continue;
}
- preg_match_all( $regex, $text, $matches, PREG_SET_ORDER );
- foreach ( $matches as $m ) {
- list( $name, $param ) = $this->parseMatch( $m );
- $found[$name] = $param;
+ $matches = array();
+ if ( preg_match_all( $regex, $text, $matches, PREG_SET_ORDER ) ) {
+ foreach ( $matches as $m ) {
+ list( $name, $param ) = $this->parseMatch( $m );
+ $found[$name] = $param;
+ }
}
$text = preg_replace( $regex, '', $text );
}
# We only need to worry about passing the IP address to the Block generator if the
# user is not immune to autoblocks/hardblocks, and they are the current user so we
# know which IP address they're actually coming from
- if ( !$this->isAllowed( 'ipblock-exempt' ) && $this->getID() == $wgUser->getID() ) {
+ if ( !$this->isAllowed( 'ipblock-exempt' ) && $this->equals( $wgUser ) ) {
$ip = $this->getRequest()->getIP();
} else {
$ip = null;
* are required to ignore it or filter it out.
*
* @deprecated since 1.25
- * @return bool
+ * @return bool Always true
*/
public function getNeedsRawData() {
- return false;
+ wfDeprecated( __METHOD__, '1.25' );
+ return true;
}
/**@}*/
return null;
}
- /**
- * Optimization - no need to sanitize data that will not be needed
- *
- * @return bool
- */
- public function getNeedsRawData() {
- return true;
- }
-
/**
* ChannelFeed doesn't give us a method to print errors in a friendly
* manner, so just punt errors to the default printer.
return 'application/json';
}
- /**
- * @deprecated since 1.25
- */
- public function getNeedsRawData() {
- return $this->isRaw;
- }
-
/**
* @deprecated since 1.25
*/
return 'text/xml';
}
- /**
- * @deprecated since 1.25
- */
- public function getNeedsRawData() {
- return true;
- }
-
public function setRootElement( $rootElemName ) {
$this->mRootElemName = $rootElemName;
}
// Create an appropriate printer
$this->mPrinter = $this->createPrinterByName( $params['format'] );
}
-
- if ( $this->mPrinter->getNeedsRawData() ) {
- $this->getResult()->setRawMode();
- }
}
/**
private $errorFormatter;
// Deprecated fields
- private $isRawMode, $checkingSize, $mainForContinuation;
+ private $checkingSize, $mainForContinuation;
/**
* @param int|bool $maxSize Maximum result "size", or false for no limit
}
$this->maxSize = $maxSize;
- $this->isRawMode = false;
$this->checkingSize = true;
$this->reset();
}
*/
/**
- * Call this function when special elements such as '_element'
- * are needed by the formatter, for example in XML printing.
+ * Formerly used to enable/disable "raw mode".
* @deprecated since 1.25, you shouldn't have been using it in the first place
* @since 1.23 $flag parameter added
* @param bool $flag Set the raw mode flag to this state
*/
public function setRawMode( $flag = true ) {
- // Can't wfDeprecated() here, since we need to set this flag from
- // ApiMain for BC with stuff using self::getIsRawMode as
- // "self::getIsXMLMode".
- $this->isRawMode = $flag;
+ wfDeprecated( __METHOD__, '1.25' );
}
/**
- * Returns true whether the formatter requested raw data.
+ * Returns true, the equivalent of "raw mode" is always enabled now
* @deprecated since 1.25, you shouldn't have been using it in the first place
* @return bool
*/
public function getIsRawMode() {
- /// @todo: After Wikibase stops calling this, warn
- return $this->isRawMode;
+ wfDeprecated( __METHOD__, '1.25' );
+ return true;
}
/**
return $this->getResultData( null, array(
'BC' => array(),
'Types' => array(),
- 'Strip' => $this->isRawMode ? 'bc' : 'all',
+ 'Strip' => 'all',
) );
}
if ( $this->content instanceof Message ) {
$contentHtml = $this->content->escaped();
} else {
- $contentHtml = htmlspecialchars( $this->content );
+ $contentHtml = nl2br( htmlspecialchars( $this->content ) );
}
return "<!DOCTYPE html>\n" .
$this->setupSchemaVars();
$dbName = $this->getVar( 'wgDBname' );
$this->db->selectDB( $dbName );
- $server = $this->getVar( 'wgDBserver' );
$password = $this->getVar( 'wgDBpassword' );
$schemaName = $this->getVar( 'wgDBmwschema' );
/**
* Purge a key from all clusters
*
- * This deletes the key and instantiates a hold-off period where the key
- * cannot be written to for the next few seconds (HOLDOFF_TTL). This is to
- * avoid the following race condition:
+ * This should only be called when the underlying data (being cached)
+ * changes in a significant way. This deletes the key and starts a hold-off
+ * period where the key cannot be written to for a few seconds (HOLDOFF_TTL).
+ * This is done to avoid the following race condition:
* a) Some DB data changes and delete() is called on a corresponding key
* b) A request refills the key with a stale value from a lagged DB
* c) The stale value is stuck there until the key is expired/evicted
* a) Replication lag is bounded to being less than HOLDOFF_TTL; or
* b) If lag is higher, the DB will have gone into read-only mode already
*
- * This should only be called when the underlying data (being cached)
- * changes in a significant way. If called twice on the same key, then
- * the last TTL takes precedence.
+ * If called twice on the same key, then the last hold-off TTL takes
+ * precedence. For idempotence, the $ttl should not vary for different
+ * delete() calls on the same key. Also note that lowering $ttl reduces
+ * the effective range of the 'lockTSE' parameter to getWithSetCallback().
*
* @param string $key Cache key
* @param integer $ttl How long to block writes to the key [seconds]
* Other threads will try to use stale values if possible.
* If, on miss, the time since expiration is low, the assumption
* is that the key is hot and that a stampede is worth avoiding.
+ * Setting this above WANObjectCache::HOLDOFF_TTL makes no difference.
* - tempTTL : TTL of the temp key used to cache values while a key is tombstoned.
* This avoids excessive regeneration of hot keys on delete() but may
* result in stale values.
return $value;
}
+ // A deleted key with a negative TTL left must be tombstoned
$isTombstone = ( $curTTL !== null && $value === false );
// Assume a key is hot if requested soon after invalidation
$isHot = ( $curTTL !== null && $curTTL <= 0 && abs( $curTTL ) <= $lockTSE );
- $locked = false;
+ $lockAcquired = false;
if ( $isHot ) {
// Acquire a cluster-local non-blocking lock
if ( $this->cache->lock( $key, 0, self::LOCK_TTL ) ) {
// Lock acquired; this thread should update the key
- $locked = true;
+ $lockAcquired = true;
} elseif ( $value !== false ) {
// If it cannot be acquired; then the stale value can be used
return $value;
}
}
- if ( !$locked && ( $isTombstone || $isHot ) ) {
+ if ( !$lockAcquired && ( $isTombstone || $isHot ) ) {
// Use the stash value for tombstoned keys to reduce regeneration load.
// For hot keys, either another thread has the lock or the lock failed;
// use the stash value from the last thread that regenerated it.
$this->cache->set( self::STASH_KEY_PREFIX . $key, $value, $tempTTL );
}
- if ( $locked ) {
+ if ( $lockAcquired ) {
$this->cache->unlock( $key );
}
$titles[] = $user->getTalkPage();
}
- // Other tab link
- if ( $title->isSpecialPage() ) {
+ // Check, if the page can hold some kind of content, otherwise do nothing
+ if ( !$title->canExist() ) {
// nothing
} elseif ( $title->isTalkPage() ) {
$titles[] = $title->getSubjectPage();
== Installation ==
-If PHPUnit is not installed, follow the installation instructions in the
-PHPUnit Manual at:
-
- http://www.phpunit.de/manual/current/en/installation.html
+If you used composer to install MediaWiki's dependencies PHPUnit will already be available, unless
+you explicitly specified the --no-dev flag during the install. In this case just run "composer update".
-- or -
-
-On Unix-like operating systems, run:
+Otherwise follow the installation instructions in the
+PHPUnit Manual at:
- make install
+ https://phpunit.de/manual/current/en/installation.html
== Running tests ==
=== Writing tests ===
-A guide to writing unit tests for MediaWiki can be found at:
+A guide to writing PHP unit tests for MediaWiki can be found at:
- http://mediawiki.org/wiki/Unit_Testing
+ https://www.mediawiki.org/wiki/Manual:PHP_unit_testing
),
'*' => 'content',
), $result->getData() );
- $result->setRawMode();
- $this->assertSame( array(
- 'foo' => array(
- 'bar' => array(
- '*' => 'content',
- ),
- ),
- '*' => 'content',
- '_element' => 'itn',
- '_subelements' => array( 'sub' ),
- ), $result->getData() );
$arr = array();
ApiResult::setContent( $arr, 'value' );