Added the ability to protect a page from moves but not from edits. See
authorShane King <shaneking@users.mediawiki.org>
Wed, 24 Nov 2004 12:55:48 +0000 (12:55 +0000)
committerShane King <shaneking@users.mediawiki.org>
Wed, 24 Nov 2004 12:55:48 +0000 (12:55 +0000)
bug #868.

includes/Article.php
includes/EditPage.php
includes/Skin.php
includes/SkinTemplate.php
includes/Title.php
languages/Language.php

index b361976..5562294 100644 (file)
@@ -407,8 +407,7 @@ class Article {
                        $this->mCounter = $s->cur_counter;
                        $this->mTimestamp = wfTimestamp(TS_MW,$s->cur_timestamp);
                        $this->mTouched = wfTimestamp(TS_MW,$s->cur_touched);
-                       $this->mTitle->mRestrictions = explode( ',', trim( $s->cur_restrictions ) );
-                       $this->mTitle->mRestrictionsLoaded = true;
+                       $this->mTitle->loadRestrictions( $s->cur_restrictions );
                } else { # oldid set, retrieve historical version
                        $s = $dbr->selectRow( 'old', $this->getOldContentFields(), array( 'old_id' => $oldid ),
                                $fname, $this->getSelectOptions() );
@@ -486,8 +485,7 @@ class Article {
                        $this->mCounter = $s->cur_counter;
                        $this->mTimestamp = wfTimestamp(TS_MW,$s->cur_timestamp);
                        $this->mTouched = wfTimestamp(TS_MW,$s->cur_touched);
-                       $this->mTitle->mRestrictions = explode( ',', trim( $s->cur_restrictions ) );
-                       $this->mTitle->mRestrictionsLoaded = true;
+                       $this->mTitle->loadRestrictions( $s->cur_restrictions );
                } else { # oldid set, retrieve historical version
                        $s = $dbr->selectRow( 'old', $this->getOldContentFields(), array( 'old_id' => $oldid ),
                                $fname, $this->getSelectOptions() );
@@ -1275,14 +1273,20 @@ class Article {
                }
 
                $confirm = $wgRequest->getBool( 'wpConfirmProtect' ) && $wgRequest->wasPosted();
+               $moveonly = $wgRequest->getBool( 'wpMoveOnly' );
                $reason = $wgRequest->getText( 'wpReasonProtect' );
 
                if ( $confirm ) {
+                       $restrictions = "move=" . $limit;
+                       if( !$moveonly ) {
+                               $restrictions .= ":edit=" . $limit;
+                       }
+                       
                        $dbw =& wfGetDB( DB_MASTER );
                        $dbw->update( 'cur',
                                array( /* SET */
                                        'cur_touched' => $dbw->timestamp(),
-                                       'cur_restrictions' => (string)$limit
+                                       'cur_restrictions' => $restrictions
                                ), array( /* WHERE */
                                        'cur_id' => $id
                                ), 'Article::protect'
@@ -1315,6 +1319,7 @@ class Article {
 
                $check = '';
                $protcom = '';
+               $moveonly = '';
 
                if ( $limit === '' ) {
                        $wgOut->setPageTitle( wfMsg( 'confirmunprotect' ) );
@@ -1328,6 +1333,7 @@ class Article {
                        $wgOut->setSubtitle( wfMsg( 'protectsub', $sub ) );
                        $wgOut->addWikiText( wfMsg( 'confirmprotecttext' ) );
                        $check = htmlspecialchars( wfMsg( 'confirmprotect' ) );
+                       $moveonly = htmlspecialchars( wfMsg( 'protectmoveonly' ) );
                        $protcom = htmlspecialchars( wfMsg( 'protectcomment' ) );
                        $formaction = $this->mTitle->escapeLocalURL( 'action=protect' . $par );
                }
@@ -1355,7 +1361,19 @@ class Article {
                        <td>
                                <label for='wpConfirmProtect'>{$check}</label>
                        </td>
-               </tr>
+               </tr> " );
+               if($moveonly != '') {
+                       $wgOut->AddHTML( "
+               <tr>
+                       <td align='right'>
+                               <input type='checkbox' name='wpMoveOnly' value='1' id='wpMoveOnly' />
+                       </td>
+                       <td>
+                               <label for='wpMoveOnly'>{$moveonly}</label>
+                       </td>
+               </tr> " );
+               }
+               $wgOut->addHTML( "
                <tr>
                        <td>&nbsp;</td>
                        <td>
index 0188851..e6e0ba7 100644 (file)
@@ -305,7 +305,7 @@ class EditPage {
                } else if ( $isCssJsSubpage and 'preview' != $formtype) {
                        $wgOut->addHTML( wfMsg( 'usercssjsyoucanpreview' ));
                }
-               if( $this->mTitle->isProtected() ) {
+               if( $this->mTitle->isProtected('edit') ) {
                        $wgOut->addHTML( '<strong>' . wfMsg( 'protectedpagewarning' ) .
                          "</strong><br />\n" );
                }
index 53094d7..f0bb25b 100644 (file)
@@ -1060,7 +1060,7 @@ class Skin {
        function moveThisPage() {
                global $wgTitle, $wgContLang;
 
-               if ( $wgTitle->userCanEdit() ) {
+               if ( $wgTitle->userCanMove() ) {
                        $s = $this->makeKnownLink( $wgContLang->specialPage( 'Movepage' ),
                          wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
                } // no message if page is protected - would be redundant
index 7b286dc..63b0c5d 100644 (file)
@@ -224,7 +224,7 @@ class SkinTemplate extends Skin {
                $tpl->set( "editable", ($wgTitle->getNamespace() != NS_SPECIAL ) );
                $tpl->set( "exists", $wgTitle->getArticleID() != 0 );
                $tpl->set( "watch", $wgTitle->userIsWatching() ? "unwatch" : "watch" );
-               $tpl->set( "protect", count($wgTitle->getRestrictions()) ? "unprotect" : "protect" );
+               $tpl->set( "protect", count($wgTitle->isProtected()) ? "unprotect" : "protect" );
                $tpl->set( "helppage", wfMsg('helppage'));
                */
                $tpl->set( 'searchaction', $this->escapeSearchLink() );
@@ -557,7 +557,7 @@ class SkinTemplate extends Skin {
                                        );
                                }
                                if ( $wgUser->getID() != 0 ) {
-                                       if ( $wgTitle->userCanEdit()) {
+                                       if ( $wgTitle->userCanMove()) {
                                                $content_actions['move'] = array(
                                                        'class' => ($wgTitle->getDbKey() == 'Movepage' and $wgTitle->getNamespace == Namespace::getSpecial()) ? 'selected' : false,
                                                        'text' => wfMsg('move'),
index 2d7f17c..7f019f7 100644 (file)
@@ -702,13 +702,21 @@ class Title {
 
        /**
         * Does the title correspond to a protected article?
+        * @param string $what the action the page is protected from,
+        *      by default checks move and edit
         * @return boolean
         * @access public
         */
-       function isProtected() {
+       function isProtected($action = '') {
                if ( -1 == $this->mNamespace ) { return true; }
-               $a = $this->getRestrictions();
-               if ( in_array( 'sysop', $a ) ) { return true; }
+               if($action == 'edit' || $action == '') {
+                       $a = $this->getRestrictions("edit");
+                       if ( in_array( 'sysop', $a ) ) { return true; }
+               }
+               if($action == 'move' || $action == '') {
+                       $a = $this->getRestrictions("move");
+                       if ( in_array( 'sysop', $a ) ) { return true; } 
+               }       
                return false;
        }
 
@@ -726,12 +734,13 @@ class Title {
                return $wgUser->isWatched( $this );
        }
 
-       /**
-        * Can $wgUser edit this page?
+       /**
+        * Is $wgUser perform $action this page?
+        * @param string $action action that permission needs to be checked for
         * @return boolean
-        * @access public
-        */
-       function userCanEdit() {
+        * @access private
+        */
+       function userCan($action) {
                $fname = 'Title::userCanEdit';
                wfProfileIn( $fname );
                
@@ -770,7 +779,7 @@ class Title {
                        return false;
                }
 
-               foreach( $this->getRestrictions() as $right ) {
+               foreach( $this->getRestrictions($action) as $right ) {
                        if( '' != $right && !$wgUser->isAllowed( $right ) ) {
                                wfProfileOut( $fname );
                                return false;
@@ -780,6 +789,24 @@ class Title {
                return true;
        }
 
+       /**
+        * Can $wgUser edit this page?
+        * @return boolean
+        * @access public
+        */
+       function userCanEdit() {
+               return $this->userCan('edit');
+       }
+       
+       /**
+        * Can $wgUser move this page?
+        * @return boolean
+        * @access public
+        */     
+       function userCanMove() {
+               return $this->userCan('move');
+       }
+
        /**
         * Can $wgUser read this page?
         * @return boolean
@@ -854,22 +881,42 @@ class Title {
                return ( $wgUser->isAllowed('editinterface') or preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform) );
        }
 
+       /**
+        * Loads a string into mRestrictions array
+        * @param string $res restrictions in string format      
+        * @access public
+        */
+       function loadRestrictions( $res ) {
+               foreach( explode( ':', trim( $res ) ) as $restrict ) {
+                       $temp = explode( '=', trim( $restrict ) );
+                       if(count($temp) == 1) {
+                               // old format should be treated as edit/move restriction
+                               $this->mRestrictions["edit"] = explode( ',', trim( $temp[0] ) );
+                               $this->mRestrictions["move"] = explode( ',', trim( $temp[0] ) );
+                       } else {
+                               $this->mRestrictions[$temp[0]] = explode( ',', trim( $temp[1] ) );
+                       }
+               }
+               $this->mRestrictionsLoaded = true;
+       }
+
        /**
         * Accessor/initialisation for mRestrictions
+        * @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() {
+       function getRestrictions($action) {
                $id = $this->getArticleID();
                if ( 0 == $id ) { return array(); }
 
                if ( ! $this->mRestrictionsLoaded ) {
                        $dbr =& wfGetDB( DB_SLAVE );
                        $res = $dbr->selectField( 'cur', 'cur_restrictions', 'cur_id='.$id );
-                       $this->mRestrictions = explode( ',', trim( $res ) );
-                       $this->mRestrictionsLoaded = true;
+                       $this->loadRestrictions( $res );
                }
-               return $this->mRestrictions;
+               $result = $this->mRestrictions[$action];
+               return $result ? $result : array();
        }
        
        /**
index 2089c1b..5df0d68 100644 (file)
@@ -1199,6 +1199,7 @@ See [[Project:Protected page]] for more information.",
 'protectsub' =>"(Protecting \"$1\")",
 'confirmprotecttext' => 'Do you really want to protect this page?',
 'confirmprotect' => 'Confirm protection',
+'protectmoveonly' => 'Protect from moves only',
 'protectcomment' => 'Reason for protecting',
 'unprotectsub' =>"(Unprotecting \"$1\")",
 'confirmunprotecttext' => 'Do you really want to unprotect this page?',