Paladox has uploaded a new change for review. https://gerrit.wikimedia.org/r/318118
Change subject: Remove duplicate class ...................................................................... Remove duplicate class Change-Id: I92065b54b38585e791865f74a2609c13f42b4021 --- M includes/forminputs/PF_TreeInput.php 1 file changed, 0 insertions(+), 116 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageForms refs/changes/18/318118/1 diff --git a/includes/forminputs/PF_TreeInput.php b/includes/forminputs/PF_TreeInput.php index 5fcc7a3..f1bd258 100644 --- a/includes/forminputs/PF_TreeInput.php +++ b/includes/forminputs/PF_TreeInput.php @@ -273,119 +273,3 @@ } } - -/** - * A class that defines a tree - and can populate it based on either - * wikitext or a category structure. - * - * @author Yaron Koren - */ -class PFTree { - var $title, $children; - - function __construct( $curTitle ) { - $this->title = $curTitle; - $this->children = array(); - } - - function addChild( $child ) { - $this->children[] = $child; - } - - /** - * Turn a manually-created "structure", defined as a bulleted list - * in wikitext, into a tree. This is based on the concept originated - * by the "menuselect" input type in the Semantic Forms Inputs - * extension - the difference here is that the text is manually - * parsed, instead of being run through the MediaWiki parser. - */ - public static function newFromWikiText( $wikitext ) { - // The top node, called "Top", will be ignored, because - // we'll set "hideroot" to true. - $fullTree = new PFTree( 'Top' ); - $lines = explode( "\n", $wikitext ); - foreach ( $lines as $line ) { - $numBullets = 0; - for ( $i = 0; $i < strlen( $line ) && $line[$i] == '*'; $i++ ) { - $numBullets++; - } - if ( $numBullets == 0 ) continue; - $lineText = trim( substr( $line, $numBullets ) ); - $curParentNode = $fullTree->getLastNodeForLevel( $numBullets ); - $curParentNode->addChild( new PFTree( $lineText ) ); - } - return $fullTree; - } - - function getLastNodeForLevel( $level ) { - if ( $level <= 1 || count( $this->children ) == 0 ) { - return $this; - } - $lastNodeOnCurLevel = end( $this->children ); - return $lastNodeOnCurLevel->getLastNodeForLevel( $level - 1 ); - } - - /** - * @param $top_category String - * @return mixed - */ - static function newFromTopCategory( $top_category ) { - $pfTree = new PFTree( $top_category ); - $defaultDepth = 20; - $pfTree->populateChildren( $defaultDepth ); - return $pfTree; - } - - /** - * Recursive function to populate a tree based on category information. - */ - private function populateChildren( $depth ) { - if ( $depth == 0 ) return; - $subcats = self::getSubcategories( $this->title ); - foreach( $subcats as $subcat ) { - $childTree = new PFTree( $subcat ); - $childTree->populateChildren( $depth - 1 ); - $this->addChild( $childTree ); - } - } - - /** - * Gets all the subcategories of the passed-in category. - * - * @TODO This might not belong in this class. - * - * @param Title $title - * @return array - */ - private static function getSubcategories( $categoryName ) { - $dbr = wfGetDb( DB_SLAVE ); - - $tables = array( 'page', 'categorylinks' ); - $fields = array( 'page_id', 'page_namespace', 'page_title', - 'page_is_redirect', 'page_len', 'page_latest', 'cl_to', - 'cl_from' ); - $where = array(); - $joins = array(); - $options = array( 'ORDER BY' => 'cl_type, cl_sortkey' ); - - $joins['categorylinks'] = array( 'JOIN', 'cl_from = page_id' ); - $where['cl_to'] = str_replace( ' ', '_', $categoryName ); - $options['USE INDEX']['categorylinks'] = 'cl_sortkey'; - - $tables = array_merge( $tables, array( 'category' ) ); - $fields = array_merge( $fields, array( 'cat_id', 'cat_title', 'cat_subcats', 'cat_pages', 'cat_files' ) ); - $joins['category'] = array( 'LEFT JOIN', array( 'cat_title = page_title', 'page_namespace' => NS_CATEGORY ) ); - - $res = $dbr->select( $tables, $fields, $where, __METHOD__, $options, $joins ); - $subcats = array(); - - foreach ( $res as $row ) { - $t = Title::newFromRow( $row ); - if ( $t->getNamespace() == NS_CATEGORY ) { - $subcats[] = $t->getText(); - } - } - return $subcats; - } - -} -- To view, visit https://gerrit.wikimedia.org/r/318118 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I92065b54b38585e791865f74a2609c13f42b4021 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/PageForms Gerrit-Branch: master Gerrit-Owner: Paladox <thomasmulhall...@yahoo.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits