Make API check for page restrictions in the old format too.
authorRotem Liss <rotem@users.mediawiki.org>
Tue, 27 Nov 2007 10:22:14 +0000 (10:22 +0000)
committerRotem Liss <rotem@users.mediawiki.org>
Tue, 27 Nov 2007 10:22:14 +0000 (10:22 +0000)
RELEASE-NOTES
includes/api/ApiQueryInfo.php

index bc04cae..5751c2d 100644 (file)
@@ -194,7 +194,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   for users with special characters in their names
 * The number of watching users in watchlists was always reported as 1
 * namespaceDupes.php no longer dies when coming across an illegal title
-
+* Make API check for restrictions in the old format too.
 
 == Parser changes in 1.12 ==
 
index b1b1a9a..39a6c80 100644 (file)
@@ -40,6 +40,7 @@ class ApiQueryInfo extends ApiQueryBase {
        }
 
        public function requestExtraData($pageSet) {
+               $pageSet->requestField('page_restrictions');
                $pageSet->requestField('page_is_redirect');
                $pageSet->requestField('page_is_new');
                $pageSet->requestField('page_counter');
@@ -70,6 +71,7 @@ class ApiQueryInfo extends ApiQueryBase {
                $titles = $pageSet->getGoodTitles();
                $result = $this->getResult();
 
+               $pageRestrictions = $pageSet->getCustomField('page_restrictions');
                $pageIsRedir = $pageSet->getCustomField('page_is_redirect');
                $pageIsNew = $pageSet->getCustomField('page_is_new');
                $pageCounter = $pageSet->getCustomField('page_counter');
@@ -125,7 +127,36 @@ class ApiQueryInfo extends ApiQueryBase {
                                        $pageInfo['protection'] = $protections[$pageid];
                                        $result->setIndexedTagName($pageInfo['protection'], 'pr');
                                } else {
-                                       $pageInfo['protection'] = array();
+                                       # Also check old restrictions
+                                       if( $pageRestrictions[$pageid] ) {
+                                               foreach( explode( ':', trim( $pageRestrictions[$pageid] ) ) as $restrict ) {
+                                                       $temp = explode( '=', trim( $restrict ) );
+                                                       if(count($temp) == 1) {
+                                                               // old old format should be treated as edit/move restriction
+                                                               $restriction = trim( $temp[0] );
+                                                               $pageInfo['protection'][] = array(
+                                                                       'type' => 'edit',
+                                                                       'level' => $restriction,
+                                                                       'expiry' => 'infinity',
+                                                               );
+                                                               $pageInfo['protection'][] = array(
+                                                                       'type' => 'move',
+                                                                       'level' => $restriction,
+                                                                       'expiry' => 'infinity',
+                                                               );
+                                                       } else {
+                                                               $restriction = trim( $temp[1] );
+                                                               $pageInfo['protection'][] = array(
+                                                                       'type' => $temp[0],
+                                                                       'level' => $restriction,
+                                                                       'expiry' => 'infinity',
+                                                               );
+                                                       }
+                                               }
+                                               $result->setIndexedTagName($pageInfo['protection'], 'pr');
+                                       } else {
+                                               $pageInfo['protection'] = array();
+                                       }
                                }
                        }