Esempio n. 1
0
 function getSubject($index)
 {
     if (Namespac::isTalk($index)) {
         return $index - 1;
     } else {
         return $index;
     }
 }
Esempio n. 2
0
 static function ns($parser, $part1 = '')
 {
     global $wgContLang;
     $found = false;
     if (intval($part1) || $part1 == "0") {
         $text = $wgContLang->getNsText(intval($part1));
         $found = true;
     } else {
         $param = str_replace(' ', '_', strtolower($part1));
         $index = Namespac::getCanonicalIndex(strtolower($param));
         if (!is_null($index)) {
             $text = $wgContLang->getNsText($index);
             $found = true;
         }
     }
     if ($found) {
         return $text;
     } else {
         return array('found' => false);
     }
 }
Esempio n. 3
0
/**
 * Constructor
 * @todo Document $par parameter.
 * @param $par String: FIXME
 */
function wfSpecialWatchlist($par)
{
    global $wgUser, $wgOut, $wgLang, $wgMemc, $wgRequest, $wgContLang;
    global $wgUseWatchlistCache, $wgWLCacheTimeout, $wgDBname;
    global $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker;
    global $wgEnotifWatchlist;
    $fname = 'wfSpecialWatchlist';
    $skin =& $wgUser->getSkin();
    $specialTitle = Title::makeTitle(NS_SPECIAL, 'Watchlist');
    $wgOut->setRobotPolicy('noindex,nofollow');
    # Anons don't get a watchlist
    if ($wgUser->isAnon()) {
        $wgOut->setPageTitle(wfMsg('watchnologin'));
        $llink = $skin->makeKnownLinkObj(Title::makeTitle(NS_SPECIAL, 'Userlogin'), wfMsgHtml('loginreqlink'), 'returnto=' . $specialTitle->getPrefixedUrl());
        $wgOut->addHtml(wfMsgWikiHtml('watchlistanontext', $llink));
        return;
    } else {
        $wgOut->setPageTitle(wfMsg('watchlist'));
        $wgOut->setSubtitle(wfMsgWikiHtml('watchlistfor', htmlspecialchars($wgUser->getName())));
    }
    if (wlHandleClear($wgOut, $wgRequest, $par)) {
        return;
    }
    $defaults = array('days' => floatval($wgUser->getOption('watchlistdays')), 'hideOwn' => (int) $wgUser->getBoolOption('watchlisthideown'), 'hideBots' => (int) $wgUser->getBoolOption('watchlisthidebots'), 'namespace' => 'all');
    extract($defaults);
    # Extract variables from the request, falling back to user preferences or
    # other default values if these don't exist
    $prefs['days'] = floatval($wgUser->getOption('watchlistdays'));
    $prefs['hideown'] = $wgUser->getBoolOption('watchlisthideown');
    $prefs['hidebots'] = $wgUser->getBoolOption('watchlisthidebots');
    # Get query variables
    $days = $wgRequest->getVal('days', $prefs['days']);
    $hideOwn = $wgRequest->getBool('hideOwn', $prefs['hideown']);
    $hideBots = $wgRequest->getBool('hideBots', $prefs['hidebots']);
    # Get namespace value, if supplied, and prepare a WHERE fragment
    $nameSpace = $wgRequest->getIntOrNull('namespace');
    if (!is_null($nameSpace)) {
        $nameSpace = intval($nameSpace);
        $nameSpaceClause = " AND rc_namespace = {$nameSpace}";
    } else {
        $nameSpace = '';
        $nameSpaceClause = '';
    }
    # Watchlist editing
    $action = $wgRequest->getVal('action');
    $remove = $wgRequest->getVal('remove');
    $id = $wgRequest->getArray('id');
    $uid = $wgUser->getID();
    if ($wgEnotifWatchlist && $wgRequest->getVal('reset') && $wgRequest->wasPosted()) {
        $wgUser->clearAllNotifications($uid);
    }
    # Deleting items from watchlist
    if ($action == 'submit' && isset($remove) && is_array($id)) {
        $wgOut->addWikiText(wfMsg('removingchecked'));
        $wgOut->addHTML('<p>');
        foreach ($id as $one) {
            $t = Title::newFromURL($one);
            if (!is_null($t)) {
                // WERELATE - run UnwatchArticle hooks; fix UnwatchArticle hook below to UnwatchArticleComplete
                $article = new Article($t);
                if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$article))) {
                    $wl = WatchedItem::fromUserTitle($wgUser, $t);
                    if ($wl->removeWatch() === false) {
                        $wgOut->addHTML("<br />\n" . wfMsg('couldntremove', htmlspecialchars($one)));
                    } else {
                        wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$article));
                        $wgOut->addHTML(' (' . htmlspecialchars($one) . ')');
                    }
                }
            } else {
                $wgOut->addHTML("<br />\n" . wfMsg('iteminvalidname', htmlspecialchars($one)));
            }
        }
        $wgOut->addHTML("<br />\n" . wfMsg('wldone') . "</p>\n");
    }
    if ($wgUseWatchlistCache) {
        $memckey = "{$wgDBname}:watchlist:id:" . $wgUser->getId();
        $cache_s = @$wgMemc->get($memckey);
        if ($cache_s) {
            $wgOut->addWikiText(wfMsg('wlsaved'));
            $wgOut->addHTML($cache_s);
            return;
        }
    }
    $dbr =& wfGetDB(DB_SLAVE);
    extract($dbr->tableNames('page', 'revision', 'watchlist', 'recentchanges'));
    $sql = "SELECT COUNT(*) AS n FROM {$watchlist} WHERE wl_user={$uid}";
    $res = $dbr->query($sql, $fname);
    $s = $dbr->fetchObject($res);
    #	Patch *** A1 *** (see A2 below)
    #	adjust for page X, talk:page X, which are both stored separately, but treated together
    $nitems = floor($s->n / 2);
    #	$nitems = $s->n;
    if ($nitems == 0) {
        $wgOut->addWikiText(wfMsg('nowatchlist'));
        return;
    }
    if (is_null($days) || !is_numeric($days)) {
        $big = 1000;
        /* The magical big */
        // WERELATE - don't change default; pages don't change that often
        //		if($nitems > $big) {
        # Set default cutoff shorter
        //			$days = $defaults['days'] = (12.0 / 24.0); # 12 hours...
        //		} else {
        $days = $defaults['days'];
        # default cutoff for shortlisters
        //		}
    } else {
        $days = floatval($days);
    }
    // Dump everything here
    $nondefaults = array();
    wfAppendToArrayIfNotDefault('days', $days, $defaults, $nondefaults);
    wfAppendToArrayIfNotDefault('hideOwn', (int) $hideOwn, $defaults, $nondefaults);
    wfAppendToArrayIfNotDefault('hideBots', (int) $hideBots, $defaults, $nondefaults);
    wfAppendToArrayIfNotDefault('namespace', $nameSpace, $defaults, $nondefaults);
    if ($days <= 0) {
        $docutoff = '';
        $cutoff = false;
        $npages = wfMsg('watchlistall1');
    } else {
        $docutoff = "AND rev_timestamp > '" . ($cutoff = $dbr->timestamp(time() - intval($days * 86400))) . "'";
        /*
        $sql = "SELECT COUNT(*) AS n FROM $page, $revision  WHERE rev_timestamp>'$cutoff' AND page_id=rev_page";
        $res = $dbr->query( $sql, $fname );
        $s = $dbr->fetchObject( $res );
        $npages = $s->n;
        */
        $npages = 40000 * $days;
    }
    /* Edit watchlist form */
    if ($wgRequest->getBool('edit') || $par == 'edit') {
        $wgOut->addWikiText(wfMsg('watchlistcontains', $wgLang->formatNum($nitems)) . "\n\n" . wfMsg('watcheditlist'));
        $wgOut->addHTML('<form action=\'' . $specialTitle->escapeLocalUrl('action=submit') . "' method='post'>\n");
        #		Patch A2
        #		The following was proposed by KTurner 07.11.2004 to T.Gries
        #		$sql = "SELECT distinct (wl_namespace & ~1),wl_title FROM $watchlist WHERE wl_user=$uid";
        $sql = "SELECT wl_namespace, wl_title, page_is_redirect FROM {$watchlist} LEFT JOIN {$page} ON wl_namespace = page_namespace AND wl_title = page_title WHERE wl_user={$uid}";
        $res = $dbr->query($sql, $fname);
        # Batch existence check
        $linkBatch = new LinkBatch();
        while ($row = $dbr->fetchObject($res)) {
            $linkBatch->addObj(Title::makeTitleSafe($row->wl_namespace, $row->wl_title));
        }
        $linkBatch->execute();
        if ($dbr->numRows($res) > 0) {
            $dbr->dataSeek($res, 0);
        }
        # Let's do the time warp again!
        $sk = $wgUser->getSkin();
        $list = array();
        while ($s = $dbr->fetchObject($res)) {
            $list[$s->wl_namespace][$s->wl_title] = $s->page_is_redirect;
        }
        // TODO: Display a TOC
        foreach ($list as $ns => $titles) {
            if (Namespac::isTalk($ns)) {
                continue;
            }
            if ($ns != NS_MAIN) {
                $wgOut->addHTML('<h2>' . $wgContLang->getFormattedNsText($ns) . '</h2>');
            }
            $wgOut->addHTML('<ul>');
            foreach ($titles as $title => $redir) {
                $titleObj = Title::makeTitle($ns, $title);
                if (is_null($titleObj)) {
                    $wgOut->addHTML('<!-- bad title "' . htmlspecialchars($s->wl_title) . '" in namespace ' . $s->wl_namespace . " -->\n");
                } else {
                    global $wgContLang;
                    $toolLinks = array();
                    $titleText = $titleObj->getPrefixedText();
                    $pageLink = $sk->makeLinkObj($titleObj);
                    $toolLinks[] = $sk->makeLinkObj($titleObj->getTalkPage(), $wgLang->getNsText(NS_TALK));
                    if ($titleObj->exists()) {
                        $toolLinks[] = $sk->makeKnownLinkObj($titleObj, wfMsgHtml('history_short'), 'action=history');
                    }
                    $toolLinks = '(' . implode(' | ', $toolLinks) . ')';
                    $checkbox = '<input type="checkbox" name="id[]" value="' . htmlspecialchars($titleObj->getPrefixedText()) . '" /> ' . ($wgContLang->isRTL() ? '&rlm;' : '&lrm;');
                    if ($redir) {
                        $spanopen = '<span class="watchlistredir">';
                        $spanclosed = '</span>';
                    } else {
                        $spanopen = $spanclosed = '';
                    }
                    $wgOut->addHTML("<li>{$checkbox}{$spanopen}{$pageLink}{$spanclosed} {$toolLinks}</li>\n");
                }
            }
            $wgOut->addHTML('</ul>');
        }
        $wgOut->addHTML("<input type='submit' name='remove' value=\"" . htmlspecialchars(wfMsg("removechecked")) . "\" />\n" . "</form>\n");
        return;
    }
    # If the watchlist is relatively short, it's simplest to zip
    # down its entirety and then sort the results.
    # If it's relatively long, it may be worth our while to zip
    # through the time-sorted page list checking for watched items.
    # Up estimate of watched items by 15% to compensate for talk pages...
    # Toggles
    $andHideOwn = $hideOwn ? "AND (rc_user <> {$uid})" : '';
    $andHideBots = $hideBots ? "AND (rc_bot = 0)" : '';
    # Show watchlist header
    $header = '';
    if ($wgUser->getOption('enotifwatchlistpages') && $wgEnotifWatchlist) {
        $header .= wfMsg('wlheader-enotif') . "\n";
    }
    if ($wgEnotifWatchlist && $wgShowUpdatedMarker) {
        $header .= wfMsg('wlheader-showupdated') . "\n";
    }
    # Toggle watchlist content (all recent edits or just the latest)
    if ($wgUser->getOption('extendwatchlist')) {
        $andLatest = '';
        $limitWatchlist = 'LIMIT ' . intval($wgUser->getOption('wllimit'));
    } else {
        $andLatest = 'AND rc_this_oldid=page_latest';
        $limitWatchlist = '';
    }
    # TODO: Consider removing the third parameter
    $header .= wfMsg('watchdetails', $wgLang->formatNum($nitems), $wgLang->formatNum($npages), '', $specialTitle->getFullUrl('edit=yes'));
    $wgOut->addWikiText($header);
    if ($wgEnotifWatchlist && $wgShowUpdatedMarker) {
        $wgOut->addHTML('<form action="' . $specialTitle->escapeLocalUrl() . '" method="post"><input type="submit" name="dummy" value="' . htmlspecialchars(wfMsg('enotif_reset')) . '" /><input type="hidden" name="reset" value="all" /></form>' . "\n\n");
    }
    // WERELATE - handle changed view
    if ($wgRequest->getBool('changed') || $par == 'changed') {
        $wgOut->addHTML('<hr /><h2>All pages changed since last visited</h2><ul><li><a href="' . $specialTitle->getFullUrl() . '">Show recently-changed pages</a></li></ul>');
        $sql = 'select wl_namespace, wl_title from watchlist where wl_user='******' and wl_notificationtimestamp > \'0\'';
        $res = $dbr->query($sql, $fname);
        $sk = $wgUser->getSkin();
        $changed = '';
        $count = 0;
        while ($obj = $dbr->fetchObject($res)) {
            $t = Title::makeTitle($obj->wl_namespace, $obj->wl_title);
            $historylink = $sk->makeKnownLinkObj($t, 'hist', wfArrayToCGI(array('action' => 'history')));
            $articlelink = $sk->makeKnownLinkObj($t);
            $changed .= "<li> ( {$historylink} ) . . {$articlelink}</li>\n";
            $count += 1;
        }
        $dbr->freeResult($res);
        $wgOut->addHTML("<h3>{$count} page(s)</h3>\n<ul>" . $changed . '</ul>');
        return;
    }
    // WERELATE - remove join with page table
    $sql = "SELECT\n\t  rc_namespace AS page_namespace, rc_title AS page_title,\n\t  rc_comment AS rev_comment, rc_cur_id AS page_id,\n\t  rc_user AS rev_user, rc_user_text AS rev_user_text,\n\t  rc_timestamp AS rev_timestamp, rc_minor AS rev_minor_edit,\n\t  rc_this_oldid AS rev_id,\n\t  rc_last_oldid, rc_id, rc_patrolled,\n\t  rc_new AS page_is_new,wl_notificationtimestamp\n\t  FROM {$watchlist},{$recentchanges}\n\t  WHERE wl_user={$uid}\n\t  AND wl_namespace=rc_namespace\n\t  AND wl_title=rc_title\n\t  AND rc_timestamp > '{$cutoff}'\n\t  {$andHideOwn}\n\t  {$andHideBots}\n\t  {$nameSpaceClause}\n\t  ORDER BY rc_timestamp DESC\n\t  {$limitWatchlist}";
    $res = $dbr->query($sql, $fname);
    // WERELATE - moved up from below so we can calculate $numRows inside the loop
    //	$numRows = $dbr->numRows( $res );
    $numRows = 0;
    $list = ChangesList::newFromUser($wgUser);
    $rcs = $list->beginRecentChangesList();
    $counter = 1;
    // WERELATE - added array of seen pagetitles
    $seen = array();
    while ($obj = $dbr->fetchObject($res)) {
        $nsTitle = "{$obj->page_namespace}:{$obj->page_title}";
        if (!$andLatest || !isset($seen[$nsTitle])) {
            $seen[$nsTitle] = 1;
            $numRows++;
            # Make fake RC entry
            $rc = RecentChange::newFromCurRow($obj, $obj->rc_last_oldid);
            $rc->counter = $counter++;
            if ($wgShowUpdatedMarker) {
                $updated = $obj->wl_notificationtimestamp;
            } else {
                // Same visual appearance as MW 1.4
                $updated = true;
            }
            if ($wgRCShowWatchingUsers && $wgUser->getOption('shownumberswatching')) {
                $sql3 = "SELECT COUNT(*) AS n FROM {$watchlist} WHERE wl_title='" . wfStrencode($obj->page_title) . "' AND wl_namespace='{$obj->page_namespace}'";
                $res3 = $dbr->query($sql3, DB_READ, $fname);
                $x = $dbr->fetchObject($res3);
                $rc->numberofWatchingusers = $x->n;
            } else {
                $rc->numberofWatchingusers = 0;
            }
            $rcs .= $list->recentChangesLine($rc, $updated);
        }
    }
    $rcs .= $list->endRecentChangesList();
    $dbr->freeResult($res);
    /* Start bottom header */
    // WERELATE - add link to changed view
    //	$wgOut->addHTML( "<hr />\n<p>" );
    $wgOut->addHTML('<hr /><h2>Recently-changed pages</h2><ul><li><a href="' . $specialTitle->getFullUrl('changed=yes') . '">Show all pages changed since last visited</a></li></ul><br/><p>');
    if ($days >= 1) {
        $wgOut->addWikiText(wfMsg('rcnote', $wgLang->formatNum($numRows), $wgLang->formatNum($days), $wgLang->timeAndDate(wfTimestampNow(), true)) . '<br />', false);
    } elseif ($days > 0) {
        $wgOut->addWikiText(wfMsg('wlnote', $wgLang->formatNum($numRows), $wgLang->formatNum(round($days * 24))) . '<br />', false);
    }
    $wgOut->addHTML("\n" . wlCutoffLinks($days, 'Watchlist', $nondefaults) . "<br />\n");
    # Spit out some control panel links
    $thisTitle = Title::makeTitle(NS_SPECIAL, 'Watchlist');
    $skin = $wgUser->getSkin();
    $linkElements = array('hideOwn' => 'wlhideshowown', 'hideBots' => 'wlhideshowbots');
    # Problems encountered using the fancier method
    $label = $hideBots ? wfMsgHtml('show') : wfMsgHtml('hide');
    $linkBits = wfArrayToCGI(array('hideBots' => 1 - (int) $hideBots), $nondefaults);
    $link = $skin->makeKnownLinkObj($thisTitle, $label, $linkBits);
    $links[] = wfMsgHtml('wlhideshowbots', $link);
    $label = $hideOwn ? wfMsgHtml('show') : wfMsgHtml('hide');
    $linkBits = wfArrayToCGI(array('hideOwn' => 1 - (int) $hideOwn), $nondefaults);
    $link = $skin->makeKnownLinkObj($thisTitle, $label, $linkBits);
    $links[] = wfMsgHtml('wlhideshowown', $link);
    $wgOut->addHTML(implode(' | ', $links));
    # Form for namespace filtering
    $thisAction = $thisTitle->escapeLocalUrl();
    $nsForm = "<form method=\"post\" action=\"{$thisAction}\">\n";
    $nsForm .= "<label for=\"namespace\">" . wfMsgExt('namespace', array('parseinline')) . "</label> ";
    $nsForm .= HTMLnamespaceselector($nameSpace, '') . "\n";
    $nsForm .= $hideOwn ? "<input type=\"hidden\" name=\"hideown\" value=\"1\" />\n" : "";
    $nsForm .= $hideBots ? "<input type=\"hidden\" name=\"hidebots\" value=\"1\" />\n" : "";
    $nsForm .= "<input type=\"hidden\" name=\"days\" value=\"" . $days . "\" />\n";
    $nsForm .= "<input type=\"submit\" name=\"submit\" value=\"" . wfMsgExt('allpagessubmit', array('escape')) . "\" />\n";
    $nsForm .= "</form>\n";
    $wgOut->addHTML($nsForm);
    if ($numRows == 0) {
        $wgOut->addWikitext("<br />" . wfMsg('watchnochange'), false);
        $wgOut->addHTML("</p>\n");
        return;
    }
    $wgOut->addHTML("</p>\n");
    /* End bottom header */
    // WERELATE - change $s to $rcs
    $wgOut->addHTML($rcs);
    if ($wgUseWatchlistCache) {
        $wgMemc->set($memckey, $s, $wgWLCacheTimeout);
    }
}
Esempio n. 4
0
 /**
  * Back-end article deletion
  * Deletes the article with database consistency, writes logs, purges caches
  * Returns success
  */
 function doDeleteArticle($reason, $rc = true)
 {
     global $wgUseSquid, $wgDeferredUpdateList;
     global $wgPostCommitUpdateList, $wgUseTrackbacks;
     wfDebug(__METHOD__ . "\n");
     $dbw =& wfGetDB(DB_MASTER);
     $ns = $this->mTitle->getNamespace();
     $t = $this->mTitle->getDBkey();
     $id = $this->mTitle->getArticleID();
     if ($t == '' || $id == 0) {
         return false;
     }
     $u = new SiteStatsUpdate(0, 1, -(int) $this->isCountable($this->getContent()), -1);
     array_push($wgDeferredUpdateList, $u);
     // For now, shunt the revision data into the archive table.
     // Text is *not* removed from the text table; bulk storage
     // is left intact to avoid breaking block-compression or
     // immutable storage schemes.
     //
     // For backwards compatibility, note that some older archive
     // table entries will have ar_text and ar_flags fields still.
     //
     // In the future, we may keep revisions and mark them with
     // the rev_deleted field, which is reserved for this purpose.
     $dbw->insertSelect('archive', array('page', 'revision'), array('ar_namespace' => 'page_namespace', 'ar_title' => 'page_title', 'ar_comment' => 'rev_comment', 'ar_user' => 'rev_user', 'ar_user_text' => 'rev_user_text', 'ar_timestamp' => 'rev_timestamp', 'ar_minor_edit' => 'rev_minor_edit', 'ar_rev_id' => 'rev_id', 'ar_text_id' => 'rev_text_id'), array('page_id' => $id, 'page_id = rev_page'), __METHOD__);
     # Now that it's safely backed up, delete it
     $dbw->delete('revision', array('rev_page' => $id), __METHOD__);
     $dbw->delete('page', array('page_id' => $id), __METHOD__);
     if ($wgUseTrackbacks) {
         $dbw->delete('trackbacks', array('tb_page' => $id), __METHOD__);
     }
     # Clean up recentchanges entries...
     $dbw->delete('recentchanges', array('rc_namespace' => $ns, 'rc_title' => $t), __METHOD__);
     // WERELATE: remove from watchlists on delete
     if (Namespac::isMain($ns)) {
         $rows = $dbw->select(array('watchlist', 'user'), array('user_name'), array('wl_user=user_id', 'wl_namespace' => $ns, 'wl_title' => $t));
         while ($row = $dbw->fetchObject($rows)) {
             $user = User::newFromName($row->user_name, false);
             $wl = WatchedItem::fromUserTitle($user, $this->mTitle);
             $wl->removeWatch();
         }
         $dbw->freeResult($rows);
     }
     # Finally, clean up the link tables
     $t = $this->mTitle->getPrefixedDBkey();
     # Clear caches
     Article::onArticleDelete($this->mTitle);
     # Delete outgoing links
     $dbw->delete('pagelinks', array('pl_from' => $id));
     $dbw->delete('imagelinks', array('il_from' => $id));
     $dbw->delete('categorylinks', array('cl_from' => $id));
     $dbw->delete('templatelinks', array('tl_from' => $id));
     $dbw->delete('externallinks', array('el_from' => $id));
     $dbw->delete('langlinks', array('ll_from' => $id));
     # Log the deletion
     $log = new LogPage('delete', $rc);
     // WERELATE - add id as a log param
     $log->addEntry('delete', $this->mTitle, $reason, array($id));
     # Clear the cached article id so the interface doesn't act like we exist
     $this->mTitle->resetArticleID(0);
     $this->mTitle->mArticleID = 0;
     return true;
 }
Esempio n. 5
0
 function tabAction($title, $message, $selected, $query = '', $checkEdit = false)
 {
     $classes = array();
     if ($selected) {
         $classes[] = 'selected';
     }
     if ($checkEdit && $title->getArticleId() == 0) {
         $classes[] = 'new';
         // WERELATE: removed action=edit
         //			$query = 'action=edit';
     }
     $text = wfMsg($message);
     if ($text == "&lt;{$message}&gt;") {
         global $wgContLang;
         $text = $wgContLang->getNsText(Namespac::getSubject($title->getNamespace()));
     }
     // WERELATE: added title attribute
     return array('class' => implode(' ', $classes), 'text' => $text, 'title' => $this->getMsgOrEmpty($message . 'tip'), 'href' => $title->getLocalUrl($query));
 }
Esempio n. 6
0
 /**
  * Get a title object associated with the subject page of this
  * talk page
  *
  * @return Title the object for the subject page
  * @access public
  */
 function getSubjectPage()
 {
     return Title::makeTitle(Namespac::getSubject($this->getNamespace()), $this->getDBkey());
 }
Esempio n. 7
0
 public static function getWatchlistSummary($title, $text)
 {
     $mainNS = Namespac::getSubject($title->getNamespace());
     if ($mainNS == NS_PERSON) {
         $xml = StructuredData::getXml('person', $text);
         $summary = Person::getSummary($xml, $title);
     } else {
         if ($mainNS == NS_FAMILY) {
             $xml = StructuredData::getXml('family', $text);
             $summary = Family::getSummary($xml, $title);
         } else {
             $summary = '';
         }
     }
     return $summary;
 }
Esempio n. 8
0
 /**
  * Get a local URL given any page title (optionally with namespace prefix).
  *
  * This is a rather verbose workaround to avoid Title calling
  * Namespac::getCanonicalIndex() statically and so throwing an error in
  * newer PHP versions. It can be replaced by Title::newFromText($text)->getLocalURL()
  * one day.
  *
  * @param string $title Page title, possibly with colon-separated NS prefix
  * @return string The local URL as given by Title::getLocalURL()
  */
 function getLocalUrl($title)
 {
     global $wgSitename;
     $targetParts = explode(':', $title);
     $ns = count($targetParts) == 2 ? $targetParts[0] : '';
     if ($ns == $wgSitename) {
         $ns = 'Project';
     } else {
         if ($ns == $wgSitename . '_talk') {
             $ns = 'Project_talk';
         }
     }
     $title = count($targetParts) == 2 ? $targetParts[1] : $targetParts[0];
     $namespace = new Namespac();
     $nsIndex = $namespace->getCanonicalIndex(strtolower($ns));
     $url = Title::makeTitle($nsIndex, $title)->getLocalURL();
     return $url;
 }
Esempio n. 9
0
function readListParams()
{
    global $wgRequest, $wgUser;
    $userName = $wgRequest->getVal('user');
    if ($userName) {
        $user = User::newFromName($userName);
    } else {
        $user = $wgUser;
    }
    $ns = Namespac::getCanonicalIndex(strtolower($wgRequest->getVal('namespace')));
    if (!$ns) {
        $ns = NS_PERSON;
    }
    $callback = $wgRequest->getVal('callback');
    return array($user, $ns, $callback);
}
Esempio n. 10
0
 function getIRCLine()
 {
     global $wgUseRCPatrol;
     extract($this->mAttribs);
     extract($this->mExtra);
     $titleObj =& $this->getTitle();
     if ($rc_type == RC_LOG) {
         $title = Namespac::getCanonicalName($titleObj->getNamespace()) . $titleObj->getText();
     } else {
         $title = $titleObj->getPrefixedText();
     }
     $title = $this->cleanupForIRC($title);
     $bad = array("\n", "\r");
     $empty = array("", "");
     $title = $titleObj->getPrefixedText();
     $title = str_replace($bad, $empty, $title);
     // FIXME: *HACK* these should be getFullURL(), hacked for SSL madness --brion 2005-12-26
     if ($rc_type == RC_LOG) {
         $url = '';
     } elseif ($rc_new && $wgUseRCPatrol) {
         $url = $titleObj->getInternalURL("rcid={$rc_id}");
     } else {
         if ($rc_new) {
             $url = $titleObj->getInternalURL();
         } else {
             if ($wgUseRCPatrol) {
                 $url = $titleObj->getInternalURL("diff={$rc_this_oldid}&oldid={$rc_last_oldid}&rcid={$rc_id}");
             } else {
                 $url = $titleObj->getInternalURL("diff={$rc_this_oldid}&oldid={$rc_last_oldid}");
             }
         }
     }
     if (isset($oldSize) && isset($newSize)) {
         $szdiff = $newSize - $oldSize;
         if ($szdiff < -500) {
             $szdiff = "{$szdiff}";
         } elseif ($szdiff >= 0) {
             $szdiff = '+' . $szdiff;
         }
         $szdiff = '(' . $szdiff . ')';
     } else {
         $szdiff = '';
     }
     $user = $this->cleanupForIRC($rc_user_text);
     if ($rc_type == RC_LOG) {
         $logTargetText = $logTarget->getPrefixedText();
         $comment = $this->cleanupForIRC(str_replace($logTargetText, "02{$logTargetText}10", $rc_comment));
         $flag = $logAction;
     } else {
         $comment = $this->cleanupForIRC($rc_comment);
         $flag = ($rc_minor ? "M" : "") . ($rc_new ? "N" : "");
     }
     # see http://www.irssi.org/documentation/formats for some colour codes. prefix is \003,
     # no colour (\003) switches back to the term default
     $fullString = "14[[07{$title}14]]4 {$flag}10 " . "02{$url} 5* 03{$user} 5* {$szdiff} 10{$comment}\n";
     return $fullString;
 }
Esempio n. 11
0
 /**
  * If the namespace isn't listed on the priority list return the
  * default priority for the namespace, varies depending on whether it's
  * a talkpage or not.
  *
  * @param int $namespace The namespace to get the priority for
  *
  * @return string
  */
 function guessPriority($namespace)
 {
     return Namespac::isMain($namespace) ? $this->priorities[GS_MAIN] : $this->priorities[GS_TALK];
 }
Esempio n. 12
0
/**
 * Get index contents for specified page_id's
 *
 * @param unknown_type $args page_id=id,id,id,... (up to IAF_MAX_COUNT_CONTENTS)|index=1 to return watchers (defaults to 0)
 * @return IAF_SUCCESS, IAF_INVALID_ARG
 */
function wfGetPageIndexContents($args)
{
    global $wgAjaxCachePolicy;
    // set cache policy
    $wgAjaxCachePolicy->setPolicy(0);
    // validate input arguments
    $status = IAF_SUCCESS;
    $result = array();
    $args = iafGetArgs($args);
    $pageidString = iafGetArg($args, 'page_id', null);
    $index = iafGetArg($args, 'index', false);
    $pageids = explode(',', $pageidString);
    if (!$pageidString || count($pageids) > IAF_MAX_COUNT_CONTENTS) {
        $status = IAF_INVALID_ARG;
    } else {
        $db =& wfGetDB(DB_SLAVE);
        $db->ignoreErrors(true);
        foreach ($pageids as $pageid) {
            $ns = 0;
            $fullTitle = '';
            $timestamp = '';
            $revid = '';
            $text = '';
            $popularity = '';
            $users = array();
            $trees = array();
            $revision = Revision::loadFromPageId($db, $pageid);
            $errno = $db->lastErrno();
            if ($errno != 0) {
                $status = IAF_DB_ERROR;
                break;
            }
            if ($revision) {
                $ns = $revision->getTitle()->getNamespace();
                $fullTitle = $revision->getTitle()->getPrefixedText();
                $timestamp = $revision->getTimestamp();
                $revid = $revision->getId();
                $text =& $revision->getText();
                $errno = $db->lastErrno();
                if ($errno != 0) {
                    $status = IAF_DB_ERROR;
                    break;
                }
                if ($index) {
                    $watcherCount = 0;
                    $dbkey = $revision->getTitle()->getDBkey();
                    $rows = $db->select(array('watchlist', 'user'), array('user_name'), array('wl_user=user_id', 'wl_namespace' => $ns, 'wl_title' => $dbkey));
                    $errno = $db->lastErrno();
                    if ($errno != 0) {
                        $status = IAF_DB_ERROR;
                        break;
                    }
                    while ($row = $db->fetchObject($rows)) {
                        $users[] = '<user>' . StructuredData::escapeXml($row->user_name) . '</user>';
                        $watcherCount++;
                    }
                    $db->freeResult($rows);
                    $rows = $db->select(array('familytree_page', 'familytree'), array('ft_user', 'ft_name'), array('fp_tree_id=ft_tree_id', 'fp_namespace' => $ns, 'fp_title' => $dbkey));
                    $errno = $db->lastErrno();
                    if ($errno != 0) {
                        $status = IAF_DB_ERROR;
                        break;
                    }
                    while ($row = $db->fetchObject($rows)) {
                        $temp = $row->ft_user . '/' . $row->ft_name;
                        $trees[] = '<tree>' . StructuredData::escapeXml($temp) . '</tree>';
                    }
                    $db->freeResult($rows);
                    $wlhCount = 0;
                    $sns = Namespac::getSubject($ns);
                    if ($sns == NS_MAIN || $sns == NS_IMAGE || $sns == NS_CATEGORY || $sns == NS_PROJECT || $sns == NS_USER || $sns == NS_HELP || $sns == NS_SOURCE || $sns == NS_REPOSITORY || $sns == NS_PORTAL || $sns == NS_PLACE || $sns == NS_TRANSCRIPT) {
                        if (($ns == NS_SOURCE || $ns == NS_REPOSITORY) && ($dbkey == 'Family_History_Library' || $dbkey == 'Family_History_Center')) {
                            $wlhCount = 100000;
                        } else {
                            if ($ns == NS_IMAGE) {
                                $wlhCount = $db->selectField('imagelinks', 'count(*)', array('il_to' => $dbkey));
                            } else {
                                $wlhCount = $db->selectField('pagelinks', 'count(*)', array('pl_namespace' => $ns, 'pl_title' => $dbkey));
                            }
                        }
                        if ($ns == NS_PLACE || $ns == NS_USER || $ns == NS_CATEGORY) {
                            // discount links to place/user pages
                            $wlhCount = $wlhCount / 128;
                        }
                    }
                    $popularity = $watcherCount + $wlhCount > 0 ? max(20, min(384, floor(128 * log10($watcherCount * 4 + $wlhCount)))) : 0;
                }
            }
            $result[] = '<page page_id="' . $pageid . '" namespace="' . $ns . '" title="' . StructuredData::escapeXml($fullTitle) . '" rev_id="' . $revid . '" rev_timestamp="' . $timestamp . '" popularity="' . $popularity . '">' . '<contents>' . StructuredData::escapeXml($text) . '</contents>' . join("\n", $users) . join("\n", $trees) . '</page>';
        }
    }
    // return status
    return "<result status=\"{$status}\">" . join("\n", $result) . '</result>';
}
Esempio n. 13
0
 function pass($page)
 {
     return !Namespac::isTalk($page->page_namespace);
 }