Merge "Revert "Adding sanity check to Title::isRedirect().""
[lhc/web/wiklou.git] / includes / api / ApiProtect.php
index 596bc5c..286f191 100644 (file)
@@ -37,22 +37,8 @@ class ApiProtect extends ApiBase {
                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 ) {
@@ -70,7 +56,7 @@ class ApiProtect extends ApiBase {
                }
 
                $restrictionTypes = $titleObj->getRestrictionTypes();
-               $dbr = wfGetDB( DB_SLAVE );
+               $db = $this->getDB();
 
                $protections = array();
                $expiryarray = array();
@@ -94,7 +80,7 @@ class ApiProtect extends ApiBase {
                        }
 
                        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 ) {
@@ -108,7 +94,7 @@ class ApiProtect extends ApiBase {
                                $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]] ) ) );
                }
@@ -204,10 +190,8 @@ class ApiProtect extends ApiBase {
 
        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' ),