* (bug 1765) Tidy causes corruption inside <gallery>
[lhc/web/wiklou.git] / includes / Article.php
index 7dd7584..1b83657 100644 (file)
@@ -34,6 +34,7 @@ class Article {
        var $mId, $mTable;
        var $mForUpdate;
        var $mOldId;
+       var $mRevIdFetched;
        /**#@-*/
 
        /**
@@ -58,13 +59,17 @@ class Article {
          * @private
          */
        function clear() {
+               $this->mDataLoaded    = false;
                $this->mContentLoaded = false;
+               
                $this->mCurID = $this->mUser = $this->mCounter = -1; # Not loaded
                $this->mRedirectedFrom = $this->mUserText =
                $this->mTimestamp = $this->mComment = $this->mFileCache = '';
                $this->mCountAdjustment = 0;
                $this->mTouched = '19700101000000';
                $this->mForUpdate = false;
+               $this->mIsRedirect = false;
+               $this->mRevIdFetched = false;
        }
 
        /**
@@ -298,6 +303,25 @@ class Article {
                        'page_id' => IntVal( $id ) ) );
        }
        
+       /**
+        * Set the general counter, title etc data loaded from
+        * some source.
+        *
+        * @param object $data
+        * @access private
+        */
+       function loadPageData( $data ) {
+               $this->mTitle->mRestrictions = explode( ',', trim( $data->page_restrictions ) );
+               $this->mTitle->mRestrictionsLoaded = true;
+               
+               $this->mCounter    = $data->page_counter;
+               $this->mTouched    = wfTimestamp( TS_MW, $data->page_touched );
+               $this->mIsRedirect = $data->page_is_redirect;
+               $this->mLatest     = $data->page_latest;
+               
+               $this->mDataLoaded = true;
+       }
+       
        /**
         * Get text of an article from database
         * @param int $oldid 0 for whatever the latest revision is
@@ -327,16 +351,30 @@ class Article {
                if( $oldid ) {
                        $revision = Revision::newFromId( $oldid );
                        if( is_null( $revision ) ) {
+                               wfDebug( "$fname failed to retrieve specified revision, id $oldid\n" );
                                return false;
                        }
                        $data = $this->pageDataFromId( $dbr, $revision->getPage() );
                        if( !$data ) {
+                               wfDebug( "$fname failed to get page data linked to revision id $oldid\n" );
                                return false;
                        }
                        $this->mTitle = Title::makeTitle( $data->page_namespace, $data->page_title );
+                       $this->loadPageData( $data );
                } else {
-                       $data = $this->pageDataFromTitle( $dbr, $this->mTitle );
-                       $revision = Revision::newFromId( $data->page_latest );
+                       if( !$this->mDataLoaded ) {
+                               $data = $this->pageDataFromTitle( $dbr, $this->mTitle );
+                               if( !$data ) {
+                                       wfDebug( "$fname failed to find page data for title " . $this->mTitle->getPrefixedText() . "\n" );
+                                       return false;
+                               }
+                               $this->loadPageData( $data );
+                       }
+                       $revision = Revision::newFromId( $this->mLatest );
+                       if( is_null( $revision ) ) {
+                               wfDebug( "$fname failed to retrieve current page, rev_id $data->page_latest\n" );
+                               return false;
+                       }
                }
 
                # If we got a redirect, follow it (unless we've been told
@@ -367,6 +405,7 @@ class Article {
                                                $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
                                                $this->mTitle = $rt;
                                                $data = $redirData;
+                                               $this->loadPageData( $data );
                                                $revision = $redirRev;
                                        }
                                }
@@ -382,11 +421,6 @@ class Article {
                }
                
                # Back to the business at hand...
-               $this->mCounter   = $data->page_counter;
-               $this->mTitle->mRestrictions = explode( ',', trim( $data->page_restrictions ) );
-               $this->mTitle->mRestrictionsLoaded = true;
-               $this->mTouched   = wfTimestamp( TS_MW, $data->page_touched );
-
                $this->mContent   = $revision->getText();
                
                $this->mUser      = $revision->getUser();
@@ -394,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;
        }
 
@@ -487,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 );
                }
@@ -543,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';
@@ -735,10 +776,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 );
                
@@ -748,7 +790,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(),
@@ -842,7 +884,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;
 
@@ -875,7 +917,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();
@@ -1205,10 +1249,26 @@ class Article {
         * Validate function
         */
        function validate() {
-               global $wgOut, $wgUser;
+               global $wgOut, $wgUser, $wgRequest, $wgUseValidation;
+               
+               if ( !$wgUseValidation ) # Are we using article validation at all?
+               {
+                       $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
+                       return ;
+               }
+               
                $wgOut->setRobotpolicy( 'noindex,follow' );
+               $revision = $wgRequest->getVal( 'revision' );
+               
+               include_once ( "SpecialValidate.php" ) ; # The "Validation" class
                
-               $wgOut->addWikiText ( "Not implemented yet" ) ;
+               $v = new Validation ;
+               if ( $wgRequest->getVal ( "mode" , "" ) == "list" )
+                       $t = $v->showList ( $this ) ;
+               else
+                       $t = $v->validatePageForm ( $this , $revision ) ;
+               
+               $wgOut->addHTML ( $t ) ;
        }
 
        /**
@@ -1393,9 +1453,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( "
@@ -1403,7 +1460,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> " );
@@ -1417,7 +1474,7 @@ class Article {
                </tr>
        </table>
        <input type='hidden' name='wpEditToken' value=\"{$token}\" />
-</form>\n" );
+</form>" );
 
                $wgOut->returnToMain( false );
        }
@@ -1571,9 +1628,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>
@@ -1995,16 +2049,14 @@ class Article {
         */
        function checkTouched() {
                $fname = 'Article::checkTouched';
-               $id = $this->getID();
-               $dbr =& $this->getDB();
-               $s = $dbr->selectRow( 'page', array( 'page_touched', 'page_is_redirect' ),
-                       array( 'page_id' => $id ), $fname, $this->getSelectOptions() );
-               if( $s !== false ) {
-                       $this->mTouched = wfTimestamp( TS_MW, $s->page_touched );
-                       return !$s->page_is_redirect;
-               } else {
-                       return false;
+               if( !$this->mDataLoaded ) {
+                       $dbr =& $this->getDB();
+                       $data = $this->pageDataFromId( $dbr, $this->getId() );
+                       if( $data ) {
+                               $this->loadPageData( $data );
+                       }
                }
+               return !$this->mIsRedirect;
        }
 
        /**