Reverting r16861; incompatible change to message texts, breaks a lot of toggle displa...
[lhc/web/wiklou.git] / includes / Article.php
index 402bced..8c07b06 100644 (file)
@@ -4,11 +4,6 @@
  * @package MediaWiki
  */
 
-/**
- * Need the CacheManager to be loaded
- */
-require_once( 'CacheManager.php' );
-
 /**
  * Class representing a MediaWiki article and history.
  *
@@ -146,25 +141,9 @@ class Article {
        function getContent() {
                global $wgRequest, $wgUser, $wgOut;
 
-               # Get variables from query string :P
-               $action = $wgRequest->getText( 'action', 'view' );
-               $section = $wgRequest->getText( 'section' );
-               $preload = $wgRequest->getText( 'preload' );
-
                wfProfileIn( __METHOD__ );
 
                if ( 0 == $this->getID() ) {
-                       if ( 'edit' == $action ) {
-                               wfProfileOut( __METHOD__ );
-
-                               # If requested, preload some text.
-                               $text=$this->getPreloadedText($preload);
-
-                               # We used to put MediaWiki:Newarticletext here if
-                               # $text was empty at this point.
-                               # This is now shown above the edit box instead.
-                               return $text;
-                       }
                        wfProfileOut( __METHOD__ );
                        $wgOut->setRobotpolicy( 'noindex,nofollow' );
 
@@ -177,51 +156,11 @@ class Article {
                        return "<div class='noarticletext'>$ret</div>";
                } else {
                        $this->loadContent();
-                       if($action=='edit') {
-                               if($section!='') {
-                                       if($section=='new') {
-                                               wfProfileOut( __METHOD__ );
-                                               $text=$this->getPreloadedText($preload);
-                                               return $text;
-                                       }
-
-                                       # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
-                                       # comments to be stripped as well)
-                                       $rv=$this->getSection($this->mContent,$section);
-                                       wfProfileOut( __METHOD__ );
-                                       return $rv;
-                               }
-                       }
                        wfProfileOut( __METHOD__ );
                        return $this->mContent;
                }
        }
 
-       /**
-        * Get the contents of a page from its title and remove includeonly tags
-        *
-        * @param $preload String: the title of the page.
-        * @return string The contents of the page.
-        */
-       function getPreloadedText($preload) {
-               if ( $preload === '' )
-                       return '';
-               else {
-                       $preloadTitle = Title::newFromText( $preload );
-                       if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
-                               $rev=Revision::newFromTitle($preloadTitle);
-                               if ( is_object( $rev ) ) {
-                                       $text = $rev->getText();
-                                       // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing
-                                       // its own mini-parser! -ævar
-                                       $text = preg_replace( '~</?includeonly>~', '', $text );
-                                       return $text;
-                               } else
-                                       return '';
-                       }
-               }
-       }
-
        /**
         * This function returns the text of a section, specified by a number ($section).
         * A section is text under a heading like == Heading == or \<h1\>Heading\</h1\>, or
@@ -232,6 +171,7 @@ class Article {
         * @param $text String: text to look in
         * @param $section Integer: section number
         * @return string text of the requested section
+        * @deprecated
         */
        function getSection($text,$section) {
                global $wgParser;
@@ -278,6 +218,7 @@ class Article {
                        # unused:
                        # $lastid = $oldid;
                }
+
                if ( !$oldid ) {
                        $oldid = 0;
                }
@@ -705,15 +646,16 @@ class Article {
                # diff page instead of the article.
 
                if ( !is_null( $diff ) ) {
-                       require_once( 'DifferenceEngine.php' );
                        $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
 
                        $de = new DifferenceEngine( $this->mTitle, $oldid, $diff, $rcid );
                        // DifferenceEngine directly fetched the revision:
                        $this->mRevIdFetched = $de->mNewid;
                        $de->showDiffPage();
-
-                       if( $diff == 0 ) {
+                       
+                       // Needed to get the page's current revision
+                       $this->loadPageData();
+                       if( $diff == 0 || $diff == $this->mLatest ) {
                                # Run view updates for current revision only
                                $this->viewUpdates();
                        }
@@ -735,6 +677,7 @@ class Article {
                                return;
                        }
                }
+
                # Should the parser cache be used?
                $pcache = $wgEnableParserCache &&
                        intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 &&
@@ -772,6 +715,7 @@ class Article {
                $outputDone = false;
                if ( $pcache ) {
                        if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
+                               wfRunHooks( 'ArticleViewHeader', array( &$this ) );
                                $outputDone = true;
                        }
                }
@@ -857,13 +801,13 @@ class Article {
                                # Display content, don't attempt to save to parser cache
                                # Don't show section-edit links on old revisions... this way lies madness.
                                if( !$this->isCurrent() ) {
-                                       $oldEditSectionSetting = $wgOut->mParserOptions->setEditSection( false );
+                                       $oldEditSectionSetting = $wgOut->parserOptions()->setEditSection( false );
                                }
                                # Display content and don't save to parser cache
                                $wgOut->addPrimaryWikiText( $text, $this, false );
 
                                if( !$this->isCurrent() ) {
-                                       $wgOut->mParserOptions->setEditSection( $oldEditSectionSetting );
+                                       $wgOut->parserOptions()->setEditSection( $oldEditSectionSetting );
                                }
                        }
                }
@@ -939,7 +883,7 @@ class Article {
                }
 
                if ((!$wgUser->isAllowed('delete'))) {
-                       $wgOut->sysopRequired();
+                       $wgOut->permissionRequired( 'delete' );
                        return;
                }
 
@@ -1269,7 +1213,7 @@ class Article {
 
                # Silently ignore EDIT_MINOR if not allowed
                $isminor = ( $flags & EDIT_MINOR ) && $wgUser->isAllowed('minoredit');
-               $bot = $wgUser->isBot() || ( $flags & EDIT_FORCE_BOT );
+               $bot = $wgUser->isAllowed( 'bot' ) || ( $flags & EDIT_FORCE_BOT );
 
                $text = $this->preSaveTransform( $text );
 
@@ -1354,7 +1298,8 @@ class Article {
                                Article::onArticleEdit( $this->mTitle );
                                
                                # Update links tables, site stats, etc.
-                               $this->editUpdates( $text, $summary, $isminor, $now, $revisionId );
+                               $changed = ( strcmp( $oldtext, $text ) != 0 );
+                               $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, $changed );
                        }
                } else {
                        # Create new article
@@ -1396,7 +1341,7 @@ class Article {
                        $dbw->commit();
 
                        # Update links, etc.
-                       $this->editUpdates( $text, $summary, $isminor, $now, $revisionId );
+                       $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, true );
 
                        # Clear caches
                        Article::onArticleCreate( $this->mTitle );
@@ -1499,7 +1444,7 @@ class Article {
                        $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
                        $wgOut->setRobotpolicy( 'noindex,nofollow' );
 
-                       $link = $this->mTitle->getPrefixedText();
+                       $link = wfEscapeWikiText( $this->mTitle->getPrefixedText() );
                        $text = wfMsg( 'addedwatchtext', $link );
                        $wgOut->addWikiText( $text );
                }
@@ -1519,7 +1464,6 @@ class Article {
                
                if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
                        $wgUser->addWatch( $this->mTitle );
-                       $wgUser->saveSettings();
 
                        return wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
                }
@@ -1547,7 +1491,7 @@ class Article {
                        $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
                        $wgOut->setRobotpolicy( 'noindex,nofollow' );
 
-                       $link = $this->mTitle->getPrefixedText();
+                       $link = wfEscapeWikiText( $this->mTitle->getPrefixedText() );
                        $text = wfMsg( 'removedwatchtext', $link );
                        $wgOut->addWikiText( $text );
                }
@@ -1567,7 +1511,6 @@ class Article {
 
                if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
                        $wgUser->removeWatch( $this->mTitle );
-                       $wgUser->saveSettings();
 
                        return wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
                }
@@ -1579,7 +1522,6 @@ class Article {
         * action=protect handler
         */
        function protect() {
-               require_once 'ProtectionForm.php';
                $form = new ProtectionForm( $this );
                $form->show();
        }
@@ -1693,7 +1635,7 @@ class Article {
 
                # Check permissions
                if( $wgUser->isAllowed( 'delete' ) ) {
-                       if( $wgUser->isBlocked() ) {
+                       if( $wgUser->isBlocked( !$confirm ) ) {
                                $wgOut->blockedPage();
                                return;
                        }
@@ -1894,7 +1836,7 @@ class Article {
 
                if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
                        if ( $this->doDeleteArticle( $reason ) ) {
-                               $deleted = $this->mTitle->getPrefixedText();
+                               $deleted = wfEscapeWikiText( $this->mTitle->getPrefixedText() );
 
                                $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
                                $wgOut->setRobotpolicy( 'noindex,nofollow' );
@@ -1962,29 +1904,35 @@ class Article {
                );
 
                # Now that it's safely backed up, delete it
-               $dbw->delete( 'revision', array( 'rev_page' => $id ), __METHOD__ );
                $dbw->delete( 'page', array( 'page_id' => $id ), __METHOD__);
 
-               if ($wgUseTrackbacks)
-                       $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), __METHOD__ );
+               # If using cascading deletes, we can skip some explicit deletes
+               if ( !$dbw->cascadingDeletes() ) {
 
-               # Clean up recentchanges entries...
-               $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), __METHOD__ );
+                       $dbw->delete( 'revision', array( 'rev_page' => $id ), __METHOD__ );
 
-               # Finally, clean up the link tables
-               $t = $this->mTitle->getPrefixedDBkey();
+                       if ($wgUseTrackbacks)
+                               $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), __METHOD__ );
+
+                       # Delete outgoing links
+                       $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
+                       $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
+                       $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
+                       $dbw->delete( 'templatelinks', array( 'tl_from' => $id ) );
+                       $dbw->delete( 'externallinks', array( 'el_from' => $id ) );
+                       $dbw->delete( 'langlinks', array( 'll_from' => $id ) );
+               }
+
+               # If using cleanup triggers, we can skip some manual deletes
+               if ( !$dbw->cleanupTriggers() ) {
+
+                       # Clean up recentchanges entries...
+                       $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), __METHOD__ );
+               }
 
                # Clear caches
                Article::onArticleDelete( $this->mTitle );
 
-               # Delete outgoing links
-               $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
-               $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
-               $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
-               $dbw->delete( 'templatelinks', array( 'tl_from' => $id ) );
-               $dbw->delete( 'externallinks', array( 'el_from' => $id ) );
-               $dbw->delete( 'langlinks', array( 'll_from' => $id ) );
-
                # Log the deletion
                $log = new LogPage( 'delete' );
                $log->addEntry( 'delete', $this->mTitle, $reason );
@@ -2137,9 +2085,14 @@ class Article {
         * Every 1000th edit, prune the recent changes table.
         * 
         * @private
-        * @param string $text
-        */
-       function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid) {
+        * @param $text New text of the article
+        * @param $summary Edit summary
+        * @param $minoredit Minor edit
+        * @param $timestamp_of_pagechange Timestamp associated with the page change
+        * @param $newid rev_id value of the new revision
+        * @param $changed Whether or not the content actually changed
+        */
+       function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid, $changed = true ) {
                global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgParser;
 
                wfProfileIn( __METHOD__ );
@@ -2186,8 +2139,9 @@ class Article {
                array_push( $wgDeferredUpdateList, $u );
 
                # If this is another user's talk page, update newtalk
-
-               if ($this->mTitle->getNamespace() == NS_USER_TALK && $shortTitle != $wgUser->getName()) {
+               # Don't do this if $changed = false otherwise some idiot can null-edit a
+               # load of user talk pages and piss people off
+               if( $this->mTitle->getNamespace() == NS_USER_TALK && $shortTitle != $wgUser->getTitleKey() && $changed ) {
                        if (wfRunHooks('ArticleEditUpdateNewTalk', array(&$this)) ) {
                                $other = User::newFromName( $shortTitle );
                                if( is_null( $other ) && User::isIP( $shortTitle ) ) {
@@ -2207,6 +2161,22 @@ class Article {
 
                wfProfileOut( __METHOD__ );
        }
+       
+       /**
+        * Perform article updates on a special page creation.
+        *
+        * @param Revision $rev
+        *
+        * @fixme This is a shitty interface function. Kill it and replace the
+        * other shitty functions like editUpdates and such so it's not needed
+        * anymore.
+        */
+       function createUpdates( $rev ) {
+               $this->mGoodAdjustment = $this->isCountable( $rev->getText() );
+               $this->mTotalAdjustment = 1;
+               $this->editUpdates( $rev->getText(), $rev->getComment(),
+                       $rev->isMinor(), wfTimestamp(), $rev->getId(), true );
+       }
 
        /**
         * Generate the navigation links when browsing through an article revisions
@@ -2220,6 +2190,10 @@ class Article {
        function setOldSubtitle( $oldid=0 ) {
                global $wgLang, $wgOut, $wgUser;
 
+               if ( !wfRunHooks( 'DisplayOldSubtitle', array(&$this, &$oldid) ) ) {
+                               return; 
+               }       
+
                $revision = Revision::newFromId( $oldid );
 
                $current = ( $oldid == $this->mLatest );
@@ -2232,14 +2206,20 @@ class Article {
                $prevlink = $prev
                        ? $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid )
                        : wfMsg( 'previousrevision' );
+               $prevdiff = $prev
+                       ? $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'diff' ), 'diff=prev&oldid='.$oldid )
+                       : wfMsg( 'diff' );
                $nextlink = $current
                        ? wfMsg( 'nextrevision' )
                        : $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
+               $nextdiff = $current
+                       ? wfMsg( 'diff' )
+                       : $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'diff' ), 'diff=next&oldid='.$oldid );
                
                $userlinks = $sk->userLink( $revision->getUser(), $revision->getUserText() )
                                                . $sk->userToolLinks( $revision->getUser(), $revision->getUserText() );
                
-               $r = wfMsg( 'oldrevisionnavigation', $td, $lnk, $prevlink, $nextlink, $userlinks );
+               $r = wfMsg( 'old-revision-navigation', $td, $lnk, $prevlink, $nextlink, $userlinks, $prevdiff, $nextdiff );
                $wgOut->setSubtitle( $r );
        }
 
@@ -2264,7 +2244,7 @@ class Article {
        function tryFileCache() {
                static $called = false;
                if( $called ) {
-                       wfDebug( " tryFileCache() -- called twice!?\n" );
+                       wfDebug( "Article::tryFileCache(): called twice!?\n" );
                        return;
                }
                $called = true;
@@ -2272,15 +2252,15 @@ class Article {
                        $touched = $this->mTouched;
                        $cache = new CacheManager( $this->mTitle );
                        if($cache->isFileCacheGood( $touched )) {
-                               wfDebug( " tryFileCache() - about to load\n" );
+                               wfDebug( "Article::tryFileCache(): about to load file\n" );
                                $cache->loadFromFileCache();
                                return true;
                        } else {
-                               wfDebug( " tryFileCache() - starting buffer\n" );
+                               wfDebug( "Article::tryFileCache(): starting buffer\n" );
                                ob_start( array(&$cache, 'saveToFileCache' ) );
                        }
                } else {
-                       wfDebug( " tryFileCache() - not cacheable\n" );
+                       wfDebug( "Article::tryFileCache(): not cacheable\n" );
                }
        }