'submit' => 'HTMLSubmitField',
'hidden' => 'HTMLHiddenField',
'edittools' => 'HTMLEditTools',
+ 'namespaces' => 'HTMLNamespacesField',
+ 'restrictionlevels' => 'HTMLRestrictionLevelsField',
# HTMLTextField will output the correct type="" attribute automagically.
# There are about four zillion other HTML5 input types, like url, but
public function getFlatFields() {
return $this->mFlatFields;
}
+
+ /**
+ * Returns a value of a field
+ *
+ * @param $field string Field name
+ * @return mixed
+ */
+ public function getVal( $field ) {
+ return $this->mFieldData[$field];
+ }
}
/**
. "</div></td></tr>\n";
}
}
+
+/**
+ * Dropdown for namespaces
+ */
+class HTMLNamespacesField extends HTMLSelectField {
+ function __construct( $params ) {
+ global $wgContLang;
+ parent::__construct( $params );
+
+ $namespaces = $wgContLang->getFormattedNamespaces();
+
+ $options = array();
+ $options[ wfMessage( 'namespacesall' )->escaped() ] = ''; // TODO: Make an option
+
+ foreach ( $namespaces as $index => $name ) {
+ // Don't include things like SpecialPages
+ if ( $index < NS_MAIN ) {
+ continue;
+ }
+
+ if ( $index === 0 ) {
+ $name = wfMessage( 'blanknamespace' )->escaped();
+ }
+
+ $options[$name] = $index;
+ }
+
+ $this->mParams['options'] = $options;
+ }
+}
+
+/**
+ * Dropdown for protection levels
+ */
+class HTMLRestrictionLevelsField extends HTMLSelectField {
+
+ /**
+ * Should this field be displayed? If it hits a condition where it should
+ * be hidden, set this to false.
+ *
+ * @var bool
+ */
+ protected $enabled = true;
+
+ function __construct( $params ) {
+ global $wgRestrictionLevels;
+ parent::__construct( $params );
+
+ $options = array( wfMsg('restriction-level-all') => 0 ); // Temporary array
+
+ // First pass to load the level names
+ foreach( $wgRestrictionLevels as $type ) {
+ if ( $type != '' && $type != '*' ) {
+ $text = wfMsg("restriction-level-$type");
+ $options[$text] = $type;
+ }
+ }
+
+ // Is there only one level (aside from "all")?
+ if( count($options) <= 2 ) {
+ $this->enabled = false;
+ return;
+ }
+
+ $this->mParams['options'] = $options;
+ }
+
+ /**
+ * Returns false where
+ *
+ * @param $value
+ * @return String
+ */
+ function getTableRow( $value ) {
+ if ( $this->enabled ) {
+ return parent::getTableRow( $value );
+ }
+
+ return '';
+ }
+}
\ No newline at end of file
protected $mLastShown, $mFirstShown, $mPastTheEndIndex, $mDefaultQuery, $mNavigationBar;
+ /**
+ * HTMLForm object
+ *
+ * @var HTMLForm
+ */
+ protected $mHTMLForm;
+
/**
* Result object for the query. Warning: seek before use.
*
throw new MWException( __METHOD__ . " was called without any form fields being defined" );
}
- $form = new HTMLForm( $this->getHTMLFormFields(), $this->getContext() );
- $form->setMethod( 'get' );
- $form->setWrapperLegendMsg( $this->getHTMLFormLegend() );
- $form->setSubmitTextMsg( $this->getHTMLFormSubmit() );
- $this->addHiddenFields( $form );
- $this->modifyHTMLForm( $form );
- $form->prepareForm();
+ $this->mHTMLForm = new HTMLForm( $this->getHTMLFormFields(), $this->getContext() );
+ $this->mHTMLForm->setMethod( 'get' );
+ $this->mHTMLForm->setWrapperLegendMsg( $this->getHTMLFormLegend() );
+ $this->mHTMLForm->setSubmitTextMsg( $this->getHTMLFormSubmit() );
+ $this->addHiddenFields();
+ $this->modifyHTMLForm( $this->mHTMLForm );
+ $this->mHTMLForm->prepareForm();
- return $form->getHTML( '' );
+ return $this->mHTMLForm->getHTML( '' );
}
/**
* Adds hidden elements to forms for things that are in the query string.
* This is so that parameters like offset stick through form submissions
- *
- * @param HTMLForm $form
*/
- protected function addHiddenFields( HTMLForm $form ) {
+ protected function addHiddenFields() {
$query = $this->getRequest()->getQueryValues();
$fieldsBlacklist = array( 'title' );
- $fields = $form->getFlatFields();
+ $fields = $this->mHTMLForm->getFlatFields();
foreach ( $fields as $name => $field ) {
$fieldsBlacklist[] = $field->getName();
}
if ( in_array( $name, $fieldsBlacklist ) ) {
continue;
}
- $form->addHiddenField( $name, $value );
+ $this->mHTMLForm->addHiddenField( $name, $value );
}
}
*/
class SpecialProtectedtitles extends SpecialPage {
- protected $IdLevel = 'level';
- protected $IdType = 'type';
-
public function __construct() {
parent::__construct( 'Protectedtitles' );
}
Title::purgeExpiredRestrictions();
}
- $request = $this->getRequest();
- $type = $request->getVal( $this->IdType );
- $level = $request->getVal( $this->IdLevel );
- $sizetype = $request->getVal( 'sizetype' );
- $size = $request->getIntOrNull( 'size' );
- $NS = $request->getIntOrNull( 'namespace' );
-
- $pager = new ProtectedTitlesPager( $this, array(), $type, $level, $NS, $sizetype, $size );
-
- $this->getOutput()->addHTML( $this->showOptions( $NS, $type, $level ) );
+ $pager = new ProtectedTitlesPager( $this );
+ $this->getOutput()->addHTML( $pager->buildHTMLForm() );
if ( $pager->getNumRows() ) {
$s = $pager->getNavigationBar();
/**
* Callback function to output a restriction
*
+ * @param $row
* @return string
*/
function formatRow( $row ) {
return '<li>' . $lang->specialList( $link, implode( $description_items, ', ' ) ) . "</li>\n";
}
+}
+/**
+ * @todo document
+ * @ingroup Pager
+ */
+class ProtectedTitlesPager extends AlphabeticPager {
/**
- * @param $namespace Integer:
- * @param $type string
- * @param $level string
- * @private
+ * @var SpecialProtectedtitles
*/
- function showOptions( $namespace, $type='edit', $level ) {
- global $wgScript;
- $action = htmlspecialchars( $wgScript );
- $title = $this->getTitle();
- $special = htmlspecialchars( $title->getPrefixedDBkey() );
- return "<form action=\"$action\" method=\"get\">\n" .
- '<fieldset>' .
- Xml::element( 'legend', array(), wfMsg( 'protectedtitles' ) ) .
- Html::hidden( 'title', $special ) . " \n" .
- $this->getNamespaceMenu( $namespace ) . " \n" .
- $this->getLevelMenu( $level ) . " \n" .
- " " . Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" .
- "</fieldset></form>";
- }
+ public $mForm;
/**
- * Prepare the namespace filter drop-down; standard namespace
- * selector, sans the MediaWiki namespace
- *
- * @param $namespace Mixed: pre-select namespace
- * @return string
+ * @var array
*/
- function getNamespaceMenu( $namespace = null ) {
- return Xml::label( wfMsg( 'namespace' ), 'namespace' )
- . ' '
- . Xml::namespaceSelector( $namespace, '' );
- }
+ public $mConds;
/**
- * @return string Formatted HTML
- * @private
+ * @param $form SpecialProtectedtitles
+ * @param $conds array
*/
- function getLevelMenu( $pr_level ) {
- global $wgRestrictionLevels;
-
- $m = array( wfMsg('restriction-level-all') => 0 ); // Temporary array
- $options = array();
-
- // First pass to load the log names
- foreach( $wgRestrictionLevels as $type ) {
- if ( $type !='' && $type !='*') {
- $text = wfMsg("restriction-level-$type");
- $m[$text] = $type;
- }
- }
- // Is there only one level (aside from "all")?
- if( count($m) <= 2 ) {
- return '';
- }
- // Third pass generates sorted XHTML content
- foreach( $m as $text => $type ) {
- $selected = ($type == $pr_level );
- $options[] = Xml::option( $text, $type, $selected );
- }
-
- return
- Xml::label( wfMsg('restriction-level') , $this->IdLevel ) . ' ' .
- Xml::tags( 'select',
- array( 'id' => $this->IdLevel, 'name' => $this->IdLevel ),
- implode( "\n", $options ) );
- }
-}
-
-/**
- * @todo document
- * @ingroup Pager
- */
-class ProtectedTitlesPager extends AlphabeticPager {
- public $mForm, $mConds;
-
- function __construct( $form, $conds = array(), $type, $level, $namespace, $sizetype='', $size=0 ) {
+ function __construct( $form, $conds = array() ) {
$this->mForm = $form;
$this->mConds = $conds;
- $this->level = $level;
- $this->namespace = $namespace;
- $this->size = intval($size);
parent::__construct( $form->getContext() );
}
function getQueryInfo() {
$conds = $this->mConds;
$conds[] = 'pt_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() );
- if( $this->level )
- $conds['pt_create_perm'] = $this->level;
- if( !is_null($this->namespace) )
- $conds[] = 'pt_namespace=' . $this->mDb->addQuotes( $this->namespace );
+
+ if ( $this->mHTMLForm->getVal( 'Level' ) ) {
+ $conds['pt_create_perm'] = $this->mHTMLForm->getVal( 'Level' );
+ }
+ if ( $this->mHTMLForm->getVal( 'Namespace' ) !== '' ) {
+ $conds['pt_namespace'] = $this->mHTMLForm->getVal( 'Namespace' );
+ }
+
return array(
'tables' => 'protected_titles',
'fields' => 'pt_namespace,pt_title,pt_create_perm,pt_expiry,pt_timestamp',
function getIndexField() {
return 'pt_timestamp';
}
+
+ protected function getHTMLFormFields() {
+ return array(
+ 'Namespace' => array(
+ 'type' => 'namespaces',
+ 'label-message' => 'namespace',
+ ),
+ 'Level' => array(
+ 'type' => 'restrictionlevels',
+ 'label-message' => 'restriction-level',
+ ),
+ );
+ }
+
+ protected function getHTMLFormSubmit() {
+ return 'allpagessubmit';
+ }
+
+ protected function getHTMLFormLegend() {
+ return 'protectedtitles';
+ }
+
+
}