Merge "SkinTemplate: extract formatLanguageName() from outputPage()"
[lhc/web/wiklou.git] / includes / specials / SpecialProtectedpages.php
index 5039dfd..74ed537 100644 (file)
@@ -36,8 +36,6 @@ class SpecialProtectedpages extends SpecialPage {
        }
 
        public function execute( $par ) {
-               global $wgOut, $wgRequest;
-
                $this->setHeaders();
                $this->outputHeader();
 
@@ -46,106 +44,104 @@ class SpecialProtectedpages extends SpecialPage {
                        Title::purgeExpiredRestrictions();
                }
 
-               $type = $wgRequest->getVal( $this->IdType );
-               $level = $wgRequest->getVal( $this->IdLevel );
-               $sizetype = $wgRequest->getVal( 'sizetype' );
-               $size = $wgRequest->getIntOrNull( 'size' );
-               $NS = $wgRequest->getIntOrNull( 'namespace' );
-               $indefOnly = $wgRequest->getBool( 'indefonly' ) ? 1 : 0;
-               $cascadeOnly = $wgRequest->getBool('cascadeonly') ? 1 : 0;
+               $request = $this->getRequest();
+               $type = $request->getVal( $this->IdType );
+               $level = $request->getVal( $this->IdLevel );
+               $sizetype = $request->getVal( 'sizetype' );
+               $size = $request->getIntOrNull( 'size' );
+               $NS = $request->getIntOrNull( 'namespace' );
+               $indefOnly = $request->getBool( 'indefonly' ) ? 1 : 0;
+               $cascadeOnly = $request->getBool('cascadeonly') ? 1 : 0;
 
                $pager = new ProtectedPagesPager( $this, array(), $type, $level, $NS, $sizetype, $size, $indefOnly, $cascadeOnly );
 
-               $wgOut->addHTML( $this->showOptions( $NS, $type, $level, $sizetype, $size, $indefOnly, $cascadeOnly ) );
+               $this->getOutput()->addHTML( $this->showOptions( $NS, $type, $level, $sizetype, $size, $indefOnly, $cascadeOnly ) );
 
                if( $pager->getNumRows() ) {
-                       $s = $pager->getNavigationBar();
-                       $s .= "<ul>" .
-                               $pager->getBody() .
-                               "</ul>";
-                       $s .= $pager->getNavigationBar();
+                       $this->getOutput()->addHTML(
+                               $pager->getNavigationBar() .
+                               '<ul>' . $pager->getBody() . '</ul>' .
+                               $pager->getNavigationBar()
+                       );
                } else {
-                       $s = '<p>' . wfMsgHtml( 'protectedpagesempty' ) . '</p>';
+                       $this->getOutput()->addWikiMsg( 'protectedpagesempty' );
                }
-               $wgOut->addHTML( $s );
        }
 
        /**
         * Callback function to output a restriction
-        * @param $row object Protected title
-        * @return string Formatted <li> element
+        * @param Title $row Protected title
+        * @return string Formatted "<li>" element
         */
        public function formatRow( $row ) {
-               global $wgUser, $wgLang, $wgContLang;
-
                wfProfileIn( __METHOD__ );
 
-               static $skin = null, $infinity = null;
+               static $infinity = null;
 
-               if( is_null( $skin ) ){
-                       $skin = $wgUser->getSkin();
-                       $infinity = wfGetDB( DB_READ )->getInfinity();
+               if( is_null( $infinity ) ){
+                       $infinity = wfGetDB( DB_SLAVE )->getInfinity();
                }
 
                $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
-               $link = $skin->link( $title );
+               $link = Linker::link( $title );
 
                $description_items = array ();
 
-               $protType = wfMsgHtml( 'restriction-level-' . $row->pr_level );
+               $protType = $this->msg( 'restriction-level-' . $row->pr_level )->escaped();
 
                $description_items[] = $protType;
 
                if( $row->pr_cascade ) {
-                       $description_items[] = wfMsg( 'protect-summary-cascade' );
+                       $description_items[] = $this->msg( 'protect-summary-cascade' )->text();
                }
 
                $stxt = '';
+               $lang = $this->getLanguage();
 
-               $expiry = $wgLang->formatExpiry( $row->pr_expiry, TS_MW );
+               $expiry = $lang->formatExpiry( $row->pr_expiry, TS_MW );
                if( $expiry != $infinity ) {
-
-                       $expiry_description = wfMsg(
-                               'protect-expiring',
-                               $wgLang->timeanddate( $expiry ),
-                               $wgLang->date( $expiry ),
-                               $wgLang->time( $expiry )
-                       );
-
-                       $description_items[] = htmlspecialchars($expiry_description);
+                       $user = $this->getUser();
+                       $description_items[] = $this->msg(
+                               'protect-expiring-local',
+                               $lang->userTimeAndDate( $expiry, $user ),
+                               $lang->userDate( $expiry, $user ),
+                               $lang->userTime( $expiry, $user )
+                       )->escaped();
                }
 
                if(!is_null($size = $row->page_len)) {
-                       $stxt = $wgContLang->getDirMark() . ' ' . $skin->formatRevisionSize( $size );
+                       $stxt = $lang->getDirMark() . ' ' . Linker::formatRevisionSize( $size );
                }
 
                # Show a link to the change protection form for allowed users otherwise a link to the protection log
-               if( $wgUser->isAllowed( 'protect' ) ) {
-                       $changeProtection = ' (' . $skin->linkKnown(
+               if( $this->getUser()->isAllowed( 'protect' ) ) {
+                       $changeProtection = Linker::linkKnown(
                                $title,
-                               wfMsgHtml( 'protect_change' ),
+                               $this->msg( 'protect_change' )->escaped(),
                                array(),
                                array( 'action' => 'unprotect' )
-                       ) . ')';
+                       );
                } else {
                        $ltitle = SpecialPage::getTitleFor( 'Log' );
-                       $changeProtection = ' (' . $skin->linkKnown(
+                       $changeProtection = Linker::linkKnown(
                                $ltitle,
-                               wfMsgHtml( 'protectlogpage' ),
+                               $this->msg( 'protectlogpage' )->escaped(),
                                array(),
                                array(
                                        'type' => 'protect',
                                        'page' => $title->getPrefixedText()
                                )
-                       ) . ')';
+                       );
                }
 
+               $changeProtection = ' ' . $this->msg( 'parentheses' )->rawParams( $changeProtection )->escaped();
+
                wfProfileOut( __METHOD__ );
 
                return Html::rawElement(
                        'li',
                        array(),
-                       wfSpecialList( $link . $stxt, $wgLang->commaList( $description_items ) ) . $changeProtection ) . "\n";
+                       $lang->specialList( $link . $stxt, $lang->commaList( $description_items ), false ) . $changeProtection ) . "\n";
        }
 
        /**
@@ -160,10 +156,10 @@ class SpecialProtectedpages extends SpecialPage {
         */
        protected function showOptions( $namespace, $type='edit', $level, $sizetype, $size, $indefOnly, $cascadeOnly ) {
                global $wgScript;
-               $title = SpecialPage::getTitleFor( 'Protectedpages' );
+               $title = $this->getTitle();
                return Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
                        Xml::openElement( 'fieldset' ) .
-                       Xml::element( 'legend', array(), wfMsg( 'protectedpages' ) ) .
+                       Xml::element( 'legend', array(), $this->msg( 'protectedpages' )->text() ) .
                        Html::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" .
                        $this->getNamespaceMenu( $namespace ) . "&#160;\n" .
                        $this->getTypeMenu( $type ) . "&#160;\n" .
@@ -174,7 +170,7 @@ class SpecialProtectedpages extends SpecialPage {
                        "</span><br /><span style='white-space: nowrap'>" .
                        $this->getSizeLimit( $sizetype, $size ) . "&#160;\n" .
                        "</span>" .
-                       "&#160;" . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
+                       "&#160;" . Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
                        Xml::closeElement( 'fieldset' ) .
                        Xml::closeElement( 'form' );
        }
@@ -187,9 +183,19 @@ class SpecialProtectedpages extends SpecialPage {
         * @return String
         */
        protected function getNamespaceMenu( $namespace = null ) {
-               return "<span style='white-space: nowrap'>" .
-                       Xml::label( wfMsg( 'namespace' ), 'namespace' ) . '&#160;'
-                       . Xml::namespaceSelector( $namespace, '' ) . "</span>";
+               return Html::rawElement( 'span', array( 'style' => 'white-space: nowrap;' ),
+                       Html::namespaceSelector(
+                               array(
+                                       'selected' => $namespace,
+                                       'all' => '',
+                                       'label' => $this->msg( 'namespace' )->text()
+                               ), array(
+                                       'name'  => 'namespace',
+                                       'id'    => 'namespace',
+                                       'class' => 'namespaceselector',
+                               )
+                       )
+               );
        }
 
        /**
@@ -197,7 +203,7 @@ class SpecialProtectedpages extends SpecialPage {
         */
        protected function getExpiryCheck( $indefOnly ) {
                return
-                       Xml::checkLabel( wfMsg('protectedpages-indef'), 'indefonly', 'indefonly', $indefOnly ) . "\n";
+                       Xml::checkLabel( $this->msg( 'protectedpages-indef' )->text(), 'indefonly', 'indefonly', $indefOnly ) . "\n";
        }
 
        /**
@@ -205,7 +211,7 @@ class SpecialProtectedpages extends SpecialPage {
         */
        protected function getCascadeCheck( $cascadeOnly ) {
                return
-                       Xml::checkLabel( wfMsg('protectedpages-cascade'), 'cascadeonly', 'cascadeonly', $cascadeOnly ) . "\n";
+                       Xml::checkLabel( $this->msg( 'protectedpages-cascade' )->text(), 'cascadeonly', 'cascadeonly', $cascadeOnly ) . "\n";
        }
 
        /**
@@ -215,13 +221,13 @@ class SpecialProtectedpages extends SpecialPage {
                $max = $sizetype === 'max';
 
                return
-                       Xml::radioLabel( wfMsg('minimum-size'), 'sizetype', 'min', 'wpmin', !$max ) .
+                       Xml::radioLabel( $this->msg( 'minimum-size' )->text(), 'sizetype', 'min', 'wpmin', !$max ) .
                        '&#160;' .
-                       Xml::radioLabel( wfMsg('maximum-size'), 'sizetype', 'max', 'wpmax', $max ) .
+                       Xml::radioLabel( $this->msg( 'maximum-size' )->text(), 'sizetype', 'max', 'wpmax', $max ) .
                        '&#160;' .
                        Xml::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) .
                        '&#160;' .
-                       Xml::label( wfMsg('pagesize'), 'wpsize' );
+                       Xml::label( $this->msg( 'pagesize' )->text(), 'wpsize' );
        }
 
        /**
@@ -235,7 +241,7 @@ class SpecialProtectedpages extends SpecialPage {
 
                // First pass to load the log names
                foreach( Title::getFilteredRestrictionTypes( true ) as $type ) {
-                       $text = wfMsg("restriction-$type");
+                       $text = $this->msg( "restriction-$type" )->text();
                        $m[$text] = $type;
                }
 
@@ -246,7 +252,7 @@ class SpecialProtectedpages extends SpecialPage {
                }
 
                return "<span style='white-space: nowrap'>" .
-                       Xml::label( wfMsg('restriction-type') , $this->IdType ) . '&#160;' .
+                       Xml::label( $this->msg( 'restriction-type' )->text(), $this->IdType ) . '&#160;' .
                        Xml::tags( 'select',
                                array( 'id' => $this->IdType, 'name' => $this->IdType ),
                                implode( "\n", $options ) ) . "</span>";
@@ -260,14 +266,14 @@ class SpecialProtectedpages extends SpecialPage {
        protected function getLevelMenu( $pr_level ) {
                global $wgRestrictionLevels;
 
-               $m = array( wfMsg('restriction-level-all') => 0 ); // Temporary array
+               $m = array( $this->msg( 'restriction-level-all' )->text() => 0 ); // Temporary array
                $options = array();
 
                // First pass to load the log names
                foreach( $wgRestrictionLevels as $type ) {
                        // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
                        if( $type !='' && $type !='*') {
-                               $text = wfMsg("restriction-level-$type");
+                               $text = $this->msg( "restriction-level-$type" )->text();
                                $m[$text] = $type;
                        }
                }
@@ -279,7 +285,7 @@ class SpecialProtectedpages extends SpecialPage {
                }
 
                return "<span style='white-space: nowrap'>" .
-                       Xml::label( wfMsg( 'restriction-level' ) , $this->IdLevel ) . ' ' .
+                       Xml::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel ) . ' ' .
                        Xml::tags( 'select',
                                array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ),
                                implode( "\n", $options ) ) . "</span>";
@@ -306,7 +312,7 @@ class ProtectedPagesPager extends AlphabeticPager {
                $this->size = intval($size);
                $this->indefonly = (bool)$indefonly;
                $this->cascadeonly = (bool)$cascadeonly;
-               parent::__construct();
+               parent::__construct( $form->getContext() );
        }
 
        function getStartBody() {
@@ -332,12 +338,13 @@ class ProtectedPagesPager extends AlphabeticPager {
 
                if( $this->sizetype=='min' ) {
                        $conds[] = 'page_len>=' . $this->size;
-               } else if( $this->sizetype=='max' ) {
+               } elseif( $this->sizetype=='max' ) {
                        $conds[] = 'page_len<=' . $this->size;
                }
 
                if( $this->indefonly ) {
-                       $conds[] = "pr_expiry = 'infinity' OR pr_expiry IS NULL";
+                       $db = wfGetDB( DB_SLAVE );
+                       $conds[] = "pr_expiry = {$db->addQuotes( $db->getInfinity() )} OR pr_expiry IS NULL";
                }
                if( $this->cascadeonly ) {
                        $conds[] = "pr_cascade = '1'";