Add tests for article viewing
[lhc/web/wiklou.git] / includes / page / Article.php
index 51136ff..e90334f 100644 (file)
@@ -33,23 +33,30 @@ use MediaWiki\MediaWikiServices;
  * moved to separate EditPage and HTMLFileCache classes.
  */
 class Article implements Page {
-       /** @var IContextSource The context this Article is executed in */
+       /**
+        * @var IContextSource|null The context this Article is executed in.
+        * If null, REquestContext::getMain() is used.
+        */
        protected $mContext;
 
        /** @var WikiPage The WikiPage object of this instance */
        protected $mPage;
 
-       /** @var ParserOptions ParserOptions object for $wgUser articles */
+       /**
+        * @var ParserOptions|null ParserOptions object for $wgUser articles.
+        * Initialized by getParserOptions by calling $this->mPage->makeParserOptions().
+        */
        public $mParserOptions;
 
        /**
-        * @var string Text of the revision we are working on
+        * @var string|null Text of the revision we are working on
         * @todo BC cruft
         */
        public $mContent;
 
        /**
-        * @var Content Content of the revision we are working on
+        * @var Content|null Content of the revision we are working on.
+        * Initialized by fetchContentObject().
         * @since 1.21
         */
        public $mContentObject;
@@ -60,7 +67,7 @@ class Article implements Page {
        /** @var int|null The oldid of the article that is to be shown, 0 for the current revision */
        public $mOldId;
 
-       /** @var Title Title from which we were redirected here */
+       /** @var Title|null Title from which we were redirected here, if any. */
        public $mRedirectedFrom = null;
 
        /** @var string|bool URL to redirect to or false if none */
@@ -69,10 +76,16 @@ class Article implements Page {
        /** @var int Revision ID of revision we are working on */
        public $mRevIdFetched = 0;
 
-       /** @var Revision Revision we are working on */
+       /**
+        * @var Revision|null Revision we are working on. Initialized by getOldIDFromRequest()
+        * or fetchContentObject().
+        */
        public $mRevision = null;
 
-       /** @var ParserOutput */
+       /**
+        * @var ParserOutput|null|false The ParserOutput generated for viewing the page,
+        * initialized by view(). If no ParserOutput could be generated, this is set to false.
+        */
        public $mParserOutput;
 
        /**
@@ -85,7 +98,7 @@ class Article implements Page {
        /**
         * Constructor and clear the article
         * @param Title $title Reference to a Title object.
-        * @param int $oldId Revision ID, null to fetch from request, zero for current
+        * @param int|null $oldId Revision ID, null to fetch from request, zero for current
         */
        public function __construct( Title $title, $oldId = null ) {
                $this->mOldId = $oldId;
@@ -641,7 +654,7 @@ class Article implements Page {
                # Note that $this->mParserOutput is the *current*/oldid version output.
                $pOutput = ( $outputDone instanceof ParserOutput )
                        ? $outputDone // object fetched by hook
-                       : $this->mParserOutput;
+                       : $this->mParserOutput ?: null; // ParserOutput or null, avoid false
 
                # Adjust title for main page & pages with displaytitle
                if ( $pOutput ) {
@@ -733,7 +746,7 @@ class Article implements Page {
                );
 
                // DifferenceEngine directly fetched the revision:
-               $this->mRevIdFetched = $de->mNewid;
+               $this->mRevIdFetched = $de->getNewid();
                $de->showDiffPage( $diffOnly );
 
                // Run view updates for the newer revision being diffed (and shown
@@ -750,7 +763,7 @@ class Article implements Page {
         * @return array The policy that should be set
         * @todo actions other than 'view'
         */
-       public function getRobotPolicy( $action, $pOutput = null ) {
+       public function getRobotPolicy( $action, ParserOutput $pOutput = null ) {
                global $wgArticleRobotPolicies, $wgNamespaceRobotPolicies, $wgDefaultRobotPolicy;
 
                $ns = $this->getTitle()->getNamespace();
@@ -976,6 +989,11 @@ class Article implements Page {
        public function showPatrolFooter() {
                global $wgUseNPPatrol, $wgUseRCPatrol, $wgUseFilePatrol;
 
+               // Allow hooks to decide whether to not output this at all
+               if ( !Hooks::run( 'ArticleShowPatrolFooter', [ $this ] ) ) {
+                       return false;
+               }
+
                $outputPage = $this->getContext()->getOutput();
                $user = $this->getContext()->getUser();
                $title = $this->getTitle();
@@ -1962,7 +1980,7 @@ class Article implements Page {
         * @since 1.16 (r52326) for LiquidThreads
         *
         * @param int|null $oldid Revision ID or null
-        * @param User $user The relevant user
+        * @param User|null $user The relevant user
         * @return ParserOutput|bool ParserOutput or false if the given revision ID is not found
         */
        public function getParserOutput( $oldid = null, User $user = null ) {
@@ -2615,8 +2633,8 @@ class Article implements Page {
        /**
         * @param string $reason
         * @param bool $suppress
-        * @param int $u1 Unused
-        * @param bool $u2 Unused
+        * @param int|null $u1 Unused
+        * @param bool|null $u2 Unused
         * @param string &$error
         * @return bool
         */