moving SpecialUploadMogile.php from phase3/includes/specials to extensions/MogileClie...
[lhc/web/wiklou.git] / includes / QueryPage.php
index b22231f..9d89ac3 100644 (file)
@@ -245,7 +245,7 @@ class QueryPage {
 
                        # Save results into the querycache table on the master
                        if ( count( $vals ) ) {
-                               if ( !$dbw->insert( 'querycache', $vals, __METHOD__ ) {
+                               if ( !$dbw->insert( 'querycache', $vals, __METHOD__ ) {
                                        // Set result to false to indicate error
                                        $dbr->freeResult( $res );
                                        $res = false;
@@ -304,10 +304,12 @@ class QueryPage {
                                $tRow = $dbr->fetchObject( $tRes );
 
                                if( $tRow ) {
-                                       $updated = $wgLang->timeAndDate( $tRow->qci_timestamp, true, true );
+                                       $updated = $wgLang->timeanddate( $tRow->qci_timestamp, true, true );
+                                       $updateddate = $wgLang->date( $tRow->qci_timestamp, true, true );
+                                       $updatedtime = $wgLang->time( $tRow->qci_timestamp, true, true );
                                        $wgOut->addMeta( 'Data-Cache-Time', $tRow->qci_timestamp );
                                        $wgOut->addInlineScript( "var dataCacheTime = '{$tRow->qci_timestamp}';" );
-                                       $wgOut->addWikiMsg( 'perfcachedts', $updated );
+                                       $wgOut->addWikiMsg( 'perfcachedts', $updated, $updateddate, $updatedtime );
                                } else {
                                        $wgOut->addWikiMsg( 'perfcached' );
                                }
@@ -535,3 +537,85 @@ class QueryPage {
                return $title->getFullURL();
        }
 }
+
+/**
+ * Class definition for a wanted query page like
+ * WantedPages, WantedTemplates, etc
+ */
+abstract class WantedQueryPage extends QueryPage {
+
+       function isExpensive() {
+               return true;
+       }
+
+       function isSyndicated() {
+               return false;
+       }
+
+       /**
+        * Cache page existence for performance
+        */
+       function preprocessResults( $db, $res ) {
+               $batch = new LinkBatch;
+               while ( $row = $db->fetchObject( $res ) )
+                       $batch->add( $row->namespace, $row->title );
+               $batch->execute();
+
+               // Back to start for display
+               if ( $db->numRows( $res ) > 0 )
+                       // If there are no rows we get an error seeking.
+                       $db->dataSeek( $res, 0 );
+       }
+       
+       /**
+        * Format an individual result
+        *
+        * @param $skin Skin to use for UI elements
+        * @param $result Result row
+        * @return string
+        */
+       public function formatResult( $skin, $result ) {
+               $title = Title::makeTitleSafe( $result->namespace, $result->title );
+               if( $title instanceof Title ) {
+                       if( $this->isCached() ) {
+                               $pageLink = $title->exists()
+                                       ? '<s>' . $skin->link( $title ) . '</s>'
+                                       : $skin->link(
+                                               $title,
+                                               null,
+                                               array(),
+                                               array(),
+                                               array( 'broken' )
+                                       );
+                       } else {
+                               $pageLink = $skin->link(
+                                       $title,
+                                       null,
+                                       array(),
+                                       array(),
+                                       array( 'broken' )
+                               );
+                       }
+                       return wfSpecialList( $pageLink, $this->makeWlhLink( $title, $skin, $result ) );
+               } else {
+                       $tsafe = htmlspecialchars( $result->title );
+                       return wfMsgHtml( 'wantedpages-badtitle', $tsafe );
+               }
+       }
+       
+       /**
+        * Make a "what links here" link for a given title
+        *
+        * @param $title Title to make the link for
+        * @param $skin Skin object to use
+        * @param $result Object: result row
+        * @return string
+        */
+       private function makeWlhLink( $title, $skin, $result ) {
+               global $wgLang;
+               $wlh = SpecialPage::getTitleFor( 'Whatlinkshere' );
+               $label = wfMsgExt( 'nlinks', array( 'parsemag', 'escape' ),
+               $wgLang->formatNum( $result->value ) );
+               return $skin->link( $wlh, $label, array(), array( 'target' => $title->getPrefixedText() ) );
+       }
+}