- foreach($params['protections'] as $prot)
- {
- $p = explode('=', $prot);
- $protections[$p[0]] = ($p[1] == 'all' ? '' : $p[1]);
- if($titleObj->exists() && $p[0] == 'create')
- $this->dieUsageMsg(array('create-titleexists'));
- if(!$titleObj->exists() && $p[0] != 'create')
- $this->dieUsageMsg(array('missingtitles-createonly'));
+ $expiryarray = array();
+ $resultProtections = array();
+ foreach ( $params['protections'] as $i => $prot ) {
+ $p = explode( '=', $prot );
+ $protections[$p[0]] = ( $p[1] == 'all' ? '' : $p[1] );
+
+ if ( $titleObj->exists() && $p[0] == 'create' ) {
+ $this->dieUsageMsg( array( 'create-titleexists' ) );
+ }
+ if ( !$titleObj->exists() && $p[0] != 'create' ) {
+ $this->dieUsageMsg( array( 'missingtitle-createonly' ) );
+ }
+
+ if ( !in_array( $p[0], $restrictionTypes ) && $p[0] != 'create' ) {
+ $this->dieUsageMsg( array( 'protect-invalidaction', $p[0] ) );
+ }
+ if ( !in_array( $p[1], $wgRestrictionLevels ) && $p[1] != 'all' ) {
+ $this->dieUsageMsg( array( 'protect-invalidlevel', $p[1] ) );
+ }
+
+ if ( in_array( $expiry[$i], array( 'infinite', 'indefinite', 'never' ) ) ) {
+ $expiryarray[$p[0]] = Block::infinity();
+ } else {
+ $exp = strtotime( $expiry[$i] );
+ if ( $exp < 0 || !$exp ) {
+ $this->dieUsageMsg( array( 'invalidexpiry', $expiry[$i] ) );
+ }
+
+ $exp = wfTimestamp( TS_MW, $exp );
+ if ( $exp < wfTimestampNow() ) {
+ $this->dieUsageMsg( array( 'pastexpiry', $expiry[$i] ) );
+ }
+ $expiryarray[$p[0]] = $exp;
+ }
+ $resultProtections[] = array( $p[0] => $protections[$p[0]],
+ 'expiry' => ( $expiryarray[$p[0]] == Block::infinity() ?
+ 'infinite' :
+ wfTimestamp( TS_ISO_8601, $expiryarray[$p[0]] ) ) );