UESPWiki:SearchLog/SpecialSearchLog.php

pageurl = "/wiki/Special:SearchLog";
                $this->sortkey = "none";
                $this->maxrows = 1000;
                $this->summary = 0;
                $this->empty   = 0;
        }

        function execute( $par ) {
                global $wgRequest, $wgOut, $wgUser;

                $this->setHeaders();

                if ( !$wgUser->isAllowed( 'patrol' ) )
                {
                        $wgOut->permissionRequired( 'patrol' );
                        return;
                }

                $this->showHeader();

                $this->summary = $wgRequest->getText('summary');
                $this->sortkey = $wgRequest->getText('sort');
                $this->empty   = $wgRequest->getText('empty');

                if ($this->summary)
                        $this->showSummary();
                else
                        $this->showLog();
        }

        function makePageLink ($var, $value)
        {
                $pagelink = $this->pageurl . '?';

                if ( $var != 'summary' )
                        $pagelink .= 'summary='. $this->summary .'&';
                else
                        $pagelink .= $var .'='. $value .'&';

                if ( $var != 'sort' )
                        $pagelink .= 'sort='. $this->sortkey .'&';
                else
                        $pagelink .= $var .'='. $value .'&';

                if ( $var != 'empty' )
                        $pagelink .= 'empty='. $this->empty .'&';
                else
                        $pagelink .= $var .'='. $value .'&';

                return $pagelink;
        }

        function showHeader()
        {
                global $wgOut, $ArticlePath;

                $wgOut->addHTML(' ');
                $wgOut->addHTML('      ');
                $wgOut->addHTML('      ');
                $wgOut->addHTML(' ');
                $wgOut->addHTML("  \n");
        }

        function showSummary()
        {
                global $wgOut;

                $wgOut->addHTML("Displaying accumulated summary of search queries ordered by $this->sortkey. \n");

                $dbw = wfGetDB(DB_SLAVE);
                $sortSQL = 'term ASC';

                switch ($this->sortkey)
                {
                case 'term':
                        $sortSQL = 'term';
                        break;
                case 'count':
                        $sortSQL = 'count DESC';
                        break;
                }

                $log = $dbw->select('searchlog_summary', array('term', 'count'), '', , array('ORDER BY' => $sortSQL));

                if ($log)
                        $wgOut->addHTML("Found ". $log->numRows() ." unique search queries...");
                else
                        $wgOut->addHTML("Found 0 unique search queries...");

                $wgOut->addHTML(" \n");
                $wgOut->addHTML(" ");
                $wgOut->addHTML("   ");
                $wgOut->addHTML("   \n");

                $count = 0;

                while ($result = $log->next())
                {
                        ++$count;
                        if ($count > $this->maxrows) break;

                        $wgOut->addHTML(" ");
                        $wgOut->addHTML(" ");
                        $wgOut->addHTML(" ");
                        $wgOut->addHTML(" \n");
        }

        function showLog ()
        {
                global $wgOut;

                if ($this->empty)
                        $wgOut->addHTML("Displaying log of empty search queries ordered by $this->sortkey. \n");
                else
                        $wgOut->addHTML("Displaying log of search queries ordered by $this->sortkey. \n");


                $sortSQL = 'searchdate DESC';

                switch ($this->sortkey)
                {
                case 'term':
                        $sortSQL = 'term';
                        break;
                case 'titlecount':
                        $sortSQL = 'titlecount ASC';
                        break;
                case 'textcount':
                        $sortSQL = 'textcount ASC';
                        break;
                case 'date':
                        $sortSQL = 'searchdate DESC';
                        break;
                case 'timetaken':
                        $sortSQL = 'searchtime DESC';
                        break;
                }

                $dbw = wfGetDB(DB_SLAVE);
       }

        function showLog ()
        {
                global $wgOut;

                if ($this->empty)
                        $wgOut->addHTML("Displaying log of empty search queries ordered by $this->sortkey. \n");
                else
                        $wgOut->addHTML("Displaying log of search queries ordered by $this->sortkey. \n");


                $sortSQL = 'searchdate DESC';

                switch ($this->sortkey)
                {
                case 'term':
                        $sortSQL = 'term';
                        break;
                case 'titlecount':
                        $sortSQL = 'titlecount ASC';
                        break;
                case 'textcount':
                        $sortSQL = 'textcount ASC';
                        break;
                case 'date':
                        $sortSQL = 'searchdate DESC';
                        break;
                case 'timetaken':
                        $sortSQL = 'searchtime DESC';
                        break;
                }

                $dbw = wfGetDB(DB_SLAVE);

                if ($this->empty)
                        $where = "titlecount=0 AND textcount=0";
                else
                        $where = "";

                $log = $dbw->select('searchlog', array('term', 'titlecount', 'textcount', 'searchdate', 'searchtime'), $where, , array('ORDER BY' => $sortSQL));

                if ($log)
                        $wgOut->addHTML("Found ". $log->numRows() ." search queries...");
                else
                        $wgOut->addHTML("Found 0 search queries...");

                $wgOut->addHTML(" \n");
                $wgOut->addHTML(" ");
                $wgOut->addHTML("   ");
                $wgOut->addHTML("   ");
                $wgOut->addHTML("   ");
                $wgOut->addHTML("   ");
                $wgOut->addHTML("   \n");

                $count = 0;

                while ($result = $log->next())
                {
                        ++$count;
                        if ($count > $this->maxrows) break;

                        $wgOut->addHTML(" ");
                        $wgOut->addHTML(" ");
                        $wgOut->addHTML(" ");
                        $wgOut->addHTML(" ");
                        $wgOut->addHTML(" ");
                        $wgOut->addHTML(" ");
                        $wgOut->addHTML(" \n");
        }

}

?>