Merge "jquery.makeCollapsible: fix jQuery memory leak"
[lhc/web/wiklou.git] / includes / WikiPage.php
index f2c9c29..4aab674 100644 (file)
@@ -187,7 +187,7 @@ class WikiPage implements Page, IDBAccessObject {
         * (and only when) $wgActions[$action] === true. This allows subclasses
         * to override the default behavior.
         *
-        * @todo: move this UI stuff somewhere else
+        * @todo Move this UI stuff somewhere else
         *
         * @return Array
         */
@@ -648,7 +648,7 @@ class WikiPage implements Page, IDBAccessObject {
         * @return String|false The text of the current revision
         * @deprecated as of 1.21, getContent() should be used instead.
         */
-       public function getText( $audience = Revision::FOR_PUBLIC, User $user = null ) { // @todo: deprecated, replace usage!
+       public function getText( $audience = Revision::FOR_PUBLIC, User $user = null ) { // @todo deprecated, replace usage!
                ContentHandler::deprecated( __METHOD__, '1.21' );
 
                $this->loadLastEdit();
@@ -1175,7 +1175,7 @@ class WikiPage implements Page, IDBAccessObject {
                }
 
                if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
-                       // @todo: move this logic to MessageCache
+                       // @todo move this logic to MessageCache
 
                        if ( $this->exists() ) {
                                // NOTE: use transclusion text for messages.
@@ -1459,8 +1459,8 @@ class WikiPage implements Page, IDBAccessObject {
         *
         * @return boolean whether sections are supported.
         *
-        * @todo: the skin should check this and not offer section functionality if sections are not supported.
-        * @todo: the EditPage should check this and not offer section functionality if sections are not supported.
+        * @todo The skin should check this and not offer section functionality if sections are not supported.
+        * @todo The EditPage should check this and not offer section functionality if sections are not supported.
         */
        public function supportsSections() {
                return $this->getContentHandler()->supportsSections();
@@ -1956,7 +1956,7 @@ class WikiPage implements Page, IDBAccessObject {
                $options = $this->getContentHandler()->makeParserOptions( $context );
 
                if ( $this->getTitle()->isConversionTable() ) {
-                       //@todo: ConversionTable should become a separate content model, so we don't need special cases like this one.
+                       // @todo ConversionTable should become a separate content model, so we don't need special cases like this one.
                        $options->disableContentConversion();
                }
 
@@ -2109,8 +2109,7 @@ class WikiPage implements Page, IDBAccessObject {
                }
 
                DeferredUpdates::addUpdate( new SiteStatsUpdate( 0, 1, $good, $total ) );
-               DeferredUpdates::addUpdate( new SearchUpdate( $id, $title, $content->getTextForSearchIndex() ) );
-               // @TODO: let the search engine decide what to do with the content object
+               DeferredUpdates::addUpdate( new SearchUpdate( $id, $title, $content ) );
 
                // If this is another user's talk page, update newtalk.
                // Don't do this if $options['changed'] = false (null-edits) nor if
@@ -2221,7 +2220,7 @@ class WikiPage implements Page, IDBAccessObject {
         * @return Status
         */
        public function doUpdateRestrictions( array $limit, array $expiry, &$cascade, $reason, User $user ) {
-               global $wgContLang;
+               global $wgContLang, $wgCascadingRestrictionLevels;
 
                if ( wfReadOnly() ) {
                        return Status::newFatal( 'readonlytext', wfReadOnlyReason() );
@@ -2344,12 +2343,20 @@ class WikiPage implements Page, IDBAccessObject {
                                return Status::newGood();
                        }
 
-                       // Only restrictions with the 'protect' right can cascade...
-                       // Otherwise, people who cannot normally protect can "protect" pages via transclusion
+                       // Only certain restrictions can cascade... Otherwise, users who cannot normally protect pages
+                       // could "protect" them by transcluding them on protected pages they are allowed to edit.
                        $editrestriction = isset( $limit['edit'] ) ? array( $limit['edit'] ) : $this->mTitle->getRestrictions( 'edit' );
 
+                       $cascadingRestrictionLevels = $wgCascadingRestrictionLevels;
+                       foreach ( array_keys( $cascadingRestrictionLevels, 'sysop' ) as $key ) {
+                               $cascadingRestrictionLevels[$key] = 'editprotected'; // backwards compatibility
+                       }
+                       foreach ( array_keys( $cascadingRestrictionLevels, 'autoconfirmed' ) as $key ) {
+                               $cascadingRestrictionLevels[$key] = 'editsemiprotected'; // backwards compatibility
+                       }
+
                        // The schema allows multiple restrictions
-                       if ( !in_array( 'protect', $editrestriction ) && !in_array( 'sysop', $editrestriction ) ) {
+                       if ( !array_intersect( $editrestriction, $cascadingRestrictionLevels ) ) {
                                $cascade = false;
                        }
 
@@ -2438,6 +2445,7 @@ class WikiPage implements Page, IDBAccessObject {
                }
 
                $this->mTitle->flushRestrictions();
+               InfoAction::invalidateCache( $this->mTitle );
 
                if ( $logAction == 'unprotect' ) {
                        $logParams = array();
@@ -2642,7 +2650,7 @@ class WikiPage implements Page, IDBAccessObject {
        /**
         * Do some database updates after deletion
         *
-        * @param int $id page_id value of the page being deleted (B/C, currently unused)
+        * @param int $id page_id value of the page being deleted
         * @param $content Content: optional page content to be used when determining the required updates.
         *        This may be needed because $this->getContent() may already return null when the page proper was deleted.
         */
@@ -2659,6 +2667,9 @@ class WikiPage implements Page, IDBAccessObject {
 
                // Reset this object and the Title object
                $this->loadFromRow( false, self::READ_LATEST );
+
+               // Search engine
+               DeferredUpdates::addUpdate( new SearchUpdate( $id, $this->mTitle ) );
        }
 
        /**
@@ -2668,7 +2679,7 @@ class WikiPage implements Page, IDBAccessObject {
         * performs permissions checks on $user, then calls commitRollback()
         * to do the dirty work
         *
-        * @todo: separate the business/permission stuff out from backend code
+        * @todo Separate the business/permission stuff out from backend code
         *
         * @param string $fromP Name of the user whose edits to rollback.
         * @param string $summary Custom summary. Set to default summary if empty.
@@ -2908,6 +2919,7 @@ class WikiPage implements Page, IDBAccessObject {
 
                // File cache
                HTMLFileCache::clearFileCache( $title );
+               InfoAction::invalidateCache( $title );
 
                // Messages
                if ( $title->getNamespace() == NS_MEDIAWIKI ) {
@@ -2936,7 +2948,7 @@ class WikiPage implements Page, IDBAccessObject {
         * Purge caches on page update etc
         *
         * @param $title Title object
-        * @todo:  verify that $title is always a Title object (and never false or null), add Title hint to parameter $title
+        * @todo Verify that $title is always a Title object (and never false or null), add Title hint to parameter $title
         */
        public static function onArticleEdit( $title ) {
                // Invalidate caches of articles which include this page
@@ -2950,6 +2962,7 @@ class WikiPage implements Page, IDBAccessObject {
 
                // Clear file cache for this page only
                HTMLFileCache::clearFileCache( $title );
+               InfoAction::invalidateCache( $title );
        }
 
        /**#@-*/
@@ -3033,30 +3046,8 @@ class WikiPage implements Page, IDBAccessObject {
                        function() use ( $dbw, $that, $method, $added, $deleted ) {
                                $ns = $that->getTitle()->getNamespace();
 
-                               // 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;
-                               }
-
-                               $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' );
-
                                if ( $ns == NS_CATEGORY ) {
                                        $addFields[] = 'cat_subcats = cat_subcats + 1';
                                        $removeFields[] = 'cat_subcats = cat_subcats - 1';
@@ -3065,16 +3056,26 @@ class WikiPage implements Page, IDBAccessObject {
                                        $removeFields[] = 'cat_files = cat_files - 1';
                                }
 
-                               if ( $added ) {
-                                       $dbw->update(
+                               if ( count( $added ) ) {
+                                       $insertRows = array();
+                                       foreach ( $added as $cat ) {
+                                               $insertRows[] = array(
+                                                       'cat_title'   => $cat,
+                                                       'cat_pages'   => 1,
+                                                       'cat_subcats' => ( $ns == NS_CATEGORY ) ? 1 : 0,
+                                                       'cat_files'   => ( $ns == NS_FILE ) ? 1 : 0,
+                                               );
+                                       }
+                                       $dbw->upsert(
                                                'category',
+                                               $insertRows,
+                                               array( 'cat_title' ),
                                                $addFields,
-                                               array( 'cat_title' => $added ),
                                                $method
                                        );
                                }
 
-                               if ( $deleted ) {
+                               if ( count( $deleted ) ) {
                                        $dbw->update(
                                                'category',
                                                $removeFields,
@@ -3087,6 +3088,7 @@ class WikiPage implements Page, IDBAccessObject {
                                        $cat = Category::newFromName( $catName );
                                        wfRunHooks( 'CategoryAfterPageAdded', array( $cat, $that ) );
                                }
+
                                foreach ( $deleted as $catName ) {
                                        $cat = Category::newFromName( $catName );
                                        wfRunHooks( 'CategoryAfterPageRemoved', array( $cat, $that ) );
@@ -3398,7 +3400,7 @@ class PoolWorkArticleView extends PoolCounterWork {
        function doWork() {
                global $wgUseFileCache;
 
-               // @todo: several of the methods called on $this->page are not declared in Page, but present
+               // @todo several of the methods called on $this->page are not declared in Page, but present
                //        in WikiPage and delegated by Article.
 
                $isCurrent = $this->revid === $this->page->getLatest();