Merge "resourceloader: Compile documentElement.className server-side"
[lhc/web/wiklou.git] / includes / OutputPage.php
index d63d376..15a759b 100644 (file)
@@ -44,7 +44,7 @@ use Wikimedia\WrappedStringList;
  * @todo document
  */
 class OutputPage extends ContextSource {
-       /** @var array Should be private. Used with addMeta() which adds "<meta>" */
+       /** @var string[][] Should be private. Used with addMeta() which adds "<meta>" */
        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 );
        }
 
@@ -1820,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 `<div class="$wrapperClass">`
-        * @private
         */
        private function addWikiTextTitleInternal(
                $text, Title $title, $linestart, $interface, $wrapperClass = null
@@ -3228,7 +3226,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();
@@ -3312,12 +3310,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:
@@ -3384,6 +3380,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'".
         */
@@ -3448,11 +3459,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', [