global $wgRestrictionLevels;
$params = $this->extractRequestParams();
- $this->requireOnlyOneParameter( $params, 'title', 'pageid' );
-
- if ( isset( $params['title'] ) ) {
- $titleObj = Title::newFromText( $params['title'] );
- if ( !$titleObj ) {
- $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
- }
- $pageObj = WikiPage::factory( $titleObj );
- $pageObj->loadPageData( 'fromdbmaster' );
- } elseif ( isset( $params['pageid'] ) ) {
- $pageObj = WikiPage::newFromID( $params['pageid'] );
- if ( !$pageObj ) {
- $this->dieUsageMsg( array( 'nosuchpageid', $params['pageid'] ) );
- }
- $titleObj = $pageObj->getTitle();
- }
+ $pageObj = $this->getTitleOrPageId( $params, 'fromdbmaster' );
+ $titleObj = $pageObj->getTitle();
$errors = $titleObj->getUserPermissionsErrors( 'protect', $this->getUser() );
if ( $errors ) {
}
$restrictionTypes = $titleObj->getRestrictionTypes();
- $dbr = wfGetDB( DB_SLAVE );
+ $db = $this->getDB();
$protections = array();
$expiryarray = array();
}
if ( in_array( $expiry[$i], array( 'infinite', 'indefinite', 'never' ) ) ) {
- $expiryarray[$p[0]] = $dbr->getInfinity();
+ $expiryarray[$p[0]] = $db->getInfinity();
} else {
$exp = strtotime( $expiry[$i] );
if ( $exp < 0 || !$exp ) {
$expiryarray[$p[0]] = $exp;
}
$resultProtections[] = array( $p[0] => $protections[$p[0]],
- 'expiry' => ( $expiryarray[$p[0]] == $dbr->getInfinity() ?
+ 'expiry' => ( $expiryarray[$p[0]] == $db->getInfinity() ?
'infinite' :
wfTimestamp( TS_ISO_8601, $expiryarray[$p[0]] ) ) );
}
public function getPossibleErrors() {
return array_merge( parent::getPossibleErrors(),
- $this->getRequireOnlyOneParameterErrorMessages( array( 'title', 'pageid' ) ),
+ $this->getTitleOrPageIdErrorMessage(),
array(
- array( 'invalidtitle', 'title' ),
- array( 'nosuchpageid', 'pageid' ),
array( 'toofewexpiries', 'noofexpiries', 'noofprotections' ),
array( 'create-titleexists' ),
array( 'missingtitle-createonly' ),