Reverting for now this undiscussed and problematic change:
[lhc/web/wiklou.git] / includes / Article.php
index 57a1fe0..41b6b60 100644 (file)
@@ -81,11 +81,12 @@ class Article {
         * @return Return the text of this revision
        */
        function getContent( $noredir ) {
-               global $wgRequest, $wgUser;
+               global $wgRequest, $wgUser, $wgOut;
 
                # Get variables from query string :P
                $action = $wgRequest->getText( 'action', 'view' );
                $section = $wgRequest->getText( 'section' );
+               $preload = $wgRequest->getText( 'preload' );
 
                $fname =  'Article::getContent';
                wfProfileIn( $fname );
@@ -93,9 +94,17 @@ class Article {
                if ( 0 == $this->getID() ) {
                        if ( 'edit' == $action ) {
                                wfProfileOut( $fname );
-                               return ''; # was "newarticletext", now moved above the box)
+
+                               # 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( $fname );
+                       $wgOut->setRobotpolicy( 'noindex,nofollow' );
                        return wfMsg( 'noarticletext' );
                } else {
                        $this->loadContent( $noredir );
@@ -111,7 +120,8 @@ class Article {
                                        if($section!='') {
                                                if($section=='new') {
                                                        wfProfileOut( $fname );
-                                                       return '';
+                                                       $text=$this->getPreloadedText($preload);
+                                                       return $text;
                                                }
 
                                                # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
@@ -127,6 +137,24 @@ 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.
+       */
+       function getPreloadedText($preload) {
+               if($preload) {
+                       $preloadTitle=Title::newFromText($preload);
+                       if(isset($preloadTitle) && $preloadTitle->userCanRead()) {
+                       $rev=Revision::newFromTitle($preloadTitle);
+                       if($rev) {
+                               return $rev->getText();
+                               }
+                       }
+               }
+               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
@@ -459,10 +487,11 @@ class Article {
         */
        function &getDB() {
                #if ( $this->mForUpdate ) {
-                       return wfGetDB( DB_MASTER );
+                       $ret =& wfGetDB( DB_MASTER );
                #} else {
-               #       return wfGetDB( DB_SLAVE );
+               #       $ret =& wfGetDB( DB_SLAVE );
                #}
+               return $ret;
        }
 
        /**
@@ -649,7 +678,7 @@ class Article {
        function view() {
                global $wgUser, $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgLang;
                global $wgLinkCache, $IP, $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol;
-               global $wgEnotif, $wgParser, $wgParserCache;
+               global $wgEnotif, $wgParser, $wgParserCache, $wgUseTrackbacks;
                $sk = $wgUser->getSkin();
 
                $fname = 'Article::view';
@@ -806,6 +835,10 @@ class Article {
                         );
                }
 
+               # Trackbacks
+               if ($wgUseTrackbacks)
+                       $this->addTrackbacks();
+
                # Put link titles into the link cache
                $wgOut->transformBuffer();
 
@@ -816,6 +849,68 @@ class Article {
                wfProfileOut( $fname );
        }
 
+       function addTrackbacks() {
+               global $wgOut, $wgUser;
+
+               $dbr = wfGetDB(DB_SLAVE);
+               $tbs = $dbr->select(
+                               /* FROM   */ 'trackbacks',
+                               /* SELECT */ array('tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name'),
+                               /* WHERE  */ array('tb_page' => $this->getID())
+               );
+
+               if (!$dbr->numrows($tbs))
+                       return;
+
+               $tbtext = "";
+               while ($o = $dbr->fetchObject($tbs)) {
+                       $rmvtext = "";
+                       if ($wgUser->isSysop()) {
+                               $delurl = $this->mTitle->getFullURL("action=deletetrackback&tbid="
+                                               . $o->tb_id . "&token=" . $wgUser->editToken());
+                               $rmvtxt = wfMsg('trackbackremove', $delurl);
+                       }
+                       $tbtext .= wfMsg(strlen($o->tb_ex) ? 'trackbackexcerpt' : 'trackback',
+                                       $o->tb_title,
+                                       $o->tb_url,
+                                       $o->tb_ex,
+                                       $o->tb_name,
+                                       $rmvtxt);
+               }
+               $wgOut->addWikitext(wfMsg('trackbackbox', $tbtext));
+       }
+
+       function deletetrackback() {
+               global $wgUser, $wgRequest, $wgOut, $wgTitle;
+
+               if (!$wgUser->matchEditToken($wgRequest->getVal('token'))) {
+                       $wgOut->addWikitext(wfMsg('sessionfailure'));
+                       return;
+               }
+
+               if ((!$wgUser->isAllowed('delete'))) {
+                       $wgOut->sysopRequired();
+                       return;
+               }
+
+               if (wfReadOnly()) {
+                       $wgOut->readOnlyPage();
+                       return;
+               }
+
+               $db = wfGetDB(DB_MASTER);
+               $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid')));
+               $wgTitle->invalidateCache();
+               $wgOut->addWikiText(wfMsg('trackbackdeleteok'));
+       }
+
+       function render() {
+               global $wgOut;
+
+               $wgOut->setArticleBodyOnly(true);
+               $this->view();
+       }
+
        /**
         * Insert a new empty page record for this article.
         * This *must* be followed up by creating a revision
@@ -932,7 +1027,7 @@ class Article {
         * errors at some point.
         * @private
         */
-       function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false ) {
+       function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
                global $wgOut, $wgUser;
                global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
 
@@ -943,6 +1038,11 @@ class Article {
 
                $ns = $this->mTitle->getNamespace();
                $ttl = $this->mTitle->getDBkey();
+
+               # If this is a comment, add the summary as headline
+               if($comment && $summary!="") {
+                       $text="== {$summary} ==\n\n".$text;
+               }
                $text = $this->preSaveTransform( $text );
                $isminor = ( $isminor && $wgUser->isLoggedIn() ) ? 1 : 0;
                $now = wfTimestampNow();
@@ -1087,7 +1187,7 @@ class Article {
        function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
                global $wgOut, $wgUser;
                global $wgDBtransactions, $wgMwRedir;
-               global $wgUseSquid, $wgInternalServer, $wgPostCommitUpdateList;
+               global $wgUseSquid, $wgInternalServer, $wgPostCommitUpdateList, $wgUseFileCache;
 
                $fname = 'Article::updateArticle';
                $good = true;
@@ -1192,6 +1292,12 @@ class Article {
                                array_push( $wgPostCommitUpdateList, $u );
                        }
 
+                       # File cache
+                       if ( $wgUseFileCache ) {
+                               $cm = new CacheManager($this->mTitle);
+                               @unlink($cm->fileCacheName());
+                       }
+
                        $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision );
                }
                return $good;
@@ -1725,7 +1831,8 @@ class Article {
         */
        function doDeleteArticle( $reason ) {
                global $wgUser;
-               global  $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer, $wgPostCommitUpdateList;
+               global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer, $wgPostCommitUpdateList;
+               global $wgUseTrackbacks;
 
                $fname = 'Article::doDeleteArticle';
                wfDebug( $fname."\n" );
@@ -1791,6 +1898,9 @@ class Article {
                $dbw->delete( 'revision', array( 'rev_page' => $id ), $fname );
                $dbw->delete( 'page', array( 'page_id' => $id ), $fname);
 
+               if ($wgUseTrackbacks)
+                       $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), $fname );
+
                # Clean up recentchanges entries...
                $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
 
@@ -1996,8 +2106,13 @@ class Article {
                                        $u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(), $shortTitle, $summary,
                                          $minoredit, $timestamp_of_pagechange);
                                } else {
-                                       $other = User::newFromName($shortTitle);
-                                       if ($other) {
+                                       $other = User::newFromName( $shortTitle );
+                                       if( is_null( $other ) && User::isIP( $shortTitle ) ) {
+                                               // An anonymous user
+                                               $other = new User();
+                                               $other->setName( $shortTitle );
+                                       }
+                                       if( $other ) {
                                                $other->setNewtalk(1);
                                                $other->saveNewtalk();
                                        }
@@ -2351,9 +2466,6 @@ class Article {
                $db->freeResult( $res );
                return $result;
        }
-
-
 }
 
-
 ?>