Commit e792d03b authored by vermeul's avatar vermeul

resolved conflicts

parents ee54e55e 9990d548
......@@ -120,6 +120,10 @@ See the [SMW concepts](https://www.semantic-mediawiki.org/wiki/Help:Concepts)
[[category: category_name1, category_name2 ]] # category_name1 OR category_name2
[[category: #category_tag1, #category_tag2 ]] # category hashtags can be used as well
[[category: #parent_category(0) ]] # only match annotations that are marked belonging to #parent_category,
# not to any existing child-categories. If the number is 1, only its
# direct children categories should be included.
[[category: category_name1 ]] # every line is AND'ed, so these two lines mean:
[[category: category_name2 ]] # category_name1 AND category_name2
......
......@@ -49,6 +49,19 @@ class YATA {
// Render the output of {{#annotask:}}
//
public static function annotation_query( $parser, $querystring) {
#// render math symbols in output
#$mode = (int)$parser->getUser()->getOption( 'math' );
#// Indicate that this page uses math.
#// This affects the page caching behavior.
#if ( is_callable( 'ParserOptions::getMath' ) ) {
# $parser->getOptions()->getMath();
#} else {
# $parser->getOptions()->optionUsed( 'math' );
#}
$title = $parser->getTitle();
$wikiPage = new WikiPage( $title );
$queries_found = preg_match_all(
......@@ -75,13 +88,30 @@ class YATA {
$categories = preg_split('/\s*\,\s*/', $values);
$cat_ids = array();
foreach( $categories as $category ) {
# keep category for display
array_push($in_categories, $category);
# remove the search-depth from the category name, e.g.
# category_name(1) --> category_name 1
preg_match(
'/(?P<category>\w+)\s*(\((?P<depth>\d+)\))?/',
$category, $matches, PREG_OFFSET_CAPTURE
);
$category = $matches['category'][0];
$depth = null;
if (array_key_exists('depth', $matches)) {
$depth = $matches['depth'][0];
}
# get the category entry from DB
$cat = self::get_category($dbr, $category);
if ($cat) {
$cat_ids[] = $cat->id;
$child_categories = self::get_child_categories($dbr, $cat);
foreach($child_categories as $child_category) {
$cat_ids[] = $child_category->id;
if ($depth) {
$child_categories = self::get_child_categories($dbr, $cat, 0, $depth-1);
foreach($child_categories as $child_category) {
$cat_ids[] = $child_category->id;
}
}
}
else {
......@@ -206,7 +236,6 @@ class YATA {
);
}
//print($dbr->lastQuery($annotations));
//die();
$table = "";
if ($searches) {
......@@ -260,7 +289,6 @@ class YATA {
."</td><td>".$annotation->comment
."</td><td>". $link
."</td><td><pre>" . $wikitext . "</pre>"
#." || "
."</td>";
$p_annotations = self::get_page_annotations($dbr, $annotation->page_id);
......@@ -300,22 +328,22 @@ EOT;
# fetch the annotation details
$annotations = $dbr->select(
array(
a =>'yata_annotation',
ac=>'yata_annotation_category',
c =>'yata_category',
pc=>'yata_category',
u =>'user',
'a' =>'yata_annotation',
'ac'=>'yata_annotation_category',
'c' =>'yata_category',
'pc'=>'yata_category',
'u' =>'user',
),
array(
comment => "a.comment",
wiki_text => "a.wiki_text",
start_char => "a.start_char",
bookmark => "a.bookmark",
category => "c.name",
hashtag => "c.hashtag",
parent_category => "pc.name",
last_edited_by => "u.user_name",
last_modified => "a.modified_date"
'comment' => "a.comment",
'wiki_text' => "a.wiki_text",
'start_char' => "a.start_char",
'bookmark' => "a.bookmark",
'category' => "c.name",
'hashtag' => "c.hashtag",
'parent_category' => "pc.name",
'last_edited_by' => "u.user_name",
'last_modified' => "a.modified_date"
),
array(
'a.page_id' => $wikiPage->getId(),
......@@ -366,11 +394,11 @@ EOT;
}
$dbr = wfGetDB( DB_MASTER );
$where = array('parent_id'=>null); # start with all top catgegories
$where = array('parent_id' => null); # start with all top catgegories
if ( $start_with ) {
$start_with_cat = self::get_category($dbr, $start_with);
if ( $start_with_cat ) {
$where = array(id=>$start_with_cat->id);
$where = array('id' => $start_with_cat->id);
}
}
......@@ -450,7 +478,8 @@ EOT;
}
public static function onPageContentSave(WikiPage &$wikiPage, User &$user, Content &$content, $summary, $isMinor, $isWatch, $section, $flags, Status &$status ){
public static function onPageContentSave(WikiPage &$wikiPage, User
&$user, Content &$content, $summary, $isMinor, $isWatch, $section, &$flags, Status &$status ){
/*
onPageContentSave: Hook on when page is saved
we first replace syntax sugar where necessary, e.g.
......@@ -465,6 +494,10 @@ EOT;
The annotations are saved in the next hook: onPageContentSaveComplete (see below)
*/
$data = $content->getNativeData();
$content = new WikitextContent( 'hello something' );
return true;
# get database handler
$dbw = wfGetDB( DB_MASTER );
......@@ -477,6 +510,8 @@ EOT;
$data = preg_replace( '/{{#*(annotend|annotlist)}}/U','{{#$1:}}', $data);
# 1. add / delete categories
# 2. remove these order from the wikiText,
# because they are used only once.
try {
$data = self::manage_categories($dbw, $data);
}
......@@ -505,18 +540,20 @@ EOT;
if ( !$status->isOK() ) {
return false;
}
return true;
}
/*
This function is called after the save page request has been processed.
@see https://www.mediawiki.org/wiki/Manual:Hooks/PageContentSaveComplete
- save all new or update chaned annotations
- save all new or update changed annotations
- Annotations which are no longer present should be deleted.
- all entries in annotation_category which are no longer used should be deleted.
*/
public static function onPageContentSaveComplete($wikiPage, $user, $content, $summary,
$isMinor, $isWatch, $section, $flags, $revision, $status, $baseRevId ) {
return true;
$dbw = wfGetDB( DB_MASTER );
$seen_bookmarks = array();
$seen_annotation_ids = array();
......@@ -533,14 +570,14 @@ EOT;
$dbw->update(
'yata_annotation',
array(
wiki_text => $annotation["wiki_text"],
comment => $annotation["comment"],
user_id => $user->getId(),
modified_date => $dbw->timestamp(),
'wiki_text' => $annotation["wiki_text"],
'comment' => $annotation["comment"],
'user_id' => $user->getId(),
'modified_date' => $dbw->timestamp(),
),
array(
page_id => $wikiPage->getId(),
bookmark => $bookmark
'page_id' => $wikiPage->getId(),
'bookmark' => $bookmark
)
);
}
......@@ -550,25 +587,25 @@ EOT;
# write annotation
try {
$data = array(
page_id => $wikiPage->getId(),
comment => $annotation['comment'],
wiki_text => $annotation['wiki_text'],
bookmark => $bookmark,
user_id => $user->getId(),
insert_date => $dbw->timestamp(),
modified_date => $dbw->timestamp(),
'page_id' => $wikiPage->getId(),
'comment' => $annotation['comment'],
'wiki_text' => $annotation['wiki_text'],
'bookmark' => $bookmark,
'user_id' => $user->getId(),
'insert_date' => $dbw->timestamp(),
'modified_date' => $dbw->timestamp(),
);
$dbw->insert(
'yata_annotation',
array(
page_id => $wikiPage->getId(),
comment => $annotation['comment'],
wiki_text => $annotation['wiki_text'],
bookmark => $bookmark,
user_id => $user->getId(),
insert_date => $dbw->timestamp(),
modified_date => $dbw->timestamp(),
'page_id' => $wikiPage->getId(),
'comment' => $annotation['comment'],
'wiki_text' => $annotation['wiki_text'],
'bookmark' => $bookmark,
'user_id' => $user->getId(),
'insert_date' => $dbw->timestamp(),
'modified_date' => $dbw->timestamp(),
)
);
$ex_annot = self::get_annotation($dbw, $wikiPage, $bookmark);
......@@ -600,8 +637,8 @@ EOT;
$dbw->delete(
'yata_annotation_category',
array(
page_id => $wikiPage->getId(),
annotation_id => $annotation_id,
'page_id' => $wikiPage->getId(),
'annotation_id' => $annotation_id,
'category_id NOT IN(' .$dbw->makeList($seen_acs). ')'
)
);
......@@ -612,8 +649,8 @@ EOT;
$dbw->delete(
'yata_annotation_category',
array(
page_id => $wikiPage->getId(),
annotation_id => $annotation_id,
'page_id' => $wikiPage->getId(),
'annotation_id' => $annotation_id,
)
);
}
......@@ -649,8 +686,8 @@ EOT;
# which do not exist anymore
$delete_where = [
page_id => $wikiPage->getId(),
annotation_id => $annotation->id
'page_id' => $wikiPage->getId(),
'annotation_id' => $annotation->id
];
$dbw->delete(
......@@ -704,8 +741,8 @@ EOT;
'yata_category',
array('id'),
array(
name => $category_name,
parent_id => $parent_id
'name' => $category_name,
'parent_id' => $parent_id
)
);
......@@ -721,10 +758,10 @@ EOT;
$dbw->insert(
'yata_category',
array(
name => $category_name,
hashtag => $hashtag,
description => trim($description),
parent_id => $parent_id
'name' => $category_name,
'hashtag' => $hashtag,
'description' => trim($description),
'parent_id' => $parent_id
)
);
......@@ -779,7 +816,7 @@ EOT;
'yata_category',
$set,
array(
id => $category->id
'id' => $category->id
)
);
}
......@@ -796,7 +833,7 @@ EOT;
$dbw->delete(
'yata_category',
array(
hashtag => $category_name,
'hashtag' => $category_name,
)
);
return;
......@@ -839,7 +876,11 @@ EOT;
# {{#annotcat: del | parent_category_name/category_name}}
# {{#annotcat: del | #shortcut }}
list($method, $arg1, $arg2) = preg_split('/\s*\|\s*/', $matches["params"]);
$splits = preg_split('/\s*\|\s*/', $matches["params"]);
$method = isset($splits[0]) ? $splits[0] : null;
$arg1 = isset($splits[1]) ? $splits[1] : null;
$arg2 = isset($splits[2]) ? $splits[2] : null;
if ( $method === "add" ) {
$args = self::split_cat_argstring($arg1);
self::add_category($dbw, $args['name'], $args['hashtag'], $args['description'], $args['parent']);
......@@ -861,11 +902,12 @@ EOT;
return "";
}
// manage any categories added
public static function manage_categories( $dbw, $data) {
# - handles {{#annotcat}} orders that add, update or delete categories
# - returns the wikiText with the annotcat orders removed
# look for all tags {{#annotcat:(.*)}}
# and pass the matches to the callback function category_add_del_callback
# which will return an empty string in order to remove this tag before saving the page.
$data = preg_replace_callback(
'/({{#annotcat:\s*(?P<params>.*?)}})/s',
'self::category_add_del_callback',
......@@ -879,8 +921,8 @@ EOT;
'yata_annotation',
array('id', 'wiki_text', 'comment'),
array(
page_id => $wikiPage->getId(),
bookmark => $bookmark
'page_id' => $wikiPage->getId(),
'bookmark' => $bookmark
)
);
return $row;
......@@ -1033,8 +1075,9 @@ EOT;
}
public static function get_category_and_parent_for_id($dbr, $id) {
#var_dump($id); die();
$row = $dbr->selectRow(
array(c=>'yata_category', pc=>'yata_category'),
array('c'=>'yata_category', 'pc'=>'yata_category'),
array(
'id' => 'c.id',
'name' => 'c.name',
......@@ -1053,7 +1096,8 @@ EOT;
return $row;
}
public static function get_child_categories($dbr, $category, $level=0) {
public static function get_child_categories($dbr, $category, $level=0,
$depth=null) {
$rows = $dbr->select(
array('yata_category'),
array('id', 'name', 'hashtag', 'description', 'parent_id', "$level as level"),
......@@ -1066,10 +1110,28 @@ EOT;
foreach($rows as $row) {
array_push($all_child_categories, $row);
$child_categories = self::get_child_categories($dbr, $row, $level+1);
foreach($child_categories as $child_category) {
array_push($all_child_categories, $child_category);
# if no $depth is defined (null),
# recursively search for child categories
if (is_null($depth)) {
$child_categories = self::get_child_categories(
$dbr, $row, $level+1
);
foreach($child_categories as $child_category) {
array_push($all_child_categories, $child_category);
}
}
# if $depth > 0, continue searching for
# child categories
elseif ($depth) {
$child_categories = self::get_child_categories(
$dbr, $row, $level+1, $depth-1
);
foreach($child_categories as $child_category) {
array_push($all_child_categories, $child_category);
}
}
}
return $all_child_categories;
......@@ -1079,7 +1141,7 @@ EOT;
$dbw->delete(
'yata_annotation',
array(
page_id => $wikiPage->getId()
'page_id' => $wikiPage->getId()
)
);
}
......@@ -1089,8 +1151,8 @@ EOT;
array('yata_annotation'),
array('id'),
array(
bookmark => $bookmark,
page_id => $wikiPage->getId()
'bookmark' => $bookmark,
'page_id' => $wikiPage->getId()
)
);
return $row;
......@@ -1100,7 +1162,7 @@ EOT;
$dbw->delete(
'yata_annotation_category',
array(
page_id => $wikiPage->getId()
'page_id' => $wikiPage->getId()
)
);
}
......@@ -1110,9 +1172,9 @@ EOT;
'yata_annotation_category',
array('anz' => 'COUNT(*)'),
array(
page_id => $wikiPage->getId(),
annotation_id => $annotation_id,
category_id => $category_id
'page_id' => $wikiPage->getId(),
'annotation_id' => $annotation_id,
'category_id' => $category_id
)
);
if ($ex_ac->anz) {
......@@ -1122,9 +1184,9 @@ EOT;
$dbw->insert(
'yata_annotation_category',
array(
page_id => $wikiPage->getId(),
annotation_id => $annotation_id,
category_id => $category_id
'page_id' => $wikiPage->getId(),
'annotation_id' => $annotation_id,
'category_id' => $category_id
)
);
}
......@@ -1287,10 +1349,11 @@ EOT;
# we encountered an annotation START
elseif ($reg_params["end"][$index][0] === "" && $reg_params["page"][$index][0] === "") {
# split comment|$category|$bookmark by vertical bar
list($comment, $category, $bookmark) = preg_split(
'/\s*\|\s*/',
$reg_params["opts"][$index][0]
);
$string = $reg_params["opts"][$index][0];
$words = preg_split( '/\s*\|\s*/', $string);
$comment = isset($words[0])? $words[0] : null;
$category = isset($words[1])? $words[1] : null;
$bookmark = isset($words[2])? $words[2] : null;
# more than one category can be split using a comma:
# category1, category2
# categories are by default hierarchically organized and must appear
......@@ -1405,6 +1468,8 @@ EOT;
// to change all source code where this category occurs.
public static function onEditFormInitialText($editPage) {
$data = $editPage->textbox1;
#var_dump($data);
#die();
$data = preg_replace_callback(
'/(?:{{#annot:(?P<params>.*?)}})/s',
'self::replace_id_with_category',
......@@ -1423,7 +1488,11 @@ EOT;
// using the hashtag (if available) or the parent_category/child_category naming scheme (fallback).
private static function replace_id_with_category($matches) {
$dbw = wfGetDB( DB_MASTER );
list($comment, $cat, $bookmark) = preg_split('/\s*\|\s*/', $matches["params"]);
$splits = preg_split('/\s*\|\s*/', $matches["params"]);
$comment = isset($splits[0]) ? $splits[0] : null;
$cat = isset($splits[1]) ? $splits[1] : null;
$bookmark= isset($splits[2]) ? $splits[2] : null;
if (!$cat) {
return $matches[0];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment