X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FQueryPage.php;h=86a988e987b3a0a513028caf19f7cc46680d9337;hb=f52af0ba90235fff9aedb5d4b1eabdff9397f41d;hp=8c815e37e2db039f4de0b8dfebac8c46f918e14b;hpb=087a9f70c5c152b72dc6c539cf64e334a0f2d029;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/QueryPage.php b/includes/QueryPage.php index 8c815e37e2..86a988e987 100644 --- a/includes/QueryPage.php +++ b/includes/QueryPage.php @@ -21,6 +21,7 @@ $wgQueryPages = array( array( 'DeadendPagesPage', 'Deadendpages' ), array( 'DisambiguationsPage', 'Disambiguations' ), array( 'DoubleRedirectsPage', 'DoubleRedirects' ), + array( 'LinkSearchPage', 'LinkSearch' ), array( 'ListredirectsPage', 'Listredirects' ), array( 'LonelyPagesPage', 'Lonelypages' ), array( 'LongPagesPage', 'Longpages' ), @@ -39,7 +40,9 @@ $wgQueryPages = array( array( 'UnusedCategoriesPage', 'Unusedcategories' ), array( 'UnusedimagesPage', 'Unusedimages' ), array( 'WantedCategoriesPage', 'Wantedcategories' ), + array( 'WantedFilesPage', 'Wantedfiles' ), array( 'WantedPagesPage', 'Wantedpages' ), + array( 'WantedTemplatesPage', 'Wantedtemplates' ), array( 'UnwatchedPagesPage', 'Unwatchedpages' ), array( 'UnusedtemplatesPage', 'Unusedtemplates' ), array( 'WithoutInterwikiPage', 'Withoutinterwiki' ), @@ -201,9 +204,9 @@ class QueryPage { * Clear the cache and save new results */ function recache( $limit, $ignoreErrors = true ) { - $fname = get_class($this) . '::recache'; + $fname = get_class( $this ) . '::recache'; $dbw = wfGetDB( DB_MASTER ); - $dbr = wfGetDB( DB_SLAVE, array( $this->getName(), 'QueryPage::recache', 'vslow' ) ); + $dbr = wfGetDB( DB_SLAVE, array( $this->getName(), __METHOD__, 'vslow' ) ); if ( !$dbw || !$dbr ) { return false; } @@ -219,37 +222,30 @@ class QueryPage { $dbw->delete( 'querycache', array( 'qc_type' => $this->getName() ), $fname ); # Do query $sql = $this->getSQL() . $this->getOrder(); - if ($limit !== false) - $sql = $dbr->limitResult($sql, $limit, 0); - $res = $dbr->query($sql, $fname); + if ( $limit !== false ) + $sql = $dbr->limitResult( $sql, $limit, 0 ); + $res = $dbr->query( $sql, $fname ); $num = false; if ( $res ) { $num = $dbr->numRows( $res ); # Fetch results - $insertSql = "INSERT INTO $querycache (qc_type,qc_namespace,qc_title,qc_value) VALUES "; - $first = true; + $vals = array(); while ( $res && $row = $dbr->fetchObject( $res ) ) { - if ( $first ) { - $first = false; - } else { - $insertSql .= ','; - } if ( isset( $row->value ) ) { - $value = $row->value; + $value = intval( $row->value ); // @bug 14414 } else { - $value = ''; + $value = 0; } - - $insertSql .= '(' . - $dbw->addQuotes( $row->type ) . ',' . - $dbw->addQuotes( $row->namespace ) . ',' . - $dbw->addQuotes( $row->title ) . ',' . - $dbw->addQuotes( $value ) . ')'; + + $vals[] = array('qc_type' => $row->type, + 'qc_namespace' => $row->namespace, + 'qc_title' => $row->title, + 'qc_value' => $value); } # Save results into the querycache table on the master - if ( !$first ) { - if ( !$dbw->query( $insertSql, $fname ) ) { + if ( count( $vals ) ) { + if ( !$dbw->insert( 'querycache', $vals, __METHOD__ ) ) { // Set result to false to indicate error $dbr->freeResult( $res ); $res = false; @@ -334,22 +330,22 @@ class QueryPage { $this->preprocessResults( $dbr, $res ); - $wgOut->addHtml( XML::openElement( 'div', array('class' => 'mw-spcontent') ) ); + $wgOut->addHTML( XML::openElement( 'div', array('class' => 'mw-spcontent') ) ); # Top header and navigation if( $shownavigation ) { - $wgOut->addHtml( $this->getPageHeader() ); + $wgOut->addHTML( $this->getPageHeader() ); if( $num > 0 ) { - $wgOut->addHtml( '

' . wfShowingResults( $offset, $num ) . '

' ); + $wgOut->addHTML( '

' . wfShowingResults( $offset, $num ) . '

' ); # Disable the "next" link when we reach the end $paging = wfViewPrevNext( $offset, $limit, $wgContLang->specialPage( $sname ), wfArrayToCGI( $this->linkParameters() ), ( $num < $limit ) ); - $wgOut->addHtml( '

' . $paging . '

' ); + $wgOut->addHTML( '

' . $paging . '

' ); } else { # No results to show, so don't bother with "showing X of Y" etc. # -- just let the user know and give up now - $wgOut->addHtml( '

' . wfMsgHtml( 'specialpage-empty' ) . '

' ); - $wgOut->addHtml( XML::closeElement( 'div' ) ); + $wgOut->addHTML( '

' . wfMsgHtml( 'specialpage-empty' ) . '

' ); + $wgOut->addHTML( XML::closeElement( 'div' ) ); return; } } @@ -366,10 +362,10 @@ class QueryPage { # Repeat the paging links at the bottom if( $shownavigation ) { - $wgOut->addHtml( '

' . $paging . '

' ); + $wgOut->addHTML( '

' . $paging . '

' ); } - $wgOut->addHtml( XML::closeElement( 'div' ) ); + $wgOut->addHTML( XML::closeElement( 'div' ) ); return $num; } @@ -428,7 +424,7 @@ class QueryPage { ? $wgContLang->listToText( $html ) : implode( '', $html ); - $out->addHtml( $html ); + $out->addHTML( $html ); } } @@ -531,7 +527,7 @@ class QueryPage { } function feedDesc() { - return wfMsg( 'tagline' ); + return wfMsgExt( 'tagline', 'parsemag' ); } function feedUrl() { @@ -539,3 +535,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() + ? '' . $skin->link( $title ) . '' + : $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 Title to make the link for + * @param Skin $skin Skin to use + * @param object $result 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() ) ); + } +}