Merge "Use current preference overriding for live preview"
[lhc/web/wiklou.git] / includes / WikiPage.php
index f0a58d3..a191983 100644 (file)
@@ -51,7 +51,7 @@ class WikiPage implements Page, IDBAccessObject {
        /**@}}*/
 
        /** @var stdclass Map of cache fields (text, parser output, ect) for a proposed/new edit */
-       protected $mPreparedEdit = false;
+       public $mPreparedEdit = false;
 
        /**
         * @var int
@@ -2794,6 +2794,11 @@ class WikiPage implements Page, IDBAccessObject {
                // Reparse any pages transcluding this page
                LinksUpdate::queueRecursiveJobsForTable( $this->mTitle, 'templatelinks' );
 
+               // Reparse any pages including this image
+               if ( $this->mTitle->getNamespace() == NS_FILE ) {
+                       LinksUpdate::queueRecursiveJobsForTable( $this->mTitle, 'imagelinks' );
+               }
+
                // Clear caches
                WikiPage::onArticleDelete( $this->mTitle );
 
@@ -2918,27 +2923,6 @@ class WikiPage implements Page, IDBAccessObject {
                        return array( array( 'notvisiblerev' ) );
                }
 
-               $set = array();
-               if ( $bot && $guser->isAllowed( 'markbotedits' ) ) {
-                       // Mark all reverted edits as bot
-                       $set['rc_bot'] = 1;
-               }
-
-               if ( $wgUseRCPatrol ) {
-                       // Mark all reverted edits as patrolled
-                       $set['rc_patrolled'] = 1;
-               }
-
-               if ( count( $set ) ) {
-                       $dbw->update( 'recentchanges', $set,
-                               array( /* WHERE */
-                                       'rc_cur_id' => $current->getPage(),
-                                       'rc_user_text' => $current->getUserText(),
-                                       'rc_timestamp > ' . $dbw->addQuotes( $s->rev_timestamp ),
-                               ), __METHOD__
-                       );
-               }
-
                // Generate the edit summary if necessary
                $target = Revision::newFromId( $s->rev_id );
                if ( empty( $summary ) ) {
@@ -2985,6 +2969,27 @@ class WikiPage implements Page, IDBAccessObject {
                        return $status->getErrorsArray();
                }
 
+               $set = array();
+               if ( $bot && $guser->isAllowed( 'markbotedits' ) ) {
+                       // Mark all reverted edits as bot
+                       $set['rc_bot'] = 1;
+               }
+
+               if ( $wgUseRCPatrol ) {
+                       // Mark all reverted edits as patrolled
+                       $set['rc_patrolled'] = 1;
+               }
+
+               if ( count( $set ) ) {
+                       $dbw->update( 'recentchanges', $set,
+                               array( /* WHERE */
+                                       'rc_cur_id' => $current->getPage(),
+                                       'rc_user_text' => $current->getUserText(),
+                                       'rc_timestamp > ' . $dbw->addQuotes( $s->rev_timestamp ),
+                               ), __METHOD__
+                       );
+               }
+
                if ( !empty( $status->value['revision'] ) ) {
                        $revId = $status->value['revision']->getId();
                } else {
@@ -3262,17 +3267,17 @@ class WikiPage implements Page, IDBAccessObject {
                        return;
                }
 
-               // templatelinks table may have become out of sync,
+               // templatelinks or imagelinks tables may have become out of sync,
                // especially if using variable-based transclusions.
                // For paranoia, check if things have changed and if
                // so apply updates to the database. This will ensure
                // that cascaded protections apply as soon as the changes
                // are visible.
 
-               // Get templates from templatelinks
+               // Get templates from templatelinks and images from imagelinks
                $id = $this->getId();
 
-               $tlTemplates = array();
+               $dbLinks = array();
 
                $dbr = wfGetDB( DB_SLAVE );
                $res = $dbr->select( array( 'templatelinks' ),
@@ -3282,21 +3287,35 @@ class WikiPage implements Page, IDBAccessObject {
                );
 
                foreach ( $res as $row ) {
-                       $tlTemplates["{$row->tl_namespace}:{$row->tl_title}"] = true;
+                       $dbLinks["{$row->tl_namespace}:{$row->tl_title}"] = true;
                }
 
-               // Get templates from parser output.
-               $poTemplates = array();
+               $dbr = wfGetDB( DB_SLAVE );
+               $res = $dbr->select( array( 'imagelinks' ),
+                       array( 'il_to' ),
+                       array( 'il_from' => $id ),
+                       __METHOD__
+               );
+
+               foreach ( $res as $row ) {
+                       $dbLinks[NS_FILE . ":{$row->il_to}"] = true;
+               }
+
+               // Get templates and images from parser output.
+               $poLinks = array();
                foreach ( $parserOutput->getTemplates() as $ns => $templates ) {
                        foreach ( $templates as $dbk => $id ) {
-                               $poTemplates["$ns:$dbk"] = true;
+                               $poLinks["$ns:$dbk"] = true;
                        }
                }
+               foreach ( $parserOutput->getImages() as $dbk => $id ) {
+                       $poLinks[NS_FILE . ":$dbk"] = true;
+               }
 
                // Get the diff
-               $templates_diff = array_diff_key( $poTemplates, $tlTemplates );
+               $links_diff = array_diff_key( $poLinks, $dbLinks );
 
-               if ( count( $templates_diff ) > 0 ) {
+               if ( count( $links_diff ) > 0 ) {
                        // Whee, link updates time.
                        // Note: we are only interested in links here. We don't need to get other DataUpdate items from the parser output.
                        $u = new LinksUpdate( $this->mTitle, $parserOutput, false );
@@ -3315,22 +3334,6 @@ class WikiPage implements Page, IDBAccessObject {
                return $this->mTitle->getTemplateLinksFrom();
        }
 
-       /**
-        * Perform article updates on a special page creation.
-        *
-        * @param $rev Revision object
-        *
-        * @todo This is a shitty interface function. Kill it and replace the
-        * other shitty functions like doEditUpdates and such so it's not needed
-        * anymore.
-        * @deprecated since 1.18, use doEditUpdates()
-        */
-       public function createUpdates( $rev ) {
-               wfDeprecated( __METHOD__, '1.18' );
-               global $wgUser;
-               $this->doEditUpdates( $rev, $wgUser, array( 'created' => true ) );
-       }
-
        /**
         * This function is called right before saving the wikitext,
         * so we can do things like signatures and links-in-context.
@@ -3605,12 +3608,12 @@ class PoolWorkArticleView extends PoolCounterWork {
                $this->parserOutput = ParserCache::singleton()->getDirty( $this->page, $this->parserOptions );
 
                if ( $this->parserOutput === false ) {
-                       wfDebugLog( 'dirty', "dirty missing\n" );
+                       wfDebugLog( 'dirty', 'dirty missing' );
                        wfDebug( __METHOD__ . ": no dirty cache\n" );
                        return false;
                } else {
                        wfDebug( __METHOD__ . ": sending dirty output\n" );
-                       wfDebugLog( 'dirty', "dirty output {$this->cacheKey}\n" );
+                       wfDebugLog( 'dirty', "dirty output {$this->cacheKey}" );
                        $this->isDirty = true;
                        return true;
                }