http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89177
Revision: 89177 Author: ashley Date: 2011-05-30 16:27:20 +0000 (Mon, 30 May 2011) Log Message: ----------- SemanticGlossary: fix funky spacing + some other misc. tweaks Modified Paths: -------------- trunk/extensions/SemanticGlossary/SemanticGlossary.php trunk/extensions/SemanticGlossary/SemanticGlossaryElement.php trunk/extensions/SemanticGlossary/SemanticGlossaryMessageLog.php trunk/extensions/SemanticGlossary/SemanticGlossaryParser.php trunk/extensions/SemanticGlossary/SemanticGlossaryTree.php trunk/extensions/SemanticGlossary/SpecialSemanticGlossaryBrowser.php Modified: trunk/extensions/SemanticGlossary/SemanticGlossary.php =================================================================== --- trunk/extensions/SemanticGlossary/SemanticGlossary.php 2011-05-30 16:10:23 UTC (rev 89176) +++ trunk/extensions/SemanticGlossary/SemanticGlossary.php 2011-05-30 16:27:20 UTC (rev 89177) @@ -31,12 +31,11 @@ */ define( 'SG_VERSION', '0.1 alpha' ); - // register the extension -$wgExtensionCredits[ defined( 'SEMANTIC_EXTENSION_TYPE' ) ? 'semantic' : 'other' ][ ] = array( +$wgExtensionCredits[defined( 'SEMANTIC_EXTENSION_TYPE' ) ? 'semantic' : 'other'][] = array( 'path' => __FILE__, 'name' => 'Semantic Glossary', - 'author' => array( '[http://www.mediawiki.org/wiki/User:F.trott Stephan Gambke]' ), + 'author' => '[http://www.mediawiki.org/wiki/User:F.trott Stephan Gambke]', 'url' => 'http://www.mediawiki.org/wiki/Extension:Semantic_Glossary', 'descriptionmsg' => 'semanticglossary-desc', 'version' => SG_VERSION, @@ -46,33 +45,30 @@ $dir = dirname( __FILE__ ); // register message file -$wgExtensionMessagesFiles[ 'SemanticGlossary' ] = $dir . '/SemanticGlossary.i18n.php'; -$wgExtensionMessagesFiles[ 'SemanticGlossaryAlias' ] = $dir . '/SemanticGlossary.alias.php'; +$wgExtensionMessagesFiles['SemanticGlossary'] = $dir . '/SemanticGlossary.i18n.php'; +$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[ 'SemanticGlossaryMessageLog' ] = $dir . '/SemanticGlossaryMessageLog.php'; -$wgAutoloadClasses[ 'SpecialSemanticGlossaryBrowser' ] = $dir . '/SpecialSemanticGlossaryBrowser.php'; +$wgAutoloadClasses['SemanticGlossarySettings'] = $dir . '/SemanticGlossarySettings.php'; +$wgAutoloadClasses['SemanticGlossaryParser'] = $dir . '/SemanticGlossaryParser.php'; +$wgAutoloadClasses['SemanticGlossaryTree'] = $dir . '/SemanticGlossaryTree.php'; +$wgAutoloadClasses['SemanticGlossaryElement'] = $dir . '/SemanticGlossaryElement.php'; +$wgAutoloadClasses['SemanticGlossaryMessageLog'] = $dir . '/SemanticGlossaryMessageLog.php'; +$wgAutoloadClasses['SpecialSemanticGlossaryBrowser'] = $dir . '/SpecialSemanticGlossaryBrowser.php'; - // register Special pages -$wgSpecialPages[ 'SemanticGlossaryBrowser' ] = 'SpecialSemanticGlossaryBrowser'; # Tell MediaWiki about the new special page and its class name -$wgSpecialPageGroups[ 'SemanticGlossaryBrowser' ] = 'other'; +$wgSpecialPages['SemanticGlossaryBrowser'] = 'SpecialSemanticGlossaryBrowser'; +$wgSpecialPageGroups['SemanticGlossaryBrowser'] = 'other'; // register hook handlers //$wgHooks['ParserFirstCallInit'][] = 'SemanticGlossarySetup'; // Define a setup function -$wgHooks[ 'ParserAfterTidy' ][ ] = array( 'SemanticGlossaryParser::parse' ); +$wgHooks['ParserAfterTidy'][] = 'SemanticGlossaryParser::parse'; +$wgHooks['smwInitProperties'][] = 'SemanticGlossaryRegisterProperties'; +$wgHooks['smwInitDatatypes'][] = 'SemanticGlossaryRegisterPropertyAliases'; -$wgHooks[ 'smwInitProperties' ][] = 'SemanticGlossaryRegisterProperties'; -$wgHooks[ 'smwInitDatatypes'][] = 'SemanticGlossaryRegisterPropertyAliases'; - // register resource modules with the Resource Loader -$wgResourceModules[ 'ext.SemanticGlossary' ] = array( +$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', @@ -91,14 +87,14 @@ 'remoteExtPath' => 'SemanticGlossary' ); -$wgResourceModules[ 'ext.SemanticGlossary.Browser' ] = array( +$wgResourceModules['ext.SemanticGlossary.Browser'] = array( '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; +$wgGroupPermissions['user']['editglossary'] = true; // create and initialize settings object $sggSettings = new SemanticGlossarySettings(); @@ -116,14 +112,14 @@ define( 'SG_PROP_GLL', 'Glossary-Link' ); -function SemanticGlossaryRegisterProperties () { +function SemanticGlossaryRegisterProperties() { SMWDIProperty::registerProperty( '___glt', '_str', SG_PROP_GLT, true ); SMWDIProperty::registerProperty( '___gld', '_txt', SG_PROP_GLD, true ); SMWDIProperty::registerProperty( '___gll', '_str', SG_PROP_GLL, true ); return true; } -function SemanticGlossaryRegisterPropertyAliases () { +function SemanticGlossaryRegisterPropertyAliases() { SMWDIProperty::registerPropertyAlias( '___glt', wfMsg( 'semanticglossary-prop-glt' ) ); SMWDIProperty::registerPropertyAlias( '___gld', wfMsg( 'semanticglossary-prop-gld' ) ); SMWDIProperty::registerPropertyAlias( '___gll', wfMsg( 'semanticglossary-prop-gll' ) ); Modified: trunk/extensions/SemanticGlossary/SemanticGlossaryElement.php =================================================================== --- trunk/extensions/SemanticGlossary/SemanticGlossaryElement.php 2011-05-30 16:10:23 UTC (rev 89176) +++ trunk/extensions/SemanticGlossary/SemanticGlossaryElement.php 2011-05-30 16:27:20 UTC (rev 89177) @@ -25,83 +25,78 @@ const SG_LINK = 3; private $mFullDefinition = null; - private $mDefinitions = array( ); + private $mDefinitions = array(); static private $mLinkTemplate = null; - public function __construct ( &$definition=null ) { + public function __construct( &$definition = null ) { if ( $definition ) { - $this -> addDefinition( $definition ); + $this->addDefinition( $definition ); } } - public function addDefinition ( &$definition ) { - - $this ->mDefinitions[] = $definition; + public function addDefinition( &$definition ) { + $this->mDefinitions[] = $definition; } - public function getFullDefinition ( DOMDocument &$doc ) { - + public function getFullDefinition( DOMDocument &$doc ) { // only create if not yet created - if ( $this -> mFullDefinition == null || $this -> mFullDefinition -> ownerDocument !== $doc ) { + if ( $this->mFullDefinition == null || $this->mFullDefinition->ownerDocument !== $doc ) { + $this->mFullDefinition = $doc->createElement( 'span' ); - $this -> mFullDefinition = $doc -> createElement( 'span' ); - - 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 ] ); + 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 ); + $link = $this->getLinkTemplate( $doc ); + $link->setAttribute( 'href', $linkedTitle->getFullURL() ); + $element->appendChild( $link ); } } - $this -> mFullDefinition -> appendChild( $element ); + $this->mFullDefinition->appendChild( $element ); } } - return $this -> mFullDefinition -> cloneNode( true ); + return $this->mFullDefinition->cloneNode( true ); } - public function getCurrentKey () { - return key( $this -> mDefinitions ); + public function getCurrentKey() { + return key( $this->mDefinitions ); } - public function getTerm ( $key ) { - return $this -> mDefinitions[ $key ][ self::SG_TERM ]; + public function getTerm( $key ) { + return $this->mDefinitions[$key][self::SG_TERM]; } - public function getSource ( &$key ) { - return $this -> mDefinitions[ $key ][ self::SG_SOURCE ]; + public function getSource( &$key ) { + return $this->mDefinitions[$key][self::SG_SOURCE]; } - public function getDefinition ( &$key ) { - return $this -> mDefinitions[ $key ][ self::SG_DEFINITION ]; + public function getDefinition( &$key ) { + return $this->mDefinitions[$key][self::SG_DEFINITION]; } - public function getLink ( &$key ) { - return $this -> mDefinitions[ $key ][ self::SG_LINK ]; + public function getLink( &$key ) { + return $this->mDefinitions[$key][self::SG_LINK]; } - public function next () { - next( $this -> mDefinitions ); + public function next() { + next( $this->mDefinitions ); } - private function getLinkTemplate ( DOMDocument &$doc ) { - + private function getLinkTemplate( DOMDocument &$doc ) { // create template if it does not yet exist - if ( !self::$mLinkTemplate || ( self::$mLinkTemplate -> ownerDocument !== $doc ) ) { - + if ( !self::$mLinkTemplate || ( self::$mLinkTemplate->ownerDocument !== $doc ) ) { global $wgScriptPath; - $linkimage = $doc -> createElement( 'img' ); - $linkimage -> setAttribute( "src", $wgScriptPath . '/extensions/SemanticGlossary/skins/linkicon.png' ); + $linkimage = $doc->createElement( 'img' ); + $linkimage->setAttribute( 'src', $wgScriptPath . '/extensions/SemanticGlossary/skins/linkicon.png' ); - self::$mLinkTemplate = $doc -> createElement( 'a' ); - self::$mLinkTemplate -> appendChild( $linkimage ); + self::$mLinkTemplate = $doc->createElement( 'a' ); + self::$mLinkTemplate->appendChild( $linkimage ); } - return self::$mLinkTemplate -> cloneNode( true ); + return self::$mLinkTemplate->cloneNode( true ); } } Modified: trunk/extensions/SemanticGlossary/SemanticGlossaryMessageLog.php =================================================================== --- trunk/extensions/SemanticGlossary/SemanticGlossaryMessageLog.php 2011-05-30 16:10:23 UTC (rev 89176) +++ trunk/extensions/SemanticGlossary/SemanticGlossaryMessageLog.php 2011-05-30 16:27:20 UTC (rev 89177) @@ -21,31 +21,30 @@ */ class SemanticGlossaryMessageLog { - private $mMessages = array( ); + 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 addMessage( $message, $severity = self::SG_NOTICE ) { + $this->mMessages[] = array( $message, $severity ); } - function addError ( $message ) { - $this -> mMessages[ ] = array( $message, self::SG_ERROR ); + function addError( $message ) { + $this->mMessages[] = array( $message, self::SG_ERROR ); } - function addWarning ( $message ) { - $this -> mMessages[ ] = array( $message, self::SG_WARNING ); + function addWarning( $message ) { + $this->mMessages[] = array( $message, self::SG_WARNING ); } - function addNotice ( $message ) { - $this -> mMessages[ ] = array( $message, self::SG_NOTICE ); + function addNotice( $message ) { + $this->mMessages[] = array( $message, self::SG_NOTICE ); } - function getMessagesFormatted ( $severity = self::SG_WARNING, $header = null ) { - + function getMessagesFormatted( $severity = self::SG_WARNING, $header = null ) { global $wgTitle, $wgUser; $ret = ''; @@ -54,23 +53,21 @@ $header = wfMsg( 'semanticglossary-messageheader' ); } - foreach ( $this -> mMessages as $message ) { - if ( $message[ 1 ] <= $severity ) { - $ret .= "* " . $message[ 0 ] . "\n"; + foreach ( $this->mMessages as $message ) { + if ( $message[1] <= $severity ) { + $ret .= '* ' . $message[0] . "\n"; } } if ( $ret != '' ) { - - if ( !$this -> parser ) { + 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() + $parser->parse( $ret, $wgTitle, ParserOptions::newFromUser( $wgUser ) )->getText() ); - } return $ret; Modified: trunk/extensions/SemanticGlossary/SemanticGlossaryParser.php =================================================================== --- trunk/extensions/SemanticGlossary/SemanticGlossaryParser.php 2011-05-30 16:10:23 UTC (rev 89176) +++ trunk/extensions/SemanticGlossary/SemanticGlossaryParser.php 2011-05-30 16:27:20 UTC (rev 89177) @@ -32,15 +32,14 @@ * @param $text * @return Boolean */ - static function parse ( &$parser, &$text ) { - + static function parse( &$parser, &$text ) { wfProfileIn( __METHOD__ ); if ( !self::$parserSingleton ) { self::$parserSingleton = new SemanticGlossaryParser(); } - self::$parserSingleton -> realParse( $parser, $text ); + self::$parserSingleton->realParse( $parser, $text ); wfProfileOut( __METHOD__ ); @@ -52,18 +51,17 @@ * * @return Array an array mapping terms (keys) to descriptions (values) */ - function getGlossaryArray ( SemanticGlossaryMessageLog &$messages = null ) { - + function getGlossaryArray( SemanticGlossaryMessageLog &$messages = null ) { wfProfileIn( __METHOD__ ); // build glossary array only once per request - if ( !$this -> mGlossaryArray ) { - $this -> buildGlossary( $messages ); + if ( !$this->mGlossaryArray ) { + $this->buildGlossary( $messages ); } wfProfileOut( __METHOD__ ); - return $this -> mGlossaryArray; + return $this->mGlossaryArray; } /** @@ -71,74 +69,75 @@ * * @return Array an array mapping terms (keys) to descriptions (values) */ - function getGlossaryTree ( SemanticGlossaryMessageLog &$messages = null ) { - + function getGlossaryTree( SemanticGlossaryMessageLog &$messages = null ) { wfProfileIn( __METHOD__ ); // build glossary array only once per request - if ( !$this -> mGlossaryTree ) { - $this -> buildGlossary( $messages ); + if ( !$this->mGlossaryTree ) { + $this->buildGlossary( $messages ); } wfProfileOut( __METHOD__ ); - return $this -> mGlossaryTree; + return $this->mGlossaryTree; } - protected function buildGlossary ( SemanticGlossaryMessageLog &$messages = null ) { - + protected function buildGlossary( SemanticGlossaryMessageLog &$messages = null ) { wfProfileIn( __METHOD__ ); - $this -> mGlossaryTree = new SemanticGlossaryTree(); + $this->mGlossaryTree = new SemanticGlossaryTree(); $store = smwfGetStore(); // default store // 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, true, false ); - $query -> querymode = SMWQuery::MODE_INSTANCES; + $query->querymode = SMWQuery::MODE_INSTANCES; global $smwgQDefaultLimit; - $query -> setLimit( $smwgQDefaultLimit ); - $query -> sortkeys[ SG_PROP_GLT ] = 'ASC'; + $query->setLimit( $smwgQDefaultLimit ); + $query->sortkeys[SG_PROP_GLT] = 'ASC'; // get the query result - $queryresult = $store -> getQueryResult( $query ); + $queryresult = $store->getQueryResult( $query ); // assemble the result array - $this -> mGlossaryArray = array( ); - while ( ( $resultline = $queryresult -> getNext() ) ) { + $this->mGlossaryArray = array(); + while ( ( $resultline = $queryresult->getNext() ) ) { + $term = $resultline[0]->getNextText( SMW_OUTPUT_HTML ); + $definition = $resultline[1]-> getNextText( SMW_OUTPUT_HTML ); + $link = $resultline[2]->getNextText( SMW_OUTPUT_HTML ); + $subject = $resultline[0]->getResultSubject(); - $term = $resultline[ 0 ] -> getNextText( SMW_OUTPUT_HTML ); - $definition = $resultline[ 1 ] -> getNextText( SMW_OUTPUT_HTML ); - $link = $resultline[ 2 ] -> getNextText( SMW_OUTPUT_HTML ); - $subject = $resultline[ 0 ] -> getResultSubject(); - // 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) - $nextTerm = $resultline[ 0 ] -> getNextText( SMW_OUTPUT_HTML ); - $nextDefinition = $resultline[ 1 ] -> getNextText( SMW_OUTPUT_HTML ); + $nextTerm = $resultline[0]->getNextText( SMW_OUTPUT_HTML ); + $nextDefinition = $resultline[1]->getNextText( SMW_OUTPUT_HTML ); // skip if more then one term or more than one definition present if ( ( $nextTerm || $nextDefinition ) && !( $nextTerm == $term && $nextDefinition == $definition ) ) { if ( $messages ) { - $messages -> addMessage( - wfMsg( 'semanticglossary-termdefinedtwice', array( $subject -> getTitle() -> getPrefixedText() ) ), + $messages->addMessage( + wfMsg( 'semanticglossary-termdefinedtwice', array( $subject->getTitle()->getPrefixedText() ) ), SemanticGlossaryMessageLog::SG_WARNING ); } continue; } - $source = array( $subject -> getDBkey(), $subject -> getNamespace(), $subject -> getInterwiki() ); + $source = array( + $subject->getDBkey(), + $subject->getNamespace(), + $subject->getInterwiki() + ); $elementData = array( SemanticGlossaryElement::SG_TERM => $term, @@ -147,13 +146,13 @@ SemanticGlossaryElement::SG_SOURCE => $source ); - if ( array_key_exists( $term, $this -> mGlossaryArray ) ) { - $this -> mGlossaryArray[ $term ] -> addDefinition( $elementData ); + if ( array_key_exists( $term, $this->mGlossaryArray ) ) { + $this->mGlossaryArray[$term]->addDefinition( $elementData ); } else { - $this -> mGlossaryArray[ $term ] = new SemanticGlossaryElement( $elementData ); + $this->mGlossaryArray[$term] = new SemanticGlossaryElement( $elementData ); } - $this -> mGlossaryTree -> addTerm( $term, $elementData ); + $this->mGlossaryTree->addTerm( $term, $elementData ); } wfProfileOut( __METHOD__ ); @@ -168,19 +167,18 @@ * @param $text * @return Boolean */ - protected function realParse ( &$parser, &$text ) { - + protected function realParse( &$parser, &$text ) { global $wgRequest, $sggSettings; wfProfileIn( __METHOD__ ); - $action = $wgRequest -> getVal( 'action', 'view' ); + $action = $wgRequest->getVal( 'action', 'view' ); if ( $text == null || $text == '' || - $action == "edit" || - $action == "ajax" || - isset( $_POST[ 'wpPreview' ] ) + $action == 'edit' || + $action == 'ajax' || + isset( $_POST['wpPreview'] ) ) { wfProfileOut( __METHOD__ ); @@ -188,76 +186,77 @@ } // Get array of terms - $glossary = $this -> getGlossaryTree(); + $glossary = $this->getGlossaryTree(); if ( $glossary == null ) { - wfProfileOut( __METHOD__ ); return true; } - //Parse HTML from page - // FIXME: this works in PHP 5.3.3. What about 5.1? - wfProfileIn( __METHOD__ . " 1 loadHTML" ); + // 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>' + '<html><meta http-equiv="content-type" content="charset=utf-8"/>' . $text . '</html>' ); wfRestoreWarnings(); - wfProfileOut( __METHOD__ . " 1 loadHTML" ); + wfProfileOut( __METHOD__ . ' 1 loadHTML' ); - wfProfileIn( __METHOD__ . " 2 xpath" ); - //Find all text in HTML. + 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()" + $elements = $xpath->query( + "//*[not(ancestor-or-self::*[@class='noglossary'] or ancestor-or-self::a)][text()!=' ']/text()" ); - wfProfileOut( __METHOD__ . " 2 xpath" ); + wfProfileOut( __METHOD__ . ' 2 xpath' ); - //Iterate all HTML text matches - $nb = $elements -> length; + // Iterate all HTML text matches + $nb = $elements->length; $changedDoc = false; for ( $pos = 0; $pos < $nb; $pos++ ) { + $el = $elements->item( $pos ); - $el = $elements -> item( $pos ); - - if ( strlen( $el -> nodeValue ) < $glossary -> getMinTermLength() ) { + 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" ); + 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 ) { + if ( count( $matches ) == 0 || count( $matches[0] ) == 0 ) { continue; } - $lexemes = &$matches[ 0 ]; + $lexemes = &$matches[0]; $countLexemes = count( $lexemes ); - $parent = &$el -> parentNode; + $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__ . " 4 findNextTerm" ); - list( $skipped, $used, $definition ) = $glossary -> findNextTerm( $lexemes, $index, $countLexemes ); - wfProfileOut( __METHOD__ . " 4 findNextTerm" ); - - wfProfileIn( __METHOD__ . " 5 insert" ); + 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 ) + $parent->insertBefore( + $doc->createTextNode( + substr( $el->nodeValue, + $currLexIndex = $lexemes[$index][1], + $lexemes[$index + $skipped][1] - $currLexIndex ) ), $el ); @@ -265,27 +264,27 @@ $index += $skipped; - //Wrap abbreviation in <span> tags + // Wrap abbreviation in <span> tags $span = $doc -> createElement( 'span' ); - $span -> setAttribute( 'class', "tooltip" ); + $span -> setAttribute( 'class', 'tooltip' ); - //Wrap abbreviation in <span> tags, hidden - $lastLex = $lexemes[ $index + $used - 1 ]; - $spanTerm = $doc -> createElement( 'span', - substr( $el -> nodeValue, - $currLexIndex = $lexemes[ $index ][ 1 ], - $lastLex[ 1 ] - $currLexIndex + strlen( $lastLex[ 0 ] ) ) + // Wrap abbreviation in <span> tags, hidden + $lastLex = $lexemes[$index + $used - 1]; + $spanTerm = $doc->createElement( 'span', + substr( $el->nodeValue, + $currLexIndex = $lexemes[$index][1], + $lastLex[1] - $currLexIndex + strlen( $lastLex[0] ) ) ); - $spanTerm -> setAttribute( 'class', "tooltip_abbr" ); + $spanTerm->setAttribute( 'class', 'tooltip_abbr' ); - //Wrap definition in <span> tags, hidden - $spanDefinition = $definition -> getFullDefinition( $doc ); - $spanDefinition -> setAttribute( 'class', "tooltip_tip" ); + // Wrap definition in <span> tags, hidden + $spanDefinition = $definition->getFullDefinition( $doc ); + $spanDefinition->setAttribute( 'class', 'tooltip_tip' ); // insert term and definition - $span -> appendChild( $spanTerm ); - $span -> appendChild( $spanDefinition ); - $parent -> insertBefore( $span, $el ); + $span->appendChild( $spanTerm ); + $span->appendChild( $spanDefinition ); + $parent->insertBefore( $span, $el ); $changedElem = true; } else { // did not find term, just use the rest of the text @@ -294,15 +293,14 @@ // element at all. // Only change element if found term before if ( $changedElem ) { - $parent -> insertBefore( - $doc -> createTextNode( - substr( $el -> nodeValue, $lexemes[ $index ][ 1 ] ) + $parent->insertBefore( + $doc->createTextNode( + substr( $el->nodeValue, $lexemes[$index][1] ) ), $el ); } else { - - wfProfileOut( __METHOD__ . " 5 insert" ); + wfProfileOut( __METHOD__ . ' 5 insert' ); // In principle superfluous, the loop would run out // anyway. Might save a bit of time. break; @@ -310,28 +308,28 @@ $index += $skipped; } - wfProfileOut( __METHOD__ . " 5 insert" ); + wfProfileOut( __METHOD__ . ' 5 insert' ); $index += $used; } if ( $changedElem ) { - $parent -> removeChild( $el ); + $parent->removeChild( $el ); $changedDoc = true; } } if ( $changedDoc ) { - $body = $xpath -> query( '/html/body' ); + $body = $xpath->query( '/html/body' ); $text = ''; - foreach ( $body -> item( 0 ) -> childNodes as $child ) { - $text .= $doc -> saveXML( $child ); + foreach ( $body->item( 0 )->childNodes as $child ) { + $text .= $doc->saveXML( $child ); } - $this -> loadModules( $parser ); + $this->loadModules( $parser ); } wfProfileOut( __METHOD__ ); @@ -339,24 +337,20 @@ return true; } - protected - - function loadModules ( &$parser ) { - + protected function loadModules( &$parser ) { global $wgOut, $wgScriptPath; if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) { - if ( !is_null( $parser ) ) { - $parser -> getOutput() -> addModules( 'ext.SemanticGlossary' ); + $parser->getOutput()->addModules( 'ext.SemanticGlossary' ); } else { - $wgOut -> addModules( 'ext.SemanticGlossary' ); + $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' ); + 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" />' ); + $wgOut->addHeadItem( 'ext.SemanticGlossary.css', '<link rel="stylesheet" href="' . $wgScriptPath . '/extensions/SemanticGlossary/skins/SemanticGlossary.css" />' ); } } } Modified: trunk/extensions/SemanticGlossary/SemanticGlossaryTree.php =================================================================== --- trunk/extensions/SemanticGlossary/SemanticGlossaryTree.php 2011-05-30 16:10:23 UTC (rev 89176) +++ trunk/extensions/SemanticGlossary/SemanticGlossaryTree.php 2011-05-30 16:27:20 UTC (rev 89177) @@ -24,7 +24,7 @@ */ class SemanticGlossaryTree { - private $mTree = array( ); + private $mTree = array(); private $mDefinition = null; private $mMinLength = -1; @@ -32,8 +32,7 @@ * Adds a string to the Glossary Tree * @param String $term */ - function addTerm ( &$term, $definition ) { - + function addTerm( &$term, $definition ) { if ( !$term ) { return; } @@ -41,37 +40,33 @@ $matches; preg_match_all( '/[[:alpha:]]+|[^[:alpha:]]/u', $term, $matches ); - $this -> addElement( $matches[ 0 ], $definition ); + $this->addElement( $matches[0], $definition ); - if ( $this -> mMinLength > -1 ) { - $this -> mMinLength = min( array( $this -> mMinLength, strlen( $term ) ) ); + if ( $this->mMinLength > -1 ) { + $this->mMinLength = min( array( $this->mMinLength, strlen( $term ) ) ); } else { - $this -> mMinLength = strlen( $term ); + $this->mMinLength = strlen( $term ); } } /** - * Recursively adds an element to the Glossary Tree + * Recursively adds an element to the Glossary Tree * * @param array $path * @param <type> $index */ - protected function addElement ( Array &$path, &$definition ) { - + protected function addElement( Array &$path, &$definition ) { // end of path, store description; end of recursion if ( $path == null ) { - $this -> addDefinition( $definition ); } else { - $step = array_shift( $path ); - if ( !array_key_exists( $step, $this -> mTree ) ) { - - $this -> mTree[ $step ] = new SemanticGlossaryTree(); + if ( !array_key_exists( $step, $this->mTree ) ) { + $this->mTree[$step] = new SemanticGlossaryTree(); } - $this -> mTree[ $step ] -> addElement( $path, $definition ); + $this->mTree[$step]->addElement( $path, $definition ); } } @@ -79,21 +74,19 @@ * Adds a defintion to the treenodes list of definitions * @param <type> $definition */ - protected function addDefinition ( &$definition ) { - - if ( $this -> mDefinition ) { - $this -> mDefinition -> addDefinition( $definition ); + protected function addDefinition( &$definition ) { + if ( $this->mDefinition ) { + $this->mDefinition->addDefinition( $definition ); } else { - $this -> mDefinition = new SemanticGlossaryElement( $definition ); + $this->mDefinition = new SemanticGlossaryElement( $definition ); } } - function getMinTermLength () { - return $this -> mMinLength; + function getMinTermLength() { + return $this->mMinLength; } - function findNextTerm ( &$lexemes, $index, $countLexemes ) { - + function findNextTerm( &$lexemes, $index, $countLexemes ) { wfProfileIn( __METHOD__ ); $start = $lastindex = $index; @@ -101,13 +94,11 @@ // skip until ther start of a term is found while ( $index < $countLexemes && !$definition ) { - - $currLex = &$lexemes[ $index ][ 0 ]; + $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 ); + 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; @@ -123,15 +114,13 @@ } } - function findNextTermNoSkip ( &$lexemes, $index, $countLexemes ) { + 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 ); + 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 ); + $ret = array( $index, &$this->mDefinition ); } wfProfileOut( __METHOD__ ); return $ret; Modified: trunk/extensions/SemanticGlossary/SpecialSemanticGlossaryBrowser.php =================================================================== --- trunk/extensions/SemanticGlossary/SpecialSemanticGlossaryBrowser.php 2011-05-30 16:10:23 UTC (rev 89176) +++ trunk/extensions/SemanticGlossary/SpecialSemanticGlossaryBrowser.php 2011-05-30 16:27:20 UTC (rev 89177) @@ -27,41 +27,36 @@ private $mMessages; - function __construct () { + function __construct() { parent::__construct( 'SemanticGlossaryBrowser' ); $this -> mMessages = new SemanticGlossaryMessageLog(); } - function execute ( $subpage ) { - + function execute( $subpage ) { global $wgRequest, $wgOut, $wgUser; // preparation stuff - $this -> setHeaders(); - $this -> loadModules(); + $this->setHeaders(); + $this->loadModules(); - $hasEditRights = $wgUser -> isAllowed( 'editglossary' ); + $hasEditRights = $wgUser->isAllowed( 'editglossary' ); - if ( $this -> isActionAllowed() ) { - - if ( $wgRequest -> getText( 'submit' ) != null ) { - + if ( $this->isActionAllowed() ) { + if ( $wgRequest->getText( 'submit' ) != null ) { // if the form was submitted, store the data - $this -> actionStoreData(); - } else if ( $wgRequest -> getText( 'createnew' ) != null ) { - + $this->actionStoreData(); + } elseif ( $wgRequest->getText( 'createnew' ) != null ) { // if a new term was defined, create it - $this -> actionCreateNewTerm(); - } else if ( $wgRequest -> getText( 'delete' ) != null ) { - + $this->actionCreateNewTerm(); + } elseif ( $wgRequest->getText( 'delete' ) != null ) { // if a new term was defined, create it - $this -> actionDeleteData(); + $this->actionDeleteData(); } } // get the glossary data $parser = new SemanticGlossaryParser(); - $glossaryarray = $parser -> getGlossaryArray( $this -> mMessages ); + $glossaryarray = $parser->getGlossaryArray( $this->mMessages ); // set function to create a table row (textareas when editing is // allowed, else normal text) @@ -72,23 +67,20 @@ } // create HTML fragment for table rows - $tablerows = ''; // loop through all terms foreach ( $glossaryarray as $term => $glossaryElement ) { - // One term may have several definitions. Include them all. - while ( ( $key = $glossaryElement -> getCurrentKey() ) !== null ) { + while ( ( $key = $glossaryElement->getCurrentKey() ) !== null ) { + $sourceArray = $glossaryElement->getSource( $key ); + $source = $sourceArray[2] . ':' . $sourceArray[1] . ':' . $sourceArray[0]; + $definition = $glossaryElement->getDefinition( $key ); + $link = $glossaryElement->getLink( $key ); - $sourceArray = $glossaryElement -> getSource( $key ); - $source = $sourceArray[ 2 ] . ':' . $sourceArray[ 1 ] . ':' . $sourceArray[ 0 ]; - $definition = $glossaryElement -> getDefinition( $key ); - $link = $glossaryElement -> getLink( $key ); + $tablerows .= $this->$createTableRowMethod( $source, $term, $definition, $link ); - $tablerows .= $this -> $createTableRowMethod( $source, $term, $definition, $link ); - - $glossaryElement -> next(); + $glossaryElement->next(); } } @@ -118,14 +110,13 @@ } // From here on no more errors should occur. Create list of errors. - $errorsFragment = $this -> mMessages -> getMessagesFormatted( SemanticGlossaryMessageLog::SG_NOTICE ); + $errorsFragment = $this->mMessages->getMessagesFormatted( SemanticGlossaryMessageLog::SG_NOTICE ); if ( $errorsFragment ) { $errorsFragment .= Html::rawElement( 'hr' ); } if ( $hasEditRights ) { - // create form fragment to allow input of a new term $newTermFragment = Html::rawElement( 'hr' ) . @@ -165,7 +156,6 @@ ) ); } else { - // assemble output $output = Html::rawElement( 'div', array( 'class' => 'glossarybrowser' ), @@ -174,7 +164,7 @@ ); } - $wgOut -> addHTML( $output ); + $wgOut->addHTML( $output ); } /** @@ -183,29 +173,27 @@ * * @return String */ - function getDescription () { + function getDescription() { return wfMsg( 'semanticglossary-browsertitle' ); } /** * Loads the CSS file for the GlossaryBrowser Special page */ - protected function loadModules () { - + protected function loadModules() { global $wgOut, $wgScriptPath; if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) { - $wgOut -> addModules( 'ext.SemanticGlossary.Browser' ); + $wgOut->addModules( 'ext.SemanticGlossary.Browser' ); } else { - $wgOut -> addHeadItem( 'ext.SemanticGlossary.Browser.css', '<link rel="stylesheet" href="' . $wgScriptPath . '/extensions/SemanticGlossary/skins/SemanticGlossaryBrowser.css" />' ); + $wgOut->addHeadItem( 'ext.SemanticGlossary.Browser.css', '<link rel="stylesheet" href="' . $wgScriptPath . '/extensions/SemanticGlossary/skins/SemanticGlossaryBrowser.css" />' ); } } /** * Gets data from wgRequest and stores it */ - protected function actionStoreData () { - + protected function actionStoreData() { global $wgRequest; // get ass array of input values @@ -216,139 +204,141 @@ // only consider terms here, other parameters are accessed by name if ( substr( $key, -5 ) == ':term' ) { - // cut off ':term' $pageString = substr( $key, 0, -5 ); // new data $newTerm = $value; - $newDefinition = $inputdata[ $pageString . ':definition' ]; - $newLink = $inputdata[ $pageString . ':link' ]; + $newDefinition = $inputdata[$pageString . ':definition']; + $newLink = $inputdata[$pageString . ':link']; - $page = $this -> getPageObjectFromInputName( $pageString ); + $page = $this->getPageObjectFromInputName( $pageString ); // get its data - $pageData = smwfGetStore() -> getSemanticData( $page ); + $pageData = smwfGetStore()->getSemanticData( $page ); // get old values - $oldTerm = $this -> getPropertyFromData( $pageData, '___glt' ); - if ( $oldTerm === false ) + $oldTerm = $this->getPropertyFromData( $pageData, '___glt' ); + if ( $oldTerm === false ) { continue; + } - $oldDefinition = $this -> getPropertyFromData( $pageData, '___gld' ); - if ( $oldDefinition === false ) + $oldDefinition = $this->getPropertyFromData( $pageData, '___gld' ); + if ( $oldDefinition === false ) { continue; + } - $oldLink = $this -> getPropertyFromData( $pageData, '___gll' ); - if ( $oldLink === false ) + $oldLink = $this->getPropertyFromData( $pageData, '___gll' ); + if ( $oldLink === false ) { continue; + } // only store data if anything changed if ( $newTerm != $oldTerm || $newDefinition != $oldDefinition || $newLink != $oldLink ) { - $this -> updateData( $page, array( - '___glt' => ($newTerm ? new SMWDIString( $newTerm ) : null), - '___gld' => ($newDefinition ? new SMWDIBlob( $newDefinition ) : null), - '___gll' => ($newLink ? new SMWDIString( $newLink ) : null) + '___glt' => ( $newTerm ? new SMWDIString( $newTerm ) : null ), + '___gld' => ( $newDefinition ? new SMWDIBlob( $newDefinition ) : null ), + '___gll' => ( $newLink ? new SMWDIString( $newLink ) : null ) ) ); // issue a warning if the original definition is on a real page - - $title = $page -> getTitle(); - if ( $title -> isKnown() ) { - $this -> mMessages -> addMessage( - wfMsg( 'semanticglossary-storedtermdefinedinarticle', array( $oldTerm, $title -> getPrefixedText() ) ), + $title = $page->getTitle(); + if ( $title->isKnown() ) { + $this->mMessages->addMessage( + wfMsg( 'semanticglossary-storedtermdefinedinarticle', array( $oldTerm, $title->getPrefixedText() ) ), SemanticGlossaryMessageLog::SG_WARNING ); } else { - $this -> mMessages -> addMessage( wfMsg( 'semanticglossary-termchanged', array( $oldTerm ) ), SemanticGlossaryMessageLog::SG_NOTICE ); + $this->mMessages->addMessage( + wfMsg( 'semanticglossary-termchanged', array( $oldTerm ) ), + SemanticGlossaryMessageLog::SG_NOTICE + ); } } } } } - protected function actionCreateNewTerm () { - + protected function actionCreateNewTerm() { global $wgRequest; - $newTerm = $wgRequest -> getText( 'newterm' ); + $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.', SemanticGlossaryMessageLog::SG_WARNING ); return; } - $newDefinition = $wgRequest -> getText( 'newdefinition' ); - $newLink = $wgRequest -> getText( 'newlink' ); + $newDefinition = $wgRequest->getText( 'newdefinition' ); + $newLink = $wgRequest->getText( 'newlink' ); - $page = $this -> findNextPageName(); + $page = $this->findNextPageName(); // store data $this -> updateData( $page, array( - '___glt' => ($newTerm ? new SMWDIString( $newTerm ) : null), - '___gld' => ($newDefinition ? new SMWDIBlob( $newDefinition ) : null), - '___gll' => ($newLink ? new SMWDIString( $newLink ) : null) + '___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 ); + $this->mMessages->addMessage( + wfMsg( 'semanticglossary-termadded', array( $newTerm ) ), + SemanticGlossaryMessageLog::SG_NOTICE + ); } - protected function actionDeleteData () { - + protected function actionDeleteData() { global $wgRequest; // get ass array of input values - $inputdata = $wgRequest -> getValues(); + $inputdata = $wgRequest->getValues(); foreach ( $inputdata as $key => $value ) { - // only consider checkboxes here if ( substr( $key, -8 ) == ':checked' ) { - // cut off ':checked' $pageString = substr( $key, 0, -8 ); - $page = $this -> getPageObjectFromInputName( $pageString ); + $page = $this->getPageObjectFromInputName( $pageString ); - $this -> updateData( $page, array( + $this->updateData( $page, array( '___glt' => null, '___gld' => null, '___gll' => null, - ) ); + ) ); - $oldTerm = $wgRequest -> getVal( $pageString . ':term' ); + $oldTerm = $wgRequest->getVal( $pageString . ':term' ); - $title = $page -> getTitle(); - if ( $title && $title -> isKnown() ) { - - $this -> mMessages -> addMessage( - wfMsg( 'semanticglossary-deletedtermdefinedinarticle', array( $oldTerm, $title -> getPrefixedText() ) ), + $title = $page->getTitle(); + if ( $title && $title->isKnown() ) { + $this->mMessages->addMessage( + wfMsg( 'semanticglossary-deletedtermdefinedinarticle', array( $oldTerm, $title->getPrefixedText() ) ), SemanticGlossaryMessageLog::SG_WARNING ); } else { - $this -> mMessages -> addMessage( wfMsg( 'semanticglossary-termdeleted', array( $oldTerm ) ), SemanticGlossaryMessageLog::SG_NOTICE ); + $this->mMessages->addMessage( + wfMsg( 'semanticglossary-termdeleted', array( $oldTerm ) ), + SemanticGlossaryMessageLog::SG_NOTICE + ); } } } } - protected function getPropertyFromData ( SMWSemanticData &$pageData, $propertyName ) { - + protected function getPropertyFromData( SMWSemanticData &$pageData, $propertyName ) { $property = new SMWDIProperty( $propertyName ); - $propertyValues = $pageData -> getPropertyValues( $property ); + $propertyValues = $pageData->getPropertyValues( $property ); if ( count( $propertyValues ) == 1 ) { - - return $propertyValues[ 0 ] -> getString(); - } else if ( count( $propertyValues ) > 1 ) { - + return $propertyValues[0]->getString(); + } elseif ( count( $propertyValues ) > 1 ) { if ( count( $propertyValues ) > 1 ) { - $this -> mMessages -> addMessage( wfMsg( 'semanticglossary-storedtermdefinedtwice', array( $pageData -> getSubject() -> getPrefixedText(), $propertyName, $newTerm ) ), + $this->mMessages->addMessage( + wfMsg( 'semanticglossary-storedtermdefinedtwice', array( $pageData->getSubject()->getPrefixedText(), $propertyName, $newTerm ) ), SemanticGlossaryMessageLog::SG_ERROR ); } @@ -358,35 +348,33 @@ } } - protected function getPageObjectFromInputName ( $pageString ) { - + protected function getPageObjectFromInputName( $pageString ) { // split the source string into interwiki reference, namespace and page title - $matches = array( ); + $matches = array(); preg_match( '/^(.*):(.*):(.*)$/', $pageString, $matches ); // create SMWWikiPageValue (SMW's wiki page representation) - return new SMWDIWikiPage( $matches[ 3 ], $matches[ 2 ], $matches[ 1 ] ); + return new SMWDIWikiPage( $matches[3], $matches[2], $matches[1] ); } // find unused SMW page - protected function findNextPageName () { + protected function findNextPageName() { + $termPages = smwfGetStore()->getAllPropertySubjects( new SMWDIProperty( '___glt' ) ); + $defPages = smwfGetStore()->getAllPropertySubjects( new SMWDIProperty( '___gld' ) ); + $linkPages = smwfGetStore()->getAllPropertySubjects( new SMWDIProperty( '___gll' ) ); - $termPages = smwfGetStore() -> getAllPropertySubjects( new SMWDIProperty( '___glt' ) ); - $defPages = smwfGetStore() -> getAllPropertySubjects( new SMWDIProperty( '___gld' ) ); - $linkPages = smwfGetStore() -> getAllPropertySubjects( new SMWDIProperty( '___gll' ) ); + $pages = array(); - $pages = array( ); - foreach ( $termPages as $page ) { - $pages[ $page -> getDBkey() ] = $page -> getDBkey(); + $pages[$page->getDBkey()] = $page->getDBkey(); } foreach ( $defPages as $page ) { - $pages[ $page -> getDBkey() ] = $page -> getDBkey(); + $pages[$page->getDBkey()] = $page->getDBkey(); } foreach ( $linkPages as $page ) { - $pages[ $page -> getDBkey() ] = $page -> getDBkey(); + $pages[$page->getDBkey()] = $page->getDBkey(); } $termNumber = count( $pages ); @@ -398,35 +386,30 @@ return new SMWDIWikiPage( "GlossaryTerm#$termNumber", NS_MAIN, '' ); - exit (); + exit(); } - protected function updateData ( SMWDIWikiPage &$page, array $data ) { - + protected function updateData( SMWDIWikiPage &$page, array $data ) { $newData = new SMWSemanticData( $page, false ); - $oldData = smwfGetStore() -> getSemanticData( $page ); - $oldProps = $oldData -> getProperties(); + $oldData = smwfGetStore()->getSemanticData( $page ); + $oldProps = $oldData->getProperties(); // get properties, replace as requested, retain other properties foreach ( $oldProps as $property ) { + $propertyID = $property->getKey(); - $propertyID = $property -> getKey(); - if ( array_key_exists( $propertyID, $data ) ) { - // set new data if defined, else ignore property (i.e. delete property from page) - if ( $data[ $propertyID ] != null ) { - - $newData -> addPropertyObjectValue( $property, $data[ $propertyID ] ); + if ( $data[$propertyID] != null ) { + $newData->addPropertyObjectValue( $property, $data[$propertyID] ); } - unset( $data[ $propertyID ] ); + unset( $data[$propertyID] ); } else { - - $values = $oldData -> getPropertyValues( $property ); + $values = $oldData->getPropertyValues( $property ); foreach ( $values as $value ) { - $newData -> addPropertyObjectValue( $property, $value ); + $newData->addPropertyObjectValue( $property, $value ); } } } @@ -434,23 +417,20 @@ // store properties that were not present before, i.e. properties // remaining in $data foreach ( $data as $propertyID => $propertyValue ) { - // set new data if defined, else ignore property (i.e. do not set property on this page) - if ( $data[ $propertyID ] != null ) { - + if ( $data[$propertyID] != null ) { $property = new SMWDIProperty( $propertyID ); - $newData -> addPropertyObjectValue( $property, $data[ $propertyID ] ); + $newData -> addPropertyObjectValue( $property, $data[$propertyID] ); } - unset( $data[ $propertyID ] ); + unset( $data[$propertyID] ); } // finally store the updated page data - smwfGetStore() -> doDataUpdate( $newData ); + smwfGetStore()->doDataUpdate( $newData ); } - private function createTableRowForEdit ( $source, $term, $definition, $link ) { - + private function createTableRowForEdit( $source, $term, $definition, $link ) { return Html::rawElement( 'tr', array( 'class' => 'row' ), Html::rawElement( 'td', array( 'class' => 'actioncell' ), @@ -470,8 +450,7 @@ ); } - private function createTableRowForDisplay ( $source, $term, $definition, $link ) { - + private function createTableRowForDisplay( $source, $term, $definition, $link ) { return Html::rawElement( 'tr', array( 'class' => 'row' ), Html::rawElement( 'td', array( 'class' => 'termcell' ), $term ) . @@ -486,25 +465,33 @@ * * @return Boolean */ - private function isActionAllowed () { - + private function isActionAllowed() { global $wgRequest, $wgUser; - $editTokenWithSalt = $wgRequest -> getText( 'editToken' ); + $editTokenWithSalt = $wgRequest->getText( 'editToken' ); $actionRequested = ( $editTokenWithSalt != null ); if ( $actionRequested ) { // user wants to perform an action - if ( $wgUser -> isAllowed( 'editglossary' ) ) { // user has the necessary right + if ( $wgUser->isAllowed( 'editglossary' ) ) { // user has the necessary right $editTokenAndSaltArray = explode( EDIT_TOKEN_SUFFIX, $editTokenWithSalt ); - $tokenValid = $wgUser -> matchEditTokenNoSuffix( $editTokenAndSaltArray[ 0 ], $editTokenAndSaltArray[ 1 ] ); + $tokenValid = $wgUser->matchEditTokenNoSuffix( + $editTokenAndSaltArray[0], + $editTokenAndSaltArray[1] + ); if ( $tokenValid ) { // edit token is valid return true; } else { - $this -> mMessages -> addMessage( wfMsg( 'semanticglossary-brokensession' ), SemanticGlossaryMessageLog::SG_ERROR ); + $this->mMessages->addMessage( + wfMsg( 'semanticglossary-brokensession' ), + SemanticGlossaryMessageLog::SG_ERROR + ); } } else { - $this -> mMessages -> addMessage( wfMsg( 'semanticglossary-norights' ), SemanticGlossaryMessageLog::SG_ERROR ); + $this->mMessages->addMessage( + wfMsg( 'semanticglossary-norights' ), + SemanticGlossaryMessageLog::SG_ERROR + ); } } _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs