* Fail fast on trying to find create restrictions for pages that exist.
authorAndrew Garrett <werdna@users.mediawiki.org>
Thu, 6 Aug 2009 16:26:04 +0000 (16:26 +0000)
committerAndrew Garrett <werdna@users.mediawiki.org>
Thu, 6 Aug 2009 16:26:04 +0000 (16:26 +0000)
* Break out loadRestrictionsFromRow into a new function loadRestrictionsFromRows (which actually accepts an array of rows, unlike the original), and loadRestrictionsFromResultWrapper, which has the semantics of the old function (and wraps around loadRestrictionsFromRows).

includes/Title.php

index 41fa944..5e0e539 100644 (file)
@@ -1398,6 +1398,11 @@ class Title {
                if ( $this->getNamespace() < 0 ) {
                        return false;
                }
+               
+               // Can't protect pages that exist.
+               if ($this->exists()) {
+                       return false;
+               }
 
                $dbr = wfGetDB( DB_SLAVE );
                $res = $dbr->select( 'protected_titles', '*',
@@ -1857,7 +1862,18 @@ class Title {
         * Loads a string into mRestrictions array
         * @param $res \type{Resource} restrictions as an SQL result.
         */
-       private function loadRestrictionsFromRow( $res, $oldFashionedRestrictions = NULL ) {
+       private function loadRestrictionsFromResultWrapper( $res, $oldFashionedRestrictions = NULL ) {
+               $rows = array();
+               $dbr = wfGetDB( DB_SLAVE );
+               
+               while( $row = $dbr->fetchObject( $res ) ) {
+                       $rows[] = $row;
+               }
+               
+               $this->loadRestrictionsFromRows( $rows, $oldFashionedRestrictions );
+       }
+       
+       public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = NULL ) {
                global $wgRestrictionTypes;
                $dbr = wfGetDB( DB_SLAVE );
 
@@ -1892,12 +1908,12 @@ class Title {
 
                }
 
-               if( $dbr->numRows( $res ) ) {
+               if( count($rows) ) {
                        # Current system - load second to make them override.
                        $now = wfTimestampNow();
                        $purgeExpired = false;
 
-                       foreach( $res as $row ) {
+                       foreach( $rows as $row ) {
                                # Cycle through all the restrictions.
 
                                // Don't take care of restrictions types that aren't in $wgRestrictionTypes
@@ -1939,7 +1955,7 @@ class Title {
                                $res = $dbr->select( 'page_restrictions', '*',
                                        array ( 'pr_page' => $this->getArticleId() ), __METHOD__ );
 
-                               $this->loadRestrictionsFromRow( $res, $oldFashionedRestrictions );
+                               $this->loadRestrictionsFromResultWrapper( $res, $oldFashionedRestrictions );
                        } else {
                                $title_protection = $this->getTitleProtection();