Smuggli has submitted this change and it was merged.

Change subject: CAI TitleStore and DOMHelper additions
......................................................................


CAI TitleStore and DOMHelper additions

* Changed LIKE in CAI TitleStore query to also habe a left trunc
* Added some methods to DOMHelper

Change-Id: Ief54324702993538878f4027a42a894f8634bc24
---
M includes/CommonAJAXInterface.php
M includes/utility/DOMHelper.class.php
M maintenance/BSMigrationHelper.php
3 files changed, 76 insertions(+), 11 deletions(-)

Approvals:
  Smuggli: Verified; Looks good to me, approved



diff --git a/includes/CommonAJAXInterface.php b/includes/CommonAJAXInterface.php
index ce3f74f..af92914 100644
--- a/includes/CommonAJAXInterface.php
+++ b/includes/CommonAJAXInterface.php
@@ -96,8 +96,8 @@
 
                // We want LIKE operator behind every term,
                // so multi term queries also bring results
-               $aLike = array();
                $sOp = $dbr->anyString();
+               $aLike = array( '', $sOp );
                $sParams = explode( ' ', strtolower( $oQueryTitle->getText() ) 
);
                foreach ( $sParams as $sParam ) {
                        $aLike[] = $sParam;
diff --git a/includes/utility/DOMHelper.class.php 
b/includes/utility/DOMHelper.class.php
index c201670..4c9f745 100644
--- a/includes/utility/DOMHelper.class.php
+++ b/includes/utility/DOMHelper.class.php
@@ -5,7 +5,7 @@
  * @subpackage Utility
  */
 class BsDOMHelper {
-       
+
        /**
         * Finds the previous DOMElement starting from $oNode in the DOM tree
         * @param DOMNode $oNode
@@ -21,7 +21,7 @@
                }
                return static::getPreviousDOMElementSibling( 
$oNode->previousSibling, $aElementNames );
        }
-       
+
        /**
         * Finds the next DOMElement starting from $oNode in the DOM tree
         * @param DOMNode $oNode
@@ -37,7 +37,7 @@
                }
                return static::getNextDOMElementSibling( $oNode->nextSibling, 
$aElementNames );
        }
-       
+
        /**
         * Finds the previous DOMElement starting from $oNode in the DOM tree
         * @param DOMNode $oNode
@@ -53,7 +53,7 @@
                }
                return static::getParentDOMElement( $oNode->parentNode, 
$aElementNames );
        }
-       
+
        /**
         * Finds the previous DOMElement starting from $oNode in the DOM tree
         * @param DOMNode $oNode
@@ -69,9 +69,9 @@
                }
                return static::getNextDOMElementSibling( $oNode->firstChild, 
$aElementNames );
        }
-       
+
        /**
-        * Adds one or more entries to the "class" attribute of all childNodes 
in a 
+        * Adds one or more entries to the "class" attribute of all childNodes 
in a
         * recursive manner
         * @param DOMElement $oNode
         * @param array $aClasses
@@ -80,7 +80,7 @@
        public static function addClassesRecursive( $oNode, $aClasses, 
$bOverrideExisting = false ) {
                $sNodesClasses = $oNode->getAttribute('class');
                $aNodesClasses = explode( ' ', $sNodesClasses );
-               $oNode->setAttribute( 
+               $oNode->setAttribute(
                        'class',
                        implode( ' ', array_unique( array_merge( 
$aNodesClasses, $aClasses ) ) )
                );
@@ -91,9 +91,9 @@
                        static::addClassesRecursive($oChild, $aClasses, 
$bOverrideExisting);
                }
        }
-       
+
        /**
-        * 
+        * Inserts a DOMNode after another DOMNode in the DOM tree
         * @param DOMNode $oNode
         * @param DOMNode $oRefNode
         */
@@ -105,4 +105,69 @@
                        $oRefNode->parentNode->appendChild($oNode);
                }
        }
+
+       /**
+        * HINT: 
http://stackoverflow.com/questions/1604471/how-can-i-find-an-element-by-css-class-with-xpath
+        * @param DOMDocument $oDOMDoc
+        * @param array $aClassNames
+        * @return array of DOMElement
+        */
+       public static function getElementsByClassNames( $oDOMDoc, $aClassNames 
) {
+               $oDOMXPath = new DOMXPath( $oDOMDoc );
+               $aClassQuery = array();
+               foreach( $aClassNames as $sClassName ) {
+                       # //*[contains(concat(' ', normalize-space(@class), ' 
'), ' Test ')]
+                       $aClassQuery[] = "contains(concat(' ', 
normalize-space(@class), ' '), ' $sClassName ')";
+               }
+               $sQuery = '//*['.implode( ' or ', $aClassQuery ).']';
+               $oElements = $oDOMXPath->query( $sQuery );
+
+               $aElements = array();
+               foreach( $oElements as $oElement ) {
+                       $aElements[] = $oElement;
+               }
+
+               return $aElements;
+       }
+
+       /**
+        * Returns an array of DOMElements of given tag names. The returned 
array
+        * is ordered according to the provided tag name array
+        * @param DOMDocument $oDOMDoc
+        * @param array $aTagnames
+        * @return array of DOMElements Empty array if no tags of the specified
+        * names were found of provided list was no array
+        */
+       public static function getElementsByTagNames( $oDOMDoc, $aTagnames ) {
+               $aElements = array();
+               if( !is_array( $aTagnames ) ) {
+                       return $aElements;
+               }
+               foreach( $aTagnames as $sTagname ) {
+                       $oElements = $oDOMDoc->getElementsByTagName( $sTagname 
);
+                       foreach( $oElements as $oElement ) {
+                               $aElements[] = $oElement;
+                       }
+               }
+               return $aElements;
+       }
+
+       /**
+        * Tries to remove a DOMElement from the DOM tree.
+        * @param DOMElement $oEl
+        * @return boolean true on success, false if the operation could not be
+        * performed
+        */
+       public static function removeElement($oEl) {
+               if( !is_object( $oEl ) ) {
+                       return false;
+               }
+               $oParent = $oEl->parentNode;
+               if( $oParent instanceof DOMNode === false ) {
+                       return false;
+               }
+               $oParent->removeChild( $oEl );
+               return true;
+       }
+
 }
diff --git a/maintenance/BSMigrationHelper.php 
b/maintenance/BSMigrationHelper.php
index 3e234d4..2918552 100644
--- a/maintenance/BSMigrationHelper.php
+++ b/maintenance/BSMigrationHelper.php
@@ -152,7 +152,7 @@
 
                        if( $sClass == 'MsoListParagraphCxSpMiddle' ) {
                                $sListItem = str_replace( array("\n", "\r", 
' '), ' ', $oWSElement->nodeValue);
-var_dump( $sListItem );
+
                                $sReplace = '*';
                                $count = 0;
                                //file_put_contents( '/tmp/listitem.txt', 
$sListItem."\n", FILE_APPEND );

-- 
To view, visit https://gerrit.wikimedia.org/r/176635
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ief54324702993538878f4027a42a894f8634bc24
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/BlueSpiceFoundation
Gerrit-Branch: master
Gerrit-Owner: Robert Vogel <[email protected]>
Gerrit-Reviewer: Mglaser <[email protected]>
Gerrit-Reviewer: Pigpen <[email protected]>
Gerrit-Reviewer: Smuggli <[email protected]>
Gerrit-Reviewer: Tweichart <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to