Benefit of keeping the parameter optional:
- In maintenance scripts that really only have one parameter, it's a
little more convenient to be able to ask for *the* parameter via an
empty getArg().
Disadvantages:
- It's unclear what getArg() means when there is no indication *which*
argument the code asks for. This might as well return the last
argument, or an array of all arguments.
- In scripts with two or more arguments, it's confusing to see
getArg( 1 ) next to an empty getArg().
- The methods are more complex and a bit more complicated to use with
the extra feature of this parameter being optional. Users need to
look up what the default is to be able to use it safely.
Change-Id: I22a43bfdfc0f0c9ffdb468c13aba73b888d1f15e
16 files changed:
instead. The setTags() method was overriding the tags, addTags() doesn't
override, only adds new tags.
* Block::isValid is deprecated, since it is no longer needed in core.
instead. The setTags() method was overriding the tags, addTags() doesn't
override, only adds new tags.
* Block::isValid is deprecated, since it is no longer needed in core.
+* Calling Maintenance::hasArg() as well as Maintenance::getArg() with no
+ parameter has been deprecated. Please pass the argument number 0.
=== Other changes in 1.33 ===
* (T201747) Html::openElement() warns if given an element name with a space
=== Other changes in 1.33 ===
* (T201747) Html::openElement() warns if given an element name with a space
* @return bool
*/
protected function hasArg( $argId = 0 ) {
* @return bool
*/
protected function hasArg( $argId = 0 ) {
+ if ( func_num_args() === 0 ) {
+ wfDeprecated( __METHOD__ . ' without an $argId', '1.33' );
+ }
+
return isset( $this->mArgs[$argId] );
}
return isset( $this->mArgs[$argId] );
}
* @return mixed
*/
protected function getArg( $argId = 0, $default = null ) {
* @return mixed
*/
protected function getArg( $argId = 0, $default = null ) {
+ if ( func_num_args() === 0 ) {
+ wfDeprecated( __METHOD__ . ' without an $argId', '1.33' );
+ }
+
return $this->hasArg( $argId ) ? $this->mArgs[$argId] : $default;
}
return $this->hasArg( $argId ) ? $this->mArgs[$argId] : $default;
}
// Set as a member variable to avoid function calls when we're timing the parse
$this->linkCache = MediaWikiServices::getInstance()->getLinkCache();
// Set as a member variable to avoid function calls when we're timing the parse
$this->linkCache = MediaWikiServices::getInstance()->getLinkCache();
- $title = Title::newFromText( $this->getArg() );
+ $title = Title::newFromText( $this->getArg( 0 ) );
if ( !$title ) {
$this->error( "Invalid title" );
exit( 1 );
if ( !$title ) {
$this->error( "Invalid title" );
exit( 1 );
// Hack: Grant bot rights so we don't flood RecentChanges
$wgUser->addGroup( 'bot' );
// Hack: Grant bot rights so we don't flood RecentChanges
$wgUser->addGroup( 'bot' );
- $spec = $this->getArg();
+ $spec = $this->getArg( 0 );
$protConds = [];
foreach ( [ 'http://', 'https://' ] as $prot ) {
$protConds = [];
foreach ( [ 'http://', 'https://' ] as $prot ) {
- if ( $this->hasArg() ) {
- $file = fopen( $this->getArg(), 'r' );
+ if ( $this->hasArg( 0 ) ) {
+ $file = fopen( $this->getArg( 0 ), 'r' );
} else {
$file = $this->getStdin();
}
} else {
$file = $this->getStdin();
}
$wgUser->addToDatabase();
}
$wgUser->addToDatabase();
}
- $title = Title::newFromText( $this->getArg() );
+ $title = Title::newFromText( $this->getArg( 0 ) );
if ( !$title ) {
$this->fatalError( "Invalid title" );
}
if ( !$title ) {
$this->fatalError( "Invalid title" );
}
$this->setNsfilter( explode( '|', $this->getOption( 'namespaces' ) ) );
}
$this->setNsfilter( explode( '|', $this->getOption( 'namespaces' ) ) );
}
- if ( $this->hasArg() ) {
- $this->importFromFile( $this->getArg() );
+ if ( $this->hasArg( 0 ) ) {
+ $this->importFromFile( $this->getArg( 0 ) );
} else {
$this->importFromStdin();
}
} else {
$this->importFromStdin();
}
}
public function execute() {
}
public function execute() {
- if ( $this->hasArg() ) {
+ if ( $this->hasArg( 0 ) ) {
$files = $this->mArgs;
} else {
$this->maybeHelp( true ); // @todo fixme this is a lame API :)
$files = $this->mArgs;
} else {
$this->maybeHelp( true ); // @todo fixme this is a lame API :)
$this->fatalError( "MediaWiki isn't configured with a cache named '$cache'" );
}
$servers = $wgObjectCaches[$cache]['servers'];
$this->fatalError( "MediaWiki isn't configured with a cache named '$cache'" );
}
$servers = $wgObjectCaches[$cache]['servers'];
- } elseif ( $this->hasArg() ) {
- $servers = [ $this->getArg() ];
+ } elseif ( $this->hasArg( 0 ) ) {
+ $servers = [ $this->getArg( 0 ) ];
} elseif ( $wgMainCacheType === CACHE_MEMCACHED ) {
global $wgMemCachedServers;
$servers = $wgMemCachedServers;
} elseif ( $wgMainCacheType === CACHE_MEMCACHED ) {
global $wgMemCachedServers;
$servers = $wgMemCachedServers;
$reason = $this->getOption( 'r', '' );
$interval = $this->getOption( 'i', 0 );
$noredirects = $this->hasOption( 'noredirects' );
$reason = $this->getOption( 'r', '' );
$interval = $this->getOption( 'i', 0 );
$noredirects = $this->hasOption( 'noredirects' );
- if ( $this->hasArg() ) {
- $file = fopen( $this->getArg(), 'r' );
+ if ( $this->hasArg( 0 ) ) {
+ $file = fopen( $this->getArg( 0 ), 'r' );
} else {
$file = $this->getStdin();
}
} else {
$file = $this->getStdin();
}
}
public function execute() {
}
public function execute() {
- $name = $this->getArg();
+ $name = $this->getArg( 0 );
$delete = $this->hasOption( 'delete' );
$dbw = $this->getDB( DB_MASTER );
$delete = $this->hasOption( 'delete' );
$dbw = $this->getDB( DB_MASTER );
}
public function execute() {
}
public function execute() {
- $titleArg = $this->getArg();
+ $titleArg = $this->getArg( 0 );
$title = Title::newFromText( $titleArg );
$pageExists = $title && $title->exists();
$title = Title::newFromText( $titleArg );
$pageExists = $title && $title->exists();
$this->fatalError( "Invalid username" );
}
$this->fatalError( "Invalid username" );
}
- $t = Title::newFromText( $this->getArg() );
+ $t = Title::newFromText( $this->getArg( 0 ) );
if ( !$t ) {
$this->fatalError( "Invalid title" );
}
if ( !$t ) {
$this->fatalError( "Invalid title" );
}
}
public function execute() {
}
public function execute() {
- $id = (int)$this->getArg();
+ $id = (int)$this->getArg( 0 );
$lookup = MediaWikiServices::getInstance()->getRevisionLookup();
$rev = $lookup->getRevisionById( $id );
$lookup = MediaWikiServices::getInstance()->getRevisionLookup();
$rev = $lookup->getRevisionById( $id );
$user = $this->getOption( 'user', false );
$reason = $this->getOption( 'reason', '' );
$user = $this->getOption( 'user', false );
$reason = $this->getOption( 'reason', '' );
- $pageName = $this->getArg();
+ $pageName = $this->getArg( 0 );
$title = Title::newFromText( $pageName );
if ( !$title ) {
$title = Title::newFromText( $pageName );
if ( !$title ) {
}
public function execute() {
}
public function execute() {
- $title = Title::newFromText( $this->getArg() );
+ $title = Title::newFromText( $this->getArg( 0 ) );
if ( !$title ) {
$this->fatalError( "Invalid title" );
}
if ( !$title ) {
$this->fatalError( "Invalid title" );
}