コード例 #1
0
ファイル: Categorize.body.php プロジェクト: Tjorriemorrie/app
 public static function fnCategorizeGetPageCategories($m_pageObj)
 {
     global $wgOut;
     # Get page contents:
     $m_pageText = $m_pageObj->textbox1;
     $arrAllCats = array();
     $regulartext = '';
     $nowikitext = '';
     $cleanedtext = '';
     $finaltext = '';
     # Check linewise for category links:
     # Get the first part of the text up until the first <nowiki> tag.
     $arrBlocks1 = explode("<nowiki>", $m_pageText);
     $regulartext = $arrBlocks1[0];
     # Get and strip categories from the first part
     $cleanedtext = CategorizeBody::fnCategorizeStripCats($regulartext, $arrAllCats);
     $finaltext .= $cleanedtext;
     # Go through the rest of the blocks to find more categories
     for ($i = 1; $i < count($arrBlocks1); $i++) {
         $arrBlocks2 = explode("</nowiki>", $arrBlocks1[$i]);
         // ignore cats here because it is part of the <nowiki> block
         $nowikitext = $arrBlocks2[0];
         // add to final text
         $finaltext .= '<nowiki>' . $nowikitext . '</nowiki> ';
         // strip cats here because it's the text after the <nowiki> block
         $regulartext = $arrBlocks2[1];
         $cleanedtext = CategorizeBody::fnCategorizeStripCats($regulartext, $arrAllCats);
         $finaltext .= ltrim($cleanedtext);
     }
     // Place cleaned text back into the text box:
     $m_pageObj->textbox1 = rtrim($finaltext);
     return $arrAllCats;
 }
コード例 #2
0
 public static function fnCategorizeShowHook($m_isUpload = false, &$m_pageObj)
 {
     global $wgOut, $wgParser, $wgTitle, $wgRequest, $wgScriptPath;
     global $wgTitle, $wgScriptPath, $wgCategorizeCloud, $wgCategorizejs, $wgCategorizecss;
     global $wgCategorizeLabels;
     # Get ALL categories from wiki:
     //		$m_allCats = fnAjaxSuggestGetAllCategories();
     # Get the right member variables, depending on if we're on an upload form or not:
     if (!$m_isUpload) {
         # Check if page is subpage once to save method calls later:
         $m_isSubpage = $wgTitle->isSubpage();
         # Check if page has been submitted already to Preview or Show Changes
         $strCatsFromPreview = trim($wgRequest->getVal('txtSelectedCategories2'));
         if (strlen($strCatsFromPreview) == 0) {
             # Extract all categorylinks from PAGE:
             $m_pageCats = CategorizeBody::fnCategorizeGetPageCategories($m_pageObj);
         } else {
             # Get cats from preview
             $m_pageCats = explode(";", $strCatsFromPreview);
         }
         # Never ever use editFormTextTop here as it resides outside the <form> so we will never get contents
         $m_place = 'editFormTextAfterWarn';
         # Print the localised title for the select box:
         $m_textBefore = '<b>' . wfMsg('categorize-title') . '</b>:';
     } else {
         # No need to get categories:
         $m_pageCats = array();
         # Place output at the right place:
         $m_place = 'uploadFormTextAfterSummary';
     }
     # ADD EXISTING CATEGORIES TO INPUT BOX
     $arrExistingCats = array();
     $arrExistingCats = array_unique($m_pageCats);
     # ADD JAVASCRIPT - use document.write so it is not presented if javascript is disabled.
     $m_pageObj->{$m_place} .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$wgScriptPath}/extensions/Categorize/Categorize.css\" />\n\t\n";
     # provisoire
     $m_pageObj->{$m_place} .= "<script type=\"text/javascript\" src=\"{$wgScriptPath}/extensions/Categorize/jquery.js\"></script>\n";
     $m_pageObj->{$m_place} .= "<script type=\"text/javascript\">var xSelectedLabels = new Array();</script>\n";
     foreach ($arrExistingCats as $arrExistingCat) {
         $m_pageObj->{$m_place} .= "<script type=\"text/javascript\">xSelectedLabels['{$arrExistingCat}']=1;</script>\n";
     }
     $m_pageObj->{$m_place} .= "<script type=\"text/javascript\" src=\"" . $wgCategorizejs . "\"></script>\n";
     $m_pageObj->{$m_place} .= "<script type=\"text/javascript\">/*<![CDATA[*/\n";
     $m_pageObj->{$m_place} .= "document.write(\"<div id='categoryselectmaster2'><div style='border-bottom:1px solid #AAAAAA;'><b>" . wfMsg('categorize-title') . "</b></div>\");\n";
     $m_pageObj->{$m_place} .= "document.write(\"<p>" . wfMsg('categorize-subtitle') . "</p>\");\n";
     $m_pageObj->{$m_place} .= "document.write(\"\");\n";
     $m_pageObj->{$m_place} .= "document.write(\"<input onkeyup='sendRequest(this,event);' autocomplete='off' type='text' name='txtSelectedCategories2' id='txtSelectedCategories2' maxlength='200' length='150' style='width:100%;' value='" . str_replace("_", " ", implode(";", $arrExistingCats)) . "'/>\");\n";
     $m_pageObj->{$m_place} .= "document.write(\"<br/><div id='searchResults'></div>\");\n";
     $m_pageObj->{$m_place} .= "document.write(\"<input type='hidden' value='" . $wgCategorySuggestCloud . "' id='txtCSDisplayType'/>\");\n";
     $m_pageObj->{$m_place} .= "document.write(\"<p>" . wfMsg('categorize-advice') . "</p>\");\n";
     $m_pageObj->{$m_place} .= "document.write(\"<p><table id='xtable'>\");\n";
     $l__categorize_index = 0;
     foreach ($wgCategorizeLabels as $l__label_key => $l__label_array) {
         $m_pageObj->{$m_place} .= "document.write(\"<tr>\");\n";
         if (substr($l__label_key, 0, 9) == 'separator') {
             $m_pageObj->{$m_place} .= "document.write(\"<td colspan=2> <hr/>\");\n";
         } else {
             $l__categorize_index += 1;
             $l__key_value_to_print = utf8_encode(str_replace("_", "&nbsp;", $l__label_key));
             $l__xselected = in_array($l__key_value_to_print, $arrExistingCats) ? 'xselected' : '';
             $m_pageObj->{$m_place} .= "document.write(\"<th style='text-align:left;'><span class='xlabel xmaster xcategorize{$l__categorize_index} {$l__xselected}'>{$l__key_value_to_print}</span></th><td> \");\n";
             foreach ($l__label_array as $l__label_value) {
                 $l__label_value_to_print = utf8_encode(str_replace("_", " ", $l__label_value));
                 $l__xselected = in_array($l__label_value_to_print, $arrExistingCats) ? 'xselected' : '';
                 $m_pageObj->{$m_place} .= "document.write(\"<span class='xlabel xcategorize{$l__categorize_index} {$l__xselected}'>{$l__label_value_to_print}</span>\");\n";
             }
             $m_pageObj->{$m_place} .= "document.write(\"</td></tr>\");\n";
         }
     }
     $m_pageObj->{$m_place} .= "document.write(\"</table></p>\");\n";
     $m_pageObj->{$m_place} .= "document.write(\"<p>" . wfMsg('categorize-footer') . "</p>\");\n";
     $m_pageObj->{$m_place} .= "document.write(\"</div>\");\n";
     $m_pageObj->{$m_place} .= "/*]]>*/</script>\n";
     return true;
 }