Merge "Fix form submission on Special:RandomInCategory"
[lhc/web/wiklou.git] / includes / WikiPage.php
index 4aab674..ce26fb9 100644 (file)
@@ -2071,7 +2071,9 @@ class WikiPage implements Page, IDBAccessObject {
 
                // Update the links tables and other secondary data
                if ( $content ) {
-                       $updates = $content->getSecondaryDataUpdates( $this->getTitle(), null, true, $editInfo->output );
+                       $recursive = $options['changed']; // bug 50785
+                       $updates = $content->getSecondaryDataUpdates(
+                               $this->getTitle(), null, $recursive, $editInfo->output );
                        DataUpdate::runUpdates( $updates );
                }
 
@@ -2343,9 +2345,14 @@ class WikiPage implements Page, IDBAccessObject {
                                return Status::newGood();
                        }
 
-                       // 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.
+                       // Only certain restrictions can cascade...
                        $editrestriction = isset( $limit['edit'] ) ? array( $limit['edit'] ) : $this->mTitle->getRestrictions( 'edit' );
+                       foreach ( array_keys( $editrestriction, 'sysop' ) as $key ) {
+                               $editrestriction[$key] = 'editprotected'; // backwards compatibility
+                       }
+                       foreach ( array_keys( $editrestriction, 'autoconfirmed' ) as $key ) {
+                               $editrestriction[$key] = 'editsemiprotected'; // backwards compatibility
+                       }
 
                        $cascadingRestrictionLevels = $wgCascadingRestrictionLevels;
                        foreach ( array_keys( $cascadingRestrictionLevels, 'sysop' ) as $key ) {
@@ -2360,24 +2367,6 @@ class WikiPage implements Page, IDBAccessObject {
                                $cascade = false;
                        }
 
-                       // Update restrictions table
-                       foreach ( $limit as $action => $restrictions ) {
-                               if ( $restrictions != '' ) {
-                                       $dbw->replace( 'page_restrictions', array( array( 'pr_page', 'pr_type' ) ),
-                                               array( 'pr_page' => $id,
-                                                       'pr_type' => $action,
-                                                       'pr_level' => $restrictions,
-                                                       'pr_cascade' => ( $cascade && $action == 'edit' ) ? 1 : 0,
-                                                       'pr_expiry' => $encodedExpiry[$action]
-                                               ),
-                                               __METHOD__
-                                       );
-                               } else {
-                                       $dbw->delete( 'page_restrictions', array( 'pr_page' => $id,
-                                               'pr_type' => $action ), __METHOD__ );
-                               }
-                       }
-
                        // Prepare a null revision to be added to the history
                        $editComment = $wgContLang->ucfirst(
                                wfMessage(
@@ -2399,8 +2388,30 @@ class WikiPage implements Page, IDBAccessObject {
                                )->inContentLanguage()->text();
                        }
 
-                       // Insert a null revision
                        $nullRevision = Revision::newNullRevision( $dbw, $id, $editComment, true );
+                       if ( $nullRevision === null ) {
+                               return Status::newFatal( 'no-null-revision', $this->mTitle->getPrefixedText() );
+                       }
+
+                       // Update restrictions table
+                       foreach ( $limit as $action => $restrictions ) {
+                               if ( $restrictions != '' ) {
+                                       $dbw->replace( 'page_restrictions', array( array( 'pr_page', 'pr_type' ) ),
+                                               array( 'pr_page' => $id,
+                                                       'pr_type' => $action,
+                                                       'pr_level' => $restrictions,
+                                                       'pr_cascade' => ( $cascade && $action == 'edit' ) ? 1 : 0,
+                                                       'pr_expiry' => $encodedExpiry[$action]
+                                               ),
+                                               __METHOD__
+                                       );
+                               } else {
+                                       $dbw->delete( 'page_restrictions', array( 'pr_page' => $id,
+                                               'pr_type' => $action ), __METHOD__ );
+                               }
+                       }
+
+                       // Insert a null revision
                        $nullRevId = $nullRevision->insertOn( $dbw );
 
                        $latest = $this->getLatest();
@@ -2967,6 +2978,29 @@ class WikiPage implements Page, IDBAccessObject {
 
        /**#@-*/
 
+       /**
+        * Returns a list of categories this page is a member of.
+        * Results will include hidden categories
+        *
+        * @return TitleArray
+        */
+       public function getCategories() {
+               $id = $this->getId();
+               if ( $id == 0 ) {
+                       return TitleArray::newFromResult( new FakeResultWrapper( array() ) );
+               }
+
+               $dbr = wfGetDB( DB_SLAVE );
+               $res = $dbr->select( 'categorylinks',
+                       array( 'cl_to AS page_title, ' . NS_CATEGORY . ' AS page_namespace' ),
+                       // Have to do that since DatabaseBase::fieldNamesWithAlias treats numeric indexes
+                       // as not being aliases, and NS_CATEGORY is numeric
+                       array( 'cl_from' => $id ),
+                       __METHOD__ );
+
+               return TitleArray::newFromResult( $res );
+       }
+
        /**
         * Returns a list of hidden categories this page is a member of.
         * Uses the page_props and categorylinks tables.