http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89608
Revision: 89608
Author: foxtrott
Date: 2011-06-06 21:00:22 +0000 (Mon, 06 Jun 2011)
Log Message:
-----------
using Lingo extension (removed redundant code)
Modified Paths:
--------------
trunk/extensions/SemanticGlossary/SemanticGlossary.php
trunk/extensions/SemanticGlossary/SemanticGlossaryBackend.php
trunk/extensions/SemanticGlossary/SpecialSemanticGlossaryBrowser.php
Removed Paths:
-------------
trunk/extensions/SemanticGlossary/SemanticGlossaryElement.php
trunk/extensions/SemanticGlossary/SemanticGlossaryMessageLog.php
trunk/extensions/SemanticGlossary/SemanticGlossaryParser.php
trunk/extensions/SemanticGlossary/SemanticGlossaryTree.php
trunk/extensions/SemanticGlossary/skins/SemanticGlossary.css
trunk/extensions/SemanticGlossary/skins/linkicon.png
Modified: trunk/extensions/SemanticGlossary/SemanticGlossary.php
===================================================================
--- trunk/extensions/SemanticGlossary/SemanticGlossary.php 2011-06-06
21:00:02 UTC (rev 89607)
+++ trunk/extensions/SemanticGlossary/SemanticGlossary.php 2011-06-06
21:00:22 UTC (rev 89608)
@@ -26,6 +26,10 @@
die( 'Semantic Glossary depends on the Semantic MediaWiki extension.
You need to install Semantic MediaWiki first.' );
}
+if ( !defined( 'LINGO_VERSION' ) ) {
+ die( 'Semantic Glossary depends on the Lingo extension. You need to
install Lingo first.' );
+}
+
/**
* The Semantic Glossary version
*/
@@ -41,6 +45,10 @@
'version' => SG_VERSION,
);
+
+// set SemanticGlossaryBackend as the backend to access the glossary
+$wgexLingoBackend = 'SemanticGlossaryBackend';
+
// server-local path to this file
$dir = dirname( __FILE__ );
@@ -49,12 +57,7 @@
$wgExtensionMessagesFiles['SemanticGlossaryAlias'] = $dir .
'/SemanticGlossary.alias.php';
// register class files with the Autoloader
-//$wgAutoloadClasses['SemanticGlossarySettings'] = $dir .
'/SemanticGlossarySettings.php';
-$wgAutoloadClasses['SemanticGlossaryParser'] = $dir .
'/SemanticGlossaryParser.php';
-$wgAutoloadClasses['SemanticGlossaryTree'] = $dir .
'/SemanticGlossaryTree.php';
-$wgAutoloadClasses['SemanticGlossaryElement'] = $dir .
'/SemanticGlossaryElement.php';
$wgAutoloadClasses['SemanticGlossaryBackend'] = $dir .
'/SemanticGlossaryBackend.php';
-$wgAutoloadClasses['SemanticGlossaryMessageLog'] = $dir .
'/SemanticGlossaryMessageLog.php';
$wgAutoloadClasses['SpecialSemanticGlossaryBrowser'] = $dir .
'/SpecialSemanticGlossaryBrowser.php';
// register Special pages
@@ -62,54 +65,23 @@
$wgSpecialPageGroups['SemanticGlossaryBrowser'] = 'other';
// register hook handlers
-// $wgHooks['ParserFirstCallInit'][] = 'SemanticGlossarySetup'; // Define a
setup function
-$wgHooks['ParserAfterTidy'][] = 'SemanticGlossaryParser::parse';
-
$wgHooks['smwInitProperties'][] = 'SemanticGlossaryRegisterProperties';
$wgHooks['smwInitDatatypes'][] = 'SemanticGlossaryRegisterPropertyAliases';
// register resource modules with the Resource Loader
-$wgResourceModules['ext.SemanticGlossary'] = array(
- // JavaScript and CSS styles. To combine multiple file, just list them
as an array.
- // 'scripts' => 'js/ext.myExtension.js',
- 'styles' => 'css/SemanticGlossary.css',
-
- // When your module is loaded, these messages will be available to
mediaWiki.msg()
- // 'messages' => array( 'myextension-hello-world',
'myextension-goodbye-world' ),
-
- // If your scripts need code from other modules, list their identifiers
as dependencies
- // and ResourceLoader will make sure they're loaded before you.
- // You don't need to manually list 'mediawiki' or 'jquery', which are
always loaded.
- // 'dependencies' => array( 'jquery.ui.datepicker' ),
-
- // ResourceLoader needs to know where your files are; specify your
- // subdir relative to "extensions" or $wgExtensionAssetsPath
- 'localBasePath' => dirname( __FILE__ ),
- 'remoteExtPath' => 'SemanticGlossary'
-);
-
$wgResourceModules['ext.SemanticGlossary.Browser'] = array(
+ 'localBasePath' => $dir,
'styles' => 'css/SemanticGlossaryBrowser.css',
- 'localBasePath' => dirname( __FILE__ ),
'remoteExtPath' => 'SemanticGlossary'
);
// Create new permission 'editglossary' and assign it to usergroup 'user' by
default
$wgGroupPermissions['user']['editglossary'] = true;
-/**
- * Handler for late setup of Semantic Glossary
- */
-// function SemanticGlossarySetup () {
-//
-// return true;
-// }
-
define( 'SG_PROP_GLT', 'Glossary-Term' );
define( 'SG_PROP_GLD', 'Glossary-Definition' );
define( 'SG_PROP_GLL', 'Glossary-Link' );
-
function SemanticGlossaryRegisterProperties() {
SMWDIProperty::registerProperty( '___glt', '_str', SG_PROP_GLT, true );
SMWDIProperty::registerProperty( '___gld', '_txt', SG_PROP_GLD, true );
Modified: trunk/extensions/SemanticGlossary/SemanticGlossaryBackend.php
===================================================================
--- trunk/extensions/SemanticGlossary/SemanticGlossaryBackend.php
2011-06-06 21:00:02 UTC (rev 89607)
+++ trunk/extensions/SemanticGlossary/SemanticGlossaryBackend.php
2011-06-06 21:00:22 UTC (rev 89608)
@@ -16,87 +16,83 @@
*
* @ingroup SemanticGlossary
*/
-class SemanticGlossaryBackend {
+class SemanticGlossaryBackend extends LingoBackend {
protected $mQueryResult;
- protected $mResultLine;
- protected $mMessageLog;
- protected $mTerm;
- protected $mDefinition;
- protected $mLink;
- protected $mSource;
- public function __construct ( SemanticGlossaryMessageLog &$messages =
null ) {
+ public function __construct( LingoMessageLog &$messages = null ) {
- $this -> mMessageLog = $messages;
+ parent::__construct( $messages );
- $store = smwfGetStore(); // default store
+ // get the store
+ $store = smwfGetStore();
+
// Create query
$desc = new SMWSomeProperty( new SMWDIProperty( '___glt' ), new
SMWThingDescription() );
- $desc -> addPrintRequest( new SMWPrintRequest(
SMWPrintRequest::PRINT_PROP, null, SMWPropertyValue::makeProperty( '___glt' ) )
);
- $desc -> addPrintRequest( new SMWPrintRequest(
SMWPrintRequest::PRINT_PROP, null, SMWPropertyValue::makeProperty( '___gld' ) )
);
- $desc -> addPrintRequest( new SMWPrintRequest(
SMWPrintRequest::PRINT_PROP, null, SMWPropertyValue::makeProperty( '___gll' ) )
);
+ $desc->addPrintRequest( new SMWPrintRequest(
SMWPrintRequest::PRINT_PROP, null, SMWPropertyValue::makeProperty( '___glt' ) )
);
+ $desc->addPrintRequest( new SMWPrintRequest(
SMWPrintRequest::PRINT_PROP, null, SMWPropertyValue::makeProperty( '___gld' ) )
);
+ $desc->addPrintRequest( new SMWPrintRequest(
SMWPrintRequest::PRINT_PROP, null, SMWPropertyValue::makeProperty( '___gll' ) )
);
$query = new SMWQuery( $desc, false, false );
- $query -> sort = true;
- $query -> sortkeys[ '___glt' ] = 'ASC';
+ $query->sort = true;
+ $query->sortkeys['___glt'] = 'ASC';
// get the query result
- $this -> mQueryResult = $store -> getQueryResult( $query );
+ $this->mQueryResult = $store->getQueryResult( $query );
}
- public function next () {
+ /**
+ * This function returns the next element. The element is an array of
four
+ * strings: Term, Definition, Link, Source. If there is no next element
the
+ * function returns null.
+ *
+ * @return the next element or null
+ */
+ public function next() {
+ $ret = null;
+
// find next line
- while ( $resultline = $this -> mQueryResult -> getNext() ) {
- $this -> mTerm = $resultline[ 0 ] -> getNextText(
SMW_OUTPUT_HTML );
- $this -> mDefinition = $resultline[ 1 ] -> getNextText(
SMW_OUTPUT_HTML );
- $this -> mLink = $resultline[ 2 ] -> getNextText(
SMW_OUTPUT_HTML );
- $this -> mSource = $resultline[ 0 ] ->
getResultSubject() -> getTitle() -> getPrefixedText();
+ while ( !$ret && ( $resultline = $this->mQueryResult->getNext()
) ) {
- $nextTerm = $resultline[ 0 ] -> getNextText(
SMW_OUTPUT_HTML );
- $nextDefinition = $resultline[ 1 ] -> getNextText(
SMW_OUTPUT_HTML );
- $nextLink = $resultline[ 2 ] -> getNextText(
SMW_OUTPUT_HTML );
+ $term = $resultline[0]->getNextText( SMW_OUTPUT_HTML );
+ $definition = $resultline[1]->getNextText(
SMW_OUTPUT_HTML );
+ $link = $resultline[2]->getNextText( SMW_OUTPUT_HTML );
+ // FIXME: By not checking for 2nd term defined on the
same page some
+ // time could be saved. However, no message could then
be generated.
+ // Introduce a setting?
+ $nextTerm = $resultline[0]->getNextText(
SMW_OUTPUT_HTML );
+ $nextDefinition = $resultline[1]->getNextText(
SMW_OUTPUT_HTML );
+ $nextLink = $resultline[2]->getNextText(
SMW_OUTPUT_HTML );
+
// FIXME: SMW has a bug that right after storing data
this data
// might be available twice. The workaround here is to
compare the
// first and second result and if they are identical
assume that
// it is because of the bug. (2nd condition in the if
below)
// skip if more then one term or more than one
definition present
if ( ( $nextTerm || $nextDefinition || $nextLink ) &&
- !( $nextTerm == $this -> mTerm &&
$nextDefinition == $this -> mDefinition && $nextLink == $this -> mLink ) ) {
+ !( $nextTerm == $term && $nextDefinition ==
$definition && $nextLink == $link ) ) {
- if ( $this -> mMessageLog ) {
- $this -> mMessageLog -> addMessage(
- wfMsg(
'semanticglossary-termdefinedtwice', array( $subject -> getTitle() ->
getPrefixedText() ) ),
+ if ( $ml = $this->getMessageLog() ) {
+ $ml->addMessage(
+ wfMsg(
'semanticglossary-termdefinedtwice',
array($subject->getTitle()->getPrefixedText()) ),
SemanticGlossaryMessageLog::SG_WARNING );
}
continue;
}
- return true;
+ $ret = array(
+ LingoElement::ELEMENT_TERM => $term,
+ LingoElement::ELEMENT_DEFINITION => $definition,
+ LingoElement::ELEMENT_LINK => $link,
+ LingoElement::ELEMENT_SOURCE =>
$resultline[0]->getResultSubject()->getTitle()->getPrefixedText()
+ );
}
- return $resultline != null;
+ return $ret;
}
- function &getTerm () {
- return $this -> mTerm;
- }
-
- function &getDefinition () {
- return $this -> mDefinition;
- }
-
- function &getLink () {
- return $this -> mLink;
- }
-
- function &getSource () {
- return $this -> mSource;
- }
-
}
-
Deleted: trunk/extensions/SemanticGlossary/SemanticGlossaryElement.php
===================================================================
--- trunk/extensions/SemanticGlossary/SemanticGlossaryElement.php
2011-06-06 21:00:02 UTC (rev 89607)
+++ trunk/extensions/SemanticGlossary/SemanticGlossaryElement.php
2011-06-06 21:00:22 UTC (rev 89608)
@@ -1,128 +0,0 @@
-<?php
-
-/**
- * File holding the SemanticGlossaryElement class.
- *
- * @author Stephan Gambke
- *
- * @file
- * @ingroup SemanticGlossary
- */
-if ( !defined( 'SG_VERSION' ) ) {
- die( 'This file is part of the Semantic Glossary extension, it is not a
valid entry point.' );
-}
-
-/**
- * This class represents a term-definition pair.
- * One term may be related to several definitions.
- *
- * @ingroup SemanticGlossary
- */
-class SemanticGlossaryElement {
- const SG_TERM = 0;
- const SG_DEFINITION = 1;
- const SG_SOURCE = 2;
- const SG_LINK = 3;
-
- private $mFullDefinition = null;
- private $mDefinitions = array();
- private $mTerm = null;
- static private $mLinkTemplate = null;
-
- public function __construct( &$term, &$definition = null ) {
-
- $this->mTerm = $term;
-
- if ( $definition ) {
- $this->addDefinition( $definition );
- }
- }
-
- public function addDefinition( &$definition ) {
- $this->mDefinitions[] = $definition;
- }
-
- public function getFullDefinition( DOMDocument &$doc ) {
- // only create if not yet created
- if ( $this->mFullDefinition == null ||
$this->mFullDefinition->ownerDocument !== $doc ) {
-
- // Wrap term and definition in <span> tags
- $span = $doc->createElement( 'span' );
- $span->setAttribute( 'class', 'tooltip' );
-
- // Wrap term in <span> tag, hidden
- $spanTerm = $doc->createElement( 'span', $this->mTerm );
- $spanTerm->setAttribute( 'class', 'tooltip_abbr' );
-
- // Wrap definition in two <span> tags
- $spanDefinitionOuter = $doc->createElement( 'span' );
- $spanDefinitionOuter->setAttribute( 'class',
'tooltip_tipwrapper' );
-
- $spanDefinitionInner = $doc->createElement( 'span' );
- $spanDefinitionInner->setAttribute( 'class',
'tooltip_tip' );
-
- foreach ( $this->mDefinitions as $definition ) {
- $element = $doc->createElement( 'span',
htmlentities( $definition[self::SG_DEFINITION], ENT_COMPAT, 'UTF-8' ) . ' ' );
- if ( $definition[self::SG_LINK] ) {
- $linkedTitle = Title::newFromText(
$definition[self::SG_LINK] );
- if ( $linkedTitle ) {
- $link = $this->getLinkTemplate(
$doc );
- $link->setAttribute( 'href',
$linkedTitle->getFullURL() );
- $element->appendChild( $link );
- }
- }
- $spanDefinitionInner->appendChild( $element );
- }
-
- // insert term and definition
- $span->appendChild( $spanTerm );
- $span->appendChild( $spanDefinitionOuter );
- $spanDefinitionOuter->appendChild( $spanDefinitionInner
);
-
- $this->mFullDefinition = $span;
-
- }
-
- return $this->mFullDefinition->cloneNode( true );
- }
-
- public function getCurrentKey() {
- return key( $this->mDefinitions );
- }
-
- public function getTerm( $key ) {
- return $this->mDefinitions[$key][self::SG_TERM];
- }
-
- public function getSource( &$key ) {
- return $this->mDefinitions[$key][self::SG_SOURCE];
- }
-
- public function getDefinition( &$key ) {
- return $this->mDefinitions[$key][self::SG_DEFINITION];
- }
-
- public function getLink( &$key ) {
- return $this->mDefinitions[$key][self::SG_LINK];
- }
-
- public function next() {
- next( $this->mDefinitions );
- }
-
- private function getLinkTemplate( DOMDocument &$doc ) {
- // create template if it does not yet exist
- if ( !self::$mLinkTemplate || (
self::$mLinkTemplate->ownerDocument !== $doc ) ) {
- global $wgScriptPath;
-
- $linkimage = $doc->createElement( 'img' );
- $linkimage->setAttribute( 'src', $wgScriptPath .
'/extensions/SemanticGlossary/skins/linkicon.png' );
-
- self::$mLinkTemplate = $doc->createElement( 'a' );
- self::$mLinkTemplate->appendChild( $linkimage );
- }
-
- return self::$mLinkTemplate->cloneNode( true );
- }
-
-}
Deleted: trunk/extensions/SemanticGlossary/SemanticGlossaryMessageLog.php
===================================================================
--- trunk/extensions/SemanticGlossary/SemanticGlossaryMessageLog.php
2011-06-06 21:00:02 UTC (rev 89607)
+++ trunk/extensions/SemanticGlossary/SemanticGlossaryMessageLog.php
2011-06-06 21:00:22 UTC (rev 89608)
@@ -1,77 +0,0 @@
-<?php
-
-/**
- * File holding the SemanticGlossaryMessageLog class.
- *
- * @author Stephan Gambke
- *
- * @file
- * @ingroup SemanticGlossary
- */
-if ( !defined( 'SG_VERSION' ) ) {
- die( 'This file is part of the Semantic Glossary extension, it is not a
valid entry point.' );
-}
-
-/**
- * This class holds messages (errors, warnings, notices) for Semantic Glossary
- *
- * Contains a static function to initiate the parsing.
- *
- * @ingroup SemanticGlossary
- */
-class SemanticGlossaryMessageLog {
-
- private $mMessages = array();
- private $parser = null;
-
- const SG_ERROR = 1;
- const SG_WARNING = 2;
- const SG_NOTICE = 3;
-
- function addMessage( $message, $severity = self::SG_NOTICE ) {
- $this->mMessages[] = array( $message, $severity );
- }
-
- function addError( $message ) {
- $this->mMessages[] = array( $message, self::SG_ERROR );
- }
-
- function addWarning( $message ) {
- $this->mMessages[] = array( $message, self::SG_WARNING );
- }
-
- function addNotice( $message ) {
- $this->mMessages[] = array( $message, self::SG_NOTICE );
- }
-
- function getMessagesFormatted( $severity = self::SG_WARNING, $header =
null ) {
- global $wgTitle, $wgUser;
-
- $ret = '';
-
- if ( $header == null ) {
- $header = wfMsg( 'semanticglossary-messageheader' );
- }
-
- foreach ( $this->mMessages as $message ) {
- if ( $message[1] <= $severity ) {
- $ret .= '* ' . $message[0] . "\n";
- }
- }
-
- if ( $ret != '' ) {
- if ( !$this->parser ) {
- $parser = new Parser();
- }
-
- $ret = Html::rawElement( 'div', array( 'class' =>
'messages' ),
- Html::rawElement( 'div', array( 'class'
=> 'heading' ), $header ) .
- $parser->parse( $ret, $wgTitle,
ParserOptions::newFromUser( $wgUser ) )->getText()
- );
- }
-
- return $ret;
- }
-
-}
-
Deleted: trunk/extensions/SemanticGlossary/SemanticGlossaryParser.php
===================================================================
--- trunk/extensions/SemanticGlossary/SemanticGlossaryParser.php
2011-06-06 21:00:02 UTC (rev 89607)
+++ trunk/extensions/SemanticGlossary/SemanticGlossaryParser.php
2011-06-06 21:00:22 UTC (rev 89608)
@@ -1,292 +0,0 @@
-<?php
-
-/**
- * File holding the SemanticGlossaryParser class.
- *
- * @author Stephan Gambke
- *
- * @file
- * @ingroup SemanticGlossary
- */
-if ( !defined( 'SG_VERSION' ) ) {
- die( 'This file is part of the Semantic Glossary extension, it is not a
valid entry point.' );
-}
-
-/**
- * This class parses the given text and enriches it with definitions for
defined
- * terms.
- *
- * Contains a static function to initiate the parsing.
- *
- * @ingroup SemanticGlossary
- */
-class SemanticGlossaryParser {
-
- private $mGlossaryArray = null;
- private $mGlossaryTree = null;
- private static $parserSingleton = null;
-
- /**
- *
- * @param $parser
- * @param $text
- * @return Boolean
- */
- static function parse( &$parser, &$text ) {
- wfProfileIn( __METHOD__ );
-
- if ( !self::$parserSingleton ) {
- self::$parserSingleton = new SemanticGlossaryParser();
- }
-
- self::$parserSingleton->realParse( $parser, $text );
-
- wfProfileOut( __METHOD__ );
-
- return true;
- }
-
- function getBackend() {
- return new SemanticGlossaryBackend();
- }
-
- /**
- * Returns the list of terms applicable in the current context
- *
- * @return Array an array mapping terms (keys) to descriptions (values)
- */
- function getGlossaryArray( SemanticGlossaryMessageLog &$messages = null
) {
- wfProfileIn( __METHOD__ );
-
- // build glossary array only once per request
- if ( !$this->mGlossaryArray ) {
- $this->buildGlossary( $messages );
- }
-
- wfProfileOut( __METHOD__ );
-
- return $this->mGlossaryArray;
- }
-
- /**
- * Returns the list of terms applicable in the current context
- *
- * @return Array an array mapping terms (keys) to descriptions (values)
- */
- function getGlossaryTree( SemanticGlossaryMessageLog &$messages = null
) {
- wfProfileIn( __METHOD__ );
-
- // build glossary array only once per request
- if ( !$this->mGlossaryTree ) {
- $this->buildGlossary( $messages );
- }
-
- wfProfileOut( __METHOD__ );
-
- return $this->mGlossaryTree;
- }
-
- protected function buildGlossary( SemanticGlossaryMessageLog &$messages
= null ) {
- wfProfileIn( __METHOD__ );
-
- $this->mGlossaryTree = new SemanticGlossaryTree();
-
- $backend = $this->getBackEnd();
-
- // assemble the result array
- $this->mGlossaryArray = array();
- while ( $backend->next() ) {
-
- $elementData = array(
- SemanticGlossaryElement::SG_TERM => ( $term =
$backend->getTerm() ),
- SemanticGlossaryElement::SG_DEFINITION =>
$backend->getDefinition(),
- SemanticGlossaryElement::SG_LINK =>
$backend->getLink(),
- SemanticGlossaryElement::SG_SOURCE =>
$backend->getSource()
- );
-
- if ( array_key_exists( $term, $this->mGlossaryArray ) )
{
- $this->mGlossaryArray[$term]->addDefinition(
$elementData );
- } else {
- $this->mGlossaryArray[$term] = new
SemanticGlossaryElement( $term, $elementData );
- }
-
- $this->mGlossaryTree->addTerm( $term, $elementData );
- }
-
- wfProfileOut( __METHOD__ );
- }
-
- /**
- * Parses the given text and enriches applicable terms
- *
- * This method currently only recognizes terms consisting of max one
word
- *
- * @param $parser
- * @param $text
- * @return Boolean
- */
- protected function realParse( &$parser, &$text ) {
- global $wgRequest;
-
- wfProfileIn( __METHOD__ );
-
- $action = $wgRequest->getVal( 'action', 'view' );
-
- if ( $text == null ||
- $text == '' ||
- $action == 'edit' ||
- $action == 'ajax' ||
- isset( $_POST['wpPreview'] )
- ) {
-
- wfProfileOut( __METHOD__ );
- return true;
- }
-
- // Get array of terms
- $glossary = $this->getGlossaryTree();
-
- if ( $glossary == null ) {
- wfProfileOut( __METHOD__ );
- return true;
- }
-
- // Parse HTML from page
- // @todo FIXME: this works in PHP 5.3.3. What about 5.1?
- wfProfileIn( __METHOD__ . ' 1 loadHTML' );
- wfSuppressWarnings();
-
- $doc = DOMDocument::loadHTML(
- '<html><meta http-equiv="content-type"
content="charset=utf-8"/>' . $text . '</html>'
- );
-
- wfRestoreWarnings();
- wfProfileOut( __METHOD__ . ' 1 loadHTML' );
-
- wfProfileIn( __METHOD__ . ' 2 xpath' );
- // Find all text in HTML.
- $xpath = new DOMXpath( $doc );
- $elements = $xpath->query(
-
"//*[not(ancestor-or-self::*[@class='noglossary'] or
ancestor-or-self::a)][text()!=' ']/text()"
- );
- wfProfileOut( __METHOD__ . ' 2 xpath' );
-
- // Iterate all HTML text matches
- $nb = $elements->length;
- $changedDoc = false;
-
- for ( $pos = 0; $pos < $nb; $pos++ ) {
- $el = $elements->item( $pos );
-
- if ( strlen( $el->nodeValue ) <
$glossary->getMinTermLength() ) {
- continue;
- }
-
- wfProfileIn( __METHOD__ . ' 3 lexer' );
- $matches = array();
- preg_match_all(
- '/[[:alpha:]]+|[^[:alpha:]]/u',
- $el->nodeValue,
- $matches,
- PREG_OFFSET_CAPTURE | PREG_PATTERN_ORDER
- );
- wfProfileOut( __METHOD__ . ' 3 lexer' );
-
- if ( count( $matches ) == 0 || count( $matches[0] ) ==
0 ) {
- continue;
- }
-
- $lexemes = &$matches[0];
- $countLexemes = count( $lexemes );
- $parent = &$el->parentNode;
- $index = 0;
- $changedElem = false;
-
- while ( $index < $countLexemes ) {
- wfProfileIn( __METHOD__ . ' 4 findNextTerm' );
- list( $skipped, $used, $definition ) =
- $glossary->findNextTerm( $lexemes,
$index, $countLexemes );
- wfProfileOut( __METHOD__ . ' 4 findNextTerm' );
-
- wfProfileIn( __METHOD__ . ' 5 insert' );
- if ( $used > 0 ) { // found a term
- if ( $skipped > 0 ) { // skipped some
text, insert it as is
- $parent->insertBefore(
- $doc->createTextNode(
- substr(
$el->nodeValue,
-
$currLexIndex = $lexemes[$index][1],
-
$lexemes[$index + $skipped][1] - $currLexIndex )
- ),
- $el
- );
- }
-
- $parent->insertBefore(
$definition->getFullDefinition( $doc ), $el );
-
- $changedElem = true;
- } else { // did not find term, just use the
rest of the text
- // If we found no term now and no term
before, there was no
- // term in the whole element. Might as
well not change the
- // element at all.
- // Only change element if found term
before
- if ( $changedElem ) {
- $parent->insertBefore(
- $doc->createTextNode(
- substr(
$el->nodeValue, $lexemes[$index][1] )
- ),
- $el
- );
- } else {
- wfProfileOut( __METHOD__ . ' 5
insert' );
- // In principle superfluous,
the loop would run out
- // anyway. Might save a bit of
time.
- break;
- }
- }
- wfProfileOut( __METHOD__ . ' 5 insert' );
-
- $index += $used + $skipped;
- }
-
- if ( $changedElem ) {
- $parent->removeChild( $el );
- $changedDoc = true;
- }
- }
-
- if ( $changedDoc ) {
- $body = $xpath->query( '/html/body' );
-
- $text = '';
- foreach ( $body->item( 0 )->childNodes as $child ) {
- $text .= $doc->saveXML( $child );
- }
-
- $this->loadModules( $parser );
- }
-
- wfProfileOut( __METHOD__ );
-
- return true;
- }
-
- protected function loadModules( &$parser ) {
- global $wgOut, $wgScriptPath;
-
- if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) {
- if ( !is_null( $parser ) ) {
- $parser->getOutput()->addModules(
'ext.SemanticGlossary' );
- } else {
- $wgOut->addModules( 'ext.SemanticGlossary' );
- }
- } else {
- if ( !is_null( $parser ) && ( $wgOut->isArticle() ) ) {
- $parser->getOutput()->addHeadItem( '<link
rel="stylesheet" href="' . $wgScriptPath .
'/extensions/SemanticGlossary/skins/SemanticGlossary.css" />',
'ext.SemanticGlossary.css' );
- } else {
- $wgOut->addHeadItem(
'ext.SemanticGlossary.css', '<link rel="stylesheet" href="' . $wgScriptPath .
'/extensions/SemanticGlossary/skins/SemanticGlossary.css" />' );
- }
- }
- }
-
-}
-
Deleted: trunk/extensions/SemanticGlossary/SemanticGlossaryTree.php
===================================================================
--- trunk/extensions/SemanticGlossary/SemanticGlossaryTree.php 2011-06-06
21:00:02 UTC (rev 89607)
+++ trunk/extensions/SemanticGlossary/SemanticGlossaryTree.php 2011-06-06
21:00:22 UTC (rev 89608)
@@ -1,129 +0,0 @@
-<?php
-
-/**
- * File holding the SemanticGlossaryTree class
- *
- * @author Stephan Gambke
- * @file
- * @ingroup SemanticGlossary
- */
-if ( !defined( 'SG_VERSION' ) ) {
- die( 'This file is part of the SemanticGlossary extension, it is not a
valid entry point.' );
-}
-
-/**
- * The SemanticGlossaryTree class.
- *
- * Vocabulary:
- * Term - The term as a normal string
- * Definition - Its definition object
- * Element - An element (leaf) in the glossary tree
- * Path - The path in the tree to the leaf representing a term
- *
- * @ingroup SemanticGlossary
- */
-class SemanticGlossaryTree {
-
- private $mTree = array();
- private $mDefinition = null;
- private $mMinLength = -1;
-
- /**
- * Adds a string to the Glossary Tree
- * @param String $term
- */
- function addTerm( &$term, $definition ) {
- if ( !$term ) {
- return;
- }
-
- $matches;
- preg_match_all( '/[[:alpha:]]+|[^[:alpha:]]/u', $term, $matches
);
-
- $this->addElement( $matches[0], $term, $definition );
-
- if ( $this->mMinLength > -1 ) {
- $this->mMinLength = min( array( $this->mMinLength,
strlen( $term ) ) );
- } else {
- $this->mMinLength = strlen( $term );
- }
- }
-
- /**
- * Recursively adds an element to the Glossary Tree
- *
- * @param array $path
- * @param <type> $index
- */
- protected function addElement( Array &$path, &$term, &$definition ) {
- // end of path, store description; end of recursion
- if ( $path == null ) {
- $this -> addDefinition( $term, $definition );
- } else {
- $step = array_shift( $path );
-
- if ( !array_key_exists( $step, $this->mTree ) ) {
- $this->mTree[$step] = new
SemanticGlossaryTree();
- }
-
- $this->mTree[$step]->addElement( $path, $term,
$definition );
- }
- }
-
- /**
- * Adds a defintion to the treenodes list of definitions
- * @param <type> $definition
- */
- protected function addDefinition( &$term, &$definition ) {
- if ( $this->mDefinition ) {
- $this->mDefinition->addDefinition( $definition );
- } else {
- $this->mDefinition = new SemanticGlossaryElement(
$term, $definition );
- }
- }
-
- function getMinTermLength() {
- return $this->mMinLength;
- }
-
- function findNextTerm( &$lexemes, $index, $countLexemes ) {
- wfProfileIn( __METHOD__ );
-
- $start = $lastindex = $index;
- $definition = null;
-
- // skip until ther start of a term is found
- while ( $index < $countLexemes && !$definition ) {
- $currLex = &$lexemes[$index][0];
-
- // Did we find the start of a term?
- if ( array_key_exists( $currLex, $this->mTree ) ) {
- list( $lastindex, $definition ) =
$this->mTree[$currLex]->findNextTermNoSkip( $lexemes, $index, $countLexemes );
- }
-
- // this will increase the index even if we found
something;
- // will be corrected after the loop
- $index++;
- }
-
- wfProfileOut( __METHOD__ );
- if ( $definition ) {
- return array( $index - $start - 1, $lastindex - $index
+ 2, $definition );
- } else {
- return array( $index - $start, 0, null );
- }
- }
-
- function findNextTermNoSkip( &$lexemes, $index, $countLexemes ) {
- wfProfileIn( __METHOD__ );
-
- if ( $index + 1 < $countLexemes && array_key_exists( $currLex =
$lexemes[$index + 1][0], $this->mTree ) ) {
- $ret = $this->mTree[$currLex]->findNextTermNoSkip(
$lexemes, $index + 1, $countLexemes );
- } else {
- $ret = array( $index, &$this->mDefinition );
- }
- wfProfileOut( __METHOD__ );
- return $ret;
- }
-
-}
Modified: trunk/extensions/SemanticGlossary/SpecialSemanticGlossaryBrowser.php
===================================================================
--- trunk/extensions/SemanticGlossary/SpecialSemanticGlossaryBrowser.php
2011-06-06 21:00:02 UTC (rev 89607)
+++ trunk/extensions/SemanticGlossary/SpecialSemanticGlossaryBrowser.php
2011-06-06 21:00:22 UTC (rev 89608)
@@ -29,7 +29,7 @@
function __construct() {
parent::__construct( 'SemanticGlossaryBrowser' );
- $this -> mMessages = new SemanticGlossaryMessageLog();
+ $this->mMessages = new LingoMessageLog();
}
function execute( $subpage ) {
@@ -55,8 +55,8 @@
}
// get the glossary data
- $parser = new SemanticGlossaryParser();
- $glossaryarray = $parser->getGlossaryArray( $this->mMessages );
+ $parser = new LingoParser( $this->mMessages );
+ $glossaryarray = $parser->getLingoArray();
// set function to create a table row (textareas when editing is
// allowed, else normal text)
@@ -92,24 +92,24 @@
if ( $hasEditRights ) {
// append action buttons
$listOfTermsFragment .=
- Html::element( 'input', array( 'type'
=> 'submit', 'name' => 'delete', 'value' => wfMsg(
'semanticglossary-deleteselected' ), 'accesskey' => 'd' ) ) .
- Html::element( 'input', array( 'type'
=> 'submit', 'name' => 'submit', 'value' => wfMsg(
'semanticglossary-savechanges' ), 'accesskey' => 's' ) );
+ Html::element( 'input', array('type' =>
'submit', 'name' => 'delete', 'value' => wfMsg(
'semanticglossary-deleteselected' ), 'accesskey' => 'd') ) .
+ Html::element( 'input', array('type' =>
'submit', 'name' => 'submit', 'value' => wfMsg( 'semanticglossary-savechanges'
), 'accesskey' => 's') );
}
$listOfTermsFragment =
- Html::rawElement( 'div', array( 'class' =>
'termslist' ),
- Html::element( 'div', array( 'class' =>
'heading' ), wfMsg( 'semanticglossary-termsdefined' ) ) .
+ Html::rawElement( 'div', array('class' =>
'termslist'),
+ Html::element( 'div', array('class' =>
'heading'), wfMsg( 'semanticglossary-termsdefined' ) ) .
$listOfTermsFragment
);
} else {
$listOfTermsFragment =
- Html::rawElement( 'div', array( 'class' =>
'termslist' ),
- Html::element( 'div', array( 'class' =>
'heading' ), wfMsg( 'semanticglossary-notermsdefined' ) )
+ Html::rawElement( 'div', array('class' =>
'termslist'),
+ Html::element( 'div', array('class' =>
'heading'), wfMsg( 'semanticglossary-notermsdefined' ) )
);
}
// From here on no more errors should occur. Create list of
errors.
- $errorsFragment = $this->mMessages->getMessagesFormatted(
SemanticGlossaryMessageLog::SG_NOTICE );
+ $errorsFragment = $this->mMessages->getMessagesFormatted(
LingoMessageLog::MESSAGE_NOTICE );
if ( $errorsFragment ) {
$errorsFragment .= Html::rawElement( 'hr' );
@@ -119,36 +119,36 @@
// create form fragment to allow input of a new term
$newTermFragment =
Html::rawElement( 'hr' ) .
- Html::rawElement( 'div', array( 'class' =>
'newterm' ),
- Html::rawElement( 'div', array( 'class'
=> 'heading' ), wfMsg( 'semanticglossary-enternewterm' ) ) .
+ Html::rawElement( 'div', array('class' =>
'newterm'),
+ Html::rawElement( 'div', array('class'
=> 'heading'), wfMsg( 'semanticglossary-enternewterm' ) ) .
Html::rawElement( 'table', null,
Html::rawElement( 'tbody', null,
- Html::rawElement( 'tr',
array( 'class' => 'row' ),
-
Html::rawElement( 'td', array( 'class' => 'termcell' ),
-
Html::element( 'textarea', array( 'name' => 'newterm' ) )
+ Html::rawElement( 'tr',
array('class' => 'row'),
+
Html::rawElement( 'td', array('class' => 'termcell'),
+
Html::element( 'textarea', array('name' => 'newterm') )
) .
-
Html::rawElement( 'td', array( 'class' => 'definitioncell' ),
-
Html::rawElement( 'div', array( 'class' => 'definitionareawrapper' ),
-
Html::element( 'textarea', array( 'name' => 'newdefinition' ) )
+
Html::rawElement( 'td', array('class' => 'definitioncell'),
+
Html::rawElement( 'div', array('class' => 'definitionareawrapper'),
+
Html::element( 'textarea', array('name' => 'newdefinition') )
)
) .
-
Html::rawElement( 'td', array( 'class' => 'linkcell' ),
-
Html::element( 'textarea', array( 'name' => 'newlink' ) )
+
Html::rawElement( 'td', array('class' => 'linkcell'),
+
Html::element( 'textarea', array('name' => 'newlink') )
)
)
)
) .
- Html::element( 'input', array( 'type'
=> 'submit', 'name' => 'createnew', 'value' => wfMsg(
'semanticglossary-createnew' ), 'accesskey' => 'n' ) )
+ Html::element( 'input', array('type' =>
'submit', 'name' => 'createnew', 'value' => wfMsg( 'semanticglossary-createnew'
), 'accesskey' => 'n') )
);
$salt = rand( 10000, 99999 );
- $editTokenFragment = Html::rawElement( 'input', array(
'type' => 'hidden', 'name' => 'editToken', 'value' => $wgUser -> editToken(
$salt ) . $salt ) );
+ $editTokenFragment = Html::rawElement( 'input',
array('type' => 'hidden', 'name' => 'editToken', 'value' => $wgUser->editToken(
$salt ) . $salt) );
// assemble output
$output =
- Html::rawElement( 'div', array( 'class' =>
'glossarybrowser' ),
+ Html::rawElement( 'div', array('class' =>
'glossarybrowser'),
$errorsFragment .
- Html::rawElement( 'form', array(
'method' => 'POST' ),
+ Html::rawElement( 'form',
array('method' => 'POST'),
$listOfTermsFragment .
$newTermFragment .
$editTokenFragment
@@ -157,7 +157,7 @@
} else {
// assemble output
$output =
- Html::rawElement( 'div', array( 'class' =>
'glossarybrowser' ),
+ Html::rawElement( 'div', array('class' =>
'glossarybrowser'),
$errorsFragment .
$listOfTermsFragment
);
@@ -196,7 +196,7 @@
global $wgRequest;
// get ass array of input values
- $inputdata = $wgRequest -> getValues();
+ $inputdata = $wgRequest->getValues();
// loop through all input values
foreach ( $inputdata as $key => $value ) {
@@ -238,7 +238,7 @@
$newDefinition != $oldDefinition ||
$newLink != $oldLink
) {
- $this -> updateData( $page, array(
+ $this->updateData( $page, array(
'___glt' => ( $newTerm ? new
SMWDIString( $newTerm ) : null ),
'___gld' => ( $newDefinition ?
new SMWDIBlob( $newDefinition ) : null ),
'___gll' => ( $newLink ? new
SMWDIString( $newLink ) : null )
@@ -248,13 +248,13 @@
$title = $page->getTitle();
if ( $title->isKnown() ) {
$this->mMessages->addMessage(
- wfMsg(
'semanticglossary-storedtermdefinedinarticle', array( $oldTerm,
$title->getPrefixedText() ) ),
-
SemanticGlossaryMessageLog::SG_WARNING
+ wfMsg(
'semanticglossary-storedtermdefinedinarticle', array($oldTerm,
$title->getPrefixedText()) ),
+
LingoMessageLog::MESSAGE_WARNING
);
} else {
$this->mMessages->addMessage(
- wfMsg(
'semanticglossary-termchanged', array( $oldTerm ) ),
-
SemanticGlossaryMessageLog::SG_NOTICE
+ wfMsg(
'semanticglossary-termchanged', array($oldTerm) ),
+
LingoMessageLog::MESSAGE_NOTICE
);
}
}
@@ -268,7 +268,7 @@
$newTerm = $wgRequest->getText( 'newterm' );
if ( $newTerm == null || $newTerm == '' ) {
- $this->mMessages->addMessage( 'Term was empty. Nothing
created.', SemanticGlossaryMessageLog::SG_WARNING );
+ $this->mMessages->addMessage( 'Term was empty. Nothing
created.', LingoMessageLog::MESSAGE_WARNING );
return;
}
@@ -278,15 +278,15 @@
$page = $this->findNextPageName();
// store data
- $this -> updateData( $page, array(
+ $this->updateData( $page, array(
'___glt' => ( $newTerm ? new SMWDIString( $newTerm ) :
null ),
'___gld' => ( $newDefinition ? new SMWDIBlob(
$newDefinition ) : null ),
'___gll' => ( $newLink ? new SMWDIString( $newLink ) :
null )
) );
$this->mMessages->addMessage(
- wfMsg( 'semanticglossary-termadded', array( $newTerm )
),
- SemanticGlossaryMessageLog::SG_NOTICE
+ wfMsg( 'semanticglossary-termadded', array($newTerm) ),
+ LingoMessageLog::MESSAGE_NOTICE
);
}
@@ -308,20 +308,20 @@
'___glt' => null,
'___gld' => null,
'___gll' => null,
- ) );
+ ) );
$oldTerm = $wgRequest->getVal( $pageString .
':term' );
$title = $page->getTitle();
if ( $title && $title->isKnown() ) {
$this->mMessages->addMessage(
- wfMsg(
'semanticglossary-deletedtermdefinedinarticle', array( $oldTerm,
$title->getPrefixedText() ) ),
-
SemanticGlossaryMessageLog::SG_WARNING
+ wfMsg(
'semanticglossary-deletedtermdefinedinarticle', array($oldTerm,
$title->getPrefixedText()) ),
+ LingoMessageLog::MESSAGE_WARNING
);
} else {
$this->mMessages->addMessage(
- wfMsg(
'semanticglossary-termdeleted', array( $oldTerm ) ),
-
SemanticGlossaryMessageLog::SG_NOTICE
+ wfMsg(
'semanticglossary-termdeleted', array($oldTerm) ),
+ LingoMessageLog::MESSAGE_NOTICE
);
}
}
@@ -337,8 +337,8 @@
} elseif ( count( $propertyValues ) > 1 ) {
if ( count( $propertyValues ) > 1 ) {
$this->mMessages->addMessage(
- wfMsg(
'semanticglossary-storedtermdefinedtwice', array(
$pageData->getSubject()->getPrefixedText(), $propertyName, $newTerm ) ),
- SemanticGlossaryMessageLog::SG_ERROR
+ wfMsg(
'semanticglossary-storedtermdefinedtwice',
array($pageData->getSubject()->getPrefixedText(), $propertyName, $newTerm) ),
+ LingoMessageLog::MESSAGE_ERROR
);
}
return false;
@@ -419,7 +419,7 @@
// set new data if defined, else ignore property (i.e.
do not set property on this page)
if ( $data[$propertyID] != null ) {
$property = new SMWDIProperty( $propertyID );
- $newData -> addPropertyObjectValue( $property,
$data[$propertyID] );
+ $newData->addPropertyObjectValue( $property,
$data[$propertyID] );
}
unset( $data[$propertyID] );
@@ -431,19 +431,19 @@
private function createTableRowForEdit( $source, $term, $definition,
$link ) {
return
- Html::rawElement( 'tr', array( 'class' => 'row' ),
- Html::rawElement( 'td', array( 'class' => 'actioncell'
),
+ Html::rawElement( 'tr', array('class' => 'row'),
+ Html::rawElement( 'td', array('class' => 'actioncell'),
Html::input( "$source:checked", 'true',
'checkbox' )
) .
- Html::rawElement( 'td', array( 'class' => 'termcell' ),
+ Html::rawElement( 'td', array('class' => 'termcell'),
Html::textarea( "$source:term", $term )
) .
- Html::rawElement( 'td', array( 'class' =>
'definitioncell' ),
- Html::rawElement( 'div', array( 'class' =>
'definitionareawrapper' ),
+ Html::rawElement( 'td', array('class' =>
'definitioncell'),
+ Html::rawElement( 'div', array('class' =>
'definitionareawrapper'),
Html::textarea( "$source:definition",
$definition )
)
) .
- Html::rawElement( 'td', array( 'class' => 'linkcell' ),
+ Html::rawElement( 'td', array('class' => 'linkcell'),
Html::textarea( "$source:link", $link )
)
);
@@ -451,10 +451,10 @@
private function createTableRowForDisplay( $source, $term, $definition,
$link ) {
return
- Html::rawElement( 'tr', array( 'class' => 'row' ),
- Html::rawElement( 'td', array( 'class' => 'termcell' ),
$term ) .
- Html::rawElement( 'td', array( 'class' =>
'definitioncell' ), $definition ) .
- Html::rawElement( 'td', array( 'class' => 'linkcell' ),
$link )
+ Html::rawElement( 'tr', array('class' => 'row'),
+ Html::rawElement( 'td', array('class' => 'termcell'),
$term ) .
+ Html::rawElement( 'td', array('class' =>
'definitioncell'), $definition ) .
+ Html::rawElement( 'td', array('class' => 'linkcell'),
$link )
);
}
@@ -474,8 +474,8 @@
if ( $wgUser->isAllowed( 'editglossary' ) ) { // user
has the necessary right
$editTokenAndSaltArray = explode(
EDIT_TOKEN_SUFFIX, $editTokenWithSalt );
$tokenValid = $wgUser->matchEditTokenNoSuffix(
- $editTokenAndSaltArray[0],
- $editTokenAndSaltArray[1]
+ $editTokenAndSaltArray[0],
+ $editTokenAndSaltArray[1]
);
if ( $tokenValid ) { // edit token is valid
@@ -483,13 +483,13 @@
} else {
$this->mMessages->addMessage(
wfMsg(
'semanticglossary-brokensession' ),
-
SemanticGlossaryMessageLog::SG_ERROR
+ LingoMessageLog::MESSAGE_ERROR
);
}
} else {
$this->mMessages->addMessage(
wfMsg( 'semanticglossary-norights' ),
- SemanticGlossaryMessageLog::SG_ERROR
+ LingoMessageLog::MESSAGE_ERROR
);
}
}
Deleted: trunk/extensions/SemanticGlossary/skins/SemanticGlossary.css
===================================================================
--- trunk/extensions/SemanticGlossary/skins/SemanticGlossary.css
2011-06-06 21:00:02 UTC (rev 89607)
+++ trunk/extensions/SemanticGlossary/skins/SemanticGlossary.css
2011-06-06 21:00:22 UTC (rev 89608)
@@ -1,64 +0,0 @@
-/*
-* Stylesheet for the markup of glossary terms in wiki pages.
-*/
-
-.tooltip {
- display: inline;
- position: relative;
- cursor: help;
-}
-
-.tooltip_abbr {
- border-bottom: 1px dotted #bbf;
-}
-
-.tooltip_tipwrapper {
- display: none;
-
- position: absolute;
- top: 0;
- left: 0;
-
- height: 3em;
- width: 23em;
-
- font-weight: normal;
- font-size: medium;
- line-height: 1.2em;
-
- z-index: 2;
-}
-
-.tooltip_tip {
- display: block;
-
- position: absolute;
- top: 1.5em;
- left: 2em;
-
- width: 20em;
-
- padding: 0.5em;
- margin: 0;
-
- background-color: #F9F9F9;
- border: 1px solid #aaa;
-
- -moz-border-radius: 5px;
- border-radius: 5px;
-
- -webkit-box-shadow: 3px 3px 3px #888;
- box-shadow: 3px 3px 3px #888;
-}
-
-.tooltip_tip span {
- display: block;
-}
-
-.tooltip:hover .tooltip_abbr {
- background-color:rgba(0,0,0,0.1);
-}
-
-.tooltip:hover .tooltip_tipwrapper {
- display: block;
-}
Deleted: trunk/extensions/SemanticGlossary/skins/linkicon.png
===================================================================
(Binary files differ)
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs