Development

Changeset 8377

You must first sign up to be able to contribute.

Changeset 8377

Show
Ignore:
Timestamp:
04/09/08 22:52:36 (6 months ago)
Author:
naholyr
Message:

[nahoWikiPlugin] refactoring to ease extensibility

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/nahoWikiPlugin/trunk/lib/helper/nahoWikiHelper.php

    r7063 r8377  
    1111function link_to_diff($text, $page_name, $rev1, $rev2, $mode = 'inline') 
    1212{ 
    13   return link_to($text, 'nahoWiki/diff?page=' . $page_name . '&oldRevision=' . $rev1 . '&revision=' . $rev2 . '&mode=' . $mode); 
     13  $url = nahoWikiPagePeer::url($page_name); 
     14   
     15  return link_to($text, $url . '&oldRevision=' . $rev1 . '&revision=' . $rev2 . '&mode=' . $mode); 
    1416} 
    1517 
     
    2527function link_to_raw_diff($text, $page_name, $rev1, $rev2, $mode = 'unified') 
    2628{ 
    27   return link_to($text, 'nahoWiki/diff?page=' . $page_name . '&oldRevision=' . $rev1 . '&revision=' . $rev2 . '&mode=' . $mode . '&raw=1'); 
     29  $url = nahoWikiPagePeer::url($page_name); 
     30   
     31  return link_to($text, $url . '&oldRevision=' . $rev1 . '&revision=' . $rev2 . '&mode=' . $mode . '&raw=1'); 
    2832} 
    2933 
     
    3943function url_for_wiki($page_name, $revision = null, $absolute = false) 
    4044{ 
    41   $url = 'nahoWiki/view?page=' . $page_name
     45  $url = nahoWikiPagePeer::url($page_name)
    4246  if (!is_null($revision)) { 
    4347    $url .= '&revision=' . $revision; 
     
    5862function link_to_wiki($text, $page_name, $options = array()) 
    5963{ 
    60   $url = 'nahoWiki/view?page=' . $page_name
     64  $url = nahoWikiPagePeer::url($page_name)
    6165  if (isset($options['revision'])) { 
    6266    $url .= '&revision=' . $options['revision']; 
     
    145149  $options['pagename'] = $page_name; 
    146150  $options['revision'] = $revision; 
     151   
    147152  include_component('nahoWiki', 'content', $options); 
    148153} 
     
    163168  $options['pagename'] = $page_name; 
    164169  $options['revision'] = $revision; 
     170   
    165171  return get_component('nahoWiki', 'content', $options); 
    166172} 
  • plugins/nahoWikiPlugin/trunk/lib/model/plugin/PluginnahoWikiContentPeer.php

    r7062 r8377  
    1111{ 
    1212   
     13  /** 
     14   * Converts Wiki syntax 
     15   * 
     16   * @param string $content 
     17   * @return string 
     18   */ 
    1319  public static function doConvert($content) 
    1420  { 
     
    2026  } 
    2127   
     28  /** 
     29   * Makes replacements based on an array of replaces : 
     30   * key = PCRE mask 
     31   * value = replacement (string or array for callback) 
     32   * 
     33   * @param array $replaces 
     34   * @param string $content 
     35   * @return string 
     36   */ 
    2237  public static function makeReplacements($replaces, $content) 
    2338  { 
     
    3348  } 
    3449   
     50  /** 
     51   * Applies pre-conversion modifications 
     52   * 
     53   * @param nahoWikiPage $page 
     54   * @param string $content 
     55   * @return string 
     56   */ 
    3557  public static function preConvert($page, $content) 
    3658  { 
     
    4567  } 
    4668   
     69  /** 
     70   * Applies post-conversion modifications 
     71   * 
     72   * @param nahoWikiPage $page 
     73   * @param string $html 
     74   * @return string 
     75   */ 
    4776  public static function postConvert($page, $html) 
    4877  { 
     
    5281    $replaces[] = array( 
    5382      'from' => '/<(h[1-6])( .*+)?>(.*?)<\/\1>/i', 
    54       'to'   => array('self', 'callbackNameTitle') 
     83      'to'   => array('nahoWikiContentPeer', 'callbackNameTitle') 
    5584    ); 
    5685     
     
    6493    } 
    6594     
    66     return self::makeReplacements($replaces, $html); 
    67   } 
    68    
     95    return nahoWikiContentPeer::makeReplacements($replaces, $html); 
     96  } 
     97   
     98  /** 
     99   * Extracts the link replacements to be done in content 
     100   * 
     101   * @param string $content 
     102   * @param array $masks 
     103   * @param array $pcre_masks 
     104   * @return unknown 
     105   */ 
    69106  protected static function extractLinkReplacements($content, $masks, $pcre_masks) 
    70107  { 
     
    104141  } 
    105142   
     143  /** 
     144   * Makes the link replacements, based on the replaces extracted 
     145   *  
     146   * @see self::convertInternalLinks 
     147   * 
     148   * @param string    $content 
     149   * @param array     $replaces 
     150   * @param string    $link_model 
     151   * @param array     $existing_page hash with key = an existing page 
     152   * @param string    $broken_link_model 
     153   * @return string 
     154   */ 
    106155  protected static function makeLinkReplacements($content, $replaces, $link_model, $existing_page = null, $broken_link_model = null) { 
    107156    // make full-text replacements 
     
    126175  } 
    127176   
     177  /** 
     178   * Enables internal links, based on app_nahoWikiPlugin_internal_* options 
     179   * 
     180   * @param nahoWikiPage $page 
     181   * @param string $content 
     182   * @return string 
     183   */ 
    128184  public static function convertInternalLinks($page, $content) 
    129185  { 
     
    134190    ); 
    135191     
    136     $replaces = self::extractLinkReplacements($content, $masks, $pcre_masks); 
     192    $replaces = nahoWikiContentPeer::extractLinkReplacements($content, $masks, $pcre_masks); 
    137193     
    138194    // Extract names and complete the replacements array 
     
    147203      } 
    148204      // Link 
    149       $url = 'nahoWiki/view?page=' . $replace['name']
     205      $url = nahoWikiPagePeer::url($replace['name'], $page)
    150206      if (@$replace['anchor']) { 
    151207        $url .= '#' . $replace['anchor']; 
     
    166222    $broken_link_model = sfConfig::get('app_nahoWikiPlugin_internal_link_broken_model', '[%title%(?)](%link%)'); 
    167223     
    168     return self::makeLinkReplacements($content, $replaces, $link_model, $existing_page, $broken_link_model); 
    169   } 
    170    
     224    return nahoWikiContentPeer::makeLinkReplacements($content, $replaces, $link_model, $existing_page, $broken_link_model); 
     225  } 
     226   
     227  /** 
     228   * Converts interwiki links, based on app_nahoWikiPlugin_interwiki_* options 
     229   * 
     230   * @param string $content 
     231   * @return string 
     232   */ 
    171233  public static function convertInterwikiLinks($content) 
    172234  { 
     
    177239    ); 
    178240     
    179     $replaces = self::extractLinkReplacements($content, $masks, $pcre_masks); 
     241    $replaces = nahoWikiContentPeer::extractLinkReplacements($content, $masks, $pcre_masks); 
    180242     
    181243    // Complete the replacements array 
     
    209271    $link_model = sfConfig::get('app_nahoWikiPlugin_interwiki_link_model', '[![%alttext%](%image%) %title%](%link%)'); 
    210272     
    211     return self::makeLinkReplacements($content, $replaces, $link_model); 
     273    return nahoWikiContentPeer::makeLinkReplacements($content, $replaces, $link_model); 
    212274  } 
    213275 
    214   public static function titleToID($title) 
     276  /** 
     277   * Returns an ID based on the title (cleans the string) 
     278   * 
     279   * @param string $title 
     280   * @return string 
     281   */ 
     282  protected static function titleToID($title) 
    215283  { 
    216284    if (function_exists('mb_detect_encoding') && function_exists('mb_convert_encoding')) { 
     
    231299  } 
    232300   
    233   public static function callbackNameTitle($matches) 
     301  /** 
     302   * Used as a callback to insert IDs in titles  
     303   * 
     304   * @param array $matches 
     305   * @return string 
     306   */ 
     307  protected static function callbackNameTitle($matches) 
    234308  { 
    235309    $title = $matches[3]; 
    236     $id = self::titleToID($title); 
     310    $id = nahoWikiContentPeer::titleToID($title); 
    237311     
    238312    return '<'. $matches[1] . $matches[2] . ' id="' . htmlentities($id) . '">' . $title . '</' . $matches[1] . '>'; 
    239313  } 
    240314   
    241   public static function addToTOC(&$toc, $title, $deepness = 1) 
     315  /** 
     316   * Add an item to the table of contents 
     317   * 
     318   * @param array     $toc 
     319   * @param string    $title 
     320   * @param int       $deepness 
     321   */ 
     322  protected static function addToTOC(&$toc, $title, $deepness = 1) 
    242323  { 
    243324    if ($deepness > 1) { 
     
    248329        $i = $n - 1; 
    249330      } 
    250       self::addToTOC($toc[$i]['subtitles'], $title, $deepness - 1); 
     331      nahoWikiContentPeer::addToTOC($toc[$i]['subtitles'], $title, $deepness - 1); 
    251332    } else { 
    252       $toc[] = array('title' => $title, 'id' => self::titleToID($title), 'subtitles' => array()); 
    253     } 
    254   } 
    255    
     333      $toc[] = array('title' => $title, 'id' => nahoWikiContentPeer::titleToID($title), 'subtitles' => array()); 
     334    } 
     335  } 
     336 
     337  /** 
     338   * Returns table of contents from HTML, based on <H*> tags 
     339   * Format is : 
     340   * title     => title of the content 
     341   * id        => anchor to the title 
     342   * subtitles => sub-TOC 
     343   * 
     344   * @param string    $html 
     345   * @return array 
     346   */ 
    256347  public static function getTOC($html) 
    257348  { 
     
    259350    preg_match_all('/<h([1-6]).*?>(.*?)<\/h\1>/i', $html, $matches, PREG_SET_ORDER); 
    260351    foreach ($matches as $match) { 
    261       self::addToTOC($toc, $match[2], intval($match[1])); 
     352      nahoWikiContentPeer::addToTOC($toc, $match[2], intval($match[1])); 
    262353    } 
    263354     
  • plugins/nahoWikiPlugin/trunk/lib/model/plugin/PluginnahoWikiPage.php

    r7057 r8377  
    1010class PluginnahoWikiPage extends BasenahoWikiPage 
    1111{ 
    12    
     12 
     13  /** 
     14   * Returns name (lower case) 
     15   * 
     16   * @return string 
     17   */ 
    1318  public function getName() 
    1419  { 
     
    1621  } 
    1722   
     23  /** 
     24   * Defines name (lower case) 
     25   * 
     26   * @param string $name 
     27   */ 
    1828  public function setName($name) 
    1929  { 
     
    2131  } 
    2232   
     33  /** 
     34   * Returns namespace of the page 
     35   * 
     36   * @return string 
     37   */ 
    2338  public function getNamespace() 
    2439  { 
     
    2641  } 
    2742   
    28   public function getBasename($page_name = null) 
     43  /** 
     44   * Returns basename of the page 
     45   * 
     46   * @return string 
     47   */ 
     48  public function getBasename() 
    2949  { 
    3050    return nahoWikiPagePeer::getBasename($this->getName()); 
    3151  } 
    3252   
     53  /** 
     54   * Transforms relative pagename to absolute 
     55   * 
     56   * @param string $page_name (default is current page_name) 
     57   * @return string 
     58   */ 
    3359  public function resolveAbsoluteName($page_name = null) 
    3460  { 
     
    6692  } 
    6793   
     94  /** 
     95   * Current revision 
     96   * 
     97   * @param int $revision 
     98   * @return nahoWikiRevision 
     99   */ 
    68100  public function getRevision($revision = null) 
    69101  { 
     
    81113  } 
    82114   
     115  /** 
     116   * Get all available revisions 
     117   * 
     118   * @param Criteria $criteria 
     119   * @return array 
     120   */ 
    83121  public function getRevisions($criteria= null) 
    84122  { 
     
    106144  } 
    107145   
    108   // @todo implement real rights management here 
     146  /** 
     147   * @todo implement real rights management here 
     148   * 
     149   * @param myUser $user 
     150   * @return boolean 
     151   */ 
    109152  public function canView($user) 
    110153  { 
     
    112155  } 
    113156   
    114   // @todo implement real rights management here 
     157  /** 
     158   * @todo implement real rights management here 
     159   * 
     160   * @param myUser $user 
     161   * @return boolean 
     162   */ 
    115163  public function canEdit($user) 
    116164  { 
  • plugins/nahoWikiPlugin/trunk/lib/model/plugin/PluginnahoWikiPagePeer.php

    r7057 r8377  
    1111{ 
    1212   
     13  /** 
     14   * Returns the URL to page named $page_name (from $page) 
     15   * 
     16   * @param string        $page_name 
     17   * @param nahoWikiPage  $page 
     18   * @return string 
     19   */ 
     20  public static function url($page_name, $page = null) 
     21  { 
     22    return 'nahoWiki/view?page=' . $page_name; 
     23  } 
     24   
     25  /** 
     26   * Returns the PCRE mask that validates page names 
     27   * 
     28   * @param boolean $full allows NS separator and dot in the mask ? 
     29   * @return string 
     30   */ 
    1331  public static function pageNameFormat($full = true) 
    1432  { 
     
    2442  } 
    2543   
     44  /** 
     45   * Gets basename from full pagename 
     46   * 
     47   * @param string $page_name 
     48   * @return string 
     49   */ 
    2650  public static function getBasename($page_name) 
    2751  { 
     
    3155    return array_pop($parts); 
    3256  } 
     57   
     58  /** 
     59   * Gets namespace from full pagename 
     60   * 
     61   * @param string $page_name 
     62   * @return string 
     63   */ 
    3364   
    3465  public static function getNamespace($page_name) 
     
    4172  } 
    4273   
     74  /** 
     75   * Retrieve a page from its name 
     76   * 
     77   * @param string $name 
     78   * @return nahoWikiPage 
     79   */ 
     80   
    4381  public static function retrieveByName($name) 
    4482  { 
     
    4987  } 
    5088   
     89  /** 
     90   * Retrieve pages from their names 
     91   * 
     92   * @param array $names 
     93   * @return array 
     94   */ 
     95   
    5196  public static function retrieveByNames($names) 
    5297  { 
     
    56101    return self::doSelect($c); 
    57102  } 
     103   
     104  /** 
     105   * Retrieve a page from its name 
     106   * 
     107   * @param string $name 
     108   * @return nahoWikiPage 
     109   */ 
    58110   
    59111  public static function retrieveByNameJoinAll($name) 
     
    68120  } 
    69121   
     122  /** 
     123   * Retrieve pages from their names 
     124   * 
     125   * @param array $names 
     126   * @return array 
     127   */ 
     128   
    70129  public static function retrieveByNamesJoinAll($names) 
    71130  { 
     
    76135  } 
    77136   
     137   
    78138} 
  • plugins/nahoWikiPlugin/trunk/lib/model/plugin/PluginnahoWikiRevision.php

    r7057 r8377  
    4545  } 
    4646   
     47  /** 
     48   * Initializes username from context 
     49   * 
     50   */ 
    4751  public function initUserName() 
    4852  { 
     
    5559  } 
    5660   
     61  /** 
     62   * Is current revision the latest for its page ? 
     63   * 
     64   * @return boolean 
     65   */ 
    5766  public function isLatest() 
    5867  { 
     
    6069  } 
    6170   
     71  /** 
     72   * Returns the attached page 
     73   * 
     74   * @return nahoWikiPage 
     75   */ 
     76   
    6277  public function getPage() 
    6378  { 
    6479    return $this->getnahoWikiPage(); 
    6580  } 
     81   
     82  /** 
     83   * Gets content 
     84   * 
     85   * @return string 
     86   */ 
    6687   
    6788  public function getContent() 
     
    87108  } 
    88109   
     110  /** 
     111   * Gets converted content 
     112   * 
     113   * @return string 
     114   */ 
     115   
    89116  public function getXHTMLContent() 
    90117  { 
     
    97124  } 
    98125   
     126  /** 
     127   * Defines content 
     128   * 
     129   * @param string $content 
     130   */ 
     131   
    99132  public function setContent($content) 
    100133  { 
     
    106139    $content_storage->setContent($content); 
    107140     
    108     return $content_storage->save(); 
     141    $content_storage->save(); 
    109142  } 
     143   
     144  /** 
     145   * Compress current content to save space 
     146   * 
     147   * @return boolean 
     148   */ 
    110149   
    111150  public function archiveContent() 
     
    128167  } 
    129168   
     169  /** 
     170   * Uncompress content 
     171   * 
     172   * @return boolean 
     173   */ 
     174   
    130175  public function unarchiveContent() 
    131176  { 
     
    147192  } 
    148193   
     194   
    149195}