r20571 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r20570‎ | r20571 | r20572 >
Date:09:43, 21 March 2007
Author:aaron
Status:old
Tags:
Comment:
*Add namespace filter to protectpages (bug 9326), type and level added too
Modified paths:
  • /trunk/phase3/includes/SpecialProtectedpages.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialProtectedpages.php
@@ -10,7 +10,7 @@
1111 */
1212 class ProtectedPagesForm {
1313 function showList( $msg = '' ) {
14 - global $wgOut;
 14+ global $wgOut, $wgRequest;
1515
1616 $wgOut->setPagetitle( wfMsg( "protectedpages" ) );
1717 if ( "" != $msg ) {
@@ -22,8 +22,14 @@
2323 Title::purgeExpiredRestrictions();
2424 }
2525
26 - $pager = new ProtectedPagesPager( $this );
 26+ $type = $wgRequest->getVal( 'type' );
 27+ $level = $wgRequest->getVal( 'level' );
 28+ $NS = $wgRequest->getIntOrNull( 'namespace' );
2729
 30+ $pager = new ProtectedPagesPager( $this, array(), $type, $level, $NS );
 31+
 32+ $wgOut->addHTML( $this->showOptions( $NS, $type, $level ) );
 33+
2834 if ( $pager->getNumRows() ) {
2935 $s = $pager->getNavigationBar();
3036 $s .= "<ul>" .
@@ -54,7 +60,7 @@
5561
5662 $description_items = array ();
5763
58 - $protType = wfMsg( 'restriction-level-' . $row->pr_level );
 64+ $protType = wfMsgHtml( 'restriction-level-' . $row->pr_level );
5965
6066 $description_items[] = $protType;
6167
@@ -72,6 +78,92 @@
7379
7480 return '<li>' . wfSpecialList( $link, implode( $description_items, ', ' ) ) . "</li>\n";
7581 }
 82+
 83+ /**
 84+ * @param $namespace int
 85+ * @param $type string
 86+ * @param $level string
 87+ * @private
 88+ */
 89+ function showOptions( $namespace, $type, $level ) {
 90+ global $wgScript;
 91+ $action = htmlspecialchars( $wgScript );
 92+ $title = SpecialPage::getTitleFor( 'ProtectedPages' );
 93+ $special = htmlspecialchars( $title->getPrefixedDBkey() );
 94+ return "<form action=\"$action\" method=\"get\">\n" .
 95+ '<fieldset>' .
 96+ Xml::element( 'legend', array(), wfMsg( 'protectedpages' ) ) .
 97+ Xml::hidden( 'title', $special ) . "\n" .
 98+ $this->getNamespaceMenu( $namespace ) . "\n" .
 99+ $this->getTypeMenu( $type ) . "\n" .
 100+ $this->getLevelMenu( $level ) . "\n" .
 101+ Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
 102+ "</fieldset></form>";
 103+ }
 104+
 105+ function getNamespaceMenu( $namespace=NULL ) {
 106+ return "<label for='namespace'>" . wfMsgHtml('namespace') . "</label>" . HTMLnamespaceselector($namespace, '');
 107+ }
 108+
 109+ /**
 110+ * @return string Formatted HTML
 111+ * @private
 112+ */
 113+ function getTypeMenu( $pr_type ) {
 114+ global $wgRestrictionTypes, $wgUser;
 115+
 116+ $out = "<select name='type'>\n";
 117+ $m = array(); // Temporary array
 118+
 119+ // First pass to load the log names
 120+ foreach( $wgRestrictionTypes as $type ) {
 121+ $text = wfMsgHtml("restriction-$type");
 122+ $m[$text] = $type;
 123+ }
 124+
 125+ // Second pass to sort by name
 126+ ksort($m);
 127+
 128+ // Third pass generates sorted XHTML content
 129+ foreach( $m as $text => $type ) {
 130+ $selected = ($type == $pr_type );
 131+ $out .= Xml::option( $text, $type, $selected ) . "\n";
 132+ }
 133+
 134+ $out .= '</select>';
 135+ return "<label for='type'>" . wfMsgHtml('restriction-type') . "</label>: " . $out;
 136+ }
 137+
 138+ /**
 139+ * @return string Formatted HTML
 140+ * @private
 141+ */
 142+ function getLevelMenu( $pr_level ) {
 143+ global $wgRestrictionLevels, $wgUser;
 144+
 145+ $out = "<select name='level'>\n";
 146+ $m = array( wfMsgHtml('restriction-level-all') => 0 ); // Temporary array
 147+
 148+ // First pass to load the log names
 149+ foreach( $wgRestrictionLevels as $type ) {
 150+ if ( $type !='' && $type !='*') {
 151+ $text = wfMsgHtml("restriction-level-$type");
 152+ $m[$text] = $type;
 153+ }
 154+ }
 155+
 156+ // Second pass to sort by name
 157+ ksort($m);
 158+
 159+ // Third pass generates sorted XHTML content
 160+ foreach( $m as $text => $type ) {
 161+ $selected = ($type == $pr_level );
 162+ $out .= Xml::option( $text, $type, $selected ) . "\n";
 163+ }
 164+
 165+ $out .= '</select>';
 166+ return "<label for='level'>" . wfMsgHtml('restriction-level') . "</label>: " . $out;
 167+ }
76168 }
77169
78170 /**
@@ -81,9 +173,12 @@
82174 class ProtectedPagesPager extends ReverseChronologicalPager {
83175 public $mForm, $mConds;
84176
85 - function __construct( $form, $conds = array() ) {
 177+ function __construct( $form, $conds = array(), $type, $level, $namespace ) {
86178 $this->mForm = $form;
87179 $this->mConds = $conds;
 180+ $this->type = ( $type ) ? $type : 'edit';
 181+ $this->level = $level;
 182+ $this->namespace = $namespace;
88183 parent::__construct();
89184 }
90185
@@ -112,9 +207,14 @@
113208 $conds = $this->mConds;
114209 $conds[] = 'pr_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() );
115210 $conds[] = 'page_id=pr_page';
 211+ $conds[] = 'pr_type=' . $this->mDb->addQuotes( $this->type );
 212+ if ( $this->level )
 213+ $conds[] = 'pr_level=' . $this->mDb->addQuotes( $this->level );
 214+ if ( $this->namespace )
 215+ $conds[] = 'page_namespace=' . $this->mDb->addQuotes( $this->namespace );
116216 return array(
117217 'tables' => array( 'page_restrictions', 'page' ),
118 - 'fields' => 'max(pr_id) AS pr_id,page_namespace,page_title,pr_level,pr_expiry',
 218+ 'fields' => 'max(pr_id) AS pr_id,page_namespace,page_title,pr_type,pr_level,pr_expiry',
119219 'conds' => $conds,
120220 'options' => array( 'GROUP BY' => 'page_namespace,page_title,pr_level,pr_expiry' ),
121221 );
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -1813,6 +1813,8 @@
18141814 'protect-summary-cascade' => 'cascading',
18151815 'protect-expiring' => 'expires $1 (UTC)',
18161816 'protect-cascade' => 'Cascading protection - protect any pages included in this page.',
 1817+'restriction-type' => 'Permission',
 1818+'restriction-level' => 'Restriction level',
18171819
18181820 # restrictions (nouns)
18191821 'restriction-edit' => 'Edit',
@@ -1821,6 +1823,7 @@
18221824 # restriction levels
18231825 'restriction-level-sysop' => 'full protected',
18241826 'restriction-level-autoconfirmed' => 'semi protected',
 1827+'restriction-level-all' => 'any level',
18251828
18261829
18271830 # Undelete