To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit 087c956d authored by vermeul's avatar vermeul
Browse files

use hashtag for replacing ids, if available

parent 14d0ecdb
......@@ -102,7 +102,7 @@ class YATA {
}
}
if ( $errors) {
if ($errors) {
foreach( $errors as $error) {
$errstr .= $error . "<br/>";
}
......@@ -345,14 +345,10 @@ EOT;
*/
public static function onPageContentSave(WikiPage &$wikiPage, User &$user, Content &$content, $summary, $isMinor, $isWatch, $section, $flags, Status &$status ){
/*
0. manage all categories (add/delete them)
1. get all existing annotations which exist on that page.
2. find out which annotations have been deleted.
3. find out which annotations have been added -> assign a unique identifier
4. find out which annotations have been updated (using the unique
identifier)
5. assign every annotation to one or more categories
6. assign every annotation to this page
1. manage all categories (see manage_categories)
2. parse the annotations (see parse_annotations)
3. replace the wiki_text
*/
# get database handler
......@@ -396,7 +392,7 @@ EOT;
}
/**
* Occurs after the save page request has been processed.
* 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 updated annotations. Annotations which are
......@@ -411,6 +407,8 @@ EOT;
foreach ( self::$annotations as $bookmark => $annotation ){
$annotation_id = 0;
$ex_annot = self::get_annotation($dbw, $wikiPage, $bookmark);
# existing annotation found: update wiki_text, comment
if ($ex_annot) {
$annotation_id = $ex_annot->id;
$ex_annot = self::get_annotation($dbw, $wikiPage, $bookmark);
......@@ -431,6 +429,7 @@ EOT;
);
}
}
# new annotation found: insert annotation
else {
# write annotation
$dbw->insert(
......@@ -796,7 +795,7 @@ EOT;
$row = $dbr->selectRow(
array(c=>'yata_category', pc=>'yata_category'),
array(
'id' => 'c.id',
'id' => 'c.id',
'name' => 'c.name',
'hashtag' => 'c.hashtag',
'description' => 'c.description',
......@@ -909,6 +908,14 @@ EOT;
# Main function to parse all annotations,
# insert a random id (where it doesn't exist)
public static function parse_annotations($dbw, &$data, $wikiPage){
/*
1. get all existing annotations which exist on that page.
2. find out which annotations have been updated (using the unique identifier)
3. find out which annotations have been added -> assign a unique identifier
4. find out which annotations have been removed from the wikitext and delete them
5. assign every annotation to one or more categories
6. assign every annotation to this page
*/
# match either #annot: or #annotend:
# fetch all options too
......@@ -1122,7 +1129,7 @@ EOT;
// callback function for onEditFormInitialText hook
// all category_id's are replaced with the category names themselves
// using the parent_category/child_category naming scheme.
// 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"]);
......@@ -1136,7 +1143,10 @@ EOT;
foreach($categories as $category) {
$cat_and_parent = self::get_category_and_parent_for_id($dbw, $category);
if ($cat_and_parent) {
if ($cat_and_parent->parent_name) {
if ($cat_and_parent->hashtag) {
array_push($cat_and_parents, $cat_and_parent->hashtag);
}
elseif ($cat_and_parent->parent_name) {
array_push($cat_and_parents, $cat_and_parent->parent_name .'/'. $cat_and_parent->name);
}
else {
......
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