* @since 1.22
*/
public static function getBlocksForIPList( array $ipChain, $isAnon, $fromMaster = false ) {
- if ( !count( $ipChain ) ) {
+ if ( $ipChain === [] ) {
return [];
}
$conds[] = self::getRangeCond( IP::toHex( $ipaddr ) );
}
- if ( !count( $conds ) ) {
+ if ( $conds === [] ) {
return [];
}
* @return Block|null The "best" block from the list
*/
public static function chooseBlock( array $blocks, array $ipChain ) {
- if ( !count( $blocks ) ) {
+ if ( $blocks === [] ) {
return null;
} elseif ( count( $blocks ) == 1 ) {
return $blocks[0];
// Already compressed
return;
}
- if ( !count( $this->mItems ) ) {
- // Empty
+ if ( $this->mItems === [] ) {
return;
}
$this->mDiffs = [];
$this->mDiffMap = [];
foreach ( $sequences as $seq ) {
- if ( !count( $seq['diffs'] ) ) {
+ if ( $seq['diffs'] === [] ) {
continue;
}
if ( $tail === '' ) {
*/
function __sleep() {
$this->compress();
- if ( !count( $this->mItems ) ) {
- // Empty object
+ if ( $this->mItems === [] ) {
$info = false;
} else {
// Take forward differences to improve the compression ratio for sequences
$user = $this->mRecord->getUser( $audience, $user );
return $user ? $user->getName() : '';
}
+
/**
* Fetch revision comment if it's available to the specified audience.
* If the specified audience does not have access to the comment, an
}
// no group with the given right(s) exists, no need for a query
- if ( !count( $groups ) ) {
+ if ( $groups === [] ) {
$this->getResult()->addIndexedTagName( [ 'query', $this->getModuleName() ], '' );
return;
if ( count( $ids ) ) {
$ids = $this->filterIDs( [ [ $table, $field ] ], $ids );
- if ( !count( $ids ) ) {
+ if ( $ids === [] ) {
// Return nothing, no IDs are valid
$this->where[] = '0 = 1';
} else {
return $v >= $cont_page;
} );
}
- if ( !count( $pages ) ) {
+ if ( $pages === [] ) {
// Nothing to do
return;
}
$getTitles[] = $t->getTalkPage();
}
}
- if ( !count( $getTitles ) ) {
+ if ( $getTitles === [] ) {
return;
}
$pageIds = array_keys( $this->titles );
- if ( !count( $pageIds ) ) {
+ if ( $pageIds === [] ) {
return;
}
}
private function getVariantTitles() {
- if ( !count( $this->titles ) ) {
+ if ( $this->titles === [] ) {
return;
}
$this->variantTitles = [];
$pages = $filteredPages;
}
- if ( !count( $pages ) ) {
+ if ( $pages === [] ) {
# Nothing to do
return;
}
// prepareQuery might try to sort by actor and confuse everything.
$batchSize = 1;
} elseif ( isset( $this->params['userids'] ) ) {
- if ( !count( $this->params['userids'] ) ) {
+ if ( $this->params['userids'] === [] ) {
$encParamName = $this->encodeParamName( 'userids' );
$this->dieWithError( [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName" );
}
$writeSockets["$clientIndex/$i"] = $socket;
}
}
- if ( !count( $readSockets ) && !count( $writeSockets ) ) {
+ if ( $readSockets === [] && $writeSockets === [] ) {
break;
}
public function upsert( $table, array $rows, array $uniqueIndexes, array $set,
$fname = __METHOD__
) {
- if ( !count( $rows ) ) {
+ if ( $rows === [] ) {
return true; // nothing to do
}
public function setLanguage( Language $language ) {
$this->language = $language;
}
+
/**
* @param int $cutoff
* @see $wgWikiDiff2MovedParagraphDetectionCutoff
* @return mixed[]
*/
public function mergeClassesIntoAttributes( array $classes, array $attribs ) {
- if ( !count( $classes ) ) {
+ if ( $classes === [] ) {
return $attribs;
}
'handle this content model.' );
$this->modelId = $modelId;
}
+
/** @return string */
public function getModelId() {
return $this->modelId;
* @return array[] An Array of arrays or iterators of file objects and the hash as key
*/
function findBySha1s( array $hashes ) {
- if ( !count( $hashes ) ) {
+ if ( $hashes === [] ) {
return []; // empty parameter
}
$conds['fa_sha1'] = $this->sha1;
}
- if ( !count( $conds ) ) {
+ if ( $conds === [] ) {
throw new MWException( "No specific information for retrieving archived file" );
}
final public function batchPush( array $jobs, $flags = 0 ) {
$this->assertNotReadOnly();
- if ( !count( $jobs ) ) {
+ if ( $jobs === [] ) {
return; // nothing to do
}
* @return void
*/
public function doBatchPushInternal( IDatabase $dbw, array $jobs, $flags, $method ) {
- if ( !count( $jobs ) ) {
+ if ( $jobs === [] ) {
return;
}
}
$jobs = is_array( $jobs ) ? $jobs : [ $jobs ];
- if ( !count( $jobs ) ) {
+ if ( $jobs === [] ) {
return;
}
}
}
- if ( !count( $items ) ) {
+ if ( $items === [] ) {
return; // nothing to do
}
if ( empty( $opts['bypassReadOnly'] ) && $this->isReadOnly() ) {
return $this->newStatus( 'backend-fail-readonly', $this->name, $this->readOnly );
}
- if ( !count( $ops ) ) {
+ if ( $ops === [] ) {
return $this->newStatus(); // nothing to do
}
* @see FileBackend::doOperations()
* @param array $ops
* @param array $opts
+ * @return StatusValue
*/
abstract protected function doOperationsInternal( array $ops, array $opts );
if ( empty( $opts['bypassReadOnly'] ) && $this->isReadOnly() ) {
return $this->newStatus( 'backend-fail-readonly', $this->name, $this->readOnly );
}
- if ( !count( $ops ) ) {
+ if ( $ops === [] ) {
return $this->newStatus(); // nothing to do
}
/**
* @see FileBackend::doQuickOperations()
* @param array $ops
+ * @return StatusValue
* @since 1.20
*/
abstract protected function doQuickOperationsInternal( array $ops );
/**
* @see FileBackend::prepare()
* @param array $params
+ * @return StatusValue
*/
abstract protected function doPrepare( array $params );
/**
* @see FileBackend::secure()
* @param array $params
+ * @return StatusValue
*/
abstract protected function doSecure( array $params );
/**
* @see FileBackend::publish()
* @param array $params
+ * @return StatusValue
*/
abstract protected function doPublish( array $params );
/**
* @see FileBackend::clean()
* @param array $params
+ * @return StatusValue
*/
abstract protected function doClean( array $params );
* @return StatusValue
*/
final public function logChangeBatch( array $entries, $batchId ) {
- if ( !count( $entries ) ) {
+ if ( $entries === [] ) {
return StatusValue::newGood();
}
if ( $this->locksHeld[$path][$type] <= 0 ) {
unset( $this->locksHeld[$path][$type] );
}
- if ( !count( $this->locksHeld[$path] ) ) {
+ if ( $this->locksHeld[$path] === [] ) {
unset( $this->locksHeld[$path] ); // no locks on this path
if ( isset( $this->handles[$path] ) ) {
$handlesToClose[] = $this->handles[$path];
protected function doGetLocksOnServer( $lockSrv, array $paths, $type ) {
$status = StatusValue::newGood();
- if ( !count( $paths ) ) {
+ if ( $paths === [] ) {
return $status; // nothing to lock
}
$bucket = $this->getBucketFromPath( $path );
$pathsToUnlock[$bucket][$type][] = $path;
}
- if ( !count( $this->locksHeld[$path] ) ) {
+ if ( $this->locksHeld[$path] === [] ) {
unset( $this->locksHeld[$path] ); // no SH or EX locks left for key
}
}
foreach ( $pathsToUnlock as $bucket => $pathsToUnlockByType ) {
$status->merge( $this->doUnlockingRequestBucket( $bucket, $pathsToUnlockByType ) );
}
- if ( !count( $this->locksHeld ) ) {
+ if ( $this->locksHeld === [] ) {
$status->merge( $this->releaseAllLocks() );
$this->degradedBuckets = []; // safe to retry the normal quorum
}
$this->filterMatchType = $callbackReturn;
}
}
+
/**
* Handle coming across a <!DOCTYPE declaration.
*
);
}
- if ( !count( $this->shutdownPositions ) ) {
+ if ( $this->shutdownPositions === [] ) {
return []; // nothing to save
}
public function upsert( $table, array $rows, array $uniqueIndexes, array $set,
$fname = __METHOD__
) {
- if ( !count( $rows ) ) {
+ if ( $rows === [] ) {
return true; // nothing to do
}
public function upsert( $table, array $rows, array $uniqueIndexes,
array $set, $fname = __METHOD__
) {
- if ( !count( $rows ) ) {
+ if ( $rows === [] ) {
return true; // nothing to do
}
* @return array (reader index, lagged replica mode) or false on failure
*/
private function pickReaderIndex( array $loads, $domain = false ) {
- if ( !count( $loads ) ) {
+ if ( $loads === [] ) {
throw new InvalidArgumentException( "Empty server array given to LoadBalancer" );
}
}
// If all servers were down, quit now
- if ( !count( $currentLoads ) ) {
+ if ( $currentLoads === [] ) {
$this->connLogger->error( __METHOD__ . ": all servers down" );
}
// If nobody is watching the page, and there are no users notified on all changes
// don't bother creating a job/trying to send emails, unless it's a
// talk page with an applicable notification.
- if ( !count( $watchers ) && !count( $wgUsersNotifiedOnAllChanges ) ) {
+ if ( $watchers === [] && !count( $wgUsersNotifiedOnAllChanges ) ) {
$sendEmail = false;
// Only send notification for non minor edits, unless $wgEnotifMinorEdits
if ( !$minorEdit || ( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) {
public function getMagicPMIDLinks() {
return $this->getOption( 'magicPMIDLinks' );
}
+
/**
* Are magic RFC links enabled?
* @since 1.28
}
public function pop() {
- if ( !count( $this->stack ) ) {
+ if ( $this->stack === [] ) {
throw new MWException( __METHOD__ . ': no elements remaining' );
}
$temp = array_pop( $this->stack );
* @return array
*/
public function getFlags() {
- if ( !count( $this->stack ) ) {
+ if ( $this->stack === [] ) {
return [
'findEquals' => false,
'findPipe' => false,
}
// Save response to file cache unless there are errors
- if ( isset( $fileCache ) && !$this->errors && !count( $missing ) ) {
+ if ( isset( $fileCache ) && !$this->errors && $missing === [] ) {
// Cache single modules and images...and other requests if there are enough hits
if ( ResourceFileCache::useFileCache( $context ) ) {
if ( $fileCache->isCacheWorthy() ) {
$out = '';
$states = [];
- if ( !count( $modules ) && !count( $missing ) ) {
+ if ( $modules === [] && $missing === [] ) {
return <<<MESSAGE
/* This file is the Web entry point for MediaWiki's ResourceLoader:
<https://www.mediawiki.org/wiki/ResourceLoader>. In this request,
$dom = new DOMDocument;
$dom->loadXML( file_get_contents( $this->getPath( $context ) ) );
$root = $dom->documentElement;
+ $titleNode = null;
$wrapper = $dom->createElement( 'g' );
+ // Reattach all direct children of the `<svg>` root node to the `<g>` wrapper
while ( $root->firstChild ) {
- $wrapper->appendChild( $root->firstChild );
+ $node = $root->firstChild;
+ if ( !$titleNode && $node->nodeType === XML_ELEMENT_NODE && $node->tagName === 'title' ) {
+ // Remember the first encountered `<title>` node
+ $titleNode = $node;
+ }
+ $wrapper->appendChild( $node );
+ }
+ if ( $titleNode ) {
+ // Reattach the `<title>` node to the `<svg>` root node rather than the `<g>` wrapper
+ $root->appendChild( $titleNode );
}
$root->appendChild( $wrapper );
$wrapper->setAttribute( 'fill', $variantConf['color'] );
if ( is_null( $this->namespaces ) ) {
return '';
}
- if ( !count( $this->namespaces ) ) {
+ if ( $this->namespaces === [] ) {
$namespaces = '0';
} else {
$namespaces = $this->db->makeList( $this->namespaces );
if ( is_null( $this->namespaces ) ) {
return ''; # search all
}
- if ( !count( $this->namespaces ) ) {
+ if ( $this->namespaces === [] ) {
$namespaces = '0';
} else {
$namespaces = $this->db->makeList( $this->namespaces );
$out = $this->getOutput();
$allCats = $out->getCategoryLinks();
- if ( !count( $allCats ) ) {
+ if ( $allCats === [] ) {
return '';
}
$pageRestrictions[] = $restriction->getTitle()->getPrefixedText();
}
+ if ( !$block->isSitewide() && empty( $pageRestrictions ) ) {
+ $fields['Editing']['default'] = false;
+ }
+
// Sort the restrictions so they are in alphabetical order.
sort( $pageRestrictions );
$fields['PageRestrictions']['default'] = implode( "\n", $pageRestrictions );
* @return bool|array True for success, false for didn't-try, array of errors on failure
*/
public function onSubmit( array $data, HTMLForm $form = null ) {
+ // If "Editing" checkbox is unchecked, the block must be a partial block affecting
+ // actions other than editing, and there must be no restrictions.
+ if ( isset( $data['Editing'] ) && $data['Editing'] === false ) {
+ $data['EditingRestriction'] = 'partial';
+ $data['PageRestrictions'] = [];
+ }
return self::processForm( $data, $form->getContext() );
}
* Attempts to clean up broken items
*/
private function cleanupWatchlist() {
- if ( !count( $this->badItems ) ) {
+ if ( $this->badItems === [] ) {
return; // nothing to do
}
'<span class="mw-listgrants-right-name">' . $permission . '</span>'
)->parse();
}
- if ( !count( $descs ) ) {
+ if ( $descs === [] ) {
$grantCellHtml = '';
} else {
sort( $descs );
'<span class="mw-passwordpolicies-policy-name">' . $gp . '</span>'
)->parse();
}
- if ( !count( $ret ) ) {
+ if ( $ret === [] ) {
return '';
} else {
return '<ul><li>' . implode( "</li>\n<li>", $ret ) . '</li></ul>';
$categories = array_map( 'trim', explode( '|', $opts['categories'] ) );
- if ( !count( $categories ) ) {
+ if ( $categories === [] ) {
return;
}
}
# Shortcut?
- if ( !count( $articles ) || !count( $cats ) ) {
+ if ( $articles === [] || $cats === [] ) {
return;
}
# Extract manually requested namespaces
$nslist = $this->powerSearch( $request );
- if ( !count( $nslist ) ) {
+ if ( $nslist === [] ) {
# Fallback to user preference
$nslist = $this->searchConfig->userNamespaces( $user );
}
$profile = null;
- if ( !count( $nslist ) ) {
+ if ( $nslist === [] ) {
$profile = 'default';
}
$pages = MediaWikiServices::getInstance()->getSpecialPageFactory()->
getUsablePages( $this->getUser() );
- if ( !count( $pages ) ) {
+ if ( $pages === [] ) {
# Yeah, that was pointless. Thanks for coming.
return false;
}
}
# Extra message, when no category was found
- if ( !count( $allMsgs ) ) {
+ if ( $allMsgs === [] ) {
$allMsgs[] = $this->msg( 'trackingcategories-disabled' )->parse();
}
if ( is_array( $data ) ) {
if ( isset( $data['user_groups'] ) && is_array( $data['user_groups'] ) ) {
- if ( !count( $data['user_groups'] ) ) {
+ if ( $data['user_groups'] === [] ) {
$this->mGroupMemberships = [];
} else {
$firstGroup = reset( $data['user_groups'] );
}
$toPromote = Autopromote::getAutopromoteOnceGroups( $this, $event );
- if ( !count( $toPromote ) ) {
+ if ( $toPromote === [] ) {
return [];
}
$this->output = $specialSearch->getOutput();
$this->showMultimedia = $showMultimedia;
}
+
/**
* @param string $term User provided search term
* @param SearchResultSet|SearchResultSet[] $resultSets List of interwiki
<?xml version="1.0" encoding="utf-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
+ <title>remove</title>
<g id="remove">
<path id="trash-can" d="M12 10h-1v6h1v-6zm-2 0h-1v6h1v-6zm4 0h-1v6h1v-6zm0-4v-1h-5v1h-3v3h1v7.966l1 1.031v-.074.077h6.984l.016-.018v.015l1-1.031v-7.966h1v-3h-3zm1 11h-7v-8h7v8zm1-9h-9v-1h9v1z"/>
</g>
<?xml version="1.0" encoding="utf-8"?>
-<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><g fill="red">
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><default:title xmlns:default="http://www.w3.org/2000/svg">remove</default:title><g fill="red">
+
<g xmlns:default="http://www.w3.org/2000/svg" id="remove">
<path id="trash-can" d="M12 10h-1v6h1v-6zm-2 0h-1v6h1v-6zm4 0h-1v6h1v-6zm0-4v-1h-5v1h-3v3h1v7.966l1 1.031v-.074.077h6.984l.016-.018v.015l1-1.031v-7.966h1v-3h-3zm1 11h-7v-8h7v8zm1-9h-9v-1h9v1z"/>
</g>
$this->testPageTitle = Title::newFromText( 'UTPage-' . __CLASS__ );
return $this->testPageTitle;
}
+
/**
* @return WikiPage
*/
// Allocated file for testing
$this->tempFileName = tempnam( wfTempDir(), 'WEBP' );
}
+
public function tearDown() {
parent::tearDown();
unlink( $this->tempFileName );
}
+
/**
* @dataProvider provideTestExtractMetaData
*/
$this->assertEquals( $expectedResult, WebPHandler::extractMetadata( $this->tempFileName ) );
}
+
public function provideTestExtractMetaData() {
// phpcs:disable Generic.Files.LineLength
return [
public function testWithFileExtractMetaData( $filename, $expectedResult ) {
$this->assertEquals( $expectedResult, WebPHandler::extractMetadata( $filename ) );
}
+
public function provideTestWithFileExtractMetaData() {
return [
[ __DIR__ . '/../../data/media/2_webp_ll.webp',
$handler = new WebPHandler();
$this->assertEquals( $expectedResult, $handler->getImageSize( null, $path ) );
}
+
public function provideTestGetImageSize() {
return [
// Public domain files from https://developers.google.com/speed/webp/gallery2
$mime = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer();
$this->assertEquals( 'image/webp', $mime->guessMimeType( $path, false ) );
}
+
public function provideTestGetMimeType() {
return [
// Public domain files from https://developers.google.com/speed/webp/gallery2
}
];
}
+
/**
* @dataProvider provideMagicWords
*/
]
];
}
+
/**
* @dataProvider providerWrapAndEscapeMessage
* @covers ResourceLoaderLessVarFileModule::wrapAndEscapeMessage
] ]
];
}
+
/**
* @covers ResourceLoaderStartUpModule::getModuleRegistrations
* @dataProvider provideRegistrations
$response
);
}
+
/**
* Verify that when building the startup module response,
* an exception from one module class will not break the entire
] ) ],
];
}
+
/**
* @dataProvider provideValidRequests
*/