[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/specials/ -> SpecialProtectedtitles.php (source)

   1  <?php
   2  /**
   3   * Implements Special:Protectedtitles
   4   *
   5   * This program is free software; you can redistribute it and/or modify
   6   * it under the terms of the GNU General Public License as published by
   7   * the Free Software Foundation; either version 2 of the License, or
   8   * (at your option) any later version.
   9   *
  10   * This program is distributed in the hope that it will be useful,
  11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13   * GNU General Public License for more details.
  14   *
  15   * You should have received a copy of the GNU General Public License along
  16   * with this program; if not, write to the Free Software Foundation, Inc.,
  17   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18   * http://www.gnu.org/copyleft/gpl.html
  19   *
  20   * @file
  21   * @ingroup SpecialPage
  22   */
  23  
  24  /**
  25   * A special page that list protected titles from creation
  26   *
  27   * @ingroup SpecialPage
  28   */
  29  class SpecialProtectedtitles extends SpecialPage {
  30      protected $IdLevel = 'level';
  31      protected $IdType = 'type';
  32  
  33  	public function __construct() {
  34          parent::__construct( 'Protectedtitles' );
  35      }
  36  
  37  	function execute( $par ) {
  38          $this->setHeaders();
  39          $this->outputHeader();
  40  
  41          // Purge expired entries on one in every 10 queries
  42          if ( !mt_rand( 0, 10 ) ) {
  43              Title::purgeExpiredRestrictions();
  44          }
  45  
  46          $request = $this->getRequest();
  47          $type = $request->getVal( $this->IdType );
  48          $level = $request->getVal( $this->IdLevel );
  49          $sizetype = $request->getVal( 'sizetype' );
  50          $size = $request->getIntOrNull( 'size' );
  51          $NS = $request->getIntOrNull( 'namespace' );
  52  
  53          $pager = new ProtectedTitlesPager( $this, array(), $type, $level, $NS, $sizetype, $size );
  54  
  55          $this->getOutput()->addHTML( $this->showOptions( $NS, $type, $level ) );
  56  
  57          if ( $pager->getNumRows() ) {
  58              $this->getOutput()->addHTML(
  59                  $pager->getNavigationBar() .
  60                      '<ul>' . $pager->getBody() . '</ul>' .
  61                      $pager->getNavigationBar()
  62              );
  63          } else {
  64              $this->getOutput()->addWikiMsg( 'protectedtitlesempty' );
  65          }
  66      }
  67  
  68      /**
  69       * Callback function to output a restriction
  70       *
  71       * @param object $row Database row
  72       * @return string
  73       */
  74  	function formatRow( $row ) {
  75          wfProfileIn( __METHOD__ );
  76  
  77          static $infinity = null;
  78  
  79          if ( is_null( $infinity ) ) {
  80              $infinity = wfGetDB( DB_SLAVE )->getInfinity();
  81          }
  82  
  83          $title = Title::makeTitleSafe( $row->pt_namespace, $row->pt_title );
  84          if ( !$title ) {
  85              wfProfileOut( __METHOD__ );
  86  
  87              return Html::rawElement(
  88                  'li',
  89                  array(),
  90                  Html::element(
  91                      'span',
  92                      array( 'class' => 'mw-invalidtitle' ),
  93                      Linker::getInvalidTitleDescription(
  94                          $this->getContext(),
  95                          $row->pt_namespace,
  96                          $row->pt_title
  97                      )
  98                  )
  99              ) . "\n";
 100          }
 101  
 102          $link = Linker::link( $title );
 103          $description_items = array();
 104          // Messages: restriction-level-sysop, restriction-level-autoconfirmed
 105          $protType = $this->msg( 'restriction-level-' . $row->pt_create_perm )->escaped();
 106          $description_items[] = $protType;
 107          $lang = $this->getLanguage();
 108          $expiry = strlen( $row->pt_expiry ) ?
 109              $lang->formatExpiry( $row->pt_expiry, TS_MW ) :
 110              $infinity;
 111  
 112          if ( $expiry != $infinity ) {
 113              $user = $this->getUser();
 114              $description_items[] = $this->msg(
 115                  'protect-expiring-local',
 116                  $lang->userTimeAndDate( $expiry, $user ),
 117                  $lang->userDate( $expiry, $user ),
 118                  $lang->userTime( $expiry, $user )
 119              )->escaped();
 120          }
 121  
 122          wfProfileOut( __METHOD__ );
 123  
 124          // @todo i18n: This should use a comma separator instead of a hard coded comma, right?
 125          return '<li>' . $lang->specialList( $link, implode( $description_items, ', ' ) ) . "</li>\n";
 126      }
 127  
 128      /**
 129       * @param int $namespace
 130       * @param string $type
 131       * @param string $level
 132       * @return string
 133       * @private
 134       */
 135  	function showOptions( $namespace, $type = 'edit', $level ) {
 136          $action = htmlspecialchars( wfScript() );
 137          $title = $this->getPageTitle();
 138          $special = htmlspecialchars( $title->getPrefixedDBkey() );
 139  
 140          return "<form action=\"$action\" method=\"get\">\n" .
 141              '<fieldset>' .
 142              Xml::element( 'legend', array(), $this->msg( 'protectedtitles' )->text() ) .
 143              Html::hidden( 'title', $special ) . "&#160;\n" .
 144              $this->getNamespaceMenu( $namespace ) . "&#160;\n" .
 145              $this->getLevelMenu( $level ) . "&#160;\n" .
 146              "&#160;" . Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) . "\n" .
 147              "</fieldset></form>";
 148      }
 149  
 150      /**
 151       * Prepare the namespace filter drop-down; standard namespace
 152       * selector, sans the MediaWiki namespace
 153       *
 154       * @param string|null $namespace Pre-select namespace
 155       * @return string
 156       */
 157  	function getNamespaceMenu( $namespace = null ) {
 158          return Html::namespaceSelector(
 159              array(
 160                  'selected' => $namespace,
 161                  'all' => '',
 162                  'label' => $this->msg( 'namespace' )->text()
 163              ), array(
 164                  'name' => 'namespace',
 165                  'id' => 'namespace',
 166                  'class' => 'namespaceselector',
 167              )
 168          );
 169      }
 170  
 171      /**
 172       * @param string $pr_level Determines which option is selected as default
 173       * @return string Formatted HTML
 174       * @private
 175       */
 176  	function getLevelMenu( $pr_level ) {
 177          // Temporary array
 178          $m = array( $this->msg( 'restriction-level-all' )->text() => 0 );
 179          $options = array();
 180  
 181          // First pass to load the log names
 182          foreach ( $this->getConfig()->get( 'RestrictionLevels' ) as $type ) {
 183              if ( $type != '' && $type != '*' ) {
 184                  // Messages: restriction-level-sysop, restriction-level-autoconfirmed
 185                  $text = $this->msg( "restriction-level-$type" )->text();
 186                  $m[$text] = $type;
 187              }
 188          }
 189  
 190          // Is there only one level (aside from "all")?
 191          if ( count( $m ) <= 2 ) {
 192              return '';
 193          }
 194          // Third pass generates sorted XHTML content
 195          foreach ( $m as $text => $type ) {
 196              $selected = ( $type == $pr_level );
 197              $options[] = Xml::option( $text, $type, $selected );
 198          }
 199  
 200          return Xml::label( $this->msg( 'restriction-level' )->text(), $this->IdLevel ) . '&#160;' .
 201              Xml::tags( 'select',
 202                  array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ),
 203                  implode( "\n", $options ) );
 204      }
 205  
 206  	protected function getGroupName() {
 207          return 'maintenance';
 208      }
 209  }
 210  
 211  /**
 212   * @todo document
 213   * @ingroup Pager
 214   */
 215  class ProtectedTitlesPager extends AlphabeticPager {
 216      public $mForm, $mConds;
 217  
 218  	function __construct( $form, $conds = array(), $type, $level, $namespace,
 219          $sizetype = '', $size = 0
 220      ) {
 221          $this->mForm = $form;
 222          $this->mConds = $conds;
 223          $this->level = $level;
 224          $this->namespace = $namespace;
 225          $this->size = intval( $size );
 226          parent::__construct( $form->getContext() );
 227      }
 228  
 229  	function getStartBody() {
 230          wfProfileIn( __METHOD__ );
 231          # Do a link batch query
 232          $this->mResult->seek( 0 );
 233          $lb = new LinkBatch;
 234  
 235          foreach ( $this->mResult as $row ) {
 236              $lb->add( $row->pt_namespace, $row->pt_title );
 237          }
 238  
 239          $lb->execute();
 240          wfProfileOut( __METHOD__ );
 241  
 242          return '';
 243      }
 244  
 245      /**
 246       * @return Title
 247       */
 248  	function getTitle() {
 249          return $this->mForm->getTitle();
 250      }
 251  
 252  	function formatRow( $row ) {
 253          return $this->mForm->formatRow( $row );
 254      }
 255  
 256      /**
 257       * @return array
 258       */
 259  	function getQueryInfo() {
 260          $conds = $this->mConds;
 261          $conds[] = 'pt_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() );
 262          if ( $this->level ) {
 263              $conds['pt_create_perm'] = $this->level;
 264          }
 265  
 266          if ( !is_null( $this->namespace ) ) {
 267              $conds[] = 'pt_namespace=' . $this->mDb->addQuotes( $this->namespace );
 268          }
 269  
 270          return array(
 271              'tables' => 'protected_titles',
 272              'fields' => array( 'pt_namespace', 'pt_title', 'pt_create_perm',
 273                  'pt_expiry', 'pt_timestamp' ),
 274              'conds' => $conds
 275          );
 276      }
 277  
 278  	function getIndexField() {
 279          return 'pt_timestamp';
 280      }
 281  }


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1