From: Rob Church Date: Sat, 30 Dec 2006 19:49:30 +0000 (+0000) Subject: * (bug 8437) Make Title::loadRestrictions() initialise $mRestrictions properly X-Git-Tag: 1.31.0-rc.0~54726 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=4b1811dcb088d5eb589a7a43559c03003d3b9f71;p=lhc%2Fweb%2Fwiklou.git * (bug 8437) Make Title::loadRestrictions() initialise $mRestrictions properly * (bug 8437) Fix Title::isSemiProtected() when $mRestrictions was array() or unset * Clean up Title::getRestrictions() [Most of the above from a patch by Fyren, with minor modifications] --- diff --git a/includes/Title.php b/includes/Title.php index 0342f43f27..98e2dcefdd 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -990,9 +990,15 @@ class Title { */ function isSemiProtected( $action = 'edit' ) { if( $this->exists() ) { - foreach( $this->getRestrictions( $action ) as $restriction ) { - if( strtolower( $restriction ) != 'autoconfirmed' ) - return false; + $restrictions = $this->getRestrictions( $action ); + if( count( $restrictions ) > 0 ) { + foreach( $restrictions as $restriction ) { + if( strtolower( $restriction ) != 'autoconfirmed' ) + return false; + } + } else { + # Not protected + return false; } return true; } else { @@ -1296,6 +1302,15 @@ class Title { * @access public */ function loadRestrictions( $res ) { + $this->mRestrictions['edit'] = array(); + $this->mRestrictions['move'] = array(); + + if( !$res ) { + # No restrictions (page_restrictions blank) + $this->mRestrictionsLoaded = true; + return; + } + foreach( explode( ':', trim( $res ) ) as $restrict ) { $temp = explode( '=', trim( $restrict ) ); if(count($temp) == 1) { @@ -1311,23 +1326,24 @@ class Title { /** * Accessor/initialisation for mRestrictions + * + * @access public * @param string $action action that permission needs to be checked for * @return array the array of groups allowed to edit this article - * @access public */ - function getRestrictions($action) { - $id = $this->getArticleID(); - if ( 0 == $id ) { return array(); } - - if ( ! $this->mRestrictionsLoaded ) { - $dbr =& wfGetDB( DB_SLAVE ); - $res = $dbr->selectField( 'page', 'page_restrictions', 'page_id='.$id ); - $this->loadRestrictions( $res ); - } - if( isset( $this->mRestrictions[$action] ) ) { - return $this->mRestrictions[$action]; + function getRestrictions( $action ) { + if( $this->exists() ) { + if( !$this->mRestrictionsLoaded ) { + $dbr =& wfGetDB( DB_SLAVE ); + $res = $dbr->selectField( 'page', 'page_restrictions', $this->getArticleId() ); + $this->loadRestrictions( $res ); + } + return isset( $this->mRestrictions[$action] ) + ? $this->mRestrictions[$action] + : array(); + } else { + return array(); } - return array(); } /**