New feature, nicer display of redirects. Removed special case for redirects from...
[lhc/web/wiklou.git] / includes / Article.php
index bfe325a..cca2bb0 100644 (file)
@@ -153,7 +153,7 @@ class Article {
                                                        # Try to open, return false on failure
                                                        $params = $wgKnownDBServers[$machineId];
                                                        $db = Database::newFromParams( $params['server'], $params['user'], $params['password'],
-                                                               $dbName, 1, false, true, true );
+                                                               $dbName, 1, DBO_IGNORE );
                                                }
                                        }
                                        if ( $db->isOpen() ) {
@@ -218,17 +218,14 @@ class Article {
                        return wfMsg( 'noarticletext' );
                } else {
                        $this->loadContent( $noredir );
-
-                       if(
-                               # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
-                               ( $this->mTitle->getNamespace() == Namespace::getTalk( Namespace::getUser()) ) &&
-                                 preg_match('/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/',$this->mTitle->getText()) &&
-                                 $action=='view'
-                               )
-                               {
+                       # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
+                       if ( $this->mTitle->getNamespace() == NS_USER_TALK &&
+                         preg_match('/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/',$this->mTitle->getText()) &&
+                         $action=='view'
+                       ) {
                                wfProfileOut( $fname );
-                               return $this->mContent . "\n" .wfMsg('anontalkpagetext'); }
-                       else {
+                               return $this->mContent . "\n" .wfMsg('anontalkpagetext'); 
+                       else {
                                if($action=='edit') {
                                        if($section!='') {
                                                if($section=='new') {
@@ -332,7 +329,7 @@ class Article {
                }
                return $wgArticleOldContentFields;
        }
-
+                               
        # Load the revision (including cur_text) into this object
        function loadContent( $noredir = false )
        {
@@ -371,33 +368,29 @@ class Article {
 
                        # If we got a redirect, follow it (unless we've been told
                        # not to by either the function parameter or the query
-                       if ( ( 'no' != $redirect ) && ( false == $noredir ) &&
-                         ( $wgMwRedir->matchStart( $s->cur_text ) ) ) {
-                               if ( preg_match( '/\\[\\[([^\\]\\|]+)[\\]\\|]/',
-                                 $s->cur_text, $m ) ) {
-                                       $rt = Title::newFromText( $m[1] );
-                                       if( $rt ) {
-                                               # Gotta hand redirects to special pages differently:
-                                               # Fill the HTTP response "Location" header and ignore
-                                               # the rest of the page we're on.
-
-                                               if ( $rt->getInterwiki() != '' ) {
-                                                       $wgOut->redirect( $rt->getFullURL() ) ;
-                                                       return;
-                                               }
-                                               if ( $rt->getNamespace() == Namespace::getSpecial() ) {
-                                                       $wgOut->redirect( $rt->getFullURL() );
-                                                       return;
-                                               }
-                                               $rid = $rt->getArticleID();
-                                               if ( 0 != $rid ) {
-                                                       $redirRow = $dbr->getArray( 'cur', $this->getCurContentFields(), array( 'cur_id' => $rid ), $fname );
-
-                                                       if ( $redirRow !== false ) {
-                                                               $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
-                                                               $this->mTitle = $rt;
-                                                               $s = $redirRow;
-                                                       }
+                       if ( ( 'no' != $redirect ) && ( false == $noredir ) ) {
+                               $rt = Title::newFromRedirect( $s->cur_text );
+                               if ( $rt ) {
+                                       # Gotta hand redirects to special pages differently:
+                                       # Fill the HTTP response "Location" header and ignore
+                                       # the rest of the page we're on.
+
+                                       if ( $rt->getInterwiki() != '' ) {
+                                               $wgOut->redirect( $rt->getFullURL() ) ;
+                                               return;
+                                       }
+                                       if ( $rt->getNamespace() == NS_SPECIAL ) {
+                                               $wgOut->redirect( $rt->getFullURL() );
+                                               return;
+                                       }
+                                       $rid = $rt->getArticleID();
+                                       if ( 0 != $rid ) {
+                                               $redirRow = $dbr->getArray( 'cur', $this->getCurContentFields(), array( 'cur_id' => $rid ), $fname );
+
+                                               if ( $redirRow !== false ) {
+                                                       $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
+                                                       $this->mTitle = $rt;
+                                                       $s = $redirRow;
                                                }
                                        }
                                }
@@ -461,20 +454,17 @@ class Article {
 
                        # If we got a redirect, follow it (unless we've been told
                        # not to by either the function parameter or the query
-                       if ( !$noredir && $wgMwRedir->matchStart( $s->cur_text ) ) {
-                               if ( preg_match( '/\\[\\[([^\\]\\|]+)[\\]\\|]/',
-                                 $s->cur_text, $m ) ) {
-                                       $rt = Title::newFromText( $m[1] );
-                                       if( $rt &&  $rt->getInterwiki() == '' && $rt->getNamespace() != Namespace::getSpecial() ) {
-                                               $rid = $rt->getArticleID();
-                                               if ( 0 != $rid ) {
-                                                       $redirRow = $dbr->getArray( 'cur', $this->getCurContentFields(), array( 'cur_id' => $rid ), $fname );
-
-                                                       if ( $redirRow !== false ) {
-                                                               $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
-                                                               $this->mTitle = $rt;
-                                                               $s = $redirRow;
-                                                       }
+                       if ( !$noredir ) {
+                               $rt = Title::newFromRedirect( $s->cur_text );
+                               if( $rt &&  $rt->getInterwiki() == '' && $rt->getNamespace() != NS_SPECIAL ) {
+                                       $rid = $rt->getArticleID();
+                                       if ( 0 != $rid ) {
+                                               $redirRow = $dbr->getArray( 'cur', $this->getCurContentFields(), array( 'cur_id' => $rid ), $fname );
+
+                                               if ( $redirRow !== false ) {
+                                                       $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
+                                                       $this->mTitle = $rt;
+                                                       $s = $redirRow;
                                                }
                                        }
                                }
@@ -634,8 +624,8 @@ class Article {
 
        function view()
        {
-               global $wgUser, $wgOut, $wgLang, $wgRequest;
-               global $wgLinkCache, $IP, $wgEnableParserCache;
+               global $wgUser, $wgOut, $wgLang, $wgRequest, $wgMwRedir;
+               global $wgLinkCache, $IP, $wgEnableParserCache, $wgStylePath;
 
                $fname = 'Article::view';
                wfProfileIn( $fname );
@@ -655,6 +645,10 @@ class Article {
                        $de = new DifferenceEngine( intval($oldid), intval($diff) );
                        $de->showDiffPage();
                        wfProfileOut( $fname );
+                       if( $diff == 0 ) {
+                               # Run view updates for current revision only
+                               $this->viewUpdates();
+                       }
                        return;
                }
 
@@ -711,19 +705,28 @@ class Article {
                                $pcache = false;
                        }
 
-                       $wgLinkCache->preFill( $this->mTitle );
-
                        # wrap user css and user js in pre and don't parse
                        # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
                        if (
-                               $this->mTitle->getNamespace() == Namespace::getUser() &&
+                               $this->mTitle->getNamespace() == NS_USER &&
                                preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle->getDBkey())
                        ) {
                                $wgOut->addWikiText( wfMsg('clearyourcache'));
                                $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent)."\n</pre>" );
+                       } else if ( $rt = Title::newFromRedirect( $text ) ) {
+                               # Display redirect
+                               $sk = $wgUser->getSkin();
+                               $imageUrl = "$wgStylePath/images/redirect.png";
+                               $targetUrl = $rt->escapeLocalURL();
+                               $titleText = htmlspecialchars( $rt->getPrefixedText() );
+                               $link = $sk->makeLinkObj( $rt );
+                               $wgOut->addHTML( "<img valign=\"center\" src=\"$imageUrl\">" .
+                                 "<span class=\"redirectText\">$link</span>" );
                        } else if ( $pcache ) {
+                               # Display content and save to parser cache
                                $wgOut->addWikiText( $text, true, $this );
                        } else {
+                               # Display content, don't attempt to save to parser cache
                                $wgOut->addWikiText( $text );
                        }
                }
@@ -743,7 +746,7 @@ class Article {
 
        /* private */ function insertNewArticle( $text, $summary, $isminor, $watchthis )
        {
-               global $wgOut, $wgUser, $wgLinkCache, $wgMwRedir;
+               global $wgOut, $wgUser, $wgMwRedir;
                global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
 
                $fname = 'Article::insertNewArticle';
@@ -888,7 +891,7 @@ class Article {
 
        function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' )
        {
-               global $wgOut, $wgUser, $wgLinkCache;
+               global $wgOut, $wgUser;
                global $wgDBtransactions, $wgMwRedir;
                global $wgUseSquid, $wgInternalServer;
                
@@ -1036,7 +1039,11 @@ class Article {
                # Get old version of link table to allow incremental link updates
                $wgLinkCache->preFill( $this->mTitle );
                $wgLinkCache->clear();
-
+               
+               # Switch on use of link cache in the skin
+               $sk =& $wgUser->getSkin();
+               $sk->postParseLinkColour( false );
+               
                # Now update the link cache by parsing the text
                $wgOut = new OutputPage();
                $wgOut->addWikiText( $text );
@@ -1053,11 +1060,15 @@ class Article {
        function validate ()
        {
                global $wgOut ;
-               $v = new Validation ;
-               $html = $v->validate_form ( $this->mTitle->getDBkey() ) ;               
-               $wgOut->setPagetitle( wfMsg( 'validate' ) . " : " . $this->mTitle->getText()  );
+               $wgOut->setPagetitle( wfMsg( 'validate' ) . " : " . $this->mTitle->getPrefixedText()  );
                $wgOut->setRobotpolicy( 'noindex,follow' );
-               $wgOut->addHTML( $html ) ;
+               if ( $this->mTitle->getNamespace() != 0 )
+                       {
+                       $wgOut->addHTML ( wfMsg ( 'val_validate_article_namespace_only' ) ) ;
+                       return ;
+                       }
+               $v = new Validation ;
+               $v->validate_form ( $this->mTitle->getDBkey() ) ;               
        }
 
        # Add this page to my watchlist
@@ -1095,7 +1106,7 @@ class Article {
                $up = new UserUpdate();
                array_push( $wgDeferredUpdateList, $up );
 
-               $wgOut->returnToMain( false );
+               $wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
        }
 
        function unwatch()
@@ -1393,8 +1404,7 @@ class Article {
                        $wgOut->setRobotpolicy( 'noindex,nofollow' );
 
                        $sk = $wgUser->getSkin();
-                       $loglink = $sk->makeKnownLink( $wgLang->getNsText(
-                         Namespace::getWikipedia() ) .
+                       $loglink = $sk->makeKnownLink( $wgLang->getNsText( NS_WIKIPEDIA ) .
                          ':' . wfMsg( 'dellogpage' ), wfMsg( 'deletionlog' ) );
 
                        $text = wfMsg( "deletedtext", $deleted, $loglink );
@@ -1509,7 +1519,7 @@ class Article {
                        $linkID = $titleObj->getArticleID();
                        $brokenLinks[] = array( 'bl_from' => $linkID, 'bl_to' => $t );
                }
-               $dbw->insertArray( 'brokenlinks', $brokenLinks, $fname );
+               $dbw->insert( 'brokenlinks', $brokenLinks, $fname, 'IGNORE' );
                
                # Delete live links
                $dbw->delete( 'links', array( 'l_to' => $id ) );
@@ -1632,10 +1642,10 @@ class Article {
                                $u = new SiteStatsUpdate( 1, 0, 0 );
                                array_push( $wgDeferredUpdateList, $u );
                        }
-                       $u = new UserTalkUpdate( 0, $this->mTitle->getNamespace(),
-                         $this->mTitle->getDBkey() );
-                       array_push( $wgDeferredUpdateList, $u );
                }
+               $u = new UserTalkUpdate( 0, $this->mTitle->getNamespace(),
+                 $this->mTitle->getDBkey() );
+               array_push( $wgDeferredUpdateList, $u );
        }
 
        # Do standard deferred updates after page edit.
@@ -1737,7 +1747,7 @@ class Article {
                        and ($this->getID() != 0)
                        and ($wgUser->getId() == 0)
                        and (!$wgUser->getNewtalk())
-                       and ($this->mTitle->getNamespace() != Namespace::getSpecial())
+                       and ($this->mTitle->getNamespace() != NS_SPECIAL )
                        and ($action == 'view' || empty( $action ))
                        and (!isset($oldid))
                        and (!isset($diff))
@@ -1838,14 +1848,14 @@ class Article {
                }
 
                # Not important enough to warrant an error page in case of failure
-               $oldignore = $dbw->setIgnoreErrors( true ); 
+               $oldignore = $dbw->ignoreErrors( true ); 
 
                $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
 
                $checkfreq = intval( $wgHitcounterUpdateFreq/25 + 1 );
                if( (rand() % $checkfreq != 0) or ($dbw->lastErrno() != 0) ){
                        # Most of the time (or on SQL errors), skip row count check
-                       $dbw->setIgnoreErrors( $oldignore );
+                       $dbw->ignoreErrors( $oldignore );
                        return;
                }
 
@@ -1869,7 +1879,7 @@ class Article {
                        ignore_user_abort( $old_user_abort );
                        wfProfileOut( 'Article::incViewCount-collect' );
                }
-               $dbw->setIgnoreErrors( $oldignore );
+               $dbw->ignoreErrors( $oldignore );
        }
 
        # The onArticle*() functions are supposed to be a kind of hooks