// Truncate for whole multibyte characters
$reason = $wgContLang->truncate( $reason, 255 );
+ $logRelationsValues = array();
+ $logRelationsField = null;
+
if ( $id ) { // Protection of existing page
if ( !wfRunHooks( 'ArticleProtect', array( &$this, &$user, $limit, $reason ) ) ) {
return Status::newGood();
return Status::newFatal( 'no-null-revision', $this->mTitle->getPrefixedText() );
}
+ $logRelationsField = 'pr_id';
+
// Update restrictions table
foreach ( $limit as $action => $restrictions ) {
+ $dbw->delete(
+ 'page_restrictions',
+ array(
+ 'pr_page' => $id,
+ 'pr_type' => $action
+ ),
+ __METHOD__
+ );
if ( $restrictions != '' ) {
- $dbw->replace( 'page_restrictions', array( array( 'pr_page', 'pr_type' ) ),
- array( 'pr_page' => $id,
+ $dbw->insert(
+ 'page_restrictions',
+ array(
+ 'pr_id' => $dbw->nextSequenceValue( 'page_restrictions_pr_id_seq' ),
+ 'pr_page' => $id,
'pr_type' => $action,
'pr_level' => $restrictions,
'pr_cascade' => ( $cascade && $action == 'edit' ) ? 1 : 0,
),
__METHOD__
);
- } else {
- $dbw->delete( 'page_restrictions', array( 'pr_page' => $id,
- 'pr_type' => $action ), __METHOD__ );
+ $logRelationsValues[] = $dbw->insertId();
}
}
// Update the protection log
$log = new LogPage( 'protect' );
- $log->addEntry( $logAction, $this->mTitle, $reason, $params, $user );
+ $logId = $log->addEntry( $logAction, $this->mTitle, $reason, $params, $user );
+ if ( $logRelationsField !== null && count( $logRelationsValues ) ) {
+ $log->addRelations( $logRelationsField, $logRelationsValues, $logId );
+ }
return Status::newGood();
}
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 ) ) {
if ( $pager->getNumRows() ) {
$this->getOutput()->addHTML(
$pager->getNavigationBar() .
- '<ul>' . $pager->getBody() . '</ul>' .
+ $pager->getBody() .
$pager->getNavigationBar()
);
} else {
}
}
- /**
- * 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 int $namespace
* @param string $type Restriction type
* @todo document
* @ingroup Pager
*/
-class ProtectedPagesPager extends AlphabeticPager {
+class ProtectedPagesPager extends TablePager {
public $mForm, $mConds;
private $type, $level, $namespace, $sizetype, $size, $indefonly, $cascadeonly, $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();
+ }
- return '';
+ 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 $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 a 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() {
}
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 'TablePager mw-protectedpages';
+ }
+
function getIndexField() {
return 'pr_id';
}
+
+ function getDefaultSort() {
+ return 'pr_id';
+ }
+
+ function isFieldSortable( $field ) {
+ // no index for sorting exists
+ return false;
+ }
}