Instead of creating an OutputPage and then setting a context start initializing Outpu...
[lhc/web/wiklou.git] / includes / Article.php
index 63d9bf9..0ae1032 100644 (file)
@@ -40,7 +40,7 @@ class Article {
        var $mTouched = '19700101000000'; // !<
        var $mUser = -1;                  // !< Not loaded
        var $mUserText = '';              // !< username from Revision if set
-       var $mParserOptions;              // !< ParserOptions object for $wgUser articles
+       var $mParserOptions;              // !< ParserOptions object
        var $mParserOutput;               // !< ParserCache object if set
        /**@}}*/
 
@@ -159,7 +159,7 @@ class Article {
         *
         * @param $text string article content containing redirect info
         * @return mixed false, Title of in-wiki target, or string with URL
-        * @deprecated @since 1.17
+        * @deprecated since 1.17
         */
        public function followRedirectText( $text ) {
                // recurse through to only get the final target
@@ -834,6 +834,32 @@ class Article {
 
                # Get variables from query string
                $oldid = $this->getOldID();
+
+               # getOldID may want us to redirect somewhere else
+               if ( $this->mRedirectUrl ) {
+                       $wgOut->redirect( $this->mRedirectUrl );
+                       wfDebug( __METHOD__ . ": redirecting due to oldid\n" );
+                       wfProfileOut( __METHOD__ );
+
+                       return;
+               }
+
+               $wgOut->setArticleFlag( true );
+               # Set page title (may be overridden by DISPLAYTITLE)
+               $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
+
+               # If we got diff in the query, we want to see a diff page instead of the article.
+               if ( $wgRequest->getCheck( 'diff' ) ) {
+                       wfDebug( __METHOD__ . ": showing diff page\n" );
+                       $this->showDiffPage();
+                       wfProfileOut( __METHOD__ );
+
+                       return;
+               }
+
+               # Allow frames by default
+               $wgOut->allowClickjacking();
+
                $parserCache = ParserCache::singleton();
 
                $parserOptions = $this->getParserOptions();
@@ -869,31 +895,6 @@ class Article {
                        }
                }
 
-               # getOldID may want us to redirect somewhere else
-               if ( $this->mRedirectUrl ) {
-                       $wgOut->redirect( $this->mRedirectUrl );
-                       wfDebug( __METHOD__ . ": redirecting due to oldid\n" );
-                       wfProfileOut( __METHOD__ );
-
-                       return;
-               }
-
-               $wgOut->setArticleFlag( true );
-               # Set page title (may be overridden by DISPLAYTITLE)
-               $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
-
-               # If we got diff in the query, we want to see a diff page instead of the article.
-               if ( $wgRequest->getCheck( 'diff' ) ) {
-                       wfDebug( __METHOD__ . ": showing diff page\n" );
-                       $this->showDiffPage();
-                       wfProfileOut( __METHOD__ );
-
-                       return;
-               }
-
-               # Allow frames by default
-               $wgOut->allowClickjacking();
-
                if ( !$wgUseETag && !$this->mTitle->quickUserCan( 'edit' ) ) {
                        $parserOptions->setEditSection( false );
                }
@@ -1070,9 +1071,7 @@ class Article {
                $this->mRevIdFetched = $de->mNewid;
                $de->showDiffPage( $diffOnly );
 
-               // Needed to get the page's current revision
-               $this->loadPageData();
-               if ( $diff == 0 || $diff == $this->mLatest ) {
+               if ( $diff == 0 || $diff == $this->getLatest() ) {
                        # Run view updates for current revision only
                        $this->viewUpdates();
                }
@@ -1116,8 +1115,7 @@ class Article {
                if ( $ns == NS_USER || $ns == NS_USER_TALK ) {
                        # Don't index user and user talk pages for blocked users (bug 11443)
                        if ( !$this->mTitle->isSubpage() ) {
-                               $block = new Block();
-                               if ( $block->load( $this->mTitle->getText() ) ) {
+                               if ( Block::newFromTarget( null, $this->mTitle->getText() ) instanceof Block ) {
                                        return array(
                                                'index'  => 'noindex',
                                                'follow' => 'nofollow'
@@ -1216,13 +1214,12 @@ class Article {
                global $wgOut, $wgUser, $wgRequest, $wgRedirectSources;
 
                $rdfrom = $wgRequest->getVal( 'rdfrom' );
-               $sk = $wgUser->getSkin();
 
                if ( isset( $this->mRedirectedFrom ) ) {
                        // This is an internally redirected page view.
                        // We'll need a backlink to the source page for navigation.
                        if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
-                               $redir = $sk->link(
+                               $redir = $wgUser->getSkin()->link(
                                        $this->mRedirectedFrom,
                                        null,
                                        array(),
@@ -1250,7 +1247,7 @@ class Article {
                        // This is an externally redirected view, from some other wiki.
                        // If it was reported from a trusted site, supply a backlink.
                        if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
-                               $redir = $sk->makeExternalLink( $rdfrom, $rdfrom );
+                               $redir = $wgUser->getSkin()->makeExternalLink( $rdfrom, $rdfrom );
                                $s = wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir );
                                $wgOut->setSubtitle( $s );
 
@@ -1407,7 +1404,7 @@ class Article {
                if ( !$this->hasViewableContent() ) {
                        // If there's no backing content, send a 404 Not Found
                        // for better machine handling of broken links.
-                       $wgRequest->response()->header( "HTTP/1.x 404 Not Found" );
+                       $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
                }
 
                $wgOut->addWikiText( $text );
@@ -1583,7 +1580,7 @@ class Article {
         * Builds trackback links for article display if $wgUseTrackbacks is set to true
         */
        public function addTrackbacks() {
-               global $wgOut, $wgUser;
+               global $wgOut;
 
                $dbr = wfGetDB( DB_SLAVE );
                $tbs = $dbr->select( 'trackbacks',
@@ -1601,9 +1598,9 @@ class Article {
                foreach ( $tbs as $o ) {
                        $rmvtxt = "";
 
-                       if ( $wgUser->isAllowed( 'trackback' ) ) {
+                       if ( $wgOut->getUser()->isAllowed( 'trackback' ) ) {
                                $delurl = $this->mTitle->getFullURL( "action=deletetrackback&tbid=" .
-                                       $o->tb_id . "&token=" . urlencode( $wgUser->editToken() ) );
+                                       $o->tb_id . "&token=" . urlencode( $wgOut->getUser()->editToken() ) );
                                $rmvtxt = wfMsg( 'trackbackremove', htmlspecialchars( $delurl ) );
                        }
 
@@ -1623,15 +1620,15 @@ class Article {
         * Removes trackback record for current article from trackbacks table
         */
        public function deletetrackback() {
-               global $wgUser, $wgRequest, $wgOut;
+               global $wgRequest, $wgOut;
 
-               if ( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
+               if ( !$wgOut->getUser()->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
                        $wgOut->addWikiMsg( 'sessionfailure' );
 
                        return;
                }
 
-               $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $wgUser );
+               $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $wgOut->getUser() );
 
                if ( count( $permission_errors ) ) {
                        $wgOut->showPermissionsErrorPage( $permission_errors );
@@ -1661,9 +1658,9 @@ class Article {
         * Handle action=purge
         */
        public function purge() {
-               global $wgUser, $wgRequest, $wgOut;
+               global $wgRequest, $wgOut;
 
-               if ( $wgUser->isAllowed( 'purge' ) || $wgRequest->wasPosted() ) {
+               if ( $wgOut->getUser()->isAllowed( 'purge' ) || $wgRequest->wasPosted() ) {
                        //FIXME: shouldn't this be in doPurge()?
                        if ( wfRunHooks( 'ArticlePurge', array( &$this ) ) ) {
                                $this->doPurge();
@@ -1834,7 +1831,7 @@ class Article {
                if ( !$isRedirect && !is_null( $lastRevIsRedirect ) && $lastRevIsRedirect === $isRedirect ) {
                        return true;
                }
-               
+
                wfProfileIn( __METHOD__ );
                if ( $isRedirect ) {
                        $this->insertRedirectEntry( $redirectTitle );
@@ -1937,78 +1934,6 @@ class Article {
                return $text;
        }
 
-       /**
-        * @deprecated @since 1.7 use Article::doEdit()
-        */
-       function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC = false, $comment = false, $bot = false ) {
-               wfDeprecated( __METHOD__ );
-
-               $flags = EDIT_NEW | EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY |
-                       ( $isminor ? EDIT_MINOR : 0 ) |
-                       ( $suppressRC ? EDIT_SUPPRESS_RC : 0 ) |
-                       ( $bot ? EDIT_FORCE_BOT : 0 );
-
-               # If this is a comment, add the summary as headline
-               if ( $comment && $summary != "" ) {
-                       $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $summary ) . "\n\n" . $text;
-               }
-               $this->doEdit( $text, $summary, $flags );
-
-               $dbw = wfGetDB( DB_MASTER );
-               if ( $watchthis ) {
-                       if ( !$this->mTitle->userIsWatching() ) {
-                               $dbw->begin();
-                               $this->doWatch();
-                               $dbw->commit();
-                       }
-               } else {
-                       if ( $this->mTitle->userIsWatching() ) {
-                               $dbw->begin();
-                               $this->doUnwatch();
-                               $dbw->commit();
-                       }
-               }
-               $this->doRedirect( $this->isRedirect( $text ) );
-       }
-
-       /**
-        * @deprecated @since 1.7 use Article::doEdit()
-        */
-       function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
-               wfDeprecated( __METHOD__ );
-
-               $flags = EDIT_UPDATE | EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY |
-                       ( $minor ? EDIT_MINOR : 0 ) |
-                       ( $forceBot ? EDIT_FORCE_BOT : 0 );
-
-               $status = $this->doEdit( $text, $summary, $flags );
-
-               if ( !$status->isOK() ) {
-                       return false;
-               }
-
-               $dbw = wfGetDB( DB_MASTER );
-               if ( $watchthis ) {
-                       if ( !$this->mTitle->userIsWatching() ) {
-                               $dbw->begin();
-                               $this->doWatch();
-                               $dbw->commit();
-                       }
-               } else {
-                       if ( $this->mTitle->userIsWatching() ) {
-                               $dbw->begin();
-                               $this->doUnwatch();
-                               $dbw->commit();
-                       }
-               }
-
-               $extraQuery = ''; // Give extensions a chance to modify URL query on update
-               wfRunHooks( 'ArticleUpdateBeforeRedirect', array( $this, &$sectionanchor, &$extraQuery ) );
-
-               $this->doRedirect( $this->isRedirect( $text ), $sectionanchor, $extraQuery );
-               return true;
-       }
-
        /**
         * Check flags and add EDIT_NEW or EDIT_UPDATE to them as needed.
         * @param $flags Int
@@ -2348,14 +2273,14 @@ class Article {
         * Mark this particular edit/page as patrolled
         */
        public function markpatrolled() {
-               global $wgOut, $wgUser, $wgRequest;
+               global $wgOut, $wgRequest;
 
                $wgOut->setRobotPolicy( 'noindex,nofollow' );
 
                # If we haven't been given an rc_id value, we can't do anything
                $rcid = (int) $wgRequest->getVal( 'rcid' );
 
-               if ( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ), $rcid ) ) {
+               if ( !$wgOut->getUser()->matchEditToken( $wgRequest->getVal( 'token' ), $rcid ) ) {
                        $wgOut->showErrorPage( 'sessionfailure-title', 'sessionfailure' );
                        return;
                }
@@ -2408,9 +2333,9 @@ class Article {
         * User-interface handler for the "watch" action
         */
        public function watch() {
-               global $wgUser, $wgOut;
+               global $wgOut;
 
-               if ( $wgUser->isAnon() ) {
+               if ( $wgOut->getUser()->isAnon() ) {
                        $wgOut->showErrorPage( 'watchnologin', 'watchnologintext' );
                        return;
                }
@@ -2455,9 +2380,9 @@ class Article {
         * User interface handler for the "unwatch" action.
         */
        public function unwatch() {
-               global $wgUser, $wgOut;
+               global $wgOut;
 
-               if ( $wgUser->isAnon() ) {
+               if ( $wgOut->getUser()->isAnon() ) {
                        $wgOut->showErrorPage( 'watchnologin', 'watchnologintext' );
                        return;
                }
@@ -2617,9 +2542,9 @@ class Article {
                                $protect_description = '';
                                foreach ( $limit as $action => $restrictions ) {
                                        if ( !isset( $expiry[$action] ) )
-                                               $expiry[$action] = Block::infinity();
+                                               $expiry[$action] = $dbw->getInfinity();
 
-                                       $encodedExpiry[$action] = Block::encodeExpiry( $expiry[$action], $dbw );
+                                       $encodedExpiry[$action] = $dbw->encodeExpiry( $expiry[$action] );
                                        if ( $restrictions != '' ) {
                                                $protect_description .= "[$action=$restrictions] (";
                                                if ( $encodedExpiry[$action] != 'infinity' ) {
@@ -2801,8 +2726,8 @@ class Article {
                // Replace newlines with spaces to prevent uglyness
                $contents = preg_replace( "/[\n\r]/", ' ', $contents );
                // Calculate the maximum amount of chars to get
-               // Max content length = max comment length - length of the comment (excl. $1) - '...'
-               $maxLength = 255 - ( strlen( $reason ) - 2 ) - 3;
+               // Max content length = max comment length - length of the comment (excl. $1)
+               $maxLength = 255 - ( strlen( $reason ) - 2 );
                $contents = $wgContLang->truncate( $contents, $maxLength );
                // Remove possible unfinished links
                $contents = preg_replace( '/\[\[([^\]]*)\]?$/', '$1', $contents );
@@ -2817,10 +2742,10 @@ class Article {
         * UI entry point for page deletion
         */
        public function delete() {
-               global $wgUser, $wgOut, $wgRequest;
+               global $wgOut, $wgRequest;
 
                $confirm = $wgRequest->wasPosted() &&
-                               $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
+                               $wgOut->getUser()->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
 
                $this->DeleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' );
                $this->DeleteReason = $wgRequest->getText( 'wpReason' );
@@ -2835,7 +2760,7 @@ class Article {
                }
 
                # Flag to hide all contents of the archived revisions
-               $suppress = $wgRequest->getVal( 'wpSuppress' ) && $wgUser->isAllowed( 'suppressrevision' );
+               $suppress = $wgRequest->getVal( 'wpSuppress' ) && $wgOut->getUser()->isAllowed( 'suppressrevision' );
 
                # This code desperately needs to be totally rewritten
 
@@ -2847,7 +2772,7 @@ class Article {
                }
 
                # Check permissions
-               $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $wgUser );
+               $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $wgOut->getUser() );
 
                if ( count( $permission_errors ) > 0 ) {
                        $wgOut->showPermissionsErrorPage( $permission_errors );
@@ -2893,7 +2818,7 @@ class Article {
                if ( $confirm ) {
                        $this->doDelete( $reason, $suppress );
 
-                       if ( $wgRequest->getCheck( 'wpWatch' ) && $wgUser->isLoggedIn() ) {
+                       if ( $wgRequest->getCheck( 'wpWatch' ) && $wgOut->getUser()->isLoggedIn() ) {
                                $this->doWatch();
                        } elseif ( $this->mTitle->userIsWatching() ) {
                                $this->doUnwatch();
@@ -2912,7 +2837,7 @@ class Article {
                if ( $hasHistory && !$confirm ) {
                        global $wgLang;
 
-                       $skin = $wgUser->getSkin();
+                       $skin = $wgOut->getSkin();
                        $revisions = $this->estimateRevisionCount();
                        //FIXME: lego
                        $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
@@ -3019,18 +2944,18 @@ class Article {
         * @param $reason String: prefilled reason
         */
        public function confirmDelete( $reason ) {
-               global $wgOut, $wgUser;
+               global $wgOut;
 
                wfDebug( "Article::confirmDelete\n" );
 
-               $deleteBackLink = $wgUser->getSkin()->linkKnown( $this->mTitle );
+               $deleteBackLink = $wgOut->getSkin()->linkKnown( $this->mTitle );
                $wgOut->setSubtitle( wfMsgHtml( 'delete-backlink', $deleteBackLink ) );
                $wgOut->setRobotPolicy( 'noindex,nofollow' );
                $wgOut->addWikiMsg( 'confirmdeletetext' );
 
                wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
 
-               if ( $wgUser->isAllowed( 'suppressrevision' ) ) {
+               if ( $wgOut->getUser()->isAllowed( 'suppressrevision' ) ) {
                        $suppress = "<tr id=\"wpDeleteSuppressRow\">
                                        <td></td>
                                        <td class='mw-input'><strong>" .
@@ -3041,7 +2966,7 @@ class Article {
                } else {
                        $suppress = '';
                }
-               $checkWatch = $wgUser->getBoolOption( 'watchdeletion' ) || $this->mTitle->userIsWatching();
+               $checkWatch = $wgOut->getUser()->getBoolOption( 'watchdeletion' ) || $this->mTitle->userIsWatching();
 
                $form = Xml::openElement( 'form', array( 'method' => 'post',
                        'action' => $this->mTitle->getLocalURL( 'action=delete' ), 'id' => 'deleteconfirm' ) ) .
@@ -3074,7 +2999,7 @@ class Article {
                        </tr>";
 
                # Disallow watching if user is not logged in
-               if ( $wgUser->isLoggedIn() ) {
+               if ( $wgOut->getUser()->isLoggedIn() ) {
                        $form .= "
                        <tr>
                                <td></td>
@@ -3096,11 +3021,11 @@ class Article {
                        </tr>" .
                        Xml::closeElement( 'table' ) .
                        Xml::closeElement( 'fieldset' ) .
-                       Html::hidden( 'wpEditToken', $wgUser->editToken() ) .
+                       Html::hidden( 'wpEditToken', $wgOut->getUser()->editToken() ) .
                        Xml::closeElement( 'form' );
 
-                       if ( $wgUser->isAllowed( 'editinterface' ) ) {
-                               $skin = $wgUser->getSkin();
+                       if ( $wgOut->getUser()->isAllowed( 'editinterface' ) ) {
+                               $skin = $wgOut->getSkin();
                                $title = Title::makeTitle( NS_MEDIAWIKI, 'Deletereason-dropdown' );
                                $link = $skin->link(
                                        $title,
@@ -3122,24 +3047,21 @@ class Article {
         * Perform a deletion and output success or failure messages
         */
        public function doDelete( $reason, $suppress = false ) {
-               global $wgOut, $wgUser;
+               global $wgOut;
 
                $id = $this->mTitle->getArticleID( Title::GAID_FOR_UPDATE );
 
                $error = '';
-               if ( wfRunHooks( 'ArticleDelete', array( &$this, &$wgUser, &$reason, &$error ) ) ) {
-                       if ( $this->doDeleteArticle( $reason, $suppress, $id ) ) {
-                               $deleted = $this->mTitle->getPrefixedText();
+               if ( $this->doDeleteArticle( $reason, $suppress, $id, $error ) ) {
+                       $deleted = $this->mTitle->getPrefixedText();
 
-                               $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
-                               $wgOut->setRobotPolicy( 'noindex,nofollow' );
+                       $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
+                       $wgOut->setRobotPolicy( 'noindex,nofollow' );
 
-                               $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
+                       $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
 
-                               $wgOut->addWikiMsg( 'deletedtext', $deleted, $loglink );
-                               $wgOut->returnToMain( false );
-                               wfRunHooks( 'ArticleDeleteComplete', array( &$this, &$wgUser, $reason, $id ) );
-                       }
+                       $wgOut->addWikiMsg( 'deletedtext', $deleted, $loglink );
+                       $wgOut->returnToMain( false );
                } else {
                        if ( $error == '' ) {
                                $wgOut->showFatalError(
@@ -3177,11 +3099,15 @@ class Article {
         * @param $commit boolean defaults to true, triggers transaction end
         * @return boolean true if successful
         */
-       public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true ) {
+       public function doDeleteArticle( $reason, $suppress = false, $id = 0, $commit = true, &$error = '' ) {
                global $wgDeferredUpdateList, $wgUseTrackbacks;
+               global $wgUser;
 
                wfDebug( __METHOD__ . "\n" );
 
+               if ( ! wfRunHooks( 'ArticleDelete', array( &$this, &$wgUser, &$reason, &$error ) ) ) {
+                       return false;
+               }
                $dbw = wfGetDB( DB_MASTER );
                $t = $this->mTitle->getDBkey();
                $id = $id ? $id : $this->mTitle->getArticleID( Title::GAID_FOR_UPDATE );
@@ -3307,6 +3233,7 @@ class Article {
                        $dbw->commit();
                }
 
+               wfRunHooks( 'ArticleDeleteComplete', array( &$this, &$wgUser, $reason, $id ) );
                return true;
        }
 
@@ -3460,7 +3387,7 @@ class Article {
                        $flags |= EDIT_MINOR;
                }
 
-               if ( $bot && ( $wgUser->isAllowed( 'markbotedits' ) || $wgUser->isAllowed( 'bot' ) ) ) {
+               if ( $bot && ( $wgUser->isAllowedAny( 'markbotedits', 'bot' ) ) ) {
                        $flags |= EDIT_FORCE_BOT;
                }
 
@@ -3612,7 +3539,7 @@ class Article {
                $edit->revid = $revid;
                $edit->newText = $text;
                $edit->pst = $this->preSaveTransform( $text, $user, $popts );
-               $edit->popts = $this->getParserOptions( true );
+               $edit->popts = $this->getParserOptions();
                $edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $edit->popts, true, true, $revid );
                $edit->oldText = $this->getRawText();
 
@@ -4397,23 +4324,15 @@ class Article {
 
        /**
         * Get parser options suitable for rendering the primary article wikitext
-        * @param $canonical boolean Determines that the generated must not depend on user preferences (see bug 14404)
         * @return mixed ParserOptions object or boolean false
         */
-       public function getParserOptions( $canonical = false ) {
-               global $wgUser, $wgLanguageCode;
-
-               if ( !$this->mParserOptions || $canonical ) {
-                       $user = !$canonical ? $wgUser : new User;
-                       $parserOptions = new ParserOptions( $user );
-                       $parserOptions->setTidy( true );
-                       $parserOptions->enableLimitReport();
-
-                       if ( $canonical ) {
-                               $parserOptions->setUserLang( $wgLanguageCode ); # Must be set explicitely
-                               return $parserOptions;
-                       }
-                       $this->mParserOptions = $parserOptions;
+       public function getParserOptions() {
+               global $wgUser;
+
+               if ( !$this->mParserOptions ) {
+                       $this->mParserOptions = new ParserOptions( $wgUser );
+                       $this->mParserOptions->setTidy( true );
+                       $this->mParserOptions->enableLimitReport();
                }
 
                // Clone to allow modifications of the return value without affecting