r51470 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51469‎ | r51470 | r51471 >
Date:15:44, 4 June 2009
Author:yaron
Status:deferred
Tags:
Comment:
Tag for version 0.2.2
Modified paths:
  • /tags/extensions/SemanticCompoundQueries/REL_0_2_2 (added) (history)
  • /tags/extensions/SemanticCompoundQueries/REL_0_2_2/README (replaced) (history)

Diff [purge]

Index: tags/extensions/SemanticCompoundQueries/REL_0_2_2/SCQ_QueryResult.php
@@ -0,0 +1,35 @@
 2+<?php
 3+
 4+if ( !defined( 'MEDIAWIKI' ) ) die();
 5+
 6+/**
 7+ * Subclass of SMWQueryResult - this class was mostly created in order to
 8+ * get around an inconvenient print-request-compatibility check in
 9+ * SMWQueryResult::addRow()
 10+ *
 11+ * @ingroup SemanticCompoundQueries
 12+ * @author Yaron Koren
 13+ */
 14+class SCQQueryResult extends SMWQueryResult {
 15+
 16+ function addResult( $new_result ) {
 17+ // create an array of the pages already in this query result,
 18+ // so that we can check against it to make sure that pages
 19+ // aren't included twice
 20+ $existing_page_names = array();
 21+ while ( $row = $this->getNext() ) {
 22+ if ( $row[0] instanceof SMWResultArray ) {
 23+ $content = $row[0]->getContent();
 24+ $existing_page_names[] = $content[0]->getLongText( SMW_OUTPUT_WIKI );
 25+ }
 26+ }
 27+ while ( ( $row = $new_result->getNext() ) !== false ) {
 28+ $row[0]->display_options = $new_result->display_options;
 29+ $content = $row[0]->getContent();
 30+ $page_name = $content[0]->getLongText( SMW_OUTPUT_WIKI );
 31+ if ( ! in_array( $page_name, $existing_page_names ) )
 32+ $this->m_content[] = $row;
 33+ }
 34+ reset( $this->m_content );
 35+ }
 36+}
Property changes on: tags/extensions/SemanticCompoundQueries/REL_0_2_2/SCQ_QueryResult.php
___________________________________________________________________
Name: svn:eol-style
137 + native
Index: tags/extensions/SemanticCompoundQueries/REL_0_2_2/SCQ_QueryProcessor.php
@@ -0,0 +1,162 @@
 2+<?php
 3+
 4+if ( !defined( 'MEDIAWIKI' ) ) die();
 5+
 6+/**
 7+ * Class that holds static functions for handling compound queries.
 8+ * This class is heavily based on Semantic MediaWiki's SMWQueryProcessor,
 9+ * and calls that class's functions when possible.
 10+ *
 11+ * @ingroup SemanticCompoundQueries
 12+ * @author Yaron Koren
 13+ */
 14+class SCQQueryProcessor {
 15+
 16+ public static function registerParserFunctions( &$parser ) {
 17+ $parser->setFunctionHook( 'compound_query', array( 'SCQQueryProcessor', 'doCompoundQuery' ) );
 18+ return true; // always return true, in order not to stop MW's hook processing!
 19+ }
 20+
 21+ /**
 22+ * An alternative to explode() - that function won't work here,
 23+ * because we don't want to split the string on all semicolons, just
 24+ * the ones that aren't contained within square brackets
 25+ */
 26+ public static function getSubParams( $param ) {
 27+ $sub_params = array();
 28+ $sub_param = "";
 29+ $uncompleted_square_brackets = 0;
 30+ for ( $i = 0; $i < strlen( $param ); $i++ ) {
 31+ $c = $param[$i];
 32+ if ( ( $c == ';' ) && ( $uncompleted_square_brackets <= 0 ) ) {
 33+ $sub_params[] = $sub_param;
 34+ $sub_param = "";
 35+ } else {
 36+ $sub_param .= $c;
 37+ if ( $c == '[' )
 38+ $uncompleted_square_brackets++;
 39+ elseif ( $c == ']' )
 40+ $uncompleted_square_brackets--;
 41+ }
 42+ }
 43+ $sub_params[] = $sub_param;
 44+ return $sub_params;
 45+ }
 46+
 47+ /**
 48+ */
 49+ public static function doCompoundQuery( &$parser ) {
 50+ global $smwgQEnabled, $smwgIQRunningNumber;
 51+ if ( $smwgQEnabled ) {
 52+ $smwgIQRunningNumber++;
 53+ $params = func_get_args();
 54+ array_shift( $params ); // we already know the $parser ...
 55+ $other_params = array();
 56+ $query_result = null;
 57+ foreach ( $params as $param ) {
 58+ // very primitive heuristic - if the parameter
 59+ // includes a square bracket, then it's a
 60+ // sub-query; otherwise it's a regular parameter
 61+ if ( strpos( $param, '[' ) !== false ) {
 62+ $sub_params = SCQQueryProcessor::getSubParams( $param );
 63+ $next_result = SCQQueryProcessor::getQueryResultFromFunctionParams( $sub_params, SMW_OUTPUT_WIKI );
 64+ if ( $query_result == null )
 65+ $query_result = new SCQQueryResult( $next_result->getPrintRequests(), new SMWQuery() );
 66+ $query_result->addResult( $next_result );
 67+ } else {
 68+ $parts = explode( '=', $param, 2 );
 69+ if ( count( $parts ) >= 2 ) {
 70+ $other_params[strtolower( trim( $parts[0] ) )] = $parts[1]; // don't trim here, some params care for " "
 71+ }
 72+ }
 73+ }
 74+ $result = SCQQueryProcessor::getResultFromQueryResult( $query_result, $other_params, null, SMW_OUTPUT_WIKI );
 75+ } else {
 76+ wfLoadExtensionMessages( 'SemanticMediaWiki' );
 77+ $result = smwfEncodeMessages( array( wfMsgForContent( 'smw_iq_disabled' ) ) );
 78+ }
 79+ return $result;
 80+ }
 81+
 82+ static function getQueryResultFromFunctionParams( $rawparams, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY, $showmode = false ) {
 83+ SMWQueryProcessor::processFunctionParams( $rawparams, $querystring, $params, $printouts, $showmode );
 84+ return SCQQueryProcessor::getQueryResultFromQueryString( $querystring, $params, $printouts, SMW_OUTPUT_WIKI, $context );
 85+ }
 86+
 87+ /**
 88+ * Combine the values from two SMWQueryResult objects into one
 89+ */
 90+ static function mergeSMWQueryResults( $result1, $result2 ) {
 91+ if ( $result1 == null ) {
 92+ $result1 = new SMWQueryResult( $result2->getPrintRequests(), new SMWQuery() );
 93+ }
 94+ $existing_page_names = array();
 95+ while ( $row = $result1->getNext() ) {
 96+ if ( $row[0] instanceof SMWResultArray ) {
 97+ $content = $row[0]->getContent();
 98+ $existing_page_names[] = $content[0]->getLongText( SMW_OUTPUT_WIKI );
 99+ }
 100+ }
 101+ while ( ( $row = $result2->getNext() ) !== false ) {
 102+ $row[0]->display_options = $result2->display_options;
 103+ $content = $row[0]->getContent();
 104+ $page_name = $content[0]->getLongText( SMW_OUTPUT_WIKI );
 105+ if ( ! in_array( $page_name, $existing_page_names ) )
 106+ $result1->addRow( $row );
 107+ }
 108+ return $result1;
 109+ }
 110+
 111+ // this method is an exact copy of SMWQueryProcessor's function,
 112+ // but it needs to be duplicated because there it's protected
 113+ static function getResultFormat( $params ) {
 114+ $format = 'auto';
 115+ if ( array_key_exists( 'format', $params ) ) {
 116+ $format = strtolower( trim( $params['format'] ) );
 117+ global $smwgResultFormats;
 118+ if ( !array_key_exists( $format, $smwgResultFormats ) ) {
 119+ $format = 'auto'; // If it is an unknown format, defaults to list/table again
 120+ }
 121+ }
 122+ return $format;
 123+ }
 124+
 125+ static function getQueryResultFromQueryString( $querystring, $params, $extraprintouts, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY ) {
 126+ wfProfileIn( 'SCQQueryProcessor::getQueryResultFromQueryString' );
 127+ $query = SMWQueryProcessor::createQuery( $querystring, $params, $context, null, $extraprintouts );
 128+ $query_result = smwfGetStore()->getQueryResult( $query );
 129+ $query_result->display_options = array();
 130+ foreach ( $params as $key => $value ) {
 131+ // special handling for 'icon' field, since it requires
 132+ // conversion of a name to a URL
 133+ if ( $key == 'icon' ) {
 134+ $icon_title = Title::newFromText( $value );
 135+ $icon_image_page = new ImagePage( $icon_title );
 136+ // method was only added in MW 1.13
 137+ if ( method_exists( 'ImagePage', 'getDisplayedFile' ) ) {
 138+ $icon_url = $icon_image_page->getDisplayedFile()->getURL();
 139+ $query_result->display_options['icon'] = $icon_url;
 140+ }
 141+ } else {
 142+ $query_result->display_options[$key] = $value;
 143+ }
 144+ }
 145+
 146+ wfProfileOut( 'SCQQueryProcessor::getQueryResultFromQueryString' );
 147+ return $query_result;
 148+ }
 149+
 150+ /*
 151+ * Matches getResultFromQueryResult() from SMWQueryProcessor,
 152+ * except that formats of type 'debug' and 'count' aren't handled
 153+ */
 154+ static function getResultFromQueryResult( $res, $params, $extraprintouts, $outputmode, $context = SMWQueryProcessor::INLINE_QUERY, $format = '' ) {
 155+ wfProfileIn( 'SCQQueryProcessor::getResultFromQueryResult' );
 156+ $format = SCQQueryProcessor::getResultFormat( $params );
 157+ $printer = SMWQueryProcessor::getResultPrinter( $format, $context, $res );
 158+ $result = $printer->getResult( $res, $params, $outputmode );
 159+ wfProfileOut( 'SCQQueryProcessor::getResultFromQueryResult' );
 160+ return $result;
 161+ }
 162+}
 163+
Property changes on: tags/extensions/SemanticCompoundQueries/REL_0_2_2/SCQ_QueryProcessor.php
___________________________________________________________________
Name: svn:eol-style
1164 + native
Index: tags/extensions/SemanticCompoundQueries/REL_0_2_2/SemanticCompoundQueries.i18n.php
@@ -0,0 +1,150 @@
 2+<?php
 3+/**
 4+ * Internationalisation file for SemanticCompoundQueries extension.
 5+ *
 6+ * @addtogroup Extensions
 7+ */
 8+
 9+$messages = array();
 10+
 11+/** English
 12+ * @author Yaron Koren
 13+ */
 14+$messages['en'] = array(
 15+ 'semanticcompoundqueries-desc' => 'A parser function that displays multiple semantic queries at the same time',
 16+);
 17+
 18+/** Message documentation (Message documentation)
 19+ * @author Purodha
 20+ */
 21+$messages['qqq'] = array(
 22+ 'semanticcompoundqueries-desc' => 'A short description of this extension. Shown in [[Special:Version]]. Do not translate link targets, or tag names.',
 23+);
 24+
 25+/** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца))
 26+ * @author EugeneZelenko
 27+ * @author Jim-by
 28+ */
 29+$messages['be-tarask'] = array(
 30+ 'semanticcompoundqueries-desc' => 'Функцыя парсэра, якая паказвае шматлікія сэмантычныя запыты ў адзін час',
 31+);
 32+
 33+/** Bosnian (Bosanski)
 34+ * @author CERminator
 35+ */
 36+$messages['bs'] = array(
 37+ 'semanticcompoundqueries-desc' => 'Parserska funkcija koja prikazuje više semantičkih upita u isto vrijeme',
 38+);
 39+
 40+/** German (Deutsch)
 41+ * @author Purodha
 42+ */
 43+$messages['de'] = array(
 44+ 'semanticcompoundqueries-desc' => 'Eine Parserfunktion, die mehrere semantische Abfragen zugleich anzuzeigen erlaubt',
 45+);
 46+
 47+/** Lower Sorbian (Dolnoserbski)
 48+ * @author Michawiki
 49+ */
 50+$messages['dsb'] = array(
 51+ 'semanticcompoundqueries-desc' => 'Parserowa funkcija, kótaraž rownocasnje zwobraznjujo někotare semantiske wótpšašanja',
 52+);
 53+
 54+/** Spanish (Español)
 55+ * @author Crazymadlover
 56+ */
 57+$messages['es'] = array(
 58+ 'semanticcompoundqueries-desc' => 'Una función analizadora que muestra múltiples consultas semánticas al mismo tiempo',
 59+);
 60+
 61+/** French (Français)
 62+ * @author IAlex
 63+ */
 64+$messages['fr'] = array(
 65+ 'semanticcompoundqueries-desc' => 'Une fonction du parseur qui affiche plusieurs requêtes sémantiques en même temps',
 66+);
 67+
 68+/** Galician (Galego)
 69+ * @author Toliño
 70+ */
 71+$messages['gl'] = array(
 72+ 'semanticcompoundqueries-desc' => 'Unha función analítica que mostra varias pescudas semánticas ao mesmo tempo',
 73+);
 74+
 75+/** Swiss German (Alemannisch)
 76+ * @author Als-Holder
 77+ */
 78+$messages['gsw'] = array(
 79+ 'semanticcompoundqueries-desc' => 'E Parserfunktion, wu erlaubt, mehreri semantischi Abfroge uf eimol aazzeige',
 80+);
 81+
 82+/** Upper Sorbian (Hornjoserbsce)
 83+ * @author Michawiki
 84+ */
 85+$messages['hsb'] = array(
 86+ 'semanticcompoundqueries-desc' => 'Parserowa funkcija, kotraž wjacore semantiske wotprašowanja nadobo zwobrazuje',
 87+);
 88+
 89+/** Interlingua (Interlingua)
 90+ * @author McDutchie
 91+ */
 92+$messages['ia'] = array(
 93+ 'semanticcompoundqueries-desc' => 'Un function syntactic que presenta plure consultas semantic al mesme tempore',
 94+);
 95+
 96+/** Japanese (日本語)
 97+ * @author Fryed-peach
 98+ */
 99+$messages['ja'] = array(
 100+ 'semanticcompoundqueries-desc' => '複数の意味的クエリーを一度に表示するパーサー関数',
 101+);
 102+
 103+/** Ripoarisch (Ripoarisch)
 104+ * @author Purodha
 105+ */
 106+$messages['ksh'] = array(
 107+ 'semanticcompoundqueries-desc' => 'En Paaser_Funkßuhn öm ettlijje semantesche Froore op eijmohl aanzezeije.',
 108+);
 109+
 110+/** Luxembourgish (Lëtzebuergesch)
 111+ * @author Robby
 112+ */
 113+$messages['lb'] = array(
 114+ 'semanticcompoundqueries-desc' => 'Eng Parserfonctioun déi et erlaabt méi semantesch Ufroe mateneen ze weisen',
 115+);
 116+
 117+/** Dutch (Nederlands)
 118+ * @author Siebrand
 119+ */
 120+$messages['nl'] = array(
 121+ 'semanticcompoundqueries-desc' => 'Een parserfunctie die meerdere semantische zoekopdrachten op hetzelfde moment kan weergeven',
 122+);
 123+
 124+/** Norwegian (bokmål)‬ (‪Norsk (bokmål)‬)
 125+ * @author Nghtwlkr
 126+ */
 127+$messages['no'] = array(
 128+ 'semanticcompoundqueries-desc' => 'En tolkefunksjon som viser flere semantiske spørringer samtidig',
 129+);
 130+
 131+/** Occitan (Occitan)
 132+ * @author Cedric31
 133+ */
 134+$messages['oc'] = array(
 135+ 'semanticcompoundqueries-desc' => "Una foncion del parser qu'aficha mai d'una requèsta semanticas a l'encòp",
 136+);
 137+
 138+/** Slovak (Slovenčina)
 139+ * @author Helix84
 140+ */
 141+$messages['sk'] = array(
 142+ 'semanticcompoundqueries-desc' => 'Funkcia syntaktického analyzátora, ktorá zobrazuje viaceré sémantické požiadavky naraz',
 143+);
 144+
 145+/** Vietnamese (Tiếng Việt)
 146+ * @author Minh Nguyen
 147+ */
 148+$messages['vi'] = array(
 149+ 'semanticcompoundqueries-desc' => 'Hàm cú pháp hiển thị nhiều truy vấn ngữ nghĩa cùng lúc',
 150+);
 151+
Property changes on: tags/extensions/SemanticCompoundQueries/REL_0_2_2/SemanticCompoundQueries.i18n.php
___________________________________________________________________
Name: svn:keywords
1152 + Id
Name: svn:eol-style
2153 + native
Index: tags/extensions/SemanticCompoundQueries/REL_0_2_2/SCQ_Settings.php
@@ -0,0 +1,57 @@
 2+<?php
 3+/**
 4+ * Initialization file for SemanticCompoundQueries
 5+ *
 6+ * @file
 7+ * @ingroup SemanticCompoundQueries
 8+ * @author Yaron Koren
 9+ */
 10+
 11+if ( !defined( 'MEDIAWIKI' ) ) die();
 12+
 13+define( 'SCQ_VERSION', '0.2.2' );
 14+
 15+$wgExtensionCredits['parserhook'][] = array(
 16+ 'path' => __FILE__,
 17+ 'name' => 'Semantic Compound Queries',
 18+ 'version' => SCQ_VERSION,
 19+ 'author' => 'Yaron Koren',
 20+ 'url' => 'http://www.mediawiki.org/wiki/Extension:Semantic_Compound_Queries',
 21+ 'description' => 'A parser function that displays multiple semantic queries at the same time',
 22+ 'descriptionmsg' => 'semanticcompoundqueries-desc',
 23+);
 24+
 25+$wgExtensionMessagesFiles['SemanticCompoundQueries'] = dirname( __FILE__ ) . '/SemanticCompoundQueries.i18n.php';
 26+
 27+
 28+$wgExtensionFunctions[] = 'scqgParserFunctions';
 29+$wgHooks['LanguageGetMagic'][] = 'scqgLanguageGetMagic';
 30+
 31+$scqIP = $IP . '/extensions/SemanticCompoundQueries';
 32+$wgAutoloadClasses['SCQQueryProcessor'] = $scqIP . '/SCQ_QueryProcessor.php';
 33+$wgAutoloadClasses['SCQQueryResult'] = $scqIP . '/SCQ_QueryResult.php';
 34+
 35+function scqgParserFunctions() {
 36+ global $wgHooks, $wgParser;
 37+ if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) {
 38+ $wgHooks['ParserFirstCallInit'][] = 'scqgRegisterParser';
 39+ } else {
 40+ if ( class_exists( 'StubObject' ) && !StubObject::isRealObject( $wgParser ) ) {
 41+ $wgParser->_unstub();
 42+ }
 43+ SCQQueryProcessor::registerParserFunctions( $wgParser );
 44+ }
 45+}
 46+
 47+function scqgRegisterParser( &$parser ) {
 48+ $parser->setFunctionHook( 'compound_query', array( 'SCQQueryProcessor', 'doCompoundQuery' ) );
 49+ return true; // always return true, in order not to stop MW's hook processing!
 50+}
 51+
 52+function scqgLanguageGetMagic( &$magicWords, $langCode = "en" ) {
 53+ switch ( $langCode ) {
 54+ default:
 55+ $magicWords['compound_query'] = array ( 0, 'compound_query' );
 56+ }
 57+ return true;
 58+}
Property changes on: tags/extensions/SemanticCompoundQueries/REL_0_2_2/SCQ_Settings.php
___________________________________________________________________
Name: svn:eol-style
159 + native
Index: tags/extensions/SemanticCompoundQueries/REL_0_2_2/README
@@ -0,0 +1,48 @@
 2+Semantic Compound Queries Extension
 3+
 4+ Version 0.2.2
 5+ Yaron Koren
 6+
 7+This is free software licensed under the GNU General Public License. Please
 8+see http://www.gnu.org/copyleft/gpl.html for further details, including the
 9+full text and terms of the license.
 10+
 11+== Overview ==
 12+
 13+Semantic Compound Queries is an extension to MediaWiki that defines a
 14+parser function, '#compound_query', that displays the results of the
 15+equivalent of multiple Semantic MediaWiki #ask queries at the same time.
 16+The syntax of #compound_query resembles that of #ask, but with more than
 17+one query, and with the elements of each sub-query delimited by semicolons
 18+instead of pipes. Elements that are common across all sub-queries, like
 19+'format=' and 'width=' (for maps) should be placed after all sub-queries.
 20+
 21+A sample call to #compound query, which retrieves both biographies, along
 22+with their subject; and fiction books, along with their author; is:
 23+
 24+{{#compound_query:[[Category:Books]][[Has gentre::Biography]];?Covers subject=Subject
 25+ |[[Category:Books]][[Has genre::Fiction]];?Has author=Author
 26+ |format=list}}
 27+
 28+
 29+For more information, see the extension homepage at:
 30+http://www.mediawiki.org/wiki/Extension:Semantic_Compound_Queries
 31+
 32+== Requirements ==
 33+
 34+This version of the Semantic Compound Queries extension requires MediaWiki 1.8
 35+or higher and Semantic MediaWiki 1.2 or higher.
 36+
 37+== Installation ==
 38+
 39+To install the extension, place the entire 'SemanticCompoundQueries' directory
 40+within your MediaWiki 'extensions' directory, then add the following
 41+line to your 'LocalSettings.php' file:
 42+
 43+ require_once( "$IP/extensions/SemanticCompoundQueries/SCQ_Settings.php" );
 44+
 45+== Contact ==
 46+
 47+Comments, questions, suggestions and bug reports are welcome, and can
 48+be placed on the Talk page for the extension, or sent to Yaron at
 49+yaron57@gmail.com.
Property changes on: tags/extensions/SemanticCompoundQueries/REL_0_2_2/README
___________________________________________________________________
Name: svn:eol-style
150 + native

Status & tagging log