SpecialProtectedtitles.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. /**
  3. * @file
  4. * @ingroup SpecialPage
  5. */
  6. /**
  7. * @todo document
  8. * @ingroup SpecialPage
  9. */
  10. class ProtectedTitlesForm {
  11. protected $IdLevel = 'level';
  12. protected $IdType = 'type';
  13. function showList( $msg = '' ) {
  14. global $wgOut, $wgRequest;
  15. if ( "" != $msg ) {
  16. $wgOut->setSubtitle( $msg );
  17. }
  18. // Purge expired entries on one in every 10 queries
  19. if ( !mt_rand( 0, 10 ) ) {
  20. Title::purgeExpiredRestrictions();
  21. }
  22. $type = $wgRequest->getVal( $this->IdType );
  23. $level = $wgRequest->getVal( $this->IdLevel );
  24. $sizetype = $wgRequest->getVal( 'sizetype' );
  25. $size = $wgRequest->getIntOrNull( 'size' );
  26. $NS = $wgRequest->getIntOrNull( 'namespace' );
  27. $pager = new ProtectedTitlesPager( $this, array(), $type, $level, $NS, $sizetype, $size );
  28. $wgOut->addHTML( $this->showOptions( $NS, $type, $level, $sizetype, $size ) );
  29. if ( $pager->getNumRows() ) {
  30. $s = $pager->getNavigationBar();
  31. $s .= "<ul>" .
  32. $pager->getBody() .
  33. "</ul>";
  34. $s .= $pager->getNavigationBar();
  35. } else {
  36. $s = '<p>' . wfMsgHtml( 'protectedtitlesempty' ) . '</p>';
  37. }
  38. $wgOut->addHTML( $s );
  39. }
  40. /**
  41. * Callback function to output a restriction
  42. */
  43. function formatRow( $row ) {
  44. global $wgUser, $wgLang, $wgContLang;
  45. wfProfileIn( __METHOD__ );
  46. static $skin=null;
  47. if( is_null( $skin ) )
  48. $skin = $wgUser->getSkin();
  49. $title = Title::makeTitleSafe( $row->pt_namespace, $row->pt_title );
  50. $link = $skin->makeLinkObj( $title );
  51. $description_items = array ();
  52. $protType = wfMsgHtml( 'restriction-level-' . $row->pt_create_perm );
  53. $description_items[] = $protType;
  54. $expiry_description = ''; $stxt = '';
  55. if ( $row->pt_expiry != 'infinity' && strlen($row->pt_expiry) ) {
  56. $expiry = Block::decodeExpiry( $row->pt_expiry );
  57. $expiry_description = wfMsg( 'protect-expiring', $wgLang->timeanddate( $expiry ) , $wgLang->date( $expiry ) , $wgLang->time( $expiry ) );
  58. $description_items[] = $expiry_description;
  59. }
  60. wfProfileOut( __METHOD__ );
  61. return '<li>' . wfSpecialList( $link . $stxt, implode( $description_items, ', ' ) ) . "</li>\n";
  62. }
  63. /**
  64. * @param $namespace int
  65. * @param $type string
  66. * @param $level string
  67. * @param $minsize int
  68. * @private
  69. */
  70. function showOptions( $namespace, $type='edit', $level, $sizetype, $size ) {
  71. global $wgScript;
  72. $action = htmlspecialchars( $wgScript );
  73. $title = SpecialPage::getTitleFor( 'ProtectedTitles' );
  74. $special = htmlspecialchars( $title->getPrefixedDBkey() );
  75. return "<form action=\"$action\" method=\"get\">\n" .
  76. '<fieldset>' .
  77. Xml::element( 'legend', array(), wfMsg( 'protectedtitles' ) ) .
  78. Xml::hidden( 'title', $special ) . "&nbsp;\n" .
  79. $this->getNamespaceMenu( $namespace ) . "&nbsp;\n" .
  80. $this->getLevelMenu( $level ) . "&nbsp;\n" .
  81. "&nbsp;" . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
  82. "</fieldset></form>";
  83. }
  84. /**
  85. * Prepare the namespace filter drop-down; standard namespace
  86. * selector, sans the MediaWiki namespace
  87. *
  88. * @param mixed $namespace Pre-select namespace
  89. * @return string
  90. */
  91. function getNamespaceMenu( $namespace = null ) {
  92. return Xml::label( wfMsg( 'namespace' ), 'namespace' )
  93. . '&nbsp;'
  94. . Xml::namespaceSelector( $namespace, '' );
  95. }
  96. /**
  97. * @return string Formatted HTML
  98. * @private
  99. */
  100. function getLevelMenu( $pr_level ) {
  101. global $wgRestrictionLevels;
  102. $m = array( wfMsg('restriction-level-all') => 0 ); // Temporary array
  103. $options = array();
  104. // First pass to load the log names
  105. foreach( $wgRestrictionLevels as $type ) {
  106. if ( $type !='' && $type !='*') {
  107. $text = wfMsg("restriction-level-$type");
  108. $m[$text] = $type;
  109. }
  110. }
  111. // Is there only one level (aside from "all")?
  112. if( count($m) <= 2 ) {
  113. return '';
  114. }
  115. // Third pass generates sorted XHTML content
  116. foreach( $m as $text => $type ) {
  117. $selected = ($type == $pr_level );
  118. $options[] = Xml::option( $text, $type, $selected );
  119. }
  120. return
  121. Xml::label( wfMsg('restriction-level') , $this->IdLevel ) . '&nbsp;' .
  122. Xml::tags( 'select',
  123. array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ),
  124. implode( "\n", $options ) );
  125. }
  126. }
  127. /**
  128. * @todo document
  129. * @ingroup Pager
  130. */
  131. class ProtectedtitlesPager extends AlphabeticPager {
  132. public $mForm, $mConds;
  133. function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0 ) {
  134. $this->mForm = $form;
  135. $this->mConds = $conds;
  136. $this->level = $level;
  137. $this->namespace = $namespace;
  138. $this->size = intval($size);
  139. parent::__construct();
  140. }
  141. function getStartBody() {
  142. wfProfileIn( __METHOD__ );
  143. # Do a link batch query
  144. $this->mResult->seek( 0 );
  145. $lb = new LinkBatch;
  146. while ( $row = $this->mResult->fetchObject() ) {
  147. $lb->add( $row->pt_namespace, $row->pt_title );
  148. }
  149. $lb->execute();
  150. wfProfileOut( __METHOD__ );
  151. return '';
  152. }
  153. function formatRow( $row ) {
  154. return $this->mForm->formatRow( $row );
  155. }
  156. function getQueryInfo() {
  157. $conds = $this->mConds;
  158. $conds[] = 'pt_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() );
  159. if( $this->level )
  160. $conds['pt_create_perm'] = $this->level;
  161. if( !is_null($this->namespace) )
  162. $conds[] = 'pt_namespace=' . $this->mDb->addQuotes( $this->namespace );
  163. return array(
  164. 'tables' => 'protected_titles',
  165. 'fields' => 'pt_namespace,pt_title,pt_create_perm,pt_expiry,pt_timestamp',
  166. 'conds' => $conds
  167. );
  168. }
  169. function getIndexField() {
  170. return 'pt_timestamp';
  171. }
  172. }
  173. /**
  174. * Constructor
  175. */
  176. function wfSpecialProtectedtitles() {
  177. $ppForm = new ProtectedTitlesForm();
  178. $ppForm->showList();
  179. }