// Make sure we're on PHP5.3.2 or better
if ( !function_exists( 'version_compare' ) || version_compare( PHP_VERSION, '5.3.2' ) < 0 ) {
// We need to use dirname( __FILE__ ) here cause __DIR__ is PHP5.3+
- require_once( dirname( __FILE__ ) . '/../includes/PHPVersionError.php' );
+ require_once dirname( __FILE__ ) . '/../includes/PHPVersionError.php';
wfPHPVersionError( 'cli' );
}
}
if ( $channel === null ) {
$this->cleanupChanneled();
- print( $out );
+ print $out;
} else {
$out = preg_replace( '/\n\z/', '', $out );
$this->outputChanneled( $out, $channel );
$this->addOption( 'server', "The protocol and server name to use in URLs, e.g. " .
"http://en.wikipedia.org. This is sometimes necessary because " .
"server name detection may fail in command line scripts.", false, true );
+ $this->addOption( 'profiler', 'Set to "text" or "trace" to show profiling output', false, true );
# Save generic options to display them separately in help
$this->mGenericParameters = $this->mParams;
// Make sure the class is loaded first
if ( !MWInit::classExists( $maintClass ) ) {
if ( $classFile ) {
- require_once( $classFile );
+ require_once $classFile;
}
if ( !MWInit::classExists( $maintClass ) ) {
$this->error( "Cannot spawn child: $maintClass" );
$this->output( "\n" );
$scriptDependantParams = $this->mDependantParameters;
- if ( count($scriptDependantParams) > 0 ) {
+ if ( count( $scriptDependantParams ) > 0 ) {
$this->output( "Script dependant parameters:\n" );
// Parameters description
foreach ( $scriptDependantParams as $par => $info ) {
$this->mGenericParameters,
$this->mDependantParameters
);
- if ( count($scriptSpecificParams) > 0 ) {
+ if ( count( $scriptSpecificParams ) > 0 ) {
$this->output( "Script specific parameters:\n" );
// Parameters description
foreach ( $scriptSpecificParams as $par => $info ) {
$wgShowSQLErrors = true;
@set_time_limit( 0 );
$this->adjustMemoryLimit();
+
+ // Per-script profiling; useful for debugging
+ $forcedProfiler = $this->getOption( 'profiler' );
+ if ( $forcedProfiler === 'text' ) {
+ Profiler::setInstance( new ProfilerSimpleText( array() ) );
+ Profiler::instance()->setTemplated( true );
+ } elseif ( $forcedProfiler === 'trace' ) {
+ Profiler::setInstance( new ProfilerSimpleTrace( array() ) );
+ Profiler::instance()->setTemplated( true );
+ }
}
/**
( strpos( file_get_contents( $file ), '$maintClass' ) === false ) ) {
continue;
}
- require( $file );
+ require $file;
$vars = get_defined_vars();
if ( array_key_exists( 'maintClass', $vars ) ) {
self::$mCoreScripts[$vars['maintClass']] = $file;
* @param &$db DatabaseBase object
*/
private function unlockSearchindex( &$db ) {
- $db->unlockTables( __CLASS__ . '::' . __METHOD__ );
+ $db->unlockTables( __CLASS__ . '::' . __METHOD__ );
}
/**
$title = $titleObj->getPrefixedDBkey();
$this->output( "$title..." );
# Update searchindex
- # TODO: pass the Content object to SearchUpdate, let the search engine decide how to deal with it.
- $u = new SearchUpdate( $pageId, $titleObj->getText(), $rev->getContent()->getTextForSearchIndex() );
+ $u = new SearchUpdate( $pageId, $titleObj->getText(), $rev->getContent() );
$u->doUpdate();
$this->output( "\n" );
}