Merge "Made WikiPage::isRedirect() actually use page_is_redirect"
[lhc/web/wiklou.git] / includes / page / WikiPage.php
index c99928a..d3978ea 100644 (file)
@@ -469,12 +469,11 @@ class WikiPage implements Page, IDBAccessObject {
         * @return bool
         */
        public function isRedirect() {
-               $content = $this->getContent();
-               if ( !$content ) {
-                       return false;
+               if ( !$this->mDataLoaded ) {
+                       $this->loadPageData();
                }
 
-               return $content->isRedirect();
+               return (bool)$this->mIsRedirect;
        }
 
        /**
@@ -950,7 +949,6 @@ class WikiPage implements Page, IDBAccessObject {
                if ( $rt->isExternal() ) {
                        if ( $rt->isLocal() ) {
                                // Offsite wikis need an HTTP redirect.
-                               //
                                // 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' );
@@ -964,10 +962,8 @@ class WikiPage implements Page, IDBAccessObject {
 
                if ( $rt->isSpecialPage() ) {
                        // Gotta handle redirects to special pages differently:
-                       // Fill the HTTP response "Location" header and ignore
-                       // the rest of the page we're on.
-                       //
-                       // Some pages are not valid targets
+                       // Fill the HTTP response "Location" header and ignore the rest of the page we're on.
+                       // Some pages are not valid targets.
                        if ( $rt->isValidRedirectTarget() ) {
                                return $rt->getFullURL();
                        } else {
@@ -1434,7 +1430,7 @@ class WikiPage implements Page, IDBAccessObject {
        ) {
                ContentHandler::deprecated( __METHOD__, '1.21' );
 
-               //NOTE: keep condition in sync with condition in replaceSectionContent!
+               // NOTE: keep condition in sync with condition in replaceSectionContent!
                if ( strval( $sectionId ) === '' ) {
                        // Whole-page edit; let the whole text through
                        return $text;
@@ -1811,8 +1807,7 @@ class WikiPage implements Page, IDBAccessObject {
                                }
                                $revisionId = $revision->insertOn( $dbw );
 
-                               // Update page
-                               //
+                               // Update page.
                                // We check for conflicts by comparing $oldid with the current latest revision ID.
                                $ok = $this->updateRevisionOn( $dbw, $revision, $oldid, $oldIsRedirect );
 
@@ -2046,7 +2041,7 @@ class WikiPage implements Page, IDBAccessObject {
                }
 
                $user = is_null( $user ) ? $wgUser : $user;
-               //XXX: check $user->getId() here???
+               // XXX: check $user->getId() here???
 
                // Use a sane default for $serialFormat, see bug 57026
                if ( $serialFormat === null ) {
@@ -2409,6 +2404,7 @@ class WikiPage implements Page, IDBAccessObject {
 
                $logRelationsValues = array();
                $logRelationsField = null;
+               $logParamsDetails = array();
 
                if ( $id ) { // Protection of existing page
                        if ( !Hooks::run( 'ArticleProtect', array( &$this, &$user, $limit, $reason ) ) ) {
@@ -2467,6 +2463,7 @@ class WikiPage implements Page, IDBAccessObject {
                                        __METHOD__
                                );
                                if ( $restrictions != '' ) {
+                                       $cascadeValue = ( $cascade && $action == 'edit' ) ? 1 : 0;
                                        $dbw->insert(
                                                'page_restrictions',
                                                array(
@@ -2474,12 +2471,18 @@ class WikiPage implements Page, IDBAccessObject {
                                                        'pr_page' => $id,
                                                        'pr_type' => $action,
                                                        'pr_level' => $restrictions,
-                                                       'pr_cascade' => ( $cascade && $action == 'edit' ) ? 1 : 0,
+                                                       'pr_cascade' => $cascadeValue,
                                                        'pr_expiry' => $dbw->encodeExpiry( $expiry[$action] )
                                                ),
                                                __METHOD__
                                        );
                                        $logRelationsValues[] = $dbw->insertId();
+                                       $logParamsDetails[] = array(
+                                               'type' => $action,
+                                               'level' => $restrictions,
+                                               'expiry' => $expiry[$action],
+                                               'cascade' => (bool)$cascadeValue,
+                                       );
                                }
                        }
 
@@ -2510,6 +2513,11 @@ class WikiPage implements Page, IDBAccessObject {
                                                'pt_reason' => $reason,
                                        ), __METHOD__
                                );
+                               $logParamsDetails[] = array(
+                                       'type' => 'create',
+                                       'level' => $limit['create'],
+                                       'expiry' => $expiry['create'],
+                               );
                        } else {
                                $dbw->delete( 'protected_titles',
                                        array(
@@ -2527,15 +2535,24 @@ class WikiPage implements Page, IDBAccessObject {
                        $params = array();
                } else {
                        $protectDescriptionLog = $this->protectDescriptionLog( $limit, $expiry );
-                       $params = array( $protectDescriptionLog, $cascade ? 'cascade' : '' );
+                       $params = array(
+                               '4::description' => $protectDescriptionLog, // parameter for IRC
+                               '5:bool:cascade' => $cascade,
+                               'details' => $logParamsDetails, // parameter for localize and api
+                       );
                }
 
                // Update the protection log
-               $log = new LogPage( 'protect' );
-               $logId = $log->addEntry( $logAction, $this->mTitle, $reason, $params, $user );
+               $logEntry = new ManualLogEntry( 'protect', $logAction );
+               $logEntry->setTarget( $this->mTitle );
+               $logEntry->setComment( $reason );
+               $logEntry->setPerformer( $user );
+               $logEntry->setParameters( $params );
                if ( $logRelationsField !== null && count( $logRelationsValues ) ) {
-                       $log->addRelations( $logRelationsField, $logRelationsValues, $logId );
+                       $logEntry->setRelations( array( $logRelationsField => $logRelationsValues ) );
                }
+               $logId = $logEntry->insert();
+               $logEntry->publish( $logId );
 
                return Status::newGood();
        }
@@ -2795,16 +2812,18 @@ class WikiPage implements Page, IDBAccessObject {
                        $bitfield = 'rev_deleted';
                }
 
-               // For now, shunt the revision data into the archive table.
-               // Text is *not* removed from the text table; bulk storage
-               // is left intact to avoid breaking block-compression or
-               // immutable storage schemes.
-               //
-               // For backwards compatibility, note that some older archive
-               // table entries will have ar_text and ar_flags fields still.
-               //
-               // In the future, we may keep revisions and mark them with
-               // the rev_deleted field, which is reserved for this purpose.
+               /**
+                * For now, shunt the revision data into the archive table.
+                * Text is *not* removed from the text table; bulk storage
+                * is left intact to avoid breaking block-compression or
+                * immutable storage schemes.
+                *
+                * For backwards compatibility, note that some older archive
+                * table entries will have ar_text and ar_flags fields still.
+                *
+                * In the future, we may keep revisions and mark them with
+                * the rev_deleted field, which is reserved for this purpose.
+                */
 
                $row = array(
                        'ar_namespace'  => 'page_namespace',
@@ -2911,12 +2930,15 @@ class WikiPage implements Page, IDBAccessObject {
         *   may already return null when the page proper was deleted.
         */
        public function doDeleteUpdates( $id, Content $content = null ) {
-               // update site status
+               // Update site status
                DeferredUpdates::addUpdate( new SiteStatsUpdate( 0, 1, - (int)$this->isCountable(), -1 ) );
 
-               // remove secondary indexes, etc
+               // Delete pagelinks, update secondary indexes, etc
                $updates = $this->getDeletionUpdates( $content );
-               DataUpdate::runUpdates( $updates, 'enqueue' );
+               // Make sure an enqueued jobs run after commit so they see the deletion
+               wfGetDB( DB_MASTER )->onTransactionIdle( function() use ( $updates ) {
+                       DataUpdate::runUpdates( $updates, 'enqueue' );
+               } );
 
                // Reparse any pages transcluding this page
                LinksUpdate::queueRecursiveJobsForTable( $this->mTitle, 'templatelinks' );