Fix regression in unwatch links sent out by enotif. {{FULLPAGENAMEE}} happens to...
[lhc/web/wiklou.git] / includes / ProtectionForm.php
index e6b7dbe..28df01a 100644 (file)
@@ -54,20 +54,29 @@ class ProtectionForm {
        var $mExistingExpiry = array();
 
        function __construct( Article $article ) {
-               global $wgRequest, $wgUser;
-               global $wgRestrictionTypes, $wgRestrictionLevels;
+               global $wgUser;
+               // Set instance variables.
                $this->mArticle = $article;
                $this->mTitle = $article->mTitle;
-               $this->mApplicableTypes = $this->mTitle->exists() ? $wgRestrictionTypes : array('create');
-
-               $this->mCascade = $this->mTitle->areRestrictionsCascading();
-
-               // The form will be available in read-only to show levels.
+               $this->mApplicableTypes = $this->mTitle->getRestrictionTypes();
+               
+               // Check if the form should be disabled.
+               // If it is, the form will be available in read-only to show levels.
                $this->mPermErrors = $this->mTitle->getUserPermissionsErrors('protect',$wgUser);
                $this->disabled = wfReadOnly() || $this->mPermErrors != array();
                $this->disabledAttrib = $this->disabled
                        ? array( 'disabled' => 'disabled' )
                        : array();
+               
+               $this->loadData();
+       }
+       
+       // Loads the current state of protection into the object.
+       function loadData() {
+               global $wgRequest, $wgUser;
+               global $wgRestrictionLevels;
+               
+               $this->mCascade = $this->mTitle->areRestrictionsCascading();
 
                $this->mReason = $wgRequest->getText( 'mwProtect-reason' );
                $this->mReasonSelection = $wgRequest->getText( 'wpProtectReasonSelection' );
@@ -76,6 +85,8 @@ class ProtectionForm {
                foreach( $this->mApplicableTypes as $action ) {
                        // Fixme: this form currently requires individual selections,
                        // but the db allows multiples separated by commas.
+                       
+                       // Pull the actual restriction from the DB
                        $this->mRestrictions[$action] = implode( '', $this->mTitle->getRestrictions( $action ) );
 
                        if ( !$this->mRestrictions[$action] ) {
@@ -180,7 +191,7 @@ class ProtectionForm {
 
                list( $cascadeSources, /* $restrictions */ ) = $this->mTitle->getCascadeProtectionSources();
 
-               if ( "" != $err ) {
+               if ( $err != "" ) {
                        $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
                        $wgOut->addHTML( "<p class='error'>{$err}</p>\n" );
                }
@@ -284,7 +295,7 @@ class ProtectionForm {
                        return false;
                }
 
-               if( $wgRequest->getCheck( 'mwProtectWatch' ) ) {
+               if( $wgRequest->getCheck( 'mwProtectWatch' ) && $wgUser->isLoggedIn() ) {
                        $this->mArticle->doWatch();
                } elseif( $this->mTitle->userIsWatching() ) {
                        $this->mArticle->doUnwatch();
@@ -440,7 +451,10 @@ class ProtectionForm {
                                                Xml::input( 'mwProtect-reason', 60, $this->mReason, array( 'type' => 'text',
                                                        'id' => 'mwProtect-reason', 'maxlength' => 255 ) ) .
                                        "</td>
-                               </tr>
+                               </tr>";
+                       # Disallow watching is user is not logged in
+                       if( $wgUser->isLoggedIn() ) {
+                               $out .= "
                                <tr>
                                        <td></td>
                                        <td class='mw-input'>" .
@@ -448,7 +462,9 @@ class ProtectionForm {
                                                        'mwProtectWatch', 'mwProtectWatch',
                                                        $this->mTitle->userIsWatching() || $wgUser->getOption( 'watchdefault' ) ) .
                                        "</td>
-                               </tr>
+                               </tr>";
+                       }
+                       $out .= "
                                <tr>
                                        <td></td>
                                        <td class='mw-submit'>" .
@@ -547,8 +563,8 @@ class ProtectionForm {
                }
                $script .= "[" . implode(',',$CascadeableLevels) . "];\n";
                $options = (object)array(
-                       'tableId' => 'mw-protect-table-move',
-                       'labelText' => wfMsg( 'protect-unchain' ),
+                       'tableId' => 'mwProtectSet',
+                       'labelText' => wfMsg( 'protect-unchain-permissions' ),
                        'numTypes' => count($this->mApplicableTypes),
                        'existingMatch' => 1 == count( array_unique( $this->mExistingExpiry ) ),
                );