Introduce Language::getMessageKeysFor() and use it in ApiQueryAllmessages
[lhc/web/wiklou.git] / includes / specials / SpecialProtectedpages.php
index 7c6999b..2145108 100644 (file)
  *
  * @ingroup SpecialPage
  */
-class ProtectedPagesForm {
+class SpecialProtectedpages extends SpecialPage {
 
        protected $IdLevel = 'level';
        protected $IdType  = 'type';
 
-       public function showList( $msg = '' ) {
+       public function __construct() {
+               parent::__construct( 'Protectedpages' );
+       }
+
+       public function execute( $par ) {
                global $wgOut, $wgRequest;
 
-               if( $msg != "" ) {
-                       $wgOut->setSubtitle( $msg );
-               }
+               $this->setHeaders();
+               $this->outputHeader();
 
                // Purge expired entries on one in every 10 queries
                if( !mt_rand( 0, 10 ) ) {
@@ -73,14 +76,16 @@ class ProtectedPagesForm {
         * @return string Formatted <li> element
         */
        public function formatRow( $row ) {
-               global $wgUser, $wgLang, $wgContLang;
+               global $wgUser, $wgLang;
 
                wfProfileIn( __METHOD__ );
 
-               static $skin=null;
+               static $skin = null, $infinity = null;
 
-               if( is_null( $skin ) )
-                       $skin = $wgUser->getSkin();
+               if( is_null( $skin ) ){
+                       $skin = $this->getSkin();
+                       $infinity = wfGetDB( DB_SLAVE )->getInfinity();
+               }
 
                $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
                $link = $skin->link( $title );
@@ -95,20 +100,23 @@ class ProtectedPagesForm {
                        $description_items[] = wfMsg( 'protect-summary-cascade' );
                }
 
-               $expiry_description = '';
                $stxt = '';
 
-               if( $row->pr_expiry != 'infinity' && strlen($row->pr_expiry) ) {
-                       $expiry = Block::decodeExpiry( $row->pr_expiry );
+               $expiry = $wgLang->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',
+                               $wgLang->timeanddate( $expiry, true ),
+                               $wgLang->date( $expiry, true ),
+                               $wgLang->time( $expiry, true )
+                       );
 
                        $description_items[] = htmlspecialchars($expiry_description);
                }
 
                if(!is_null($size = $row->page_len)) {
-                       $stxt = $wgContLang->getDirMark() . ' ' . $skin->formatRevisionSize( $size );
+                       $stxt = $wgLang->getDirMark() . ' ' . $skin->formatRevisionSize( $size );
                }
 
                # Show a link to the change protection form for allowed users otherwise a link to the protection log
@@ -137,7 +145,7 @@ class ProtectedPagesForm {
                return Html::rawElement(
                        'li',
                        array(),
-                       wfSpecialList( $link . $stxt, $wgLang->commaList( $description_items ) ) . $changeProtection ) . "\n";
+                       wfSpecialList( $link . $stxt, $wgLang->commaList( $description_items ), false ) . $changeProtection ) . "\n";
        }
 
        /**
@@ -156,7 +164,7 @@ class ProtectedPagesForm {
                return Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
                        Xml::openElement( 'fieldset' ) .
                        Xml::element( 'legend', array(), wfMsg( 'protectedpages' ) ) .
-                       Xml::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" .
+                       Html::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" .
                        $this->getNamespaceMenu( $namespace ) . "&#160;\n" .
                        $this->getTypeMenu( $type ) . "&#160;\n" .
                        $this->getLevelMenu( $level ) . "&#160;\n" .
@@ -191,7 +199,7 @@ class ProtectedPagesForm {
                return
                        Xml::checkLabel( wfMsg('protectedpages-indef'), 'indefonly', 'indefonly', $indefOnly ) . "\n";
        }
-       
+
        /**
         * @return string Formatted HTML
         */
@@ -222,13 +230,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;
                }
@@ -288,7 +294,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;
@@ -306,13 +312,17 @@ class ProtectedPagesPager extends AlphabeticPager {
        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();
                return '';
        }
 
+       function getTitle() {
+               return SpecialPage::getTitleFor( 'Protectedpages' );
+       }
+
        function formatRow( $row ) {
                return $this->mForm->formatRow( $row );
        }
@@ -323,15 +333,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'";
@@ -352,11 +363,3 @@ class ProtectedPagesPager extends AlphabeticPager {
                return 'pr_id';
        }
 }
-
-/**
- * Constructor
- */
-function wfSpecialProtectedpages() {
-       $ppForm = new ProtectedPagesForm();
-       $ppForm->showList();
-}