BUG#1860 - Anchors of interwiki links did not get normalized
[lhc/web/wiklou.git] / includes / Article.php
index b931449..c7f9649 100644 (file)
@@ -34,6 +34,7 @@ class Article {
        var $mId, $mTable;
        var $mForUpdate;
        var $mOldId;
+       var $mRevIdFetched;
        /**#@-*/
 
        /**
@@ -68,6 +69,7 @@ class Article {
                $this->mTouched = '19700101000000';
                $this->mForUpdate = false;
                $this->mIsRedirect = false;
+               $this->mRevIdFetched = 0;
        }
 
        /**
@@ -426,7 +428,9 @@ class Article {
                $this->mComment   = $revision->getComment();
                $this->mTimestamp = wfTimestamp( TS_MW, $revision->getTimestamp() );
                
+               $this->mRevIdFetched = $revision->getID();
                $this->mContentLoaded = true;
+               
                return $this->mContent;
        }
 
@@ -519,7 +523,7 @@ class Article {
        function isRedirect( $text = false ) {
                if ( $text === false ) {
                        $this->loadContent();
-                       $titleObj = Title::newFromRedirect( $this->mText );
+                       $titleObj = Title::newFromRedirect( $this->fetchRevisionText() );
                } else {
                        $titleObj = Title::newFromRedirect( $text );
                }
@@ -575,6 +579,11 @@ class Article {
                $this->loadLastEdit();
                return $this->mMinorEdit;
        }
+       
+       function getRevIdFetched() {
+               $this->loadLastEdit();
+               return $this->mRevIdFetched;
+       }
 
        function getContributors($limit = 0, $offset = 0) {
                $fname = 'Article::getContributors';
@@ -637,8 +646,12 @@ class Article {
                if ( !is_null( $diff ) ) {
                        require_once( 'DifferenceEngine.php' );
                        $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
+                       
                        $de = new DifferenceEngine( $oldid, $diff, $rcid );
+                       // DifferenceEngine directly fetched the revision:
+                       $this->mRevIdFetched = $de->mNewid;
                        $de->showDiffPage();
+
                        if( $diff == 0 ) {
                                # Run view updates for current revision only
                                $this->viewUpdates();
@@ -737,7 +750,12 @@ class Article {
                                $wgOut->addWikiText( $text );
                        }
                }
-               $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
+               /* title may have been set from the cache */
+               $t = $wgOut->getPageTitle();    
+               if( empty( $t ) ) {
+                       $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
+               }
+
                # If we have been passed an &rcid= parameter, we want to give the user a
                # chance to mark this new article as patrolled.
                if ( $wgUseRCPatrol && !is_null ( $rcid ) && $rcid != 0 && $wgUser->isLoggedIn() &&
@@ -767,10 +785,11 @@ class Article {
         * Best if all done inside a transaction.
         *
         * @param Database $dbw
-        * @return int The newly created page_id key
+        * @param string   $restrictions
+        * @return int     The newly created page_id key
         * @access private
         */
-       function insertOn( &$dbw ) {
+       function insertOn( &$dbw, $restrictions = '' ) {
                $fname = 'Article::insertOn';
                wfProfileIn( $fname );
                
@@ -780,7 +799,7 @@ class Article {
                        'page_namespace'    => $this->mTitle->getNamespace(),
                        'page_title'        => $this->mTitle->getDBkey(),
                        'page_counter'      => 0,
-                       'page_restrictions' => '',
+                       'page_restrictions' => $restrictions,
                        'page_is_redirect'  => 0, # Will set this shortly...
                        'page_is_new'       => 1,
                        'page_random'       => wfRandom(),
@@ -874,7 +893,7 @@ class Article {
         * errors at some point.
         * @private
         */
-       function insertNewArticle( $text, $summary, $isminor, $watchthis ) {
+       function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false ) {
                global $wgOut, $wgUser;
                global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
 
@@ -886,6 +905,7 @@ class Article {
                $ttl = $this->mTitle->getDBkey();
                $text = $this->preSaveTransform( $text );
                $isminor = ( $isminor && $wgUser->isLoggedIn() ) ? 1 : 0;
+               $now = wfTimestampNow();
 
                $dbw =& wfGetDB( DB_MASTER );
 
@@ -907,7 +927,9 @@ class Article {
                $this->updateRevisionOn( $dbw, $revision, 0 );
 
                Article::onArticleCreate( $this->mTitle );
-               RecentChange::notifyNew( $now, $this->mTitle, $isminor, $wgUser, $summary );
+               if(!$suppressRC) {
+                       RecentChange::notifyNew( $now, $this->mTitle, $isminor, $wgUser, $summary );
+               }
 
                if ($watchthis) {
                        if(!$this->mTitle->userIsWatching()) $this->watch();
@@ -1071,19 +1093,19 @@ class Article {
 
                $text = $this->preSaveTransform( $text );
                $dbw =& wfGetDB( DB_MASTER );
+               $now = wfTimestampNow();
 
                # Update article, but only if changed.
 
                # It's important that we either rollback or complete, otherwise an attacker could
                # overwrite cur entries by sending precisely timed user aborts. Random bored users
                # could conceivably have the same effect, especially if cur is locked for long periods.
-               if( $wgDBtransactions ) {
-                       $dbw->query( 'BEGIN', $fname );
-               } else {
+               if( !$wgDBtransactions ) {
                        $userAbort = ignore_user_abort( true );
                }
 
                $oldtext = $this->getContent( true );
+               $lastRevision = 0;
 
                if ( 0 != strcmp( $text, $oldtext ) ) {
                        $this->mCountAdjustment = $this->isCountable( $text )
@@ -1110,15 +1132,13 @@ class Article {
                        } else {
                                # Update recentchanges and purge cache and whatnot
                                $bot = (int)($wgUser->isBot() || $forceBot);
-                               RecentChange::notifyEdit( $now, $this->mTitle, $me2, $wgUser, $summary,
+                               RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $wgUser, $summary,
                                        $lastRevision, $this->getTimestamp(), $bot );
                                Article::onArticleEdit( $this->mTitle );
                        }
                }
 
-               if( $wgDBtransactions ) {
-                       $dbw->query( 'COMMIT', $fname );
-               } else {
+               if( !$wgDBtransactions ) {
                        ignore_user_abort( $userAbort );
                }
 
@@ -1154,7 +1174,7 @@ class Article {
                                array_push( $wgPostCommitUpdateList, $u );
                        }
        
-                       $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $me2, $now, $summary, $lastRevision );
+                       $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision );
                }
                return $good;
        }
@@ -1251,13 +1271,10 @@ class Article {
                include_once ( "SpecialValidate.php" ) ; # The "Validation" class
                
                $v = new Validation ;
-               $t = $v->validatePageForm ( $this , $revision ) ;
-/*             $a = $v->getTopicList () ;
-               $t = "" ;
-               foreach ( $a AS $x => $y ) {
-                       $t .= $x . " : " . $y->val_comment . " (1-" . $y->val_value . ")<br>" ;
-                       }
-               $t .= "Revision {$revision}" ;*/
+               if ( $wgRequest->getVal ( "mode" , "" ) == "list" )
+                       $t = $v->showList ( $this ) ;
+               else
+                       $t = $v->validatePageForm ( $this , $revision ) ;
                
                $wgOut->addHTML ( $t ) ;
        }
@@ -1444,9 +1461,6 @@ class Article {
                        <td align='left'>
                                <input type='text' size='60' name='wpReasonProtect' id='wpReasonProtect' value=\"" . htmlspecialchars( $reason ) . "\" />
                        </td>
-               </tr>
-               <tr>
-                       <td>&nbsp;</td>
                </tr>" );
                if($moveonly != '') {
                        $wgOut->AddHTML( "
@@ -1454,7 +1468,7 @@ class Article {
                        <td align='right'>
                                <input type='checkbox' name='wpMoveOnly' value='1' id='wpMoveOnly' />
                        </td>
-                       <td>
+                       <td align='left'>
                                <label for='wpMoveOnly'>{$moveonly}</label>
                        </td>
                </tr> " );
@@ -1468,7 +1482,7 @@ class Article {
                </tr>
        </table>
        <input type='hidden' name='wpEditToken' value=\"{$token}\" />
-</form>\n" );
+</form>" );
 
                $wgOut->returnToMain( false );
        }
@@ -1622,9 +1636,6 @@ class Article {
                                <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
                        </td>
                </tr>
-               <tr>
-                       <td>&nbsp;</td>
-               </tr>
                <tr>
                        <td>&nbsp;</td>
                        <td>
@@ -2266,6 +2277,35 @@ class Article {
                
                return array( 'edits' => $edits, 'authors' => $authors );
        }
+
+       /**
+        * Return a list of templates used by this article.
+        * Uses the links table to find the templates
+        *
+        * @return array
+        */
+       function getUsedTemplates() {
+               $result = array();
+               $id = $this->mTitle->getArticleID();
+
+               $db =& wfGetDB( DB_SLAVE );
+               $page = $db->tableName( 'page' );
+               $links = $db->tableName( 'links' );
+               $sql = "SELECT page_title ".
+                       "FROM $page,$links WHERE l_to=page_id AND l_from={$id} and page_namespace=".NS_TEMPLATE;
+               $res = $db->query( $sql, "Article:getUsedTemplates" );
+               if ( false !== $res ) {
+                       if ( $db->numRows( $res ) ) {
+                               while ( $row = $db->fetchObject( $res ) ) {
+                                       $result[] = $row->page_title;
+                               }
+                       }
+               }
+               $db->freeResult( $res );
+               return $result;
+       }
+
+
 }