Fixed spacing in files direct in includes folder
[lhc/web/wiklou.git] / includes / WikiPage.php
index f4d2e23..39a71ad 100644 (file)
@@ -305,7 +305,7 @@ class WikiPage implements Page, IDBAccessObject {
        public function pageDataFromTitle( $dbr, $title, $options = array() ) {
                return $this->pageData( $dbr, array(
                        'page_namespace' => $title->getNamespace(),
-                       'page_title'     => $title->getDBkey() ), $options );
+                       'page_title' => $title->getDBkey() ), $options );
        }
 
        /**
@@ -462,7 +462,9 @@ class WikiPage implements Page, IDBAccessObject {
         */
        public function isRedirect() {
                $content = $this->getContent();
-               if ( !$content ) return false;
+               if ( !$content ) {
+                       return false;
+               }
 
                return $content->isRedirect();
        }
@@ -797,7 +799,7 @@ class WikiPage implements Page, IDBAccessObject {
        public function setCachedLastEditTime( $timestamp ) {
                global $wgMemc;
                $key = wfMemcKey( 'page-lastedit', md5( $this->mTitle->getPrefixedDBkey() ) );
-               $wgMemc->set( $key, wfTimestamp( TS_MW, $timestamp ), 60*15 );
+               $wgMemc->set( $key, wfTimestamp( TS_MW, $timestamp ), 60 * 15 );
        }
 
        /**
@@ -906,10 +908,10 @@ class WikiPage implements Page, IDBAccessObject {
                $dbw = wfGetDB( DB_MASTER );
                $dbw->replace( 'redirect', array( 'rd_from' ),
                        array(
-                               'rd_from'      => $this->getId(),
+                               'rd_from' => $this->getId(),
                                'rd_namespace' => $rt->getNamespace(),
-                               'rd_title'     => $rt->getDBkey(),
-                               'rd_fragment'  => $rt->getFragment(),
+                               'rd_title' => $rt->getDBkey(),
+                               'rd_fragment' => $rt->getFragment(),
                                'rd_interwiki' => $rt->getInterwiki(),
                        ),
                        __METHOD__
@@ -1155,13 +1157,12 @@ class WikiPage implements Page, IDBAccessObject {
        public function doPurge() {
                global $wgUseSquid;
 
-               if( !wfRunHooks( 'ArticlePurge', array( &$this ) ) ) {
+               if ( !wfRunHooks( 'ArticlePurge', array( &$this ) ) ) {
                        return false;
                }
 
                // Invalidate the cache
                $this->mTitle->invalidateCache();
-               $this->clear();
 
                if ( $wgUseSquid ) {
                        // Commit the transaction before the purge is sent
@@ -1183,7 +1184,9 @@ class WikiPage implements Page, IDBAccessObject {
                                $content = $this->getContent();
                                $text = $content === null ? null : $content->getWikitextForTransclusion();
 
-                               if ( $text === null ) $text = false;
+                               if ( $text === null ) {
+                                       $text = false;
+                               }
                        } else {
                                $text = false;
                        }
@@ -1482,6 +1485,7 @@ class WikiPage implements Page, IDBAccessObject {
                        $newContent = $sectionContent;
                } else {
                        if ( !$this->supportsSections() ) {
+                               wfProfileOut( __METHOD__ );
                                throw new MWException( "sections not supported for content model " . $this->getContentHandler()->getModelID() );
                        }
 
@@ -1698,7 +1702,9 @@ class WikiPage implements Page, IDBAccessObject {
 
                // Provide autosummaries if one is not provided and autosummaries are enabled.
                if ( $wgUseAutomaticEditSummaries && $flags & EDIT_AUTOSUMMARY && $summary == '' ) {
-                       if ( !$old_content ) $old_content = null;
+                       if ( !$old_content ) {
+                               $old_content = null;
+                       }
                        $summary = $handler->getAutosummary( $old_content, $content, $flags );
                }
 
@@ -1747,6 +1753,7 @@ class WikiPage implements Page, IDBAccessObject {
 
                        if ( $changed ) {
                                if ( !$content->isValid() ) {
+                                       wfProfileOut( __METHOD__ );
                                        throw new MWException( "New content failed validity check!" );
                                }
 
@@ -2120,17 +2127,20 @@ class WikiPage implements Page, IDBAccessObject {
                        && $shortTitle != $user->getTitleKey()
                        && !( $revision->isMinor() && $user->isAllowed( 'nominornewtalk' ) )
                ) {
-                       if ( wfRunHooks( 'ArticleEditUpdateNewTalk', array( &$this ) ) ) {
-                               $other = User::newFromName( $shortTitle, false );
-                               if ( !$other ) {
-                                       wfDebug( __METHOD__ . ": invalid username\n" );
-                               } elseif ( User::isIP( $shortTitle ) ) {
-                                       // An anonymous user
-                                       $other->setNewtalk( true, $revision );
-                               } elseif ( $other->isLoggedIn() ) {
-                                       $other->setNewtalk( true, $revision );
-                               } else {
-                                       wfDebug( __METHOD__ . ": don't need to notify a nonexistent user\n" );
+                       $recipient = User::newFromName( $shortTitle, false );
+                       if ( !$recipient ) {
+                               wfDebug( __METHOD__ . ": invalid username\n" );
+                       } else {
+                               // Allow extensions to prevent user notification when a new message is added to their talk page
+                               if ( wfRunHooks( 'ArticleEditUpdateNewTalk', array( &$this, $recipient ) ) ) {
+                                       if ( User::isIP( $shortTitle ) ) {
+                                               // An anonymous user
+                                               $recipient->setNewtalk( true, $revision );
+                                       } elseif ( $recipient->isLoggedIn() ) {
+                                               $recipient->setNewtalk( true, $revision );
+                                       } else {
+                                               wfDebug( __METHOD__ . ": don't need to notify a nonexistent user\n" );
+                                       }
                                }
                        }
                }
@@ -2138,12 +2148,14 @@ class WikiPage implements Page, IDBAccessObject {
                if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
                        // XXX: could skip pseudo-messages like js/css here, based on content model.
                        $msgtext = $content ? $content->getWikitextForTransclusion() : null;
-                       if ( $msgtext === false || $msgtext === null ) $msgtext = '';
+                       if ( $msgtext === false || $msgtext === null ) {
+                               $msgtext = '';
+                       }
 
                        MessageCache::singleton()->replace( $shortTitle, $msgtext );
                }
 
-               if( $options['created'] ) {
+               if ( $options['created'] ) {
                        self::onArticleCreate( $this->mTitle );
                } else {
                        self::onArticleEdit( $this->mTitle );
@@ -2807,7 +2819,7 @@ class WikiPage implements Page, IDBAccessObject {
                        $wgContLang->timeanddate( wfTimestamp( TS_MW, $s->rev_timestamp ) ),
                        $current->getId(), $wgContLang->timeanddate( $current->getTimestamp() )
                );
-               if( $summary instanceof Message ) {
+               if ( $summary instanceof Message ) {
                        $summary = $summary->params( $args )->inContentLanguage()->text();
                } else {
                        $summary = wfMsgReplaceArgs( $summary, $args );
@@ -2848,8 +2860,8 @@ class WikiPage implements Page, IDBAccessObject {
                $resultDetails = array(
                        'summary' => $summary,
                        'current' => $current,
-                       'target'  => $target,
-                       'newid'   => $revId
+                       'target' => $target,
+                       'newid' => $revId
                );
 
                return array();
@@ -3018,69 +3030,76 @@ class WikiPage implements Page, IDBAccessObject {
         * @param array $added   The names of categories that were added
         * @param array $deleted The names of categories that were deleted
         */
-       public function updateCategoryCounts( $added, $deleted ) {
-               $ns = $this->mTitle->getNamespace();
+       public function updateCategoryCounts( array $added, array $deleted ) {
+               $that = $this;
+               $method = __METHOD__;
                $dbw = wfGetDB( DB_MASTER );
 
-               // First make sure the rows exist.  If one of the "deleted" ones didn't
-               // exist, we might legitimately not create it, but it's simpler to just
-               // create it and then give it a negative value, since the value is bogus
-               // anyway.
-               //
-               // Sometimes I wish we had INSERT ... ON DUPLICATE KEY UPDATE.
-               $insertCats = array_merge( $added, $deleted );
-               if ( !$insertCats ) {
-                       // Okay, nothing to do
-                       return;
-               }
+               // Do this at the end of the commit to reduce lock wait timeouts
+               $dbw->onTransactionPreCommitOrIdle(
+                       function() use ( $dbw, $that, $method, $added, $deleted ) {
+                               $ns = $that->getTitle()->getNamespace();
 
-               $insertRows = array();
+                               // First make sure the rows exist.  If one of the "deleted" ones didn't
+                               // exist, we might legitimately not create it, but it's simpler to just
+                               // create it and then give it a negative value, since the value is bogus
+                               // anyway.
+                               //
+                               // Sometimes I wish we had INSERT ... ON DUPLICATE KEY UPDATE.
+                               $insertCats = array_merge( $added, $deleted );
+                               if ( !$insertCats ) {
+                                       // Okay, nothing to do
+                                       return;
+                               }
 
-               foreach ( $insertCats as $cat ) {
-                       $insertRows[] = array(
-                               'cat_id' => $dbw->nextSequenceValue( 'category_cat_id_seq' ),
-                               'cat_title' => $cat
-                       );
-               }
-               $dbw->insert( 'category', $insertRows, __METHOD__, 'IGNORE' );
+                               $insertRows = array();
+                               foreach ( $insertCats as $cat ) {
+                                       $insertRows[] = array(
+                                               'cat_id' => $dbw->nextSequenceValue( 'category_cat_id_seq' ),
+                                               'cat_title' => $cat
+                                       );
+                               }
+                               $dbw->insert( 'category', $insertRows, $method, 'IGNORE' );
 
-               $addFields = array( 'cat_pages = cat_pages + 1' );
-               $removeFields = array( 'cat_pages = cat_pages - 1' );
+                               $addFields = array( 'cat_pages = cat_pages + 1' );
+                               $removeFields = array( 'cat_pages = cat_pages - 1' );
 
-               if ( $ns == NS_CATEGORY ) {
-                       $addFields[] = 'cat_subcats = cat_subcats + 1';
-                       $removeFields[] = 'cat_subcats = cat_subcats - 1';
-               } elseif ( $ns == NS_FILE ) {
-                       $addFields[] = 'cat_files = cat_files + 1';
-                       $removeFields[] = 'cat_files = cat_files - 1';
-               }
+                               if ( $ns == NS_CATEGORY ) {
+                                       $addFields[] = 'cat_subcats = cat_subcats + 1';
+                                       $removeFields[] = 'cat_subcats = cat_subcats - 1';
+                               } elseif ( $ns == NS_FILE ) {
+                                       $addFields[] = 'cat_files = cat_files + 1';
+                                       $removeFields[] = 'cat_files = cat_files - 1';
+                               }
 
-               if ( $added ) {
-                       $dbw->update(
-                               'category',
-                               $addFields,
-                               array( 'cat_title' => $added ),
-                               __METHOD__
-                       );
-               }
+                               if ( $added ) {
+                                       $dbw->update(
+                                               'category',
+                                               $addFields,
+                                               array( 'cat_title' => $added ),
+                                               $method
+                                       );
+                               }
 
-               if ( $deleted ) {
-                       $dbw->update(
-                               'category',
-                               $removeFields,
-                               array( 'cat_title' => $deleted ),
-                               __METHOD__
-                       );
-               }
+                               if ( $deleted ) {
+                                       $dbw->update(
+                                               'category',
+                                               $removeFields,
+                                               array( 'cat_title' => $deleted ),
+                                               $method
+                                       );
+                               }
 
-               foreach( $added as $catName ) {
-                       $cat = Category::newFromName( $catName );
-                       wfRunHooks( 'CategoryAfterPageAdded', array( $cat, $this ) );
-               }
-               foreach( $deleted as $catName ) {
-                       $cat = Category::newFromName( $catName );
-                       wfRunHooks( 'CategoryAfterPageRemoved', array( $cat, $this ) );
-               }
+                               foreach ( $added as $catName ) {
+                                       $cat = Category::newFromName( $catName );
+                                       wfRunHooks( 'CategoryAfterPageAdded', array( $cat, $that ) );
+                               }
+                               foreach ( $deleted as $catName ) {
+                                       $cat = Category::newFromName( $catName );
+                                       wfRunHooks( 'CategoryAfterPageRemoved', array( $cat, $that ) );
+                               }
+                       }
+               );
        }
 
        /**