Ejemplo n.º 1
0
 /**
  * Retrieve short text from provided article
  *
  * This is a way to access a functionality of private __getRevisionText method
  *
  * @author Kamil Koterba
  * @since June 2013
  *
  * @param integer $iPage Page id
  * @param Revision $oRev Revision of article to get text from
  * @return mixed|string
  */
 public static function getShortText($iPage, Revision $oRev)
 {
     wfProfileIn(__METHOD__);
     // backup current value
     $aOptions_bck = self::$aOptions;
     // set options required to retrieve short text
     self::$aOptions = array('type' => 'plain', 'summary' => 'true');
     // get short text
     $shortText = self::__getRevisionText($iPage, $oRev);
     // restore options
     self::$aOptions = $aOptions_bck;
     wfProfileOut(__METHOD__);
     return $shortText;
 }
Ejemplo n.º 2
0
 private static function __parse($aInput, $aParams, &$parser, $returnPlainData = false)
 {
     global $wgLang, $wgUser, $wgCityId, $wgParser, $wgTitle;
     global $wgExtensionsPath, $wgStylePath, $wgRequest;
     wfProfileIn(__METHOD__);
     /** 
      * because this parser tag contains elements of interface we need to 
      * inform parser to vary parser cache key by user lang option
      **/
     $parser->mOutput->recordOption('userlang');
     $result = "";
     self::$aTables = self::$aWhere = self::$aOptions = array();
     self::$dbr = null;
     /* default settings for query */
     self::__setDefault();
     $showOnlyPage = 0;
     try {
         /* database connect */
         self::$dbr = wfGetDB(DB_SLAVE, 'dpl');
         /* parse parameters as XML tags */
         wfDebugLog(__METHOD__, "parse " . count($aInput) . " parameters (XML tags)\n");
         $relationArray = array();
         foreach ($aInput as $sParamName => $aParamValues) {
             /* ignore empty lines */
             if (empty($aParamValues)) {
                 wfDebugLog(__METHOD__, "ignore empty param: " . $sParamName . " \n");
                 continue;
             }
             /* invalid name of parameter or empty name */
             if (!in_array($sParamName, array_keys(self::$aBlogParams))) {
                 throw new Exception(wfMsg('blog-invalidparam', $sParamName, implode(", ", array_keys(self::$aBlogParams))));
             } elseif (trim($sParamName) == '') {
                 throw new Exception(wfMsg('blog-emptyparam'));
             }
             /* ignore comment lines */
             if ($sParamName[0] == '#') {
                 wfDebugLog(__METHOD__, "ignore comment line: " . $sParamName . " \n");
                 continue;
             }
             /* parse value of parameter */
             switch ($sParamName) {
                 case 'category':
                     if (!empty($aParamValues)) {
                         $aParamValues = array_slice($aParamValues, 0, self::$aBlogParams[$sParamName]['count']);
                         $aParamValues = str_replace(" ", "_", $aParamValues);
                         if (!empty($aParamValues) && is_array($aParamValues)) {
                             $relationArray[$sParamName] = $aParamValues;
                         }
                         $aPages = self::__getCategories($aParamValues, $parser);
                         if (!empty($aPages)) {
                             self::$aWhere[] = "page_id in (" . implode(",", $aPages) . ")";
                         } else {
                             self::$aWhere[] = "page_id = 0";
                         }
                     }
                     break;
                 case 'pages':
                     if (!empty($aParamValues)) {
                         $showOnlyPage = $aParamValues;
                     }
                     break;
                 case 'author':
                     if (!empty($aParamValues)) {
                         $aParamValues = array_slice($aParamValues, 0, self::$aBlogParams[$sParamName]['count']);
                         if (!empty($aParamValues) && is_array($aParamValues)) {
                             $relationArray[$sParamName] = $aParamValues;
                             $aTmpWhere = array();
                             foreach ($aParamValues as $id => $sParamValue) {
                                 $sParamValue = str_replace(" ", "_", $sParamValue);
                                 $aTmpWhere[] = "page_title like '" . addslashes($sParamValue) . "/%'";
                             }
                             if (!empty($aTmpWhere)) {
                                 self::$aWhere[] = implode(" OR ", $aTmpWhere);
                             }
                         }
                     }
                     break;
                 case 'order':
                     if (!empty($aParamValues) && is_array($aParamValues)) {
                         list($sParamValue) = $aParamValues;
                         self::__makeOrder($sParamName, $sParamValue);
                     }
                     break;
                 case 'ordertype':
                 case 'type':
                     if (!empty($aParamValues) && is_array($aParamValues)) {
                         list($sParamValue) = $aParamValues;
                         self::__makeListOption($sParamName, $sParamValue);
                     }
                     break;
                 case 'count':
                 case 'displaycount':
                 case 'offset':
                 case 'summarylength':
                 case 'create_timestamp':
                 case 'timestamp':
                     if (!empty($aParamValues) && is_array($aParamValues)) {
                         list($sParamValue) = $aParamValues;
                         self::__makeIntOption($sParamName, $sParamValue);
                     }
                     break;
                 case 'summary':
                 case 'paging':
                     if (!empty($aParamValues) && is_array($aParamValues)) {
                         list($sParamValue) = $aParamValues;
                         self::__makeBoolOption($sParamName, $sParamValue);
                     }
                     break;
                 case 'seemore':
                 case 'title':
                 case 'class':
                 case 'style':
                     if (!empty($aParamValues) && is_array($aParamValues)) {
                         list($sParamValue) = $aParamValues;
                         self::__makeStringOption($sParamName, $sParamValue);
                     }
                     break;
             }
         }
         wfRunHooks('BlogListAfterParse', array(self::$oTitle, $relationArray));
         /* */
         if (!empty($showOnlyPage)) {
             self::$aWhere = array("page_id in (" . self::$dbr->makeList($showOnlyPage) . ")");
         }
         /* parse parameters */
         foreach ($aParams as $sParamName => $sParamValue) {
             /* ignore empty lines */
             if (!isset($sParamValue)) {
                 wfDebugLog(__METHOD__, "ignore empty param: " . $sParamName . " \n");
                 continue;
             }
             /* invalid name of parameter or empty name */
             if (!in_array($sParamName, array_keys(self::$aBlogParams))) {
                 throw new Exception(wfMsg('blog-invalidparam', $sParamName, implode(", ", array_keys(self::$aBlogParams))));
             }
             /* parse value of parameter */
             switch ($sParamName) {
                 case 'order':
                     self::__makeOrder($sParamName, $sParamValue);
                     break;
                 case 'ordertype':
                 case 'type':
                     self::__makeListOption($sParamName, $sParamValue);
                     break;
                 case 'count':
                 case 'displaycount':
                 case 'offset':
                 case 'create_timestamp':
                 case 'timestamp':
                 case 'summarylength':
                     self::__makeIntOption($sParamName, $sParamValue);
                     break;
                 case 'summary':
                 case 'paging':
                     self::__makeBoolOption($sParamName, $sParamValue);
                     break;
                 case 'seemore':
                 case 'title':
                 case 'class':
                 case 'style':
                     self::__makeStringOption($sParamName, $sParamValue);
                     break;
             }
         }
         // Allows caller to turn off paging of results
         if (self::$aOptions['paging'] == true) {
             $__pageVal = $wgRequest->getVal('page');
             if (isset($__pageVal) && !empty($__pageVal)) {
                 $count = intval(self::$aOptions['count']);
                 self::__makeIntOption('offset', $count * $__pageVal);
             }
         }
         # use revision table to get results
         self::__addRevisionTable();
         /* build query */
         if ($returnPlainData) {
             return self::__getResults();
         } else {
             if (self::$aOptions['type'] == 'count') {
                 /* get results count */
                 $result = self::getResultsCount();
             } else {
                 $aResult = self::__getResults();
                 /* set output */
                 if (!empty($aResult)) {
                     if (self::$aOptions['type'] != 'array') {
                         $sPager = "";
                         if (self::$aOptions['type'] == 'plain') {
                             $iCount = self::getResultsCount();
                             $sPager = self::__getPager($iCount, intval(self::$aOptions['offset']));
                         }
                         if (F::app()->checkSkin('oasis')) {
                             wfRunHooks('BlogsRenderBlogArticlePage', array(&$result, $aResult, self::$aOptions, $sPager));
                         } else {
                             /* run template */
                             $oTmpl = new EasyTemplate(dirname(__FILE__) . "/templates/");
                             $oTmpl->set_vars(array("wgUser" => $wgUser, "cityId" => $wgCityId, "wgLang" => $wgLang, "aRows" => $aResult, "aOptions" => self::$aOptions, "wgParser" => $wgParser, "skin" => RequestContext::getMain()->getSkin(), "wgExtensionsPath" => $wgExtensionsPath, "wgStylePath" => $wgStylePath, "sPager" => $sPager, "wgTitle" => self::$oTitle));
                             #---
                             if (self::$aOptions['type'] == 'box') {
                                 $result = $oTmpl->render("blog-page");
                             } else {
                                 $page = $oTmpl->render("blog-post-page");
                                 $oTmpl->set_vars(array("page" => $page));
                                 $result = $oTmpl->render("blog-article-page");
                             }
                         }
                     } else {
                         unset($result);
                         $result = self::__makeRssOutput($aResult);
                     }
                 } else {
                     if (!empty(self::$oTitle) && self::$oTitle->getNamespace() == NS_BLOG_ARTICLE) {
                         $result = wfMsgExt('blog-empty-user-blog', array('parse'));
                     } else {
                         if (self::$aOptions['type'] != 'array') {
                             //$sk = RequestContext::getMain()->getSkin();
                             $result = "";
                             // RT #69906
                             // $result = wfMsg('blog-nopostfound') . " " . $sk->makeLinkObj(Title::newFromText('CreateBlogPage', NS_SPECIAL), wfMsg('blog-writeone' ) );
                         } else {
                             $result = "";
                         }
                     }
                 }
             }
         }
     } catch (Exception $e) {
         wfDebugLog(__METHOD__, "parse error: " . $e->getMessage() . "\n");
         wfProfileOut(__METHOD__);
         return $e->getMessage();
     }
     wfProfileOut(__METHOD__);
     return $result;
 }