Beispiel #1
0
 /**
  * ページの関連性データーベースを更新
  * @global string $WikiName
  * @global boolean $autolink
  * @global type $nowikiname
  * @global array $search_non_list
  * @param string $page
  * @return void
  */
 public function update($page = '')
 {
     $time = Factory::Wiki($page)->time();
     $rel_old = self::getRel($this->page);
     $rel_exist = $rel_old === array();
     $rel_auto = $rel_new = array();
     $pages = self::getObjects($page);
     if (!empty($pages)) {
         foreach ($pages as $_obj) {
             if (!isset($_obj->type) || $_obj->type !== 'pagename' || $_obj->name === $page || empty($_obj->name)) {
                 continue;
             }
             if ($_obj instanceof AutoLink) {
                 // Not cool though
                 $rel_auto[] = $_obj->name;
             } else {
                 if ($_obj instanceof AutoAlias) {
                     $_alias = AutoAlias::getAutoAliasDict($_obj->name);
                     if (Factory::Wiki($_alias)->isValied()) {
                         $rel_auto[] = $_alias;
                     }
                 } else {
                     $rel_new[] = $_obj->name;
                 }
             }
         }
     }
     // All pages "Referenced to" only by AutoLink
     $rel_auto = array_diff(array_unique($rel_auto), $rel_new);
     // All pages "Referenced to"
     $rel_new = array_merge(array_unique($rel_new), $rel_auto);
     // update Pages referred from the $page
     if ($time) {
         // Page exists
         self::setRel($this->page, $rel_new);
     }
     // .ref: Pages refer to the $page
     self::add($this->page, array_diff($rel_new, $rel_old), $rel_auto);
     self::remove($this->page, array_diff($rel_old, $rel_new));
     global $autolink, $nowikiname, $search_non_list;
     // $page seems newly created, and matches with AutoLink
     if ($time && !$rel_exist && $autolink && (Utility::isWikiName($page) ? $nowikiname : strlen($page) >= $autolink)) {
         // Update all, because they __MAY__ refer the $page [HEAVY]
         $search_non_list = 1;
         $pages = Search::do_search($page, 'AND', TRUE);
         foreach ($pages as $_page) {
             if ($_page !== $page) {
                 $this->update($_page);
             }
         }
     }
     // $pageが削除されたときに、
     foreach (self::getRef($this->page) as $line) {
         list($ref_page, $ref_auto) = explode("\t", rtrim($line));
         // $pageをAutoLinkでしか参照していないページを一斉更新する(おいおい)
         if ($ref_auto) {
             self::remove($ref_page, array($page));
         }
     }
 }
Beispiel #2
0
 /**
  * ページの自動リンクを作成
  * @global type $vars
  * @global type $link_compact
  * @global type $related
  * @global type $_symbol_noexists
  * @param string $page ページ名
  * @param string $alias リンクの名前
  * @param string $anchor ページ内アンカー(アドレスの#以降のテキスト)
  * @param string $refer リンク元
  * @param boolean $isautolink 自動リンクか?
  * @return string
  */
 public static function setAutoLink($page, $alias = '', $anchor = '', $refer = '', $isautolink = FALSE)
 {
     global $vars, $link_compact, $related, $_symbol_noexists, $related;
     if (empty($page)) {
         // ページ内リンク
         return '<a href="' . $anchor . '">' . Utility::htmlsc($alias) . '</a>';
     }
     $wiki = Factory::Wiki($page);
     if (!$wiki->has()) {
         // ページが存在しない場合は、AutoAliasから該当ページが存在するかを確認する
         foreach (AutoAlias::getAutoAliasDict() as $aliaspage => $realpage) {
             if (Factory::Wiki($realpage)->has()) {
                 // リンクをエイリアス先に
                 return self::setLink($page, $aliaspage);
             }
         }
     } else {
         if (!isset($related[$page]) && isset($vars['page']) && $page !== $vars['page']) {
             $related[$page] = $wiki->time();
         }
     }
     $s_page = Utility::htmlsc($page);
     $anchor_name = empty($alias) ? $page : $alias;
     $anchor_name = str_replace('&amp;#039;', '\'', $anchor_name);
     // 'が&#039;になってしまう問題をとりあえず解消
     if ($isautolink || $wiki->has()) {
         // ページが存在する場合
         // 用語集にページ名と同じワードが含まれていた場合
         $glossary = Glossary::getGlossary($page);
         if (!empty($glossary)) {
             // AutoGlossray
             return '<abbr class="glossary" title="' . $glossary . ' ' . $wiki->passage(false, true) . '">' . '<a href="' . $wiki->uri() . '"' . ($isautolink === true ? ' class="autolink"' : '') . '>' . $anchor_name . '</a></abbr>';
         }
         return '<a href="' . $wiki->uri() . $anchor . '" ' . (!$link_compact ? 'title="' . $s_page . ' ' . $wiki->passage(false, true) . '"' : '') . ($isautolink === true ? ' class="autolink"' : '') . '>' . $anchor_name . '</a>';
     } else {
         // Dangling link
         if (Auth::check_role('readonly')) {
             return Utility::htmlsc($alias);
         }
         // No dacorations
         $retval = $anchor_name . '<a href="' . $wiki->uri('edit', empty($refer) ? null : array('refer' => $refer)) . '" rel="nofollow">' . $_symbol_noexists . '</a>';
         return $link_compact ? $retval : sprintf(RendererDefines::NOEXISTS_STRING, $retval);
     }
 }