Merge "Add GENDER support to protection null revision edit summary"
[lhc/web/wiklou.git] / includes / page / WikiPage.php
index 9aa8503..dd78d19 100644 (file)
@@ -2399,6 +2399,10 @@ class WikiPage implements Page, IDBAccessObject {
                } elseif ( $options['changed'] ) { // bug 50785
                        self::onArticleEdit( $this->mTitle, $revision );
                }
+
+               ResourceLoaderWikiModule::invalidateModuleCache(
+                       $this->mTitle, $options['oldrevision'], $revision, wfWikiID()
+               );
        }
 
        /**
@@ -2481,13 +2485,13 @@ class WikiPage implements Page, IDBAccessObject {
                }
 
                if ( !$protect ) { // No protection at all means unprotection
-                       $revCommentMsg = 'unprotectedarticle';
+                       $revCommentMsg = 'unprotectedarticle-comment';
                        $logAction = 'unprotect';
                } elseif ( $isProtected ) {
-                       $revCommentMsg = 'modifiedarticleprotection';
+                       $revCommentMsg = 'modifiedarticleprotection-comment';
                        $logAction = 'modify';
                } else {
-                       $revCommentMsg = 'protectedarticle';
+                       $revCommentMsg = 'protectedarticle-comment';
                        $logAction = 'protect';
                }
 
@@ -2671,16 +2675,14 @@ class WikiPage implements Page, IDBAccessObject {
        public function insertProtectNullRevision( $revCommentMsg, array $limit,
                array $expiry, $cascade, $reason, $user = null
        ) {
-               global $wgContLang;
                $dbw = wfGetDB( DB_MASTER );
 
                // Prepare a null revision to be added to the history
-               $editComment = $wgContLang->ucfirst(
-                       wfMessage(
-                               $revCommentMsg,
-                               $this->mTitle->getPrefixedText()
-                       )->inContentLanguage()->text()
-               );
+               $editComment = wfMessage(
+                       $revCommentMsg,
+                       $this->mTitle->getPrefixedText(),
+                       $user ? $user->getName() : ''
+               )->inContentLanguage()->text();
                if ( $reason ) {
                        $editComment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $reason;
                }
@@ -2912,6 +2914,7 @@ class WikiPage implements Page, IDBAccessObject {
                // unless they actually try to catch exceptions (which is rare).
 
                // we need to remember the old content so we can use it to generate all deletion updates.
+               $revision = $this->getRevision();
                try {
                        $content = $this->getContent( Revision::RAW );
                } catch ( Exception $ex ) {
@@ -2921,17 +2924,13 @@ class WikiPage implements Page, IDBAccessObject {
                        $content = null;
                }
 
+               $fields = Revision::selectFields();
+               $bitfield = false;
+
                // Bitfields to further suppress the content
                if ( $suppress ) {
-                       $bitfield = 0;
-                       // This should be 15...
-                       $bitfield |= Revision::DELETED_TEXT;
-                       $bitfield |= Revision::DELETED_COMMENT;
-                       $bitfield |= Revision::DELETED_USER;
-                       $bitfield |= Revision::DELETED_RESTRICTED;
-                       $deletionFields = [ $dbw->addQuotes( $bitfield ) . ' AS deleted' ];
-               } else {
-                       $deletionFields = [ 'rev_deleted AS deleted' ];
+                       $bitfield = Revision::SUPPRESSED_ALL;
+                       $fields = array_diff( $fields, [ 'rev_deleted' ] );
                }
 
                // For now, shunt the revision data into the archive table.
@@ -2942,10 +2941,9 @@ class WikiPage implements Page, IDBAccessObject {
                // the rev_deleted field, which is reserved for this purpose.
 
                // Get all of the page revisions
-               $fields = array_diff( Revision::selectFields(), [ 'rev_deleted' ] );
                $res = $dbw->select(
                        'revision',
-                       array_merge( $fields, $deletionFields ),
+                       $fields,
                        [ 'rev_page' => $id ],
                        __METHOD__,
                        'FOR UPDATE'
@@ -2968,7 +2966,7 @@ class WikiPage implements Page, IDBAccessObject {
                                'ar_flags'      => '',
                                'ar_len'        => $row->rev_len,
                                'ar_page_id'    => $id,
-                               'ar_deleted'    => $row->deleted,
+                               'ar_deleted'    => $suppress ? $bitfield : $row->rev_deleted,
                                'ar_sha1'       => $row->rev_sha1,
                        ];
                        if ( $wgContentHandlerUseDB ) {
@@ -3011,7 +3009,7 @@ class WikiPage implements Page, IDBAccessObject {
 
                $dbw->endAtomic( __METHOD__ );
 
-               $this->doDeleteUpdates( $id, $content );
+               $this->doDeleteUpdates( $id, $content, $revision );
 
                Hooks::run( 'ArticleDeleteComplete', [
                        &$wikiPageBeforeDelete,
@@ -3058,11 +3056,12 @@ class WikiPage implements Page, IDBAccessObject {
         * Do some database updates after deletion
         *
         * @param int $id The page_id value of the page being deleted
-        * @param Content $content Optional page content to be used when determining
+        * @param Content|null $content Optional page content to be used when determining
         *   the required updates. This may be needed because $this->getContent()
         *   may already return null when the page proper was deleted.
+        * @param Revision|null $revision The latest page revision
         */
-       public function doDeleteUpdates( $id, Content $content = null ) {
+       public function doDeleteUpdates( $id, Content $content = null, Revision $revision = null ) {
                try {
                        $countable = $this->isCountable();
                } catch ( Exception $ex ) {
@@ -3090,6 +3089,9 @@ class WikiPage implements Page, IDBAccessObject {
 
                // Clear caches
                WikiPage::onArticleDelete( $this->mTitle );
+               ResourceLoaderWikiModule::invalidateModuleCache(
+                       $this->mTitle, $revision, null, wfWikiID()
+               );
 
                // Reset this object and the Title object
                $this->loadFromRow( false, self::READ_LATEST );