X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FOutputPage.php;h=14639aa86751b27a8aaac4aa4b93da7c9126dbfa;hb=3f67d38778da9f142f93e048bd5bbd6d1739a773;hp=b7341e3b7a2a8b90e65de3bd9190cbb6ad8c04ab;hpb=dd62bdfd87ef59e923f25394e3c2b961dcf0092d;p=lhc%2Fweb%2Fwiklou.git
diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index b7341e3b7a..14639aa867 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -44,7 +44,7 @@ use Wikimedia\WrappedStringList;
* @todo document
*/
class OutputPage extends ContextSource {
- /** @var array Should be private. Used with addMeta() which adds "" */
+ /** @var string[][] Should be private. Used with addMeta() which adds "" */
protected $mMetatags = [];
/** @var array */
@@ -995,6 +995,8 @@ class OutputPage extends ContextSource {
* @param Title $t
*/
public function setTitle( Title $t ) {
+ // @phan-suppress-next-next-line PhanUndeclaredMethod
+ // @fixme Not all implementations of IContextSource have this method!
$this->getContext()->setTitle( $t );
}
@@ -1661,6 +1663,16 @@ class OutputPage extends ContextSource {
return $this->mRevisionId;
}
+ /**
+ * Whether the revision displayed is the latest revision of the page
+ *
+ * @since 1.34
+ * @return bool
+ */
+ public function isRevisionCurrent() {
+ return $this->mRevisionId == 0 || $this->mRevisionId == $this->getTitle()->getLatestRevID();
+ }
+
/**
* Set the timestamp of the revision which will be displayed. This is used
* to avoid a extra DB call in Skin::lastModified().
@@ -1810,14 +1822,10 @@ class OutputPage extends ContextSource {
* @param string $text Wikitext
* @param Title $title
* @param bool $linestart Is this the start of a line?
- * @param bool $tidy Whether to use tidy.
- * Setting this to false (or omitting it) is deprecated
- * since 1.32; all wikitext should be tidied.
* @param bool $interface Whether it is an interface message
* (for example disables conversion)
* @param string $wrapperClass if not empty, wraps the output in
* a `
`
- * @private
*/
private function addWikiTextTitleInternal(
$text, Title $title, $linestart, $interface, $wrapperClass = null
@@ -2666,6 +2674,8 @@ class OutputPage extends ContextSource {
* @param string|null $action Action that was denied or null if unknown
*/
public function showPermissionsErrorPage( array $errors, $action = null ) {
+ $services = MediaWikiServices::getInstance();
+ $permissionManager = $services->getPermissionManager();
foreach ( $errors as $key => $error ) {
$errors[$key] = (array)$error;
}
@@ -2675,11 +2685,12 @@ class OutputPage extends ContextSource {
// 1. the user is not logged in
// 2. the only error is insufficient permissions (i.e. no block or something else)
// 3. the error can be avoided simply by logging in
+
if ( in_array( $action, [ 'read', 'edit', 'createpage', 'createtalk', 'upload' ] )
&& $this->getUser()->isAnon() && count( $errors ) == 1 && isset( $errors[0][0] )
&& ( $errors[0][0] == 'badaccess-groups' || $errors[0][0] == 'badaccess-group0' )
- && ( User::groupHasPermission( 'user', $action )
- || User::groupHasPermission( 'autoconfirmed', $action ) )
+ && ( $permissionManager->groupHasPermission( 'user', $action )
+ || $permissionManager->groupHasPermission( 'autoconfirmed', $action ) )
) {
$displayReturnto = null;
@@ -2715,8 +2726,6 @@ class OutputPage extends ContextSource {
}
}
- $services = MediaWikiServices::getInstance();
-
$title = SpecialPage::getTitleFor( 'Userlogin' );
$linkRenderer = $services->getLinkRenderer();
$loginUrl = $title->getLinkURL( $query, false, PROTO_RELATIVE );
@@ -2730,8 +2739,6 @@ class OutputPage extends ContextSource {
$this->prepareErrorPage( $this->msg( 'loginreqtitle' ) );
$this->addHTML( $this->msg( $msg )->rawParams( $loginLink )->params( $loginUrl )->parse() );
- $permissionManager = $services->getPermissionManager();
-
# Don't return to a page the user can't read otherwise
# we'll end up in a pointless loop
if ( $displayReturnto && $permissionManager->userCan(
@@ -3218,7 +3225,7 @@ class OutputPage extends ContextSource {
$title = $this->getTitle();
$ns = $title->getNamespace();
- $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
+ $nsInfo = $services->getNamespaceInfo();
$canonicalNamespace = $nsInfo->exists( $ns )
? $nsInfo->getCanonicalName( $ns )
: $title->getNsText();
@@ -3302,12 +3309,10 @@ class OutputPage extends ContextSource {
$vars['wgUserVariant'] = $contLang->getPreferredVariant();
}
// Same test as SkinTemplate
- $vars['wgIsProbablyEditable'] = $title->quickUserCan( 'edit', $user )
- && ( $title->exists() || $title->quickUserCan( 'create', $user ) );
+ $vars['wgIsProbablyEditable'] = $this->userCanEditOrCreate( $user, $title );
- $vars['wgRelevantPageIsProbablyEditable'] = $relevantTitle
- && $relevantTitle->quickUserCan( 'edit', $user )
- && ( $relevantTitle->exists() || $relevantTitle->quickUserCan( 'create', $user ) );
+ $vars['wgRelevantPageIsProbablyEditable'] = $relevantTitle &&
+ $this->userCanEditOrCreate( $user, $relevantTitle );
foreach ( $title->getRestrictionTypes() as $type ) {
// Following keys are set in $vars:
@@ -3374,6 +3379,21 @@ class OutputPage extends ContextSource {
return true;
}
+ /**
+ * @param User $user
+ * @param LinkTarget $title
+ * @return bool
+ */
+ private function userCanEditOrCreate(
+ User $user,
+ LinkTarget $title
+ ) {
+ $pm = MediaWikiServices::getInstance()->getPermissionManager();
+ return $pm->quickUserCan( 'edit', $user, $title )
+ && ( $this->getTitle()->exists() ||
+ $pm->quickUserCan( 'create', $user, $title ) );
+ }
+
/**
* @return array Array in format "link name or number => 'link html'".
*/
@@ -3438,11 +3458,7 @@ class OutputPage extends ContextSource {
# Universal edit button
if ( $config->get( 'UniversalEditButton' ) && $this->isArticleRelated() ) {
- $user = $this->getUser();
- if ( $this->getTitle()->quickUserCan( 'edit', $user )
- && ( $this->getTitle()->exists() ||
- $this->getTitle()->quickUserCan( 'create', $user ) )
- ) {
+ if ( $this->userCanEditOrCreate( $this->getUser(), $this->getTitle() ) ) {
// Original UniversalEditButton
$msg = $this->msg( 'edit' )->text();
$tags['universal-edit-button'] = Html::element( 'link', [