r57279 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57278‎ | r57279 | r57280 >
Date:09:11, 2 October 2009
Author:thomasv
Status:deferred
Tags:
Comment:
search button using SearchEngine (follow up r57173)
Modified paths:
  • /trunk/extensions/ProofreadPage/ProofreadPage.i18n.php (modified) (history)
  • /trunk/extensions/ProofreadPage/SpecialProofreadPages.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ProofreadPage/ProofreadPage.i18n.php
@@ -68,6 +68,8 @@
6969 <td ><span id=pr_index style=\"visibility:hidden;\">$7</span></td>
7070 </tr></table>",
7171 'proofreadpage_pages' => "{{PLURAL:$1|page|pages}}",
 72+ 'proofreadpage_specialpage_text' => '',
 73+ 'proofreadpage_specialpage_legend' => 'Search index pages',
7274 );
7375
7476 /** Message documentation (Message documentation)
Index: trunk/extensions/ProofreadPage/SpecialProofreadPages.php
@@ -17,10 +17,39 @@
1818 }
1919
2020 function execute( $parameters ) {
 21+ global $wgOut, $wgRequest, $wgDisableTextSearch;
 22+
2123 $this->setHeaders();
2224 list( $limit, $offset ) = wfCheckLimits();
23 -
24 - $cnl = new ProofreadPagesQuery();
 25+ $wgOut->addWikiText( wfMsgForContentNoTrans( 'proofreadpage_specialpage_text' ) );
 26+ $searchList = array();
 27+ if( ! $wgDisableTextSearch ) {
 28+ $searchTerm = $wgRequest->getText( 'key' );
 29+ $wgOut->addHTML(
 30+ Xml::openElement( 'form' ) .
 31+ Xml::openElement( 'fieldset' ) .
 32+ Xml::element( 'legend', null, wfMsg( 'proofreadpage_specialpage_legend' ) ) .
 33+ Xml::input( 'key', 20, $searchTerm ) . ' ' .
 34+ Xml::submitButton( wfMsg( 'ilsubmit' ) ) .
 35+ Xml::closeElement( 'fieldset' ) .
 36+ Xml::closeElement( 'form' )
 37+ );
 38+ if( $searchTerm ) {
 39+ $index_namespace = pr_index_ns() ;
 40+ $index_ns_index = MWNamespace::getCanonicalIndex( strtolower( $index_namespace ) );
 41+ $searchEngine = SearchEngine::create();
 42+ $searchEngine->setLimitOffset( $limit, $offset );
 43+ $searchEngine->setNamespaces( array( $index_ns_index ) );
 44+ $searchEngine->showRedirects = false;
 45+ $textMatches = $searchEngine->searchText( $searchTerm );
 46+ while( $result = $textMatches->next() ) {
 47+ if ( preg_match( "/^$index_namespace:(.*)$/", $result->getTitle(), $m ) ) {
 48+ array_push( $searchList, str_replace( ' ' , '_' , $m[1] ) );
 49+ }
 50+ }
 51+ }
 52+ }
 53+ $cnl = new ProofreadPagesQuery( $searchList );
2554 $cnl->doQuery( $offset, $limit );
2655 }
2756 }
@@ -29,6 +58,10 @@
3059
3160 class ProofreadPagesQuery extends QueryPage {
3261
 62+ function ProofreadPagesQuery( $searchList ) {
 63+ $this->searchList = $searchList;
 64+ }
 65+
3366 function getName() {
3467 return 'IndexPages';
3568 }
@@ -46,17 +79,24 @@
4780 $page = $dbr->tableName( 'page' );
4881 $pr_index = $dbr->tableName( 'pr_index' );
4982
50 - return
51 - "SELECT pr_page_id as title,
52 - page_title as title,
53 - pr_count,
54 - pr_q0,
55 - pr_q1,
56 - pr_q2,
57 - pr_q3,
58 - pr_q4
59 - FROM $pr_index
60 - LEFT JOIN $page ON page_id = pr_page_id";
 83+ if( $this->searchList ) {
 84+ $index_namespace = pr_index_ns() ;
 85+ $index_ns_index = MWNamespace::getCanonicalIndex( strtolower( $index_namespace ) );
 86+ $querylist = '';
 87+ foreach( $this->searchList as $item ) {
 88+ if( $querylist ) $querylist .= ', ';
 89+ $querylist .= "'" . $dbr->strencode( $item ). "'";
 90+ }
 91+ $query = "SELECT page_title as title,
 92+ pr_count,pr_q0,pr_q1,pr_q2,pr_q3,pr_q4
 93+ FROM $pr_index LEFT JOIN $page ON page_id = pr_page_id
 94+ WHERE page_namespace=$index_ns_index AND page_title IN ($querylist)";
 95+ } else {
 96+ $query = "SELECT page_title as title,
 97+ pr_count,pr_q0,pr_q1,pr_q2,pr_q3,pr_q4
 98+ FROM $pr_index LEFT JOIN $page ON page_id = pr_page_id";
 99+ }
 100+ return $query;
61101 }
62102
63103 function getOrder() {

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r57173Revert r57115, r57123 "search capability"...brion23:16, 30 September 2009

Status & tagging log