Merge "Add 'suppressrevision' right to new 'oversight' grant"
[lhc/web/wiklou.git] / includes / Title.php
index 972d5b1..909f528 100644 (file)
@@ -954,6 +954,7 @@ class Title implements LinkTarget {
 
        /**
         * Get the DB key with the initial letter case as specified by the user
+        * @deprecated since 1.33; please use Title::getDBKey() instead
         *
         * @return string DB key
         */
@@ -2860,10 +2861,12 @@ class Title implements LinkTarget {
                }
 
                $errors = [];
-               while ( count( $checks ) > 0 &&
-                               !( $short && count( $errors ) > 0 ) ) {
-                       $method = array_shift( $checks );
+               foreach ( $checks as $method ) {
                        $errors = $this->$method( $action, $user, $errors, $rigor, $short );
+
+                       if ( $short && $errors !== [] ) {
+                               break;
+                       }
                }
 
                return $errors;
@@ -3275,9 +3278,13 @@ class Title implements LinkTarget {
         * indicating who can move or edit the page from the page table, (pre 1.10) rows.
         * Edit and move sections are separated by a colon
         * Example: "edit=autoconfirmed,sysop:move=sysop"
+        * @param bool $readLatest When true, skip replicas and read from the master DB.
         */
-       public function loadRestrictionsFromRows( $rows, $oldFashionedRestrictions = null ) {
-               $dbr = wfGetDB( DB_REPLICA );
+       public function loadRestrictionsFromRows(
+               $rows, $oldFashionedRestrictions = null, $readLatest = false
+       ) {
+               $whichDb = $readLatest ? DB_MASTER : DB_REPLICA;
+               $dbr = wfGetDB( $whichDb );
 
                $restrictionTypes = $this->getRestrictionTypes();
 
@@ -3347,9 +3354,10 @@ class Title implements LinkTarget {
         * indicating who can move or edit the page from the page table, (pre 1.10) rows.
         * Edit and move sections are separated by a colon
         * Example: "edit=autoconfirmed,sysop:move=sysop"
+        * @param bool $readLatest When true, skip replicas and read from the master DB.
         */
-       public function loadRestrictions( $oldFashionedRestrictions = null ) {
-               if ( $this->mRestrictionsLoaded ) {
+       public function loadRestrictions( $oldFashionedRestrictions = null, $readLatest = false ) {
+               if ( $this->mRestrictionsLoaded && !$readLatest ) {
                        return;
                }
 
@@ -3359,10 +3367,11 @@ class Title implements LinkTarget {
                        $fname = __METHOD__;
                        $rows = $cache->getWithSetCallback(
                                // Page protections always leave a new null revision
-                               $cache->makeKey( 'page-restrictions', $id, $this->getLatestRevID() ),
+                               $cache->makeKey( 'page-restrictions', $id, $this->getLatestRevID(), $readLatest ),
                                $cache::TTL_DAY,
-                               function ( $curValue, &$ttl, array &$setOpts ) use ( $fname ) {
-                                       $dbr = wfGetDB( DB_REPLICA );
+                               function ( $curValue, &$ttl, array &$setOpts ) use ( $fname, $readLatest ) {
+                                       $whichDb = $readLatest ? DB_MASTER : DB_REPLICA;
+                                       $dbr = wfGetDB( $whichDb );
 
                                        $setOpts += Database::getCacheSetOptions( $dbr );
 
@@ -3377,7 +3386,7 @@ class Title implements LinkTarget {
                                }
                        );
 
-                       $this->loadRestrictionsFromRows( $rows, $oldFashionedRestrictions );
+                       $this->loadRestrictionsFromRows( $rows, $oldFashionedRestrictions, $readLatest );
                } else {
                        $title_protection = $this->getTitleProtectionInternal();
 
@@ -5220,10 +5229,9 @@ class Title implements LinkTarget {
 
                if ( MWNamespace::hasSubpages( $this->mNamespace ) ) {
                        // Optional notice for page itself and any parent page
-                       $parts = explode( '/', $this->mDbkeyform );
                        $editnotice_base = $editnotice_ns;
-                       while ( count( $parts ) > 0 ) {
-                               $editnotice_base .= '-' . array_shift( $parts );
+                       foreach ( explode( '/', $this->mDbkeyform ) as $part ) {
+                               $editnotice_base .= '-' . $part;
                                $msg = wfMessage( $editnotice_base );
                                if ( $msg->exists() ) {
                                        $html = $msg->parseAsBlock();