$from = self::convertSelectType( $from );
$db = wfGetDB( $from === self::READ_LATEST ? DB_MASTER : DB_SLAVE );
$row = $db->selectRow(
- 'page', self::selectFields(), array( 'page_id' => $id ), __METHOD__ );
+ 'page', self::selectFields(), [ 'page_id' => $id ], __METHOD__ );
if ( !$row ) {
return null;
}
public static function selectFields() {
global $wgContentHandlerUseDB, $wgPageLanguageUseDB;
- $fields = array(
+ $fields = [
'page_id',
'page_namespace',
'page_title',
'page_links_updated',
'page_latest',
'page_len',
- );
+ ];
if ( $wgContentHandlerUseDB ) {
$fields[] = 'page_content_model';
* @param array $options
* @return object|bool Database result resource, or false on failure
*/
- protected function pageData( $dbr, $conditions, $options = array() ) {
+ protected function pageData( $dbr, $conditions, $options = [] ) {
$fields = self::selectFields();
- Hooks::run( 'ArticlePageDataBefore', array( &$this, &$fields ) );
+ Hooks::run( 'ArticlePageDataBefore', [ &$this, &$fields ] );
$row = $dbr->selectRow( 'page', $fields, $conditions, __METHOD__, $options );
- Hooks::run( 'ArticlePageDataAfter', array( &$this, &$row ) );
+ Hooks::run( 'ArticlePageDataAfter', [ &$this, &$row ] );
return $row;
}
* @param array $options
* @return object|bool Database result resource, or false on failure
*/
- public function pageDataFromTitle( $dbr, $title, $options = array() ) {
- return $this->pageData( $dbr, array(
+ public function pageDataFromTitle( $dbr, $title, $options = [] ) {
+ return $this->pageData( $dbr, [
'page_namespace' => $title->getNamespace(),
- 'page_title' => $title->getDBkey() ), $options );
+ 'page_title' => $title->getDBkey() ], $options );
}
/**
* @param array $options
* @return object|bool Database result resource, or false on failure
*/
- public function pageDataFromId( $dbr, $id, $options = array() ) {
- return $this->pageData( $dbr, array( 'page_id' => $id ), $options );
+ public function pageDataFromId( $dbr, $id, $options = [] ) {
+ return $this->pageData( $dbr, [ 'page_id' => $id ], $options );
}
/**
$row = null;
while ( $continue ) {
$row = $db->selectRow(
- array( 'page', 'revision' ),
+ [ 'page', 'revision' ],
$revSelectFields,
- array(
+ [
'page_namespace' => $this->mTitle->getNamespace(),
'page_title' => $this->mTitle->getDBkey(),
'rev_page = page_id'
- ),
+ ],
__METHOD__,
- array(
+ [
'ORDER BY' => 'rev_timestamp ASC'
- )
+ ]
);
if ( $row ) {
$hasLinks = (bool)count( $editInfo->output->getLinks() );
} else {
$hasLinks = (bool)wfGetDB( DB_SLAVE )->selectField( 'pagelinks', 1,
- array( 'pl_from' => $this->getId() ), __METHOD__ );
+ [ 'pl_from' => $this->getId() ], __METHOD__ );
}
}
// Query the redirect table
$dbr = wfGetDB( DB_SLAVE );
$row = $dbr->selectRow( 'redirect',
- array( 'rd_namespace', 'rd_title', 'rd_fragment', 'rd_interwiki' ),
- array( 'rd_from' => $this->getId() ),
+ [ 'rd_namespace', 'rd_title', 'rd_fragment', 'rd_interwiki' ],
+ [ 'rd_from' => $this->getId() ],
__METHOD__
);
if ( !$oldLatest || $oldLatest == $this->lockAndGetLatest() ) {
$dbw->replace( 'redirect',
- array( 'rd_from' ),
- array(
+ [ 'rd_from' ],
+ [
'rd_from' => $this->getId(),
'rd_namespace' => $rt->getNamespace(),
'rd_title' => $rt->getDBkey(),
'rd_fragment' => $rt->getFragment(),
'rd_interwiki' => $rt->getInterwiki(),
- ),
+ ],
__METHOD__
);
}
// This can be hard to reverse and may produce loops,
// so they may be disabled in the site configuration.
$source = $this->mTitle->getFullURL( 'redirect=no' );
- return $rt->getFullURL( array( 'rdfrom' => $source ) );
+ return $rt->getFullURL( [ 'rdfrom' => $source ] );
} else {
// External pages without "local" bit set are not valid
// redirect targets
$realNameField = 'MIN(user_real_name) AS user_real_name';
}
- $tables = array( 'revision', 'user' );
+ $tables = [ 'revision', 'user' ];
- $fields = array(
+ $fields = [
'user_id' => 'rev_user',
'user_name' => 'rev_user_text',
$realNameField,
'timestamp' => 'MAX(rev_timestamp)',
- );
+ ];
- $conds = array( 'rev_page' => $this->getId() );
+ $conds = [ 'rev_page' => $this->getId() ];
// The user who made the top revision gets credited as "this page was last edited by
// John, based on contributions by Tom, Dick and Harry", so don't include them twice.
// Username hidden?
$conds[] = "{$dbr->bitAnd( 'rev_deleted', Revision::DELETED_USER )} = 0";
- $jconds = array(
- 'user' => array( 'LEFT JOIN', 'rev_user = user_id' ),
- );
+ $jconds = [
+ 'user' => [ 'LEFT JOIN', 'rev_user = user_id' ],
+ ];
- $options = array(
- 'GROUP BY' => array( 'rev_user', 'rev_user_text' ),
+ $options = [
+ 'GROUP BY' => [ 'rev_user', 'rev_user_text' ],
'ORDER BY' => 'timestamp DESC',
- );
+ ];
$res = $dbr->select( $tables, $fields, $conds, __METHOD__, $options, $jconds );
return new UserArrayFromResult( $res );
return;
}
- Hooks::run( 'PageViewUpdates', array( $this, $user ) );
+ Hooks::run( 'PageViewUpdates', [ $this, $user ] );
// Update newtalk / watchlist notification status
try {
$user->clearNotification( $this->mTitle, $oldid );
* @return bool
*/
public function doPurge() {
- if ( !Hooks::run( 'ArticlePurge', array( &$this ) ) ) {
+ if ( !Hooks::run( 'ArticlePurge', [ &$this ] ) ) {
return false;
}
$pageIdForInsert = $pageId ?: $dbw->nextSequenceValue( 'page_page_id_seq' );
$dbw->insert(
'page',
- array(
+ [
'page_id' => $pageIdForInsert,
'page_namespace' => $this->mTitle->getNamespace(),
'page_title' => $this->mTitle->getDBkey(),
'page_touched' => $dbw->timestamp(),
'page_latest' => 0, // Fill this in shortly...
'page_len' => 0, // Fill this in shortly...
- ),
+ ],
__METHOD__,
'IGNORE'
);
$len = $content ? $content->getSize() : 0;
$rt = $content ? $content->getUltimateRedirectTarget() : null;
- $conditions = array( 'page_id' => $this->getId() );
+ $conditions = [ 'page_id' => $this->getId() ];
if ( !is_null( $lastRevision ) ) {
// An extra check against threads stepping on each other
$conditions['page_latest'] = $lastRevision;
}
- $row = array( /* SET */
+ $row = [ /* SET */
'page_latest' => $revision->getId(),
'page_touched' => $dbw->timestamp( $revision->getTimestamp() ),
'page_is_new' => ( $lastRevision === 0 ) ? 1 : 0,
'page_is_redirect' => $rt !== null ? 1 : 0,
'page_len' => $len,
- );
+ ];
if ( $wgContentHandlerUseDB ) {
$row['page_content_model'] = $revision->getContentModel();
$this->insertRedirectEntry( $redirectTitle );
} else {
// This is not a redirect, remove row from redirect table
- $where = array( 'rd_from' => $this->getId() );
+ $where = [ 'rd_from' => $this->getId() ];
$dbw->delete( 'redirect', $where, __METHOD__ );
}
public function updateIfNewerOn( $dbw, $revision ) {
$row = $dbw->selectRow(
- array( 'revision', 'page' ),
- array( 'rev_id', 'rev_timestamp', 'page_is_redirect' ),
- array(
+ [ 'revision', 'page' ],
+ [ 'rev_id', 'rev_timestamp', 'page_is_redirect' ],
+ [
'page_id' => $this->getId(),
- 'page_latest=rev_id' ),
+ 'page_latest=rev_id' ],
__METHOD__ );
if ( $row ) {
return $handler->getUndoContent( $this->getRevision(), $undo, $undoafter );
}
- /**
- * Get the text that needs to be saved in order to undo all revisions
- * between $undo and $undoafter. Revisions must belong to the same page,
- * must exist and must not be deleted
- * @param Revision $undo
- * @param Revision $undoafter Must be an earlier revision than $undo
- * @return string|bool String on success, false on failure
- * @deprecated since 1.21: use ContentHandler::getUndoContent() instead.
- */
- public function getUndoText( Revision $undo, Revision $undoafter = null ) {
- ContentHandler::deprecated( __METHOD__, '1.21' );
-
- $this->loadLastEdit();
-
- if ( $this->mLastRevision ) {
- if ( is_null( $undoafter ) ) {
- $undoafter = $undo->getPrevious();
- }
-
- $handler = $this->getContentHandler();
- $undone = $handler->getUndoContent( $this->mLastRevision, $undo, $undoafter );
-
- if ( !$undone ) {
- return false;
- } else {
- return ContentHandler::getContentText( $undone );
- }
- }
-
- return false;
- }
-
- /**
- * @param string|number|null|bool $sectionId Section identifier as a number or string
- * (e.g. 0, 1 or 'T-1'), null/false or an empty string for the whole page
- * or 'new' for a new section.
- * @param string $text New text of the section.
- * @param string $sectionTitle New section's subject, only if $section is "new".
- * @param string $edittime Revision timestamp or null to use the current revision.
- *
- * @throws MWException
- * @return string|null New complete article text, or null if error.
- *
- * @deprecated since 1.21, use replaceSectionAtRev() instead
- */
- public function replaceSection( $sectionId, $text, $sectionTitle = '',
- $edittime = null
- ) {
- ContentHandler::deprecated( __METHOD__, '1.21' );
-
- // NOTE: keep condition in sync with condition in replaceSectionContent!
- if ( strval( $sectionId ) === '' ) {
- // Whole-page edit; let the whole text through
- return $text;
- }
-
- if ( !$this->supportsSections() ) {
- throw new MWException( "sections not supported for content model " .
- $this->getContentHandler()->getModelID() );
- }
-
- // could even make section title, but that's not required.
- $sectionContent = ContentHandler::makeContent( $text, $this->getTitle() );
-
- $newContent = $this->replaceSectionContent( $sectionId, $sectionContent, $sectionTitle,
- $edittime );
-
- return ContentHandler::getContentText( $newContent );
- }
-
/**
* Returns true if this page's content model supports sections.
*
* @param User $user The user doing the edit
* @param string $serialFormat Format for storing the content in the
* database.
+ * @param array|null $tags Change tags to apply to this edit
+ * Callers are responsible for permission checks
+ * (with ChangeTags::canAddTagsAccompanyingChange)
*
* @throws MWException
* @return Status Possible errors:
*/
public function doEditContent(
Content $content, $summary, $flags = 0, $baseRevId = false,
- User $user = null, $serialFormat = null
+ User $user = null, $serialFormat = null, $tags = null
) {
global $wgUser, $wgUseAutomaticEditSummaries;
$flags = $this->checkFlags( $flags );
// Trigger pre-save hook (using provided edit summary)
- $hookStatus = Status::newGood( array() );
- $hook_args = array( &$this, &$user, &$content, &$summary,
- $flags & EDIT_MINOR, null, null, &$flags, &$hookStatus );
+ $hookStatus = Status::newGood( [] );
+ $hook_args = [ &$this, &$user, &$content, &$summary,
+ $flags & EDIT_MINOR, null, null, &$flags, &$hookStatus ];
// Check if the hook rejected the attempted save
if ( !Hooks::run( 'PageContentSave', $hook_args )
|| !ContentHandler::runLegacyHooks( 'ArticleSave', $hook_args )
// Get the pre-save transform content and final parser output
$editInfo = $this->prepareContentForEdit( $content, null, $user, $serialFormat );
$pstContent = $editInfo->pstContent; // Content object
- $meta = array(
+ $meta = [
'bot' => ( $flags & EDIT_FORCE_BOT ),
'minor' => ( $flags & EDIT_MINOR ) && $user->isAllowed( 'minoredit' ),
'serialized' => $editInfo->pst,
'oldContent' => $old_content,
'oldId' => $this->getLatest(),
'oldIsRedirect' => $this->isRedirect(),
- 'oldCountable' => $this->isCountable()
- );
+ 'oldCountable' => $this->isCountable(),
+ 'tags' => ( $tags !== null ) ? (array)$tags : []
+ ];
// Actually create the revision and create/update the page
if ( $flags & EDIT_UPDATE ) {
global $wgUseRCPatrol;
// Update article, but only if changed.
- $status = Status::newGood( array( 'new' => false, 'revision' => null ) );
+ $status = Status::newGood( [ 'new' => false, 'revision' => null ] );
// Convenience variables
$now = wfTimestampNow();
}
// @TODO: pass content object?!
- $revision = new Revision( array(
+ $revision = new Revision( [
'page' => $this->getId(),
'title' => $this->mTitle, // for determining the default content model
'comment' => $summary,
'timestamp' => $now,
'content_model' => $content->getModel(),
'content_format' => $meta['serialFormat'],
- ) );
+ ] );
$changed = !$content->equals( $oldContent );
}
Hooks::run( 'NewRevisionFromEditComplete',
- array( $this, $revision, $meta['baseRevId'], $user ) );
+ [ $this, $revision, $meta['baseRevId'], $user ] );
// Update recentchanges
if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
$oldContent ? $oldContent->getSize() : 0,
$newsize,
$revisionId,
- $patrolled
+ $patrolled,
+ $meta['tags']
);
}
$that->doEditUpdates(
$revision,
$user,
- array(
+ [
'changed' => $changed,
'oldcountable' => $meta['oldCountable'],
'oldrevision' => $meta['oldRevision']
- )
+ ]
);
// Trigger post-save hook
- $params = array( &$that, &$user, $content, $summary, $flags & EDIT_MINOR,
- null, null, &$flags, $revision, &$status, $meta['baseRevId'] );
+ $params = [ &$that, &$user, $content, $summary, $flags & EDIT_MINOR,
+ null, null, &$flags, $revision, &$status, $meta['baseRevId'] ];
ContentHandler::runLegacyHooks( 'ArticleSaveComplete', $params );
Hooks::run( 'PageContentSaveComplete', $params );
}
) {
global $wgUseRCPatrol, $wgUseNPPatrol;
- $status = Status::newGood( array( 'new' => true, 'revision' => null ) );
+ $status = Status::newGood( [ 'new' => true, 'revision' => null ] );
$now = wfTimestampNow();
$newsize = $content->getSize();
// unless they actually try to catch exceptions (which is rare).
// @TODO: pass content object?!
- $revision = new Revision( array(
+ $revision = new Revision( [
'page' => $newid,
'title' => $this->mTitle, // for determining the default content model
'comment' => $summary,
'timestamp' => $now,
'content_model' => $content->getModel(),
'content_format' => $meta['serialFormat'],
- ) );
+ ] );
// Save the revision text...
$revisionId = $revision->insertOn( $dbw );
throw new MWException( "Failed to update page row to use new revision." );
}
- Hooks::run( 'NewRevisionFromEditComplete', array( $this, $revision, false, $user ) );
+ Hooks::run( 'NewRevisionFromEditComplete', [ $this, $revision, false, $user ] );
// Update recentchanges
if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
'',
$newsize,
$revisionId,
- $patrolled
+ $patrolled,
+ $meta['tags']
);
}
// Do per-page updates in a transaction
$dbw->setFlag( DBO_TRX );
// Update links, etc.
- $that->doEditUpdates( $revision, $user, array( 'created' => true ) );
+ $that->doEditUpdates( $revision, $user, [ 'created' => true ] );
// Trigger post-create hook
- $params = array( &$that, &$user, $content, $summary,
- $flags & EDIT_MINOR, null, null, &$flags, $revision );
+ $params = [ &$that, &$user, $content, $summary,
+ $flags & EDIT_MINOR, null, null, &$flags, $revision ];
ContentHandler::runLegacyHooks( 'ArticleInsertComplete', $params );
Hooks::run( 'PageContentInsertComplete', $params );
// Trigger post-save hook
- $params = array_merge( $params, array( &$status, $meta['baseRevId'] ) );
+ $params = array_merge( $params, [ &$status, $meta['baseRevId'] ] );
ContentHandler::runLegacyHooks( 'ArticleSaveComplete', $params );
Hooks::run( 'PageContentSaveComplete', $params );
: false;
$popts = ParserOptions::newFromUserAndLang( $user, $wgContLang );
- Hooks::run( 'ArticlePrepareTextForEdit', array( $this, $popts ) );
+ Hooks::run( 'ArticlePrepareTextForEdit', [ $this, $popts ] );
- $edit = (object)array();
+ $edit = (object)[];
if ( $cachedEdit ) {
$edit->timestamp = $cachedEdit->timestamp;
} else {
* is true, do update the article count
* - 'no-change': don't update the article count, ever
*/
- public function doEditUpdates( Revision $revision, User $user, array $options = array() ) {
+ public function doEditUpdates( Revision $revision, User $user, array $options = [] ) {
global $wgRCWatchCategoryMembership, $wgContLang;
- $options += array(
+ $options += [
'changed' => true,
'created' => false,
'moved' => false,
'restored' => false,
'oldrevision' => null,
'oldcountable' => null
- );
+ ];
$content = $revision->getContent();
// Parse the text
DeferredUpdates::addUpdate( $update );
}
if ( $wgRCWatchCategoryMembership
+ && $this->getContentHandler()->supportsCategories() === true
&& ( $options['changed'] || $options['created'] )
&& !$options['restored']
) {
// bot/deletion/IP flags, ect.
JobQueueGroup::singleton()->lazyPush( new CategoryMembershipChangeJob(
$this->getTitle(),
- array(
+ [
'pageId' => $this->getId(),
'revTimestamp' => $revision->getTimestamp()
- )
+ ]
) );
}
}
- Hooks::run( 'ArticleEditUpdates', array( &$this, &$editInfo, $options['changed'] ) );
+ Hooks::run( 'ArticleEditUpdates', [ &$this, &$editInfo, $options['changed'] ] );
- if ( Hooks::run( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
+ if ( Hooks::run( 'ArticleEditUpdatesDeleteFromRecentchanges', [ &$this ] ) ) {
// Flush old entries from the `recentchanges` table
if ( mt_rand( 0, 9 ) == 0 ) {
JobQueueGroup::singleton()->lazyPush( RecentChangesUpdateJob::newPurgeJob() );
} else {
// Allow extensions to prevent user notification
// when a new message is added to their talk page
- if ( Hooks::run( 'ArticleEditUpdateNewTalk', array( &$this, $recipient ) ) ) {
+ if ( Hooks::run( 'ArticleEditUpdateNewTalk', [ &$this, $recipient ] ) ) {
if ( User::isIP( $shortTitle ) ) {
// An anonymous user
$recipient->setNewtalk( true, $revision );
$serialized = $content->serialize( $serialFormat );
$dbw = wfGetDB( DB_MASTER );
- $revision = new Revision( array(
+ $revision = new Revision( [
'title' => $this->getTitle(), // for determining the default content model
'page' => $this->getId(),
'user_text' => $user->getName(),
'length' => $content->getSize(),
'comment' => $comment,
'minor_edit' => $minor ? 1 : 0,
- ) ); // XXX: set the content object?
+ ] ); // XXX: set the content object?
$revision->insertOn( $dbw );
$this->updateRevisionOn( $dbw, $revision );
- Hooks::run( 'NewRevisionFromEditComplete', array( $this, $revision, false, $user ) );
+ Hooks::run( 'NewRevisionFromEditComplete', [ $this, $revision, false, $user ] );
}
* @param int &$cascade Set to false if cascading protection isn't allowed.
* @param string $reason
* @param User $user The user updating the restrictions
- * @return Status
+ * @param string|string[] $tags Change tags to add to the pages and protection log entries
+ * ($user should be able to add the specified tags before this is called)
+ * @return Status Status object; if action is taken, $status->value is the log_id of the
+ * protection log entry.
*/
public function doUpdateRestrictions( array $limit, array $expiry,
- &$cascade, $reason, User $user
+ &$cascade, $reason, User $user, $tags = null
) {
global $wgCascadingRestrictionLevels, $wgContLang;
// Truncate for whole multibyte characters
$reason = $wgContLang->truncate( $reason, 255 );
- $logRelationsValues = array();
+ $logRelationsValues = [];
$logRelationsField = null;
- $logParamsDetails = array();
+ $logParamsDetails = [];
+
+ // Null revision (used for change tag insertion)
+ $nullRevision = null;
if ( $id ) { // Protection of existing page
- if ( !Hooks::run( 'ArticleProtect', array( &$this, &$user, $limit, $reason ) ) ) {
+ if ( !Hooks::run( 'ArticleProtect', [ &$this, &$user, $limit, $reason ] ) ) {
return Status::newGood();
}
// Only certain restrictions can cascade...
$editrestriction = isset( $limit['edit'] )
- ? array( $limit['edit'] )
+ ? [ $limit['edit'] ]
: $this->mTitle->getRestrictions( 'edit' );
foreach ( array_keys( $editrestriction, 'sysop' ) as $key ) {
$editrestriction[$key] = 'editprotected'; // backwards compatibility
foreach ( $limit as $action => $restrictions ) {
$dbw->delete(
'page_restrictions',
- array(
+ [
'pr_page' => $id,
'pr_type' => $action
- ),
+ ],
__METHOD__
);
if ( $restrictions != '' ) {
$cascadeValue = ( $cascade && $action == 'edit' ) ? 1 : 0;
$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' => $cascadeValue,
'pr_expiry' => $dbw->encodeExpiry( $expiry[$action] )
- ),
+ ],
__METHOD__
);
$logRelationsValues[] = $dbw->insertId();
- $logParamsDetails[] = array(
+ $logParamsDetails[] = [
'type' => $action,
'level' => $restrictions,
'expiry' => $expiry[$action],
'cascade' => (bool)$cascadeValue,
- );
+ ];
}
}
// Clear out legacy restriction fields
$dbw->update(
'page',
- array( 'page_restrictions' => '' ),
- array( 'page_id' => $id ),
+ [ 'page_restrictions' => '' ],
+ [ 'page_id' => $id ],
__METHOD__
);
Hooks::run( 'NewRevisionFromEditComplete',
- array( $this, $nullRevision, $latest, $user ) );
- Hooks::run( 'ArticleProtectComplete', array( &$this, &$user, $limit, $reason ) );
+ [ $this, $nullRevision, $latest, $user ] );
+ Hooks::run( 'ArticleProtectComplete', [ &$this, &$user, $limit, $reason ] );
} else { // Protection of non-existing page (also known as "title protection")
// Cascade protection is meaningless in this case
$cascade = false;
if ( $limit['create'] != '' ) {
$dbw->replace( 'protected_titles',
- array( array( 'pt_namespace', 'pt_title' ) ),
- array(
+ [ [ 'pt_namespace', 'pt_title' ] ],
+ [
'pt_namespace' => $this->mTitle->getNamespace(),
'pt_title' => $this->mTitle->getDBkey(),
'pt_create_perm' => $limit['create'],
'pt_expiry' => $dbw->encodeExpiry( $expiry['create'] ),
'pt_user' => $user->getId(),
'pt_reason' => $reason,
- ), __METHOD__
+ ], __METHOD__
);
- $logParamsDetails[] = array(
+ $logParamsDetails[] = [
'type' => 'create',
'level' => $limit['create'],
'expiry' => $expiry['create'],
- );
+ ];
} else {
$dbw->delete( 'protected_titles',
- array(
+ [
'pt_namespace' => $this->mTitle->getNamespace(),
'pt_title' => $this->mTitle->getDBkey()
- ), __METHOD__
+ ], __METHOD__
);
}
}
InfoAction::invalidateCache( $this->mTitle );
if ( $logAction == 'unprotect' ) {
- $params = array();
+ $params = [];
} else {
$protectDescriptionLog = $this->protectDescriptionLog( $limit, $expiry );
- $params = array(
+ $params = [
'4::description' => $protectDescriptionLog, // parameter for IRC
'5:bool:cascade' => $cascade,
'details' => $logParamsDetails, // parameter for localize and api
- );
+ ];
}
// Update the protection log
$logEntry->setComment( $reason );
$logEntry->setPerformer( $user );
$logEntry->setParameters( $params );
+ if ( !is_null( $nullRevision ) ) {
+ $logEntry->setAssociatedRevId( $nullRevision->getId() );
+ }
+ $logEntry->setTags( $tags );
if ( $logRelationsField !== null && count( $logRelationsValues ) ) {
- $logEntry->setRelations( array( $logRelationsField => $logRelationsValues ) );
+ $logEntry->setRelations( [ $logRelationsField => $logRelationsValues ] );
}
$logId = $logEntry->insert();
$logEntry->publish( $logId );
- return Status::newGood();
+ return Status::newGood( $logId );
}
/**
throw new MWException( __METHOD__ . ' given non-array restriction set' );
}
- $bits = array();
+ $bits = [];
ksort( $limit );
foreach ( array_filter( $limit ) as $action => $restrictions ) {
$user = is_null( $user ) ? $wgUser : $user;
if ( !Hooks::run( 'ArticleDelete',
- array( &$this, &$user, &$reason, &$error, &$status, $suppress )
+ [ &$this, &$user, &$reason, &$error, &$status, $suppress ]
) ) {
if ( $status->isOK() ) {
// Hook aborted but didn't set a fatal status
$dbw->startAtomic( __METHOD__ );
$this->loadPageData( self::READ_LATEST );
- $id = $this->getID();
+ $id = $this->getId();
// T98706: lock the page from various other updates but avoid using
// WikiPage::READ_LOCKING as that will carry over the FOR UPDATE to
// the revisions queries (which also JOIN on user). Only lock the page
* the rev_deleted field, which is reserved for this purpose.
*/
- $row = array(
+ $row = [
'ar_namespace' => 'page_namespace',
'ar_title' => 'page_title',
'ar_comment' => 'rev_comment',
'ar_page_id' => 'page_id',
'ar_deleted' => $bitfield,
'ar_sha1' => 'rev_sha1',
- );
+ ];
if ( $wgContentHandlerUseDB ) {
$row['ar_content_model'] = 'rev_content_model';
// Copy all the page revisions into the archive table
$dbw->insertSelect(
'archive',
- array( 'page', 'revision' ),
+ [ 'page', 'revision' ],
$row,
- array(
+ [
'page_id' => $id,
'page_id = rev_page'
- ),
+ ],
__METHOD__
);
// Now that it's safely backed up, delete it
- $dbw->delete( 'page', array( 'page_id' => $id ), __METHOD__ );
+ $dbw->delete( 'page', [ 'page_id' => $id ], __METHOD__ );
if ( !$dbw->cascadingDeletes() ) {
- $dbw->delete( 'revision', array( 'rev_page' => $id ), __METHOD__ );
+ $dbw->delete( 'revision', [ 'rev_page' => $id ], __METHOD__ );
}
// Clone the title, so we have the information we need when we log
$this->doDeleteUpdates( $id, $content );
Hooks::run( 'ArticleDeleteComplete',
- array( &$this, &$user, $reason, $id, $content, $logEntry ) );
+ [ &$this, &$user, $reason, $id, $content, $logEntry ] );
$status->value = $logid;
// Show log excerpt on 404 pages rather than just a link
return (int)wfGetDB( DB_MASTER )->selectField(
'page',
'page_latest',
- array(
+ [
'page_id' => $this->getId(),
// Typically page_id is enough, but some code might try to do
// updates assuming the title is the same, so verify that
'page_namespace' => $this->getTitle()->getNamespace(),
'page_title' => $this->getTitle()->getDBkey()
- ),
+ ],
__METHOD__,
- array( 'FOR UPDATE' )
+ [ 'FOR UPDATE' ]
);
}
* success : 'summary' (str), 'current' (rev), 'target' (rev)
*
* @param User $user The user performing the rollback
+ * @param array|null $tags Change tags to apply to the rollback
+ * Callers are responsible for permission checks
+ * (with ChangeTags::canAddTagsAccompanyingChange)
+ *
* @return array Array of errors, each error formatted as
* array(messagekey, param1, param2, ...).
* On success, the array is empty. This array can also be passed to
* OutputPage::showPermissionsErrorPage().
*/
public function doRollback(
- $fromP, $summary, $token, $bot, &$resultDetails, User $user
+ $fromP, $summary, $token, $bot, &$resultDetails, User $user, $tags = null
) {
$resultDetails = null;
$rollbackErrors = $this->mTitle->getUserPermissionsErrors( 'rollback', $user );
$errors = array_merge( $editErrors, wfArrayDiff2( $rollbackErrors, $editErrors ) );
- if ( !$user->matchEditToken( $token, array( $this->mTitle->getPrefixedText(), $fromP ) ) ) {
- $errors[] = array( 'sessionfailure' );
+ if ( !$user->matchEditToken( $token, [ $this->mTitle->getPrefixedText(), $fromP ] ) ) {
+ $errors[] = [ 'sessionfailure' ];
}
if ( $user->pingLimiter( 'rollback' ) || $user->pingLimiter() ) {
- $errors[] = array( 'actionthrottledtext' );
+ $errors[] = [ 'actionthrottledtext' ];
}
// If there were errors, bail out now
return $errors;
}
- return $this->commitRollback( $fromP, $summary, $bot, $resultDetails, $user );
+ return $this->commitRollback( $fromP, $summary, $bot, $resultDetails, $user, $tags );
}
/**
*
* @param array $resultDetails Contains result-specific array of additional values
* @param User $guser The user performing the rollback
+ * @param array|null $tags Change tags to apply to the rollback
+ * Callers are responsible for permission checks
+ * (with ChangeTags::canAddTagsAccompanyingChange)
+ *
* @return array
*/
- public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User $guser ) {
+ public function commitRollback( $fromP, $summary, $bot,
+ &$resultDetails, User $guser, $tags = null
+ ) {
global $wgUseRCPatrol, $wgContLang;
$dbw = wfGetDB( DB_MASTER );
if ( wfReadOnly() ) {
- return array( array( 'readonlytext' ) );
+ return [ [ 'readonlytext' ] ];
}
// Get the last editor
$current = $this->getRevision();
if ( is_null( $current ) ) {
// Something wrong... no page?
- return array( array( 'notanarticle' ) );
+ return [ [ 'notanarticle' ] ];
}
$from = str_replace( '_', ' ', $fromP );
// User name given should match up with the top revision.
// If the user was deleted then $from should be empty.
if ( $from != $current->getUserText() ) {
- $resultDetails = array( 'current' => $current );
- return array( array( 'alreadyrolled',
+ $resultDetails = [ 'current' => $current ];
+ return [ [ 'alreadyrolled',
htmlspecialchars( $this->mTitle->getPrefixedText() ),
htmlspecialchars( $fromP ),
htmlspecialchars( $current->getUserText() )
- ) );
+ ] ];
}
// Get the last edit not by this person...
$user = intval( $current->getUser( Revision::RAW ) );
$user_text = $dbw->addQuotes( $current->getUserText( Revision::RAW ) );
$s = $dbw->selectRow( 'revision',
- array( 'rev_id', 'rev_timestamp', 'rev_deleted' ),
- array( 'rev_page' => $current->getPage(),
+ [ 'rev_id', 'rev_timestamp', 'rev_deleted' ],
+ [ 'rev_page' => $current->getPage(),
"rev_user != {$user} OR rev_user_text != {$user_text}"
- ), __METHOD__,
- array( 'USE INDEX' => 'page_timestamp',
- 'ORDER BY' => 'rev_timestamp DESC' )
+ ], __METHOD__,
+ [ 'USE INDEX' => 'page_timestamp',
+ 'ORDER BY' => 'rev_timestamp DESC' ]
);
if ( $s === false ) {
// No one else ever edited this page
- return array( array( 'cantrollback' ) );
+ return [ [ 'cantrollback' ] ];
} elseif ( $s->rev_deleted & Revision::DELETED_TEXT
|| $s->rev_deleted & Revision::DELETED_USER
) {
// Only admins can see this text
- return array( array( 'notvisiblerev' ) );
+ return [ [ 'notvisiblerev' ] ];
}
// Generate the edit summary if necessary
}
// Allow the custom summary to use the same args as the default message
- $args = array(
+ $args = [
$target->getUserText(), $from, $s->rev_id,
$wgContLang->timeanddate( wfTimestamp( TS_MW, $s->rev_timestamp ) ),
$current->getId(), $wgContLang->timeanddate( $current->getTimestamp() )
- );
+ ];
if ( $summary instanceof Message ) {
$summary = $summary->params( $args )->inContentLanguage()->text();
} else {
$summary,
$flags,
$target->getId(),
- $guser
+ $guser,
+ null,
+ $tags
);
// Set patrolling and bot flag on the edits, which gets rollbacked.
// This is done even on edit failure to have patrolling in that case (bug 62157).
- $set = array();
+ $set = [];
if ( $bot && $guser->isAllowed( 'markbotedits' ) ) {
// Mark all reverted edits as bot
$set['rc_bot'] = 1;
if ( count( $set ) ) {
$dbw->update( 'recentchanges', $set,
- array( /* WHERE */
+ [ /* WHERE */
'rc_cur_id' => $current->getPage(),
'rc_user_text' => $current->getUserText(),
'rc_timestamp > ' . $dbw->addQuotes( $s->rev_timestamp ),
- ),
+ ],
__METHOD__
);
}
? $status->value['revision']
: null;
if ( !( $statusRev instanceof Revision ) ) {
- $resultDetails = array( 'current' => $current );
- return array( array( 'alreadyrolled',
+ $resultDetails = [ 'current' => $current ];
+ return [ [ 'alreadyrolled',
htmlspecialchars( $this->mTitle->getPrefixedText() ),
htmlspecialchars( $fromP ),
htmlspecialchars( $current->getUserText() )
- ) );
+ ] ];
}
$revId = $statusRev->getId();
- Hooks::run( 'ArticleRollbackComplete', array( $this, $guser, $target, $current ) );
+ Hooks::run( 'ArticleRollbackComplete', [ $this, $guser, $target, $current ] );
- $resultDetails = array(
+ $resultDetails = [
'summary' => $summary,
'current' => $current,
'target' => $target,
'newid' => $revId
- );
+ ];
- return array();
+ return [];
}
/**
public function getCategories() {
$id = $this->getId();
if ( $id == 0 ) {
- return TitleArray::newFromResult( new FakeResultWrapper( array() ) );
+ return TitleArray::newFromResult( new FakeResultWrapper( [] ) );
}
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select( 'categorylinks',
- array( 'cl_to AS page_title, ' . NS_CATEGORY . ' AS page_namespace' ),
+ [ 'cl_to AS page_title, ' . NS_CATEGORY . ' AS page_namespace' ],
// Have to do that since DatabaseBase::fieldNamesWithAlias treats numeric indexes
// as not being aliases, and NS_CATEGORY is numeric
- array( 'cl_from' => $id ),
+ [ 'cl_from' => $id ],
__METHOD__ );
return TitleArray::newFromResult( $res );
* @return array Array of Title objects
*/
public function getHiddenCategories() {
- $result = array();
+ $result = [];
$id = $this->getId();
if ( $id == 0 ) {
- return array();
+ return [];
}
$dbr = wfGetDB( DB_SLAVE );
- $res = $dbr->select( array( 'categorylinks', 'page_props', 'page' ),
- array( 'cl_to' ),
- array( 'cl_from' => $id, 'pp_page=page_id', 'pp_propname' => 'hiddencat',
- 'page_namespace' => NS_CATEGORY, 'page_title=cl_to' ),
+ $res = $dbr->select( [ 'categorylinks', 'page_props', 'page' ],
+ [ 'cl_to' ],
+ [ 'cl_from' => $id, 'pp_page=page_id', 'pp_propname' => 'hiddencat',
+ 'page_namespace' => NS_CATEGORY, 'page_title=cl_to' ],
__METHOD__ );
if ( $res !== false ) {
function () use ( $dbw, $that, $method, $added, $deleted ) {
$ns = $that->getTitle()->getNamespace();
- $addFields = array( 'cat_pages = cat_pages + 1' );
- $removeFields = array( 'cat_pages = cat_pages - 1' );
+ $addFields = [ 'cat_pages = cat_pages + 1' ];
+ $removeFields = [ 'cat_pages = cat_pages - 1' ];
if ( $ns == NS_CATEGORY ) {
$addFields[] = 'cat_subcats = cat_subcats + 1';
$removeFields[] = 'cat_subcats = cat_subcats - 1';
$existingAdded = $dbw->selectFieldValues(
'category',
'cat_title',
- array( 'cat_title' => $added ),
+ [ 'cat_title' => $added ],
__METHOD__
);
$dbw->update(
'category',
$addFields,
- array( 'cat_title' => $existingAdded ),
+ [ 'cat_title' => $existingAdded ],
__METHOD__
);
}
$missingAdded = array_diff( $added, $existingAdded );
if ( count( $missingAdded ) ) {
- $insertRows = array();
+ $insertRows = [];
foreach ( $missingAdded as $cat ) {
- $insertRows[] = array(
+ $insertRows[] = [
'cat_title' => $cat,
'cat_pages' => 1,
'cat_subcats' => ( $ns == NS_CATEGORY ) ? 1 : 0,
'cat_files' => ( $ns == NS_FILE ) ? 1 : 0,
- );
+ ];
}
$dbw->upsert(
'category',
$insertRows,
- array( 'cat_title' ),
+ [ 'cat_title' ],
$addFields,
$method
);
$dbw->update(
'category',
$removeFields,
- array( 'cat_title' => $deleted ),
+ [ 'cat_title' => $deleted ],
$method
);
}
foreach ( $added as $catName ) {
$cat = Category::newFromName( $catName );
- Hooks::run( 'CategoryAfterPageAdded', array( $cat, $that ) );
+ Hooks::run( 'CategoryAfterPageAdded', [ $cat, $that ] );
}
foreach ( $deleted as $catName ) {
$cat = Category::newFromName( $catName );
- Hooks::run( 'CategoryAfterPageRemoved', array( $cat, $that ) );
+ Hooks::run( 'CategoryAfterPageRemoved', [ $cat, $that ] );
}
}
);
}
if ( !Hooks::run( 'OpportunisticLinksUpdate',
- array( $this, $this->mTitle, $parserOutput )
+ [ $this, $this->mTitle, $parserOutput ]
) ) {
return;
}
- $params = array(
+ $params = [
'isOpportunistic' => true,
'rootJobTimestamp' => $parserOutput->getCacheTime()
- );
+ ];
if ( $this->mTitle->areRestrictionsCascading() ) {
// If the page is cascade protecting, the links should really be up-to-date
}
if ( !$content ) {
- $updates = array();
+ $updates = [];
} else {
$updates = $content->getDeletionUpdates( $this );
}
- Hooks::run( 'WikiPageDeletionUpdates', array( $this, $content, &$updates ) );
+ Hooks::run( 'WikiPageDeletionUpdates', [ $this, $content, &$updates ] );
return $updates;
}
}