Followup r87340: Post-hook swap bodytext into a new bodycontent key and append printf...
[lhc/web/wiklou.git] / includes / ProtectionForm.php
index 6f04e97..cac3025 100644 (file)
@@ -57,11 +57,11 @@ class ProtectionForm {
        /** Map of action to the expiry time of the existing protection */
        var $mExistingExpiry = array();
 
-       function __construct( Article $article ) {
+       function __construct( Page $article ) {
                global $wgUser;
                // Set instance variables.
                $this->mArticle = $article;
-               $this->mTitle = $article->mTitle;
+               $this->mTitle = $article->getTitle();
                $this->mApplicableTypes = $this->mTitle->getRestrictionTypes();
                
                // Check if the form should be disabled.
@@ -89,7 +89,7 @@ class ProtectionForm {
                $this->mCascade = $wgRequest->getBool( 'mwProtect-cascade', $this->mCascade );
 
                foreach( $this->mApplicableTypes as $action ) {
-                       // Fixme: this form currently requires individual selections,
+                       // @todo FIXME: This form currently requires individual selections,
                        // but the db allows multiples separated by commas.
                        
                        // Pull the actual restriction from the DB
@@ -147,7 +147,9 @@ class ProtectionForm {
        /**
         * Get the expiry time for a given action, by combining the relevant inputs.
         *
-        * @return 14-char timestamp or "infinity", or false if the input was invalid
+        * @param $action string
+        * 
+        * @return string 14-char timestamp or "infinity", or false if the input was invalid
         */
        function getExpiry( $action ) {
                if ( $this->mExpirySelection[$action] == 'existing' ) {
@@ -166,7 +168,7 @@ class ProtectionForm {
                                return false;
                        }
 
-                       // Fixme: non-qualified absolute times are not in users specified timezone
+                       // @todo FIXME: Non-qualified absolute times are not in users specified timezone
                        // and there isn't notice about it in the ui
                        $time = wfTimestamp( TS_MW, $unix );
                }
@@ -235,7 +237,8 @@ class ProtectionForm {
                                $wgOut->showPermissionsErrorPage( $this->mPermErrors );
                        }
                } else {
-                       $wgOut->addWikiMsg( 'protect-text', $this->mTitle->getPrefixedText() );
+                       $wgOut->addWikiMsg( 'protect-text',
+                               wfEscapeWikiText( $this->mTitle->getPrefixedText() ) );
                }
 
                $wgOut->addHTML( $this->buildForm() );
@@ -316,10 +319,10 @@ class ProtectionForm {
                        return false;
                }
 
-               if( $wgRequest->getCheck( 'mwProtectWatch' ) && $wgUser->isLoggedIn() ) {
-                       Action::factory( 'watch', $this->mArticle )->execute();
-               } elseif( $this->mTitle->userIsWatching() ) {
-                       Action::factory( 'unwatch', $this->mArticle )->execute();
+               if ( $wgRequest->getCheck( 'mwProtectWatch' ) && $wgUser->isLoggedIn() ) {
+                       WatchAction::doWatch( $this->mTitle, $wgUser );
+               } elseif ( $this->mTitle->userIsWatching() ) {
+                       WatchAction::doUnwatch( $this->mTitle, $wgUser );
                }
                return $ok;
        }
@@ -354,7 +357,7 @@ class ProtectionForm {
                        $msg = wfMessage( 'restriction-' . $action );
                        $out .= "<tr><td>".
                        Xml::openElement( 'fieldset' ) .
-                       Xml::element( 'legend', null, $msg->exists() ? $action : $msg->text() ) .
+                       Xml::element( 'legend', null, $msg->exists() ? $msg->text() : $action ) .
                        Xml::openElement( 'table', array( 'id' => "mw-protect-table-$action" ) ) .
                                "<tr><td>" . $this->buildSelector( $action, $selected ) . "</td></tr><tr><td>";
 
@@ -372,9 +375,9 @@ class ProtectionForm {
 
                        $expiryFormOptions = '';
                        if ( $this->mExistingExpiry[$action] && $this->mExistingExpiry[$action] != 'infinity' ) {
-                               $timestamp = $wgLang->timeanddate( $this->mExistingExpiry[$action] );
-                               $d = $wgLang->date( $this->mExistingExpiry[$action] );
-                               $t = $wgLang->time( $this->mExistingExpiry[$action] );
+                               $timestamp = $wgLang->timeanddate( $this->mExistingExpiry[$action], true );
+                               $d = $wgLang->date( $this->mExistingExpiry[$action], true );
+                               $t = $wgLang->time( $this->mExistingExpiry[$action], true );
                                $expiryFormOptions .=
                                        Xml::option(
                                                wfMsg( 'protect-existing-expiry', $timestamp, $d, $t ),
@@ -467,7 +470,10 @@ class ProtectionForm {
                                        </td>
                                        <td class='mw-input'>" .
                                                Xml::input( 'mwProtect-reason', 60, $this->mReason, array( 'type' => 'text',
-                                                       'id' => 'mwProtect-reason', 'maxlength' => 255 ) ) .
+                                                       'id' => 'mwProtect-reason', 'maxlength' => 180 ) ) .
+                                                       // Limited maxlength as the database trims at 255 bytes and other texts
+                                                       // chosen by dropdown menus on this page are also included in this database field.
+                                                       // The byte limit of 180 bytes is enforced in javascript
                                        "</td>
                                </tr>";
                        # Disallow watching is user is not logged in
@@ -563,7 +569,7 @@ class ProtectionForm {
                        return wfMsg( 'protect-default' );
                } else {
                        $msg = wfMessage( "protect-level-{$permission}" );
-                       if( !$msg->exists() ) {
+                       if( $msg->exists() ) {
                                return $msg->text();
                        }
                        return wfMsg( 'protect-fallback', $permission );