Converted ApiQueryPageProps to use PageProps; added multi-property query to PageProps.
[lhc/web/wiklou.git] / includes / actions / InfoAction.php
index 6560083..4027b35 100644 (file)
@@ -139,11 +139,6 @@ class InfoAction extends FormlessAction {
                        $content .= $this->msg( 'pageinfo-footer' )->parse();
                }
 
-               // Page credits
-               /*if ( $this->page->exists() ) {
-                       $content .= Html::rawElement( 'div', array( 'id' => 'mw-credits' ), $this->getContributors() );
-               }*/
-
                return $content;
        }
 
@@ -169,10 +164,13 @@ class InfoAction extends FormlessAction {
         * @return string The table with the row added
         */
        protected function addRow( $table, $name, $value, $id ) {
-               return $table . Html::rawElement( 'tr', $id === null ? array() : array( 'id' => 'mw-' . $id ),
-                       Html::rawElement( 'td', array( 'style' => 'vertical-align: top;' ), $name ) .
-                       Html::rawElement( 'td', array(), $value )
-               );
+               return $table .
+                       Html::rawElement(
+                               'tr',
+                               $id === null ? array() : array( 'id' => 'mw-' . $id ),
+                               Html::rawElement( 'td', array( 'style' => 'vertical-align: top;' ), $name ) .
+                                       Html::rawElement( 'td', array(), $value )
+                       );
        }
 
        /**
@@ -205,18 +203,10 @@ class InfoAction extends FormlessAction {
 
                $pageCounts = $this->pageCounts( $this->page );
 
-               // Get page properties
-               $dbr = wfGetDB( DB_SLAVE );
-               $result = $dbr->select(
-                       'page_props',
-                       array( 'pp_propname', 'pp_value' ),
-                       array( 'pp_page' => $id ),
-                       __METHOD__
-               );
-
                $pageProperties = array();
-               foreach ( $result as $row ) {
-                       $pageProperties[$row->pp_propname] = $row->pp_value;
+               $props = PageProps::getInstance()->getAllProperties( $title );
+               if ( isset( $props[$id] ) ) {
+                       $pageProperties = $props[$id];
                }
 
                // Basic information
@@ -305,7 +295,8 @@ class InfoAction extends FormlessAction {
                $policy = $this->page->getRobotPolicy( 'view', $pOutput );
                $pageInfo['header-basic'][] = array(
                        // Messages: pageinfo-robot-index, pageinfo-robot-noindex
-                       $this->msg( 'pageinfo-robot-policy' ), $this->msg( "pageinfo-robot-${policy['index']}" )
+                       $this->msg( 'pageinfo-robot-policy' ),
+                       $this->msg( "pageinfo-robot-${policy['index']}" )
                );
 
                $unwatchedPageThreshold = $config->get( 'UnwatchedPageThreshold' );
@@ -371,7 +362,8 @@ class InfoAction extends FormlessAction {
 
                // Subpages of this page, if subpages are enabled for the current NS
                if ( MWNamespace::hasSubpages( $title->getNamespace() ) ) {
-                       $prefixIndex = SpecialPage::getTitleFor( 'Prefixindex', $title->getPrefixedText() . '/' );
+                       $prefixIndex = SpecialPage::getTitleFor(
+                               'Prefixindex', $title->getPrefixedText() . '/' );
                        $pageInfo['header-basic'][] = array(
                                Linker::link( $prefixIndex, $this->msg( 'pageinfo-subpages-name' )->escaped() ),
                                $this->msg( 'pageinfo-subpages-value' )
@@ -418,10 +410,11 @@ class InfoAction extends FormlessAction {
                // Is this page affected by the cascading protection of something which includes it?
                if ( $title->isCascadeProtected() ) {
                        $cascadingFrom = '';
-                       $sources = $title->getCascadeProtectionSources(); // Array deferencing is in PHP 5.4 :(
+                       $sources = $title->getCascadeProtectionSources()[0];
 
-                       foreach ( $sources[0] as $sourceTitle ) {
-                               $cascadingFrom .= Html::rawElement( 'li', array(), Linker::linkKnown( $sourceTitle ) );
+                       foreach ( $sources as $sourceTitle ) {
+                               $cascadingFrom .= Html::rawElement(
+                                       'li', array(), Linker::linkKnown( $sourceTitle ) );
                        }
 
                        $cascadingFrom = Html::rawElement( 'ul', array(), $cascadingFrom );
@@ -529,7 +522,9 @@ class InfoAction extends FormlessAction {
                                $this->msg( 'pageinfo-lasttime' ),
                                Linker::linkKnown(
                                        $title,
-                                       htmlspecialchars( $lang->userTimeAndDate( $this->page->getTimestamp(), $user ) ),
+                                       htmlspecialchars(
+                                               $lang->userTimeAndDate( $this->page->getTimestamp(), $user )
+                                       ),
                                        array(),
                                        array( 'oldid' => $this->page->getLatest() )
                                )
@@ -550,13 +545,15 @@ class InfoAction extends FormlessAction {
 
                // Recent number of edits (within past 30 days)
                $pageInfo['header-edits'][] = array(
-                       $this->msg( 'pageinfo-recent-edits', $lang->formatDuration( $config->get( 'RCMaxAge' ) ) ),
+                       $this->msg( 'pageinfo-recent-edits',
+                               $lang->formatDuration( $config->get( 'RCMaxAge' ) ) ),
                        $lang->formatNum( $pageCounts['recent_edits'] )
                );
 
                // Recent number of distinct authors
                $pageInfo['header-edits'][] = array(
-                       $this->msg( 'pageinfo-recent-authors' ), $lang->formatNum( $pageCounts['recent_authors'] )
+                       $this->msg( 'pageinfo-recent-authors' ),
+                       $lang->formatNum( $pageCounts['recent_authors'] )
                );
 
                // Array of MagicWord objects
@@ -670,6 +667,7 @@ class InfoAction extends FormlessAction {
 
                return ObjectCache::getMainWANInstance()->getWithSetCallback(
                        self::getCacheKey( $page->getTitle(), $page->getLatest() ),
+                       86400 * 7,
                        function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname ) {
                                $title = $page->getTitle();
                                $id = $title->getArticleID();
@@ -677,7 +675,7 @@ class InfoAction extends FormlessAction {
                                $dbr = wfGetDB( DB_SLAVE );
                                $dbrWatchlist = wfGetDB( DB_SLAVE, 'watchlist' );
 
-                               $setOpts += DatabaseBase::getCacheSetOptions( $dbr, $dbrWatchlist );
+                               $setOpts += Database::getCacheSetOptions( $dbr, $dbrWatchlist );
 
                                $result = array();
 
@@ -705,8 +703,9 @@ class InfoAction extends FormlessAction {
                                                array(
                                                        'wl_namespace' => $title->getNamespace(),
                                                        'wl_title' => $title->getDBkey(),
-                                                       'wl_notificationtimestamp >= ' . $dbrWatchlist->addQuotes( $threshold ) .
-                                                       ' OR wl_notificationtimestamp IS NULL'
+                                                       'wl_notificationtimestamp >= ' .
+                                                               $dbrWatchlist->addQuotes( $threshold ) .
+                                                               ' OR wl_notificationtimestamp IS NULL'
                                                ),
                                                $fname
                                        );
@@ -812,8 +811,7 @@ class InfoAction extends FormlessAction {
                                );
 
                                return $result;
-                       },
-                       86400 * 7
+                       }
                );
        }
 
@@ -859,15 +857,17 @@ class InfoAction extends FormlessAction {
 
                # "ThisSite user(s) A, B and C"
                if ( count( $user_names ) ) {
-                       $user = $this->msg( 'siteusers' )->rawParams( $lang->listToText( $user_names ) )->params(
-                               count( $user_names ) )->escaped();
+                       $user = $this->msg( 'siteusers' )
+                               ->rawParams( $lang->listToText( $user_names ) )
+                               ->params( count( $user_names ) )->escaped();
                } else {
                        $user = false;
                }
 
                if ( count( $anon_ips ) ) {
-                       $anon = $this->msg( 'anonusers' )->rawParams( $lang->listToText( $anon_ips ) )->params(
-                               count( $anon_ips ) )->escaped();
+                       $anon = $this->msg( 'anonusers' )
+                               ->rawParams( $lang->listToText( $anon_ips ) )
+                               ->params( count( $anon_ips ) )->escaped();
                } else {
                        $anon = false;
                }