2010 July, 7 (Guerric)

    Table of contents
    No headers
    http://bugs.developer.mindtouch.com/view.php?id=8144
    Index: deki/core/objects/deki_template_properties.php
    ===================================================================
    --- deki/core/objects/deki_template_properties.php    (revision 20371)
    +++ deki/core/objects/deki_template_properties.php    (working copy)
    @@ -5,7 +5,8 @@
     class DekiTemplateProperties extends DekiPageProperties
     {    
         const TYPE_PAGE = 'page';
    -    const TYPE_FUNCTIONAL = 'functional';
    +    const TYPE_DYNAMIC = 'dynamic';
    +    const TYPE_CONTENT = 'content';
     
         // @note kalida: default is a placehold name for forms and comparisons, and not saved
         const TYPE_DEFAULT = 'default';
    @@ -14,9 +15,81 @@
         const PROP_DESCRIPTION = 'description';
         const PROP_SCREENSHOT = 'screenshot';
     
    -    public static $VALID_TYPES = array(self::TYPE_DEFAULT, self::TYPE_PAGE);
    +    public static $VALID_TYPES = array(
    +        self::TYPE_DEFAULT,
    +        self::TYPE_PAGE,
    +        self::TYPE_CONTENT
    +    );
        
    +    
         /**
    +     * Find all template pages of a given type (uses property search)
    +     * @note kalida: currently, new pages without types will not be returned
    +     *
    +     * @param array &$templates - reference to an array of verbose page xml arrays
    +     * @param string $type - type of page to filter on
    +     * @return DekiResult $Result
    +     */
    +    public static function getTemplateXml(&$templates, $type, $language = null)
    +    {
    +        $templates = array();
    +    
    +        // find templates marked with the following type
    +        $query = self::NS_TEMPLATE . self::PROP_TYPE . ':"' . $type . '"';
    +        
    +        $constraint = array(
    +            // only search the template namespace
    +            'namespace:template',
    +            // include all neutral pages by default
    +            'language:neutral'
    +        );
    +        
    +        if (!is_null($language))
    +        {
    +            // if en-us, allow both en and en-us
    +            $constraint[] = 'language:' . $language;
    +        
    +            if (strpos($language, '-') > 0)
    +            {
    +                $data = explode('-', $language);
    +                $lang = $data[0];
    +                $constraint[] = 'language:' . $lang;
    +            }
    +        }
    +        
    +        $Plug = DekiPlug::getInstance()
    +            ->At('site', 'search')
    +            ->With('q', $query)
    +            ->With('constraint', implode(' ', $constraint))
    +            ->With('parser', 'lucene');
    +        $Result = $Plug->Get();
    +        
    +        $templates = $Result->getAll('body/search/page', array());
    +        if (!$Result->isSuccess() || empty($templates))
    +        {
    +            return $Result;
    +        }
    +        
    +        // sort templates by title
    +        $pageXml = array();
    +        $pageTitles = array();
    +        foreach ($templates as &$page)
    +        {
    +            $title = trim($page['title']);
    +            
    +            $pageXml[] = $page;
    +            $pageTitles[] = strtolower($title);
    +        }
    +        unset($page);
    +        
    +        // usort copies the large page objects; sort by the smaller pageTitles[]
    +        array_multisort($pageTitles, SORT_ASC, $pageXml);
    +        $templates = $pageXml;
    +        
    +        return $Result;
    +    }
    +    
    +    /**
          * Create new DekiTemplateProperties from page api results
          * @param array $result
          * @return DekiTemplateProperties
    @@ -96,20 +169,18 @@
          */
         public function setType($type)
         {
    -        if (in_array($type, self::$VALID_TYPES))
    +        if (!in_array($type, self::$VALID_TYPES))
             {
    -            if ($type == self::TYPE_DEFAULT)
    -            {
    -                $this->remove(self::PROP_TYPE, self::NS_TEMPLATE);
    -            }
    -            else
    -            {
    -                $this->set(self::PROP_TYPE, $type, self::NS_TEMPLATE);    
    -            }
    +            throw new Exception("Attempted to set template to an invalid type.");
             }
    +        
    +        if ($type == self::TYPE_DEFAULT)
    +        {
    +            $this->remove(self::PROP_TYPE, self::NS_TEMPLATE);
    +        }
             else
             {
    -            throw new Exception("Attempted to set template to an invalid type.");
    +            $this->set(self::PROP_TYPE, $type, self::NS_TEMPLATE);
             }
         }
     
    Index: deki/gui/templates.php
    ===================================================================
    --- deki/gui/templates.php    (revision 20371)
    +++ deki/gui/templates.php    (working copy)
    @@ -12,7 +12,7 @@
         {
             $this->Request = DekiRequest::getInstance();
     
    -        $action = $this->Request->getVal( 'action' );
    +        $action = $this->Request->getVal('action');
            
             $result = '';
            
    @@ -21,6 +21,13 @@
                 case 'getcontent':
                     $result = $this->getContent();
                     break;
    +            
    +            case 'getitems':
    +                $result = $this->getItems();
    +                echo json_encode($result);
    +                exit();
    +                break;
    +            
                 default:
                     header('HTTP/1.0 404 Not Found');
                     exit(' '); // flush the headers
    @@ -28,8 +35,8 @@
            
             echo $result;
         }
    -
    -    private function getContent()
    +        
    +    protected function getContent()
         {
             $templateId = $this->Request->getVal('templateId');
             $pageId = $this->Request->getVal('pageId');
    @@ -54,6 +61,69 @@
     
             return $Article->mContent;
         }
    +    
    +    /**
    +     * Generate the items list
    +     * @return string
    +     */
    +    protected function getItems()
    +    {
    +        $pageId = $this->Request->getVal('pageId');
    +        $items = '';
    +
    +        $Result = DekiPlug::getInstance()->At('pages', $pageId, 'tree')->Get();
    +        if ($Result->isSuccess())
    +        {
    +            $page = $Result->getVal('body/pages/page');
    +            // convert to items string
    +            $key = $this->buildTemplateListItem($page);
    +            $keys = explode('|', $key);
    +            $name = array_shift($keys);
    +            $isSite = array_shift($keys);
    +            $items = implode('|', $keys);
    +        }
    +        
    +        return array(
    +            'items' => $items
    +        );
    +    }
    +    
    +    /**
    +     * Builds the ridiculous key required for the template dialog
    +     * @note copied from /skins/common/popups/select_template.php
    +     * @param string $key
    +     */
    +    private function buildTemplateListItem($page, $key = '')
    +    {
    +        $Page = new XArray($page);
    +        $href = $Page->getVal('subpages/@href', null);
    +        $subpages = $Page->getAll('subpages/page', array());
    +        if (empty($key))
    +        {
    +            $key = $Page->getVal('@id') . '|';
    +            if (empty($subpages))
    +            {
    +                $key .= is_null($href) ? '0|' : '2';
    +            }
    +            else
    +            {
    +                $key .= '1';
    +            }
    +        }
    +        
    +        foreach ($subpages as &$subpage)
    +        {
    +            $Info = DekiPageInfo::newFromArray($subpage);
    +            
    +            $paths = $Info->getParents();
    +            $templatePath = implode(HPS_SEPARATOR, $paths);
    +            
    +            $key .= '|' . $templatePath;
    +            $key = $this->buildTemplateListItem($subpage, $key);
    +        }
    +        
    +        return $key;
    +    }
     }
     
     new TemplatesFormatter();
    Index: deki/plugins/page_template_selector/page_template_selector.php
    ===================================================================
    --- deki/plugins/page_template_selector/page_template_selector.php    (revision 20371)
    +++ deki/plugins/page_template_selector/page_template_selector.php    (working copy)
    @@ -42,8 +42,9 @@
        
         /**
          * Attaches javascript handler for new page
    +     *
          * @param $Template
    -     * @return N/A
    +     * @return
          */
         public static function renderSkinHook(&$Template)
         {
    @@ -91,6 +92,7 @@
     
         /**
          * Create content for special page
    +     *
          * @param string $pageName - incoming page name
          * @param string $pageTitle - page title to set
          * @param string $html - html to output
    @@ -129,8 +131,12 @@
             $blankIcon = $wgDekiPluginPath . '/' . self::PLUGIN_FOLDER . '/icons/page-blank.png';
             $defaultTemplate = self::renderPageTemplateItem($baseuri, wfMsg('Page.PageTemplateSelector.page.blank'), '', $blankIcon);
             $View->set('templates.default', $defaultTemplate);
    -
    -        $pages = self::searchTemplatePages(DekiTemplateProperties::TYPE_PAGE, wfLanguageActive());
    +        
    +        $pages = array();
    +        $Result = DekiTemplateProperties::getTemplateXml($pages, DekiTemplateProperties::TYPE_PAGE, wfLanguageActive());
    +        // bubble any errors
    +        $Result->handleResponse();
    +        
             $renderedTemplates = array();
     
             foreach ($pages as $page)
    @@ -157,82 +163,10 @@
            
             $html .= $View->render();
         }
    -        
    -    /**
    -     * Find all template pages of a given type (uses property search)
    -     * @note kalida: currently, new pages without types will not be returned
    -     * @param string $type - type of page to filter on
    -     * @return array $pages - result of api call
    -     */
    -    public static function searchTemplatePages($type, $language = null)
    -    {
    -        $pages = array();
    -
    -        $propertyQuery = DekiProperties::NS_TEMPLATE . DekiTemplateProperties::PROP_TYPE;
    -        $query = 'property:' . '"' . $propertyQuery . '"';
    -
    -        // include all neutral pages by default
    -        $constraint = 'language:neutral';
    -
    -        if (!is_null($language))
    -        {
    -            // if en-us, allow both en and en-us
    -            $constraint .= ' language:' . $language;
    -
    -            if (strpos($language, '-') > 0)
    -            {
    -                $data = explode('-', $language);
    -                $lang = $data[0];
    -                $constraint .= ' language:' . $lang;
    -            }
    -        }
    -
    -        $Plug = DekiPlug::getInstance()->At('site', 'search')->With('q', $query);
    -        $Plug = $Plug->With('constraint', $constraint)->With('parser', 'lucene');
    -        $Result = $Plug->Get();
    -
    -        if (!$Result->handleResponse())
    -        {
    -            return $pages;
    -        }
    -
    -        $searchResults = $Result->getAll('body/search/page', array());
    -        
    -        if (empty($searchResults))
    -        {
    -            return $pages;
    -        }
    -
    -        $pages = &$searchResults;
    -        
    -        // filter by type
    -        $type = strtolower(trim($type));
    -        $matchedTypes = array();
    -        $pageTitles = array();
    -
    -        foreach ($pages as $page)
    -        {
    -            $Properties = DekiTemplateProperties::newFromArray($page);
    -            $page_type = $Properties->getType();
    -            
    -            if (strcasecmp($page_type, $type) == 0)
    -            {
    -                $PageInfo = DekiPageInfo::newFromArray($page);
    -                
    -                $matchedTypes[] = $page;
    -                $pageTitles[] = strtolower(trim($PageInfo->title));
    -            }
    -        }
    -
    -        // usort copies the large page objects; sort by the smaller pageTitles[]
    -        array_multisort($pageTitles, SORT_ASC, $matchedTypes);
    -        $pages = &$matchedTypes;
    -
    -        return $pages;
    -    }
        
         /**
          * Create html for a single page template item
    +     *
          * @param $uri - uri to create item
          * @param $title - display title
          * @param $description - display description
    Index: deki/plugins/special_page/special_listtemplates/special_listtemplates.css
    ===================================================================
    --- deki/plugins/special_page/special_listtemplates/special_listtemplates.css    (revision 20371)
    +++ deki/plugins/special_page/special_listtemplates/special_listtemplates.css    (working copy)
    @@ -19,8 +19,12 @@
         border-collapse: collapse;
         border-spacing: 0;
     }
    -
     #SpecialListTemplates td {
    +    vertical-align: middle;
    +    white-space: nowrap;
    +}
    +#SpecialListTemplates td.col1 {
    +    white-space: normal;
         margin: 3px 0px 0px 0px;
         padding: 3px 0px 3px 10px;
         border-top: 1px solid #efefef;
    @@ -30,26 +34,19 @@
         background: #ffffee;
     }
     
    -#SpecialListTemplates td a {
    -    position: relative;
    -    top: 2px;
    -}
    -
     #SpecialListTemplates td.col2,
     #SpecialListTemplates td.col3 {
    -    width: 30px;
    +    width: 60px;
    +    text-align: center;
     }
     
     #SpecialListTemplates td.col4 {
         width: 80px;
    -    white-space: nowrap;
         font-size: 10px;
         text-align: center;
    -    padding: 0px 10px 0px 10px;
     }
     
     /* Popup styles */
    -
     .deki-template-url {
         padding: 3px 0px 0px 3px;
         width: 90%;
    Index: deki/plugins/special_page/special_listtemplates/special_listtemplates.php
    ===================================================================
    --- deki/plugins/special_page/special_listtemplates/special_listtemplates.php    (revision 20371)
    +++ deki/plugins/special_page/special_listtemplates/special_listtemplates.php    (working copy)
    @@ -30,7 +30,8 @@
         // template choices; first is default in dropdown
         private static $VALID_TYPES = array(
             DekiTemplateProperties::TYPE_DEFAULT,
    -        DekiTemplateProperties::TYPE_PAGE
    +        DekiTemplateProperties::TYPE_PAGE,
    +        DekiTemplateProperties::TYPE_CONTENT
         );
        
         const SPECIAL_EDIT_TEMPLATE = 'Special:EditTemplate';
    Index: resources/resources.txt
    ===================================================================
    --- resources/resources.txt    (revision 20371)
    +++ resources/resources.txt    (working copy)
    @@ -1479,10 +1479,12 @@
         label.type=Template type
         label.properties.edit=Update template properties
         error.page=Could not load the requested page
    -    type.page=Page
    -    type.page.help=Used for new page layouts
         type.default=Default
         type.default.help=General purpose template
    +    type.page=New Page
    +    type.page.help=Used for new page layouts
    +    type.content=Content
    +    type.content.help=Snippets to insert across pages
     
     [Page.ListUsers]
         header-contributions=Contributions
    Index: skins/common/popups/select_template.php
    ===================================================================
    --- skins/common/popups/select_template.php    (revision 20371)
    +++ skins/common/popups/select_template.php    (working copy)
    @@ -23,10 +23,10 @@
      * http://www.gnu.org/copyleft/gpl.html
      */
     
    -define( 'MINDTOUCH_DEKI', true );
    -require_once( '../../../includes/Defines.php' );
    -require_once( '../../../LocalSettings.php' );
    -require_once( '../../../includes/Setup.php' );
    +define('MINDTOUCH_DEKI', true);
    +require_once('../../../includes/Defines.php');
    +require_once('../../../LocalSettings.php');
    +require_once('../../../includes/Setup.php');
     
     $_templates = wfGetTemplatesList();
     if (is_array($_templates) && count($_templates) > 0) {
    @@ -35,10 +35,23 @@
             $items = explode("|",$key);
             $name = array_shift($items);
             $isSite = array_shift($items);
    -        if ($isSite) {
    -            $text = '+'.$text;
    -            $items = ' items="' . str_replace('"','""',implode("|",$items)) . '"';
    -        } else $items = '';
    +        switch ($isSite)
    +        {
    +            default:
    +            case 0:
    +                $items = '';
    +                break;
    +            case 1:
    +                $text = '+'.$text;
    +                $items = ' items="' . str_replace('"','""',implode("|",$items)) . '"';
    +                break;
    +            case 2:
    +                // support lazy loading the template tree
    +                $text = '+'.$text;
    +                $items = ' items="gui"';
    +                break;
    +        }
    +
             $select .= '<option class="'.($isSite ? 'tmplt_site' : 'tmplt_cntnt').'" value="'.$name.'"'.$items.'>'.$text.'</option>';
         }
         $select .= '</select>';
    @@ -56,6 +69,7 @@
     <title><?php echo wfMsg('Dialog.Templates.page-title') ?></title>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
     <script type="text/javascript" src="popup.js"></script>
    +<script type="text/javascript" src="/skins/common/jquery/jquery.min.js"></script>
     <link rel="stylesheet" type="text/css" href="css/styles.css">
     <script type="text/javascript">
           //<![CDATA[
    @@ -102,6 +116,21 @@
                 if (cls == "tmplt_site")
                 {
                     var items = selectedOption.attributes['items'].value;
    +                if (items == "gui") {
    +                    // load the items
    +                    $.ajax({
    +                        url: '/deki/gui/templates.php',
    +                        data: {
    +                            action: "getitems",
    +                            pageId: selectedValue
    +                        },
    +                        async: false,
    +                        success: function(data) {
    +                            items = data.items;
    +                        }    
    +                    });
    +                }
    +                
                     items = items.replace(new RegExp("//","g"),'%2F%2F');
                     items = items.replace(/ /g,'_');
                     items = items.split("|");
    @@ -246,20 +275,28 @@
     function wfBuildTemplateListItem($page, $key = '')
     {
         $Page = new XArray($page);
    +    $href = $Page->getVal('subpages/@href', null);
         $subpages = $Page->getAll('subpages/page', array());
    -
         if (empty($key))
         {
             $key = $Page->getVal('@id') . '|';
    -        $key .= (empty($subpages) ? '0|' : '1');
    +        if (empty($subpages))
    +        {
    +            $key .= is_null($href) ? '0|' : '2';
    +        }
    +        else
    +        {
    +            $key .= '1';
    +        }
         }
        
         foreach ($subpages as &$subpage)
         {
    -        $paths = Article::getParentsFromName($subpage['path']);
    -        array_shift($paths);
    +        $Info = DekiPageInfo::newFromArray($subpage);
    +        
    +        $paths = $Info->getParents();
             $templatePath = implode(HPS_SEPARATOR, $paths);
    -
    +        
             $key .= '|' . $templatePath;
             $key = wfBuildTemplateListItem($subpage, $key);
         }
    @@ -267,12 +304,24 @@
         return $key;
     }
     
    +/**
    + * Retrieve the list of content templates
    + * @TODO: refactor template listing code path to be more efficient
    + * @return array
    + */
     function wfGetTemplatesList()
     {
    -    $Plug = DekiPlug::getInstance();
    -    $Result = $Plug->At('pages', '=Template:', 'tree')->Get();
    -    $pages = $Result->getAll('body/pages/page/subpages/page');
    -
    +    // attempt to load content templates
    +    $pages = array();
    +    $Result = DekiTemplateProperties::getTemplateXml($pages, DekiTemplateProperties::TYPE_CONTENT);
    +    if (empty($pages))
    +    {
    +        // no content template located, backwards compat mode    
    +        $Plug = DekiPlug::getInstance();
    +        $Result = $Plug->At('pages', '=Template:', 'tree')->Get();
    +        $pages = $Result->getAll('body/pages/page/subpages/page');
    +    }
    +    
         $return = array();
         if (!empty($pages))
         {
    Tag page
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by