namespace 8 bug fix
[lhc/web/wiklou.git] / includes / Article.php
index 7592c7b..003ae20 100644 (file)
@@ -186,7 +186,13 @@ class Article {
                $this->mContentLoaded = true;
        }
 
-       function getID() { return $this->mTitle->getArticleID(); }
+       function getID() {
+               if( $this->mTitle ) {
+                       return $this->mTitle->getArticleID();
+               } else {
+                       return 0;
+               }
+       }
 
        function getCount()
        {
@@ -314,8 +320,6 @@ class Article {
                        $s = wfMsg( "redirectedfrom", $redir );
                        $wgOut->setSubtitle( $s );
                }
-               $wgOut->checkLastModified( $this->mTouched );
-               $this->tryFileCache();
                $wgLinkCache->preFill( $this->mTitle );
                $wgOut->addWikiText( $text );
 
@@ -335,6 +339,8 @@ class Article {
                
                $fname = "Article::insertNewArticle";
 
+               $this->mCountAdjustment = $this->isCountable( $text );
+
                $ns = $this->mTitle->getNamespace();
                $ttl = $this->mTitle->getDBkey();
                $text = $this->preSaveTransform( $text );
@@ -487,22 +493,15 @@ class Article {
                        $sql = "UPDATE recentchanges SET rc_cur_time='{$now}' " .
                          "WHERE rc_cur_id=" . $this->getID();
                        wfQuery( $sql, DB_WRITE, $fname );
-                       
-                       if ( $wgEnablePersistentLC ) {
 
-                               // Purge link cache for this page 
+                       global $wgEnablePersistentLC;
+                       if ( $wgEnablePersistentLC ) {
+                               // Purge link cache for this page
                                $pageid=$this->getID();
                                wfQuery("DELETE FROM linkscc WHERE lcc_pageid='{$pageid}'", DB_WRITE);
-
-                               // This next query just makes sure stub colored links to this page 
-                               // are updated correctly (I think). If performance is more important
-                               // than real-time updating of stub links, we really should skip
-                               // this query.
-                               wfQuery("DELETE linkscc FROM linkscc,links ".
-                                       "WHERE lcc_title=links.l_from AND l_to={$pageid}", DB_WRITE);
-                       }
-
+                       }                       
                }
+
                if( $wgDBtransactions ) {
                        $sql = "COMMIT";
                        wfQuery( $sql, DB_WRITE );
@@ -720,7 +719,7 @@ class Article {
                        return;
                }
 
-               if ( $wpConfirm ) {
+               if ( $_POST["wpConfirm"] ) {
                        $this->doDelete();
                        return;
                }
@@ -728,15 +727,18 @@ class Article {
                # determine whether this page has earlier revisions
                # and insert a warning if it does
                # we select the text because it might be useful below
-               $sql="SELECT old_text FROM old WHERE old_namespace=0 and old_title='" . wfStrencode($this->mTitle->getPrefixedDBkey())."' ORDER BY inverse_timestamp LIMIT 1";
-               $res=wfQuery($sql, DB_READ, $fname);
+               $ns = $this->mTitle->getNamespace();
+               $title = $this->mTitle->getDBkey();
+               $etitle = wfStrencode( $title );
+               $sql = "SELECT old_text FROM old WHERE old_namespace=$ns and old_title='$etitle' ORDER BY inverse_timestamp LIMIT 1";
+               $res = wfQuery( $sql, DB_READ, $fname );
                if( ($old=wfFetchObject($res)) && !$wpConfirm ) {
                        $skin=$wgUser->getSkin();
                        $wgOut->addHTML("<B>".wfMsg("historywarning"));
                        $wgOut->addHTML( $skin->historyLink() ."</B><P>");
                }
 
-               $sql="SELECT cur_text FROM cur WHERE cur_namespace=0 and cur_title='" . wfStrencode($this->mTitle->getPrefixedDBkey())."'";
+               $sql="SELECT cur_text FROM cur WHERE cur_namespace=$ns and cur_title='$etitle'";
                $res=wfQuery($sql, DB_READ, $fname);
                if( ($s=wfFetchObject($res))) {
 
@@ -786,6 +788,7 @@ class Article {
        function confirmDelete( $par = "" )
        {
                global $wgOut;
+               global $wpReason;
 
                wfDebug( "Article::confirmDelete\n" );
                
@@ -805,7 +808,7 @@ class Article {
 <form id=\"deleteconfirm\" method=\"post\" action=\"{$formaction}\">
 <table border=0><tr><td align=right>
 {$delcom}:</td><td align=left>
-<input type=text size=60 name=\"wpReason\" value=\"{$wpReason}\">
+<input type=text size=60 name=\"wpReason\" value=\"" . htmlspecialchars( $wpReason ) . "\">
 </td></tr><tr><td>&nbsp;</td></tr>
 <tr><td align=right>
 <input type=checkbox name=\"wpConfirm\" value='1' id=\"wpConfirm\">
@@ -843,7 +846,8 @@ class Article {
 
        function doDeleteArticle( $title )
        {
-               global $wgUser, $wgOut, $wgLang, $wpReason, $wgDeferredUpdateList;
+               global $wgUser, $wgOut, $wgLang, $wpReason, $wgDeferredUpdateList, 
+                       $wgEnablePersistentLC;
 
                $fname = "Article::doDeleteArticle";
                wfDebug( "$fname\n" );
@@ -1012,6 +1016,11 @@ class Article {
                $wgOut->addHTML( "<h2>" . $newcomment . "</h2>\n<hr>\n" );
                $this->updateArticle( $s->old_text, $newcomment, 1, $this->mTitle->userIsWatching() );
 
+               global $wgEnablePersistentLC;
+               if ( $wgEnablePersistentLC ) {
+                       wfQuery("DELETE FROM linkscc WHERE lcc_pageid='{$pid}'", DB_WRITE);
+               }
+       
                $wgOut->returnToMain( false );
        }
        
@@ -1065,13 +1074,13 @@ class Article {
                          $this->mTitle->getDBkey() );
                        array_push( $wgDeferredUpdateList, $u );
 
-                       if ( $this->getNamespace == NS_MEDIAWIKI ) {
+                       if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
                                $messageCache = $wgMemc->get( "$wgDBname:messages" );
                                if (!$messageCache) {
                                        $messageCache = wfLoadAllMessages();
                                }
                                $messageCache[$title] = $text;
-                               $wgMemc->set( "$wgDBname:messages" );
+                               $wgMemc->set( "$wgDBname:messages", $messageCache, 86400 );
                        }
                }
        }
@@ -1165,6 +1174,12 @@ class Article {
        /* Caching functions */
        
        function tryFileCache() {
+               static $called = false;
+               if( $called ) {
+                       wfDebug( " tryFileCache() -- called twice!?\n" );
+                       return;
+               }
+               $called = true;
                if($this->isFileCacheable()) {
                        $touched = $this->mTouched;
                        if( strpos( $this->mContent, "{{" ) !== false ) {