Merge "Remove patrol config check in User::isAllowed()"
[lhc/web/wiklou.git] / includes / page / Article.php
index 35621a4..c9af075 100644 (file)
@@ -191,7 +191,7 @@ class Article implements Page {
        }
 
        /**
-        * Note that getContent/loadContent do not follow redirects anymore.
+        * Note that getContent does not follow redirects anymore.
         * If you need to fetch redirectable content easily, try
         * the shortcut in WikiPage::getRedirectTarget()
         *
@@ -212,7 +212,7 @@ class Article implements Page {
         * Returns a Content object representing the pages effective display content,
         * not necessarily the revision's content!
         *
-        * Note that getContent/loadContent do not follow redirects anymore.
+        * Note that getContent does not follow redirects anymore.
         * If you need to fetch redirectable content easily, try
         * the shortcut in WikiPage::getRedirectTarget()
         *
@@ -309,16 +309,6 @@ class Article implements Page {
                return $oldid;
        }
 
-       /**
-        * Load the revision (including text) into this object
-        *
-        * @deprecated since 1.19; use fetchContent()
-        */
-       function loadContent() {
-               wfDeprecated( __METHOD__, '1.19' );
-               $this->fetchContent();
-       }
-
        /**
         * Get text of an article from database
         * Does *NOT* follow redirects.
@@ -1071,14 +1061,14 @@ class Article implements Page {
         * @return bool
         */
        public function showPatrolFooter() {
-               global $wgUseNPPatrol, $wgUseRCPatrol, $wgEnableAPI, $wgEnableWriteAPI;
+               global $wgUseNPPatrol, $wgUseRCPatrol, $wgUseFilePatrol, $wgEnableAPI, $wgEnableWriteAPI;
 
                $outputPage = $this->getContext()->getOutput();
                $user = $this->getContext()->getUser();
                $rc = false;
 
                if ( !$this->getTitle()->quickUserCan( 'patrol', $user )
-                       || !( $wgUseRCPatrol || $wgUseNPPatrol )
+                       || !( $wgUseRCPatrol || $wgUseNPPatrol || $wgUseFilePatrol )
                ) {
                        // Patrolling is disabled or the user isn't allowed to
                        return false;
@@ -1113,6 +1103,9 @@ class Article implements Page {
                        __METHOD__
                );
 
+               $cantPatrolNewPage = false;
+               $cantPatrolFile = false;
+
                if ( $oldestRevisionTimestamp
                        && RecentChange::isInRCLifespan( $oldestRevisionTimestamp, 21600 )
                ) {
@@ -1126,7 +1119,51 @@ class Article implements Page {
                                ),
                                __METHOD__
                        );
+                       if ( $rc ) {
+                               // Use generic patrol message for new pages
+                               $markPatrolledMsg = wfMessage( 'markaspatrolledtext' );
+                       }
                } else {
+                       $cantPatrolNewPage = true;
+               }
+
+               // Allow patrolling of latest file upload
+               if ( !$rc && $wgUseFilePatrol && $this->getTitle()->getNamespace() === NS_FILE ) {
+                       // Retrieve timestamp of most recent upload
+                       $newestUploadTimestamp = $dbr->selectField(
+                               'image',
+                               'MAX( img_timestamp )',
+                               array( 'img_name' => $this->getTitle()->getDBkey() ),
+                               __METHOD__
+                       );
+                       if ( $newestUploadTimestamp
+                               && RecentChange::isInRCLifespan( $newestUploadTimestamp, 21600 )
+                       ) {
+                               // 6h tolerance because the RC might not be cleaned out regularly
+                               $rc = RecentChange::newFromConds(
+                                       array(
+                                               'rc_type' => RC_LOG,
+                                               'rc_log_type' => 'upload',
+                                               'rc_timestamp' => $newestUploadTimestamp,
+                                               'rc_namespace' => NS_FILE,
+                                               'rc_cur_id' => $this->getTitle()->getArticleID(),
+                                               'rc_patrolled' => 0
+                                       ),
+                                       __METHOD__,
+                                       array( 'USE INDEX' => 'rc_timestamp' )
+                               );
+                               if ( $rc ) {
+                                       // Use patrol message specific to files
+                                       $markPatrolledMsg = wfMessage( 'markaspatrolledtext-file' );
+                               }
+                       } else {
+                               $cantPatrolFile = true;
+                       }
+               } else {
+                       $cantPatrolFile = true;
+               }
+
+               if ( $cantPatrolFile && $cantPatrolNewPage ) {
                        // Cache the information we gathered above in case we can't patrol
                        // Don't cache in case we can patrol as this could change
                        $cache->set( $key, '1' );
@@ -1166,7 +1203,7 @@ class Article implements Page {
 
                $link = Linker::linkKnown(
                        $this->getTitle(),
-                       wfMessage( 'markaspatrolledtext' )->escaped(),
+                       $markPatrolledMsg->escaped(),
                        array(),
                        array(
                                'action' => 'markpatrolled',
@@ -1184,6 +1221,17 @@ class Article implements Page {
                return true;
        }
 
+       /**
+        * Purge the cache used to check if it is worth showing the patrol footer
+        * For example, it is done during re-uploads when file patrol is used.
+        * @param int $articleID ID of the article to purge
+        * @since 1.27
+        */
+       public static function purgePatrolFooterCache( $articleID ) {
+               $cache = ObjectCache::getMainWANInstance();
+               $cache->delete( wfMemcKey( 'unpatrollable-page', $articleID ) );
+       }
+
        /**
         * Show the error text for a missing article. For articles in the MediaWiki
         * namespace, show the default message text. To be called from Article::view().