Merge "API: Overhaul ApiResult, make format=xml not throw, and add json formatversion"
[lhc/web/wiklou.git] / includes / api / ApiProtect.php
index a3d12b7..496db8f 100644 (file)
@@ -29,6 +29,8 @@
  */
 class ApiProtect extends ApiBase {
        public function execute() {
+               global $wgContLang;
+
                $params = $this->extractRequestParams();
 
                $pageObj = $this->getTitleOrPageId( $params, 'fromdbmaster' );
@@ -77,8 +79,8 @@ class ApiProtect extends ApiBase {
                                $this->dieUsageMsg( array( 'protect-invalidlevel', $p[1] ) );
                        }
 
-                       if ( in_array( $expiry[$i], array( 'infinite', 'indefinite', 'infinity', 'never' ) ) ) {
-                               $expiryarray[$p[0]] = $db->getInfinity();
+                       if ( wfIsInfinity( $expiry[$i] ) ) {
+                               $expiryarray[$p[0]] = 'infinity';
                        } else {
                                $exp = strtotime( $expiry[$i] );
                                if ( $exp < 0 || !$exp ) {
@@ -93,10 +95,7 @@ class ApiProtect extends ApiBase {
                        }
                        $resultProtections[] = array(
                                $p[0] => $protections[$p[0]],
-                               'expiry' => ( $expiryarray[$p[0]] == $db->getInfinity()
-                                       ? 'infinite'
-                                       : wfTimestamp( TS_ISO_8601, $expiryarray[$p[0]] )
-                               )
+                               'expiry' => $wgContLang->formatExpiry( $expiryarray[$p[0]], TS_ISO_8601, 'infinite' ),
                        );
                }
 
@@ -128,7 +127,7 @@ class ApiProtect extends ApiBase {
                }
                $res['protections'] = $resultProtections;
                $result = $this->getResult();
-               $result->setIndexedTagName( $res['protections'], 'protection' );
+               ApiResult::setIndexedTagName( $res['protections'], 'protection' );
                $result->addValue( null, $this->getModuleName(), $res );
        }
 
@@ -175,43 +174,21 @@ class ApiProtect extends ApiBase {
                );
        }
 
-       public function getParamDescription() {
-               $p = $this->getModulePrefix();
-
-               return array(
-                       'title' => "Title of the page you want to (un)protect. Cannot be used together with {$p}pageid",
-                       'pageid' => "ID of the page you want to (un)protect. Cannot be used together with {$p}title",
-                       'protections' => 'List of protection levels, formatted action=group (e.g. edit=sysop)',
-                       'expiry' => array(
-                               'Expiry timestamps. If only one timestamp is ' .
-                                       'set, it\'ll be used for all protections.',
-                               'Use \'infinite\', \'indefinite\', \'infinity\' or \'never\', for a never-expiring protection.'
-                       ),
-                       'reason' => 'Reason for (un)protecting',
-                       'cascade' => array(
-                               'Enable cascading protection (i.e. protect pages included in this page)',
-                               'Ignored if not all protection levels are \'sysop\' or \'protect\''
-                       ),
-                       'watch' => 'If set, add the page being (un)protected to your watchlist',
-                       'watchlist' => 'Unconditionally add or remove the page from your ' .
-                               'watchlist, use preferences or do not change watch',
-               );
-       }
-
-       public function getDescription() {
-               return 'Change the protection level of a page.';
-       }
-
        public function needsToken() {
                return 'csrf';
        }
 
-       public function getExamples() {
+       protected function getExamplesMessages() {
                return array(
-                       'api.php?action=protect&title=Main%20Page&token=123ABC&' .
-                               'protections=edit=sysop|move=sysop&cascade=&expiry=20070901163000|never',
-                       'api.php?action=protect&title=Main%20Page&token=123ABC&' .
+                       'action=protect&title=Main%20Page&token=123ABC&' .
+                               'protections=edit=sysop|move=sysop&cascade=&expiry=20070901163000|never'
+                               => 'apihelp-protect-example-protect',
+                       'action=protect&title=Main%20Page&token=123ABC&' .
                                'protections=edit=all|move=all&reason=Lifting%20restrictions'
+                               => 'apihelp-protect-example-unprotect',
+                       'action=protect&title=Main%20Page&token=123ABC&' .
+                               'protections=&reason=Lifting%20restrictions'
+                               => 'apihelp-protect-example-unprotect2',
                );
        }