Merge "Added assertArrayEquals method to MediaWikiTestCase to avoid duplicating asort...
[lhc/web/wiklou.git] / includes / api / ApiProtect.php
index 57bf111..0fcaf42 100644 (file)
@@ -37,8 +37,8 @@ class ApiProtect extends ApiBase {
                global $wgRestrictionLevels;
                $params = $this->extractRequestParams();
 
-               $titleObj = $this->getTitleOrPageId( $params );
-               $pageObj = WikiPage::factory( $titleObj );
+               $pageObj = $this->getTitleOrPageId( $params, 'fromdbmaster' );
+               $titleObj = $pageObj->getTitle();
 
                $errors = $titleObj->getUserPermissionsErrors( 'protect', $this->getUser() );
                if ( $errors ) {
@@ -56,7 +56,7 @@ class ApiProtect extends ApiBase {
                }
 
                $restrictionTypes = $titleObj->getRestrictionTypes();
-               $dbr = wfGetDB( DB_SLAVE );
+               $db = $this->getDB();
 
                $protections = array();
                $expiryarray = array();
@@ -80,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 ) {
@@ -94,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]] ) ) );
                }
@@ -184,6 +184,16 @@ class ApiProtect extends ApiBase {
                );
        }
 
+       public function getResultProperties() {
+               return array(
+                       '' => array(
+                               'title' => 'string',
+                               'reason' => 'string',
+                               'cascade' => 'boolean'
+                       )
+               );
+       }
+
        public function getDescription() {
                return 'Change the protection level of a page';
        }
@@ -192,8 +202,6 @@ class ApiProtect extends ApiBase {
                return array_merge( parent::getPossibleErrors(),
                        $this->getTitleOrPageIdErrorMessage(),
                        array(
-                               array( 'invalidtitle', 'title' ),
-                               array( 'nosuchpageid', 'pageid' ),
                                array( 'toofewexpiries', 'noofexpiries', 'noofprotections' ),
                                array( 'create-titleexists' ),
                                array( 'missingtitle-createonly' ),