Cleanup for r43315 (per aaron's comment): remove extra set of parenthesis
[lhc/web/wiklou.git] / includes / Article.php
index ced850a..f64e9f4 100644 (file)
@@ -816,7 +816,7 @@ class Article {
                                $count = $pager->getNumRows();
                                if( $count > 0 ) {
                                        $pager->mLimit = 10;
-                                       $wgOut->addHtml( '<div id="mw-deleted-notice">' );
+                                       $wgOut->addHTML( '<div class="mw-warning-with-logexcerpt">' );
                                        $wgOut->addWikiMsg( 'deleted-notice' );
                                        $wgOut->addHTML(
                                                $loglist->beginLogEventsList() .
@@ -824,7 +824,7 @@ class Article {
                                                $loglist->endLogEventsList()
                                        );
                                        if($count > 10){
-                                               $wgOut->addHtml( $wgUser->getSkin()->link(
+                                               $wgOut->addHTML( $wgUser->getSkin()->link(
                                                        SpecialPage::getTitleFor( 'Log' ),
                                                        wfMsgHtml( 'deletelog-fulllog' ),
                                                        array(),
@@ -832,7 +832,7 @@ class Article {
                                                                'type' => 'delete',
                                                                'page' => $this->mTitle->getPrefixedText() ) ) );
                                        }
-                                       $wgOut->addHtml( '</div>' );
+                                       $wgOut->addHTML( '</div>' );
                                }
                        }
                        $text = $this->getContent();
@@ -880,15 +880,15 @@ class Article {
 
                         // Pages containing custom CSS or JavaScript get special treatment
                        if( $this->mTitle->isCssOrJsPage() || $this->mTitle->isCssJsSubpage() ) {
-                               $wgOut->addHtml( wfMsgExt( 'clearyourcache', 'parse' ) );
+                               $wgOut->addHTML( wfMsgExt( 'clearyourcache', 'parse' ) );
                                // Give hooks a chance to customise the output
                                if( wfRunHooks( 'ShowRawCssJs', array( $this->mContent, $this->mTitle, $wgOut ) ) ) {
                                        // Wrap the whole lot in a <pre> and don't parse
                                        $m = array();
                                        preg_match( '!\.(css|js)$!u', $this->mTitle->getText(), $m );
-                                       $wgOut->addHtml( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
-                                       $wgOut->addHtml( htmlspecialchars( $this->mContent ) );
-                                       $wgOut->addHtml( "\n</pre>\n" );
+                                       $wgOut->addHTML( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
+                                       $wgOut->addHTML( htmlspecialchars( $this->mContent ) );
+                                       $wgOut->addHTML( "\n</pre>\n" );
                                }
                        } else if ( $rt = Title::newFromRedirect( $text ) ) {
                                # Don't append the subtitle if this was an old revision
@@ -1075,17 +1075,16 @@ class Article {
                                $this->view();
                        }
                } else {
-                       $msg = $wgOut->parse( wfMsg( 'confirm_purge' ) );
-                       $action = htmlspecialchars( $_SERVER['REQUEST_URI'] );
-                       $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 );
-
+                       $action = htmlspecialchars( $wgRequest->getRequestURL() );
+                       $button = wfMsgExt( 'confirm_purge_button', array('escapenoentities') );
+                       $form = "<form method=\"post\" action=\"$action\">\n" .
+                                       "<input type=\"submit\" name=\"submit\" value=\"$button\" />\n" .
+                                       "</form>\n";
+                       $top = wfMsgExt( 'confirm-purge-top', array('parse') );
+                       $bottom = wfMsgExt( 'confirm-purge-bottom', array('parse') );
                        $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
                        $wgOut->setRobotPolicy( 'noindex,nofollow' );
-                       $wgOut->addHTML( $msg );
+                       $wgOut->addHTML( $top . $form . $bottom );
                }
        }
 
@@ -1593,8 +1592,8 @@ class Article {
                        }
 
                        # Invalidate cache of this article and all pages using this article
-                       # as a template. Partly deferred.
-                       Article::onArticleEdit( $this->mTitle, false ); // leave templatelinks for editUpdates()
+                       # as a template. Partly deferred. Leave templatelinks for editUpdates().
+                       Article::onArticleEdit( $this->mTitle, 'skiptransclusions' );
                        # Update links tables, site stats, etc.
                        $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, $changed );
                } else {
@@ -2257,8 +2256,7 @@ class Article {
         * @param $reason string Prefilled reason
         */
        function confirmDelete( $reason ) {
-               global $wgOut, $wgUser, $wgContLang;
-               $align = $wgContLang->isRtl() ? 'left' : 'right';
+               global $wgOut, $wgUser;
 
                wfDebug( "Article::confirmDelete\n" );
 
@@ -2267,9 +2265,13 @@ class Article {
                $wgOut->addWikiMsg( 'confirmdeletetext' );
 
                if( $wgUser->isAllowed( 'suppressrevision' ) ) {
-                       $suppress = "<tr id=\"wpDeleteSuppressRow\" name=\"wpDeleteSuppressRow\"><td></td><td>";
-                       $suppress .= Xml::checkLabel( wfMsg( 'revdelete-suppress' ), 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '2' ) );
-                       $suppress .= "</td></tr>";
+                       $suppress = "<tr id=\"wpDeleteSuppressRow\" name=\"wpDeleteSuppressRow\">
+                                       <td></td>
+                                       <td class='mw-input'>" .
+                                               Xml::checkLabel( wfMsg( 'revdelete-suppress' ),
+                                                       'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '4' ) ) .
+                                       "</td>
+                               </tr>";
                } else {
                        $suppress = '';
                }
@@ -2279,37 +2281,39 @@ class Article {
                        'action' => $this->mTitle->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
                        Xml::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
                        Xml::tags( 'legend', null, wfMsgExt( 'delete-legend', array( 'parsemag', 'escapenoentities' ) ) ) .
-                       Xml::openElement( 'table' ) .
+                       Xml::openElement( 'table', array( 'id' => 'mw-deleteconfirm-table' ) ) .
                        "<tr id=\"wpDeleteReasonListRow\">
-                               <td align='$align'>" .
+                               <td class='mw-label'>" .
                                        Xml::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
                                "</td>
-                               <td>" .
+                               <td class='mw-input'>" .
                                        Xml::listDropDown( 'wpDeleteReasonList',
                                                wfMsgForContent( 'deletereason-dropdown' ),
                                                wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
                                "</td>
                        </tr>
                        <tr id=\"wpDeleteReasonRow\">
-                               <td align='$align'>" .
+                               <td class='mw-label'>" .
                                        Xml::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
                                "</td>
-                               <td>" .
+                               <td class='mw-input'>" .
                                        Xml::input( 'wpReason', 60, $reason, array( 'type' => 'text', 'maxlength' => '255', 
                                                'tabindex' => '2', 'id' => 'wpReason' ) ) .
                                "</td>
                        </tr>
                        <tr>
                                <td></td>
-                               <td>" .
-                                       Xml::checkLabel( wfMsg( 'watchthis' ), 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
+                               <td class='mw-input'>" .
+                                       Xml::checkLabel( wfMsg( 'watchthis' ),
+                                               'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
                                "</td>
                        </tr>
                        $suppress
                        <tr>
                                <td></td>
-                               <td>" .
-                                       Xml::submitButton( wfMsg( 'deletepage' ), array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '4' ) ) .
+                               <td class='mw-submit'>" .
+                                       Xml::submitButton( wfMsg( 'deletepage' ),
+                                               array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '5' ) ) .
                                "</td>
                        </tr>" .
                        Xml::closeElement( 'table' ) .
@@ -2332,7 +2336,7 @@ class Article {
         * Show relevant lines from the deletion log
         */
        function showLogExtract( $out ) {
-               $out->addHtml( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) );
+               $out->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) );
                LogEventsList::showLogExtract( $out, 'delete', $this->mTitle->getPrefixedText() );
        }
 
@@ -2361,7 +2365,7 @@ class Article {
                                $wgOut->returnToMain( false );
                                wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason, $id));
                        } else {
-                               if ($error = '')
+                               if ($error == '')
                                        $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
                                else
                                        $wgOut->showFatalError( $error );
@@ -2468,6 +2472,11 @@ class Article {
                # If using cleanup triggers, we can skip some manual deletes
                if ( !$dbw->cleanupTriggers() ) {
                        # Clean up recentchanges entries...
+                       $dbw->delete( 'recentchanges',
+                               array( 'rc_type != '.RC_LOG, 
+                                       'rc_namespace' => $this->mTitle->getNamespace(),
+                                       'rc_title' => $this->mTitle->getDBKey() ),
+                               __METHOD__ );
                        $dbw->delete( 'recentchanges',
                                array( 'rc_type != '.RC_LOG, 'rc_cur_id' => $id ),
                                __METHOD__ );
@@ -2721,10 +2730,10 @@ class Article {
                        . $wgUser->getSkin()->userToolLinks( $current->getUser(), $current->getUserText() );
                $new = $wgUser->getSkin()->userLink( $target->getUser(), $target->getUserText() )
                        . $wgUser->getSkin()->userToolLinks( $target->getUser(), $target->getUserText() );
-               $wgOut->addHtml( wfMsgExt( 'rollback-success', array( 'parse', 'replaceafter' ), $old, $new ) );
+               $wgOut->addHTML( wfMsgExt( 'rollback-success', array( 'parse', 'replaceafter' ), $old, $new ) );
                $wgOut->returnToMain( false, $this->mTitle );
 
-               if( !$wgRequest->getBool( 'hidediff', false ) ) {
+               if( !$wgRequest->getBool( 'hidediff', false ) && !$wgUser->getBoolOption( 'norollbackdiff', false ) ) {
                        $de = new DifferenceEngine( $this->mTitle, $current->getId(), $newId, false, true );
                        $de->showDiff( '', '' );
                }
@@ -2814,6 +2823,8 @@ class Article {
                $u = new LinksUpdate( $this->mTitle, $editInfo->output, false );
                $u->setRecursiveTouch( $changed ); // refresh/invalidate including pages too
                $u->doUpdate();
+               
+               wfRunHooks( 'ArticleEditUpdates', array( &$this, &$editInfo, $changed ) );
 
                if( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
                        if ( 0 == mt_rand( 0, 99 ) ) {
@@ -2956,7 +2967,7 @@ class Article {
                        ? 'revision-info-current'
                        : 'revision-info';
 
-               $r = "\n\t\t\t\t<div id=\"mw-{$infomsg}\">" . wfMsg( $infomsg, $td, $userlinks ) . "</div>\n" .
+               $r = "\n\t\t\t\t<div id=\"mw-{$infomsg}\">" . wfMsg( $infomsg, $td, $userlinks, $revision->getID() ) . "</div>\n" .
 
                     "\n\t\t\t\t<div id=\"mw-revision-nav\">" . $cdel . wfMsg( 'revision-nav', $prevdiff, 
                                $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>\n\t\t\t";
@@ -2985,13 +2996,13 @@ class Article {
                static $called = false;
                if( $called ) {
                        wfDebug( "Article::tryFileCache(): called twice!?\n" );
-                       return;
+                       return false;
                }
                $called = true;
-               if($this->isFileCacheable()) {
+               if( $this->isFileCacheable() ) {
                        $touched = $this->mTouched;
                        $cache = new HTMLFileCache( $this->mTitle );
-                       if($cache->isFileCacheGood( $touched )) {
+                       if( $cache->isFileCacheGood( $touched ) ) {
                                wfDebug( "Article::tryFileCache(): about to load file\n" );
                                $cache->loadFromFileCache();
                                return true;
@@ -3002,6 +3013,7 @@ class Article {
                } else {
                        wfDebug( "Article::tryFileCache(): not cacheable\n" );
                }
+               return false;
        }
 
        /**
@@ -3010,40 +3022,31 @@ class Article {
         */
        function isFileCacheable() {
                global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest, $wgLang, $wgContLang;
-               $action    = $wgRequest->getVal( 'action'    );
-               $oldid     = $wgRequest->getVal( 'oldid'     );
-               $diff      = $wgRequest->getVal( 'diff'      );
-               $redirect  = $wgRequest->getVal( 'redirect'  );
-               $printable = $wgRequest->getVal( 'printable' );
-               $page      = $wgRequest->getVal( 'page' );
-               $useskin   = $wgRequest->getVal( 'useskin' );
-
-               //check for non-standard user language; this covers uselang,
-               //and extensions for auto-detecting user language.
-               $ulang     = $wgLang->getCode();
-               $clang     = $wgContLang->getCode();
+               // Get all query values
+               $queryVals = $wgRequest->getValues();
+               foreach( $queryVals as $query => $val ) {
+                       if( $query == 'title' || ($query == 'action' && $val == 'view') ) {
+                               // Normal page view in query form
+                       } else {
+                               return false;
+                       }
+               }
+               // Check for non-standard user language; this covers uselang,
+               // and extensions for auto-detecting user language.
+               $ulang = $wgLang->getCode();
+               $clang = $wgContLang->getCode();
 
                $cacheable = $wgUseFileCache
                        && (!$wgShowIPinHeader)
-                       && ($this->getID() != 0)
+                       && ($this->getID() > 0)
                        && ($wgUser->isAnon())
                        && (!$wgUser->getNewtalk())
-                       && ($this->mTitle->getNamespace() != NS_SPECIAL )
-                       && (!isset($useskin))
-                       && (empty( $action ) || $action == 'view')
-                       && (!isset($oldid))
-                       && (!isset($diff))
-                       && (!isset($redirect))
-                       && (!isset($printable))
-                       && !isset($page)
                        && (!$this->mRedirectedFrom)
                        && ($ulang === $clang);
-
-               if ( $cacheable ) {
-                       //extension may have reason to disable file caching on some pages.
+               // Extension may have reason to disable file caching on some pages.
+               if( $cacheable ) {
                        $cacheable = wfRunHooks( 'IsFileCacheable', array( &$this ) );
                }
-
                return $cacheable;
        }
 
@@ -3235,11 +3238,11 @@ class Article {
        /**
         * Purge caches on page update etc
         */
-       public static function onArticleEdit( $title, $touchTemplates = true ) {
+       public static function onArticleEdit( $title, $transclusions = 'transclusions' ) {
                global $wgDeferredUpdateList, $wgUseFileCache;
 
                // Invalidate caches of articles which include this page
-               if( $touchTemplates )
+               if( $transclusions !== 'skiptransclusions' )
                        $wgDeferredUpdateList[] = new HTMLCacheUpdate( $title, 'templatelinks' );
 
                // Invalidate the caches of all pages which redirect here
@@ -3287,18 +3290,18 @@ class Article {
                $wgOut->setSubtitle( wfMsg( 'infosubtitle' ) );
 
                if( !$this->mTitle->exists() ) {
-                       $wgOut->addHtml( '<div class="noarticletext">' );
+                       $wgOut->addHTML( '<div class="noarticletext">' );
                        if( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
                                // This doesn't quite make sense; the user is asking for
                                // information about the _page_, not the message... -- RC
-                               $wgOut->addHtml( htmlspecialchars( wfMsgWeirdKey( $this->mTitle->getText() ) ) );
+                               $wgOut->addHTML( htmlspecialchars( wfMsgWeirdKey( $this->mTitle->getText() ) ) );
                        } else {
                                $msg = $wgUser->isLoggedIn()
                                        ? 'noarticletext'
                                        : 'noarticletextanon';
-                               $wgOut->addHtml( wfMsgExt( $msg, 'parse' ) );
+                               $wgOut->addHTML( wfMsgExt( $msg, 'parse' ) );
                        }
-                       $wgOut->addHtml( '</div>' );
+                       $wgOut->addHTML( '</div>' );
                } else {
                        $dbr = wfGetDB( DB_SLAVE );
                        $wl_clause = array(
@@ -3429,8 +3432,9 @@ class Article {
                # Decide what kind of autosummary is needed.
 
                # Redirect autosummaries
+               $ot = Title::newFromRedirect( $oldtext );
                $rt = Title::newFromRedirect( $newtext );
-               if( is_object( $rt ) ) {
+               if( is_object( $rt ) && ( !is_object( $ot ) || !$rt->equals( $ot ) || $ot->getFragment() != $rt->getFragment() ) ) {
                        return wfMsgForContent( 'autoredircomment', $rt->getFullText() );
                }
 
@@ -3440,14 +3444,14 @@ class Article {
                        global $wgContLang;
                        $truncatedtext = $wgContLang->truncate(
                                str_replace("\n", ' ', $newtext),
-                               max( 0, 200 - strlen( wfMsgForContent( 'autosumm-new') ) ),
+                               max( 0, 200 - strlen( wfMsgForContent( 'autosumm-new' ) ) ),
                                '...' );
                        return wfMsgForContent( 'autosumm-new', $truncatedtext );
                }
 
                # Blanking autosummaries
                if( $oldtext != '' && $newtext == '' ) {
-                       return wfMsgForContent('autosumm-blank');
+                       return wfMsgForContent( 'autosumm-blank' );
                } elseif( strlen( $oldtext ) > 10 * strlen( $newtext ) && strlen( $newtext ) < 500) {
                        # Removing more than 90% of the article
                        global $wgContLang;
@@ -3473,7 +3477,7 @@ class Article {
         * @param bool    $cache
         */
        public function outputWikiText( $text, $cache = true ) {
-               global $wgParser, $wgUser, $wgOut, $wgEnableParserCache;
+               global $wgParser, $wgUser, $wgOut, $wgEnableParserCache, $wgUseFileCache;
 
                $popts = $wgOut->parserOptions();
                $popts->setTidy(true);
@@ -3486,8 +3490,14 @@ class Article {
                        $parserCache = ParserCache::singleton();
                        $parserCache->save( $parserOutput, $this, $wgUser );
                }
+               // Make sure file cache is not used on uncacheable content.
+               // Output that has magic words in it can still use the parser cache
+               // (if enabled), though it will generally expire sooner.
+               if( $parserOutput->getCacheTime() == -1 || $parserOutput->containsOldMagic() ) {
+                       $wgUseFileCache = false;
+               }
 
-               if ( !wfReadOnly() && $this->mTitle->areRestrictionsCascading() ) {
+               if ( $this->isCurrent() && !wfReadOnly() && $this->mTitle->areRestrictionsCascading() ) {
                        // templatelinks table may have become out of sync,
                        // especially if using variable-based transclusions.
                        // For paranoia, check if things have changed and if