Commit 65308a7a authored by vermeul's avatar vermeul

...

parent 9b805e09
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PublishConfigData" serverName="mispar" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/sql/yata.mysql.sql" dialect="MySQL" />
<file url="PROJECT" dialect="PostgreSQL" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -29,13 +29,15 @@ not only are take to the right page but also to the exact position of the annota
### Annotation Syntax
Annotations always have a start and an end. They look like this:
```
{{#annot:}} # opening tag, which marks the start of an annotation
{{#annotend:}} # closing tag, which marks the end of an annotation
```
Annotations usually contain comments and may be categorised (Categories: see below):
````
```
{{#annot: comment}} # basic annotation with just a comment
{{#annot: comment | category}} # categorized annotation (see annotaion categories below)
{{#annot: comment | cat_parent/cat_child}} # annotation with a specific category identified by a `cat_parent/cat_child` pair
......@@ -68,6 +70,7 @@ connect start and ending of every comment.
```
Annotation (a) then contains:
```
more text
which has even overlapping
......@@ -75,10 +78,11 @@ comments
```
while annotation (b) will contain this part of the WikiText:
```
overlapping
comments, which means we need
```
```
### display all annotations of a given page
......@@ -101,6 +105,7 @@ See the [SMW concepts](https://www.semantic-mediawiki.org/wiki/Help:Concepts)
### annotask Query syntax
```
[[category: category_name1 ]] # this category (and all categories below it)
[[category: category_name1, category_name2 ]] # category_name1 OR category_name2
......@@ -186,10 +191,10 @@ Put this on any WikiPage and it will list existing categories:
{{#annotcat: list | parent_name/category_name}} # start list with node parent_category/category
```
### add a new category
To add a new category into the categories table, we simply add one of the following anywhere in a Wiki Page:
```
{{#annotcat: add | name='new top category', hashtag='#my_top_cat', description='some meaningful comments', parent='grandparent_category/parent_category' }}
{{#annotcat: add | name='new top category', hashtag='#my_top_cat', description='some meaningful comments', parent='parent_category' }} # add to an existing top category
......
......@@ -25,6 +25,7 @@ class YATA {
$parser->setFunctionHook( 'annotlist', 'YATA::annotations_list' );
$parser->setFunctionHook( 'annotask', 'YATA::annotation_query' );
$parser->setFunctionHook( 'annotcat', 'YATA::annotation_categories' );
$parser->setFunctionHook( 'annotpage', 'YATA::annotation_page' );
}
//
......@@ -45,29 +46,6 @@ class YATA {
// Render the output of {{#annotask:}}
//
public static function annotation_query( $parser, $querystring) {
#$smw_querystring = "{{#ask: [[Has author::Swen Vermeul]]
# |?Has author
# |?Has population
# |?Has date
#}}
#";
#$printouts = array();
#$parameters = array();
##SMWQueryProcessor:addThisPrintout( $printouts, $parameters );
#$query = SMWQueryProcessor::createQuery(
# $smw_querystring,
# SMWQueryProcessor::getProcessedParams( $parameters, $printouts ),
# SMWQueryProcessor::SPECIAL_PAGE,
# '',
# $printouts
#);
#$query->setOption( SMWQuery::PROC_CONTEXT, 'API' );
#$result = ApplicationFactory::getInstance()->getStore()->getQueryResult( $query );
#var_dump($result);
#die;
$title = $parser->getTitle();
$wikiPage = new WikiPage( $title );
$queries_found = preg_match_all(
......@@ -270,7 +248,7 @@ EOT;
last_modified => "a.modified_date"
),
array(
'a.page_id' => $wikiPage->getId()
'a.page_id' => $wikiPage->getId(),
),
__METHOD__,
array(
......@@ -313,10 +291,6 @@ EOT;
// Render the output of {{#annotcat: list}}.
//
public static function annotation_categories( $parser, $method, $start_with=null ) {
#use Ask;
#print("hello!");
##print(Ask::getVersion());
#die;
if (! $method == "list") {
return "";
}
......@@ -369,6 +343,38 @@ EOT;
}
//
// Rendering of {{#annotpage}}
//
public static function annotation_page( $parser ) {
$title = $parser->getTitle();
$wikiPage = new WikiPage( $title );
$dbr = wfGetDB( DB_MASTER );
$annotations = self::get_page_annotations($dbr, $wikiPage );
$table = <<<"EOT"
{| class="wikitable sortable"
|-
! Name !! Value !! Creation Date !! Created By
EOT;
foreach($annotation as $annotations) {
# if a annotations has no parent, just show the annotations name
# in all other cases show parent_annotations:child_annotations
$table .= "|-\n";
$table .= "| ".$annotations->name
." || ".$annotations->value
." || ".$annotations->created
." || ".$annotations->create
."\n";
}
$table .= "|}";
return $table;
}
public static function onPageContentSave(WikiPage &$wikiPage, User &$user, Content &$content, $summary, $isMinor, $isWatch, $section, $flags, Status &$status ){
/*
......@@ -396,7 +402,7 @@ EOT;
# replace all {{#annotlist}} or {{annotlist}} with {{#annotlist:}}, where necessary
$data = preg_replace( '/{{#*(annotend|annotlist)}}/U','{{#$1:}}', $data);
# add / delete categories
# 1. add / delete categories
try {
$data = self::manage_categories($dbw, $data);
}
......@@ -405,9 +411,9 @@ EOT;
return false;
}
# get all annotations that exist in the current wikitext
# 2. get all annotations that exist in the current wikitext
try {
$annotations = self::parse_annotations($dbw, $data, $wikiPage);
list($annotations, $page_annotations) = self::parse_annotations($dbw, $data, $wikiPage);
}
catch (Exception $e) {
$status->fatal($e->getMessage());
......@@ -417,7 +423,7 @@ EOT;
# keep the annotations for saving later (onPageContentSaveComplete)
self::$annotations = $annotations;
# replace the content and save it
# 3. replace the content and save it
$content = new WikitextContent( $data );
}
......@@ -777,6 +783,36 @@ EOT;
return $row;
}
public static function get_page_annotations($dbr, $wikiPage, $order_by) {
if (! $order_by) {
$order_by = array('ORDER BY' => 'name');
}
$annotations = $dbr->select(
array('pa' => 'yata_page_annotation',
'u' => 'user'),
array(
'pa.id',
'pa.page_id',
'pa.name',
'pa.value',
'pa.insert_date',
'u.user_name'
),
array(
'pa.page_id' => $wikiPage->getId(),
'pa.user_id' => 'u.user_id'
),
__METHOD__,
$order_by,
array(
'u' => array( 'LEFT JOIN', array('u.user_id = pa.user_id') )
)
);
return $annotations;
}
public static function search_categories($dbr, $where, $order_by) {
if (! $order_by) {
......@@ -987,7 +1023,7 @@ EOT;
# match either #annot: or #annotend:
# fetch all options too
$annotations_found = preg_match_all(
'/(?P<annotation>{{\s*#annot(?P<end>end)?\s*:\s*(?P<opts>.*?)\s*}})/s',
'/(?P<annotation>{{\s*#annot((?P<end>end)|(?P<page>page))?\s*:\s*(?P<opts>.*?)\s*}})/s',
$data,
$reg_params,
PREG_OFFSET_CAPTURE
......@@ -1013,8 +1049,8 @@ EOT;
$new_data = $new_data . substr($data, $start_loc, $end_loc-$start_loc);
$start_loc = $value[1] + strlen($value[0]);
# we encountered an annotation START
if ($reg_params["end"][$index][0] === "") {
# we encountered an annotation ending
if ($reg_params["page"][$index][0] === "end") {
# split comment|$category|$bookmark by vertical bar
list($comment, $category, $bookmark) = preg_split(
'/\s*\|\s*/',
......@@ -1044,6 +1080,7 @@ EOT;
throw new Exception("no such category: $cat_str");
}
}
# we encountered an id: replace it with a unique one,
# if it doesn't exist yet.
$new_bookmark = 0;
......@@ -1059,19 +1096,15 @@ EOT;
}
$annotations_with_id[$bookmark] = $new_bookmark;
$annotations[$new_bookmark] = array();
$annotations[$new_bookmark]["start_char"] = $value[1] + strlen($value[0]);
$annotations[$new_bookmark]["annotpage"] = true;
$annotations[$new_bookmark]["wiki_text"] = "";
$annotations[$new_bookmark]["is_new"] = true;
$annotations[$new_bookmark]["categories"] = $cats;
$annotations[$new_bookmark]["comment"] = $comment;
}
# we found no id, push it on the stack to find its
# ending counterpart later
# we found no bookmark, create a new bookmark.
else {
$new_bookmark = self::create_bookmark();
$value["new_bookmark"] = $new_bookmark;
$value["categories"] = $cats;
$value["comment"] = $comment;
array_push($starts, $value);
}
# replace category names with their corresponding id's
......@@ -1081,7 +1114,8 @@ EOT;
$cats
)
);
$new_data = $new_data . "{{#annot:$comment|$new_category|$new_bookmark}}";
$new_data = $new_data . "{{#annotpage:$comment|$new_category|$new_bookmark}}";
}
# we encountered an annotation ending
......@@ -1131,13 +1165,85 @@ EOT;
$new_data = $new_data . "{{#annotend:$new_bookmark}}";
}
}
# 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]
);
# more than one category can be split using a comma:
# category1, category2
# categories are by default hierarchically organized and must appear
# in following formats:
# parent_category/child_category
# /top_category
# top_category
$cat_strs = preg_split("/\s*\,\s*/", $category, -1, PREG_SPLIT_NO_EMPTY);
$cats = array();
foreach($cat_strs as $cat_str) {
# we got a category id, which consists only of numbers
if ( preg_match("/^\s*\d*\s*$/", $cat_str) ) {
$cat = self::get_category_and_parent_for_id($dbw, $cat_str);
}
else {
$cat = self::get_category($dbw, $cat_str);
}
if ($cat) {
array_push($cats, $cat);
}
else {
throw new Exception("no such category: $cat_str");
}
}
# we encountered an id: replace it with a unique one,
# if it doesn't exist yet.
$new_bookmark = 0;
if ($bookmark) {
if ( self::check_annotation_bookmark_exist($dbw, $wikiPage, $bookmark))
{
# it is an existing annotation, we keep the id
$new_bookmark = $bookmark;
}
else {
# we replace the manually entered id by a random one
$new_bookmark = self::create_bookmark();
}
$annotations_with_id[$bookmark] = $new_bookmark;
$annotations[$new_bookmark] = array();
$annotations[$new_bookmark]["start_char"] = $value[1] + strlen($value[0]);
$annotations[$new_bookmark]["is_new"] = true;
$annotations[$new_bookmark]["categories"] = $cats;
$annotations[$new_bookmark]["comment"] = $comment;
}
# we found no id, push it on the stack to find its
# ending counterpart later
else {
$new_bookmark = self::create_bookmark();
$value["new_bookmark"] = $new_bookmark;
$value["categories"] = $cats;
$value["comment"] = $comment;
array_push($starts, $value);
}
# replace category names with their corresponding id's
$new_category = join(',',
array_map(
function($row) { return $row->id; },
$cats
)
);
$new_data = $new_data . "{{#annot:$comment|$new_category|$new_bookmark}}";
}
}
# add the end of the text
$new_data = $new_data . substr($data, $start_loc, strlen($data)-$start_loc);
# replace the original wikiText
$data = $new_data;
return $annotations;
return array($annotations, $page_annotations);
}
......@@ -1165,7 +1271,7 @@ EOT;
public static function onEditFilter($editor, $text, $section, &$error, $summary) {
}
// this is called after Save changes
// this is called after �Save changes�
// and after onEditFilter
public static function onArticlePrepareTextForEdit(&$wikiPage, &$popts) {
}
......
......@@ -3,7 +3,7 @@
--
-- Annotations table
CREATE TABLE /*_*/yata_annotation (
CREATE TABLE IF NOT EXISTS /*_*/yata_annotation (
-- unique identifier for every annotation
id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
......@@ -32,8 +32,32 @@ CREATE TABLE /*_*/yata_annotation (
)/*$wgDBTableOptions*/;
CREATE INDEX /*i*/yata_annot_page ON /*_*/yata_annotation (page_id);
CREATE INDEX /*i*/yata_annot_user ON /*_*/yata_annotation (user_id);
DROP INDEX /*i*/yata_annot_page_idx ON /*_*/yata_annotation;
DROP INDEX /*i*/yata_annot_user_idx ON /*_*/yata_annotation;
CREATE INDEX /*i*/yata_annot_page_idx ON /*_*/yata_annotation (page_id);
CREATE INDEX /*i*/yata_annot_user_idx ON /*_*/yata_annotation (user_id);
-- Page-Annotations table
CREATE TABLE IF NOT EXISTS /*_*/yata_page_annotation (
-- unique identifier for every annotation
id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
-- foreign key to page.page_id
page_id int unsigned NOT NULL,
name varchar(255) NOT NULL,
value varchar(255) NOT NULL,
insert_date varbinary(14),
modified_date varbinary(14)
)/*$wgDBTableOptions*/;
DROP INDEX /*i*/yata_page_annot_name_idx ON /*_*/yata_page_annotation;
DROP INDEX /*i*/yata_page_annot_page_idx ON /*_*/yata_page_annotation;
CREATE INDEX /*i*/yata_page_annot_name_idx ON /*_*/yata_page_annotation (name);
CREATE INDEX /*i*/yata_page_annot_page_idx ON /*_*/yata_page_annotation (page_id);
--
......@@ -42,7 +66,7 @@ CREATE INDEX /*i*/yata_annot_user ON /*_*/yata_annotation (user_id);
-- Many to many table for annotation and category.
-- Any given annotation can be assigned to more than one category.
CREATE TABLE /*_*/yata_annotation_category (
CREATE TABLE IF NOT EXISTS /*_*/yata_annotation_category (
-- foreign key to a page (for faster lookups)
page_id int unsigned NOT NULL,
......@@ -54,6 +78,10 @@ CREATE TABLE /*_*/yata_annotation_category (
category_id int unsigned NOT NULL
)/*$wgDBTableOptions*/;
DROP INDEX /*i*/yata_ann_cat_page_idx ON /*_*/yata_annotation_category;
DROP INDEX /*i*/yata_ann_cat_annotation_idx ON /*_*/yata_annotation_category;
DROP INDEX /*i*/yata_ann_cat_category_idx ON /*_*/yata_annotation_category;
CREATE INDEX /*i*/yata_ann_cat_page_idx ON /*_*/yata_annotation_category (page_id);
CREATE INDEX /*i*/yata_ann_cat_annotation_idx ON /*_*/yata_annotation_category (annotation_id);
CREATE INDEX /*i*/yata_ann_cat_category_idx ON /*_*/yata_annotation_category (category_id);
......@@ -65,7 +93,7 @@ CREATE INDEX /*i*/yata_ann_cat_category_idx ON /*_*/yata_annotation_category (ca
-- Annotation Category table
-- Annotation category table
CREATE TABLE /*_*/yata_category (
CREATE TABLE IF NOT EXISTS /*_*/yata_category (
-- unique identifier for every annotation category
id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
name varchar(255),
......@@ -75,6 +103,10 @@ CREATE TABLE /*_*/yata_category (
parent_id int unsigned
);
DROP INDEX /*i*/yata_category_name ON /*_*/yata_category;
DROP INDEX /*i*/yata_category_parent ON /*_*/yata_category;
DROP INDEX /*i*/yata_category_hashtag_unq ON /*_*/yata_category;
CREATE INDEX /*i*/yata_category_name ON /*_*/yata_category (name);
CREATE INDEX /*i*/yata_category_parent ON /*_*/yata_category (parent_id);
CREATE UNIQUE INDEX /*i*/yata_category_hashtag_unq ON /*_*/yata_category(hashtag);
......
......@@ -3,7 +3,7 @@
--
-- Annotations table
CREATE TABLE mediawiki.yata_annotation
CREATE TABLE IF NOT EXISTS mediawiki.yata_annotation
(
id SERIAL NOT NULL,
comment TEXT,
......@@ -17,26 +17,42 @@ CREATE TABLE mediawiki.yata_annotation
PRIMARY KEY (id)
);
CREATE INDEX yata_annot_page_idx ON mediawiki.yata_annotation (page_id);
CREATE INDEX yata_annot_user_idx ON mediawiki.yata_annotation (user_id);
CREATE INDEX IF NOT EXISTS yata_annot_page_idx ON mediawiki.yata_annotation (page_id);
CREATE INDEX IF NOT EXISTS yata_annot_user_idx ON mediawiki.yata_annotation (user_id);
--
-- Page-Annotations table
--
CREATE TABLE IF NOT EXISTS mediawiki.yata_page_annotation (
id SERIAL NOT NULL,
page_id INT NOT NULL,
"name" VARCHAR (255),
"value" VARCHAR (255),
insert_date timestamp (6) WITH TIME ZONE,
modified_date timestamp (6) WITH TIME ZONE,
PRIMARY KEY (id)
);
CREATE INDEX IF NOT EXISTS yata_page_annot_name_idx ON mediawiki.yata_page_annotation (name);
CREATE INDEX IF NOT EXISTS yata_page_annot_page_idx ON mediawiki.yata_page_annotation (page_id);
--
-- Tables for the YATA extension
--
-- Many to many table for annotation and category.
-- Any given annotation can be assigned to more than one category.
CREATE TABLE mediawiki.yata_annotation_category
CREATE TABLE IF NOT EXISTS mediawiki.yata_annotation_category
(
page_id INT NOT NULL,
annotation_id INT NOT NULL,
category_id INT NOT NULL
);
CREATE INDEX yata_ann_cat_page_idx ON mediawiki.yata_annotation_category (page_id);
CREATE INDEX yata_ann_cat_annotation_idx ON mediawiki.yata_annotation_category (annotation_id);
CREATE INDEX yata_ann_cat_category_idx ON mediawiki.yata_annotation_category (category_id);
CREATE INDEX IF NOT EXISTS yata_ann_cat_page_idx ON mediawiki.yata_annotation_category (page_id);
CREATE INDEX IF NOT EXISTS yata_ann_cat_annotation_idx ON mediawiki.yata_annotation_category (annotation_id);
CREATE INDEX IF NOT EXISTS yata_ann_cat_category_idx ON mediawiki.yata_annotation_category (category_id);
--
-- Tables for the YATA extension
......@@ -44,7 +60,7 @@ CREATE INDEX yata_ann_cat_category_idx ON mediawiki.yata_annotation_category (ca
-- Annotation Category table
CREATE TABLE mediawiki.yata_category
CREATE TABLE IF NOT EXISTS mediawiki.yata_category
(
id SERIAL NOT NULL,
"name" VARCHAR (255),
......@@ -54,7 +70,7 @@ CREATE TABLE mediawiki.yata_category
PRIMARY KEY (id)
);
CREATE INDEX yata_category_name_idx ON mediawiki.yata_category (name);
CREATE INDEX yata_category_parent_idx ON mediawiki.yata_category (parent_id);
CREATE UNIQUE INDEX yata_category_hashtag_unq ON mediawiki.yata_category(hashtag);
CREATE INDEX IF NOT EXISTS yata_category_name_idx ON mediawiki.yata_category (name);
CREATE INDEX IF NOT EXISTS yata_category_parent_idx ON mediawiki.yata_category (parent_id);
CREATE UNIQUE INDEX IF NOT EXISTS yata_category_hashtag_unq ON mediawiki.yata_category(hashtag);
<?php
$where = [
"bla" => 'blu'
];
$where[] = 'blubber1';
array_push($where, 'blubber2');
var_dump($where);
die;
$data = <<<'EOT'
The start. Blalablaljka fjlsd
just before A{{#annot : as}}start A
......
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