*/
$wgMimeInfoFile = 'includes/mime.info';
-/**
- * Switch for loading the FileInfo extension by PECL at runtime.
- * This should be used only if fileinfo is installed as a shared object
- * or a dynamic library.
- */
-$wgLoadFileinfoExtension = false;
-
/**
* Sets an external mime detector program. The command must print only
* the mime type to standard output.
|| preg_match( "/^\s*[+-]?0*[1-9]/", $val ); // approx C atoi() function
}
-/**
- * Wrapper function for PHP's dl(). This doesn't work in most situations from
- * PHP 5.3 onward, and is usually disabled in shared environments anyway.
- *
- * @param string $extension A PHP extension. The file suffix (.so or .dll)
- * should be omitted
- * @param string $fileName Name of the library, if not $extension.suffix
- * @return Bool - Whether or not the extension is loaded
- */
-function wfDl( $extension, $fileName = null ) {
- if ( extension_loaded( $extension ) ) {
- return true;
- }
-
- $canDl = false;
- if ( PHP_SAPI == 'cli' || PHP_SAPI == 'cgi' || PHP_SAPI == 'embed' ) {
- $canDl = ( function_exists( 'dl' ) && is_callable( 'dl' )
- && wfIniGetBool( 'enable_dl' ) && !wfIniGetBool( 'safe_mode' ) );
- }
-
- if ( $canDl ) {
- $fileName = $fileName ? $fileName : $extension;
- if ( wfIsWindows() ) {
- $fileName = 'php_' . $fileName;
- }
- wfSuppressWarnings();
- dl( $fileName . '.' . PHP_SHLIB_SUFFIX );
- wfRestoreWarnings();
- }
- return extension_loaded( $extension );
-}
-
/**
* Windows-compatible version of escapeshellarg()
* Windows doesn't recognise single-quotes in the shell, but the escapeshellarg()
*/
private static $instance;
- /** True if the fileinfo extension has been loaded
- */
- private static $extensionLoaded = false;
-
/** Initializes the MimeMagic object. This is called by MimeMagic::singleton().
*
* This constructor parses the mime.types and mime.info files and build internal mappings.
* --- load mime.types ---
*/
- global $wgMimeTypeFile, $IP, $wgLoadFileinfoExtension;
+ global $wgMimeTypeFile, $IP;
$types = MM_WELL_KNOWN_MIME_TYPES;
$wgMimeTypeFile = "$IP/$wgMimeTypeFile";
}
- if ( $wgLoadFileinfoExtension && !self::$extensionLoaded ) {
- self::$extensionLoaded = true;
- wfDl( 'fileinfo' );
- }
-
if ( $wgMimeTypeFile ) {
if ( is_file( $wgMimeTypeFile ) and is_readable( $wgMimeTypeFile ) ) {
wfDebug( __METHOD__ . ": loading mime types from $wgMimeTypeFile\n" );
}
protected function mysqlConnect( $realServer ) {
- # Load mysql.so if we don't have it
- wfDl( 'mysql' );
-
# Fail now
# Otherwise we get a suppressed fatal error, which is very hard to track down
- if ( !function_exists( 'mysql_connect' ) ) {
+ if ( !extension_loaded( 'mysql' ) ) {
throw new DBConnectionError( $this, "MySQL functions missing, have you compiled PHP with the --with-mysql option?\n" );
}
return $difftext;
}
- /**
- * Make sure the proper modules are loaded before we try to
- * make the diff
- */
- private function initDiffEngines() {
- global $wgExternalDiffEngine;
- if ( $wgExternalDiffEngine == 'wikidiff' && !function_exists( 'wikidiff_do_diff' ) ) {
- wfProfileIn( __METHOD__ . '-php_wikidiff.so' );
- wfDl( 'php_wikidiff' );
- wfProfileOut( __METHOD__ . '-php_wikidiff.so' );
- }
- elseif ( $wgExternalDiffEngine == 'wikidiff2' && !function_exists( 'wikidiff2_do_diff' ) ) {
- wfProfileIn( __METHOD__ . '-php_wikidiff2.so' );
- wfDl( 'wikidiff2' );
- wfProfileOut( __METHOD__ . '-php_wikidiff2.so' );
- }
- }
-
/**
* Generate a diff, no caching.
*
$otext = str_replace( "\r\n", "\n", $otext );
$ntext = str_replace( "\r\n", "\n", $ntext );
- $this->initDiffEngines();
-
if ( $wgExternalDiffEngine == 'wikidiff' && function_exists( 'wikidiff_do_diff' ) ) {
# For historical reasons, external diff engine expects
# input text to be HTML-escaped already
* Convenience function.
* Check if a named extension is present.
*
- * @see wfDl
* @param $name
* @return bool
*/
protected static function checkExtension( $name ) {
- wfSuppressWarnings();
- $compiled = wfDl( $name );
- wfRestoreWarnings();
-
- return $compiled;
+ return extension_loaded( $name );
}
/**
break;
case "force-normal":
if ( !function_exists( 'utf8_normalize' ) ) {
- wfDl( "php_utfnormal.so" );
- if ( !function_exists( 'utf8_normalize' ) ) {
- $this->fatalError( "Failed to load UTF-8 normalization extension. " .
- "Install or remove --force-normal parameter to use slower code." );
- }
+ $this->fatalError( "UTF-8 normalization extension not loaded. " .
+ "Install or remove --force-normal parameter to use slower code." );
}
break;
default:
$dbr = wfGetDB( DB_SLAVE );
if ( array_diff( array_keys( $params ),
- array( 'table', 'conds', 'index', 'callback' ) ) )
- {
+ array( 'table', 'conds', 'index', 'callback' ) )
+ ) {
throw new MWException( __METHOD__ . ': Missing parameter ' . implode( ', ', $params ) );
}
$this->init( $count, $table );
$this->output( "Processing $table...\n" );
-
$index = (array)$params['index'];
$indexConds = array();
$options = array(
if ( !is_null( $title )
&& $title->canExist()
&& $title->getNamespace() == $row->page_namespace
- && $title->getDBkey() === $row->page_title )
- {
- $this->progress( 0 ); // all is fine
+ && $title->getDBkey() === $row->page_title
+ ) {
+ $this->progress( 0 ); // all is fine
+
return;
}
// This is reasonable, since cleanupImages.php only iterates over the image table.
$dbr = wfGetDB( DB_SLAVE );
$row = $dbr->selectRow( 'image', array( 'img_name' ), array( 'img_name' => $name ), __METHOD__ );
+
return $row !== false;
}
$dest = $title->getDBkey();
if ( $this->dryrun ) {
- $this->output( "DRY RUN: would rename $row->page_id ($row->page_namespace,'$row->page_title') to ($row->page_namespace,'$dest')\n" );
+ $this->output( "DRY RUN: would rename $row->page_id ($row->page_namespace," .
+ "'$row->page_title') to ($row->page_namespace,'$dest')\n" );
} else {
- $this->output( "renaming $row->page_id ($row->page_namespace,'$row->page_title') to ($row->page_namespace,'$dest')\n" );
+ $this->output( "renaming $row->page_id ($row->page_namespace," .
+ "'$row->page_title') to ($row->page_namespace,'$dest')\n" );
$dbw = wfGetDB( DB_MASTER );
$dbw->update( 'page',
array( 'page_title' => $dest ),
$dest = $title->getDBkey();
if ( $this->dryrun ) {
- $this->output( "DRY RUN: would rename $row->page_id ($row->page_namespace,'$row->page_title') to ($ns,'$dest')\n" );
+ $this->output( "DRY RUN: would rename $row->page_id ($row->page_namespace," .
+ "'$row->page_title') to ($ns,'$dest')\n" );
} else {
- $this->output( "renaming $row->page_id ($row->page_namespace,'$row->page_title') to ($ns,'$dest')\n" );
+ $this->output( "renaming $row->page_id ($row->page_namespace," .
+ "'$row->page_title') to ($ns,'$dest')\n" );
$dbw = wfGetDB( DB_MASTER );
$dbw->update( 'page',
array(
* @return bool
*/
public static function isPresent() {
- wfSuppressWarnings();
- $compiled = wfDl( 'pdo_sqlite' );
- wfRestoreWarnings();
- return $compiled;
+ return extension_loaded( 'pdo_sqlite' );
}
/**
class CollationTest extends MediaWikiLangTestCase {
protected function setUp() {
parent::setUp();
- if ( !wfDl( 'intl' ) ) {
+ if ( !extension_loaded( 'intl' ) ) {
$this->markTestSkipped( 'These tests require intl extension' );
}
}
$this->assertEquals( $expected, $text );
}
+ /**
+ * Test editing of sections
+ */
+ function testEditSection() {
+ $name = 'Help:ApiEditPageTest_testEditSection';
+ $page = WikiPage::factory( Title::newFromText( $name ) );
+ $text = "==section 1==\ncontent 1\n==section 2==\ncontent2";
+ // Preload the page with some text
+ $page->doEditContent( ContentHandler::makeContent( $text, $page->getTitle() ), 'summary' );
+
+ list( $re ) = $this->doApiRequestWithToken( array(
+ 'action' => 'edit',
+ 'title' => $name,
+ 'section' => '1',
+ 'text' => "==section 1==\nnew content 1",
+ ) );
+ $this->assertEquals( 'Success', $re['edit']['result'] );
+ $newtext = WikiPage::factory( Title::newFromText( $name) )->getContent( Revision::RAW )->getNativeData();
+ $this->assertEquals( $newtext, "==section 1==\nnew content 1\n\n==section 2==\ncontent2" );
+
+ // Test that we raise a 'nosuchsection' error
+ try {
+ $this->doApiRequestWithToken( array(
+ 'action' => 'edit',
+ 'title' => $name,
+ 'section' => '9999',
+ 'text' => 'text',
+ ) );
+ $this->fail( "Should have raised a UsageException" );
+ } catch ( UsageException $e ) {
+ $this->assertEquals( $e->getCodeString(), 'nosuchsection' );
+ }
+ }
+
/**
* Test action=edit§ion=new
* Run it twice so we test adding a new section on a
* translation (to en) where XMP should win.
*/
public function testMultilingualCascade() {
- if ( !wfDl( 'exif' ) ) {
+ if ( !extension_loaded( 'exif' ) ) {
$this->markTestSkipped( "This test needs the exif extension." );
}
- if ( !wfDl( 'xml' ) ) {
+ if ( !extension_loaded( 'xml' ) ) {
$this->markTestSkipped( "This test needs the xml extension." );
}
}
public function testPNGXMP() {
- if ( !wfDl( 'xml' ) ) {
+ if ( !extension_loaded( 'xml' ) ) {
$this->markTestSkipped( "This test needs the xml extension." );
}
$handler = new BitmapMetadataHandler();
protected function setUp() {
parent::setUp();
+ if ( !extension_loaded( 'exif' ) ) {
+ $this->markTestSkipped( "This test needs the exif extension." );
+ }
$this->setMwGlobals( 'wgShowEXIF', true );
$this->handler = new ExifBitmapHandler;
- if ( !wfDl( 'exif' ) ) {
- $this->markTestSkipped( "This test needs the exif extension." );
- }
+
}
public function testIsOldBroken() {
protected function setUp() {
parent::setUp();
+ if ( !extension_loaded( 'exif' ) ) {
+ $this->markTestSkipped( "This test needs the exif extension." );
+ }
+
$this->handler = new BitmapHandler();
$filePath = __DIR__ . '/../../data/media';
'containerPaths' => array( 'temp-thumb' => $tmpDir, 'data' => $filePath )
) )
) );
- if ( !wfDl( 'exif' ) ) {
- $this->markTestSkipped( "This test needs the exif extension." );
- }
$this->setMwGlobals( array(
'wgShowEXIF' => true,
protected function setUp() {
parent::setUp();
+ if ( !extension_loaded( 'exif' ) ) {
+ $this->markTestSkipped( "This test needs the exif extension." );
+ }
$this->mediaPath = __DIR__ . '/../../data/media/';
- if ( !wfDl( 'exif' ) ) {
- $this->markTestSkipped( "This test needs the exif extension." );
- }
+
$this->setMwGlobals( 'wgShowEXIF', true );
}
protected function setUp() {
parent::setUp();
- if ( !wfDl( 'exif' ) ) {
+ if ( !extension_loaded( 'exif' ) ) {
$this->markTestSkipped( "This test needs the exif extension." );
}
$filePath = __DIR__ . '/../../data/media';
protected function setUp() {
parent::setUp();
-
- $this->filePath = __DIR__ . '/../../data/media/';
- if ( !wfDl( 'exif' ) ) {
+ if ( !extension_loaded( 'exif' ) ) {
$this->markTestSkipped( "This test needs the exif extension." );
}
+ $this->filePath = __DIR__ . '/../../data/media/';
+
+
$this->setMwGlobals( 'wgShowEXIF', true );
}
protected function setUp() {
parent::setUp();
+ if ( !extension_loaded( 'exif' ) ) {
+ $this->markTestSkipped( "This test needs the exif extension." );
+ }
$this->setMwGlobals( 'wgShowEXIF', true );
}
public function testInvalidFile() {
- if ( !wfDl( 'exif' ) ) {
- $this->markTestIncomplete( "This test needs the exif extension." );
- }
$res = $this->handler->getMetadata( null, $this->filePath . 'README' );
$this->assertEquals( ExifBitmapHandler::BROKEN_FILE, $res );
}
public function testTiffMetadataExtraction() {
- if ( !wfDl( 'exif' ) ) {
- $this->markTestIncomplete( "This test needs the exif extension." );
- }
$res = $this->handler->getMetadata( null, $this->filePath . 'test.tiff' );
$expected = 'a:16:{s:10:"ImageWidth";i:20;s:11:"ImageLength";i:20;s:13:"BitsPerSample";a:3:{i:0;i:8;i:1;i:8;i:2;i:8;}s:11:"Compression";i:5;s:25:"PhotometricInterpretation";i:2;s:16:"ImageDescription";s:17:"Created with GIMP";s:12:"StripOffsets";i:8;s:11:"Orientation";i:1;s:15:"SamplesPerPixel";i:3;s:12:"RowsPerStrip";i:64;s:15:"StripByteCounts";i:238;s:11:"XResolution";s:19:"1207959552/16777216";s:11:"YResolution";s:19:"1207959552/16777216";s:19:"PlanarConfiguration";i:1;s:14:"ResolutionUnit";i:2;s:22:"MEDIAWIKI_EXIF_VERSION";i:2;}';
// Re-unserialize in case there are subtle differences between how versions
protected function setUp() {
parent::setUp();
- if ( !wfDl( 'xml' ) ) {
+ if ( !extension_loaded( 'xml' ) ) {
$this->markTestSkipped( 'Requires libxml to do XMP parsing' );
}
}