'MediaHandler' => __DIR__ . '/includes/media/MediaHandler.php',
'MediaStatisticsPage' => __DIR__ . '/includes/specials/SpecialMediaStatistics.php',
'MediaTransformError' => __DIR__ . '/includes/media/MediaTransformOutput.php',
+ 'MediaTransformInvalidParametersException' => __DIR__ . '/includes/media/MediaTransformInvalidParametersException.php',
'MediaTransformOutput' => __DIR__ . '/includes/media/MediaTransformOutput.php',
'MediaWiki' => __DIR__ . '/includes/MediaWiki.php',
'MediaWikiI18N' => __DIR__ . '/includes/skins/MediaWikiI18N.php',
* Generate and use thumbnails suitable for screens with 1.5 and 2.0 pixel densities.
*
* This means a 320x240 use of an image on the wiki will also generate 480x360 and 640x480
- * thumbnails, output via data-src-1-5 and data-src-2-0. Runtime JavaScript switches the
- * images in after loading the original low-resolution versions depending on the reported
- * window.devicePixelRatio.
+ * thumbnails, output via the srcset attribute.
+ *
+ * On older browsers, a JavaScript polyfill switches the appropriate images in after loading
+ * the original low-resolution versions depending on the reported window.devicePixelRatio.
+ * The polyfill can be found in the jquery.hidpi module.
*/
$wgResponsiveImages = true;
$keepReading = $this->reader->read();
$skip = false;
- while ( $keepReading ) {
- $tag = $this->reader->name;
- $type = $this->reader->nodeType;
-
- if ( !Hooks::run( 'ImportHandleToplevelXMLTag', array( $this ) ) ) {
- // Do nothing
- } elseif ( $tag == 'mediawiki' && $type == XMLReader::END_ELEMENT ) {
- break;
- } elseif ( $tag == 'siteinfo' ) {
- $this->handleSiteInfo();
- } elseif ( $tag == 'page' ) {
- $this->handlePage();
- } elseif ( $tag == 'logitem' ) {
- $this->handleLogItem();
- } elseif ( $tag != '#text' ) {
- $this->warn( "Unhandled top-level XML tag $tag" );
-
- $skip = true;
- }
+ $rethrow = null;
+ try {
+ while ( $keepReading ) {
+ $tag = $this->reader->name;
+ $type = $this->reader->nodeType;
+
+ if ( !Hooks::run( 'ImportHandleToplevelXMLTag', array( $this ) ) ) {
+ // Do nothing
+ } elseif ( $tag == 'mediawiki' && $type == XMLReader::END_ELEMENT ) {
+ break;
+ } elseif ( $tag == 'siteinfo' ) {
+ $this->handleSiteInfo();
+ } elseif ( $tag == 'page' ) {
+ $this->handlePage();
+ } elseif ( $tag == 'logitem' ) {
+ $this->handleLogItem();
+ } elseif ( $tag != '#text' ) {
+ $this->warn( "Unhandled top-level XML tag $tag" );
+
+ $skip = true;
+ }
- if ( $skip ) {
- $keepReading = $this->reader->next();
- $skip = false;
- $this->debug( "Skip" );
- } else {
- $keepReading = $this->reader->read();
+ if ( $skip ) {
+ $keepReading = $this->reader->next();
+ $skip = false;
+ $this->debug( "Skip" );
+ } else {
+ $keepReading = $this->reader->read();
+ }
}
+ } catch ( Exception $ex ) {
+ $rethrow = $ex;
}
+ // finally
libxml_disable_entity_loader( $oldDisable );
+ $this->reader->close();
+
+ if ( $rethrow ) {
+ throw $rethrow;
+ }
+
return true;
}
/**
* Get a list of all available permissions.
- * @return string[] Array of permission names
+ * @return array Array of permission names
*/
public static function getAllRights() {
if ( self::$mAllRights === false ) {
/**
* Replaces User::addUserGroup()
* @param string $group
+ *
+ * @return bool
*/
function addGroup( $group ) {
$this->db->insert( 'user_groups',
),
__METHOD__,
array( 'IGNORE' ) );
+
+ return true;
}
/**
* Replaces User::removeUserGroup()
* @param string $group
+ *
+ * @return bool
*/
function removeGroup( $group ) {
$this->db->delete( 'user_groups',
'ug_group' => $group,
),
__METHOD__ );
+
+ return true;
}
/**
);
}
- $common = $file->getCommonMetaArray();
-
- if ( $common !== false ) {
- foreach ( $common as $key => $value ) {
- $fileMetadata[$key] = array(
- 'value' => $value,
- 'source' => 'file-metadata',
- );
- }
- }
-
return $fileMetadata;
}
} elseif ( isset( $params['width'] ) ) {
$width = $params['width'];
} else {
- throw new MWException( 'No width specified to ' . __METHOD__ );
+ throw new MediaTransformInvalidParametersException( 'No width specified to ' . __METHOD__ );
}
# Removed for ProofreadPage
--- /dev/null
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * MediaWiki exception thrown by some methods when the transform parameter array is invalid
+ *
+ * @ingroup Exception
+ */
+class MediaTransformInvalidParametersException extends MWException {}
if ( isset( $data['localBasePath'] ) ) {
$data['localBasePath'] = "$dir/{$data['localBasePath']}";
}
- if ( $defaultPaths && !isset( $data['class'] ) ) {
+ if ( $defaultPaths ) {
$data += $defaultPaths;
}
$this->globals['wgResourceModules'][$name] = $data;
foreach ( $this->queued as $path => $mtime ) {
$json = file_get_contents( $path );
$info = json_decode( $json, /* $assoc = */ true );
+ if ( !is_array( $info ) ) {
+ throw new Exception( "$path is not a valid JSON file." );
+ }
$autoload = $this->processAutoLoader( dirname( $path ), $info );
// Set up the autoloader now so custom processors will work
$GLOBALS['wgAutoloadClasses'] += $autoload;
return array();
}
}
-
- /**
- * @param string $filename absolute path to the JSON file
- * @param int $mtime modified time of the file
- * @return array
- */
- protected function loadInfoFromFile( $filename, $mtime ) {
- $key = wfMemcKey( 'registry', md5( $filename ) );
- $cached = $this->cache->get( $key );
- if ( isset( $cached['mtime'] ) && $cached['mtime'] === $mtime ) {
- return $cached['info'];
- }
-
- $contents = file_get_contents( $filename );
- $json = json_decode( $contents, /* $assoc = */ true );
- if ( is_array( $json ) ) {
- $this->cache->set( $key, array( 'mtime' => $mtime, 'info' => $json ) );
- } else {
- // Don't throw an error here, but don't cache it either.
- // @todo log somewhere?
- $json = array();
- }
-
- return $json;
- }
}
* @return {jQuery.Promise} See mw.Api#post
*/
login: function ( username, password ) {
- var params, request,
- deferred = $.Deferred(),
+ var params, apiPromise,
api = this;
params = {
lgpassword: password
};
- request = api.post( params );
- request.fail( deferred.reject );
- request.done( function ( data ) {
- params.lgtoken = data.login.token;
- api.post( params )
- .fail( deferred.reject )
- .done( function ( data ) {
- var code;
- if ( data.login && data.login.result === 'Success' ) {
- deferred.resolve( data );
- } else {
- // Set proper error code whenever possible
- code = data.error && data.error.code || 'unknown';
- deferred.reject( code, data );
- }
- } );
- } );
-
- return deferred.promise( { abort: request.abort } );
+ apiPromise = api.post( params );
+ return apiPromise
+ .then( function ( data ) {
+ params.lgtoken = data.login.token;
+ return api.post( params )
+ .then( function ( data ) {
+ var code;
+ if ( data.login.result !== 'Success' ) {
+ // Set proper error code whenever possible
+ code = data.error && data.error.code || 'unknown';
+ return $.Deferred().reject( code, data );
+ }
+ return data;
+ } );
+ } )
+ .promise( { abort: apiPromise.abort } );
}
} );
-/**
+/*!
* Auto-register from pre-loaded startup scripts
- * @ignore (this line will make JSDuck happy)
*/
( function ( $ ) {
'use strict';
'test.class' => array(
'class' => 'FooBarModule',
'extra' => 'argument',
+ 'localBasePath' => $dir,
+ 'remoteExtPath' => 'FooBar',
),
'test.class.with.path' => array(
'class' => 'FooBarPathModule',
'extra' => 'argument',
'localBasePath' => $dir,
+ 'remoteExtPath' => 'FooBar',
)
),
),
+++ /dev/null
-<?php
-
-/**
- * Try to make sure that extensions register all rights in $wgAvailableRights
- * or via the 'UserGetAllRights' hook.
- *
- * @author Marius Hoch < hoo@online.de >
- */
-class AvailableRightsTest extends PHPUnit_Framework_TestCase {
-
- /**
- * Returns all rights that should be in $wgAvailableRights + all rights
- * registered via the 'UserGetAllRights' hook + all "core" rights.
- *
- * @return string[]
- */
- private function getAllVisibleRights() {
- global $wgGroupPermissions, $wgRevokePermissions;
-
- $rights = User::getAllRights();
-
- foreach( $wgGroupPermissions as $permissions ) {
- $rights = array_merge( $rights, array_keys( $permissions ) );
- }
-
- foreach( $wgRevokePermissions as $permissions ) {
- $rights = array_merge( $rights, array_keys( $permissions ) );
- }
-
- $rights = array_unique( $rights );
- sort( $rights );
-
- return $rights;
- }
-
- public function testAvailableRights() {
- $missingRights = array_diff( $this->getAllVisibleRights(), User::getAllRights() );
-
- $this->assertEquals(
- array(),
- array_values( $missingRights ), // Re-Index to produce nicer output, keys are meaningless
- 'Additional user rights need to be added to $wgAvailableRights or via the "UserGetAllRights" hook'
- );
- }
-}
try {
$thumbName = $img->thumbName( $params );
if ( !strlen( $thumbName ) ) { // invalid params?
- wfThumbError( 400, 'The specified thumbnail parameters are not valid.' );
- return;
+ throw new MediaTransformInvalidParametersException( 'Empty return from File::thumbName' );
}
$thumbName2 = $img->thumbName( $params, File::THUMB_FULL_NAME ); // b/c; "long" style
+ } catch ( MediaTransformInvalidParametersException $e ) {
+ wfThumbError( 400, 'The specified thumbnail parameters are not valid: ' . $e->getMessage() );
+ return;
} catch ( MWException $e ) {
wfThumbError( 500, $e->getHTML() );
return;