Merge "StringUtils: Add a utility for checking if a string is a valid regex"
[lhc/web/wiklou.git] / includes / page / Article.php
index 535aeff..6aeb038 100644 (file)
@@ -363,8 +363,16 @@ class Article implements Page {
                        }
                }
 
+               $rl = MediaWikiServices::getInstance()->getRevisionLookup();
+               $oldRev = $this->mRevision ? $this->mRevision->getRevisionRecord() : null;
                if ( $request->getVal( 'direction' ) == 'next' ) {
-                       $nextid = $this->getTitle()->getNextRevisionID( $oldid );
+                       $nextid = 0;
+                       if ( $oldRev ) {
+                               $nextRev = $rl->getNextRevision( $oldRev );
+                               if ( $nextRev ) {
+                                       $nextid = $nextRev->getId();
+                               }
+                       }
                        if ( $nextid ) {
                                $oldid = $nextid;
                                $this->mRevision = null;
@@ -372,7 +380,13 @@ class Article implements Page {
                                $this->mRedirectUrl = $this->getTitle()->getFullURL( 'redirect=no' );
                        }
                } elseif ( $request->getVal( 'direction' ) == 'prev' ) {
-                       $previd = $this->getTitle()->getPreviousRevisionID( $oldid );
+                       $previd = 0;
+                       if ( $oldRev ) {
+                               $prevRev = $rl->getPreviousRevision( $oldRev );
+                               if ( $prevRev ) {
+                                       $previd = $prevRev->getId();
+                               }
+                       }
                        if ( $previd ) {
                                $oldid = $previd;
                                $this->mRevision = null;
@@ -1310,7 +1324,10 @@ class Article implements Page {
                }
 
                $outputPage->preventClickjacking();
-               if ( $user->isAllowed( 'writeapi' ) ) {
+               if ( MediaWikiServices::getInstance()
+                               ->getPermissionManager()
+                               ->userHasRight( $user, 'writeapi' )
+               ) {
                        $outputPage->addModules( 'mediawiki.page.patrol.ajax' );
                }
 
@@ -1596,8 +1613,9 @@ class Article implements Page {
                                        'oldid' => $oldid
                                ] + $extraParams
                        );
-               $prev = $this->getTitle()->getPreviousRevisionID( $oldid );
-               $prevlink = $prev
+               $rl = MediaWikiServices::getInstance()->getRevisionLookup();
+               $prevExist = (bool)$rl->getPreviousRevision( $revision->getRevisionRecord() );
+               $prevlink = $prevExist
                        ? Linker::linkKnown(
                                $this->getTitle(),
                                $context->msg( 'previousrevision' )->escaped(),
@@ -1608,7 +1626,7 @@ class Article implements Page {
                                ] + $extraParams
                        )
                        : $context->msg( 'previousrevision' )->escaped();
-               $prevdiff = $prev
+               $prevdiff = $prevExist
                        ? Linker::linkKnown(
                                $this->getTitle(),
                                $context->msg( 'diff' )->escaped(),
@@ -1827,7 +1845,10 @@ class Article implements Page {
                        [ 'delete', $this->getTitle()->getPrefixedText() ] )
                ) {
                        # Flag to hide all contents of the archived revisions
-                       $suppress = $request->getCheck( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );
+
+                       $suppress = $request->getCheck( 'wpSuppress' ) && MediaWikiServices::getInstance()
+                                       ->getPermissionManager()
+                                       ->userHasRight( $user, 'suppressrevision' );
 
                        $this->doDelete( $reason, $suppress );
 
@@ -1929,6 +1950,8 @@ class Article implements Page {
 
                $outputPage->enableOOUI();
 
+               $fields = [];
+
                $options = Xml::listDropDownOptions(
                        $ctx->msg( 'deletereason-dropdown' )->inContentLanguage()->text(),
                        [ 'other' => $ctx->msg( 'deletereasonotherlist' )->inContentLanguage()->text() ]
@@ -1984,8 +2007,8 @@ class Article implements Page {
                                ]
                        );
                }
-
-               if ( $user->isAllowed( 'suppressrevision' ) ) {
+               $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
+               if ( $permissionManager->userHasRight( $user, 'suppressrevision' ) ) {
                        $fields[] = new OOUI\FieldLayout(
                                new OOUI\CheckboxInputWidget( [
                                        'name' => 'wpSuppress',
@@ -2043,7 +2066,7 @@ class Article implements Page {
                        ] )
                );
 
-               if ( $user->isAllowed( 'editinterface' ) ) {
+               if ( $permissionManager->userHasRight( $user, 'editinterface' ) ) {
                        $link = Linker::linkKnown(
                                $ctx->msg( 'deletereason-dropdown' )->inContentLanguage()->getTitle(),
                                wfMessage( 'delete-edit-reasonlist' )->escaped(),