Commit fa33ccbd authored by vermeul's avatar vermeul

fixed regex and added page annotations to annotask table

parent 4a944ce8
......@@ -62,6 +62,7 @@ class YATA {
);
$searches = array();
$in_categories = array();
$search_in_annotations = false;
$where = array();
$dbr = wfGetDB( DB_REPLICA );
......@@ -99,6 +100,7 @@ class YATA {
. join(',', $cat_ids)
. ")
)";
$search_in_annotations = true;
}
elseif( $field === 'user' ) {
$where["u.username"] = $values;
......@@ -107,17 +109,17 @@ class YATA {
elseif( $field === 'page' ) {
$key_comp_vals = self::extract_query_keyvalues($values);
foreach($key_comp_vals as $key_comp_val){
$where[] =
$where[] =
"EXISTS(
SELECT NULL
FROM yata_page_annotation pa
WHERE pa.page_id = ".$wikiPage->getId()
WHERE pa.page_id = p.page_id"
." AND pa.name = "
.$dbr->addQuotes($key_comp_val[0])
." AND pa.value "
.$key_comp_val[1]
.$dbr->addQuotes($key_comp_val[2])
.")";
.")";
}
}
# annotation
......@@ -129,6 +131,7 @@ class YATA {
else {
$where["a.$field"] = $values;
}
$search_in_annotations = true;
}
}
......@@ -138,45 +141,75 @@ class YATA {
}
return $errstr;
}
//var_dump($where);
//die();
# fetch the annotation details
$annotations = $dbr->select(
array(
'a' => 'yata_annotation',
'u' => 'user',
'ac'=> 'yata_annotation_category',
'c' => 'yata_category',
'pc'=> 'yata_category',
'p' => 'page',
),
array(
'category' => "c.name",
'parent_category' => "pc.name",
'hashtag' => "c.hashtag",
'title' => "p.page_title",
'comment' => "a.comment",
'wiki_text' => "a.wiki_text",
'start_char' => "a.start_char",
'bookmark' => "a.bookmark",
'last_edited_by' => "u.user_name",
'last_modified' => "a.modified_date"
),
$where,
__METHOD__,
array(
'ORDER BY' => 'a.start_char ASC'
),
array(
'u' => array( 'LEFT JOIN', array( 'u.user_id = a.user_id') ),
'ac' => array( 'LEFT JOIN', array( 'ac.annotation_id = a.id' ) ),
'c' => array( 'LEFT JOIN', array( 'ac.category_id = c.id' ) ),
'pc' => array( 'LEFT JOIN', array( 'pc.id = c.parent_id') ),
'p' => array( 'INNER JOIN', array( 'p.page_id = a.page_id') ),
)
);
$annotations = null;
if ($search_in_annotations) {
# fetch the annotation details
$annotations = $dbr->select(
array(
'p' => 'page',
'a' => 'yata_annotation',
'u' => 'user',
'ac'=> 'yata_annotation_category',
'c' => 'yata_category',
'pc'=> 'yata_category',
),
array(
'page_id' => "p.page_id",
'category' => "c.name",
'parent_category' => "pc.name",
'hashtag' => "c.hashtag",
'title' => "p.page_title",
'comment' => "a.comment",
'wiki_text' => "a.wiki_text",
'start_char' => "a.start_char",
'bookmark' => "a.bookmark",
'last_edited_by' => "u.user_name",
'last_modified' => "a.modified_date",
),
$where,
__METHOD__,
array(
'ORDER BY' => 'a.start_char ASC'
),
array(
'u' => array( 'LEFT JOIN', array( 'u.user_id = a.user_id') ),
'ac' => array( 'LEFT JOIN', array( 'ac.annotation_id = a.id' ) ),
'c' => array( 'LEFT JOIN', array( 'ac.category_id = c.id' ) ),
'pc' => array( 'LEFT JOIN', array( 'pc.id = c.parent_id') ),
'p' => array( 'LEFT JOIN', array( 'p.page_id = a.page_id') ),
)
);
}
else {
# fetch the annotation details
$annotations = $dbr->select(
array(
'p' => 'page',
),
array(
'page_id' => "p.page_id",
'category' => "NULL",
'parent_category' => "NULL",
'hashtag' => "NULL",
'title' => "p.page_title",
'comment' => "NULL",
'wiki_text' => "NULL",
'start_char' => "NULL",
'bookmark' => "NULL",
'last_edited_by' => "NULL",
'last_modified' => "NULL",
),
$where,
__METHOD__,
array(
),
array(
)
);
}
//print($dbr->lastQuery($annotations));
//die();
$table = "";
if ($searches) {
......@@ -191,9 +224,11 @@ class YATA {
$table .= "<pre>".$category."</pre>";
}
}
$table .= "<b>Results</b> ";
$table .= "<b>Results of annotask query: </b>";
$table .= '([' . $title->getFullURL() . '?action=purge' . ' refresh page]):';
if (count($annotations)>0) {
if ($dbr->numRows($annotations) > 0) {
$table .= '
<table class="wikitable sortable jquery-tablesorter">
<tr>
......@@ -203,6 +238,7 @@ class YATA {
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending"> Annotated text </th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending"> Last edited by </th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending"> Modification date </th>
<th class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending"> Page Attributes </th>
</tr>';
# compose the wiki table
......@@ -211,22 +247,37 @@ class YATA {
# in all other cases show parent_category:child_category
$cat = $annotation->parent_category ? $annotation->parent_category . "/" . $annotation->category : $annotation->category;
$wikitext = $annotation->wiki_text;
$wikitext = htmlentities($wikitext, ENT_QUOTES);
$a = array('=', '{', '|', '}');
$b = array('&#61;', '&#123;', '&#124;', '&#125;');
$wikitext = str_replace($a, $b, $wikitext);
$link = null;
if ($annotation && $annotation->bookmark) {
$link = "[[".$annotation->title."#".$annotation->bookmark."]]";
}
else {
$link = "[[".$annotation->title."]]";
}
$table .= "<tr><td>".$cat
."</td><td>".$annotation->comment
."</td><td>[[".$annotation->title."#".$annotation->bookmark . "]]"
."</td><td>". $link
."</td><td><pre>" . $wikitext . "</pre>"
#." || "
."</td><td>" . $annotation->last_edited_by
."</td><td>" . wfTimestamp( TS_ISO_8601, $annotation->last_modified)
."</td></tr>\n";
."</td>";
$p_annotations = self::get_page_annotations($dbr, $annotation->page_id);
$td = "<td>";
foreach ($p_annotations as $p_annotation) {
$td .= $p_annotation->name . ": ". $p_annotation->value . "<br/>";
}
$td .= "</td>";
$table .= $td;
$table .= "</tr>\n";
}
$table .= "</table>";
}
......@@ -381,7 +432,7 @@ EOT;
$wikiPage->doPurge();
$dbr = wfGetDB( DB_MASTER );
$annotations = self::get_page_annotations($dbr, $wikiPage );
$annotations = self::get_page_annotations($dbr, $wikiPage->getId() );
$table = <<<"EOT"
{| class="wikitable sortable"
......@@ -615,7 +666,7 @@ EOT;
);
}
$ex_page_annotations = self::get_page_annotations($dbw, $wikiPage);
$ex_page_annotations = self::get_page_annotations($dbw, $wikiPage->getId());
$ex_annotations = array();
if ($ex_page_annotations) {
foreach ($ex_page_annotations as $ex_page_annotation) {
......@@ -842,10 +893,10 @@ EOT;
return $row;
}
public static function get_page_annotations($dbr, $wikiPage) {
public static function get_page_annotations($dbr, $page_id) {
$order_by = array('ORDER BY' => 'name');
$where = array(
'pa.page_id' => $wikiPage->getId()
'pa.page_id' => $page_id
);
$annotations = $dbr->select(
......@@ -1108,13 +1159,13 @@ EOT;
// Will match key and values that are:
// within single quotes ' \'.*?(?<!\\\\)\'
// within double quotes " \".*?(?<!\\\\)\"
// with no quotes at all (and no spaces): [^\s]+
// including one of these comperators: = <> >= <=
// with no quotes at all (may contain no spaces or any comperator char): [^\<\>\=\s]+
// allowed comperators: = <> >= <= < >
$key_comp_vals = array();
$re =
'/(?P<key>\'.*?(?<!\\\\)\'|\".*?(?<!\\\\)\"|[^\s]+)'
.'\s*?(?P<comp>\=|\<\>|\>\=|\<\=)\s*?'
'/(?P<key>\'.*?(?<!\\\\)\'|\".*?(?<!\\\\)\"|[^\<\>\=\s]+)'
.'\s*?(?P<comp>\=|\<\>|\>\=|\>|\<\=|\<)\s*?'
.'(?P<val>\'.*?(?<!\\\\)\'|\".*?(?<!\\\\)\"|[^\s]+)/';
preg_match_all($re, $string, $matches, PREG_SET_ORDER, 0);
foreach($matches as $match) {
......@@ -1170,7 +1221,6 @@ EOT;
# we encountered an annotation ending
if ($reg_params["page"][$index][0] === "page") {
//print($reg_params["page"][$index][0]);
$opts = $reg_params["opts"][$index][0];
// Match key-value pairs.
......@@ -1190,7 +1240,6 @@ EOT;
$val = trim($match["val"], " '\"");
$page_annotations[$key] = $val;
}
//var_dump($page_annotations);
}
# we encountered an annotation ending
......
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