diff options
Diffstat (limited to 'includes/specials/SpecialProtectedpages.php')
-rw-r--r-- | includes/specials/SpecialProtectedpages.php | 406 |
1 files changed, 266 insertions, 140 deletions
diff --git a/includes/specials/SpecialProtectedpages.php b/includes/specials/SpecialProtectedpages.php index 3de6ea24..0ba73857 100644 --- a/includes/specials/SpecialProtectedpages.php +++ b/includes/specials/SpecialProtectedpages.php @@ -27,7 +27,6 @@ * @ingroup SpecialPage */ class SpecialProtectedpages extends SpecialPage { - protected $IdLevel = 'level'; protected $IdType = 'type'; @@ -38,6 +37,7 @@ class SpecialProtectedpages extends SpecialPage { public function execute( $par ) { $this->setHeaders(); $this->outputHeader(); + $this->getOutput()->addModuleStyles( 'mediawiki.special' ); // Purge expired entries on one in every 10 queries if ( !mt_rand( 0, 10 ) ) { @@ -52,6 +52,7 @@ class SpecialProtectedpages extends SpecialPage { $ns = $request->getIntOrNull( 'namespace' ); $indefOnly = $request->getBool( 'indefonly' ) ? 1 : 0; $cascadeOnly = $request->getBool( 'cascadeonly' ) ? 1 : 0; + $noRedirect = $request->getBool( 'noredirect' ) ? 1 : 0; $pager = new ProtectedPagesPager( $this, @@ -62,7 +63,8 @@ class SpecialProtectedpages extends SpecialPage { $sizetype, $size, $indefOnly, - $cascadeOnly + $cascadeOnly, + $noRedirect ); $this->getOutput()->addHTML( $this->showOptions( @@ -72,137 +74,34 @@ class SpecialProtectedpages extends SpecialPage { $sizetype, $size, $indefOnly, - $cascadeOnly + $cascadeOnly, + $noRedirect ) ); if ( $pager->getNumRows() ) { - $this->getOutput()->addHTML( - $pager->getNavigationBar() . - '<ul>' . $pager->getBody() . '</ul>' . - $pager->getNavigationBar() - ); + $this->getOutput()->addParserOutputContent( $pager->getFullOutput() ); } else { $this->getOutput()->addWikiMsg( 'protectedpagesempty' ); } } /** - * Callback function to output a restriction - * @param Title $row Protected title - * @return string Formatted "<li>" element - */ - public function formatRow( $row ) { - wfProfileIn( __METHOD__ ); - - static $infinity = null; - - if ( is_null( $infinity ) ) { - $infinity = wfGetDB( DB_SLAVE )->getInfinity(); - } - - $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title ); - if ( !$title ) { - wfProfileOut( __METHOD__ ); - - return Html::rawElement( - 'li', - array(), - Html::element( - 'span', - array( 'class' => 'mw-invalidtitle' ), - Linker::getInvalidTitleDescription( - $this->getContext(), - $row->page_namespace, - $row->page_title - ) - ) - ) . "\n"; - } - - $link = Linker::link( $title ); - - $description_items = array(); - - // Messages: restriction-level-sysop, restriction-level-autoconfirmed - $protType = $this->msg( 'restriction-level-' . $row->pr_level )->escaped(); - - $description_items[] = $protType; - - if ( $row->pr_cascade ) { - $description_items[] = $this->msg( 'protect-summary-cascade' )->text(); - } - - $stxt = ''; - $lang = $this->getLanguage(); - - $expiry = $lang->formatExpiry( $row->pr_expiry, TS_MW ); - if ( $expiry != $infinity ) { - $user = $this->getUser(); - $description_items[] = $this->msg( - 'protect-expiring-local', - $lang->userTimeAndDate( $expiry, $user ), - $lang->userDate( $expiry, $user ), - $lang->userTime( $expiry, $user ) - )->escaped(); - } - - if ( !is_null( $size = $row->page_len ) ) { - $stxt = $lang->getDirMark() . ' ' . Linker::formatRevisionSize( $size ); - } - - // Show a link to the change protection form for allowed users otherwise - // a link to the protection log - if ( $this->getUser()->isAllowed( 'protect' ) ) { - $changeProtection = Linker::linkKnown( - $title, - $this->msg( 'protect_change' )->escaped(), - array(), - array( 'action' => 'unprotect' ) - ); - } else { - $ltitle = SpecialPage::getTitleFor( 'Log' ); - $changeProtection = Linker::linkKnown( - $ltitle, - $this->msg( 'protectlogpage' )->escaped(), - array(), - array( - 'type' => 'protect', - 'page' => $title->getPrefixedText() - ) - ); - } - - $changeProtection = ' ' . $this->msg( 'parentheses' )->rawParams( $changeProtection ) - ->escaped(); - - wfProfileOut( __METHOD__ ); - - return Html::rawElement( - 'li', - array(), - $lang->specialList( $link . $stxt, $lang->commaList( $description_items ), false ) . - $changeProtection - ) . "\n"; - } - - /** - * @param $namespace Integer - * @param string $type restriction type - * @param string $level restriction level + * @param int $namespace + * @param string $type Restriction type + * @param string $level Restriction level * @param string $sizetype "min" or "max" - * @param $size Integer - * @param $indefOnly Boolean: only indefinie protection - * @param $cascadeOnly Boolean: only cascading protection - * @return String: input form + * @param int $size + * @param bool $indefOnly Only indefinite protection + * @param bool $cascadeOnly Only cascading protection + * @param bool $noRedirect Don't show redirects + * @return string Input form */ protected function showOptions( $namespace, $type = 'edit', $level, $sizetype, - $size, $indefOnly, $cascadeOnly + $size, $indefOnly, $cascadeOnly, $noRedirect ) { - global $wgScript; + $title = $this->getPageTitle(); - $title = $this->getTitle(); - - return Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) . + return Xml::openElement( 'form', array( 'method' => 'get', 'action' => wfScript() ) ) . Xml::openElement( 'fieldset' ) . Xml::element( 'legend', array(), $this->msg( 'protectedpages' )->text() ) . Html::hidden( 'title', $title->getPrefixedDBkey() ) . "\n" . @@ -212,6 +111,7 @@ class SpecialProtectedpages extends SpecialPage { "<br /><span style='white-space: nowrap'>" . $this->getExpiryCheck( $indefOnly ) . " \n" . $this->getCascadeCheck( $cascadeOnly ) . " \n" . + $this->getRedirectCheck( $noRedirect ) . " \n" . "</span><br /><span style='white-space: nowrap'>" . $this->getSizeLimit( $sizetype, $size ) . " \n" . "</span>" . @@ -224,8 +124,8 @@ class SpecialProtectedpages extends SpecialPage { * Prepare the namespace filter drop-down; standard namespace * selector, sans the MediaWiki namespace * - * @param $namespace Mixed: pre-select namespace - * @return String + * @param string|null $namespace Pre-select namespace + * @return string */ protected function getNamespaceMenu( $namespace = null ) { return Html::rawElement( 'span', array( 'style' => 'white-space: nowrap;' ), @@ -270,6 +170,19 @@ class SpecialProtectedpages extends SpecialPage { } /** + * @param bool $noRedirect + * @return string Formatted HTML + */ + protected function getRedirectCheck( $noRedirect ) { + return Xml::checkLabel( + $this->msg( 'protectedpages-noredirect' )->text(), + 'noredirect', + 'noredirect', + $noRedirect + ) . "\n"; + } + + /** * @param string $sizetype "min" or "max" * @param mixed $size * @return string Formatted HTML @@ -300,7 +213,7 @@ class SpecialProtectedpages extends SpecialPage { /** * Creates the input label of the restriction type - * @param $pr_type string Protection type + * @param string $pr_type Protection type * @return string Formatted HTML */ protected function getTypeMenu( $pr_type ) { @@ -329,18 +242,16 @@ class SpecialProtectedpages extends SpecialPage { /** * Creates the input label of the restriction level - * @param $pr_level string Protection level + * @param string $pr_level Protection level * @return string Formatted HTML */ protected function getLevelMenu( $pr_level ) { - global $wgRestrictionLevels; - // Temporary array $m = array( $this->msg( 'restriction-level-all' )->text() => 0 ); $options = array(); // First pass to load the log names - foreach ( $wgRestrictionLevels as $type ) { + foreach ( $this->getConfig()->get( 'RestrictionLevels' ) as $type ) { // Messages used can be 'restriction-level-sysop' and 'restriction-level-autoconfirmed' if ( $type != '' && $type != '*' ) { $text = $this->msg( "restriction-level-$type" )->text(); @@ -370,12 +281,12 @@ class SpecialProtectedpages extends SpecialPage { * @todo document * @ingroup Pager */ -class ProtectedPagesPager extends AlphabeticPager { +class ProtectedPagesPager extends TablePager { public $mForm, $mConds; - private $type, $level, $namespace, $sizetype, $size, $indefonly; + private $type, $level, $namespace, $sizetype, $size, $indefonly, $cascadeonly, $noredirect; function __construct( $form, $conds = array(), $type, $level, $namespace, - $sizetype = '', $size = 0, $indefonly = false, $cascadeonly = false + $sizetype = '', $size = 0, $indefonly = false, $cascadeonly = false, $noredirect = false ) { $this->mForm = $form; $this->mConds = $conds; @@ -386,28 +297,203 @@ class ProtectedPagesPager extends AlphabeticPager { $this->size = intval( $size ); $this->indefonly = (bool)$indefonly; $this->cascadeonly = (bool)$cascadeonly; + $this->noredirect = (bool)$noredirect; parent::__construct( $form->getContext() ); } - function getStartBody() { + function preprocessResults( $result ) { # Do a link batch query $lb = new LinkBatch; - foreach ( $this->mResult as $row ) { + $userids = array(); + + foreach ( $result as $row ) { $lb->add( $row->page_namespace, $row->page_title ); + // field is nullable, maybe null on old protections + if ( $row->log_user !== null ) { + $userids[] = $row->log_user; + } + } + + // fill LinkBatch with user page and user talk + if ( count( $userids ) ) { + $userCache = UserCache::singleton(); + $userCache->doQuery( $userids, array(), __METHOD__ ); + foreach ( $userids as $userid ) { + $name = $userCache->getProp( $userid, 'name' ); + if ( $name !== false ) { + $lb->add( NS_USER, $name ); + $lb->add( NS_USER_TALK, $name ); + } + } } + $lb->execute(); + } + + function getFieldNames() { + static $headers = null; + + if ( $headers == array() ) { + $headers = array( + 'log_timestamp' => 'protectedpages-timestamp', + 'pr_page' => 'protectedpages-page', + 'pr_expiry' => 'protectedpages-expiry', + 'log_user' => 'protectedpages-performer', + 'pr_params' => 'protectedpages-params', + 'log_comment' => 'protectedpages-reason', + ); + foreach ( $headers as $key => $val ) { + $headers[$key] = $this->msg( $val )->text(); + } + } - return ''; + return $headers; } - function formatRow( $row ) { - return $this->mForm->formatRow( $row ); + /** + * @param string $field + * @param string $value + * @return string + * @throws MWException + */ + function formatValue( $field, $value ) { + /** @var $row object */ + $row = $this->mCurrentRow; + + $formatted = ''; + + switch ( $field ) { + case 'log_timestamp': + // when timestamp is null, this is a old protection row + if ( $value === null ) { + $formatted = Html::rawElement( + 'span', + array( 'class' => 'mw-protectedpages-unknown' ), + $this->msg( 'protectedpages-unknown-timestamp' )->escaped() + ); + } else { + $formatted = $this->getLanguage()->userTimeAndDate( $value, $this->getUser() ); + } + break; + + case 'pr_page': + $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title ); + if ( !$title ) { + $formatted = Html::element( + 'span', + array( 'class' => 'mw-invalidtitle' ), + Linker::getInvalidTitleDescription( + $this->getContext(), + $row->page_namespace, + $row->page_title + ) + ); + } else { + $formatted = Linker::link( $title ); + } + if ( !is_null( $row->page_len ) ) { + $formatted .= $this->getLanguage()->getDirMark() . + ' ' . Html::rawElement( + 'span', + array( 'class' => 'mw-protectedpages-length' ), + Linker::formatRevisionSize( $row->page_len ) + ); + } + break; + + case 'pr_expiry': + $formatted = $this->getLanguage()->formatExpiry( $value, /* User preference timezone */true ); + $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title ); + if ( $this->getUser()->isAllowed( 'protect' ) && $title ) { + $changeProtection = Linker::linkKnown( + $title, + $this->msg( 'protect_change' )->escaped(), + array(), + array( 'action' => 'unprotect' ) + ); + $formatted .= ' ' . Html::rawElement( + 'span', + array( 'class' => 'mw-protectedpages-actions' ), + $this->msg( 'parentheses' )->rawParams( $changeProtection )->escaped() + ); + } + break; + + case 'log_user': + // when timestamp is null, this is a old protection row + if ( $row->log_timestamp === null ) { + $formatted = Html::rawElement( + 'span', + array( 'class' => 'mw-protectedpages-unknown' ), + $this->msg( 'protectedpages-unknown-performer' )->escaped() + ); + } else { + $username = UserCache::singleton()->getProp( $value, 'name' ); + if ( LogEventsList::userCanBitfield( + $row->log_deleted, + LogPage::DELETED_USER, + $this->getUser() + ) ) { + if ( $username === false ) { + $formatted = htmlspecialchars( $value ); + } else { + $formatted = Linker::userLink( $value, $username ) + . Linker::userToolLinks( $value, $username ); + } + } else { + $formatted = $this->msg( 'rev-deleted-user' )->escaped(); + } + if ( LogEventsList::isDeleted( $row, LogPage::DELETED_USER ) ) { + $formatted = '<span class="history-deleted">' . $formatted . '</span>'; + } + } + break; + + case 'pr_params': + $params = array(); + // Messages: restriction-level-sysop, restriction-level-autoconfirmed + $params[] = $this->msg( 'restriction-level-' . $row->pr_level )->escaped(); + if ( $row->pr_cascade ) { + $params[] = $this->msg( 'protect-summary-cascade' )->text(); + } + $formatted = $this->getLanguage()->commaList( $params ); + break; + + case 'log_comment': + // when timestamp is null, this is an old protection row + if ( $row->log_timestamp === null ) { + $formatted = Html::rawElement( + 'span', + array( 'class' => 'mw-protectedpages-unknown' ), + $this->msg( 'protectedpages-unknown-reason' )->escaped() + ); + } else { + if ( LogEventsList::userCanBitfield( + $row->log_deleted, + LogPage::DELETED_COMMENT, + $this->getUser() + ) ) { + $formatted = Linker::formatComment( $value !== null ? $value : '' ); + } else { + $formatted = $this->msg( 'rev-deleted-comment' )->escaped(); + } + if ( LogEventsList::isDeleted( $row, LogPage::DELETED_COMMENT ) ) { + $formatted = '<span class="history-deleted">' . $formatted . '</span>'; + } + } + break; + + default: + throw new MWException( "Unknown field '$field'" ); + } + + return $formatted; } function getQueryInfo() { $conds = $this->mConds; - $conds[] = '(pr_expiry>' . $this->mDb->addQuotes( $this->mDb->timestamp() ) . - 'OR pr_expiry IS NULL)'; + $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 ); @@ -424,6 +510,9 @@ class ProtectedPagesPager extends AlphabeticPager { if ( $this->cascadeonly ) { $conds[] = 'pr_cascade = 1'; } + if ( $this->noredirect ) { + $conds[] = 'page_is_redirect = 0'; + } if ( $this->level ) { $conds[] = 'pr_level=' . $this->mDb->addQuotes( $this->level ); @@ -433,14 +522,51 @@ class ProtectedPagesPager extends AlphabeticPager { } return array( - 'tables' => array( 'page_restrictions', 'page' ), - 'fields' => array( 'pr_id', 'page_namespace', 'page_title', 'page_len', - 'pr_type', 'pr_level', 'pr_expiry', 'pr_cascade' ), - 'conds' => $conds + 'tables' => array( 'page', 'page_restrictions', 'log_search', 'logging' ), + 'fields' => array( + 'pr_id', + 'page_namespace', + 'page_title', + 'page_len', + 'pr_type', + 'pr_level', + 'pr_expiry', + 'pr_cascade', + 'log_timestamp', + 'log_user', + 'log_comment', + 'log_deleted', + ), + 'conds' => $conds, + 'join_conds' => array( + 'log_search' => array( + 'LEFT JOIN', array( + 'ls_field' => 'pr_id', 'ls_value = pr_id' + ) + ), + 'logging' => array( + 'LEFT JOIN', array( + 'ls_log_id = log_id' + ) + ) + ) ); } + public function getTableClass() { + return parent::getTableClass() . ' mw-protectedpages'; + } + function getIndexField() { return 'pr_id'; } + + function getDefaultSort() { + return 'pr_id'; + } + + function isFieldSortable( $field ) { + // no index for sorting exists + return false; + } } |