Moved contribs rev parent ID batch query into doBatchLookups()
[lhc/web/wiklou.git] / includes / ProtectionForm.php
index 5f8ab3f..9771493 100644 (file)
@@ -57,7 +57,7 @@ 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;
@@ -196,7 +196,7 @@ class ProtectionForm {
         * @param $err String: error message or null if there's no error
         */
        function show( $err = null ) {
-               global $wgOut, $wgUser;
+               global $wgOut;
 
                $wgOut->setRobotPolicy( 'noindex,nofollow' );
 
@@ -223,8 +223,7 @@ class ProtectionForm {
                        $wgOut->wrapWikiMsg( "<div id=\"mw-protect-cascadeon\">\n$1\n" . $titles . "</div>", array( 'protect-cascadeon', count($cascadeSources) ) );
                }
 
-               $sk = $wgUser->getSkin();
-               $titleLink = $sk->link( $this->mTitle );
+               $titleLink = Linker::link( $this->mTitle );
                $wgOut->setPageTitle( wfMsg( 'protect-title', $this->mTitle->getPrefixedText() ) );
                $wgOut->setSubtitle( wfMsg( 'protect-backlink', $titleLink ) );
 
@@ -357,7 +356,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>";
 
@@ -375,9 +374,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 ),
@@ -501,7 +500,7 @@ class ProtectionForm {
 
                if ( $wgUser->isAllowed( 'editinterface' ) ) {
                        $title = Title::makeTitle( NS_MEDIAWIKI, 'Protect-dropdown' );
-                       $link = $wgUser->getSkin()->link(
+                       $link = Linker::link(
                                $title,
                                wfMsgHtml( 'protect-edit-reasonlist' ),
                                array(),
@@ -569,7 +568,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 );
@@ -577,25 +576,26 @@ class ProtectionForm {
        }
        
        function buildCleanupScript() {
-               global $wgRestrictionLevels, $wgGroupPermissions;
-               $script = 'var wgCascadeableLevels=';
-               $CascadeableLevels = array();
+               global $wgRestrictionLevels, $wgGroupPermissions, $wgOut;
+
+               $cascadeableLevels = array();
                foreach( $wgRestrictionLevels as $key ) {
-                       if ( (isset($wgGroupPermissions[$key]['protect']) && $wgGroupPermissions[$key]['protect']) || $key == 'protect' ) {
-                               $CascadeableLevels[] = "'" . Xml::escapeJsString( $key ) . "'";
+                       if ( ( isset( $wgGroupPermissions[$key]['protect'] ) && $wgGroupPermissions[$key]['protect'] )
+                               || $key == 'protect' 
+                       ) {
+                               $cascadeableLevels[] = $key;
                        }
                }
-               $script .= "[" . implode(',',$CascadeableLevels) . "];\n";
-               $options = (object)array(
+               $options = array(
                        'tableId' => 'mwProtectSet',
-                       'labelText' => wfMsg( 'protect-unchain-permissions' ),
-                       'numTypes' => count($this->mApplicableTypes),
-                       'existingMatch' => 1 == count( array_unique( $this->mExistingExpiry ) ),
+                       'labelText' => wfMessage( 'protect-unchain-permissions' )->plain(),
+                       'numTypes' => count( $this->mApplicableTypes ),
+                       'existingMatch' => count( array_unique( $this->mExistingExpiry ) ) === 1,
                );
-               $encOptions = Xml::encodeJsVar( $options );
 
-               $script .= "ProtectionForm.init($encOptions)";
-               return Html::inlineScript( "if ( window.mediaWiki ) { $script }" );
+               $wgOut->addJsConfigVars( 'wgCascadeableLevels', $cascadeableLevels );
+               $script = Xml::encodeJsCall( 'ProtectionForm.init', array( $options ) );
+               return Html::inlineScript( ResourceLoader::makeLoaderConditionalScript( $script ) );
        }
 
        /**
@@ -607,7 +607,7 @@ class ProtectionForm {
        function showLogExtract( &$out ) {
                # Show relevant lines from the protection log:
                $out->addHTML( Xml::element( 'h2', null, LogPage::logName( 'protect' ) ) );
-               LogEventsList::showLogExtract( $out, 'protect', $this->mTitle->getPrefixedText() );
+               LogEventsList::showLogExtract( $out, 'protect', $this->mTitle );
                # Let extensions add other relevant log extracts
                wfRunHooks( 'ProtectionForm::showLogExtract', array($this->mArticle,$out) );
        }