Changeset 8377
- Timestamp:
- 04/09/08 22:52:36 (6 months ago)
- Files:
-
- plugins/nahoWikiPlugin/trunk/lib/helper/nahoWikiHelper.php (modified) (6 diffs)
- plugins/nahoWikiPlugin/trunk/lib/model/plugin/PluginnahoWikiContentPeer.php (modified) (16 diffs)
- plugins/nahoWikiPlugin/trunk/lib/model/plugin/PluginnahoWikiPage.php (modified) (8 diffs)
- plugins/nahoWikiPlugin/trunk/lib/model/plugin/PluginnahoWikiPagePeer.php (modified) (8 diffs)
- plugins/nahoWikiPlugin/trunk/lib/model/plugin/PluginnahoWikiRevision.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/nahoWikiPlugin/trunk/lib/helper/nahoWikiHelper.php
r7063 r8377 11 11 function link_to_diff($text, $page_name, $rev1, $rev2, $mode = 'inline') 12 12 { 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); 14 16 } 15 17 … … 25 27 function link_to_raw_diff($text, $page_name, $rev1, $rev2, $mode = 'unified') 26 28 { 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'); 28 32 } 29 33 … … 39 43 function url_for_wiki($page_name, $revision = null, $absolute = false) 40 44 { 41 $url = 'nahoWiki/view?page=' . $page_name;45 $url = nahoWikiPagePeer::url($page_name); 42 46 if (!is_null($revision)) { 43 47 $url .= '&revision=' . $revision; … … 58 62 function link_to_wiki($text, $page_name, $options = array()) 59 63 { 60 $url = 'nahoWiki/view?page=' . $page_name;64 $url = nahoWikiPagePeer::url($page_name); 61 65 if (isset($options['revision'])) { 62 66 $url .= '&revision=' . $options['revision']; … … 145 149 $options['pagename'] = $page_name; 146 150 $options['revision'] = $revision; 151 147 152 include_component('nahoWiki', 'content', $options); 148 153 } … … 163 168 $options['pagename'] = $page_name; 164 169 $options['revision'] = $revision; 170 165 171 return get_component('nahoWiki', 'content', $options); 166 172 } plugins/nahoWikiPlugin/trunk/lib/model/plugin/PluginnahoWikiContentPeer.php
r7062 r8377 11 11 { 12 12 13 /** 14 * Converts Wiki syntax 15 * 16 * @param string $content 17 * @return string 18 */ 13 19 public static function doConvert($content) 14 20 { … … 20 26 } 21 27 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 */ 22 37 public static function makeReplacements($replaces, $content) 23 38 { … … 33 48 } 34 49 50 /** 51 * Applies pre-conversion modifications 52 * 53 * @param nahoWikiPage $page 54 * @param string $content 55 * @return string 56 */ 35 57 public static function preConvert($page, $content) 36 58 { … … 45 67 } 46 68 69 /** 70 * Applies post-conversion modifications 71 * 72 * @param nahoWikiPage $page 73 * @param string $html 74 * @return string 75 */ 47 76 public static function postConvert($page, $html) 48 77 { … … 52 81 $replaces[] = array( 53 82 'from' => '/<(h[1-6])( .*+)?>(.*?)<\/\1>/i', 54 'to' => array(' self', 'callbackNameTitle')83 'to' => array('nahoWikiContentPeer', 'callbackNameTitle') 55 84 ); 56 85 … … 64 93 } 65 94 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 */ 69 106 protected static function extractLinkReplacements($content, $masks, $pcre_masks) 70 107 { … … 104 141 } 105 142 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 */ 106 155 protected static function makeLinkReplacements($content, $replaces, $link_model, $existing_page = null, $broken_link_model = null) { 107 156 // make full-text replacements … … 126 175 } 127 176 177 /** 178 * Enables internal links, based on app_nahoWikiPlugin_internal_* options 179 * 180 * @param nahoWikiPage $page 181 * @param string $content 182 * @return string 183 */ 128 184 public static function convertInternalLinks($page, $content) 129 185 { … … 134 190 ); 135 191 136 $replaces = self::extractLinkReplacements($content, $masks, $pcre_masks);192 $replaces = nahoWikiContentPeer::extractLinkReplacements($content, $masks, $pcre_masks); 137 193 138 194 // Extract names and complete the replacements array … … 147 203 } 148 204 // Link 149 $url = 'nahoWiki/view?page=' . $replace['name'];205 $url = nahoWikiPagePeer::url($replace['name'], $page); 150 206 if (@$replace['anchor']) { 151 207 $url .= '#' . $replace['anchor']; … … 166 222 $broken_link_model = sfConfig::get('app_nahoWikiPlugin_internal_link_broken_model', '[%title%(?)](%link%)'); 167 223 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 */ 171 233 public static function convertInterwikiLinks($content) 172 234 { … … 177 239 ); 178 240 179 $replaces = self::extractLinkReplacements($content, $masks, $pcre_masks);241 $replaces = nahoWikiContentPeer::extractLinkReplacements($content, $masks, $pcre_masks); 180 242 181 243 // Complete the replacements array … … 209 271 $link_model = sfConfig::get('app_nahoWikiPlugin_interwiki_link_model', '[ %title%](%link%)'); 210 272 211 return self::makeLinkReplacements($content, $replaces, $link_model);273 return nahoWikiContentPeer::makeLinkReplacements($content, $replaces, $link_model); 212 274 } 213 275 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) 215 283 { 216 284 if (function_exists('mb_detect_encoding') && function_exists('mb_convert_encoding')) { … … 231 299 } 232 300 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) 234 308 { 235 309 $title = $matches[3]; 236 $id = self::titleToID($title);310 $id = nahoWikiContentPeer::titleToID($title); 237 311 238 312 return '<'. $matches[1] . $matches[2] . ' id="' . htmlentities($id) . '">' . $title . '</' . $matches[1] . '>'; 239 313 } 240 314 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) 242 323 { 243 324 if ($deepness > 1) { … … 248 329 $i = $n - 1; 249 330 } 250 self::addToTOC($toc[$i]['subtitles'], $title, $deepness - 1);331 nahoWikiContentPeer::addToTOC($toc[$i]['subtitles'], $title, $deepness - 1); 251 332 } 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 */ 256 347 public static function getTOC($html) 257 348 { … … 259 350 preg_match_all('/<h([1-6]).*?>(.*?)<\/h\1>/i', $html, $matches, PREG_SET_ORDER); 260 351 foreach ($matches as $match) { 261 self::addToTOC($toc, $match[2], intval($match[1]));352 nahoWikiContentPeer::addToTOC($toc, $match[2], intval($match[1])); 262 353 } 263 354 plugins/nahoWikiPlugin/trunk/lib/model/plugin/PluginnahoWikiPage.php
r7057 r8377 10 10 class PluginnahoWikiPage extends BasenahoWikiPage 11 11 { 12 12 13 /** 14 * Returns name (lower case) 15 * 16 * @return string 17 */ 13 18 public function getName() 14 19 { … … 16 21 } 17 22 23 /** 24 * Defines name (lower case) 25 * 26 * @param string $name 27 */ 18 28 public function setName($name) 19 29 { … … 21 31 } 22 32 33 /** 34 * Returns namespace of the page 35 * 36 * @return string 37 */ 23 38 public function getNamespace() 24 39 { … … 26 41 } 27 42 28 public function getBasename($page_name = null) 43 /** 44 * Returns basename of the page 45 * 46 * @return string 47 */ 48 public function getBasename() 29 49 { 30 50 return nahoWikiPagePeer::getBasename($this->getName()); 31 51 } 32 52 53 /** 54 * Transforms relative pagename to absolute 55 * 56 * @param string $page_name (default is current page_name) 57 * @return string 58 */ 33 59 public function resolveAbsoluteName($page_name = null) 34 60 { … … 66 92 } 67 93 94 /** 95 * Current revision 96 * 97 * @param int $revision 98 * @return nahoWikiRevision 99 */ 68 100 public function getRevision($revision = null) 69 101 { … … 81 113 } 82 114 115 /** 116 * Get all available revisions 117 * 118 * @param Criteria $criteria 119 * @return array 120 */ 83 121 public function getRevisions($criteria= null) 84 122 { … … 106 144 } 107 145 108 // @todo implement real rights management here 146 /** 147 * @todo implement real rights management here 148 * 149 * @param myUser $user 150 * @return boolean 151 */ 109 152 public function canView($user) 110 153 { … … 112 155 } 113 156 114 // @todo implement real rights management here 157 /** 158 * @todo implement real rights management here 159 * 160 * @param myUser $user 161 * @return boolean 162 */ 115 163 public function canEdit($user) 116 164 { plugins/nahoWikiPlugin/trunk/lib/model/plugin/PluginnahoWikiPagePeer.php
r7057 r8377 11 11 { 12 12 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 */ 13 31 public static function pageNameFormat($full = true) 14 32 { … … 24 42 } 25 43 44 /** 45 * Gets basename from full pagename 46 * 47 * @param string $page_name 48 * @return string 49 */ 26 50 public static function getBasename($page_name) 27 51 { … … 31 55 return array_pop($parts); 32 56 } 57 58 /** 59 * Gets namespace from full pagename 60 * 61 * @param string $page_name 62 * @return string 63 */ 33 64 34 65 public static function getNamespace($page_name) … … 41 72 } 42 73 74 /** 75 * Retrieve a page from its name 76 * 77 * @param string $name 78 * @return nahoWikiPage 79 */ 80 43 81 public static function retrieveByName($name) 44 82 { … … 49 87 } 50 88 89 /** 90 * Retrieve pages from their names 91 * 92 * @param array $names 93 * @return array 94 */ 95 51 96 public static function retrieveByNames($names) 52 97 { … … 56 101 return self::doSelect($c); 57 102 } 103 104 /** 105 * Retrieve a page from its name 106 * 107 * @param string $name 108 * @return nahoWikiPage 109 */ 58 110 59 111 public static function retrieveByNameJoinAll($name) … … 68 120 } 69 121 122 /** 123 * Retrieve pages from their names 124 * 125 * @param array $names 126 * @return array 127 */ 128 70 129 public static function retrieveByNamesJoinAll($names) 71 130 { … … 76 135 } 77 136 137 78 138 } plugins/nahoWikiPlugin/trunk/lib/model/plugin/PluginnahoWikiRevision.php
r7057 r8377 45 45 } 46 46 47 /** 48 * Initializes username from context 49 * 50 */ 47 51 public function initUserName() 48 52 { … … 55 59 } 56 60 61 /** 62 * Is current revision the latest for its page ? 63 * 64 * @return boolean 65 */ 57 66 public function isLatest() 58 67 { … … 60 69 } 61 70 71 /** 72 * Returns the attached page 73 * 74 * @return nahoWikiPage 75 */ 76 62 77 public function getPage() 63 78 { 64 79 return $this->getnahoWikiPage(); 65 80 } 81 82 /** 83 * Gets content 84 * 85 * @return string 86 */ 66 87 67 88 public function getContent() … … 87 108 } 88 109 110 /** 111 * Gets converted content 112 * 113 * @return string 114 */ 115 89 116 public function getXHTMLContent() 90 117 { … … 97 124 } 98 125 126 /** 127 * Defines content 128 * 129 * @param string $content 130 */ 131 99 132 public function setContent($content) 100 133 { … … 106 139 $content_storage->setContent($content); 107 140 108 return$content_storage->save();141 $content_storage->save(); 109 142 } 143 144 /** 145 * Compress current content to save space 146 * 147 * @return boolean 148 */ 110 149 111 150 public function archiveContent() … … 128 167 } 129 168 169 /** 170 * Uncompress content 171 * 172 * @return boolean 173 */ 174 130 175 public function unarchiveContent() 131 176 { … … 147 192 } 148 193 194 149 195 }