Use local context to get message
[lhc/web/wiklou.git] / includes / specials / SpecialProtectedpages.php
index 61a82cf..eec974f 100644 (file)
@@ -1,41 +1,61 @@
 <?php
 /**
+ * Implements Special:Protectedpages
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
  * @file
  * @ingroup SpecialPage
  */
 
 /**
- * @todo document
+ * A special page that lists protected pages
+ *
  * @ingroup SpecialPage
  */
-class ProtectedPagesForm {
+class SpecialProtectedpages extends SpecialPage {
 
        protected $IdLevel = 'level';
        protected $IdType  = 'type';
 
-       public function showList( $msg = '' ) {
-               global $wgOut, $wgRequest;
+       public function __construct() {
+               parent::__construct( 'Protectedpages' );
+       }
 
-               if( $msg != "" ) {
-                       $wgOut->setSubtitle( $msg );
-               }
+       public function execute( $par ) {
+               $this->setHeaders();
+               $this->outputHeader();
 
                // Purge expired entries on one in every 10 queries
                if( !mt_rand( 0, 10 ) ) {
                        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();
@@ -46,7 +66,7 @@ class ProtectedPagesForm {
                } else {
                        $s = '<p>' . wfMsgHtml( 'protectedpagesempty' ) . '</p>';
                }
-               $wgOut->addHTML( $s );
+               $this->getOutput()->addHTML( $s );
        }
 
        /**
@@ -55,17 +75,16 @@ class ProtectedPagesForm {
         * @return string Formatted <li> element
         */
        public function formatRow( $row ) {
-               global $wgUser, $wgLang, $wgContLang;
-
                wfProfileIn( __METHOD__ );
 
-               static $skin=null;
+               static $infinity = null;
 
-               if( is_null( $skin ) )
-                       $skin = $wgUser->getSkin();
+               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 ();
 
@@ -77,25 +96,29 @@ class ProtectedPagesForm {
                        $description_items[] = wfMsg( 'protect-summary-cascade' );
                }
 
-               $expiry_description = '';
                $stxt = '';
+               $lang = $this->getLanguage();
 
-               if( $row->pr_expiry != 'infinity' && strlen($row->pr_expiry) ) {
-                       $expiry = Block::decodeExpiry( $row->pr_expiry );
+               $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 ) );
+                       $expiry_description = wfMsg(
+                               'protect-expiring-local',
+                               $lang->timeanddate( $expiry, true ),
+                               $lang->date( $expiry, true ),
+                               $lang->time( $expiry, true )
+                       );
 
                        $description_items[] = htmlspecialchars($expiry_description);
                }
 
                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' ),
                                array(),
@@ -103,7 +126,7 @@ class ProtectedPagesForm {
                        ) . ')';
                } else {
                        $ltitle = SpecialPage::getTitleFor( 'Log' );
-                       $changeProtection = ' (' . $skin->linkKnown(
+                       $changeProtection = ' (' . Linker::linkKnown(
                                $ltitle,
                                wfMsgHtml( 'protectlogpage' ),
                                array(),
@@ -119,7 +142,7 @@ class ProtectedPagesForm {
                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";
        }
 
        /**
@@ -134,21 +157,21 @@ class ProtectedPagesForm {
         */
        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::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" .
-                       $this->getNamespaceMenu( $namespace ) . "&nbsp;\n" .
-                       $this->getTypeMenu( $type ) . "&nbsp;\n" .
-                       $this->getLevelMenu( $level ) . "&nbsp;\n" .
+                       Html::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" .
+                       $this->getNamespaceMenu( $namespace ) . "&#160;\n" .
+                       $this->getTypeMenu( $type ) . "&#160;\n" .
+                       $this->getLevelMenu( $level ) . "&#160;\n" .
                        "<br /><span style='white-space: nowrap'>" .
-                       $this->getExpiryCheck( $indefOnly ) . "&nbsp;\n" .
-                       $this->getCascadeCheck( $cascadeOnly ) . "&nbsp;\n" .
+                       $this->getExpiryCheck( $indefOnly ) . "&#160;\n" .
+                       $this->getCascadeCheck( $cascadeOnly ) . "&#160;\n" .
                        "</span><br /><span style='white-space: nowrap'>" .
-                       $this->getSizeLimit( $sizetype, $size ) . "&nbsp;\n" .
+                       $this->getSizeLimit( $sizetype, $size ) . "&#160;\n" .
                        "</span>" .
-                       "&nbsp;" . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
+                       "&#160;" . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
                        Xml::closeElement( 'fieldset' ) .
                        Xml::closeElement( 'form' );
        }
@@ -162,7 +185,7 @@ class ProtectedPagesForm {
         */
        protected function getNamespaceMenu( $namespace = null ) {
                return "<span style='white-space: nowrap'>" .
-                       Xml::label( wfMsg( 'namespace' ), 'namespace' ) . '&nbsp;'
+                       Xml::label( wfMsg( 'namespace' ), 'namespace' ) . '&#160;'
                        . Xml::namespaceSelector( $namespace, '' ) . "</span>";
        }
 
@@ -173,7 +196,7 @@ class ProtectedPagesForm {
                return
                        Xml::checkLabel( wfMsg('protectedpages-indef'), 'indefonly', 'indefonly', $indefOnly ) . "\n";
        }
-       
+
        /**
         * @return string Formatted HTML
         */
@@ -190,11 +213,11 @@ class ProtectedPagesForm {
 
                return
                        Xml::radioLabel( wfMsg('minimum-size'), 'sizetype', 'min', 'wpmin', !$max ) .
-                       '&nbsp;' .
+                       '&#160;' .
                        Xml::radioLabel( wfMsg('maximum-size'), 'sizetype', 'max', 'wpmax', $max ) .
-                       '&nbsp;' .
+                       '&#160;' .
                        Xml::input( 'size', 9, $size, array( 'id' => 'wpsize' ) ) .
-                       '&nbsp;' .
+                       '&#160;' .
                        Xml::label( wfMsg('pagesize'), 'wpsize' );
        }
 
@@ -204,13 +227,11 @@ class ProtectedPagesForm {
         * @return string Formatted HTML
         */
        protected function getTypeMenu( $pr_type ) {
-               global $wgRestrictionTypes;
-
                $m = array(); // Temporary array
                $options = array();
 
                // First pass to load the log names
-               foreach( $wgRestrictionTypes as $type ) {
+               foreach( Title::getFilteredRestrictionTypes( true ) as $type ) {
                        $text = wfMsg("restriction-$type");
                        $m[$text] = $type;
                }
@@ -222,7 +243,7 @@ class ProtectedPagesForm {
                }
 
                return "<span style='white-space: nowrap'>" .
-                       Xml::label( wfMsg('restriction-type') , $this->IdType ) . '&nbsp;' .
+                       Xml::label( wfMsg('restriction-type') , $this->IdType ) . '&#160;' .
                        Xml::tags( 'select',
                                array( 'id' => $this->IdType, 'name' => $this->IdType ),
                                implode( "\n", $options ) ) . "</span>";
@@ -270,7 +291,7 @@ class ProtectedPagesPager extends AlphabeticPager {
        public $mForm, $mConds;
        private $type, $level, $namespace, $sizetype, $size, $indefonly;
 
-       function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0, 
+       function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0,
                $indefonly = false, $cascadeonly = false )
        {
                $this->mForm = $form;
@@ -282,13 +303,13 @@ class ProtectedPagesPager extends AlphabeticPager {
                $this->size = intval($size);
                $this->indefonly = (bool)$indefonly;
                $this->cascadeonly = (bool)$cascadeonly;
-               parent::__construct();
+               parent::__construct( $form->getContext() );
        }
 
        function getStartBody() {
                # Do a link batch query
                $lb = new LinkBatch;
-               while( $row = $this->mResult->fetchObject() ) {
+               foreach ( $this->mResult as $row ) {
                        $lb->add( $row->page_namespace, $row->page_title );
                }
                $lb->execute();
@@ -305,15 +326,16 @@ class ProtectedPagesPager extends AlphabeticPager {
                                'OR pr_expiry IS NULL)';
                $conds[] = 'page_id=pr_page';
                $conds[] = 'pr_type=' . $this->mDb->addQuotes( $this->type );
-               
+
                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'";
@@ -334,11 +356,3 @@ class ProtectedPagesPager extends AlphabeticPager {
                return 'pr_id';
        }
 }
-
-/**
- * Constructor
- */
-function wfSpecialProtectedpages() {
-       $ppForm = new ProtectedPagesForm();
-       $ppForm->showList();
-}