useless call
[lhc/web/wiklou.git] / includes / Article.php
index df9589c..5d86ccf 100644 (file)
@@ -142,7 +142,8 @@ class Article {
        /**
                This function accepts a title string as parameter
                ($preload). If this string is non-empty, it attempts
-               to fetch the current revision text.
+               to fetch the current revision text. It respects
+               <includeonly>.
        */
        function getPreloadedText($preload) {
                if($preload) {
@@ -150,7 +151,9 @@ class Article {
                        if(isset($preloadTitle) && $preloadTitle->userCanRead()) {
                        $rev=Revision::newFromTitle($preloadTitle);
                        if($rev) {
-                               return $rev->getText();
+                               $text=$rev->getText();
+                               $text=preg_replace('/<\/?includeonly>/i','',$text);
+                               return $text;
                                }
                        }
                }
@@ -421,15 +424,17 @@ class Article {
                                                return false;
                                        }
                                }
-                               $redirData = $this->pageDataFromTitle( $dbr, $rt );
-                               if( $redirData ) {
-                                       $redirRev = Revision::newFromId( $redirData->page_latest );
-                                       if( !is_null( $redirRev ) ) {
-                                               $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
-                                               $this->mTitle = $rt;
-                                               $data = $redirData;
-                                               $this->loadPageData( $data );
-                                               $revision = $redirRev;
+                               if( $rt->getInterwiki() == '' ) {
+                                       $redirData = $this->pageDataFromTitle( $dbr, $rt );
+                                       if( $redirData ) {
+                                               $redirRev = Revision::newFromId( $redirData->page_latest );
+                                               if( !is_null( $redirRev ) ) {
+                                                       $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
+                                                       $this->mTitle = $rt;
+                                                       $data = $redirData;
+                                                       $this->loadPageData( $data );
+                                                       $revision = $redirRev;
+                                               }
                                        }
                                }
                        }
@@ -671,9 +676,9 @@ class Article {
         * the given title.
        */
        function view() {
-               global $wgUser, $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgLang;
-               global $wgLinkCache, $IP, $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol;
-               global $wgEnotif, $wgParser, $wgParserCache, $wgUseTrackbacks;
+               global $wgUser, $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgContLang;
+               global $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol, $wgParser;
+               global $wgParserCache, $wgUseTrackbacks;
                $sk = $wgUser->getSkin();
 
                $fname = 'Article::view';
@@ -693,7 +698,7 @@ class Article {
                        require_once( 'DifferenceEngine.php' );
                        $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
 
-                       $de = new DifferenceEngine( $oldid, $diff, $rcid );
+                       $de = new DifferenceEngine( $this->mTitle, $oldid, $diff, $rcid );
                        // DifferenceEngine directly fetched the revision:
                        $this->mRevIdFetched = $de->mNewid;
                        $de->showDiffPage();
@@ -749,14 +754,21 @@ class Article {
                                $this->setOldSubtitle( isset($this->mOldId) ? $this->mOldId : $oldid );
                                $wgOut->setRobotpolicy( 'noindex,follow' );
                        }
+                       $wasRedirected = false;
                        if ( '' != $this->mRedirectedFrom ) {
                                if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
                                        $sk = $wgUser->getSkin();
                                        $redir = $sk->makeKnownLink( $this->mRedirectedFrom, '', 'redirect=no' );
                                        $s = wfMsg( 'redirectedfrom', $redir );
                                        $wgOut->setSubtitle( $s );
-                                       # Can't cache redirects
-                                       $pcache = false;
+                                       
+                                       // Check the parser cache again, for the target page
+                                       if( $pcache ) {
+                                               if( $wgOut->tryParserCache( $this, $wgUser ) ) {
+                                                       $outputDone = true;
+                                               }
+                                       }
+                                       $wasRedirected = true;
                                }
                        } elseif ( !empty( $rdfrom ) ) {
                                global $wgRedirectSources;
@@ -765,9 +777,11 @@ class Article {
                                        $redir = $sk->makeExternalLink( $rdfrom, $rdfrom );
                                        $s = wfMsg( 'redirectedfrom', $redir );
                                        $wgOut->setSubtitle( $s );
+                                       $wasRedirected = true;
                                }
                        }
-
+               }
+               if( !$outputDone ) {
                        # 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 (
@@ -778,7 +792,11 @@ class Article {
                                $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent)."\n</pre>" );
                        } else if ( $rt = Title::newFromRedirect( $text ) ) {
                                # Display redirect
-                               $imageUrl = $wgStylePath.'/common/images/redirect.png';
+                               $imageDir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
+                               $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
+                               if( !$wasRedirected ) {
+                                       $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) );
+                               }
                                $targetUrl = $rt->escapeLocalURL();
                                $titleText = htmlspecialchars( $rt->getPrefixedText() );
                                $link = $sk->makeLinkObj( $rt );
@@ -792,6 +810,7 @@ class Article {
                                $skin = $wgUser->getSkin();
                        } else if ( $pcache ) {
                                # Display content and save to parser cache
+                               $wgOut->setRevisionId( $this->getRevIdFetched() );
                                $wgOut->addPrimaryWikiText( $text, $this );
                        } else {
                                # Display content, don't attempt to save to parser cache
@@ -800,6 +819,7 @@ class Article {
                                if( !$this->isCurrent() ) {
                                        $oldEditSectionSetting = $wgOut->mParserOptions->setEditSection( false );
                                }
+                               $wgOut->setRevisionId( $this->getRevIdFetched() );
                                $wgOut->addWikiText( $text );
 
                                if( !$this->isCurrent() ) {
@@ -905,6 +925,38 @@ class Article {
                $wgOut->setArticleBodyOnly(true);
                $this->view();
        }
+       
+       function purge() {
+               global $wgUser, $wgRequest, $wgOut, $wgUseSquid;
+
+               if ( $wgUser->isLoggedIn() || $wgRequest->wasPosted() ) {
+                       // Invalidate the cache
+                       $this->mTitle->invalidateCache();
+
+                       if ( $wgUseSquid ) {
+                               // Commit the transaction before the purge is sent
+                               $dbw = wfGetDB( DB_MASTER );
+                               $dbw->immediateCommit();
+
+                               // Send purge
+                               $update = SquidUpdate::newSimplePurge( $this->mTitle );
+                               $update->doUpdate();
+                       }
+                       $this->view();
+               } else {
+                       $msg = $wgOut->parse( wfMsg( 'confirm_purge' ) );
+                       $action = $this->mTitle->escapeLocalURL( 'action=purge' );
+                       $button = htmlspecialchars( wfMsg( 'confirm_purge_button' ) );
+                       $msg = str_replace( '$1', 
+                               "<form method=\"post\" action=\"$action\">\n" .
+                               "<input type=\"submit\" name=\"submit\" value=\"$button\" />\n" .
+                               "</form>\n", $msg );
+
+                       $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
+                       $wgOut->setRobotpolicy( 'noindex,nofollow' );
+                       $wgOut->addHTML( $msg );
+               }
+       }
 
        /**
         * Insert a new empty page record for this article.
@@ -934,6 +986,7 @@ class Article {
                        'page_random'       => wfRandom(),
                        'page_touched'      => $dbw->timestamp(),
                        'page_latest'       => 0, # Fill this in shortly...
+                       'page_len'          => 0, # Fill this in shortly...
                ), $fname );
                $newid = $dbw->insertId();
 
@@ -1024,8 +1077,7 @@ class Article {
         * @private
         */
        function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
-               global $wgOut, $wgUser;
-               global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
+               global $wgOut, $wgUser, $wgUseSquid;
 
                $fname = 'Article::insertNewArticle';
                wfProfileIn( $fname );
@@ -1096,7 +1148,7 @@ class Article {
                $this->editUpdates( $text, $summary, $isminor, $now );
 
                $oldid = 0; # new article
-               $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid );
+               $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid, $revisionId );
 
                wfRunHooks( 'ArticleSaveComplete', array( &$this, &$wgUser, $text,
                        $summary, $isminor,
@@ -1108,6 +1160,9 @@ class Article {
                $this->replaceSection( $section, $text, $summary, $edittime );
        }
 
+       /**
+        * @return string Complete article text, or null if error
+        */
        function replaceSection($section, $text, $summary = '', $edittime = NULL) {
                $fname = 'Article::replaceSection';
                wfProfileIn( $fname );
@@ -1119,6 +1174,11 @@ class Article {
                                $dbw =& wfGetDB( DB_MASTER );
                                $rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime );
                        }
+                       if( is_null( $rev ) ) {
+                               wfDebug( "Article::replaceSection asked for bogus section (page: " .
+                                       $this->getId() . "; section: $section; edittime: $edittime)\n" );
+                               return null;
+                       }
                        $oldtext = $rev->getText();
 
                        if($section=='new') {
@@ -1202,9 +1262,8 @@ class Article {
         * first set $wgUser, and clean up $wgDeferredUpdates after each edit.
         */
        function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
-               global $wgOut, $wgUser;
-               global $wgDBtransactions, $wgMwRedir;
-               global $wgUseSquid, $wgInternalServer, $wgPostCommitUpdateList, $wgUseFileCache;
+               global $wgOut, $wgUser, $wgDBtransactions, $wgMwRedir, $wgUseSquid;
+               global $wgPostCommitUpdateList, $wgUseFileCache;
 
                $fname = 'Article::updateArticle';
                wfProfileIn( $fname );
@@ -1337,7 +1396,7 @@ class Article {
                                @unlink($cm->fileCacheName());
                        }
 
-                       $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision );
+                       $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision, $revisionId );
                }
                wfRunHooks( 'ArticleSaveComplete',
                        array( &$this, &$wgUser, $text,
@@ -1351,7 +1410,7 @@ class Article {
         * After we've either updated or inserted the article, update
         * the link tables and redirect to the new page.
         */
-       function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
+       function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid, $newid ) {
                global $wgUseDumbLinkUpdate, $wgAntiLockFlags, $wgOut, $wgUser, $wgLinkCache, $wgEnotif;
                global $wgUseEnotif;
 
@@ -1368,14 +1427,11 @@ class Article {
                        }
                }
 
-               # Parse the text and replace links with placeholders
+               # Parse the text and save it to the parser cache
                $wgOut = new OutputPage();
-
-               # Pass the current title along in case we're creating a wiki page
-               # which is different than the currently displayed one (e.g. image
-               # pages created on file uploads); otherwise, link updates will
-               # go wrong.
-               $wgOut->addWikiTextWithTitle( $text, $this->mTitle );
+               $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
+               $wgOut->setRevisionId( $newid );
+               $wgOut->addPrimaryWikiText( $text, $this );
 
                if ( !$wgUseDumbLinkUpdate ) {
                        # Move the current links back to the second register
@@ -1689,7 +1745,7 @@ class Article {
         * UI entry point for page deletion
         */
        function delete() {
-               global $wgUser, $wgOut, $wgMessageCache, $wgRequest;
+               global $wgUser, $wgOut, $wgRequest;
                $fname = 'Article::delete';
                $confirm = $wgRequest->wasPosted() &&
                        $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
@@ -1877,9 +1933,8 @@ class Article {
         * Returns success
         */
        function doDeleteArticle( $reason ) {
-               global $wgUser;
-               global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer, $wgPostCommitUpdateList;
-               global $wgUseTrackbacks;
+               global $wgUser, $wgUseSquid, $wgDeferredUpdateList;
+               global $wgPostCommitUpdateList, $wgUseTrackbacks;
 
                $fname = 'Article::doDeleteArticle';
                wfDebug( $fname."\n" );
@@ -2061,15 +2116,17 @@ class Article {
                        );
                }
 
-               # Save it!
+               # Get the edit summary
                $target = Revision::newFromId( $s->rev_id );
-               $newcomment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
+               $newComment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
+               $newComment = $wgRequest->getText( 'summary', $newComment );
 
+               # Save it!
                $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
                $wgOut->setRobotpolicy( 'noindex,nofollow' );
-               $wgOut->addHTML( '<h2>' . htmlspecialchars( $newcomment ) . "</h2>\n<hr />\n" );
+               $wgOut->addHTML( '<h2>' . htmlspecialchars( $newComment ) . "</h2>\n<hr />\n" );
 
-               $this->updateArticle( $target->getText(), $newcomment, 1, $this->mTitle->userIsWatching(), $bot );
+               $this->updateArticle( $target->getText(), $newComment, 1, $this->mTitle->userIsWatching(), $bot );
                Article::onArticleEdit( $this->mTitle );
 
                $dbw->commit();
@@ -2120,11 +2177,9 @@ class Article {
         * @param string $text
         */
        function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange) {
-               global $wgDeferredUpdateList, $wgDBname, $wgMemc;
-               global $wgMessageCache, $wgUser, $wgUseEnotif;
+               global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgUseEnotif;
 
-               
-               if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', &$this ) ) {
+               if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
                        wfSeedRandom();
                        if ( 0 == mt_rand( 0, 999 ) ) {
                                # Periodically flush old entries from the recentchanges table.