Moved some of the functionality from mediawiki.legacy.prefs into mediawiki.specials...
[lhc/web/wiklou.git] / includes / specials / SpecialProtectedpages.php
index 58deff1..2b01412 100644 (file)
@@ -1,28 +1,48 @@
 <?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 = '' ) {
+       public function __construct() {
+               parent::__construct( 'Protectedpages' );
+       }
+
+       public function execute( $par ) {
                global $wgOut, $wgRequest;
 
-               $wgOut->setPagetitle( wfMsg( "protectedpages" ) );
-               if ( "" != $msg ) {
-                       $wgOut->setSubtitle( $msg );
-               }
+               $this->setHeaders();
+               $this->outputHeader();
 
                // Purge expired entries on one in every 10 queries
-               if ( !mt_rand( 0, 10 ) ) {
+               if( !mt_rand( 0, 10 ) ) {
                        Title::purgeExpiredRestrictions();
                }
 
@@ -32,12 +52,13 @@ class ProtectedPagesForm {
                $size = $wgRequest->getIntOrNull( 'size' );
                $NS = $wgRequest->getIntOrNull( 'namespace' );
                $indefOnly = $wgRequest->getBool( 'indefonly' ) ? 1 : 0;
+               $cascadeOnly = $wgRequest->getBool('cascadeonly') ? 1 : 0;
 
-               $pager = new ProtectedPagesPager( $this, array(), $type, $level, $NS, $sizetype, $size, $indefOnly );
+               $pager = new ProtectedPagesPager( $this, array(), $type, $level, $NS, $sizetype, $size, $indefOnly, $cascadeOnly );
 
-               $wgOut->addHTML( $this->showOptions( $NS, $type, $level, $sizetype, $size, $indefOnly ) );
+               $wgOut->addHTML( $this->showOptions( $NS, $type, $level, $sizetype, $size, $indefOnly, $cascadeOnly ) );
 
-               if ( $pager->getNumRows() ) {
+               if( $pager->getNumRows() ) {
                        $s = $pager->getNavigationBar();
                        $s .= "<ul>" .
                                $pager->getBody() .
@@ -65,7 +86,7 @@ class ProtectedPagesForm {
                        $skin = $wgUser->getSkin();
 
                $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
-               $link = $skin->makeLinkObj( $title );
+               $link = $skin->link( $title );
 
                $description_items = array ();
 
@@ -73,69 +94,82 @@ class ProtectedPagesForm {
 
                $description_items[] = $protType;
 
-               if ( $row->pr_cascade ) {
+               if( $row->pr_cascade ) {
                        $description_items[] = wfMsg( 'protect-summary-cascade' );
                }
 
                $expiry_description = '';
                $stxt = '';
 
-               if ( $row->pr_expiry != 'infinity' && strlen($row->pr_expiry) ) {
+               if( $row->pr_expiry != 'infinity' && strlen($row->pr_expiry) ) {
                        $expiry = Block::decodeExpiry( $row->pr_expiry );
 
-                       $expiry_description = wfMsgForContent( 'protect-expiring', $wgLang->timeanddate( $expiry ) );
+                       $expiry_description = wfMsg( 'protect-expiring' , $wgLang->timeanddate( $expiry ) , 
+                               $wgLang->date( $expiry ) , $wgLang->time( $expiry ) );
 
-                       $description_items[] = $expiry_description;
+                       $description_items[] = htmlspecialchars($expiry_description);
                }
 
-               if (!is_null($size = $row->page_len)) {
-                       if ($size == 0) {
-                               $stxt = wfMsg('historyempty');
-                       } else {
-                               $stxt = wfMsg('nbytes', $wgLang->formatNum( $size ) );
-                               $stxt = "($stxt)";
-                       }
-                       $stxt = htmlspecialchars( $stxt );
-                       $stxt = $wgContLang->getDirMark() . $stxt;
+               if(!is_null($size = $row->page_len)) {
+                       $stxt = $wgContLang->getDirMark() . ' ' . $skin->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->makeKnownLinkObj( $title, wfMsgHtml( 'protect_change' ), 'action=unprotect' ) . ')';
+                       $changeProtection = ' (' . $skin->linkKnown(
+                               $title,
+                               wfMsgHtml( 'protect_change' ),
+                               array(),
+                               array( 'action' => 'unprotect' )
+                       ) . ')';
                } else {
                        $ltitle = SpecialPage::getTitleFor( 'Log' );
-                       $changeProtection = ' (' . $skin->makeKnownLinkObj( $ltitle, wfMsgHtml( 'protectlogpage' ), 'type=protect&page=' . $title->getPrefixedUrl() ) . ')';
+                       $changeProtection = ' (' . $skin->linkKnown(
+                               $ltitle,
+                               wfMsgHtml( 'protectlogpage' ),
+                               array(),
+                               array(
+                                       'type' => 'protect',
+                                       'page' => $title->getPrefixedText()
+                               )
+                       ) . ')';
                }
 
                wfProfileOut( __METHOD__ );
 
-               return '<li>' . wfSpecialList( $link . $stxt, implode( $description_items, ', ' ) ) . $changeProtection . "</li>\n";
+               return Html::rawElement(
+                       'li',
+                       array(),
+                       wfSpecialList( $link . $stxt, $wgLang->commaList( $description_items ) ) . $changeProtection ) . "\n";
        }
 
        /**
-        * @param $namespace int
-        * @param $type string
-        * @param $level string
-        * @param $minsize int
-        * @param $indefOnly bool
-        * @return string Input form
-        * @private
+        * @param $namespace Integer
+        * @param $type String: restriction type
+        * @param $level String: restriction level
+        * @param $sizetype String: "min" or "max"
+        * @param $size Integer
+        * @param $indefOnly Boolean: only indefinie protection
+        * @param $cascadeOnly Boolean: only cascading protection
+        * @return String: input form
         */
-       protected function showOptions( $namespace, $type='edit', $level, $sizetype, $size, $indefOnly ) {
+       protected function showOptions( $namespace, $type='edit', $level, $sizetype, $size, $indefOnly, $cascadeOnly ) {
                global $wgScript;
-               $title = SpecialPage::getTitleFor( 'ProtectedPages' );
+               $title = SpecialPage::getTitleFor( 'Protectedpages' );
                return Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) .
                        Xml::openElement( 'fieldset' ) .
                        Xml::element( 'legend', array(), wfMsg( 'protectedpages' ) ) .
-                       Xml::hidden( 'title', $title->getPrefixedDBkey() ) . "&nbsp;\n" .
-                       $this->getNamespaceMenu( $namespace ) . "&nbsp;\n" .
-                       $this->getTypeMenu( $type ) . "&nbsp;\n" .
-                       $this->getLevelMenu( $level ) . "&nbsp;\n" .
-                       "<br /><span style='white-space: nowrap'>&nbsp;&nbsp;" .
-                       $this->getExpiryCheck( $indefOnly ) . "&nbsp;\n" .
-                       $this->getSizeLimit( $sizetype, $size ) . "&nbsp;\n" .
+                       Xml::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 ) . "&#160;\n" .
+                       $this->getCascadeCheck( $cascadeOnly ) . "&#160;\n" .
+                       "</span><br /><span style='white-space: nowrap'>" .
+                       $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' );
        }
@@ -144,12 +178,12 @@ class ProtectedPagesForm {
         * Prepare the namespace filter drop-down; standard namespace
         * selector, sans the MediaWiki namespace
         *
-        * @param mixed $namespace Pre-select namespace
-        * @return string
+        * @param $namespace Mixed: pre-select namespace
+        * @return String
         */
        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>";
        }
 
@@ -160,6 +194,14 @@ class ProtectedPagesForm {
                return
                        Xml::checkLabel( wfMsg('protectedpages-indef'), 'indefonly', 'indefonly', $indefOnly ) . "\n";
        }
+       
+       /**
+        * @return string Formatted HTML
+        */
+       protected function getCascadeCheck( $cascadeOnly ) {
+               return
+                       Xml::checkLabel( wfMsg('protectedpages-cascade'), 'cascadeonly', 'cascadeonly', $cascadeOnly ) . "\n";
+       }
 
        /**
         * @return string Formatted HTML
@@ -169,15 +211,17 @@ 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' );
        }
 
        /**
+        * Creates the input label of the restriction type
+        * @param $pr_type string Protection type
         * @return string Formatted HTML
         */
        protected function getTypeMenu( $pr_type ) {
@@ -199,13 +243,15 @@ 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>";
        }
 
        /**
+        * Creates the input label of the restriction level
+        * @param $pr_level string Protection level
         * @return string Formatted HTML
         */
        protected function getLevelMenu( $pr_level ) {
@@ -216,7 +262,8 @@ class ProtectedPagesForm {
 
                // First pass to load the log names
                foreach( $wgRestrictionLevels as $type ) {
-                       if ( $type !='' && $type !='*') {
+                       // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed'
+                       if( $type !='' && $type !='*') {
                                $text = wfMsg("restriction-level-$type");
                                $m[$text] = $type;
                        }
@@ -228,11 +275,11 @@ class ProtectedPagesForm {
                        $options[] = Xml::option( $text, $type, $selected );
                }
 
-               return
-                       Xml::label( wfMsg('restriction-level') , $this->IdLevel ) . '&nbsp;' .
+               return "<span style='white-space: nowrap'>" .
+                       Xml::label( wfMsg( 'restriction-level' ) , $this->IdLevel ) . ' ' .
                        Xml::tags( 'select',
                                array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ),
-                               implode( "\n", $options ) );
+                               implode( "\n", $options ) ) . "</span>";
        }
 }
 
@@ -244,7 +291,9 @@ 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, $indefonly=false ) {
+       function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0, 
+               $indefonly = false, $cascadeonly = false )
+       {
                $this->mForm = $form;
                $this->mConds = $conds;
                $this->type = ( $type ) ? $type : 'edit';
@@ -253,19 +302,17 @@ class ProtectedPagesPager extends AlphabeticPager {
                $this->sizetype = $sizetype;
                $this->size = intval($size);
                $this->indefonly = (bool)$indefonly;
+               $this->cascadeonly = (bool)$cascadeonly;
                parent::__construct();
        }
 
        function getStartBody() {
-               wfProfileIn( __METHOD__ );
                # Do a link batch query
                $lb = new LinkBatch;
                while( $row = $this->mResult->fetchObject() ) {
                        $lb->add( $row->page_namespace, $row->page_title );
                }
                $lb->execute();
-
-               wfProfileOut( __METHOD__ );
                return '';
        }
 
@@ -275,10 +322,11 @@ class ProtectedPagesPager extends AlphabeticPager {
 
        function getQueryInfo() {
                $conds = $this->mConds;
-               $conds[] = 'pr_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() );
+               $conds[] = '(pr_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() ) .
+                               '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' ) {
@@ -288,6 +336,9 @@ class ProtectedPagesPager extends AlphabeticPager {
                if( $this->indefonly ) {
                        $conds[] = "pr_expiry = 'infinity' OR pr_expiry IS NULL";
                }
+               if( $this->cascadeonly ) {
+                       $conds[] = "pr_cascade = '1'";
+               }
 
                if( $this->level )
                        $conds[] = 'pr_level=' . $this->mDb->addQuotes( $this->level );
@@ -304,13 +355,3 @@ class ProtectedPagesPager extends AlphabeticPager {
                return 'pr_id';
        }
 }
-
-/**
- * Constructor
- */
-function wfSpecialProtectedpages() {
-
-       $ppForm = new ProtectedPagesForm();
-
-       $ppForm->showList();
-}