$out is needed here
[lhc/web/wiklou.git] / includes / Article.php
index 10ff075..f49c1c4 100644 (file)
@@ -34,6 +34,7 @@ class Article {
        var $mTouched;                  //!<
        var $mUser;                             //!<
        var $mUserText;                 //!<
+       var $mRedirectTarget;           //!<
        /**@}}*/
 
        /**
@@ -56,12 +57,58 @@ class Article {
                $this->mRedirectedFrom = $from;
        }
 
+       /**
+        * If this page is a redirect, get its target
+        *
+        * The target will be fetched from the redirect table if possible.
+        * If this page doesn't have an entry there, call insertRedirect()
+        * @return mixed Title object, or null if this page is not a redirect
+        */
+       public function getRedirectTarget() {
+               if(!$this->mTitle || !$this->mTitle->isRedirect())
+                       return null;
+               if(!is_null($this->mRedirectTarget))
+                       return $this->mRedirectTarget;
+
+               # Query the redirect table
+               $dbr = wfGetDb(DB_SLAVE);
+               $res = $dbr->select('redirect',
+                               array('rd_namespace', 'rd_title'),
+                               array('rd_from' => $this->getID()),
+                               __METHOD__
+               );
+               $row = $dbr->fetchObject($res);
+               if($row)
+                       return $this->mRedirectTarget = Title::makeTitle($row->rd_namespace, $row->rd_title);
+
+               # This page doesn't have an entry in the redirect table
+               return $this->mRedirectTarget = $this->insertRedirect();
+       }
+
+       /**
+        * Insert an entry for this page into the redirect table.
+        *
+        * Don't call this function directly unless you know what you're doing.
+        * @return Title object
+        */
+       public function insertRedirect() {
+               $retval = Title::newFromRedirect($this->getContent());
+               if(!$retval)
+                       return null;
+               $dbw = wfGetDb(DB_MASTER);
+               $dbw->insert('redirect', array(
+                               'rd_from' => $this->getID(),
+                               'rd_namespace' => $retval->getNamespace(),
+                               'rd_title' => $retval->getDBKey()
+               ));
+               return $retval;
+       }
+
        /**
         * @return mixed false, Title of in-wiki target, or string with URL
         */
        function followRedirect() {
-               $text = $this->getContent();
-               $rt = Title::newFromRedirect( $text );
+               $rt = $this->getRedirectTarget();
 
                # process if title object is valid and not special:userlogout
                if( $rt ) {
@@ -114,6 +161,7 @@ class Article {
 
                $this->mCurID = $this->mUser = $this->mCounter = -1; # Not loaded
                $this->mRedirectedFrom = null; # Title object if set
+               $this->mRedirectTarget = null; # Title object if set
                $this->mUserText =
                $this->mTimestamp = $this->mComment = '';
                $this->mGoodAdjustment = $this->mTotalAdjustment = 0;
@@ -153,7 +201,7 @@ class Article {
                                $ret = wfMsg( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon' );
                        }
 
-                       return "<div class='noarticletext'>$ret</div>";
+                       return "<div class='noarticletext'>\n$ret\n</div>";
                } else {
                        $this->loadContent();
                        wfProfileOut( __METHOD__ );
@@ -303,9 +351,9 @@ class Article {
                        $data = $this->pageDataFromId( $dbr, $this->getId() );
                }
 
-               $lc =& LinkCache::singleton();
+               $lc = LinkCache::singleton();
                if ( $data ) {
-                       $lc->addGoodLinkObj( $data->page_id, $this->mTitle );
+                       $lc->addGoodLinkObj( $data->page_id, $this->mTitle, $data->page_len, $data->page_is_redirect );
 
                        $this->mTitle->mArticleID = $data->page_id;
 
@@ -618,7 +666,7 @@ class Article {
 
                wfProfileIn( __METHOD__ );
 
-               $parserCache =& ParserCache::singleton();
+               $parserCache = ParserCache::singleton();
                $ns = $this->mTitle->getNamespace(); # shortcut
 
                # Get variables from query string
@@ -801,7 +849,7 @@ class Article {
                        
                        }
                        
-                       elseif ( $rt = Title::newFromRedirect( $text ) ) {
+                       elseif ( $rt = $this->getRedirectTarget() ) {
                                # Display redirect
                                $imageDir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
                                $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
@@ -897,6 +945,7 @@ class Article {
                                                . $o->tb_id . "&token=" . urlencode( $wgUser->editToken() ) );
                                $rmvtxt = wfMsg( 'trackbackremove', htmlspecialchars( $delurl ) );
                        }
+                       $tbtext .= "\n";
                        $tbtext .= wfMsg(strlen($o->tb_ex) ? 'trackbackexcerpt' : 'trackback',
                                        $o->tb_title,
                                        $o->tb_url,
@@ -1111,6 +1160,8 @@ class Article {
                                $dbw->delete( 'redirect', $where, __METHOD__);
                        }
 
+                       if( $this->getTitle()->getNamespace() == NS_IMAGE )
+                               RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect( $this->getTitle() );
                        wfProfileOut( __METHOD__ );
                        return ( $dbw->affectedRows() != 0 );
                }
@@ -1367,7 +1418,8 @@ class Article {
                                        'page'       => $this->getId(),
                                        'comment'    => $summary,
                                        'minor_edit' => $isminor,
-                                       'text'       => $text
+                                       'text'       => $text,
+                                       'parent_id'  => $lastRevision
                                        ) );
 
                                $dbw->begin();
@@ -1518,7 +1570,7 @@ class Article {
                # Check patrol config options
 
                if ( !($wgUseNPPatrol || $wgUseRCPatrol)) {
-                       $wgOut->errorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
+                       $wgOut->showErrorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
                        return;         
                }
 
@@ -1527,7 +1579,7 @@ class Article {
                $rc = $rcid ? RecentChange::newFromId($rcid) : null;
                if ( is_null ( $rc ) )
                {
-                       $wgOut->errorPage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
+                       $wgOut->showErrorPage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
                        return;
                }
 
@@ -1535,7 +1587,7 @@ class Article {
                        // Only new pages can be patrolled if the general patrolling is off....???
                        // @fixme -- is this necessary? Shouldn't we only bother controlling the
                        // front end here?
-                       $wgOut->errorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
+                       $wgOut->showErrorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
                        return;
                }
                
@@ -1728,8 +1780,8 @@ class Article {
                $updated = Article::flattenRestrictions( $limit );
 
                $changed = ( $current != $updated );
-               $changed = $changed || ($this->mTitle->areRestrictionsCascading() != $cascade);
-               $changed = $changed || ($this->mTitle->mRestrictionsExpiry != $expiry);
+               $changed = $changed || ($updated && $this->mTitle->areRestrictionsCascading() != $cascade);
+               $changed = $changed || ($updated && $this->mTitle->mRestrictionsExpiry != $expiry);
                $protect = ( $updated != '' );
 
                # If nothing's changed, do nothing
@@ -2155,12 +2207,7 @@ class Article {
         */
        function showLogExtract( $out ) {
                $out->addHtml( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) );
-               $logViewer = new LogViewer(
-                       new LogReader(
-                               new FauxRequest(
-                                       array( 'page' => $this->mTitle->getPrefixedText(),
-                                              'type' => 'delete' ) ) ) );
-               $logViewer->showList( $out );
+               LogEventsList::showLogExtract( $out, 'delete', $this->mTitle->getPrefixedText() );
        }
 
 
@@ -2298,14 +2345,15 @@ class Article {
                # Clear caches
                Article::onArticleDelete( $this->mTitle );
 
-               # Log the deletion, if the page was suppressed, log it at Oversight instead
-               $logtype = $suppress ? 'oversight' : 'delete';
-               $log = new LogPage( $logtype );
-               $log->addEntry( 'delete', $this->mTitle, $reason );
-
                # Clear the cached article id so the interface doesn't act like we exist
                $this->mTitle->resetArticleID( 0 );
                $this->mTitle->mArticleID = 0;
+
+               # Log the deletion, if the page was suppressed, log it at Oversight instead
+               $logtype = $suppress ? 'suppress' : 'delete';
+               $log = new LogPage( $logtype );
+               $log->addEntry( 'delete', $this->mTitle, $reason );
+               
                return true;
        }
 
@@ -2598,7 +2646,7 @@ class Article {
 
                # Save it to the parser cache
                if ( $wgEnableParserCache ) {
-                       $parserCache =& ParserCache::singleton();
+                       $parserCache = ParserCache::singleton();
                        $parserCache->save( $editInfo->output, $this, $wgUser );
                }
 
@@ -2985,6 +3033,15 @@ class Article {
        static function onArticleDelete( $title ) {
                global $wgUseFileCache, $wgMessageCache;
 
+               // Update existence markers on article/talk tabs...
+               if( $title->isTalkPage() ) {
+                       $other = $title->getSubjectPage();
+               } else {
+                       $other = $title->getTalkPage();
+               }
+               $other->invalidateCache();
+               $other->purgeSquid();
+               
                $title->touchLinks();
                $title->purgeSquid();
 
@@ -3288,7 +3345,7 @@ class Article {
                $popts->setTidy(false);
                $popts->enableLimitReport( false );
                if ( $wgEnableParserCache && $cache && $this && $parserOutput->getCacheTime() != -1 ) {
-                       $parserCache =& ParserCache::singleton();
+                       $parserCache = ParserCache::singleton();
                        $parserCache->save( $parserOutput, $this, $wgUser );
                }
 
@@ -3367,6 +3424,10 @@ class Article {
                #
                # Sometimes I wish we had INSERT ... ON DUPLICATE KEY UPDATE.
                $insertCats = array_merge( $added, $deleted );
+               if( !$insertCats ) {
+                       # Okay, nothing to do
+                       return;
+               }
                $insertRows = array();
                foreach( $insertCats as $cat ) {
                        $insertRows[] = array( 'cat_title' => $cat );