Merge "Fix typo in Release note"
[lhc/web/wiklou.git] / includes / ProtectionForm.php
index 4aa65d9..f777a37 100644 (file)
@@ -209,11 +209,11 @@ class ProtectionForm {
                if ( $this->mTitle->getRestrictionTypes() === array() ) {
                        // No restriction types available for the current title
                        // this might happen if an extension alters the available types
-                       $out->setPageTitle( wfMessage(
+                       $out->setPageTitle( $this->mContext->msg(
                                'protect-norestrictiontypes-title',
                                $this->mTitle->getPrefixedText()
                        ) );
-                       $out->addWikiText( wfMessage( 'protect-norestrictiontypes-text' )->text() );
+                       $out->addWikiText( $this->mContext->msg( 'protect-norestrictiontypes-text' )->plain() );
 
                        // Show the log in case protection was possible once
                        $this->showLogExtract( $out );
@@ -240,12 +240,12 @@ class ProtectionForm {
                # the protection settings at this time
                if ( $this->disabled ) {
                        $out->setPageTitle(
-                               wfMessage( 'protect-title-notallowed',
+                               $this->mContext->msg( 'protect-title-notallowed',
                                        $this->mTitle->getPrefixedText() )
                        );
                        $out->addWikiText( $out->formatPermissionsErrorMessage( $this->mPermErrors, 'protect' ) );
                } else {
-                       $out->setPageTitle( wfMessage( 'protect-title', $this->mTitle->getPrefixedText() ) );
+                       $out->setPageTitle( $this->mContext->msg( 'protect-title', $this->mTitle->getPrefixedText() ) );
                        $out->addWikiMsg( 'protect-text',
                                wfEscapeWikiText( $this->mTitle->getPrefixedText() ) );
                }
@@ -279,7 +279,7 @@ class ProtectionForm {
                $reasonstr = $this->mReasonSelection;
                if ( $reasonstr != 'other' && $this->mReason != '' ) {
                        // Entry from drop down menu + additional comment
-                       $reasonstr .= wfMessage( 'colon-separator' )->text() . $this->mReason;
+                       $reasonstr .= $this->mContext->msg( 'colon-separator' )->text() . $this->mReason;
                } elseif ( $reasonstr == 'other' ) {
                        $reasonstr = $this->mReason;
                }
@@ -321,7 +321,7 @@ class ProtectionForm {
                 *             you can also return an array of message name and its parameters
                 */
                $errorMsg = '';
-               if ( !wfRunHooks( 'ProtectionForm::save', array( $this->mArticle, &$errorMsg, $reasonstr ) ) ) {
+               if ( !Hooks::run( 'ProtectionForm::save', array( $this->mArticle, &$errorMsg, $reasonstr ) ) ) {
                        if ( $errorMsg == '' ) {
                                $errorMsg = array( 'hookaborted' );
                        }
@@ -342,21 +342,22 @@ class ProtectionForm {
         * @return string HTML form
         */
        function buildForm() {
-               $user = $this->mContext->getUser();
-               $output = $this->mContext->getOutput();
-               $lang = $this->mContext->getLanguage();
-               $cascadingRestrictionLevels = $this->mContext->getConfig()->get( 'CascadingRestrictionLevels' );
+               $context = $this->mContext;
+               $user = $context->getUser();
+               $output = $context->getOutput();
+               $lang = $context->getLanguage();
+               $cascadingRestrictionLevels = $context->getConfig()->get( 'CascadingRestrictionLevels' );
                $out = '';
                if ( !$this->disabled ) {
                        $output->addModules( 'mediawiki.legacy.protect' );
                        $output->addJsConfigVars( 'wgCascadeableLevels', $cascadingRestrictionLevels );
                        $out .= Xml::openElement( 'form', array( 'method' => 'post',
                                'action' => $this->mTitle->getLocalURL( 'action=protect' ),
-                               'id' => 'mw-Protect-Form', 'onsubmit' => 'ProtectionForm.enableUnchainedInputs(true)' ) );
+                               'id' => 'mw-Protect-Form' ) );
                }
 
                $out .= Xml::openElement( 'fieldset' ) .
-                       Xml::element( 'legend', null, wfMessage( 'protect-legend' )->text() ) .
+                       Xml::element( 'legend', null, $context->msg( 'protect-legend' )->text() ) .
                        Xml::openElement( 'table', array( 'id' => 'mwProtectSet' ) ) .
                        Xml::openElement( 'tbody' );
 
@@ -367,7 +368,7 @@ class ProtectionForm {
                foreach ( $this->mRestrictions as $action => $selected ) {
                        // Messages:
                        // restriction-edit, restriction-move, restriction-create, restriction-upload
-                       $msg = wfMessage( 'restriction-' . $action );
+                       $msg = $context->msg( 'restriction-' . $action );
                        $out .= "<tr><td>" .
                        Xml::openElement( 'fieldset' ) .
                        Xml::element( 'legend', null, $msg->exists() ? $msg->text() : $action ) .
@@ -375,29 +376,34 @@ class ProtectionForm {
                                "<tr><td>" . $this->buildSelector( $action, $selected ) . "</td></tr><tr><td>";
 
                        $mProtectexpiry = Xml::label(
-                               wfMessage( 'protectexpiry' )->text(),
+                               $context->msg( 'protectexpiry' )->text(),
                                "mwProtectExpirySelection-$action"
                        );
                        $mProtectother = Xml::label(
-                               wfMessage( 'protect-othertime' )->text(),
+                               $context->msg( 'protect-othertime' )->text(),
                                "mwProtect-$action-expires"
                        );
 
                        $expiryFormOptions = '';
-                       if ( $this->mExistingExpiry[$action] && $this->mExistingExpiry[$action] != 'infinity' ) {
-                               $timestamp = $lang->timeanddate( $this->mExistingExpiry[$action], true );
-                               $d = $lang->date( $this->mExistingExpiry[$action], true );
-                               $t = $lang->time( $this->mExistingExpiry[$action], true );
+                       if ( $this->mExistingExpiry[$action] ) {
+                               if ( $this->mExistingExpiry[$action] == 'infinity' ) {
+                                       $existingExpiryMessage = $context->msg( 'protect-existing-expiry-infinity' );
+                               } else {
+                                       $timestamp = $lang->userTimeAndDate( $this->mExistingExpiry[$action], $user );
+                                       $d = $lang->userDate( $this->mExistingExpiry[$action], $user );
+                                       $t = $lang->userTime( $this->mExistingExpiry[$action], $user );
+                                       $existingExpiryMessage = $context->msg( 'protect-existing-expiry', $timestamp, $d, $t );
+                               }
                                $expiryFormOptions .=
                                        Xml::option(
-                                               wfMessage( 'protect-existing-expiry', $timestamp, $d, $t )->text(),
+                                               $existingExpiryMessage->text(),
                                                'existing',
                                                $this->mExpirySelection[$action] == 'existing'
                                        ) . "\n";
                        }
 
                        $expiryFormOptions .= Xml::option(
-                               wfMessage( 'protect-othertime-op' )->text(),
+                               $context->msg( 'protect-othertime-op' )->text(),
                                "othertime"
                        ) . "\n";
                        foreach ( explode( ',', $scExpiryOptions ) as $option ) {
@@ -406,11 +412,9 @@ class ProtectionForm {
                                } else {
                                        list( $show, $value ) = explode( ":", $option );
                                }
-                               $show = htmlspecialchars( $show );
-                               $value = htmlspecialchars( $value );
                                $expiryFormOptions .= Xml::option(
                                        $show,
-                                       $value,
+                                       htmlspecialchars( $value ),
                                        $this->mExpirySelection[$action] === $value
                                ) . "\n";
                        }
@@ -426,16 +430,13 @@ class ProtectionForm {
                                                                array(
                                                                        'id' => "mwProtectExpirySelection-$action",
                                                                        'name' => "wpProtectExpirySelection-$action",
-                                                                       'onchange' => "ProtectionForm.updateExpiryList(this)",
                                                                        'tabindex' => '2' ) + $this->disabledAttrib,
                                                                $expiryFormOptions ) .
                                                "</td>
                                        </tr></table>";
                        }
                        # Add custom expiry field
-                       $attribs = array( 'id' => "mwProtect-$action-expires",
-                               'onkeyup' => 'ProtectionForm.updateExpiry(this)',
-                               'onchange' => 'ProtectionForm.updateExpiry(this)' ) + $this->disabledAttrib;
+                       $attribs = array( 'id' => "mwProtect-$action-expires" ) + $this->disabledAttrib;
                        $out .= "<table><tr>
                                        <td class='mw-label'>" .
                                                $mProtectother .
@@ -450,7 +451,7 @@ class ProtectionForm {
                        "</td></tr>";
                }
                # Give extensions a chance to add items to the form
-               wfRunHooks( 'ProtectionForm::buildForm', array( $this->mArticle, &$out ) );
+               Hooks::run( 'ProtectionForm::buildForm', array( $this->mArticle, &$out ) );
 
                $out .= Xml::closeElement( 'tbody' ) . Xml::closeElement( 'table' );
 
@@ -462,7 +463,7 @@ class ProtectionForm {
                                        <td></td>
                                        <td class="mw-input">' .
                                                Xml::checkLabel(
-                                                       wfMessage( 'protect-cascade' )->text(),
+                                                       $context->msg( 'protect-cascade' )->text(),
                                                        'mwProtect-cascade',
                                                        'mwProtect-cascade',
                                                        $this->mCascade, $this->disabledAttrib
@@ -475,12 +476,12 @@ class ProtectionForm {
                # Add manual and custom reason field/selects as well as submit
                if ( !$this->disabled ) {
                        $mProtectreasonother = Xml::label(
-                               wfMessage( 'protectcomment' )->text(),
+                               $context->msg( 'protectcomment' )->text(),
                                'wpProtectReasonSelection'
                        );
 
                        $mProtectreason = Xml::label(
-                               wfMessage( 'protect-otherreason' )->text(),
+                               $context->msg( 'protect-otherreason' )->text(),
                                'mwProtect-reason'
                        );
 
@@ -519,7 +520,7 @@ class ProtectionForm {
                                <tr>
                                        <td></td>
                                        <td class='mw-input'>" .
-                                               Xml::checkLabel( wfMessage( 'watchthis' )->text(),
+                                               Xml::checkLabel( $context->msg( 'watchthis' )->text(),
                                                        'mwProtectWatch', 'mwProtectWatch',
                                                        $user->isWatched( $this->mTitle ) || $user->getOption( 'watchdefault' ) ) .
                                        "</td>
@@ -530,7 +531,7 @@ class ProtectionForm {
                                        <td></td>
                                        <td class='mw-submit'>" .
                                                Xml::submitButton(
-                                                       wfMessage( 'confirm' )->text(),
+                                                       $context->msg( 'confirm' )->text(),
                                                        array( 'id' => 'mw-Protect-submit' )
                                                ) .
                                        "</td>
@@ -543,7 +544,7 @@ class ProtectionForm {
                        $title = Title::makeTitle( NS_MEDIAWIKI, 'Protect-dropdown' );
                        $link = Linker::link(
                                $title,
-                               wfMessage( 'protect-edit-reasonlist' )->escaped(),
+                               $context->msg( 'protect-edit-reasonlist' )->escaped(),
                                array(),
                                array( 'action' => 'edit' )
                        );
@@ -556,7 +557,6 @@ class ProtectionForm {
                                $user->getEditToken( array( 'protect', $this->mTitle->getPrefixedDBkey() ) )
                        );
                        $out .= Xml::closeElement( 'form' );
-                       $output->addScript( $this->buildCleanupScript() );
                }
 
                return $out;
@@ -581,8 +581,7 @@ class ProtectionForm {
                        'id' => $id,
                        'name' => $id,
                        'size' => count( $levels ),
-                       'onchange' => 'ProtectionForm.updateLevels(this)',
-                       ) + $this->disabledAttrib;
+               ) + $this->disabledAttrib;
 
                $out = Xml::openElement( 'select', $attribs );
                foreach ( $levels as $key ) {
@@ -600,30 +599,17 @@ class ProtectionForm {
         */
        private function getOptionLabel( $permission ) {
                if ( $permission == '' ) {
-                       return wfMessage( 'protect-default' )->text();
+                       return $this->mContext->msg( 'protect-default' )->text();
                } else {
                        // Messages: protect-level-autoconfirmed, protect-level-sysop
-                       $msg = wfMessage( "protect-level-{$permission}" );
+                       $msg = $this->mContext->msg( "protect-level-{$permission}" );
                        if ( $msg->exists() ) {
                                return $msg->text();
                        }
-                       return wfMessage( 'protect-fallback', $permission )->text();
+                       return $this->mContext->msg( 'protect-fallback', $permission )->text();
                }
        }
 
-       function buildCleanupScript() {
-               $options = array(
-                       'tableId' => 'mwProtectSet',
-                       'labelText' => wfMessage( 'protect-unchain-permissions' )->plain(),
-                       'numTypes' => count( $this->mApplicableTypes ),
-                       'existingMatch' => count( array_unique( $this->mExistingExpiry ) ) === 1,
-               );
-
-               $script = Xml::encodeJsCall( 'ProtectionForm.init', array( $options ) );
-
-               return Html::inlineScript( ResourceLoader::makeLoaderConditionalScript( $script ) );
-       }
-
        /**
         * Show protection long extracts for this page
         *
@@ -636,6 +622,6 @@ class ProtectionForm {
                $out->addHTML( Xml::element( 'h2', null, $protectLogPage->getName()->text() ) );
                LogEventsList::showLogExtract( $out, 'protect', $this->mTitle );
                # Let extensions add other relevant log extracts
-               wfRunHooks( 'ProtectionForm::showLogExtract', array( $this->mArticle, $out ) );
+               Hooks::run( 'ProtectionForm::showLogExtract', array( $this->mArticle, $out ) );
        }
 }